00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "AtlfastAlgs/FinalStateParticleHistogramMaker.h"
00010
00011 #include <cmath>
00012 #include <algorithm>
00013 #include <iomanip>
00014 #include <float.h>
00015
00016
00017 #include "GaudiKernel/DataSvc.h"
00018 #include "GaudiKernel/IHistogramSvc.h"
00019
00020
00021 #include "CLHEP/Units/SystemOfUnits.h"
00022
00023
00024
00025
00026
00027 namespace Atlfast {
00028 using std::vector;
00029 using std::cout;
00030 using std::endl;
00031 using std::ios;
00032
00033
00034
00035
00036
00037 void FillHistograms::operator()(pair< string, HepMC_helper::MCselectorWrapper*> &pairPtr){
00038
00039
00040
00041
00042 string identifier = pairPtr.first;
00043 HepMC_helper::MCselectorWrapper* wrapperPtr = pairPtr.second;
00044
00045 MCparticleCollection mcParticles;
00046 const HepMC_helper::IMCselector* imcSelector =
00047 wrapperPtr->asIMCselector();
00048 TesIoStat stat = m_tesIO->getMC( mcParticles, imcSelector) ;
00049 if (!stat){
00050
00051 m_log << MSG::DEBUG << "Problem in getMC using " << identifier << " selectors" << endreq;
00052 }
00053
00054 m_log << MSG::DEBUG << mcParticles.size() << " GenParticles selected with "
00055 << identifier << " selectors" << endreq;
00056
00057 Fill(mcParticles,identifier);
00058
00059 }
00060
00061 void FillHistograms::Fill(MCparticleCollection &mcParticles, string &identifier){
00062
00063
00064
00065
00066
00067
00068
00069 m_histogramContainer[identifier].at(0)->fill(float(mcParticles.size()),1.0);
00070
00071 float sumE = 0., sumPx = 0., sumPy = 0., sumPz = 0.;
00072
00073 MCparticleCollection::const_iterator genItr = mcParticles.begin();
00074 for (;genItr!=mcParticles.end();++genItr){
00075
00076
00077 m_histogramContainer[identifier].at(1)->fill((*genItr)->momentum().e(),1.0);
00078 m_histogramContainer[identifier].at(2)->fill((*genItr)->momentum().px(),1.0);
00079 m_histogramContainer[identifier].at(3)->fill((*genItr)->momentum().py(),1.0);
00080 m_histogramContainer[identifier].at(4)->fill((*genItr)->momentum().pz(),1.0);
00081
00082
00083 sumE += (*genItr)->momentum().e();
00084 sumPx += (*genItr)->momentum().px();
00085 sumPy += (*genItr)->momentum().py();
00086 sumPz += (*genItr)->momentum().pz();
00087
00088 }
00089
00090
00091 m_histogramContainer[identifier].at(5)->fill(sumE,1.0);
00092 m_histogramContainer[identifier].at(6)->fill(sumPx,1.0);
00093 m_histogramContainer[identifier].at(7)->fill(sumPy,1.0);
00094 m_histogramContainer[identifier].at(8)->fill(sumPz,1.0);
00095
00096 return;
00097
00098 }
00099
00100
00101
00102
00103
00104 FinalStateParticleHistogramMaker::FinalStateParticleHistogramMaker
00105 ( const std::string& name, ISvcLocator* pSvcLocator )
00106 : Algorithm( name, pSvcLocator ){
00107
00108
00109
00110 m_inputLocation = "/Event/McEventCollection";
00111
00112 declareProperty( "InputLocation", m_inputLocation ) ;
00113
00114 SetHistogramLimits();
00115
00116 }
00117
00118
00119 FinalStateParticleHistogramMaker::~FinalStateParticleHistogramMaker() {}
00120
00121 void FinalStateParticleHistogramMaker::PutIntoContainer(std::string &identifier,
00122 HepMC_helper::MCselectorWrapper* wrapper){
00123 std::pair<string,HepMC_helper::MCselectorWrapper*> thePair;
00124 thePair.first = identifier;
00125 thePair.second = wrapper;
00126 m_selectorContainer.push_back(thePair);
00127 return;
00128 }
00129
00130
00131
00132
00133
00134 StatusCode FinalStateParticleHistogramMaker::initialize()
00135 {
00136
00137 MsgStream log( messageService(), name() ) ;
00138 log << MSG::DEBUG << "Initialising" << endreq;
00139
00140 string identifier;
00141 HepMC_helper::MCselectorWrapper* wrapper = 0;
00142
00143
00144 GlobalEventData* ged = GlobalEventData::Instance();
00145
00146 AllSelectorSetups(identifier,wrapper);
00147 Z0SelectorSetups(identifier,wrapper);
00148 VisibleToCalSelectorSetups(identifier,wrapper,ged);
00149 InvisibleToAtlasSelectorSetups(identifier,wrapper,ged);
00150 IsFinalStateSelectorSetups(identifier,wrapper);
00151 BSelectorSetups(identifier,wrapper);
00152 ElectronSelectorSetups(identifier,wrapper);
00153 PhotonSelectorSetups(identifier,wrapper);
00154 MuonSelectorSetups(identifier,wrapper);
00155
00156 m_mcLocation = ged -> mcLocation();
00157 m_tesIO = new TesIO(m_mcLocation, ged->justHardScatter());
00158
00159 return StatusCode::SUCCESS ;
00160
00161 }
00162
00163 void FinalStateParticleHistogramMaker::SetHistogramLimits(){
00164
00165 declareProperty("MultiplicityBins", m_multBins = 100);
00166 declareProperty("MultiplicityLow", m_multLow = 0.);
00167 declareProperty("MultiplicityHigh", m_multHigh = 1000.);
00168
00169 declareProperty("EnergyBins", m_eBins = 100);
00170 declareProperty("EnergyLow", m_eLow = 0.);
00171 declareProperty("EnergyHigh", m_eHigh = 50.*GeV);
00172 declareProperty("PxBins", m_pxBins = 100);
00173 declareProperty("PxLow", m_pxLow = -20.*GeV);
00174 declareProperty("PxHigh", m_pxHigh = 20.*GeV);
00175 declareProperty("PyBins", m_pyBins = 100);
00176 declareProperty("PyLow", m_pyLow = -20.*GeV);
00177 declareProperty("PyHigh", m_pyHigh = 20.*GeV);
00178 declareProperty("PzBins", m_pzBins = 100);
00179 declareProperty("PzLow", m_pzLow = -20.*GeV);
00180 declareProperty("PzHigh", m_pzHigh = 20.*GeV);
00181
00182 declareProperty("EnergySumBins", m_eSumBins = 100);
00183 declareProperty("EnergySumLow", m_eSumLow = 13000.*GeV);
00184 declareProperty("EnergySumHigh", m_eSumHigh = 15000.*GeV);
00185 declareProperty("PxSumBins", m_pxSumBins = 100);
00186 declareProperty("PxSumLow", m_pxSumLow = -2.*GeV);
00187 declareProperty("PxSumHigh", m_pxSumHigh = 2.*GeV);
00188 declareProperty("PySumBins", m_pySumBins = 100);
00189 declareProperty("PySumLow", m_pySumLow = -2.*GeV);
00190 declareProperty("PySumHigh", m_pySumHigh = 2.*GeV);
00191 declareProperty("PzSumBins", m_pzSumBins = 100);
00192 declareProperty("PzSumLow", m_pzSumLow = -2.*GeV);
00193 declareProperty("PzSumHigh", m_pzSumHigh = 2.*GeV);
00194
00195 return;
00196
00197 }
00198
00199 void FinalStateParticleHistogramMaker::AllSelectorSetups(string &identifier,
00200 HepMC_helper::MCselectorWrapper* wrapper){
00201 identifier = "all";
00202 wrapper = new HepMC_helper::MCselectorWrapper( new HepMC_helper::All() ) ;
00203 BookHistograms(identifier);
00204 PutIntoContainer(identifier,wrapper);
00205 return;
00206
00207 }
00208
00209 void FinalStateParticleHistogramMaker::Z0SelectorSetups(string &identifier,
00210 HepMC_helper::MCselectorWrapper* wrapper){
00211
00212 identifier = "z0selector";
00213 wrapper = new HepMC_helper::MCselectorWrapper( new HepMC_helper::SelectZ0(0.0, FLT_MAX));
00214 BookHistograms(identifier);
00215 PutIntoContainer(identifier,wrapper);
00216 return;
00217
00218 }
00219
00220 void FinalStateParticleHistogramMaker::VisibleToCalSelectorSetups(string &identifier,
00221 HepMC_helper::MCselectorWrapper* wrapper,
00222 GlobalEventData* ged){
00223
00224
00225
00226 identifier = "visibleToCal";
00227 wrapper = new HepMC_helper::MCselectorWrapper(ged -> visibleToCal());
00228 BookHistograms(identifier);
00229 PutIntoContainer(identifier,wrapper);
00230 return;
00231
00232 }
00233
00234 void FinalStateParticleHistogramMaker::InvisibleToAtlasSelectorSetups(string &identifier,
00235 HepMC_helper::MCselectorWrapper* wrapper,
00236 GlobalEventData* ged){
00237
00238
00239
00240 identifier = "invisibleToAtlas";
00241 wrapper = new HepMC_helper::MCselectorWrapper(ged -> visibleToAtlas());
00242 BookHistograms(identifier);
00243 PutIntoContainer(identifier,wrapper);
00244 return;
00245
00246 }
00247
00248 void FinalStateParticleHistogramMaker::IsFinalStateSelectorSetups(string &identifier,
00249 HepMC_helper::MCselectorWrapper* wrapper){
00250 identifier = "isFinalState";
00251 wrapper = new HepMC_helper::MCselectorWrapper(new HepMC_helper::IsFinalState() );
00252 BookHistograms(identifier);
00253 PutIntoContainer(identifier,wrapper);
00254 return;
00255
00256 }
00257
00258 void FinalStateParticleHistogramMaker::BSelectorSetups(string &identifier,
00259 HepMC_helper::MCselectorWrapper* wrapper){
00260
00261 identifier = "bSelector";
00262 wrapper =
00263 new HepMC_helper::MCselectorWrapper( new HepMC_helper::SelectJetTag (ParticleCodes::BQUARK,
00264 5.0*GeV,
00265 2.5));
00266 BookHistograms(identifier);
00267 PutIntoContainer(identifier,wrapper);
00268 return;
00269
00270 }
00271
00272 void FinalStateParticleHistogramMaker::ElectronSelectorSetups(string &identifier,
00273 HepMC_helper::MCselectorWrapper* wrapper){
00274
00275
00276
00277 identifier = "electronSelector";
00278 DefaultReconstructedParticleSelectorSetups(wrapper,11,0.0*GeV,100.0);
00279 BookHistograms(identifier);
00280 PutIntoContainer(identifier,wrapper);
00281 return;
00282
00283 }
00284
00285 void FinalStateParticleHistogramMaker::PhotonSelectorSetups(string &identifier,
00286 HepMC_helper::MCselectorWrapper* wrapper){
00287
00288
00289
00290 identifier = "photonSelector";
00291 DefaultReconstructedParticleSelectorSetups(wrapper,22,0.0*GeV,100.0);
00292 BookHistograms(identifier);
00293 PutIntoContainer(identifier,wrapper);
00294 return;
00295
00296 }
00297
00298 void FinalStateParticleHistogramMaker::MuonSelectorSetups(string &identifier,
00299 HepMC_helper::MCselectorWrapper* wrapper){
00300
00301
00302
00303 identifier = "muonSelector";
00304 DefaultReconstructedParticleSelectorSetups(wrapper,13,0.5*GeV,100.0);
00305 BookHistograms(identifier);
00306 PutIntoContainer(identifier,wrapper);
00307 return;
00308
00309 }
00310
00311 void FinalStateParticleHistogramMaker::DefaultReconstructedParticleSelectorSetups
00312 (HepMC_helper::MCselectorWrapper* &wrapper, int particleType, double ptMin, double etaMax){
00313
00314
00315
00316 HepMC_helper::IMCselector* typeSelector =
00317 new HepMC_helper::SelectType(particleType);
00318 HepMC_helper::IMCselector* kineSelector =
00319 new HepMC_helper::MCCuts(ptMin, etaMax);
00320 HepMC_helper::IMCselector* fstaSelector =
00321 new HepMC_helper::IsFinalState();
00322
00323 vector<HepMC_helper::IMCselector*> selectors;
00324 selectors.push_back(fstaSelector);
00325 selectors.push_back(typeSelector);
00326 selectors.push_back(kineSelector);
00327
00328 HepMC_helper::NCutter* ncutter = new HepMC_helper::NCutter(selectors);
00329 wrapper = new HepMC_helper::MCselectorWrapper(ncutter);
00330
00331 delete typeSelector;
00332 delete kineSelector;
00333 delete fstaSelector;
00334 return;
00335
00336 }
00337
00338 void FinalStateParticleHistogramMaker::BookHistograms(string &id){
00339
00340 int nHistAll = 0;
00341 vector<IHistogram1D*> &hists = m_histogramContainer[id];
00342 string path = "/stat/finalstate_"+id+"/";
00343 string of = " of GenParticles from '"+id+"' selectors";
00344
00345 hists.push_back(histoSvc()->book(path,++nHistAll,"Multiplicity"+of,m_multBins,m_multLow,m_multHigh));
00346 hists.push_back(histoSvc()->book(path,++nHistAll,"Energy"+of,m_eBins,m_eLow,m_eHigh));
00347 hists.push_back(histoSvc()->book(path,++nHistAll,"px"+of,m_pxBins,m_pxLow,m_pxHigh));
00348 hists.push_back(histoSvc()->book(path,++nHistAll,"py"+of,m_pyBins,m_pyLow,m_pyHigh));
00349 hists.push_back(histoSvc()->book(path,++nHistAll,"pz"+of,m_pzBins,m_pzLow,m_pzHigh));
00350 hists.push_back(histoSvc()->book(path,++nHistAll,"Energy sum"+of,m_eSumBins,m_eSumLow,m_eSumHigh));
00351 hists.push_back(histoSvc()->book(path,++nHistAll,"px sum"+of,m_pxSumBins,m_pxSumLow,m_pxSumHigh));
00352 hists.push_back(histoSvc()->book(path,++nHistAll,"py sum"+of,m_pySumBins,m_pySumLow,m_pySumHigh));
00353 hists.push_back(histoSvc()->book(path,++nHistAll,"pz sum"+of,m_pzSumBins,m_pzSumLow,m_pzSumHigh));
00354
00355 return;
00356
00357 }
00358
00359
00360
00361
00362
00363 StatusCode FinalStateParticleHistogramMaker::finalize()
00364 {
00365
00366
00367 return StatusCode::SUCCESS ;
00368 }
00369
00370
00371
00372
00373
00374
00375
00376 StatusCode FinalStateParticleHistogramMaker::execute( )
00377 {
00378
00379
00380
00381 MsgStream log( messageService(), name() ) ;
00382 log << MSG::DEBUG << "Executing" << endreq;
00383
00384
00385
00386
00387
00388
00389
00390
00391 std::for_each( m_selectorContainer.begin(),
00392 m_selectorContainer.end(),
00393 FillHistograms(m_tesIO,log,m_histogramContainer) );
00394
00395 return StatusCode::SUCCESS;
00396 }
00397
00398 }