00001
00002
00003
00004
00005
00006
00007
00008
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
00095 TransportedParticleCollectionIter divider;
00096 divider = std::partition(f, l, m_calSectionReject);
00097
00098
00099 TransportedParticleCollectionCIter i=divider;
00100 for(; i<l; ++i) newHit(i);
00101
00102
00103
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
00112
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
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
00124
00125 m_hitCells[index] = cell;
00126
00127 return;
00128 }
00129
00130
00131
00132
00133 void CalSection::deposit(std::vector<Atlfast::EPileupDeposit*>::iterator& f,
00134 std::vector<Atlfast::EPileupDeposit*>::iterator& l){
00135
00136 std::vector<Atlfast::EPileupDeposit*>::iterator divider;
00137 divider = std::partition(f, l, m_calSectionReject);
00138
00139
00140 std::vector<Atlfast::EPileupDeposit*>::iterator i=divider;
00141 for(; i<l; ++i) newHit(i);
00142
00143
00144
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
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
00161
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
00171 if( (*p_cellselect) (((*i).second))){
00172 Cell* cell = new Cell(*((*i).second));
00173
00174
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
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