FlatG4Tree.h
Go to the documentation of this file.
1 /*
2  * FlatG4Tree.h
3  *
4  * Created on: Feb 9, 2021
5  * Author: chilgenb
6  */
7 
8 #ifndef GARANA_FLATG4TREE_H_
9 #define GARANA_FLATG4TREE_H_
10 
11 #include "garana/Base/G4Tree.h"
12 #include <map>
13 #include <utility>
14 
15 using std::vector;
16 
17 namespace garana {
18 
19  class FlatG4Tree : public G4Tree {
20 
21  public:
22 
24  FlatG4Tree(TTree* tree);
25  FlatG4Tree(TTree* tree, char opt);
26  // default dest'or
27 
28  // accessors inherited from G4Tree
29  const UInt_t NSim() const override;
30  const UInt_t NPoints(const UInt_t& iparticle) const override;
31  const UInt_t NRegions(const UInt_t& iparticle) const override;
32  const Int_t Region(const UInt_t& iparticle, const UInt_t& iregion) const override;
33  const vector<const TLorentzVector*>* SimMomEnter(const UInt_t& iparticle) const override;
34  const vector<const TLorentzVector*>* SimMomExit(const UInt_t& iparticle) const override;
35  const vector<const TLorentzVector*>* SimPosEnter(const UInt_t& iparticle) const override;
36  const vector<const TLorentzVector*>* SimPosExit(const UInt_t& iparticle) const override;
37  const TLorentzVector* SimMomEnter(const UInt_t& iparticle, const UInt_t& iregion)const override;
38  const TLorentzVector* SimMomExit(const UInt_t& iparticle, const UInt_t& iregion) const override;
39  const TLorentzVector* SimPosEnter(const UInt_t& iparticle, const UInt_t& iregion)const override;
40  const TLorentzVector* SimPosExit(const UInt_t& iparticle, const UInt_t& iregion) const override;
41  const bool IsPrimary(const UInt_t& iparticle) const override;
42  const Int_t PDG(const UInt_t& iparticle) const override;
43  const int ParentPDG(const UInt_t& iparticle) const override;
44  const int ProgenitorPDG(const UInt_t& iparticle) const override;
45  const int TrackID(const UInt_t& iparticle) const override;
46  const int ParentTrackID(const UInt_t& iparticle) const override;
47  const int ProgenitorTrackID(const UInt_t& iparticle) const override;
48  const Int_t ProcessI(const UInt_t& iparticle) const override;
49  const Int_t ProcessF(const UInt_t& iparticle) const override;
50 
51  void GetEntry(const UInt_t& ientry) override;
52 
53  const UInt_t NSubEntries() const;
54 
55  protected:
56 
57  bool SetBranchAddresses() override;
58  void SetVecs();
59  void ClearVecs();
60  void SetLimits();
61  void FillIndexMap();
62  const UInt_t LocalToGlobalIndex(const UInt_t& iparticle) const;
63 
64  std::map<UInt_t, std::pair<UInt_t,UInt_t>> fLimits; ///< tree is completely flat so need first and last index
65  ///< for each array for a given particle
66  std::map<UInt_t,UInt_t> fLocalToGlobalIndex; //particle index -> index in array
67 
68  // leaves and branches
69  // vectors are all same length (2*fNSim * sum_iparticle (fNRegions[iparticle]))
70  // some redundant info yes, but it makes the relation between branches clearer
71  // could come back to this if trees need slimming
72  UInt_t fNSim = UINT_MAX; ///< number of G4 particles per event
73  vector<UInt_t>* fNPts = nullptr; ///< number of 4-vector "snapshots" (G4 steps)
74  vector<UInt_t>* fNRegions = nullptr; ///< number of regions of interest cross by the particle
75  vector<Int_t>* fRegions = nullptr; ///< region IDs
76  vector<Int_t>* fTrkID = nullptr; ///< particle's G4 trackID
77  vector<Int_t>* fPDG = nullptr; ///< particle's PDG code
78  vector<Int_t>* fParentPdg = nullptr; ///< particle parent's PDG code
79  vector<Int_t>* fProgenitorPdg = nullptr; ///< FS particle from gen stage that led to this one
80  vector<Int_t>* fParentTrackId = nullptr; ///< particle's parent's trackID
81  vector<Int_t>* fProgenitorTrackId = nullptr; ///< FS particle from gen stage that led to this one
82  vector<Int_t>* fProcessI = nullptr; ///< process that produced the particle
83  vector<Int_t>* fProcessF = nullptr; ///< process that killed the particle
84  vector<Float_t>* fX = nullptr; ///< particle's x-position in lab frame [cm]
85  vector<Float_t>* fY = nullptr; ///< particle's y-position in lab frame [cm]
86  vector<Float_t>* fZ = nullptr; ///< particle's z-position in lab frame [cm]
87  vector<Float_t>* fT = nullptr; ///< particle's time in lab frame [ns]
88  vector<Float_t>* fPx = nullptr; ///< particle's x-momentum in lab frame [GeV/c]
89  vector<Float_t>* fPy = nullptr; ///< particle's y-momentum in lab frame [GeV/c]
90  vector<Float_t>* fPz = nullptr; ///< particle's z-momentum in lab frame [GeV/c]
91  vector<Float_t>* fE = nullptr; ///< particle's total energy in lab frame [GeV]
92 
93 
94  TBranch* b_NSim = nullptr;
95  TBranch* b_NPts = nullptr;
96  TBranch* b_NRegions = nullptr;
97  TBranch* b_Regions = nullptr;
98  TBranch* b_TrkID = nullptr;
99  TBranch* b_PDG = nullptr;
100  TBranch* b_ParentPdg = nullptr;
101  TBranch* b_ProgenitorPdg = nullptr;
102  TBranch* b_ParentTrackId = nullptr;
103  TBranch* b_ProgenitorTrackId = nullptr;
104  TBranch* b_ProcessI = nullptr;
105  TBranch* b_ProcessF = nullptr;
106  TBranch* b_X = nullptr;
107  TBranch* b_Y = nullptr;
108  TBranch* b_Z = nullptr;
109  TBranch* b_T = nullptr;
110  TBranch* b_Px = nullptr;
111  TBranch* b_Py = nullptr;
112  TBranch* b_Pz = nullptr;
113  TBranch* b_E = nullptr;
114 
115  };//class
116 }//namespace
117 
118 #endif /* FLATG4TREE_H_ */
vector< Int_t > * fTrkID
particle&#39;s G4 trackID
Definition: FlatG4Tree.h:76
const UInt_t LocalToGlobalIndex(const UInt_t &iparticle) const
Definition: FlatG4Tree.cxx:313
const Int_t ProcessI(const UInt_t &iparticle) const override
code for process that created this one
Definition: FlatG4Tree.cxx:288
TBranch * b_ProgenitorTrackId
Definition: FlatG4Tree.h:103
const UInt_t NSim() const override
number of particles
Definition: FlatG4Tree.cxx:152
vector< Int_t > * fParentPdg
particle parent&#39;s PDG code
Definition: FlatG4Tree.h:78
vector< Float_t > * fPy
particle&#39;s y-momentum in lab frame [GeV/c]
Definition: FlatG4Tree.h:89
std::map< UInt_t, std::pair< UInt_t, UInt_t > > fLimits
for each array for a given particle
Definition: FlatG4Tree.h:64
vector< Int_t > * fProcessI
process that produced the particle
Definition: FlatG4Tree.h:82
const vector< const TLorentzVector * > * SimPosEnter(const UInt_t &iparticle) const override
particle 4-position at entry point, all regions
Definition: FlatG4Tree.cxx:213
opt
Definition: train.py:196
vector< Int_t > * fRegions
region IDs
Definition: FlatG4Tree.h:75
TBranch * b_ParentTrackId
Definition: FlatG4Tree.h:102
const Int_t ProcessF(const UInt_t &iparticle) const override
code for process that killed this one
Definition: FlatG4Tree.cxx:292
const UInt_t NRegions(const UInt_t &iparticle) const override
number of regions traversed by particle
Definition: FlatG4Tree.cxx:169
const int ParentTrackID(const UInt_t &iparticle) const override
G4 track ID of parent particle.
Definition: FlatG4Tree.cxx:280
struct vector vector
vector< UInt_t > * fNRegions
number of regions of interest cross by the particle
Definition: FlatG4Tree.h:74
TBranch * b_TrkID
Definition: FlatG4Tree.h:98
TBranch * b_Regions
Definition: FlatG4Tree.h:97
vector< UInt_t > * fNPts
number of 4-vector "snapshots" (G4 steps)
Definition: FlatG4Tree.h:73
TBranch * b_ProgenitorPdg
Definition: FlatG4Tree.h:101
const int TrackID(const UInt_t &iparticle) const override
G4 track ID (can be <0 if it fell below trking threshold)
Definition: FlatG4Tree.cxx:276
const UInt_t NSubEntries() const
Definition: FlatG4Tree.cxx:296
const int ProgenitorPDG(const UInt_t &iparticle) const override
PDG of primary that led this one.
Definition: FlatG4Tree.cxx:272
TBranch * b_NRegions
Definition: FlatG4Tree.h:96
const vector< const TLorentzVector * > * SimMomExit(const UInt_t &iparticle) const override
particle 4-momentum at exit point, all regions
Definition: FlatG4Tree.cxx:195
const int ParentPDG(const UInt_t &iparticle) const override
parent particle&#39;s PDG code
Definition: FlatG4Tree.cxx:268
const vector< const TLorentzVector * > * SimMomEnter(const UInt_t &iparticle) const override
particle 4-momentum at entry point, all regions
Definition: FlatG4Tree.cxx:177
const Int_t Region(const UInt_t &iparticle, const UInt_t &iregion) const override
region number
Definition: FlatG4Tree.cxx:173
vector< Float_t > * fE
particle&#39;s total energy in lab frame [GeV]
Definition: FlatG4Tree.h:91
vector< Float_t > * fT
particle&#39;s time in lab frame [ns]
Definition: FlatG4Tree.h:87
const Int_t PDG(const UInt_t &iparticle) const override
particle PDG code
Definition: FlatG4Tree.cxx:165
TBranch * b_ProcessF
Definition: FlatG4Tree.h:105
TBranch * b_PDG
Definition: FlatG4Tree.h:99
vector< Int_t > * fProgenitorPdg
FS particle from gen stage that led to this one.
Definition: FlatG4Tree.h:79
vector< Int_t > * fParentTrackId
particle&#39;s parent&#39;s trackID
Definition: FlatG4Tree.h:80
const vector< const TLorentzVector * > * SimPosExit(const UInt_t &iparticle) const override
particle 4-position at exit point, all regions
Definition: FlatG4Tree.cxx:231
UInt_t fNSim
number of G4 particles per event
Definition: FlatG4Tree.h:72
TBranch * b_ParentPdg
Definition: FlatG4Tree.h:100
vector< Float_t > * fY
particle&#39;s y-position in lab frame [cm]
Definition: FlatG4Tree.h:85
vector< Float_t > * fZ
particle&#39;s z-position in lab frame [cm]
Definition: FlatG4Tree.h:86
vector< Float_t > * fPz
particle&#39;s z-momentum in lab frame [GeV/c]
Definition: FlatG4Tree.h:90
void GetEntry(const UInt_t &ientry) override
Definition: FlatG4Tree.cxx:38
const int ProgenitorTrackID(const UInt_t &iparticle) const override
G4 track ID of primary that led this one.
Definition: FlatG4Tree.cxx:284
vector< Int_t > * fProcessF
process that killed the particle
Definition: FlatG4Tree.h:83
TBranch * b_NPts
Definition: FlatG4Tree.h:95
std::map< UInt_t, UInt_t > fLocalToGlobalIndex
Definition: FlatG4Tree.h:66
vector< Int_t > * fProgenitorTrackId
FS particle from gen stage that led to this one.
Definition: FlatG4Tree.h:81
const UInt_t NPoints(const UInt_t &iparticle) const override
number of G4 steps (i.e. trajectory points)
Definition: FlatG4Tree.cxx:156
vector< Int_t > * fPDG
particle&#39;s PDG code
Definition: FlatG4Tree.h:77
TBranch * b_ProcessI
Definition: FlatG4Tree.h:104
const bool IsPrimary(const UInt_t &iparticle) const override
did particle come from generator?
Definition: FlatG4Tree.cxx:160
TBranch * b_NSim
Definition: FlatG4Tree.h:94
vector< Float_t > * fPx
particle&#39;s x-momentum in lab frame [GeV/c]
Definition: FlatG4Tree.h:88
vector< Float_t > * fX
particle&#39;s x-position in lab frame [cm]
Definition: FlatG4Tree.h:84
bool SetBranchAddresses() override
Definition: FlatG4Tree.cxx:47