BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
TruthDemo.cxx
Go to the documentation of this file.
1// Example algoritm to demonstrate how to use
2// the predicates in Genarators/GenAnalysisTools/TruthHelper
3// Ian Hinchliffe
4// January 2003#include <math.h>
5//
6#include "TruthExamples/TruthDemo.h"
7#include "GeneratorObject/McEventCollection.h"
8
9#include "GaudiKernel/AlgFactory.h"
10#include "GaudiKernel/MsgStream.h"
11
12#include "GaudiKernel/DataSvc.h"
13#include "GaudiKernel/SmartDataPtr.h"
14
15#include "GaudiKernel/IHistogramSvc.h"
16
18
19#include "AIDA/IHistogram1D.h"
20#include "AIDA/IHistogram2D.h"
21
22#include "GaudiKernel/IDataProviderSvc.h"
23#include "GaudiKernel/INTupleSvc.h"
24#include "GaudiKernel/ISvcLocator.h"
25#include "GaudiKernel/MsgStream.h"
26#include "GaudiKernel/ObjectList.h"
27#include "GaudiKernel/PropertyMgr.h"
28
29#include "HepMC/GenEvent.h"
30#include "HepMC/GenParticle.h"
31// #include "HepMC/ParticleData.h"
32// #include "HepMC/ParticleDataTable.h"
33// #include "HepMC/IO_PDG_ParticleDataTable.h"
34#include "HepMC/GenVertex.h"
35
36typedef std::vector<const HepMC::GenParticle*> MCparticleCollection;
37
38static const AlgFactory<TruthDemo> Factory;
39const IAlgFactory& TruthDemoFactory = Factory;
40
42TruthDemo::TruthDemo( const std::string& name, ISvcLocator* pSvcLocator )
43 : Algorithm( name, pSvcLocator ) {
44 // Declare the algorithm's properties
45 declareProperty( "HistogramFlag", m_produceHistogram = true );
46 // declareProperty("HistogramFlag", m_produceHistogram = false );
47}
48
50 StatusCode result = StatusCode::SUCCESS;
51 MsgStream msglog( msgSvc(), name() );
52 msglog << MSG::INFO << ">>> Truthdemo from Initialize" << endmsg;
53 m_hgenerated = histoSvc()->book( "/stat/1Dhist/1", "Generated", 100, 0, 1200 );
54 if ( 0 == m_hgenerated )
55 {
56 msglog << MSG::ERROR << " ERROR booking histogram" << endmsg;
57 result = StatusCode::FAILURE;
58 }
59 m_pxBalance = histoSvc()->book( "/stat/1Dhist/25", "px balance", 50, -10., 10. );
60 m_pyBalance = histoSvc()->book( "/stat/1Dhist/26", "py balance", 50, -10., 10. );
61 m_totEnergy = histoSvc()->book( "/stat/1Dhist/27", "total energy", 50, 10000., 20000. );
62 m_tesIO = new GenAccessIO();
63
64 // return StatusCode::SUCCESS;
65 return result;
66}
67StatusCode TruthDemo::execute() {
68 // HepMC::IO_PDG_ParticleDataTable pdg_io("PDGTABLE");
69 // static HepMC::ParticleDataTable *pp = NULL;
70 // if (pp == NULL) pp = pdg_io.read_particle_data_table();
71 MsgStream msglog( msgSvc(), name() );
72 msglog << MSG::INFO << ">>> TruthDemo from execute" << endmsg;
73 //
74 // Px/Py Balance and total energy
75 //
76 float totenergy = 0.;
77 float pxbalance = 0.;
78 float pybalance = 0.;
79 // Iterate over MC particles We are using the IsGenStable predicate from
80 IsGenStable ifs;
81 std::vector<const HepMC::GenParticle*> particles;
82 StatusCode stat = m_tesIO->getMC( particles, &ifs );
83 for ( std::vector<const HepMC::GenParticle*>::iterator pitr = particles.begin();
84 pitr != particles.end(); pitr++ )
85 {
86 pxbalance += ( *pitr )->momentum().x();
87 pybalance += ( *pitr )->momentum().y();
88 totenergy += ( *pitr )->momentum().e();
89 }
90 m_pxBalance->fill( pxbalance, 1. );
91 m_pyBalance->fill( pybalance, 1. );
92 m_totEnergy->fill( totenergy, 1. );
93 // End of execution for each event
94 return StatusCode::SUCCESS;
95}
96
97StatusCode TruthDemo::finalize() {
98 MsgStream msglog( msgSvc(), name() );
99 msglog << MSG::INFO << ">>> TruthDemo from finalize" << endmsg;
100 return StatusCode::SUCCESS;
101}
DECLARE_COMPONENT(BesBdkRc)
IHistogramSvc * histoSvc()
IMessageSvc * msgSvc()
std::vector< const HepMC::GenParticle * > MCparticleCollection
Definition TruthDemo.cxx:36
const IAlgFactory & TruthDemoFactory
Definition TruthDemo.cxx:39
StatusCode finalize()
Definition TruthDemo.cxx:97
StatusCode execute()
Definition TruthDemo.cxx:67
StatusCode initialize()
Definition TruthDemo.cxx:49
TruthDemo(const std::string &name, ISvcLocator *pSvcLocator)
Definition TruthDemo.cxx:42