/////////////////////////////////////////////////////////////////////////////
//
// EEezPatch
//
// Author: Jason C. Webb <jwebb@iucf.indiana.edu>
//
// A simple container class for describing a "patch" of towers.  A "patch"
// might correspond to a trigger patch, a group of trigger patches, or
// any configuration... e.g. a sector or the entire calorimeter.
//
/////////////////////////////////////////////////////////////////////////////

#include "EEezPatch.h"
#include <iostream>

ClassImp(EEezPatch);

/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

 EEezPatch::EEezPatch() 
{
  // Class Constructor.
  mProfileU = 0;
  mProfileV = 0;
  mETowers  = 0;

}

 EEezPatch::~EEezPatch()
{
  // Class Destructor.
  if ( mProfileU ) delete mProfileU;
  if ( mProfileV ) delete mProfileV;
  if ( mETowers  ) delete mETowers;
}



/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

 void EEezPatch::addTower ( EEezTower *tower )
{
  // Add the specified EEezTower to the list of towers contained
  // in this patch.  Reject duplicate entries.

  if ( hasTower(tower) ) return;
  mTowers.push_back( tower );

}

/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

 void EEezPatch::addStrip ( EEezStrip *strip )
{
  // Add the specified strip to the list(s) of SMD strips which
  // fall within the fiducial volume of the towers in this patch.
  // Reject duplicate entries.

  if ( hasStrip(strip) ) return;

  if ( strip -> getPlane() == 0 ) {

    mUStrips.push_back( strip );

  }
  else if ( strip -> getPlane() == 1 ) {
    
    mVStrips.push_back( strip );

  }
  else

    assert( (2+2)==5 ); // 0==U, 1==V, otherwise crash

}

/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

 void EEezPatch::addNeighbor( EEezPatch *p ) 
{
  // Adds a neighboring patch to the list of neighboring 
  // tower patches.

  mNeighbors.push_back( p );

}

/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

 EEezTowerPtrVec_t *EEezPatch::getTowers()
{
  // Returns a pointer to the list of towers contained
  // within this patch.
  return &mTowers;
}

/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

 EEezStripPtrVec_t *EEezPatch::getUStrips()
{
  // Returns a pointer to the list of U strips within
  // the fiducial volume of the towers contained
  // within this patch.
  return &mUStrips;
}

 EEezStripPtrVec_t *EEezPatch::getVStrips()
{
  // Returns a pointer to the list of V strips within
  // the fiducial volume of the towers contained
  // within this patch.
  return &mVStrips;
}

/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

 EEezPatchPtrVec_t *EEezPatch::getNeighbors()
{
  // Returns a pointer to the list of neighboring patches.
  return &mNeighbors;
}

/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

 Int_t EEezPatch::hasTower( EEezTower *tower )
{
  // Determine if the tower belongs to this tower patch.  Complexity = 
  // N towers.

  EEezTowerPtrVecIter_t iter = mTowers.begin();
  while ( iter != mTowers.end() ) {
    if ( (*iter)->getIndex() == tower->getIndex() ) return 1;
    iter++;
  }
  return 0;

}

/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

 Int_t EEezPatch::hasStrip( EEezStrip *strip )
{
  // Determine if the strip belongs to this tower patch.  Complexity ~=
  // N strips.

  Int_t sector = strip -> getSector();
  Int_t plane  = strip -> getPlane();
  Int_t index  = strip -> getIndex();

  EEezStripPtrVecIter_t iter = (plane==0)?mUStrips.begin():mVStrips.begin();
  EEezStripPtrVecIter_t endv = (plane==0)?mUStrips.end():mVStrips.end();

  while ( iter != endv ) {

    if ( (*iter)->getSector() == sector  &&
	 (*iter)->getIndex()  == index ) return 1;
    
    iter++;
  }
  return 0;

}

/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

 void EEezPatch::addCluster( EEezCluster *cluster )
{
  // Add the towers and underlying SMD strips in the cluster
  // to the patch.  Need to increase speed.  Too many redundant
  // calls to hasTower() and hasStrip() are possible here.

  //-- Get the seed tower of the cluster and add it to
  //-- the patch.
  EEezTower *seed = cluster -> getSeedTower();
  addTower(seed);
  Int_t nu = seed -> getNUStrips();
  Int_t nv = seed -> getNVStrips();
  for ( Int_t j = 0; j < nu; j++ ) addStrip( seed->getUStrip(j) );
  for ( Int_t j = 0; j < nv; j++ ) addStrip( seed->getVStrip(j) );
 
  //-- Loop over all neighbors, and add them to the patch
  for ( Int_t i = 0; i < seed -> getNNeighbors(); i++ ) {
    EEezTower *tower = seed -> getNeighbor(i);
    addTower ( tower );
    nu = tower -> getNUStrips();
    nv = tower -> getNVStrips();
    for ( Int_t j = 0; j < nu; j++ ) addStrip( tower->getUStrip(j) );
    for ( Int_t j = 0; j < nv; j++ ) addStrip( tower->getVStrip(j) );
  }

}

/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

 void EEezPatch::addPatch ( EEezPatch *patch )
{
  // Add another patch of towers to this patch
  EEezTowerPtrVec_t *towers = patch -> getTowers();
  EEezTowerPtrVecIter_t iterTower = towers -> begin();
  while ( iterTower != towers -> end() ){
    addTower( (*iterTower) );
    iterTower++;
  }

  EEezStripPtrVec_t *strips = patch -> getUStrips();
  EEezStripPtrVecIter_t iterStrips = strips -> begin();
  while ( iterStrips != strips -> end() ) {
    addStrip( (*iterStrips) );
    iterStrips++;
  }
  strips = patch -> getVStrips();
  iterStrips = strips -> begin();
  while ( iterStrips != strips -> end() ) {
    addStrip( (*iterStrips) );
    iterStrips++;
  }

}

