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

ReconstructedParticleHistogramMaker.cxx

Go to the documentation of this file.
00001 // ================================================
00002 // ReconstructedParticleHistogramMaker class Implementation
00003 // ================================================
00004 //
00005 //
00006 // Namespace Atlfast::
00007 //
00008 #include "AtlfastAlgs/ReconstructedParticleHistogramMaker.h"
00009 #include "AtlfastEvent/ReconstructedParticle.h"
00010 #include "AtlfastEvent/CollectionDefs.h"
00011 #include "AtlfastEvent/MCparticleCollection.h"
00012 #include "AtlfastUtils/HepMC_helper/IMCselector.h"
00013 #include "AtlfastUtils/HepMC_helper/SelectType.h"
00014 #include "AtlfastUtils/HepMC_helper/IsFinalState.h"
00015 #include "AtlfastUtils/HepMC_helper/MCCuts.h"
00016 #include "AtlfastUtils/HepMC_helper/NCutter.h"
00017 
00018 // library includes
00019 #include <cmath> 
00020 
00021 // Gaudi includes
00022 #include "GaudiKernel/AlgFactory.h"
00023 #include "GaudiKernel/DataSvc.h"
00024 #include "AIDA/IHistogram1D.h"
00025 #include "GaudiKernel/IHistogramSvc.h"
00026 
00027 // Generator includes
00028 #include "GeneratorObjects/McEventCollection.h"
00029 #include "HepMC/GenParticle.h"
00030 
00031 
00032 //-------------------------------
00033 // Gaudi magic lines.
00034 // These are so that it can make instances of this algorithm
00035 // You never need to know why or how !!!
00036 //-------------------------------
00037 
00038 static const AlgFactory<Atlfast::ReconstructedParticleHistogramMaker> s_factory ;
00039 const IAlgFactory& ReconstructedParticleHistogramMakerFactory = s_factory ;
00040 
00041 
00042 namespace Atlfast {
00043 //--------------------------------
00044 // Constructors and destructors
00045 //-------------------------------
00046 
00047 ReconstructedParticleHistogramMaker::ReconstructedParticleHistogramMaker 
00048   ( const std::string& name, ISvcLocator* pSvcLocator ) 
00049     : Algorithm( name, pSvcLocator ){
00050 
00051 
00052 
00053 
00054   // Default paths for entities in the TES
00055   m_inputLocation     = "/Event/Electrons";
00056   m_mcTruthLocation   = "/Event/McEventCollection";
00057   
00058 
00059   m_histStart         = 0;            // ID of first histogram
00060   m_particleType      = 11;           // Default particle type to examine
00061   m_histTitle         = "Electron ";  // Default prefixfor histogram titles
00062 
00063   declareProperty( "InputLocation", m_inputLocation ) ;
00064   declareProperty( "McTruthLocation", m_mcTruthLocation ); 
00065   declareProperty( "HistogramStart", m_histStart );
00066   declareProperty( "ParticleType", m_particleType );
00067   declareProperty( "HistogramTitle", m_histTitle );
00068 
00069 }
00070 
00071 
00072 ReconstructedParticleHistogramMaker::~ReconstructedParticleHistogramMaker(){
00073   MsgStream log(messageService(), name());
00074   log << MSG::INFO << "destructor" << endreq;
00075 
00076 }
00077 
00078 
00079 //---------------------------------
00080 // initialise() 
00081 //---------------------------------
00082 
00083 StatusCode ReconstructedParticleHistogramMaker::initialize()
00084 {
00085   // .. put any initialisation in here...
00086   MsgStream log(messageService(), name());
00087   log << MSG::DEBUG << "in initialize()" << endreq;
00088   
00089   m_nHist = m_histStart;
00090   
00091   book(m_h_multiplicity, string("Multiplicity"),20,0.0,20.0,-5.0, 5.0);
00092   log << MSG::DEBUG << "Made multiplicity histos" << endreq;  
00093 
00094   book(m_h_energy,       string("Energy"),100,0.0,500.0,-10.0, 10.0);
00095   log << MSG::DEBUG << "Made energy histos" << endreq;
00096 
00097   book(m_h_pt,           string("Pt"), 100,0.0,500.0,-10.0,10.0);
00098   log << MSG::DEBUG << "Made pt histos" << endreq;
00099 
00100   book(m_h_eta,          string("Eta"), 100,-3.0,3.0,-0.2,0.2);
00101   log << MSG::DEBUG << "Made eta histos" << endreq;
00102 
00103   book(m_h_phi,          string("Phi"),20,-M_PI,M_PI,-0.1,0.1);
00104   log << MSG::DEBUG << "Made phi histos" << endreq;
00105 
00106   book(m_h_theta,        string("Theta"),20,0.0,M_PI,-0.1,0.1);
00107   log << MSG::DEBUG << "Made thetahistos" << endreq;
00108 
00109 
00110   log << MSG::DEBUG << "Booked histograms OK" << endreq;
00111   //  m_tesIO = new TesIO(eventDataService());
00112   m_tesIO = new TesIO();
00113   
00114   // Set up NCutter to select the required HepMC::GenParticles
00115   typedef HepMC_helper::IMCselector Selector;
00116   
00117   Selector* typeSelector = new HepMC_helper::SelectType( m_particleType);
00118   Selector* kineSelector = new HepMC_helper::MCCuts(m_mcPtMin, m_mcEtaMax);
00119   Selector* fstaSelector = new HepMC_helper::IsFinalState();
00120   
00121   vector<HepMC_helper::IMCselector*> selectors;
00122   selectors.push_back(fstaSelector);
00123   selectors.push_back(typeSelector);
00124   selectors.push_back(kineSelector);
00125   
00126   m_ncutter = new  HepMC_helper::NCutter(selectors);
00127   
00128   delete typeSelector;
00129   delete fstaSelector;
00130   delete kineSelector;
00131   //=======================================================
00132   
00133   return StatusCode::SUCCESS ;
00134 }
00135 
00136 
00137 
00138 //---------------------------------
00139 // finalise() 
00140 //---------------------------------
00141 
00142 StatusCode ReconstructedParticleHistogramMaker::finalize()
00143 {
00144   // .. put any finalisation in here...
00145   MsgStream log(messageService(), name());
00146   log << MSG::INFO << "finalizing" << endreq;
00147 
00148   return StatusCode::SUCCESS ;
00149 }
00150 
00151 
00152 
00153 
00154 //----------------------------------------------
00155 // execute() method called once per event
00156 //----------------------------------------------
00157 
00158 StatusCode ReconstructedParticleHistogramMaker::execute( )
00159 {
00160 
00161   //................................
00162   // make a message logging stream
00163 
00164   MsgStream log( messageService(), name() ) ;
00165   log << MSG::DEBUG << "Executing " << endreq;
00166 
00167   // Access the reconstructed particles in the TES
00168   std::vector<ReconstructedParticle*> myParticles;
00169   // Access the collection of "McEvent" records in the TES
00170   std::vector<McEvent*> mcEvents;
00171 
00172 
00173   //Get the MC truth list
00174     MCparticleCollection  myMC_particles ;
00175     MCparticleCollectionCIter src ;
00176     
00177     TesIoStat stat = m_tesIO->getMC( myMC_particles, m_ncutter ) ;
00178     mess = stat? "Retrieved MC from TES ":"Failed MC retrieve from TES";
00179     log << MSG::DEBUG << mess << endreq;
00180  
00181 
00182    //check to see whether any reconstructed particles are found at the requested location
00183   if(!m_tesIO->copy(myParticles, m_inputLocation)){
00184     log << MSG::DEBUG << "no particles found in the TES. This is probably normal" << endreq; 
00185     // fill any histograms that have meaning in the absence of rec particles
00186     fill(m_h_multiplicity,0.0,float(myMC_particles.size()) );
00187     //log << MSG::DEBUG 
00188     //<< "filled multiplicity 0.0 and " 
00189     //<< float(myMC_particles.size()) 
00190     //<< endreq;
00191   } else {
00192     // fill all histograms
00193     //log << MSG::DEBUG << "Fill multiplicity" << endreq;
00194     fill(m_h_multiplicity,
00195          double(myParticles.size()),
00196          double(myMC_particles.size()) );
00197 
00198     //iterate over the electrons
00199 
00200     std::vector<ReconstructedParticle*>::const_iterator iter = myParticles.begin();
00201     for (; iter != myParticles.end(); ++iter) {
00202       const HepMC::GenParticle* truth = (*iter)->truth();
00203       HepLorentzVector momentum = (*iter)->momentum();
00204       HepLorentzVector trueMomentum = truth->momentum();
00205       
00206       //log << MSG::DEBUG << "Fill per-electron histos" << endreq;
00207       fill(m_h_pt,    (*iter)->pT(),                trueMomentum.perp());
00208       fill(m_h_eta,   (*iter)->eta(),           trueMomentum.pseudoRapidity());
00209       fill(m_h_energy,((*iter)->momentum()).e(),    trueMomentum.e());
00210       fill(m_h_phi,   (*iter)->phi(),               trueMomentum.phi());
00211       fill(m_h_theta, ((*iter)->momentum()).theta(),trueMomentum.theta());
00212     }
00213   }
00214   log << MSG::DEBUG << "Done the filling OK" << endreq;
00215   return StatusCode::SUCCESS ;
00216 }
00217 
00218 
00219 
00220 //--------------------------------------------------------------
00221 //
00222 void ReconstructedParticleHistogramMaker::book
00223       (
00224        std::vector<IHistogram1D*>& start, 
00225        const std::string title, 
00226        const int nbins, 
00227        const double xmin, 
00228        const double xmax,
00229        const double xminDiff,
00230        const double xmaxDiff
00231       ) 
00232 {
00233   
00234   // book the histograms in turn, incrementing the counter before using it
00235   start.push_back(histoSvc()->book(
00236                                    "/stat/simple1d/",
00237                                    ++m_nHist,
00238                                    m_histTitle+" Rec "+title,
00239                                    nbins,
00240                                    xmin,
00241                                    xmax
00242                                    )
00243                   );
00244 
00245   start.push_back(histoSvc()->book(
00246                                    "/stat/simple1d/",
00247                                    ++m_nHist,
00248                                    m_histTitle+" Tru "+title,
00249                                    nbins,
00250                                    xmin,
00251                                    xmax
00252                                    )
00253                   );
00254 
00255   start.push_back(histoSvc()->book(
00256                                    "/stat/simple1d/",
00257                                    ++m_nHist,
00258                                    m_histTitle+" Dif "+title,
00259                                    nbins*2,
00260                                    xminDiff,
00261                                    xmaxDiff
00262                                    )
00263                   );
00264   start.push_back(histoSvc()->book(
00265                                    "/stat/simple1d/",
00266                                    ++m_nHist,
00267                                    m_histTitle+" Res "+title,
00268                                    nbins*2,
00269                                    -2.0,
00270                                    2.0
00271                                    )
00272                   );
00273 
00274   return;
00275 }
00276 
00277 
00278 //-------------------------------------------------------------------
00279 
00280 void ReconstructedParticleHistogramMaker::fill(std::vector<IHistogram1D*>& start, const double rec, const double tru) {
00281  
00282   MsgStream log( messageService(), name() ) ;
00283 
00284   if (!start[0] || !start[1] || !start[2] || !start[3]) {
00285     log << MSG::WARNING << "trying to fill to a null histogram pointer" << endreq;
00286     return;
00287    }
00288   start[0]->fill(rec,1.0);
00289   start[1]->fill(tru,1.0);
00290   start[2]->fill(tru-rec,1.0);
00291   if (tru != 0.0) {
00292     start[3]->fill((tru-rec)/tru,1.0);
00293   }
00294   return;
00295 }
00296 
00297 } // end of namespace bracket
00298 
00299 
00300 
00301 
00302 
00303 
00304 
00305 
00306 
00307 
00308 
00309 
00310 
00311 
00312 
00313 
00314 
00315 

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