StructuredGenTree.cxx
Go to the documentation of this file.
1 
3 #include <climits>
4 
5 using namespace garana;
6 
8 
9  SetupRead(tree); //initialize tree pointer in TreeReader instance and set branch address
10 
11 }//
12 
14 {
15  // Set branch addresses and branch pointers
16  fTreeIn->SetBranchAddress("Event", &fEvent, &b_Event);
17  fTreeIn->SetBranchAddress("GIndex", &fGIndex, &b_GIndex);
18  //fTreeIn->SetBranchAddress("FSIndex", &fFSIndex, &b_FSIndex);
19  fTreeIn->SetBranchAddress("GTruth", &fGTruth, &b_GTruth);
20  fTreeIn->SetBranchAddress("FSParticles", &fFSParticles, &b_FSParticles);
21 
22  return true;
23 }//
24 
25 // get number of MCTruths in this event
26 const UInt_t StructuredGenTree::NGen() const {
27  return fFSParticles->size();
28 }//
29 
30 //get pointer to igen^th GTruth object
31 const GTruth* StructuredGenTree::GetGTruth(const UInt_t& igen) const {
32 
33  if(!IsGenie(igen)) {
34  const GTruth* ptr = nullptr;
35  return ptr;
36  }
37  else {
38  const GTruth* ptr = &(fGTruth->at(igen));
39  return ptr;
40  }
41 }
42 
43 // get number of FSParticles associated with igen'th MCTruth
44 const UInt_t StructuredGenTree::NFSParticles(const UInt_t& igen ) const {
45 
46  UInt_t index = CheckFSRange(igen) ? igen : 0;
47  return fFSParticles->at(index).size();
48 
49 }//
50 
51 //Fill a passed vector with GenFSParticles for the igen'th MCTruth
52 const std::vector<FSParticle>* StructuredGenTree::GetParticles(const UInt_t& igen) const {
53 
54  UInt_t index = CheckFSRange(igen) ? igen : 0;
55  return &(fFSParticles->at(index));
56 
57 }//
58 
59 // returns true if MCTruth (FSParticles) came from GENIE
60 const Bool_t StructuredGenTree::IsGenie(const UInt_t& igen) const {
61 
62  if(fGIndex->size()==fFSParticles->size()){
63  UInt_t index = CheckFSRange(igen) ? igen : 0;
64  return fGIndex->at(index) != -1;
65  }
66  else{
67  std::cout << "ERROR: StructuredGenTree::IsGenie -> "
68  << " sizeof(GIndex) != sizeof(FSParticles)"
69  << std::endl;
70  return false;
71  }
72 }//
73 
74 // check if nu interaction is CC (supports only GENIE ints for now)
75 const Bool_t StructuredGenTree::IsCC(const UInt_t& igen) const {
76 
77  if(IsGenie(igen))
78  return fGTruth->at(igen).fGint == 2;
79  else
80  return false;
81 
82 }//
83 
84 // Get the region code for the neutrino vertex
85 const int StructuredGenTree::NuRegion(const UInt_t& igen ) const {
86 
87  if(IsGenie(igen))
88  return fGTruth->at(igen).fVertexRegion;
89  else
90  return INT_MAX;
91 
92 }//
93 
94 // Get the GENIE neutrino PDG code
95 const Int_t StructuredGenTree::NuPDG(const UInt_t& igen) const {
96 
97  if(IsGenie(igen))
98  return fGTruth->at(igen).fProbePDG;
99  else
100  return INT_MAX;
101 
102 }
103 
104 // Get the GENIE neutrino four-momentum prior to interacting
105 const TLorentzVector* StructuredGenTree::NuP(const UInt_t& igen) {
106 
107  if(IsGenie(igen))
108  return &(fGTruth->at(igen).fProbeP4);
109 
110  else
111  return nullptr;
112 }
113 
114 //Get the GENIE neutrino vertex four-position
115 const TLorentzVector* StructuredGenTree::NuVertex(const UInt_t& igen) {
116 
117  if(IsGenie(igen))
118  return &(fGTruth->at(igen).fVertex);
119 
120  else
121  return nullptr;
122 }
123 
124 const int StructuredGenTree::ScatterCode(const UInt_t& igen) const {
125  return GetGTruth(igen)->fGscatter;
126 }
127 
128 const int StructuredGenTree::InteractCode(const UInt_t& igen) const {
129  return GetGTruth(igen)->fGint;
130 }
131 
132 const TLorentzVector* StructuredGenTree::TgtP4(const UInt_t& igen) const {
133  return &(GetGTruth(igen)->fTgtP4);
134 }
135 
136 const int StructuredGenTree::TgtZ(const UInt_t& igen ) const {
137  return GetGTruth(igen)->ftgtZ;
138 }
139 
140 const int StructuredGenTree::TgtA(const UInt_t& igen ) const {
141  return GetGTruth(igen)->ftgtA;
142 }
143 
144 const int StructuredGenTree::TgtPDG(const UInt_t& igen ) const {
145  return GetGTruth(igen)->ftgtPDG;
146 }
147 
148 const int StructuredGenTree::HitNucPDG(const UInt_t& igen ) const {
149  return GetGTruth(igen)->fHitNucPDG;
150 }
151 
152 const TLorentzVector* StructuredGenTree::HitNucP4(const UInt_t& igen ) const {
153  return &(GetGTruth(igen)->fHitNucP4);
154 }
155 
156 const double StructuredGenTree::Q2(const UInt_t& igen ) const {
157  return GetGTruth(igen)->fgQ2;
158 }
159 
160 const double StructuredGenTree::q2(const UInt_t& igen ) const {
161  return GetGTruth(igen)->fgq2;
162 }
163 
164 const double StructuredGenTree::W(const UInt_t& igen ) const {
165  return GetGTruth(igen)->fgW;
166 }
167 
168 const double StructuredGenTree::T(const UInt_t& igen ) const {
169  return GetGTruth(igen)->fgT;
170 }
171 
172 const double StructuredGenTree::X(const UInt_t& igen ) const {
173  return GetGTruth(igen)->fgX;
174 }
175 
176 const double StructuredGenTree::Y(const UInt_t& igen ) const {
177  return GetGTruth(igen)->fgY;
178 }
179 
180 const TLorentzVector* StructuredGenTree::FSLeptonP4(const UInt_t& igen ) const {
181  return &(GetGTruth(igen)->fFSleptonP4);
182 }
183 
184 const TLorentzVector* StructuredGenTree::FSHadSystP4(const UInt_t& igen ) const {
185  return &(GetGTruth(igen)->fFShadSystP4);
186 }
187 
188 const int StructuredGenTree::NumNuProton(const UInt_t& igen) const {
189  return GetGTruth(igen)->fNumProton;
190 }
191 
192 const int StructuredGenTree::NumNuNeutron(const UInt_t& igen) const {
193  return GetGTruth(igen)->fNumNeutron;
194 }
195 
196 const int StructuredGenTree::NumNuPi0(const UInt_t& igen) const {
197  return GetGTruth(igen)->fNumPi0;
198 }
199 
200 const int StructuredGenTree::NumNuPiPlus(const UInt_t& igen) const {
201  return GetGTruth(igen)->fNumPiPlus;
202 }
203 
204 const int StructuredGenTree::NumNuPiMinus(const UInt_t& igen) const {
205  return GetGTruth(igen)->fNumPiMinus;
206 }
207 
208 // Calculate the total energy of the FS system (excludes fleeting neutrinos e.g. from NC ints)
209 const Float_t StructuredGenTree::FSTotEnergy(const UInt_t& igen) const {
210 
211  Float_t e = 0.;
212  for(auto const& fsp : fFSParticles->at(igen))
213  e += fsp.E();
214 
215  return e;
216 }
217 
218 const Float_t StructuredGenTree::FSEnergy(const UInt_t& igen, const UInt_t& ifsp) const {
219  return fFSParticles->at(igen)[ifsp].E();
220 }
221 
222 const Float_t StructuredGenTree::FSPDG(const UInt_t& igen, const UInt_t& ifsp) const {
223  return fFSParticles->at(igen)[ifsp].PDG();
224 }
225 
226 const Int_t StructuredGenTree::FSTrackId(const UInt_t& igen, const UInt_t& ifsp) const {
227  return fFSParticles->at(igen)[ifsp].TrackId();
228 }
229 
230 //utility method for checking validity of index for FSParticles
231 const Bool_t StructuredGenTree::CheckFSRange(const UInt_t& igen) const {
232  if(igen < fFSParticles->size())
233  return kTRUE;
234  else{
235  std::cout << "ERROR: StructuredGenTree -> "
236  << "passed index to FSParticle is out of range ("
237  << igen << " vs. " << fFSParticles->size() << ")."
238  << " Returning first element."
239  << std::endl;
240  return kFALSE;
241  }
242 }//
const Float_t FSTotEnergy(const UInt_t &igen) const override
double fgq2
Definition: GTruth.h:60
const GTruth * GetGTruth(const UInt_t &igen) const
TLorentzVector fTgtP4
Definition: GTruth.h:41
const TLorentzVector * FSLeptonP4(const UInt_t &igen) const override
final state primary lepton 4-momentum (LAB frame)
const Bool_t CheckFSRange(const UInt_t &igen) const
const Float_t FSPDG(const UInt_t &igen, const UInt_t &ifsp) const override
const TLorentzVector * HitNucP4(const UInt_t &igen) const override
hit nucleon (initial) 4-momentum
int fNumPiMinus
number of pi minuses after reaction, before FSI
Definition: GTruth.h:77
const int NumNuPiPlus(const UInt_t &igen) const override
number of pi pluses after reaction, before FSI
const int InteractCode(const UInt_t &igen) const override
GENIE interaction code.
int fNumProton
number of protons after reaction, before FSI
Definition: GTruth.h:73
const double W(const UInt_t &igen) const override
TTree * fTreeIn
pointer to the analyzed TTree or TChain
Definition: TreeReader.h:51
int fGscatter
neutrino scattering code
Definition: GTruth.h:54
const TLorentzVector * NuVertex(const UInt_t &igen) override
4-position of neutrino vertex
double fgY
Definition: GTruth.h:64
TLorentzVector fFSleptonP4
generated final state primary lepton (LAB frame) // added version 13
Definition: GTruth.h:65
double fgT
Definition: GTruth.h:62
int fNumNeutron
number of neutrons after reaction, before FSI
Definition: GTruth.h:74
const int NumNuPi0(const UInt_t &igen) const override
number of pi0 after reaction, before FSI
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
const Int_t FSTrackId(const UInt_t &igen, const UInt_t &ifsp) const override
const Int_t NuPDG(const UInt_t &igen) const override
neutrino PDG code
const TLorentzVector * NuP(const UInt_t &igen) override
initial neutrino 4-momentum
const vector< FSParticle > * GetParticles(const UInt_t &igen) const
const int TgtZ(const UInt_t &igen) const override
target Z
const double e
const double X(const UInt_t &igen) const override
double fgX
Definition: GTruth.h:63
const double q2(const UInt_t &igen) const override
int ftgtPDG
PDG of Target Nucleus, nucleon only if free.
Definition: GTruth.h:46
TLorentzVector fHitNucP4
Definition: GTruth.h:50
int fNumPi0
number of pi0 after reaction, before FSI
Definition: GTruth.h:75
const double Y(const UInt_t &igen) const override
const int TgtA(const UInt_t &igen) const override
target A
const int NumNuPiMinus(const UInt_t &igen) const override
number of pi minuses after reaction, before FSI
const double Q2(const UInt_t &igen) const override
vector< vector< FSParticle > > * fFSParticles
const Bool_t IsGenie(const UInt_t &igen) const override
const int NumNuProton(const UInt_t &igen) const override
number of protons after reaction, before FSI
double fgW
Definition: GTruth.h:61
const TLorentzVector * FSHadSystP4(const UInt_t &igen) const override
final state hadronic system 4-momentum(LAB frame)
const double T(const UInt_t &igen) const override
const int NuRegion(const UInt_t &igen) const override
region code where the vertex is located
const Bool_t IsCC(const UInt_t &igen) const override
whether interaction is CC or not
const TLorentzVector * TgtP4(const UInt_t &igen) const override
target 4-momentum
const int NumNuNeutron(const UInt_t &igen) const override
number of neutrons after reaction, before FSI
TBranch * b_Event
Definition: TreeReader.h:54
void SetupRead(TTree *tree)
Definition: TreeReader.cxx:6
int fNumPiPlus
number of pi pluses after reaction, before FSI
Definition: GTruth.h:76
const int ScatterCode(const UInt_t &igen) const override
GENIE neutrino scattering code.
int fHitNucPDG
hit nucleon PDG code
Definition: GTruth.h:47
const Float_t FSEnergy(const UInt_t &igen, const UInt_t &ifsp) const override
bool SetBranchAddresses() override
< inherited from TreeReader
int fGint
interaction code
Definition: GTruth.h:55
const int HitNucPDG(const UInt_t &igen) const override
hit nucleon PDG code
const std::vector< Int_t > * fGIndex
Definition: GenTree.h:66
Int_t fEvent
event number for tree entry
Definition: TreeReader.h:55
TLorentzVector fFShadSystP4
generated final state hadronic system (LAB frame)
Definition: GTruth.h:66
const Int_t TgtPDG(const UInt_t &igen) const override
PDG of Target Nucleus, nucleon only if free.
TBranch * b_GIndex
Definition: GenTree.h:67
double fgQ2
< these are for the internal (on shell) genie kinematics
Definition: GTruth.h:59
vector< GTruth > * fGTruth
QTextStream & endl(QTextStream &s)
const UInt_t NGen() const override
const UInt_t NFSParticles(const UInt_t &igen) const override