00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "AtlfastAlgs/CellMaker.h"
00012 #include "AtlfastAlgs/CellsAboveThreshold.h"
00013 #include "AtlfastEvent/ITransportedParticleFactory.h"
00014 #include "AtlfastAlgs/Calorimeter.h"
00015 #include "AtlfastAlgs/ICellSelector.h"
00016 #include "AtlfastAlgs/ISmearer.h"
00017 #include "AtlfastAlgs/CellSmearer.h"
00018 #include "AtlfastAlgs/GlobalEventData.h"
00019 #include "AtlfastAlgs/EPileupMap.h"
00020 #include "AtlfastAlgs/containerDelete.h"
00021 #include "AtlfastEvent/CollectionDefs.h"
00022
00023 #include "AtlfastUtils/TesIO.h"
00024 #include "AtlfastUtils/HeaderPrinter.h"
00025
00026 #include <cmath>
00027 #include <iomanip>
00028 #include <vector>
00029
00030 #include "GaudiKernel/DataSvc.h"
00031 #include "GaudiKernel/Chrono.h"
00032 #include "GaudiKernel/ISvcLocator.h"
00033 #include "GaudiKernel/MsgStream.h"
00034
00035 #include "CLHEP/Units/SystemOfUnits.h"
00036 #include "NavFourMom/INavigable4MomentumCollection.h"
00037
00038 namespace Atlfast {
00039 CellMaker:: CellMaker(const std::string& name, ISvcLocator* pSvcLocator):
00040 Algorithm(name,pSvcLocator),
00041 m_calorimeter(0),
00042 m_cellSelector(0),
00043 m_mcSelector(0),
00044 m_epileupMap(0),
00045 m_smearer(0),
00046 m_tesIO(0),
00047 m_log( messageService(), name )
00048 {
00049
00050
00051 m_outputLocation = "/Event/AtlfastCells" ;
00052 m_outputLocation_IN4M = "/Event/AtlfastCellsIN4M";
00053
00054
00055 m_etaCoverage = 5.0;
00056 m_minETCell = 0.0*GeV;
00057 m_granBarrelEta = 0.1;
00058 m_granBarrelPhi = 0.1;
00059 m_granForwardEta = 0.2;
00060 m_granForwardPhi = 0.2;
00063 m_doSmearing = false;
00064 m_fastShower = false;
00065
00066 declareProperty("OutputLocation", m_outputLocation);
00067 declareProperty("OutputLocationIN4M", m_outputLocation_IN4M);
00068 declareProperty("EtaCoverage", m_etaCoverage);
00069 declareProperty("MinETCell", m_minETCell);
00070 declareProperty("GranBarrelEta", m_granBarrelEta);
00071 declareProperty("GranBarrelPhi", m_granBarrelPhi);
00072 declareProperty("GranForwardEta", m_granForwardEta);
00073 declareProperty("GranForwardPhi", m_granForwardPhi);
00075 declareProperty("DoSmearing", m_doSmearing);
00076 declareProperty("FastShower", m_fastShower);
00077
00078 }
00079
00080
00081 CellMaker::~CellMaker(){
00082
00083 m_log<<MSG::DEBUG<<"CellMaker destructor starts "<<endreq;
00084
00085 m_log<<MSG::DEBUG<<"Deleting Calorimeter "<<endreq;
00086 if (m_calorimeter) delete m_calorimeter;
00087
00088 m_log<<MSG::DEBUG<<"Deleting TesIO "<<endreq;
00089 if (m_tesIO) delete m_tesIO;
00090
00091 m_log<<MSG::DEBUG<<"Deleting Cell Selector "<<endreq;
00092 if (m_cellSelector) delete m_cellSelector;
00093
00094 if (m_epileupMap) delete m_epileupMap;
00095 if (m_smearer) delete m_smearer;
00096
00097 m_log<<MSG::DEBUG<<"CellMaker destructor ends "<<endreq;
00098 }
00099
00100 StatusCode CellMaker::initialize()
00101 {
00102
00103
00104
00105
00106 m_cellSelector = new CellsAboveThreshold(m_minETCell);
00107
00108
00109
00110 GlobalEventData* ged = GlobalEventData::Instance();
00111 m_fieldOn = ged -> fieldOn();
00112 m_mcSelector = ged -> visibleToCal();
00113 m_barrelForwardEta = ged -> barrelForwardEta();
00114 m_mcLocation = ged -> mcLocation();
00115 m_monopoleIDs = ged -> monopoleIDs();
00116
00117
00118 m_tesIO = new TesIO(m_mcLocation, ged->justHardScatter());
00119
00120
00121 if (fabs(m_etaCoverage) < fabs(m_barrelForwardEta) ) {
00122 m_log << MSG::ERROR
00123 << "asked to makecalo with max extent "
00124 << m_etaCoverage
00125 << "but barrel-forward boundary at "
00126 << m_barrelForwardEta << endreq;
00127 return StatusCode::FAILURE;
00128 }
00129 m_calorimeter = new Calorimeter(
00130 m_log,
00131 m_fastShower,
00132 m_etaCoverage,
00133 m_barrelForwardEta,
00134 m_granBarrelEta,
00135 m_granBarrelPhi,
00136 m_granForwardEta,
00137 m_granForwardPhi
00138 );
00142 if(m_doSmearing == true){
00143 m_epileupMap = new EPileupMap(ged->lumi());
00144 m_smearer = new CellSmearer(ged->randSeed(),m_barrelForwardEta);
00145 }else{
00146 m_epileupMap = NULL;
00147 m_smearer = NULL;
00148 }
00149
00150 HeaderPrinter hp("Atlfast Cell Maker:", m_log);
00151
00152 hp.add("Min Cell ET ", m_minETCell);
00153 hp.add("Magnetic Field is on? ", m_fieldOn);
00154 hp.add("MC Input Location ", m_mcLocation);
00155 hp.add("Output Location ", m_outputLocation);
00156 hp.add("INavigable4Momentum Output Location ", m_outputLocation_IN4M);
00157 hp.add("DoSmearing ", m_doSmearing);
00158 hp.add("Run FastShower ", m_fastShower);
00159 hp.add("Calorimeter Geometry: ");
00160 hp.add("Total Eta Range ", m_etaCoverage);
00161 hp.add("Barrel Eta Range ", m_barrelForwardEta);
00162 hp.add("Barrel Eta Granularity ", m_granBarrelEta);
00163 hp.add("Barrel Phi Granularity ", m_granBarrelPhi);
00164 hp.add("Forward Eta Granularity ", m_granForwardEta);
00165 hp.add("Forward Phi Granularity ", m_granForwardPhi);
00166 hp.print();
00167
00168
00169
00170 return StatusCode::SUCCESS;
00171 }
00172
00173 StatusCode CellMaker::finalize()
00174 {
00175
00176 m_log<<MSG::INFO<<"Finalizing"<<endreq;
00177 return StatusCode::SUCCESS;
00178 }
00179
00180
00181 StatusCode CellMaker::execute()
00182 {
00183
00184
00185 m_log << MSG::DEBUG << "CellMaker execute()" << endreq;
00186
00187 ITransportedParticleCollection particlesAtCal;
00188 deflectParticles(particlesAtCal);
00189
00190
00191 ITransportedParticleCollectionIter fpart = particlesAtCal.begin();
00192 ITransportedParticleCollectionIter lpart = particlesAtCal.end();
00193 m_calorimeter->deposit(fpart, lpart);
00194
00195
00196 containerDelete(particlesAtCal.begin(), particlesAtCal.end());
00197
00198
00199
00200 if(m_doSmearing){
00201
00202
00203 m_calorimeter->smearCells(m_smearer);
00204 m_log << MSG::DEBUG << "Doing Smearing" << endreq;
00205
00207 m_epileupMap->fillMap();
00208 m_log << MSG::DEBUG
00209 << "Size of EM EPileup vector: "
00210 << m_epileupMap->getEMMap()->size()
00211 << endreq;
00212 std::vector<Atlfast::EPileupDeposit*>::iterator fdep =
00213 m_epileupMap->getEMMap()->begin();
00214 std::vector<Atlfast::EPileupDeposit*>::iterator ldep =
00215 m_epileupMap->getEMMap()->end();
00216
00218 m_calorimeter->deposit(fdep, ldep);
00219 m_log << MSG::DEBUG << "ECAL pileup deposited" << endreq;
00220 m_log << MSG::DEBUG << "Size of HAD EPileup vector: "
00221 << m_epileupMap->getHadMap()->size()
00222 << endreq;
00223 fdep = m_epileupMap->getHadMap()->begin();
00224 ldep = m_epileupMap->getHadMap()->end();
00225
00227 m_calorimeter->deposit(fdep, ldep);
00228 m_log << MSG::DEBUG << "HCAL pileup deposited" << endreq;
00229 }
00230
00231 m_log << MSG::DEBUG << "deposit" << endreq;
00232
00233
00234
00235
00236
00237 ITwoCptCellCollection* cells = new ITwoCptCellCollection;
00238
00239 INavigable4MomentumCollection *cells_IN4M =
00240 new INavigable4MomentumCollection(SG::VIEW_ELEMENTS);
00241
00242
00243
00246 m_calorimeter->giveHitCells(m_cellSelector, cells);
00247 m_log << MSG::DEBUG << "hit cells retrieved, " << cells->size()
00248 << " cells were hit this event " << endreq;
00249
00250
00251 ITwoCptCellCollection::const_iterator cellItr = cells->begin();
00252 for (;cellItr != cells->end(); ++cellItr){
00253 INavigable4Momentum *cell_IN4M = *cellItr;
00254 cells_IN4M->push_back(cell_IN4M);
00255 }
00256
00257
00258 m_calorimeter->reset();
00259 m_log << MSG::DEBUG << "calorimeter reset" << endreq;
00260
00261
00262 TesIoStat stat = m_tesIO->store(cells, m_outputLocation );
00263 std::string mess = stat ? "Stored cells in TES":"Failed store cells in TES";
00264 m_log << MSG::DEBUG << mess << endreq;
00265
00266 stat = m_tesIO->store(cells_IN4M, m_outputLocation_IN4M );
00267 if (stat) m_log << MSG::DEBUG << "Stored cells in TES as INavigable4MomentumCollection" << endreq;
00268 else m_log << MSG::ERROR << "Failed to store cells in TES as INavigable4MomentumCollection" << endreq;
00269
00270 return stat;
00271
00272 }
00273
00274 void CellMaker::deflectParticles(ITransportedParticleCollection &itpc){
00275
00276 m_log << MSG::DEBUG << "CellMaker deflectParticles()" << endreq;
00277
00278
00279 MCparticleCollection p;
00280 TesIoStat stat = m_tesIO->getMC( p, m_mcSelector ) ;
00281 std::string mess;
00282 mess = stat? "Retrieved MC from TES ":"Failed MC retrieve from TES ";
00283 m_log << MSG::DEBUG << mess << p.size()<<endreq;
00284
00285 MCparticleCollectionCIter ip= p.begin();
00286 for(; ip<p.end(); ++ip){
00287
00288
00289 ITransportedParticle *itp = ITransportedParticleFactory::create(*ip,m_monopoleIDs);
00290 itp->deflect();
00291 itpc.push_back(itp);
00292
00293 }
00294
00295 return;
00296
00297 }
00298
00299
00300 }
00301
00302
00303
00304
00305
00306
00307