EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Acceptance.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Acceptance.cxx
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 
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  if ( mGenre != 0 && PGenre(prt) != mGenre ) {
52  return false;
53  } // if
54 
55  // Check if the particle charge matches the required value.
56  if (mCharge != kAllCharges) { // Don't need to check if accepting all
57  // Try to find the particle's charge via its TParticlePDG object.
58  TParticlePDG* pdg = prt.Id().Info();
59  if (pdg) {
60  bool charged = fabs(pdg->Charge()) > 0.;
61  // Check the charge against the requested value and return false
62  // if it is incorrect.
63  if ((kNeutral == mCharge && charged) ||
64  (kCharged == mCharge && !charged)) {
65  return false;
66  } // if
67  } else {
68  // The particle is unknown. We can't guarantee it's charge matches
69  // the requested value, so return false.
70  return false;
71  } // if
72  } // if
73  // Check against exclusive particle list
74  if (!mParticles.empty() && mParticles.count(prt.Id()) == 0) {
75  return false;
76  } // if
77  // If there are no Zones, accept everything that passed genre check
78  if (mZones.empty()) {
79  return true;
80  } // if
81  for (unsigned i(0); i < mZones.size(); i++) {
82  if (mZones.at(i).Contains(prt)) {
83  return true;
84  } // if
85  } // for
86  return false;
87 }
88 
89 //
90 // class Acceptance::CustomCut
91 //
92 
94 }
95 
97 : mFormula("CustomCutFormula", "0")
98 , dim(0)
99 , Kin1(kP)
100 , Kin2(kTheta)
101 , Min(-TMath::Infinity())
102 , Max(TMath::Infinity()) {
103 }
104 
106 }
107 
109  : func(func)
110 { }
111 
112 // bool Acceptance::CustomCutFunction::Contains(const erhic::VirtualParticle& p) const {
113 // return func ( p );
114 // }
115 
116 Acceptance::CustomCut::CustomCut(const TString& formula,
117  double min, double max)
118 : mFormula("CustomCutFormula", "0")
119 , dim(0)
120 , Kin1(kP)
121 , Kin2(kTheta)
122 , Min(min)
123 , Max(max) {
124  TString s(formula);
126  if (!IsCoreType(Kin1) || !IsCoreType(Kin2)) {
127  std::cerr <<
128  "ERROR! Custom acceptance is not a function of E, p, theta, phi"
129  << std::endl;
130  } // if
131  if (1 == dim || 2 == dim) {
132  mFormula = TFormula("CustomCutFormula", s);
133  } else {
134  std::cerr <<
135  "ERROR! Provided custom acceptance is not of dimension 1 or 2."
136  << std::endl;
137  return;
138  } // if
139  std::cout << "Added custom cut " << formula << std::endl;
140 }
141 
143  const erhic::VirtualParticle& prt) const {
144  double x = GetVariable(prt, Kin1);
145  double y(0.);
146  if (2 == dim) {
147  y = GetVariable(prt, Kin2);
148  } // if
149  double z = mFormula.Eval(x, y);
150  return z >= Min && z < Max;
151 }
152 
153 //
154 // class Acceptance::Zone
155 //
156 
158 }
159 
160 Acceptance::Zone::Zone(double thMin, double thMax,
161  double phMin, double phMax,
162  double eMin, double eMax,
163  double pMin, double pMax,
164  double ptmin, double ptmax,
165  double pzmin, double pzmax)
166 : thetaMin(thMin)
167 , thetaMax(thMax)
168 , phiMin(phMin)
169 , phiMax(phMax)
170 , EMin(eMin)
171 , EMax(eMax)
172 , PMin(pMin)
173 , PMax(pMax)
174 , pTMin(ptmin)
175 , pTMax(ptmax)
176 , pZMin(pzmin)
177 , pZMax(pzmax) {
178 }
179 
181  CustomCuts.push_back(cut);
182 }
183 
185  bool accept(true);
186  const double theta = FixTheta(prt.GetTheta());
187  const double phi = FixPhi(prt.GetPhi());
188  if (theta < thetaMin || theta > thetaMax) {
189  accept = false;
190  } else if (phi < phiMin || phi > phiMax) {
191  accept = false;
192  } else if (prt.GetE() < EMin || prt.GetE() > EMax) {
193  accept = false;
194  } else if (prt.GetP() < PMin || prt.GetP() > PMax) {
195  accept = false;
196  } else if (prt.GetPz() < pZMin || prt.GetPz() > pZMax) {
197  accept = false;
198  } else if (prt.GetPt() < pTMin || prt.GetPt() > pTMax) {
199  accept = false;
200  } // if
201  // If it made it this far, test the custom cut(s)
202  if (accept) {
203  for (unsigned j(0); j < CustomCuts.size(); ++j) {
204  if (!CustomCuts.at(j).Contains(prt)) {
205  accept = false;
206  break;
207  } // if
208  } // for
209  } // if
210  return accept;
211 }
212 
213 } // namespace Smear