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 
38 void Acceptance::SetCharge(ECharge charge) {
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 
89 Acceptance::CustomCut::~CustomCut() {
90 }
91 
92 Acceptance::CustomCut::CustomCut()
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);
110  dim = ParseInputFunction(s, Kin1, Kin2);
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 
127 bool Acceptance::CustomCut::Contains(
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
virtual void Add(const CustomCut &)
Definition: Acceptance.cxx:165
virtual Double_t GetPhi() const =0
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())
Definition: Acceptance.cxx:145
virtual Double_t GetP() const =0
virtual ~Acceptance()
Definition: Acceptance.cxx:18
void AddZone(const Zone &)
Definition: Acceptance.cxx:26
virtual Double_t GetE() const =0
void SetGenre(int genre)
Definition: Acceptance.cxx:30
virtual Double_t GetPz() const =0
virtual Bool_t Contains(const erhic::VirtualParticle &) const
Definition: Acceptance.cxx:169
bool Is(const erhic::VirtualParticle &prt) const
Definition: Acceptance.cxx:46
virtual Double_t GetPt() const =0
void AddParticle(int particle)
Definition: Acceptance.cxx:42
TParticlePDG * Info() const
Definition: Pid.cxx:31
Acceptance(int genre=kAll)
Definition: Acceptance.cxx:21
virtual Pid Id() const =0
virtual Double_t GetTheta() const =0
Abstract base class for a general particle.
void SetCharge(ECharge charge)
Definition: Acceptance.cxx:38