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

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