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
Acceptance.cxx
Go to the documentation of this file.
1 
11 
12 #include <TDatabasePDG.h>
13 #include <TLorentzVector.h>
14 #include <TString.h>
15 
16 namespace Smear {
17 
19 }
20 
22 : mGenre(genre)
23 , mCharge(kAllCharges) {
24 }
25 
26 void Acceptance::AddZone(const Zone& z) {
27  mZones.push_back(z);
28 }
29 
30 void Acceptance::SetGenre(int n) {
31  if (n > 0 && n < 3) {
32  mGenre = n;
33  } else {
34  mGenre = 0;
35  } // if
36 }
37 
39  mCharge = charge;
40 }
41 
43  mParticles.insert(n);
44 }
45 
46 bool Acceptance::Is(const erhic::VirtualParticle& prt) const {
47  // Check for genre first (em, hadronic, any)
48  if (PGenre(prt) == 0 || (mGenre != 0 && PGenre(prt) != mGenre)) {
49  return false;
50  } // if
51  // Check if the particle charge matches the required value.
52  if (mCharge != kAllCharges) { // Don't need to check if accepting all
53  // Try to find the particle's charge via its TParticlePDG object.
54  TParticlePDG* pdg = prt.Id().Info();
55  if (pdg) {
56  bool charged = fabs(pdg->Charge()) > 0.;
57  // Check the charge against the requested value and return false
58  // if it is incorrect.
59  if ((kNeutral == mCharge && charged) ||
60  (kCharged == mCharge && !charged)) {
61  return false;
62  } // if
63  } else {
64  // The particle is unknown. We can't guarantee it's charge matches
65  // the requested value, so return false.
66  return false;
67  } // if
68  } // if
69  // Check against exclusive particle list
70  if (!mParticles.empty() && mParticles.count(prt.Id()) == 0) {
71  return false;
72  } // if
73  // If there are no Zones, accept everything that passed genre check
74  if (mZones.empty()) {
75  return true;
76  } // if
77  for (unsigned i(0); i < mZones.size(); i++) {
78  if (mZones.at(i).Contains(prt)) {
79  return true;
80  } // if
81  } // for
82  return false;
83 }
84 
85 //
86 // class Acceptance::CustomCut
87 //
88 
90 }
91 
93 : mFormula("CustomCutFormula", "0")
94 , dim(0)
95 , Kin1(kP)
96 , Kin2(kTheta)
97 , Min(-TMath::Infinity())
98 , Max(TMath::Infinity()) {
99 }
100 
101 Acceptance::CustomCut::CustomCut(const TString& formula,
102  double min, double max)
103 : mFormula("CustomCutFormula", "0")
104 , dim(0)
105 , Kin1(kP)
106 , Kin2(kTheta)
107 , Min(min)
108 , Max(max) {
109  TString s(formula);
111  if (!IsCoreType(Kin1) || !IsCoreType(Kin2)) {
112  std::cerr <<
113  "ERROR! Custom acceptance is not a function of E, p, theta, phi"
114  << std::endl;
115  } // if
116  if (1 == dim || 2 == dim) {
117  mFormula = TFormula("CustomCutFormula", s);
118  } else {
119  std::cerr <<
120  "ERROR! Provided custom acceptance is not of dimension 1 or 2."
121  << std::endl;
122  return;
123  } // if
124  std::cout << "Added custom cut " << formula << std::endl;
125 }
126 
128  const erhic::VirtualParticle& prt) const {
129  double x = GetVariable(prt, Kin1);
130  double y(0.);
131  if (2 == dim) {
132  y = GetVariable(prt, Kin2);
133  } // if
134  double z = mFormula.Eval(x, y);
135  return z >= Min && z < Max;
136 }
137 
138 //
139 // class Acceptance::Zone
140 //
141 
143 }
144 
145 Acceptance::Zone::Zone(double thMin, double thMax,
146  double phMin, double phMax,
147  double eMin, double eMax,
148  double pMin, double pMax,
149  double ptmin, double ptmax,
150  double pzmin, double pzmax)
151 : thetaMin(thMin)
152 , thetaMax(thMax)
153 , phiMin(phMin)
154 , phiMax(phMax)
155 , EMin(eMin)
156 , EMax(eMax)
157 , PMin(pMin)
158 , PMax(pMax)
159 , pTMin(ptmin)
160 , pTMax(ptmax)
161 , pZMin(pzmin)
162 , pZMax(pzmax) {
163 }
164 
166  CustomCuts.push_back(cut);
167 }
168 
170  bool accept(true);
171  const double theta = FixTheta(prt.GetTheta());
172  const double phi = FixPhi(prt.GetPhi());
173  if (theta < thetaMin || theta > thetaMax) {
174  accept = false;
175  } else if (phi < phiMin || phi > phiMax) {
176  accept = false;
177  } else if (prt.GetE() < EMin || prt.GetE() > EMax) {
178  accept = false;
179  } else if (prt.GetP() < PMin || prt.GetP() > PMax) {
180  accept = false;
181  } else if (prt.GetPz() < pZMin || prt.GetPz() > pZMax) {
182  accept = false;
183  } else if (prt.GetPt() < pTMin || prt.GetPt() > pTMax) {
184  accept = false;
185  } // if
186  // If it made it this far, test the custom cut(s)
187  if (accept) {
188  for (unsigned j(0); j < CustomCuts.size(); ++j) {
189  if (!CustomCuts.at(j).Contains(prt)) {
190  accept = false;
191  break;
192  } // if
193  } // for
194  } // if
195  return accept;
196 }
197 
198 } // namespace Smear
Smear::ParseInputFunction
int ParseInputFunction(TString &s, KinType &kin1, KinType &kin2)
Definition: Smear.cxx:18
Smear::Acceptance::Acceptance
Acceptance(int genre=kAll)
Default constructor.
Definition: Acceptance.cxx:21
Smear
Definition: Acceptance.cxx:16
Smear::Acceptance::Is
bool Is(const erhic::VirtualParticle &prt) const
This function determines if the particle provided lies within the acceptance of the detector.
Definition: Acceptance.cxx:46
Smear::FixPhi
double FixPhi(double phi)
Fix an azimuthal angle so that it lies within [0,2*pi).
Definition: Smear.h:101
erhic::VirtualParticle::GetPz
virtual Double_t GetPz() const =0
Returns the z component of 3-momentum.
Smear::Acceptance::CustomCut::Kin2
KinType Kin2
Definition: Acceptance.h:54
Smear::kAllCharges
@ kAllCharges
Definition: Smear.h:54
erhic::Pid::Info
TParticlePDG * Info() const
Returns the particle information object corresponding to this PDG code.
Definition: Pid.cxx:31
erhic::VirtualParticle::GetP
virtual Double_t GetP() const =0
Returns the magnitude of 3-momentum (GeV).
Smear::Acceptance::Zone::Add
virtual void Add(const CustomCut &)
Add a CustomCut to the list of acceptance tests.
Definition: Acceptance.cxx:165
Smear::kTheta
@ kTheta
Definition: Smear.h:44
Smear::Acceptance::AddParticle
void AddParticle(int particle)
Add a particle type to the list of particles to be smeared.
Definition: Acceptance.cxx:42
Smear::Acceptance::Zone
A single contiguous region of acceptance.
Definition: Acceptance.h:62
Smear::Acceptance::Zone::~Zone
virtual ~Zone()
Destructor.
Definition: Acceptance.cxx:142
erhic::VirtualParticle::GetE
virtual Double_t GetE() const =0
Returns total energy.
Smear::Acceptance::CustomCut::CustomCut
CustomCut()
Definition: Acceptance.cxx:92
Smear::Acceptance::mParticles
std::set< int > mParticles
Definition: Acceptance.h:173
Smear::Acceptance::CustomCut::dim
int dim
Definition: Acceptance.h:52
Smear::Acceptance::SetGenre
void SetGenre(int genre)
Select the class(es) of particles to accept.
Definition: Acceptance.cxx:30
Smear::Acceptance::SetCharge
void SetCharge(ECharge charge)
Select the charges of particles to accept.
Definition: Acceptance.cxx:38
Smear::FixTheta
double FixTheta(double theta)
Fix a polar angle so that it lies within [0,pi].
Definition: Smear.h:85
erhic::VirtualParticle
Abstract base class for a general particle.
Definition: VirtualParticle.h:23
Smear::IsCoreType
bool IsCoreType(KinType kin)
Definition: Smear.h:184
Smear::kCharged
@ kCharged
Definition: Smear.h:54
Acceptance.h
Smear::Acceptance::Zone::Contains
virtual Bool_t Contains(const erhic::VirtualParticle &) const
Returns true if the particle lies in this zone, false if not.
Definition: Acceptance.cxx:169
Smear::Acceptance::~Acceptance
virtual ~Acceptance()
Destructor.
Definition: Acceptance.cxx:18
Smear::kP
@ kP
Definition: Smear.h:44
erhic::VirtualParticle::GetPt
virtual Double_t GetPt() const =0
Returns momentum perpendicular to the beam direction.
erhic::VirtualParticle::GetTheta
virtual Double_t GetTheta() const =0
Returns the polar angle in the range [0, pi] radians.
Smear::Acceptance::CustomCut
A (min, max) range in some variable evaluated as an arbitrary function of theta, phi,...
Definition: Acceptance.h:44
Smear::Acceptance::mGenre
int mGenre
Definition: Acceptance.h:170
Smear::Acceptance::mZones
std::vector< Zone > mZones
Definition: Acceptance.h:172
Smear::Acceptance::mCharge
ECharge mCharge
Definition: Acceptance.h:171
Smear::Acceptance::CustomCut::mFormula
TFormula mFormula
Definition: Acceptance.h:51
Smear::Acceptance::Zone::Zone
Zone(double theta=0., double=TMath::Pi(), double phi=0., double=TMath::TwoPi(), double E=0., double=TMath::Infinity(), double p=0., double=TMath::Infinity(), double pt=0., double=TMath::Infinity(), double pz=-TMath::Infinity(), double=TMath::Infinity())
Constructor.
Definition: Acceptance.cxx:145
Smear::Acceptance::CustomCut::~CustomCut
virtual ~CustomCut()
Definition: Acceptance.cxx:89
Smear::ECharge
ECharge
Particle charged.
Definition: Smear.h:53
Smear::Acceptance::AddZone
void AddZone(const Zone &)
Add a new zone with user-specified coverage.
Definition: Acceptance.cxx:26
Smear::PGenre
int PGenre(const erhic::VirtualParticle &prt)
Determine particle "genre".
Definition: Smear.h:68
erhic::VirtualParticle::GetPhi
virtual Double_t GetPhi() const =0
Returns the polar angle in the range [0, 2pi] radians.
Smear::Acceptance::CustomCut::Kin1
KinType Kin1
Definition: Acceptance.h:53
Smear::GetVariable
double GetVariable(const erhic::VirtualParticle &prt, KinType kin)
Returns the kinematic variable associated with kin from the input particle.
Definition: Smear.h:108
Smear::kNeutral
@ kNeutral
Definition: Smear.h:54
Smear::Acceptance::CustomCut::Contains
virtual bool Contains(const erhic::VirtualParticle &) const
Definition: Acceptance.cxx:127
erhic::VirtualParticle::Id
virtual Pid Id() const =0
Returns identity information for the Particle species.