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 "AtlfastEvent/ITransportedParticle.h"
00025 #include "AtlfastAlgs/DeleteObject.h"
00026 #include "GaudiKernel/MsgStream.h"
00027 #include "AtlfastEvent/EPileupDeposit.h"
00028 #include "FastShowerUtils/Gridlet.h"
00029 #include "CLHEP/Vector/LorentzVector.h"
00030 namespace Atlfast {
00031   using FastShower::GridletElement;
00032 
00033 //____________________________________________________________________
00034   CalSection::CalSection(
00035                          MsgStream& log,
00036                          double minEta,
00037                          double maxEta,
00038                          double granEta,
00039                          double granPhi,
00040                          double minPhi,
00041                          double maxPhi
00042                          ):
00043     m_log(log),
00044     m_minEta(minEta), m_maxEta(maxEta),
00045     m_minPhi(minPhi), m_maxPhi(maxPhi),
00046     m_calSectionReject(minEta, maxEta, minPhi, maxPhi){
00047     
00048     log <<MSG::DEBUG<< "CalSection: construction. Eta range: "
00049         <<minEta<<" - "<<maxEta<<endreq; 
00050     log <<MSG::DEBUG<< "                          Phi range: "
00051         <<minPhi<<" - "<<maxPhi<<endreq; 
00052     log <<MSG::DEBUG<< " starting granularity Eta: "<<granEta
00053         << " phi: "<<granPhi
00054         <<endreq;
00055 
00056     log <<MSG::DEBUG<<"CalSectionReject parameters:"<<endreq;
00057     log <<MSG::DEBUG<<m_calSectionReject<<endreq;
00058 
00059     int nEta    = int(((maxEta-minEta)/granEta)+0.5);
00060     m_granEta   = (maxEta-minEta)/int(nEta);
00061     m_nPhi      = 1+int(((m_maxPhi-m_minPhi)/granPhi)+0.5);
00062     m_granPhi   = (m_maxPhi-m_minPhi)/double(m_nPhi); 
00063     log <<MSG::DEBUG<< " final granularity Eta: "<<m_granEta
00064         << " phi: "<<m_granPhi
00065         <<endreq; 
00066     log <<MSG::DEBUG<< " final Bins in Eta: "<<nEta
00067         << " phi: "<<m_nPhi
00068         <<endreq; 
00069 
00070     for (int ieta=0; ieta<nEta; ieta++){
00071       for (int iphi=0; iphi<m_nPhi; iphi++){
00072         
00073         double eta        = minEta+((double(ieta)+0.5)*double(m_granEta));
00074         double phi        = m_minPhi + ((double(iphi)+0.5)*double(m_granPhi));
00075         CellDescriptor id = CellDescriptor(eta,phi);
00076         ITwoCptCell* cell = new TwoCptCell(id);
00077         
00078         m_cells.push_back(cell);
00079       }
00080     }
00081   }
00082   CalSection::~CalSection(){
00083     m_log<<MSG::DEBUG<<"CalSection destructor starts "<<endreq;
00084     std::for_each(m_cells.begin(), m_cells.end(), DeleteObject());
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(ITransportedParticleCollectionIter& f, 
00102                            ITransportedParticleCollectionIter& l){
00103     // remove particles not in acceptance
00104     ITransportedParticleCollectionIter divider;
00105     divider = std::partition(f, l, m_calSectionReject);
00106     
00107     // fill cells 
00108     for(ITransportedParticleCollectionCIter i=divider; i<l; ++i){newHit(*i);}
00109 
00110     // assume sections do not overlap: do not reprocess.
00111     l=divider;
00112   }
00113   //----------------------------------------------------------------
00114   void 
00115   CalSection::depositEcal(std::vector<const GridletElement*>::iterator& f, 
00116                           std::vector<const GridletElement*>::iterator& l
00117                           ){
00118     //    cerr<<"Calsection depositEcal begin"<<endl;
00119   
00120     //    cerr<<"  no of elements on entry "<<l-f<<endl;
00121     std::vector<const GridletElement*>::iterator divider;
00122     divider = std::partition(f, l, m_calSectionReject);
00123     //    cerr<<"Calsection depositEcal after partition"<<endl;
00124   
00125     std::vector<const GridletElement*>::iterator i;
00126     for( i=divider; i<l; ++i){newEHit(*i);}
00127     //    cerr<<"Calsection depositEcal after newhit call"<<endl;
00128   
00129 
00130     // assume sections do not overlap: do not reprocess.
00131     l=divider;
00132     //    cerr<<"  no of elements on exit "<<l-f<<endl;
00133     //    cerr<<"Calsection depositEcal end"<<endl;
00134   }
00135   //----------------------------------------------------------------
00136   void CalSection::depositHcal(std::vector<const GridletElement*>::iterator& f, 
00137                                std::vector<const GridletElement*>::iterator& l
00138                                ){
00139     
00140     std::vector<const GridletElement*>::iterator divider;
00141     divider = std::partition(f, l, m_calSectionReject);
00142   
00143     std::vector<const GridletElement*>::iterator i;
00144     for( i=divider; i<l; ++i){newHHit(*i);}
00145 
00146     // assume sections do not overlap: do not reprocess.
00147     l=divider;
00148   }
00149   //----------------------------------------------------------------
00150   void CalSection::depositEgen(std::vector<const Gridlet*>::iterator& f, 
00151                                std::vector<const Gridlet*>::iterator& l
00152                                ){
00153     std::vector<const Gridlet*>::iterator divider;
00154     divider = std::partition(f, l, m_calSectionReject);
00155     
00156     
00157     std::vector<const Gridlet*>::iterator i;
00158     for( i=divider; i<l; ++i){setEgen(*i);}
00159     
00160     // assume sections do not overlap: do not reprocess.
00161     l=divider;
00162   }
00163   
00164   //----------------------------------------------------------------
00165   void CalSection::newHit( const ITransportedParticle* tp){
00166     //check cell is reasonable
00167     const HepMC::GenParticle* particle = tp->particle();
00168     //const double eta = particle->momentum().pseudoRapidity();
00169     const double eta = tp->eta();
00170     const double phi = tp->phi();
00171     int ind = iindex(phi, eta);
00172     ITwoCptCell* cell = m_cells[ind];
00173     assert(std::abs( eta-(cell->eta()) ) <m_granEta);
00174     assert(std::abs( phi-(cell->phi()) ) <m_granPhi);
00175     cell->newHit(particle);
00176     //use a map to store pointers to hit cells to avoid
00177     //duplicate entries if the cell is hit more than once.
00178     m_hitCells[ind] = cell;
00179 
00180     return;
00181   }
00182   //----------------------------------------------------------------
00183   void CalSection::newEHit( const GridletElement* ge){
00184     int ind = index(ge);
00185     ITwoCptCell* cell = m_cells[ind];
00186     //    cerr<<"gridletEl, phi, eta, eT:     "
00187     //    <<ge->phi()<<" "<<ge->eta()<<" "<<ge->et()<<endl;
00188     //    cerr<<"cell, phi, eta, granularity: "<<cell->phi()<<" "<<cell->eta()
00189     //  <<" "<<m_granPhi<<" "<<m_granEta<<endl;
00190     assert(std::abs( (ge->eta()-cell->eta()) )<m_granEta);
00191     assert(std::abs( (ge->phi()-cell->phi()) )<m_granPhi);
00192     cell->depositEcal(ge->et());
00193     //use a map to store pointers to hit cells to avoid
00194     //duplicate entries if the cell is hit more than once.
00195     m_hitCells[ind] = cell;
00196 
00197     return;
00198   }
00199   //----------------------------------------------------------------
00200   void CalSection::newHHit( const GridletElement* ge){
00201     int ind = index(ge);
00202     ITwoCptCell* cell = m_cells[ind];
00203 
00204     assert(std::abs( (ge->eta())-(cell->eta()) )<m_granEta);
00205     assert(std::abs( (ge->phi())-(cell->phi()) )<m_granPhi);
00206 
00207     cell->depositHcal(ge->et());
00208     //use a map to store pointers to hit cells to avoid
00209     //duplicate entries if the cell is hit more than once.
00210     m_hitCells[ind] = cell;
00211 
00212     return;
00213   }
00214   //----------------------------------------------------------------
00215   void CalSection::setEgen( const Gridlet* gr){
00216     int ind = index(gr);
00217     ITwoCptCell* cell = m_cells[ind];
00218     cell->addEgen(gr->eGen());
00219     m_hitCells[ind] = cell;
00220     return;
00221   }
00222   //----------------------------------------------------------------
00223   int  CalSection::index(const Gridlet* gr) const{
00224     int ind = this->iindex( gr->phi0(), gr->eta0() );
00225     return ind;
00226   }
00227   //----------------------------------------------------------------
00228   int  CalSection::index(const GridletElement* ge) const{
00229     int ind = this->iindex( ge->phi(), ge->eta() );
00230     return ind;
00231   }
00232   //----------------------------------------------------------------
00233   int  CalSection::index(const ITransportedParticle* tp) const {
00234     const HepMC::GenParticle* particle = tp->particle();
00235     const double eta = particle->momentum().pseudoRapidity();
00236     const double phi = tp->phi();
00237     int ind = iindex(phi, eta);
00238     return ind;
00239   }
00240   //----------------------------------------------------------------
00241   int  CalSection::index(const Atlfast::EPileupDeposit* ep) const{
00242     int ind = iindex(ep->phi(),ep->eta());
00243     return ind;
00244   }
00245   //----------------------------------------------------------------
00246   int CalSection::iindex(double phi, double eta) const{
00247     int iphi = int( (phi-m_minPhi)/m_granPhi );
00248     int ieta = int( (eta-m_minEta)/m_granEta );
00249     
00250     return  (m_nPhi*ieta  + iphi);
00251   }
00252   //----------------------------------------------------------------
00253   // FOR ENERGY PILEUP METHODS
00254   //----------------------------------------------------------------
00255   void CalSection::deposit(std::vector<Atlfast::EPileupDeposit*>::iterator& f, 
00256                            std::vector<Atlfast::EPileupDeposit*>::iterator& l){
00257     // remove pileup deposits not in acceptance
00258     std::vector<Atlfast::EPileupDeposit*>::iterator divider;
00259     divider = std::partition(f, l, m_calSectionReject);
00260 
00261     // fill cells 
00262     std::vector<Atlfast::EPileupDeposit*>::iterator  i=divider;
00263     for(; i<l; ++i) newHit(*i);
00264 
00265     // assume sections do not overlap: do not reprocess.
00266     // hits processed here: set last to end of unprocessed hits
00267     l=divider;
00268   }
00269 
00270   //----------------------------------------------------------------
00271   void CalSection::newHit( const Atlfast::EPileupDeposit* ep){
00272     //check cell is reasonable
00273     int ind = index(ep);
00274     ITwoCptCell* cell = m_cells[ind];
00275     assert(std::abs( (ep->eta()) - (cell->eta()) )<m_granEta);
00276     assert(std::abs( (ep->phi()) - (cell->phi()) )<m_granPhi);
00277     cell->newHit(ep);
00278      //use a map to store pointers to hit cells to avoid
00279     //duplicate entries if the cell is hit more than once.
00280     m_hitCells[ind] = cell;
00281     return;
00282   }
00283   //===========================================================================
00284   void CalSection::giveHits
00285     (const ICellSelector* p_cellselect, ITwoCptCellCollection* cells) const{
00286     std::map<int, ITwoCptCell*, std::less<int> >::const_iterator i;
00287     for(i=m_hitCells.begin(); i!=m_hitCells.end(); ++i){
00288       //test cell before newing and filling vector
00289       if( (*p_cellselect) (((*i).second))){ 
00290         ITwoCptCell* cell = ((*i).second)->cloneITCC();
00291       //Need to copy cells because Athena deletes container AND POINTERS
00292       // AND POINTEES
00293         cells->push_back(cell);
00294       }
00295     }
00296 
00297   }
00298   //===========================================================================
00299   void CalSection::smearCells
00300     (ISmearer* p_smearer) {
00301     std::map<int, ITwoCptCell*, std::less<int> >::const_iterator i;
00302     for(i=m_hitCells.begin(); i!=m_hitCells.end(); ++i){
00303       if((*((*i).second)).momentum().e() > 0){
00304         HepLorentzVector temp = p_smearer->smear((*((*i).second)).momentum());
00305           (*((*i).second)).setPt(temp);
00306       }
00307     }
00308   }
00309 
00310 
00311 
00312   void CalSection::reset(){
00313     //reset the cells of this CalSection
00314 
00315     std::map<int, ITwoCptCell*>::const_iterator i = m_hitCells.begin();
00316     for(;i!=m_hitCells.end();++i) (*i).second->resetCell();
00317     m_hitCells.erase(m_hitCells.begin(), m_hitCells.end());
00318   }
00319 }
00320 
00321     
00322     
00323   
00324 
00325 
00326 
00327 
00328 
00329 
00330 
00331 

Generated on Mon Sep 24 14:19:11 2007 for AtlfastAlgs by  doxygen 1.5.1