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/Cell.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 "CLHEP/Vector/LorentzVector.h"
00028 namespace Atlfast {
00029 
00030 //____________________________________________________________________
00031   CalSection::CalSection(
00032                          MsgStream& log,
00033                          double minEta,
00034                          double maxEta,
00035                          double granEta,
00036                          double granPhi,
00037                          double minPhi,
00038                          double maxPhi
00039                          ):
00040   m_minEta(minEta), m_maxEta(maxEta),
00041   m_minPhi(minPhi), m_maxPhi(maxPhi),
00042   m_calSectionReject(minEta, maxEta, minPhi, maxPhi)
00043   {
00044     log <<MSG::DEBUG<< "CalSection: construction. Eta range: "
00045         <<minEta<<" - "<<maxEta<<endreq; 
00046     log <<MSG::DEBUG<< "                          Phi range: "
00047         <<minPhi<<" - "<<maxPhi<<endreq; 
00048     log <<MSG::DEBUG<< " starting granularity Eta: "<<granEta
00049         << " phi: "<<granPhi
00050         <<endreq;
00051 
00052     log <<MSG::DEBUG<<"CalSectionReject parameters:"<<endreq;
00053     log <<MSG::DEBUG<<m_calSectionReject<<endreq;
00054 
00055     int nEta    = int(((maxEta-minEta)/granEta)+0.5);
00056     m_granEta   = (maxEta-minEta)/int(nEta);
00057     m_nPhi      = 1+int(((m_maxPhi-m_minPhi)/granPhi)+0.5);
00058     m_granPhi   = (m_maxPhi-m_minPhi)/double(m_nPhi); 
00059     log <<MSG::DEBUG<< " final granularity Eta: "<<m_granEta
00060         << " phi: "<<m_granPhi
00061         <<endreq; 
00062     log <<MSG::DEBUG<< " final Bins in Eta: "<<nEta
00063         << " phi: "<<m_nPhi
00064         <<endreq; 
00065 
00066     for (int ieta=0; ieta<nEta; ieta++){
00067       for (int iphi=0; iphi<m_nPhi; iphi++){
00068         
00069         double eta        = minEta+((double(ieta)+0.5)*double(m_granEta));
00070         double phi        = m_minPhi + ((double(iphi)+0.5)*double(m_granPhi));
00071         CellDescriptor id = CellDescriptor(eta,phi);
00072         Cell* cell        = new Cell(id);
00073         
00074         m_cells.push_back(cell);
00075       }
00076     } 
00077   }
00078   CalSection::~CalSection(){
00079     std::vector<Cell*>::iterator i=m_cells.begin();
00080     for(;i<m_cells.end();++i) delete *i;
00081   }
00082   CalSection::CalSection(const CalSection& c):
00083     m_minEta(c.m_minEta),
00084     m_maxEta(c.m_maxEta),
00085     m_minPhi(c.m_minPhi),
00086     m_maxPhi(c.m_maxPhi),
00087     m_calSectionReject(c.m_calSectionReject){
00088     std::vector<Cell*>::const_iterator i=c.m_cells.begin();
00089     for(;i<c.m_cells.end();++i) m_cells.push_back(new Cell(*(*i)));
00090   }
00091   //----------------------------------------------------------------
00092   void CalSection::deposit(TransportedParticleCollectionIter& f, 
00093                            TransportedParticleCollectionIter& l){
00094     // remove particles not in acceptance
00095     TransportedParticleCollectionIter divider;
00096     divider = std::partition(f, l, m_calSectionReject);
00097 
00098     // fill cells 
00099     TransportedParticleCollectionCIter i=divider;
00100     for(; i<l; ++i) newHit(i);
00101 
00102     // assume sections do not overlap: do not reprocess.
00103     // hits processed here: set last to end of unprocessed hits
00104     l=divider;
00105   }
00106   //----------------------------------------------------------------
00107   void CalSection::newHit( const TransportedParticleCollectionCIter& tpPtr){
00108     const HepMC::GenParticle* particle = (*tpPtr)->particle();
00109     const double eta = particle->momentum().pseudoRapidity();
00110     const double phi = (*tpPtr)->phi();
00111     //    if(eta <= m_minEta || eta > m_maxEta) return;   
00112     //    if(phi <= m_minPhi || phi > m_maxPhi) return false;
00113     
00114     int iphi = int((phi-m_minPhi)/m_granPhi);
00115     int ieta = int((eta-m_minEta)/m_granEta);
00116 
00117     int index = m_nPhi*ieta  + iphi;
00118     //check cell is reasonable
00119     Cell* cell = m_cells[index];
00120     assert(abs(eta-(cell->eta()))<m_granEta);
00121     assert(abs(phi-(cell->phi()))<m_granPhi);
00122     cell->newHit(particle);
00123     //use a map to store pointers to hit cells to avoid
00124     //duplicate entries if the cell is hit more than once.
00125     m_hitCells[index] = cell;
00126 
00127     return;
00128   }
00129 
00130   //----------------------------------------------------------------
00131   // FOR ENERGY PILEUP METHODS
00132   //----------------------------------------------------------------
00133   void CalSection::deposit(std::vector<Atlfast::EPileupDeposit*>::iterator& f, 
00134                            std::vector<Atlfast::EPileupDeposit*>::iterator& l){
00135     // remove pileup deposits not in acceptance
00136     std::vector<Atlfast::EPileupDeposit*>::iterator divider;
00137     divider = std::partition(f, l, m_calSectionReject);
00138 
00139     // fill cells 
00140     std::vector<Atlfast::EPileupDeposit*>::iterator  i=divider;
00141     for(; i<l; ++i) newHit(i);
00142 
00143     // assume sections do not overlap: do not reprocess.
00144     // hits processed here: set last to end of unprocessed hits
00145     l=divider;
00146   }
00147 
00148   //----------------------------------------------------------------
00149   void CalSection::newHit( const std::vector<Atlfast::EPileupDeposit*>::iterator& tpPtr){
00150     const double eta = (*tpPtr)->eta();
00151     const double phi = (*tpPtr)->phi();
00152     int iphi = int((phi-m_minPhi)/m_granPhi);
00153     int ieta = int((eta-m_minEta)/m_granEta);
00154     int index = m_nPhi*ieta  + iphi;
00155     //check cell is reasonable
00156     Cell* cell = m_cells[index];
00157     assert(abs(eta-(cell->eta()))<m_granEta);
00158     assert(abs(phi-(cell->phi()))<m_granPhi);
00159     cell->newHit(*tpPtr);
00160      //use a map to store pointers to hit cells to avoid
00161     //duplicate entries if the cell is hit more than once.
00162     m_hitCells[index] = cell;
00163     return;
00164   }
00165   //=============================================================================
00166   void CalSection::giveHits
00167     (const ICellSelector* p_cellselect, CellCollection* cells) const{
00168     std::map<int, Cell*, std::less<int> >::const_iterator i;
00169     for(i=m_hitCells.begin(); i!=m_hitCells.end(); ++i){
00170       //test cell before newing and filling vector
00171       if( (*p_cellselect) (((*i).second))){ 
00172         Cell* cell = new Cell(*((*i).second));
00173       //Need to copy cells because Athena deletes container AND POINTERS
00174       // AND POINTEES
00175         cells->push_back(cell);
00176       }
00177     }
00178 
00179   }
00180   //=============================================================================
00181   void CalSection::smearCells
00182     (ISmearer* p_smearer) {
00183     std::map<int, Cell*, std::less<int> >::const_iterator i;
00184     for(i=m_hitCells.begin(); i!=m_hitCells.end(); ++i){
00185       if((*((*i).second)).momentum().e() > 0){
00186         HepLorentzVector temp = p_smearer->smear((*((*i).second)).momentum());
00187           (*((*i).second)).setPt(temp);
00188       }
00189     }
00190   }
00191 
00192 
00193 
00194   void CalSection::reset(){
00195     //reset the cells of this CalSection
00196 
00197     std::map<int, Cell*>::const_iterator i = m_hitCells.begin();
00198     for(;i!=m_hitCells.end();++i) (*i).second->resetCell();
00199     m_hitCells.erase(m_hitCells.begin(), m_hitCells.end());
00200   }
00201 }
00202 
00203     
00204     
00205   
00206 
00207 
00208 
00209 
00210 
00211 
00212 
00213 

Generated on Tue Jan 28 09:57:12 2003 for AtlfastAlgs by doxygen1.3-rc1