Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

CalSection.cxx

Go to the documentation of this file.
00001 
00002 //                                                                      //
00003 // PS   CalSection.                                                     //
00004 // 00/09/06                                                             //
00005 //                                                                      //
00006 // build an array of cells spanning the eta and phi ranges passed in the//
00007 // constructor. The granularities used are the closest to the requested //
00008 // values, but which divide exactly into the requested ranges.          //
00009 //                                                                      //
00010 //                                                                      //
00011 //                                                                      //
00012 //                                                                      //
00013 //                                                                      //
00015 
00016 
00017 #include "AtlfastAlgs/CalSection.h"
00018 #include <iostream>
00019 #include <assert.h>
00020 #include <algorithm>
00021 #include "AtlfastEvent/TwoCptCell.h"
00022 #include "AtlfastAlgs/ICellSelector.h"
00023 #include "AtlfastAlgs/ISmearer.h"
00024 #include "AtlfastAlgs/TransportedParticle.h"
00025 #include "GaudiKernel/MsgStream.h"
00026 #include "AtlfastEvent/EPileupDeposit.h"
00027 #include "FastShowerUtils/Gridlet.h"
00028 #include "CLHEP/Vector/LorentzVector.h"
00029 namespace Atlfast {
00030   using FastShower::GridletElement;
00031 
00032 //____________________________________________________________________
00033   CalSection::CalSection(
00034                          MsgStream& log,
00035                          double minEta,
00036                          double maxEta,
00037                          double granEta,
00038                          double granPhi,
00039                          double minPhi,
00040                          double maxPhi
00041                          ):
00042     m_log(log),
00043     m_minEta(minEta), m_maxEta(maxEta),
00044     m_minPhi(minPhi), m_maxPhi(maxPhi),
00045     m_calSectionReject(minEta, maxEta, minPhi, maxPhi){
00046     
00047     log <<MSG::DEBUG<< "CalSection: construction. Eta range: "
00048         <<minEta<<" - "<<maxEta<<endreq; 
00049     log <<MSG::DEBUG<< "                          Phi range: "
00050         <<minPhi<<" - "<<maxPhi<<endreq; 
00051     log <<MSG::DEBUG<< " starting granularity Eta: "<<granEta
00052         << " phi: "<<granPhi
00053         <<endreq;
00054 
00055     log <<MSG::DEBUG<<"CalSectionReject parameters:"<<endreq;
00056     log <<MSG::DEBUG<<m_calSectionReject<<endreq;
00057 
00058     int nEta    = int(((maxEta-minEta)/granEta)+0.5);
00059     m_granEta   = (maxEta-minEta)/int(nEta);
00060     m_nPhi      = 1+int(((m_maxPhi-m_minPhi)/granPhi)+0.5);
00061     m_granPhi   = (m_maxPhi-m_minPhi)/double(m_nPhi); 
00062     log <<MSG::DEBUG<< " final granularity Eta: "<<m_granEta
00063         << " phi: "<<m_granPhi
00064         <<endreq; 
00065     log <<MSG::DEBUG<< " final Bins in Eta: "<<nEta
00066         << " phi: "<<m_nPhi
00067         <<endreq; 
00068 
00069     for (int ieta=0; ieta<nEta; ieta++){
00070       for (int iphi=0; iphi<m_nPhi; iphi++){
00071         
00072         double eta        = minEta+((double(ieta)+0.5)*double(m_granEta));
00073         double phi        = m_minPhi + ((double(iphi)+0.5)*double(m_granPhi));
00074         CellDescriptor id = CellDescriptor(eta,phi);
00075         ITwoCptCell* cell = new TwoCptCell(id);
00076         
00077         m_cells.push_back(cell);
00078       }
00079     }
00080   }
00081   CalSection::~CalSection(){
00082     m_log<<MSG::DEBUG<<"CalSection destructor starts "<<endreq;
00083     std::vector<ITwoCptCell*>::iterator i=m_cells.begin();
00084     for(;i<m_cells.end();++i) delete *i;
00085     m_log<<MSG::DEBUG<<"CalSection destructor ends "<<endreq;
00086   }
00087   CalSection::CalSection(const CalSection& c):
00088     m_log(c.m_log),
00089     m_minEta(c.m_minEta),
00090     m_maxEta(c.m_maxEta),
00091     m_minPhi(c.m_minPhi),
00092     m_maxPhi(c.m_maxPhi),
00093     m_granEta(c.m_granEta),
00094     m_granPhi(c.m_granPhi),
00095     m_nPhi(c.m_nPhi),
00096     m_calSectionReject(c.m_calSectionReject){
00097     std::vector<ITwoCptCell*>::const_iterator i=c.m_cells.begin();
00098     for(;i<c.m_cells.end();++i) m_cells.push_back((*i)->cloneITCC());
00099   }
00100   //----------------------------------------------------------------
00101   void CalSection::deposit(TransportedParticleCollectionIter& f, 
00102                            TransportedParticleCollectionIter& l){
00103     // remove particles not in acceptance
00104     TransportedParticleCollectionIter divider;
00105     divider = std::partition(f, l, m_calSectionReject);
00106 
00107     // fill cells 
00108     for(TransportedParticleCollectionCIter i=divider; i<l; ++i){newHit(*i);}
00109 
00110     // assume sections do not overlap: do not reprocess.
00111     l=divider;
00112   }
00113   //----------------------------------------------------------------
00114   void CalSection::depositEcal(std::vector<GridletElement*>::iterator f, 
00115                                std::vector<GridletElement*>::iterator l
00116                                ){
00117     
00118     std::vector<GridletElement*>::iterator divider;
00119     divider = std::partition(f, l, m_calSectionReject);
00120   
00121     std::vector<GridletElement*>::iterator i;
00122     for( i=divider; i<l; ++i){newEHit(*i);}
00123 
00124     // assume sections do not overlap: do not reprocess.
00125     l=divider;
00126   }
00127   //----------------------------------------------------------------
00128   void CalSection::depositHcal(std::vector<GridletElement*>::iterator f, 
00129                                std::vector<GridletElement*>::iterator l
00130                                ){
00131     
00132     std::vector<GridletElement*>::iterator divider;
00133     divider = std::partition(f, l, m_calSectionReject);
00134   
00135     std::vector<GridletElement*>::iterator i;
00136     for( i=divider; i<l; ++i){newHHit(*i);}
00137 
00138     // assume sections do not overlap: do not reprocess.
00139     l=divider;
00140   }
00141   //----------------------------------------------------------------
00142   void CalSection::newHit( const TransportedParticle* tp){
00143     //check cell is reasonable
00144     const HepMC::GenParticle* particle = tp->particle();
00145     const double eta = particle->momentum().pseudoRapidity();
00146     const double phi = tp->phi();
00147     int ind = iindex(phi, eta);
00148     ITwoCptCell* cell = m_cells[ind];
00149     assert(abs( eta-(cell->eta()) ) <m_granEta);
00150     assert(abs( phi-(cell->phi()) ) <m_granPhi);
00151     cell->newHit(particle);
00152     //use a map to store pointers to hit cells to avoid
00153     //duplicate entries if the cell is hit more than once.
00154     m_hitCells[ind] = cell;
00155 
00156     return;
00157   }
00158   //----------------------------------------------------------------
00159   void CalSection::newEHit( const GridletElement* ge){
00160     int ind = index(ge);
00161     ITwoCptCell* cell = m_cells[ind];
00162     //    cerr<<"gridletEl, phi, eta, eT:     "
00163     //    <<ge->phi()<<" "<<ge->eta()<<" "<<ge->et()<<endl;
00164     //    cerr<<"cell, phi, eta, granularity: "<<cell->phi()<<" "<<cell->eta()
00165     //  <<" "<<m_granPhi<<" "<<m_granEta<<endl;
00166     assert(abs( (ge->eta()-cell->eta()) )<m_granEta);
00167     assert(abs( (ge->phi()-cell->phi()) )<m_granPhi);
00168     cell->depositEcal(ge->et());
00169     //use a map to store pointers to hit cells to avoid
00170     //duplicate entries if the cell is hit more than once.
00171     m_hitCells[ind] = cell;
00172 
00173     return;
00174   }
00175   //----------------------------------------------------------------
00176   void CalSection::newHHit( const GridletElement* ge){
00177     int ind = index(ge);
00178     ITwoCptCell* cell = m_cells[ind];
00179     //    cerr<<"gridletEl, phi, eta, eT:     "
00180     //  <<ge->phi()<<" "<<ge->eta()<<" "<<ge->et()<<endl;
00181     //    cerr<<"cell, phi, eta, granularity: "<<cell->phi()<<" "<<cell->eta()
00182     //  <<" "<<m_granPhi<<" "<<m_granEta<<endl;
00183     assert(abs( (ge->eta())-(cell->eta()) )<m_granEta);
00184     assert(abs( (ge->phi())-(cell->phi()) )<m_granPhi);
00185     cell->depositHcal(ge->et());
00186     //use a map to store pointers to hit cells to avoid
00187     //duplicate entries if the cell is hit more than once.
00188     m_hitCells[ind] = cell;
00189 
00190     return;
00191   }
00192   //----------------------------------------------------------------
00193   int  CalSection::index(const GridletElement* ge) const{
00194     int ind = this->iindex( ge->phi(), ge->eta() );
00195     return ind;
00196   }
00197   //----------------------------------------------------------------
00198   int  CalSection::index(const  TransportedParticle* tp) const {
00199     const HepMC::GenParticle* particle = tp->particle();
00200     const double eta = particle->momentum().pseudoRapidity();
00201     const double phi = tp->phi();
00202     int ind = iindex(phi, eta);
00203     return ind;
00204   }
00205   //----------------------------------------------------------------
00206   int  CalSection::index(const Atlfast::EPileupDeposit* ep) const{
00207     int ind = iindex(ep->phi(),ep->eta());
00208     return ind;
00209   }
00210   //----------------------------------------------------------------
00211   int CalSection::iindex(double phi, double eta) const{
00212     int iphi = int( (phi-m_minPhi)/m_granPhi );
00213     int ieta = int( (eta-m_minEta)/m_granEta );
00214     
00215     return  (m_nPhi*ieta  + iphi);
00216   }
00217   //----------------------------------------------------------------
00218   // FOR ENERGY PILEUP METHODS
00219   //----------------------------------------------------------------
00220   void CalSection::deposit(std::vector<Atlfast::EPileupDeposit*>::iterator& f, 
00221                            std::vector<Atlfast::EPileupDeposit*>::iterator& l){
00222     // remove pileup deposits not in acceptance
00223     std::vector<Atlfast::EPileupDeposit*>::iterator divider;
00224     divider = std::partition(f, l, m_calSectionReject);
00225 
00226     // fill cells 
00227     std::vector<Atlfast::EPileupDeposit*>::iterator  i=divider;
00228     for(; i<l; ++i) newHit(*i);
00229 
00230     // assume sections do not overlap: do not reprocess.
00231     // hits processed here: set last to end of unprocessed hits
00232     l=divider;
00233   }
00234 
00235   //----------------------------------------------------------------
00236   void CalSection::newHit( const Atlfast::EPileupDeposit* ep){
00237     //check cell is reasonable
00238     int ind = index(ep);
00239     ITwoCptCell* cell = m_cells[ind];
00240     assert(abs( (ep->eta()) - (cell->eta()) )<m_granEta);
00241     assert(abs( (ep->phi()) - (cell->phi()) )<m_granPhi);
00242     cell->newHit(ep);
00243      //use a map to store pointers to hit cells to avoid
00244     //duplicate entries if the cell is hit more than once.
00245     m_hitCells[ind] = cell;
00246     return;
00247   }
00248   //===========================================================================
00249   void CalSection::giveHits
00250     (const ICellSelector* p_cellselect, ITwoCptCellCollection* cells) const{
00251     std::map<int, ITwoCptCell*, std::less<int> >::const_iterator i;
00252     for(i=m_hitCells.begin(); i!=m_hitCells.end(); ++i){
00253       //test cell before newing and filling vector
00254       if( (*p_cellselect) (((*i).second))){ 
00255         ITwoCptCell* cell = ((*i).second)->cloneITCC();
00256       //Need to copy cells because Athena deletes container AND POINTERS
00257       // AND POINTEES
00258         cells->push_back(cell);
00259       }
00260     }
00261 
00262   }
00263   //===========================================================================
00264   void CalSection::smearCells
00265     (ISmearer* p_smearer) {
00266     std::map<int, ITwoCptCell*, std::less<int> >::const_iterator i;
00267     for(i=m_hitCells.begin(); i!=m_hitCells.end(); ++i){
00268       if((*((*i).second)).momentum().e() > 0){
00269         HepLorentzVector temp = p_smearer->smear((*((*i).second)).momentum());
00270           (*((*i).second)).setPt(temp);
00271       }
00272     }
00273   }
00274 
00275 
00276 
00277   void CalSection::reset(){
00278     //reset the cells of this CalSection
00279 
00280     std::map<int, ITwoCptCell*>::const_iterator i = m_hitCells.begin();
00281     for(;i!=m_hitCells.end();++i) (*i).second->resetCell();
00282     m_hitCells.erase(m_hitCells.begin(), m_hitCells.end());
00283   }
00284 }
00285 
00286     
00287     
00288   
00289 
00290 
00291 
00292 
00293 
00294 
00295 
00296 

Generated on Tue Mar 18 11:18:22 2003 for AtlfastAlgs by doxygen1.3-rc1