EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Tracker.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Tracker.cxx
1 
10 #include "eicsmear/smear/Tracker.h"
11 
12 #include <algorithm>
13 #include <cmath>
14 #include <limits>
15 #include <list>
16 
17 #include <TMath.h>
18 
19 namespace {
20 
21 // Functor for testing non-existent intersection points,
22 struct NoIntersection {
23  bool operator()(const TVector3& v) const {
24  return TMath::IsNaN(v.z());
25  }
26 };
27 
28 } // anonymous namespace
29 
30 namespace Smear {
31 
32 Tracker::Tracker(double magneticField, double nRadiationLengths,
33  double resolution)
34 : mFactor(720) // Assume no vertex constraint.
35 , mMagField(magneticField)
36 , mNRadLengths(nRadiationLengths)
37 , mSigmaRPhi(resolution) {
38 }
39 
41 }
42 
44  const erhic::VirtualParticle& p) const {
45  // Technically should be a factor of particle charge in the numerator
46  // but this is effectively always one.
47  double val = 0.016 / 0.3 * p.GetP() * sqrt(mNRadLengths) / LPrime(p) /
48  p.Get4Vector().Beta() / mMagField;
49  if (TMath::IsNaN(val)) {
50  std::cerr << "MS nan!" << std::endl;
51  } // if
52  return val;
53 }
54 
56  const erhic::VirtualParticle& p) const {
57  // The factor
58  // sqrt(720 * N^3 / ((N-1)(N+1)(N+2)(N+3)))
59  // is a more exact version of the factor
60  // sqrt(720 / (N+5))
61  // The constant factor in the sqrt depends on whether there is
62  // a vertex constraint assumed.
63  double val = sqrt(mFactor * pow(NPoints(p), 3.)) / 0.3 * pow(p.GetP(), 2.)
64  * mSigmaRPhi / mMagField / pow(LPrime(p), 2.)
65  / sqrt((NPoints(p)-1)*(NPoints(p)+1)*(NPoints(p)+2)*(NPoints(p)+3));
66  if (TMath::IsNaN(val)) {
67  std::cerr << "Intrinsic nan!" << std::endl;
68  } // if
69  return val;
70 }
71 
73  // Don't compute resolution for very small path length
74  // as L in the denominator causes it to blow up.
75  if (!Accepts(p)) {
76  return 0.;
77  } // if
78  return sqrt(pow(MultipleScatteringContribution(p), 2.) +
79  pow(IntrinsicContribution(p), 2.));
80 }
81 
83  ParticleMCS& pOut) {
84  if (Accepts(pIn) && Accept.Is(pIn)) {
85  double y = GetVariable(pIn, kP);
86  // Randomly generate a smeared value from the resolution
87  // and set it in the smeared particle.
89  // Ensure E, p are positive definite
90  pOut.HandleBogusValues(kP);
91  if (pOut.GetP() < 0.) {
92  std::cerr << "p " << pOut.GetP() << std::endl;
93  } // if
94  if (TMath::IsNaN(pOut.GetP())) {
95  std::cerr << "p nan" << std::endl;
96  } // if
97  } // if
98 }
99 
100 void Tracker::SetVertexConstraint(bool constrain) {
101  if (constrain) {
102  mFactor = 320;
103  } else {
104  mFactor = 720;
105  } // if
106 }
107 
108 } // namespace Smear