StructuredG4Tree.cxx
Go to the documentation of this file.
1 /*
2  * StructuredG4Tree.cxx
3  *
4  * Created on: Feb 18, 2021
5  * Author: chilgenb
6  */
7 
9 
10 using namespace garana;
11 using std::vector;
12 
14 
15  SetupRead(tree); //initialize tree pointer in TreeReader instance and set branch address
16 }//
17 
19 
20  fTreeIn->SetBranchAddress("Event", &fEvent, &b_Event );
21  fTreeIn->SetBranchAddress("TruthIndex", &fG4TruthIndex, &b_G4TruthIndex);
22  //fTreeIn->SetBranchAddress("FSIndex", &fG4FSIndex, &b_G4FSIndex);
23  fTreeIn->SetBranchAddress("G4Particles", &fG4Particles, &b_G4Particles );
24 
25  return true;
26 }//
27 
28 const bool StructuredG4Tree::IsPrimary(const UInt_t& iparticle) const {
29  if(GetParticle(iparticle)->ParentPDG()==INT_MAX) return true;
30  else return false;
31 }
32 
33 const Int_t StructuredG4Tree::PDG(const UInt_t& iparticle) const {
34  return GetParticle(iparticle)->PDG();
35 }
36 
37 const G4Particle* StructuredG4Tree::GetParticle(const UInt_t& iparticle) const {
38 
39  try {
40  if(iparticle<NSim())
41  return &(this->fG4Particles->at(iparticle));
42  else
43  throw iparticle;
44  }
45  catch(UInt_t iparticle){
46  std::cerr << "ERROR(StructuredG4Tree::GetParticle): index out of bounds (NSim ="
47  << NSim() << " vs. requested index = " << iparticle << ")" << std::endl;
48  }
49  return nullptr;
50 
51 }//
52 
53 /*vector<G4Particle*>* StructuredG4Tree::GetG4Particles() {
54 
55  fG4ps->clear();
56  for(UInt_t i=0; i<NSim(); i++){
57  fG4ps->push_back(GetParticle(i));
58  }
59  return fG4ps;
60 
61 }//*/
62 
63 const UInt_t StructuredG4Tree::NSim() const {
64  return fG4Particles->size();
65 }//
66 
67 const UInt_t StructuredG4Tree::NPoints(const UInt_t& iparticle) const {
68  return GetParticle(iparticle)->NPoints();
69 }//
70 
71 const UInt_t StructuredG4Tree::NRegions(const UInt_t& iparticle) const {
72  return GetParticle(iparticle)->NRegions();
73 }
74 const Int_t StructuredG4Tree::Region(const UInt_t& iparticle, const UInt_t& iregion) const {
75  return GetParticle(iparticle)->Region(iregion);
76 }
77 const vector<const TLorentzVector*>* StructuredG4Tree::SimMomEnter(const UInt_t& iparticle) const {
78  auto v = new vector<const TLorentzVector*>();
79  for(size_t ireg=0; ireg<NRegions(iparticle); ireg++){
80  v->push_back(GetParticle(iparticle)->MomentumEnter(ireg));
81  }
82 
83  return v;
84 }
85 const vector<const TLorentzVector*>* StructuredG4Tree::SimMomExit(const UInt_t& iparticle) const {
86  auto v = new vector<const TLorentzVector*>();
87  for(size_t ireg=0; ireg<NRegions(iparticle); ireg++){
88  v->push_back(GetParticle(iparticle)->MomentumExit(ireg));
89  }
90 
91  return v;
92 }
93 const vector<const TLorentzVector*>* StructuredG4Tree::SimPosEnter(const UInt_t& iparticle) const {
94  auto v = new vector<const TLorentzVector*>();
95  for(size_t ireg=0; ireg<NRegions(iparticle); ireg++){
96  v->push_back(GetParticle(iparticle)->PositionEnter(ireg));
97  }
98 
99  return v;
100 }
101 const vector<const TLorentzVector*>* StructuredG4Tree::SimPosExit(const UInt_t& iparticle) const {
102  auto v = new vector<const TLorentzVector*>();
103  for(size_t ireg=0; ireg<NRegions(iparticle); ireg++){
104  v->push_back(GetParticle(iparticle)->PositionExit(ireg));
105  }
106 
107  return v;
108 }
109 
110 const TLorentzVector* StructuredG4Tree::SimMomEnter(const UInt_t& iparticle, const UInt_t& iregion) const {
111  return GetParticle(iparticle)->MomentumEnter(iregion);
112 }
113 
114 const TLorentzVector* StructuredG4Tree::SimMomExit(const UInt_t& iparticle, const UInt_t& iregion) const {
115  return GetParticle(iparticle)->MomentumExit(iregion);
116 }
117 
118 const TLorentzVector* StructuredG4Tree::SimPosEnter(const UInt_t& iparticle, const UInt_t& iregion) const {
119  return GetParticle(iparticle)->PositionEnter(iregion);
120 }
121 const TLorentzVector* StructuredG4Tree::SimPosExit(const UInt_t& iparticle, const UInt_t& iregion) const {
122  return GetParticle(iparticle)->PositionExit(iregion);
123 }
124 
125 const int StructuredG4Tree::ParentPDG(const UInt_t& iparticle) const {
126  return GetParticle(iparticle)->ParentPDG();
127 }//
128 
129 const int StructuredG4Tree::ProgenitorPDG(const UInt_t& iparticle) const {
130  return GetParticle(iparticle)->ProgenitorPDG();
131 }//
132 
133 const int StructuredG4Tree::TrackID(const UInt_t& iparticle) const {
134  return GetParticle(iparticle)->TrackID();
135 }//
136 
137 const int StructuredG4Tree::ParentTrackID(const UInt_t& iparticle) const {
138  return GetParticle(iparticle)->ParentTrackID();
139 }//
140 
141 const int StructuredG4Tree::ProgenitorTrackID(const UInt_t& iparticle) const {
142  return GetParticle(iparticle)->ProgenitorTrackID();
143 }//
144 
145 const Int_t StructuredG4Tree::ProcessI(const UInt_t& iparticle) const {
146  return GetParticle(iparticle)->ProcessI();
147 }//
148 
149 const Int_t StructuredG4Tree::ProcessF(const UInt_t& iparticle) const {
150  return GetParticle(iparticle)->ProcessF();
151 }//
152 
153 
154 
const int ParentPDG(const UInt_t &iparticle) const override
parent particle&#39;s PDG code
const TLorentzVector * MomentumEnter(const size_t &iregion) const
Definition: G4Particle.h:61
int const & NPoints() const
Definition: G4Particle.h:50
const UInt_t NSim() const override
number of particles
int const & ProcessI() const
Definition: G4Particle.h:57
size_t NRegions() const
Definition: G4Particle.h:65
const int ParentTrackID(const UInt_t &iparticle) const override
G4 track ID of parent particle.
struct vector vector
const UInt_t NPoints(const UInt_t &iparticle) const override
number of G4 steps (i.e. trajectory points)
TTree * fTreeIn
pointer to the analyzed TTree or TChain
Definition: TreeReader.h:51
const TLorentzVector * MomentumExit(const size_t &iregion) const
Definition: G4Particle.h:62
int const & ParentTrackID() const
Definition: G4Particle.h:55
const bool IsPrimary(const UInt_t &iparticle) const override
did particle come from generator?
const vector< const TLorentzVector * > * SimMomEnter(const UInt_t &iparticle) const override
particle 4-momentum at entry point, all regions
vector< UInt_t > * fG4TruthIndex
Definition: G4Tree.h:71
const Int_t ProcessF(const UInt_t &iparticle) const override
code for process that killed this one
const TLorentzVector * PositionExit(const size_t &iregion) const
Definition: G4Particle.h:60
int const & ParentPDG() const
Definition: G4Particle.h:52
const vector< const TLorentzVector * > * SimMomExit(const UInt_t &iparticle) const override
particle 4-momentum at exit point, all regions
int const & ProcessF() const
Definition: G4Particle.h:58
const UInt_t NRegions(const UInt_t &iparticle) const override
number of regions traversed by particle
vector< G4Particle > * fG4Particles
&#39;condensed&#39; nusimdata::MCParticles from G4
TBranch * b_G4TruthIndex
Definition: G4Tree.h:73
const TLorentzVector * PositionEnter(const size_t &iregion) const
Definition: G4Particle.h:59
TBranch * b_Event
Definition: TreeReader.h:54
int const & TrackID() const
Definition: G4Particle.h:54
void SetupRead(TTree *tree)
Definition: TreeReader.cxx:6
bool SetBranchAddresses() override
const Int_t ProcessI(const UInt_t &iparticle) const override
code for process that created this one
const Int_t PDG(const UInt_t &iparticle) const override
particle PDG code
int const & PDG() const
Definition: G4Particle.h:51
int Region(const size_t &iregion) const
Definition: G4Particle.h:63
const vector< const TLorentzVector * > * SimPosEnter(const UInt_t &iparticle) const override
particle 4-position at entry point, all regions
const G4Particle * GetParticle(const UInt_t &iparticle) const
const Int_t Region(const UInt_t &iparticle, const UInt_t &iregion) const override
region number
const int TrackID(const UInt_t &iparticle) const override
G4 track ID (can be <0 if it fell below trking threshold)
const vector< const TLorentzVector * > * SimPosExit(const UInt_t &iparticle) const override
particle 4-position at exit point, all regions
const int ProgenitorTrackID(const UInt_t &iparticle) const override
G4 track ID of primary that led this one.
int const & ProgenitorPDG() const
Definition: G4Particle.h:53
const int ProgenitorPDG(const UInt_t &iparticle) const override
PDG of primary that led this one.
Int_t fEvent
event number for tree entry
Definition: TreeReader.h:55
int const & ProgenitorTrackID() const
Definition: G4Particle.h:56
QTextStream & endl(QTextStream &s)