Marlin  01.17.01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SimpleClusterSmearer.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 #include <cmath>
10 
11 // #include "CLHEP/Vector/ThreeVector.h"
12 
13 
14 namespace marlin{
15 
16 
17  SimpleClusterSmearer::SimpleClusterSmearer(const std::vector<float>& resVec ):
18  _resVec(0)
19  {
20 
21  // copy the resolution vector parameters into a more structured vector
22  const unsigned int size = resVec.size() / ( sizeof( ClusterResolution) / sizeof(float) ); // ==3
23  _resVec.reserve(size);
24 
25  int index = 0 ;
26 
27  for( unsigned int i=0 ; i < size ; i++ ){
28 
29  float A = resVec[ index++ ] ;
30  float B = resVec[ index++ ] ;
31  float thMin = resVec[ index++ ] ;
32  float thMax = resVec[ index++ ] ;
33 
34  _resVec.push_back( ClusterResolution( A, B , thMin, thMax ) );
35  }
36  }
37 
38 
39  HepLorentzVector SimpleClusterSmearer::smearedFourVector( const HepLorentzVector& v, int /*pdgCode*/ ){
40 
41 
42  // find resolution for polar angle
43  double theta = v.theta() ;
44 
45  if( theta > M_PI_2 ) theta = M_PI - theta ; // need to transform to [0,pi/2]
46 
47  std::pair<double,double> resolution = std::make_pair( -1., -1. ) ;
48 
49  for( unsigned int i=0 ; i < _resVec.size() ; i++ ){
50 
51  if( theta <= _resVec[i].ThMax && theta > _resVec[i].ThMin ) {
52  resolution.first = _resVec[i].A ;
53  resolution.second = _resVec[i].B ;
54  break ;
55  }
56  }
57  HepLorentzVector sv( 0., 0. , 0., 0. ) ;
58 
59  if( resolution.first > - 1e-10 ) {
60 
61  // do the smearing ....
62 
63  double E = v.e() ;
64 
65  double Eres = std::sqrt( resolution.first * resolution.first +
66  resolution.second * resolution.second / E ) ;
67 
68  double deltaE = RandGauss::shoot( 0.0 , E*Eres ) ;
69 
70 
71  // assume massless clusters ...
72 
73  Hep3Vector n3v( v.vect() ) ;
74 
75  n3v.setMag( E + deltaE ) ;
76 
77  double mass = 0. ;
78 
79  sv.setVectM( n3v , mass ) ;
80 
81  }
82 
83  return sv ;
84 
85  }
86 
87 }
88 
89 #endif // MARLIN_CLHEP
90 
#define M_PI
T push_back(T...args)
T make_pair(T...args)
T size(T...args)
T sqrt(T...args)