eic-smear  1.0.3
A collection of ROOT classes for Monte Carlo events and a fast-smearing code simulating detector effects for the Electron-Ion Collider task force
Tracker.cxx
Go to the documentation of this file.
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.
88  SetVariable(pOut, Distribution.Generate(y, Resolution(pIn)), kP);
89  // Ensure E, p are positive definite
90  HandleBogusValues(pOut, 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
virtual double IntrinsicContribution(const erhic::VirtualParticle &) const
Definition: Tracker.cxx:55
virtual Double_t GetP() const =0
void Smear(const erhic::VirtualParticle &, ParticleMCS &)
Definition: Tracker.cxx:82
virtual double MultipleScatteringContribution(const erhic::VirtualParticle &) const
Definition: Tracker.cxx:43
double mSigmaRPhi
Point resolution.
Definition: Tracker.h:120
void SetVertexConstraint(bool constrain)
Definition: Tracker.cxx:100
double mNRadLengths
Number of radiation lengths (dimensionless)
Definition: Tracker.h:119
double mMagField
Magnetic field strength in Tesla.
Definition: Tracker.h:118
virtual double Resolution(const erhic::VirtualParticle &) const
Definition: Tracker.cxx:72
virtual bool Accepts(const erhic::VirtualParticle &) const =0
virtual double Generate(double midpoint, double width)
Definition: Distributor.cxx:45
virtual int NPoints(const erhic::VirtualParticle &) const =0
bool Is(const erhic::VirtualParticle &prt) const
Definition: Acceptance.cxx:46
virtual double LPrime(const erhic::VirtualParticle &) const =0
Tracker(double magneticField=2., double nRadiationLengths=0.01, double resolution=0.001)
Definition: Tracker.cxx:32
Int_t mFactor
Definition: Tracker.h:116
virtual TLorentzVector Get4Vector() const =0
virtual ~Tracker()
Definition: Tracker.cxx:40
virtual Double_t GetP() const
Definition: ParticleMCS.h:213
Abstract base class for a general particle.
Distributor Distribution
Random distribution.
Definition: Tracker.h:121