Marlin  01.17.01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SimpleTrackSmearer.cc
Go to the documentation of this file.
1 #include "marlin/MarlinConfig.h" // defines MARLIN_CLHEP / MARLIN_AIDA
2 
3 #ifdef MARLIN_CLHEP // only if CLHEP is available !
4 
6 
7 #include "CLHEP/Random/RandGauss.h"
8 #include "CLHEP/Random/RandEngine.h"
9 
10 
11 #include <cmath>
12 #include <cstdlib>
13 
14 namespace CLHEP{}
15 using namespace CLHEP ;
16 
17 // #include "CLHEP/Vector/ThreeVector.h"
18 
19 
20 namespace marlin{
21 
22 
23  SimpleTrackSmearer::SimpleTrackSmearer(const std::vector<float>& resVec ):
24  _resVec(0)
25  {
26 
27  const unsigned int size = resVec.size() / ( sizeof(TrackResolution) / sizeof(float) ); // ==3
28  _resVec.reserve(size);
29  // copy the resolution vector parameters into a more structured vector
30  int index = 0 ;
31 
32  for( unsigned int i=0 ; i < size ; i++ ){
33 
34  float dPP = resVec[ index++ ] ;
35  float thMin = resVec[ index++ ] ;
36  float thMax = resVec[ index++ ] ;
37 
38  _resVec.push_back( TrackResolution( dPP, thMin, thMax ) );
39  }
40  }
41 
42 
43  HepLorentzVector SimpleTrackSmearer::smearedFourVector( const HepLorentzVector& v, int pdgCode ){
44 
45 
46  // find resolution for polar angle
47  double theta = v.theta() ;
48 
49  if( theta > M_PI_2 ) theta = M_PI - theta ; // need to transform to [0,pi/2]
50 
51  double resolution = -1. ;
52 
53  for( unsigned int i=0 ; i < _resVec.size() ; i++ ){
54 
55  if( theta <= _resVec[i].ThMax && theta > _resVec[i].ThMin ) {
56  resolution = _resVec[i].DPP ;
57  break ;
58  }
59  }
60  HepLorentzVector sv( 0., 0. , 0., 0. ) ;
61 
62  if( resolution > - 1e-10 ) {
63 
64  // do the smearing ....
65 
66  double P = v.vect().mag() ;
67 
68  double deltaP = RandGauss::shoot( 0.0 , P*P*resolution ) ;
69 
70  Hep3Vector n3v( v.vect() ) ;
71 
72  n3v.setMag( P + deltaP ) ;
73 
74 // std::cout << " SimpleTrackSmearer::smearedFourVector P0: "
75 // << P << " - P1 : " << P + deltaP
76 // << " resolution: " << resolution
77 // << std::endl ;
78 
79 
80  // assume perfect electron and muon ID and
81  // assign pion mass to everything else
82 
83  double mass = PION_MASS ;
84 
85  if( std::abs( pdgCode ) == 12 ) // electron
86 
87  mass = ELECTRON_MASS ;
88 
89  else if( std::abs( pdgCode ) == 13 ) // muon
90 
91  mass = MUON_MASS ;
92 
93  sv.setVectM( n3v , mass ) ;
94 
95  }
96 
97  return sv ;
98 
99  }
100 
101 }
102 
103 #endif // MARLIN_CLHEP
#define M_PI
T push_back(T...args)
T size(T...args)