FinalStateParticleDumper.cxx

Go to the documentation of this file.
00001 // ================================================
00002 //FinalStateParticleDumper class Implementation
00003 // ================================================
00004 //
00005 // THIS TEXT TO BE REPLACED BY ATLAS STANDARD FORMAT
00006 //
00007 // Namespace Atlfast::
00008 //
00009 #include "AtlfastAlgs/FinalStateParticleDumper.h"
00010 
00011 #include <cmath> 
00012 #include <algorithm>
00013 #include <iomanip>
00014 #include <float.h>
00015 // Gaudi includes
00016 #include "GaudiKernel/DataSvc.h"
00017 
00018 
00019 // This algorithm includes
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 #include "AtlfastAlgs/GlobalEventData.h"
00027 
00028 #include "CLHEP/Units/SystemOfUnits.h"
00029 
00030 //--------------------------------
00031 // Constructors and destructors
00032 //--------------------------------
00033 
00034 namespace Atlfast {
00035   using std::vector;
00036   using std::cout;
00037   using std::endl;
00038   using std::ios;
00039     
00040   FinalStateParticleDumper::FinalStateParticleDumper
00041   ( const std::string& name, ISvcLocator* pSvcLocator ) 
00042     : Algorithm( name, pSvcLocator ){
00043     
00044     
00045     // Default paths for entities in the TES
00046     m_inputLocation  = "/Event/McEventCollection";
00047     m_selectorName   = "All";
00048     
00049     declareProperty( "InputLocation", m_inputLocation ) ;
00050     declareProperty( "SelectorName",  m_selectorName ) ;
00051     
00052   }
00053   
00054   
00055   FinalStateParticleDumper::~FinalStateParticleDumper() {} 
00056   
00057   
00058   //---------------------------------
00059   // initialise() 
00060   //---------------------------------
00061 
00062   StatusCode FinalStateParticleDumper::initialize()
00063   {
00064 
00065     MsgStream log( messageService(), name() ) ;
00066     log<<MSG::DEBUG<<"Initialising "<<endreq;
00067     
00068     //set up MC selector.
00069     log<< "m_mcSelector  set to "<<m_selectorName<<endreq;
00070     GlobalEventData* ged = GlobalEventData::Instance();
00071     if(m_selectorName == "All") {      
00072       m_mcSelector = 
00073         new HepMC_helper::MCselectorWrapper( new HepMC_helper::All() ) ;
00074     }else if(m_selectorName == "bSelector") {
00075       m_mcSelector =  
00076         new HepMC_helper::MCselectorWrapper( new 
00077                                              HepMC_helper::SelectJetTag 
00078                                              (ParticleCodes::BQUARK, 
00079                                               5.0*GeV, 
00080                                               2.5))
00081         ;
00082     }else if(m_selectorName == "ElectronSelector"){ 
00083       HepMC_helper::IMCselector* pidSelector =  
00084         new HepMC_helper::SelectPid(0.0, FLT_MAX, ParticleCodes::ELECTRON);
00085       HepMC_helper::IMCselector* finalStateSelector = 
00086         new HepMC_helper::IsFinalState();
00087 
00088       vector<HepMC_helper::IMCselector*> selectors;
00089       selectors.push_back(finalStateSelector);
00090       selectors.push_back(pidSelector);
00091 
00092     
00093       HepMC_helper::NCutter* ncutter  = new  HepMC_helper::NCutter(selectors);
00094       m_mcSelector = new HepMC_helper::MCselectorWrapper(ncutter) ;
00095     
00096       delete pidSelector;
00097       delete finalStateSelector;
00098 
00099     }else if(m_selectorName == "PhotonSelector"){ 
00100       HepMC_helper::IMCselector* pidSelector =  
00101         new HepMC_helper::SelectPid(0.0, FLT_MAX, ParticleCodes::PHOTON);
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(pidSelector);
00108 
00109     
00110       HepMC_helper::NCutter* ncutter  = new  HepMC_helper::NCutter(selectors);
00111       m_mcSelector = new HepMC_helper::MCselectorWrapper(ncutter) ;
00112     
00113       delete pidSelector;
00114       delete finalStateSelector;
00115 
00116     }else if(m_selectorName == "MuonSelector"){ 
00117       HepMC_helper::IMCselector* pidSelector =  
00118         new HepMC_helper::SelectPid(0.0, FLT_MAX, ParticleCodes::MUON);
00119       HepMC_helper::IMCselector* finalStateSelector = 
00120         new HepMC_helper::IsFinalState();
00121 
00122       vector<HepMC_helper::IMCselector*> selectors;
00123       selectors.push_back(finalStateSelector);
00124       selectors.push_back(pidSelector);
00125 
00126     
00127       HepMC_helper::NCutter* ncutter  = new  HepMC_helper::NCutter(selectors);
00128       m_mcSelector = new HepMC_helper::MCselectorWrapper(ncutter) ;
00129     
00130       delete pidSelector;
00131       delete finalStateSelector;
00132 
00133     }else if(m_selectorName == "Z0selector"){ 
00134       m_mcSelector =  
00135         new HepMC_helper::MCselectorWrapper( new 
00136                                            HepMC_helper::SelectZ0(0.0, FLT_MAX)
00137                                            )
00138      ;
00139 
00140     }else if(m_selectorName == "Unseen") {
00141 
00142       std::vector<int> requiredTypes;
00143       requiredTypes.push_back(66); //ERW's favorite LSP number.
00144       requiredTypes.push_back(ParticleCodes::NU_E);
00145       requiredTypes.push_back(ParticleCodes::NU_MU);
00146       requiredTypes.push_back(ParticleCodes::NU_TAU);
00147 
00148       HepMC_helper::IMCselector* unseen  = 
00149         new HepMC_helper::Unseen(requiredTypes);
00150 
00151       HepMC_helper::IMCselector* finalStateSelector = 
00152         new HepMC_helper::IsFinalState();
00153 
00154       vector<HepMC_helper::IMCselector*> selectors;
00155       selectors.push_back(finalStateSelector);
00156       selectors.push_back(unseen);
00157 
00158     
00159       HepMC_helper::NCutter* ncutter  = new  HepMC_helper::NCutter(selectors);
00160       m_mcSelector = new HepMC_helper::MCselectorWrapper(ncutter) ;
00161     
00162       delete unseen;
00163       delete finalStateSelector;
00164 
00165     }else if(m_selectorName ==  "VisibleToCal"){
00166       m_mcSelector = 
00167         new HepMC_helper::MCselectorWrapper(ged -> visibleToCal());
00168     }else{
00169       m_mcSelector = 
00170         new HepMC_helper::MCselectorWrapper(new HepMC_helper::IsFinalState() ) ;
00171     }
00172     m_mcLocation       = ged -> mcLocation();
00173     //    m_tesIO = new TesIO(eventDataService());
00174     m_tesIO = new TesIO(m_mcLocation, ged->justHardScatter());
00175     return StatusCode::SUCCESS ;
00176   }
00177   
00178   //---------------------------------
00179   // finalise() 
00180   //---------------------------------
00181   
00182   StatusCode FinalStateParticleDumper::finalize()
00183   {
00184     // .. put any finalisation in here...
00185     
00186     return StatusCode::SUCCESS ;
00187   }
00188 
00189   
00190   //----------------------------------------------
00191   // execute() method called once per event
00192   //----------------------------------------------
00193   //
00194   
00195   StatusCode FinalStateParticleDumper::execute( )
00196   {
00197     //................................
00198     // make a message logging stream
00199     
00200     MsgStream log( messageService(), name() ) ;
00201     log<<MSG::DEBUG<<"Executing "<<endreq;
00202     std::string mess;
00203     
00204     // read MC particles from TES
00205     MCparticleCollection  mcParticles ;
00206     const HepMC_helper::IMCselector* imcSelector = 
00207       m_mcSelector->asIMCselector();
00208     TesIoStat stat = m_tesIO->getMC( mcParticles, imcSelector) ;
00209     mess = stat? "Retrieved MC from TES ":"Failed MC retrieve from TES";
00210     log << MSG::DEBUG << mess << endreq;
00211     
00212     std::cout<<"Dumping  particles "<<std::endl;
00213     cout<<"------------------- "<<std::endl;
00214 
00215     std::sort(mcParticles.begin(), 
00216               mcParticles.end(), 
00217               HepMC_helper::AscendingEta());
00218 
00219     cout<<"Number particles found = "<<mcParticles.size()<<std::endl;
00220 
00221     /*
00222     for(;ip!=mcParticles.end();++ip){
00223       string space = " ";
00224       this->DumpParticle(space, *ip);
00225     }
00226     */
00227 
00228     string space = " ";
00229     log<<MSG::INFO<<"Flat Dump"<<endreq<<endreq;
00230     this->DumpFlat(space, mcParticles.begin(), mcParticles.end() );
00231     //    log<<MSG::INFO<<"Tree Dump"<<endreq<<endreq;
00232     //    this->DumpTree(space, mcParticles.begin(), mcParticles.end() );
00233     //this->DumpTwoGenerations(space, mcParticles.begin(), mcParticles.end() );
00234     log<<MSG::INFO<<"End of execute "<<endreq;    
00235     return StatusCode::SUCCESS;
00236   }
00237   void FinalStateParticleDumper::DumpParticle(std::string s, 
00238                                               const HepMC::GenParticle* p){
00239     cout<<setiosflags(ios::fixed);
00240     cout<<std::setprecision(3);
00241     cout<<s
00242       <<std::setw(15)<<std::setprecision(3)<<p->momentum().phi()<<" "
00243       <<std::setw(15)<<std::setprecision(3)<<p->momentum().pseudoRapidity()<<" "
00244       <<std::setw(15)<<std::setprecision(3)<<p->momentum().perp()<<" "
00245       <<std::setw(15)<<std::setprecision(3)<<p->momentum().e()<<" "
00246       <<std::setw(15)<<std::setprecision(3)<<p->pdg_id()<<" "
00247       <<"phi, eta, pt, e"
00248       <<std::endl;
00249     cout<<s
00250       <<std::setw(15)<<std::setprecision(3)<<p->momentum().px()<<" "
00251       <<std::setw(15)<<std::setprecision(3)<<p->momentum().py()<<" "
00252       <<std::setw(15)<<std::setprecision(3)<<p->momentum().pz()<<" "
00253       <<std::setw(15)<<std::setprecision(3)<<p->momentum().e()<<" "
00254       <<std::setw(15)<<std::setprecision(3)<<p->pdg_id()<<" "
00255       <<"  x,   y,  z, e"
00256       <<std::endl;
00257   }
00258   void FinalStateParticleDumper::DumpFlat(std::string space,
00259                                           MCparticleCollection::const_iterator ib,
00260                                           MCparticleCollection::const_iterator ie){
00261     MCparticleCollection::const_iterator ip=ib;
00262     for(; ip!=ie; ++ip){
00263       this->DumpParticle(space, *ip);
00264     }
00265   }
00266   void 
00267   FinalStateParticleDumper::DumpTwoGenerations(
00268                                                std::string space,
00269                                                MCparticleCollection::const_iterator ib,
00270                                                MCparticleCollection::const_iterator ie){
00271     std::string space2 = space +" ";
00272     MCparticleCollection::const_iterator ip=ib;
00273     HepMC::GenVertex::particle_iterator ip2; 
00274     cout<<"-------first"<<std::endl;
00275     cout << "******dopo first *******"<<std::endl;
00276 for(; ip!=ie; ++ip){
00277   cout << "****particle at ip *****" << endl;
00278   this->DumpParticle(space, *ip);
00279 
00280       if((*ip)->end_vertex()){
00281         HepMC::GenVertex::particle_iterator firstChild = 
00282           (*ip)->end_vertex()->particles_begin(HepMC::children);
00283         
00284         HepMC::GenVertex::particle_iterator endChild = 
00285           (*ip)->end_vertex()->particles_end(HepMC::children);
00286 
00287         cout<<"----------second"<<std::endl;
00288         for(ip2=firstChild; ip2!=endChild; ++ip2){
00289           this->DumpParticle(space2, *ip2);
00290         }       
00291         cout<<"-------first"<<std::endl;
00292       }
00293 }
00294   }
00295   void FinalStateParticleDumper::DumpTree(std::string space,
00296                                           MCparticleCollection::const_iterator ib,
00297                                           MCparticleCollection::const_iterator ie){
00298     MCparticleCollection::const_iterator ip=ib;
00299     space = space+" ";
00300     cout<<"-----------"<<endl;
00301     for(; ip!=ie; ++ip){
00302       this->DumpParticle(space, *ip);
00303 
00304       if((*ip)->end_vertex()){
00305         HepMC::GenVertex::particle_iterator firstChild = 
00306           (*ip)->end_vertex()->particles_begin(HepMC::children);
00307         
00308         HepMC::GenVertex::particle_iterator endChild = 
00309           (*ip)->end_vertex()->particles_end(HepMC::children);
00310         /*
00311         HepMC::GenVertex::particle_iterator secondChild = firstChild;
00312         ++secondChild;
00313         
00314         if(secondChild!=endChild) this->DumpTree(space,secondChild,endChild);
00315         */
00316         this->DumpTree(space, firstChild, endChild);    
00317       }
00318     }
00319   }
00320   void FinalStateParticleDumper::DumpTree(std::string space,
00321                                           HepMC::GenVertex::particle_iterator ib,
00322                                           HepMC::GenVertex::particle_iterator ie){
00323     HepMC::GenVertex::particle_iterator ip=ib;
00324     space = space+" ";
00325     cout<<"-----------"<<endl;
00326     for(; ip!=ie; ++ip){
00327       this->DumpParticle(space, *ip);
00328       if((*ip)->end_vertex()){
00329         HepMC::GenVertex::particle_iterator firstChild = 
00330           (*ip)->end_vertex()->particles_begin(HepMC::children);
00331         
00332         HepMC::GenVertex::particle_iterator endChild = 
00333           (*ip)->end_vertex()->particles_end(HepMC::children);
00334 
00335         /*
00336         HepMC::GenVertex::particle_iterator secondChild = firstChild;
00337         ++secondChild;
00338 
00339         if(secondChild != endChild) this->DumpTree(space, secondChild, endChild);
00340         */
00341         this->DumpTree(space, firstChild, endChild);
00342       }
00343     }
00344   }   
00345 
00346 }  // end of namespace bracket
00347 
00348 
00349 
00350 
00351 
00352 
00353 
00354 
00355 
00356 
00357 

Generated on Mon Sep 24 14:19:12 2007 for AtlfastAlgs by  doxygen 1.5.1