eventAnalysis  7.0-49-g0ac7482
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
eventAnalysisEnums.hxx
Go to the documentation of this file.
1 #ifndef OANALYSISDEFS_HXX
2 #define OANALYSISDEFS_HXX
3 
4 #include <iostream>
5 #include <stdexcept>
6 #include <string>
7 
8 #include "TEnv.h"
9 #include "TMath.h"
10 #include "TObject.h"
11 #include "TParticlePDG.h"
12 #include "TSystem.h"
13 
14 /// Utility tools to be shared across analysis classes
15 ///
16 /// Mostly bookkeeping routines to ensure consistency and
17 /// easy referencing
18 namespace eventAnalysisEnums {
19 
21  kFGD1 = 0,
22  kFGD2 = 1,
23  kTPC1 = 2,
24  kTPC2 = 3,
25  kTPC3 = 4,
26  kSFG = 5,
27  kTopHAT = 6,
29  kTOF = 8,
30  kP0D = 9, // include UsECal
31  kDsECal = 10,
40  kSMRD = 19,
41  kOffAxis = 20, /// the rest of the off-axis detector
42  kINGRID = 21,
43  kCavern = 22,
45 };
46 
47 
48 
58 };
59 
60 
61 const unsigned long DetMask[] = {
62  1UL<<kFGD1,
63  1UL<<kFGD2,
64  1UL<<kTPC1,
65  1UL<<kTPC2,
66  1UL<<kTPC3,
67  1UL<<kSFG,
68  1UL<<kTopHAT,
69  1UL<<kBottomHAT,
70  1UL<<kTOF,
71  1UL<<kP0D,
72  1UL<<kDsECal,
73  1UL<<kBrlECalTop,
74  1UL<<kBrlECalBottom,
75  1UL<<kBrlECalLeft,
76  1UL<<kBrlECalRight,
77  1UL<<kP0DECalTop,
78  1UL<<kP0DECalBottom,
79  1UL<<kP0DECalLeft,
80  1UL<<kP0DECalRight,
81  1UL<<kSMRD,
82  1UL<<kOffAxis,
83  1UL<<kINGRID,
84  1UL<<kCavern,
85  1UL<<kNSubdetectors
86 };
87 
88 inline void SetDetectorUsed(unsigned long &BitField, ESubdetector det){
89  BitField = BitField | 1UL<<det;
90 }
91 
92 inline bool GetDetectorUsed(unsigned long BitField, ESubdetector det){
93  return BitField & DetMask[det];
94 }
95 
96 
97 
98 inline ESubdetector PathToSubdetector(const std::string path) {
99 
100  // Below t2k/OA/Magnet,
101  // - Basket
102  // - LeftClam
103  // - RightClam
104  // exist.
105 
106  // Basket includes
107  // - P0D (including USECal)
108  // - DsECal
109  // - Tracker (including TPC1, TPC2, TPC3, FGD1, FGD2)
110  // - SFG
111  // - TopHAT, BottomHAT
112  // - DTOF, UTOF, BTOF, TTOF, STOF
113 
114  if (path.find("Basket") != std::string::npos) {
115  // P0D
116  if (path.find("P0D") != std::string::npos) {
117  return kP0D;
118  }
119  // DsECal
120  else if (path.find("DsECal") != std::string::npos) {
121  return kDsECal;
122  }
123  // FGD1
124  else if (path.find("FGD1") != std::string::npos) {
125  return kFGD1;
126  }
127  // FGD2
128  else if (path.find("FGD2") != std::string::npos) {
129  return kFGD2;
130  }
131  // TPC1
132  else if (path.find("TPC1") != std::string::npos) {
133  return kTPC1;
134  }
135  // TPC2
136  else if (path.find("TPC2") != std::string::npos) {
137  return kTPC2;
138  }
139  // TPC3
140  else if (path.find("TPC3") != std::string::npos) {
141  return kTPC3;
142  }
143  // SFGD
144  else if (path.find("SFG") != std::string::npos) {
145  return kSFG;
146  }
147  // HAT
148  else if (path.find("TopHAT") != std::string::npos) {
149  return kTopHAT;
150  }
151  else if (path.find("BottomHAT") != std::string::npos) {
152  return kBottomHAT;
153  }
154  // TOF
155  else if (path.find("TOF") != std::string::npos) {
156  return kTOF;
157  }
158  }
159 
160  // LeftClam/RightClam includes
161  // - BrlECal
162  // - P0DECal
163  // - MRD
164 
165  if (path.find("Clam") != std::string::npos) {
166  // BrlECal
167  if (path.find("BrlECal") != std::string::npos) {
168  if (path.find("Top") != std::string::npos) {
169  return kBrlECalTop;
170  } else if (path.find("Side") != std::string::npos) {
171  if (path.find("LeftClam") != std::string::npos) {
172  return kBrlECalLeft;
173  } else if (path.find("RightClam") != std::string::npos) {
174  return kBrlECalRight;
175  }
176  } else if (path.find("Bottom") != std::string::npos) {
177  return kBrlECalBottom;
178  }
179  }
180  // P0DECal
181  else if (path.find("P0DECal") != std::string::npos) {
182  if (path.find("Top") != std::string::npos) {
183  return kP0DECalTop;
184  } else if (path.find("Side") != std::string::npos) {
185  if (path.find("LeftClam") != std::string::npos) {
186  return kP0DECalLeft;
187  } else if (path.find("RightClam") != std::string::npos) {
188  return kP0DECalRight;
189  }
190  } else if (path.find("Bottom") != std::string::npos) {
191  return kP0DECalBottom;
192  }
193  }
194  // SMRD
195  else if ((path.find("MRD") != std::string::npos) ||
196  (path.find("FluxReturn") != std::string::npos)) {
197  return kSMRD;
198  }
199  }
200 
201  // Other parts of the off-axis
202  if (path.find("OA") != std::string::npos) {
203  return kOffAxis;
204  }
205  // INGRID
206  else if (path.find("INGRID") != std::string::npos) {
207  return kINGRID;
208  } else {
209  return kCavern;
210  }
211 }
212 
213 inline std::string DetectorName(ESubdetector const subdet) {
214  switch (subdet) {
215  case kFGD1: {
216  return "FGD1";
217  }
218  case kFGD2: {
219  return "FGD2";
220  }
221  case kTPC1: {
222  return "TPC1";
223  }
224  case kTPC2: {
225  return "TPC2";
226  }
227  case kTPC3: {
228  return "TPC3";
229  }
230  case kSFG: {
231  return "SFG";
232  }
233  case kTopHAT: {
234  return "THAT";
235  }
236  case kBottomHAT: {
237  return "BHAT";
238  }
239  case kTOF: {
240  return "TOF";
241  }
242  case kP0D: {
243  return "P0D";
244  }
245  case kDsECal: {
246  return "DsECal";
247  }
248  case kBrlECalTop: {
249  return "BrlECalTop";
250  }
251  case kBrlECalBottom: {
252  return "BrlECalBottom";
253  }
254  case kBrlECalLeft: {
255  return "BrlECalLeft";
256  }
257  case kBrlECalRight: {
258  return "BrlECalRight";
259  }
260  case kP0DECalTop: {
261  return "P0DECalTop";
262  }
263  case kP0DECalBottom: {
264  return "P0DECalBottom";
265  }
266  case kP0DECalLeft: {
267  return "P0DECalLeft";
268  }
269  case kP0DECalRight: {
270  return "P0DECalRight";
271  }
272  case kSMRD: {
273  return "SMRD";
274  }
275  case kOffAxis: {
276  return "OffAxis";
277  }
278  case kINGRID: {
279  return "INGRID";
280  }
281  case kCavern: {
282  return "Cavern";
283  }
284  default: { return "NONE"; }
285  }
286 }
287 
288 inline ESubdetector Next(ESubdetector const subdet) {
289  switch (subdet) {
290  case kFGD1: {
291  return kFGD2;
292  }
293  case kFGD2: {
294  return kTPC1;
295  }
296  case kTPC1: {
297  return kTPC2;
298  }
299  case kTPC2: {
300  return kTPC3;
301  }
302  case kTPC3: {
303  return kSFG;
304  }
305  case kSFG: {
306  return kTopHAT;
307  }
308  case kTopHAT: {
309  return kBottomHAT;
310  }
311  case kBottomHAT: {
312  return kTOF;
313  }
314  case kTOF: {
315  return kP0D;
316  }
317  case kP0D: {
318  return kDsECal;
319  }
320  case kDsECal: {
321  return kBrlECalTop;
322  }
323  case kBrlECalTop: {
324  return kBrlECalBottom;
325  }
326  case kBrlECalBottom: {
327  return kBrlECalLeft;
328  }
329  case kBrlECalLeft: {
330  return kBrlECalRight;
331  }
332  case kBrlECalRight: {
333  return kP0DECalTop;
334  }
335  case kP0DECalTop: {
336  return kP0DECalBottom;
337  }
338  case kP0DECalBottom: {
339  return kP0DECalLeft;
340  }
341  case kP0DECalLeft: {
342  return kP0DECalRight;
343  }
344  case kP0DECalRight: {
345  return kSMRD;
346  }
347  case kSMRD: {
348  return kOffAxis;
349  }
350  case kOffAxis: {
351  return kINGRID;
352  }
353  case kINGRID: {
354  return kCavern;
355  }
356  case kCavern: {
357  return kNSubdetectors;
358  }
359  default: { return kNSubdetectors; }
360  }
361 }
362 
363 inline ESubdetector IntToSubdetector(int const intdet) {
364  ESubdetector subdet = static_cast<ESubdetector>(intdet);
365  switch (subdet) {
366  case kFGD1: {
367  return kFGD1;
368  }
369  case kFGD2: {
370  return kFGD2;
371  }
372  case kTPC1: {
373  return kTPC1;
374  }
375  case kTPC2: {
376  return kTPC2;
377  }
378  case kTPC3: {
379  return kTPC3;
380  }
381  case kSFG: {
382  return kSFG;
383  }
384  case kTopHAT: {
385  return kTopHAT;
386  }
387  case kBottomHAT: {
388  return kBottomHAT;
389  }
390  case kTOF: {
391  return kTOF;
392  }
393  case kP0D: {
394  return kP0D;
395  }
396  case kDsECal: {
397  return kDsECal;
398  }
399  case kBrlECalTop: {
400  return kBrlECalTop;
401  }
402  case kBrlECalBottom: {
403  return kBrlECalBottom;
404  }
405  case kBrlECalLeft: {
406  return kBrlECalLeft;
407  }
408  case kBrlECalRight: {
409  return kBrlECalRight;
410  }
411  case kP0DECalTop: {
412  return kP0DECalTop;
413  }
414  case kP0DECalBottom: {
415  return kP0DECalBottom;
416  }
417  case kP0DECalLeft: {
418  return kP0DECalLeft;
419  }
420  case kP0DECalRight: {
421  return kP0DECalRight;
422  }
423  case kSMRD: {
424  return kSMRD;
425  }
426  case kOffAxis: {
427  return kOffAxis;
428  }
429  case kINGRID: {
430  return kINGRID;
431  }
432  case kCavern: {
433  return kCavern;
434  }
435  case kNSubdetectors: {
436  return kNSubdetectors;
437  }
438  default: {
439  std::cerr << "[ERROR](" << __FILE__ ":" << __LINE__
440  << "): Attempted to cast " << intdet
441  << " to a eventAnalysisEnums::ESubdetector." << std::endl;
442  throw std::make_pair("eventAnalysisEnums::ESubdetector.", intdet);
443  }
444  }
445 }
446 
447 inline EParticleCategory PDGInfoToCategory(const TParticlePDG *pdgInfo) {
448 
449  if (pdgInfo) {
450  Int_t pdg = pdgInfo->PdgCode();
451  // rounding Double_t charge/3 to closest Int_t (ROOT returns a double in
452  // units of e/3!)
453  Int_t charge = TMath::Nint(pdgInfo->Charge() / 3.0);
454  std::string particleClass = pdgInfo->ParticleClass();
455  // Charged Particles
456  if (charge != 0) {
457  // Leptons
458  if ((TMath::Abs(pdg) == 11) || (TMath::Abs(pdg) == 13) ||
459  (TMath::Abs(pdg) == 15)) {
460  return kChargedLepton;
461  }
462 
463  if (particleClass.find("Baryon") != std::string::npos) {
464  return kChargedBaryon;
465  } else if (particleClass.find("Meson") != std::string::npos) {
466  return kChargedMeson;
467  } else {
468  return kOtherCharged;
469  }
470  } else if (pdg == 22) {
471  return kPhoton;
472  } else {
473  return kOtherNeutral;
474  }
475  } else {
476  return kOther;
477  }
478 }
479 //
480 //inline EParticleCategory PDGToCategory(const Int_t pdg) {
481 // TParticlePDG pdgInfo(pdg); this constructor no longer exists in root 6
482 // and any way - it never did anything so this code is useless!
483 // return PDGInfoToCategory(&pdgInfo);
484 //}
485 
486 inline void UseCustomPDGTable() {
487  TString tablePath = TString(gSystem->Getenv("EVENTANALYSISROOT")) +
488  "/input/oaanalysis_pdg_table.txt";
489  bool Gottit = gSystem->AccessPathName(tablePath);
490  if (Gottit) {
491  std::cerr << "[ERROR](" << __FILE__ << ":" << __LINE__ << ") " << tablePath
492  << " is not accesible, cannot load extra PDG data. "
493  "(Expect: "
494  "${EVENTANALYSISROOT}/input/oaanalysis_pdg_table.txt)"
495  << std::endl;
496  throw std::exception();
497  }
498  gEnv->SetValue("Root.DatabasePDG", tablePath);
499 }
500 
501 inline std::string ParticleName(EParticleCategory const category) {
502  switch (category) {
503  case kChargedLepton: {
504  return "Charged Lepton";
505  }
506  case kChargedBaryon: {
507  return "Charged Baryon";
508  }
509  case kChargedMeson: {
510  return "Charged Meson";
511  }
512  case kPhoton: {
513  return "Photon";
514  }
515  case kOtherCharged: {
516  return "Charged Other";
517  }
518  case kOtherNeutral: {
519  return "Neutral Other";
520  }
521  case kOther: {
522  return "Other";
523  }
524  default: { return "NONE"; }
525  }
526 }
527 
528 inline EParticleCategory Next(EParticleCategory const category) {
529  switch (category) {
530  case kChargedLepton: {
531  return kChargedBaryon;
532  }
533  case kChargedBaryon: {
534  return kChargedMeson;
535  }
536  case kChargedMeson: {
537  return kPhoton;
538  }
539  case kPhoton: {
540  return kOtherCharged;
541  }
542  case kOtherCharged: {
543  return kOtherNeutral;
544  }
545  case kOtherNeutral: {
546  return kOther;
547  }
548  case kOther: {
549  return kNParticleCategories;
550  }
551  default: { return kNParticleCategories; }
552  }
553 }
554 }
555 
556 #endif // OANALYSISDEFS_HXX
const unsigned long DetMask[]
void SetDetectorUsed(unsigned long &BitField, ESubdetector det)
the rest of the off-axis detector
std::string DetectorName(ESubdetector const subdet)
EParticleCategory PDGInfoToCategory(const TParticlePDG *pdgInfo)
ESubdetector Next(ESubdetector const subdet)
std::string ParticleName(EParticleCategory const category)
bool GetDetectorUsed(unsigned long BitField, ESubdetector det)
ESubdetector PathToSubdetector(const std::string path)
ESubdetector IntToSubdetector(int const intdet)

Package Summary
Package Name: eventAnalysis
Package Version: 7.0-49-g0ac7482
Package Manager:

Generated on Mon Mar 25 2024 14:43:58 for eventAnalysis by doxygen 1.8.5