ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
AtCutHEIST.cxx
Go to the documentation of this file.
1 #include "AtCutHEIST.h"
2 
3 #include <FairLogger.h>
4 #include <FairRootManager.h>
5 
6 #include <TCollection.h> // for TIter
7 #include <TCutG.h>
8 #include <TFile.h>
9 #include <TList.h> // for TList
10 #include <TObject.h> // for TObject
11 
12 #include <utility> // for tuple_element<>::type
13 
14 class TTree;
15 
16 AtCutHEIST::AtCutHEIST(TString treeFile, TString cutFile, TString treeName)
17  : fFile(TFile::Open(treeFile)), fReader(treeName, fFile.get()), fMusic(fReader, "MUSIC"), fUsMcp(fReader, "USMCP"),
18  fDsMcp(fReader, "DSMCP"), fCutFile(TFile::Open(cutFile))
19 {
20  if (fReader.GetTree() == nullptr)
21  LOG(fatal) << "Could not find " << treeName << " in " << treeFile;
22  if (fCutFile == nullptr)
23  LOG(fatal) << "Could not find cut file " << cutFile;
24 }
25 
26 AtCutHEIST::AtCutHEIST(TTree *tree, TString cutFile)
27  : fFile(nullptr), fReader(tree), fMusic(fReader, "MUSIC"), fUsMcp(fReader, "USMCP"), fDsMcp(fReader, "DSMCP"),
28  fCutFile(TFile::Open(cutFile))
29 {
30  if (fReader.GetTree() == nullptr)
31  LOG(fatal) << "Passed tree is null!";
32  if (fCutFile == nullptr)
33  LOG(fatal) << "Could not find cut file " << cutFile;
34 }
35 
40 bool AtCutHEIST::AddSpecies(std::string species)
41 {
42  // Return early if this species has already been added
43  if (fSpecies.find(species) != fSpecies.end())
44  return true;
45 
46  auto *cut = static_cast<TCutG *>(fCutFile->GetObjectChecked(species.data(), "TCutG"));
47  if (cut == nullptr) {
48  LOG(error) << "Could not find cut " << species << " in file";
49  return false;
50  }
51 
52  fSpecies[species] = cut;
53  if (fOutFile) {
54  fOutFile->cd();
55  cut->Write();
56  }
57  return true;
58 }
59 
61 {
62  auto keys = fCutFile->GetListOfKeys();
63  for (auto key : *keys)
64  AddSpecies(key->GetName());
65 }
66 
68 {
69  fReader.SetEntry(FairRootManager::Instance()->GetEntryNr());
70  auto energy = GetEnergy();
71  auto tof = GetToF();
72  LOG(debug) << "Energy: " << energy << " ToF: " << tof;
73 
74  for (auto &[name, cut] : fSpecies) {
75  bool inCut = cut->IsInside(tof, energy);
76 
77  if (inCut) {
78  LOG(info) << "Event is " << name;
79  return true;
80  }
81  }
82  return false;
83 }
84 
86 {
87  fReader.SetEntry(FairRootManager::Instance()->GetEntryNr());
88  auto energy = GetEnergy();
89  auto tof = GetToF();
90 
91  for (auto &[name, cut] : fSpecies) {
92  bool inCut = cut->IsInside(tof, energy);
93 
94  if (inCut) {
95  return name;
96  }
97  }
98  return "";
99 }
100 
101 double AtCutHEIST::GetEnergy()
102 {
103  double en = 0;
104  for (int i = 0; i < 9; ++i)
105  en += fMusic->GetEnergy(i);
106  return 11.17 * en;
107 }
108 
109 double AtCutHEIST::GetToF()
110 {
111  if (fUsMcp->GetTimeAnode().size() > 0)
112  return fDsMcp->GetTimeAnode()[0] - fUsMcp->GetTimeAnode()[0] + 728;
113  else
114  return 0;
115 }
AtCutHEIST::AddSpecies
bool AddSpecies(std::string species)
Add a species to accept in the cut.
Definition: AtCutHEIST.cxx:40
AtCutHEIST.h
AtCutHEIST::GetSpecies
std::string GetSpecies()
Definition: AtCutHEIST.cxx:85
AtCutHEIST::AddAllSpecies
void AddAllSpecies()
Definition: AtCutHEIST.cxx:60
AtCutHEIST::operator()
bool operator()()
Definition: AtCutHEIST.cxx:67
AtCutHEIST::AtCutHEIST
AtCutHEIST(TTree *tree, TString cutFile)
Definition: AtCutHEIST.cxx:26