00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "AtlfastAlgs/FinalStateParticleDumper.h"
00010
00011 #include <cmath>
00012 #include <algorithm>
00013 #include <iomanip.h>
00014 #include <float.h>
00015
00016 #include "GaudiKernel/DataSvc.h"
00017
00018
00019
00020 #include "AtlfastEvent/Cell.h"
00021 #include "AtlfastEvent/CollectionDefs.h"
00022 #include "AtlfastEvent/SimpleKinematic.h"
00023 #include "AtlfastUtils/FunctionObjects.h"
00024 #include "AtlfastEvent/ParticleCodes.h"
00025 #include "AtlfastUtils/HepMC_helper/HepMC_helper.h"
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 namespace Atlfast {
00041 using std::vector;
00042 using std::cout;
00043 using std::endl;
00044 using std::ios;
00045
00046 FinalStateParticleDumper::FinalStateParticleDumper
00047 ( const std::string& name, ISvcLocator* pSvcLocator )
00048 : Algorithm( name, pSvcLocator ){
00049
00050
00051
00052 m_inputLocation = "/Event/McEventCollection";
00053
00054 declareProperty( "InputLocation", m_inputLocation ) ;
00055 declareProperty( "SelectorName", m_selectorName ) ;
00056
00057 }
00058
00059
00060 FinalStateParticleDumper::~FinalStateParticleDumper() {}
00061
00062
00063
00064
00065
00066
00067 StatusCode FinalStateParticleDumper::initialize()
00068 {
00069 MsgStream log( messageService(), name() ) ;
00070 log<<MSG::DEBUG<<"Initialising "<<endreq;
00071
00072
00073 log<< "m_mcSelector set to "<<m_selectorName<<endreq;
00074 if(m_selectorName == "All") {
00075 m_mcSelector =
00076 new HepMC_helper::MCselectorWrapper( new HepMC_helper::All() ) ;
00077 }else if(m_selectorName == "bSelector") {
00078 m_mcSelector =
00079 new HepMC_helper::MCselectorWrapper( new
00080 HepMC_helper::SelectJetTag
00081 (ParticleCodes::BQUARK,
00082 5.0,
00083 2.5))
00084 ;
00085 }else if(m_selectorName == "Z0selector"){
00086 m_mcSelector =
00087 new HepMC_helper::MCselectorWrapper( new
00088 HepMC_helper::SelectZ0(0.0, FLT_MAX)
00089 )
00090 ;
00091 }else if(m_selectorName == "Unseen") {
00092
00093 std::vector<int> requiredTypes;
00094 requiredTypes.push_back(66);
00095 requiredTypes.push_back(ParticleCodes::NU_E);
00096 requiredTypes.push_back(ParticleCodes::NU_MU);
00097 requiredTypes.push_back(ParticleCodes::NU_TAU);
00098
00099 HepMC_helper::IMCselector* unseen =
00100 new HepMC_helper::Unseen(requiredTypes);
00101
00102 HepMC_helper::IMCselector* finalStateSelector =
00103 new HepMC_helper::IsFinalState();
00104
00105 vector<HepMC_helper::IMCselector*> selectors;
00106 selectors.push_back(finalStateSelector);
00107 selectors.push_back(unseen);
00108
00109
00110 HepMC_helper::NCutter* ncutter = new HepMC_helper::NCutter(selectors);
00111 m_mcSelector = new HepMC_helper::MCselectorWrapper(ncutter) ;
00112
00113 delete unseen;
00114 delete finalStateSelector;
00115
00116 }else{
00117 m_mcSelector =
00118 new HepMC_helper::MCselectorWrapper(new HepMC_helper::IsFinalState() ) ;
00119 }
00120
00121 m_tesIO = new TesIO();
00122 return StatusCode::SUCCESS ;
00123 }
00124
00125
00126
00127
00128
00129 StatusCode FinalStateParticleDumper::finalize()
00130 {
00131
00132
00133 return StatusCode::SUCCESS ;
00134 }
00135
00136
00137
00138
00139
00140
00141
00142 StatusCode FinalStateParticleDumper::execute( )
00143 {
00144
00145
00146
00147 MsgStream log( messageService(), name() ) ;
00148 log<<MSG::DEBUG<<"Executing "<<endreq;
00149 std::string mess;
00150
00151
00152 MCparticleCollection mcParticles ;
00153 const HepMC_helper::IMCselector* imcSelector =
00154 m_mcSelector->asIMCselector();
00155 TesIoStat stat = m_tesIO->getMC( mcParticles, imcSelector) ;
00156 mess = stat? "Retrieved MC from TES ":"Failed MC retrieve from TES";
00157 log << MSG::DEBUG << mess << endreq;
00158
00159 log<<MSG::INFO<<"Dumping particles "<<endreq;
00160 log<<MSG::INFO<<"------------------- "<<endreq;
00161
00162 std::sort(mcParticles.begin(),
00163 mcParticles.end(),
00164 HepMC_helper::AscendingEta());
00165
00166 log<<MSG::INFO<<"Number particles found = "<<mcParticles.size()<<endreq;
00167
00168
00169
00170
00171
00172
00173
00174
00175 string space = " ";
00176 log<<MSG::INFO<<"Flat Dump"<<endreq<<endreq;
00177 this->DumpFlat(space, mcParticles.begin(), mcParticles.end() );
00178
00179
00180
00181 log<<MSG::INFO<<"End of execute "<<endreq;
00182 return StatusCode::SUCCESS;
00183 }
00184 void FinalStateParticleDumper::DumpParticle(std::string s,
00185 const HepMC::GenParticle* p){
00186 cout<<setiosflags(ios::fixed);
00187 cout<<setprecision(3);
00188 cout<<s
00189 <<setw(8)<<setprecision(3)<<p->momentum().phi()<<" "
00190 <<setw(8)<<setprecision(3)<<p->momentum().pseudoRapidity()<<" "
00191 <<setw(8)<<setprecision(3)<<p->momentum().perp()<<" "
00192 <<setw(8)<<setprecision(3)<<p->momentum().e()<<" "
00193 <<setw(8)<<setprecision(3)<<p->pdg_id()<<" "
00194 <<"phi, eta, pt, e"
00195 <<endl;
00196 cout<<s
00197 <<setw(8)<<setprecision(3)<<p->momentum().px()<<" "
00198 <<setw(8)<<setprecision(3)<<p->momentum().py()<<" "
00199 <<setw(8)<<setprecision(3)<<p->momentum().pz()<<" "
00200 <<setw(8)<<setprecision(3)<<p->momentum().e()<<" "
00201 <<setw(8)<<setprecision(3)<<p->pdg_id()<<" "
00202 <<" x, y, z, e"
00203 <<endl;
00204 }
00205 void FinalStateParticleDumper::DumpFlat(std::string space,
00206 MCparticleCollection::const_iterator ib,
00207 MCparticleCollection::const_iterator ie){
00208 MCparticleCollection::const_iterator ip=ib;
00209 for(; ip!=ie; ++ip){
00210 this->DumpParticle(space, *ip);
00211 }
00212 }
00213 void
00214 FinalStateParticleDumper::DumpTwoGenerations(
00215 std::string space,
00216 MCparticleCollection::const_iterator ib,
00217 MCparticleCollection::const_iterator ie){
00218 std::string space2 = space +" ";
00219 MCparticleCollection::const_iterator ip=ib;
00220 HepMC::GenVertex::particle_iterator ip2;
00221 cout<<"-------first"<<endl;
00222 cout << "******dopo first *******"<<endl;
00223 for(; ip!=ie; ++ip){
00224 cout << "****particle at ip *****" << endl;
00225 this->DumpParticle(space, *ip);
00226
00227 if((*ip)->end_vertex()){
00228 HepMC::GenVertex::particle_iterator firstChild =
00229 (*ip)->end_vertex()->particles_begin(HepMC::children);
00230
00231 HepMC::GenVertex::particle_iterator endChild =
00232 (*ip)->end_vertex()->particles_end(HepMC::children);
00233
00234 cout<<"----------second"<<endl;
00235 for(ip2=firstChild; ip2!=endChild; ++ip2){
00236 this->DumpParticle(space2, *ip2);
00237 }
00238 cout<<"-------first"<<endl;
00239 }
00240 }
00241 }
00242 void FinalStateParticleDumper::DumpTree(std::string space,
00243 MCparticleCollection::const_iterator ib,
00244 MCparticleCollection::const_iterator ie){
00245 MCparticleCollection::const_iterator ip=ib;
00246 space = space+" ";
00247 cout<<"-----------"<<endl;
00248 for(; ip!=ie; ++ip){
00249 this->DumpParticle(space, *ip);
00250
00251 if((*ip)->end_vertex()){
00252 HepMC::GenVertex::particle_iterator firstChild =
00253 (*ip)->end_vertex()->particles_begin(HepMC::children);
00254
00255 HepMC::GenVertex::particle_iterator endChild =
00256 (*ip)->end_vertex()->particles_end(HepMC::children);
00257
00258
00259
00260
00261
00262
00263 this->DumpTree(space, firstChild, endChild);
00264 }
00265 }
00266 }
00267 void FinalStateParticleDumper::DumpTree(std::string space,
00268 HepMC::GenVertex::particle_iterator ib,
00269 HepMC::GenVertex::particle_iterator ie){
00270 HepMC::GenVertex::particle_iterator ip=ib;
00271 space = space+" ";
00272 cout<<"-----------"<<endl;
00273 for(; ip!=ie; ++ip){
00274 this->DumpParticle(space, *ip);
00275 if((*ip)->end_vertex()){
00276 HepMC::GenVertex::particle_iterator firstChild =
00277 (*ip)->end_vertex()->particles_begin(HepMC::children);
00278
00279 HepMC::GenVertex::particle_iterator endChild =
00280 (*ip)->end_vertex()->particles_end(HepMC::children);
00281
00282
00283
00284
00285
00286
00287
00288 this->DumpTree(space, firstChild, endChild);
00289 }
00290 }
00291 }
00292
00293 };
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304