Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

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.h>
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 "AtlfastUtils/HepMC_helper/MCselectorWrapper.h"
00027 //#include "AtlfastUtils/HepMC_helper/SelectJetTag.h"
00028 //#include "AtlfastUtils/HepMC_helper/SelectZ0.h"
00029 //#include "AtlfastUtils/HepMC_helper/Unseen.h"
00030 //#include "AtlfastUtils/HepMC_helper/IsFinalState.h"
00031 //#include "AtlfastUtils/HepMC_helper/NCutter.h"
00032 //#include "AtlfastUtils/HepMC_helper/AscendingEta.h"
00033 
00034 //#include "GeneratorObjects/McEventCollection.h"
00035 
00036 //--------------------------------
00037 // Constructors and destructors
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     // Default paths for entities in the TES
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   // initialise() 
00065   //---------------------------------
00066 
00067   StatusCode FinalStateParticleDumper::initialize()
00068   {
00069     MsgStream log( messageService(), name() ) ;
00070     log<<MSG::DEBUG<<"Initialising "<<endreq;
00071     
00072     //set up MC selector.
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); //ERW's favorite LSP number.
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     //    m_tesIO = new TesIO(eventDataService());
00121     m_tesIO = new TesIO();
00122     return StatusCode::SUCCESS ;
00123   }
00124   
00125   //---------------------------------
00126   // finalise() 
00127   //---------------------------------
00128   
00129   StatusCode FinalStateParticleDumper::finalize()
00130   {
00131     // .. put any finalisation in here...
00132     
00133     return StatusCode::SUCCESS ;
00134   }
00135 
00136   
00137   //----------------------------------------------
00138   // execute() method called once per event
00139   //----------------------------------------------
00140   //
00141   
00142   StatusCode FinalStateParticleDumper::execute( )
00143   {
00144     //................................
00145     // make a message logging stream
00146     
00147     MsgStream log( messageService(), name() ) ;
00148     log<<MSG::DEBUG<<"Executing "<<endreq;
00149     std::string mess;
00150     
00151     // read MC particles from TES
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     for(;ip!=mcParticles.end();++ip){
00170       string space = " ";
00171       this->DumpParticle(space, *ip);
00172     }
00173     */
00174 
00175     string space = " ";
00176     log<<MSG::INFO<<"Flat Dump"<<endreq<<endreq;
00177     this->DumpFlat(space, mcParticles.begin(), mcParticles.end() );
00178     //    log<<MSG::INFO<<"Tree Dump"<<endreq<<endreq;
00179     //    this->DumpTree(space, mcParticles.begin(), mcParticles.end() );
00180     //this->DumpTwoGenerations(space, mcParticles.begin(), mcParticles.end() );
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         HepMC::GenVertex::particle_iterator secondChild = firstChild;
00259         ++secondChild;
00260         
00261         if(secondChild!=endChild) this->DumpTree(space,secondChild,endChild);
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         HepMC::GenVertex::particle_iterator secondChild = firstChild;
00284         ++secondChild;
00285 
00286         if(secondChild != endChild) this->DumpTree(space, secondChild, endChild);
00287         */
00288         this->DumpTree(space, firstChild, endChild);
00289       }
00290     }
00291   }   
00292 
00293 };  // end of namespace bracket
00294 
00295 
00296 
00297 
00298 
00299 
00300 
00301 
00302 
00303 
00304 

Generated on Tue Mar 18 11:18:23 2003 for AtlfastAlgs by doxygen1.3-rc1