Marlin  01.17.01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SimpleParticleFactory.cc
Go to the documentation of this file.
1 #include "marlin/MarlinConfig.h" // defines MARLIN_CLHEP
2 
3 #ifdef MARLIN_CLHEP // only if CLHEP is available !
4 
5 #include <cstdlib>
6 
8 
10 
11 // #if LCIO_VERSION_GE( 1,9)
12 // // lcio v01-09 properly fills the charge
13 // #include "UTIL/LCStdHepRdr.h"
14 // #else
15 // #ifdef USE_SEPARATE_HEPPDT
16 // #include "HepPDT/ParticleID.hh"
17 // #else
18 // #include "CLHEP/HepPDT/ParticleID.hh"
19 // #endif
20 // #endif
21 
22 #if ! LCIO_PATCHVERSION_GE( 1,51,3 )
23  //#warning "have to #define USE_CLHEP to activate code from LCIO header <UTIL/LCFourVector.h>"
24  #define USE_CLHEP // to activate code from LCIO header <UTIL/LCFourVector.h>
25 #endif
26 
27 #include "UTIL/LCFourVector.h"
28 
29 using namespace lcio ;
30 
31 
32 namespace marlin{
33 
34  SimpleParticleFactory::SimpleParticleFactory() :
35  _smearingVec(NUMBER_OF_FASTMCPARTICLETYPES, NULL), _momentumCut( 0.0000000001 ) {
36  }
37 
38 
39  void SimpleParticleFactory::setMomentumCut( double mCut ) {
40  _momentumCut = mCut ;
41  }
42 
43  void SimpleParticleFactory::registerIFourVectorSmearer( IFourVectorSmearer* sm ,
44  FastMCParticleType type ) {
45  _smearingVec[ type ] = sm ;
46 
47  }
48 
49 
50  FastMCParticleType SimpleParticleFactory::getParticleType( const lcio::MCParticle* mcp ) {
51 
52 
53  // assumes that mcp is a stable particle !
54 
55  FastMCParticleType type( UNKNOWN ) ;
56 
57  // if( mcp->getCharge() > 0.001 || mcp->getCharge() < -.001 ){ // mcp->getCharge() != 0.00
58  // NOTE: the charge is currently (LCIO v01-04) not filled when reading StdHep
59 
60 // #if LCIO_VERSION_GE( 1,9)
61  float charge = mcp->getCharge() ;
62 // #else
63 // float charge = getCharge( mcp->getPDG() ) ;
64 // #endif
65 
66  if( charge > 1e-10 || charge < -1e-10 ){
67 
68  type = CHARGED ;
69 
70  } else if( mcp->getPDG() == 22 ) { // photon
71 
72  type = PHOTON ;
73 
74  } else if( std::abs( mcp->getPDG() ) == 12 || std::abs( mcp->getPDG() ) == 14 ||
75  std::abs( mcp->getPDG() ) == 16 || std::abs( mcp->getPDG() ) == 18 ) { // neutrinos - 18 is tau-prime
76 
77  type = NEUTRINO ;
78 
79 
80  } else { // treat everything else neutral hadron
81 
82  type = NEUTRAL_HADRON ;
83  }
84 
85  return type ;
86  }
87 
88 // float SimpleParticleFactory::getCharge( int pdgCode ) {
89 // #if LCIO_VERSION_GE( 1,9)
90 // static LCStdHepRdr rdr("") ; // threeCharge should be a static method really ...
91 // return rdr.threeCharge( pdgCode ) / 3.00 ;
92 // #else
93 // return double( HepPDT::ParticleID( pdgCode ).threeCharge() / 3.00 ) ;
94 // #endif
95 // }
96 
97 
98 
99  ReconstructedParticle* SimpleParticleFactory::createReconstructedParticle( const MCParticle* mcp ) {
100 
101  // this is where we do the fast Monte Carlo ....
102 
103 
104 #ifdef LCIO_PATCHVERSION_GE // has been defined in 1.4.1 which has a bug fix in LCFourVector<T>
105  LCFourVector<MCParticle> mc4V( mcp ) ;
106 #else
107  HepLorentzVector mc4V( mcp->getMomentum()[0], mcp->getMomentum()[1],
108  mcp->getMomentum()[2], mcp->getEnergy() ) ;
109 #endif
110 
111 
112 
113  FastMCParticleType type = getParticleType(mcp ) ;
114 
115 
116  IFourVectorSmearer* sm = _smearingVec[ type ] ;
117 
118  HepLorentzVector reco4v(0.,0.,0.,0.) ;
119 
120  if( sm == 0 ){
121  // if we don't have a smearer registered we don't reconstruct the particle, e.g for neutrinos
122 
123  return 0 ;
124  }
125 
126  reco4v = sm->smearedFourVector( mc4V , mcp->getPDG() ) ;
127 
128 
129  ReconstructedParticleImpl* rec = 0 ;
130 
131  if( reco4v.vect().mag() > _momentumCut ) {
132 
133  rec = new ReconstructedParticleImpl ;
134 
135  float p[3] ;
136  p[0] = reco4v.px() ;
137  p[1] = reco4v.py() ;
138  p[2] = reco4v.pz() ;
139 
140  rec->setMomentum( p ) ;
141  rec->setEnergy( reco4v.e() ) ;
142  rec->setMass( reco4v.m() ) ;
143 
144  rec->setCharge( mcp->getCharge() ) ;
145 
146  float vtx[3] ;
147  vtx[0] = mcp->getVertex()[0] ;
148  vtx[1] = mcp->getVertex()[1] ;
149  vtx[2] = mcp->getVertex()[2] ;
150  rec->setReferencePoint( vtx ) ;
151 
152  rec->setType( type ) ;
153  }
154 
155  return rec ;
156  }
157 
158 
159 } // namespace
160 
161 #endif // MARLIN_CLHEP
162 
FastMCParticleType
Enumeration that defines integer constants for various particle types used in the fast Monte Carlo...
#define NUMBER_OF_FASTMCPARTICLETYPES