/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

 void EEezPatch::mergeNeighbors()
{
  // Merge all neighboring patches with this one, and clear the list
  // of neighboring patches.  (Not yet implemented).

  assert(0); // Not yet implemented

}

/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

 TH1F *EEezPatch::profileU()
{
  // Projects the SMD u strips into a new histogram and returns
  // a pointer to the histogram.
  //
  // NOTE: Assumes single sector at present 

  if ( mProfileU ) return mProfileU;

  //-- Determine range of SMD strips from the towers
  Int_t min,max, uMin, uMax;
  min = 999;
  max = -999;

  EEezTowerPtrVecIter_t towers = mTowers.begin();
  while ( towers != mTowers.end() ) {
    
    (*towers)->getRangeU(uMin,uMax);
    if ( uMin < min ) min = uMin;
    else
      if ( uMax > max ) max = uMax;

    towers++;
  }

  mProfileU = new TH1F("mProfileU","SMD U response",max-min,min,max);
  mProfileU -> GetXaxis() -> SetTitle("SMD-U index");

  //-- Fill histogram
  EEezStripPtrVecIter_t iter = mUStrips.begin();
  while ( iter != mUStrips.end() ) {
    Int_t index = (*iter)->getIndex();
    Float_t mip = (*iter)->getNumMips();
    mProfileU -> Fill( (index+0.5), mip );
    iter++;
  }
  return mProfileU;

}

 TH1F *EEezPatch::profileV()
{
  // Projects the SMD u strips into a new histogram and returns
  // a pointer to the histogram.
  //
  // NOTE: Assumes single sector at present 

  if ( mProfileV ) return mProfileV;

  //-- Determine range of SMD strips from the towers
  Int_t min,max, vMin, vMax;
  min = 999;
  max = -999;

  EEezTowerPtrVecIter_t towers = mTowers.begin();
  while ( towers != mTowers.end() ) {
    
    (*towers)->getRangeV(vMin,vMax);
    if ( vMin < min ) min = vMin;
    else
      if ( vMax > max ) max = vMax;

    towers++;
  }

  mProfileV = new TH1F("mProfileV","SMD V response",max-min,min,max);
  mProfileV -> GetXaxis() -> SetTitle("SMD-V index");

  //-- Fill histogram
  EEezStripPtrVecIter_t iter = mVStrips.begin();
  while ( iter != mVStrips.end() ) {
    Int_t index = (*iter)->getIndex();
    Float_t mip = (*iter)->getNumMips();
    mProfileV -> Fill( (index+0.5), mip );
    iter++;
  }
  return mProfileV;

}

 TH2F *EEezPatch::towers( Option_t *opts )
{
  // Creates a 2D histogram of tower energy response for the
  // patch.
  //
  // NOTE: Assumes single sector at present 

  if ( mETowers ) return mETowers;

  Int_t idet = 0;
  if ( TString(opts).Contains("P") )
    idet = 1;
  else if ( TString(opts).Contains("Q") )
    idet = 2;
  else if ( TString(opts).Contains("R") )
    idet = 3;

  Int_t subMin =  999;
  Int_t subMax = -999;
  Int_t etaMin =  999;
  Int_t etaMax = -999;

  //-- Find min and max eta and subsector
  EEezTowerPtrVecIter_t iter = mTowers.begin();
  while ( iter != mTowers.end() ) {
    Int_t sub = (*iter)->getSubSector();
    Int_t eta = (*iter)->getEtabin();
    if ( sub < subMin ) subMin = sub; 
    if ( sub > subMax ) subMax = sub;
    if ( eta < etaMin ) etaMin = eta; 
    if ( eta > etaMax ) etaMax = eta;
    iter++;
  }

  mETowers = new TH2F("mETowers","Energy response of towers in patch",subMax-subMin,subMin,subMax,etaMax-etaMin,etaMin,etaMax);
  iter = mTowers.begin();
  while ( iter != mTowers.end() ) {
    Float_t sub = (Float_t)(*iter)->getSubSector() - subMin + 0.5;
    Float_t eta = (Float_t)(*iter)->getEtabin()    - etaMin + 0.5;

    mETowers -> Fill ( sub, eta, (*iter)->getEnergy(idet) );
    iter++;
  }

  return mETowers;

}

/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

 void EEezPatch::print()
{
  // Print out a summary of the patch
  std::cout 
    << "-- EEezPatch::print() ----------------------" << std::endl
    << "nTowers  = " << mTowers.size() << std::endl
    << "nUStrips = " << mUStrips.size() << std::endl
    << "nVStrips = " << mVStrips.size() << std::endl;

//   EEezTowerPtrVecIter_t iter = mTowers.begin();
//   while ( iter != mTowers.end() ) {
//     (*iter)->printLine();
//     std::cout << std::endl;
//     iter++;
//   }

//   EEezTowerPtrVecIter_t uiter = mUStrips.begin();
//   while ( uiter != mUStrips.end() ) {
//     (*iter)->print();
//     std::cout << std::endl;
//     uiter++;
//   }

//   EEezTowerPtrVecIter_t viter = mVStrips.begin();
//   while ( viter != mVStrips.end() ) {
//     (*iter)->print();
//     std::cout << std::endl;
//     viter++;
//   }


    

}


ROOT page - Class index - Top of the page

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.