Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
garana::MillG4Tree Class Reference

#include <MillG4Tree.h>

Inheritance diagram for garana::MillG4Tree:
garana::Mill garana::FlatG4Tree garana::G4Tree garana::TreeReader

Public Member Functions

 MillG4Tree ()
 
 MillG4Tree (TTree *treeIn, TTree *treeOut)
 
void MillTrees () override
 
- Public Member Functions inherited from garana::Mill
virtual ~Mill ()
 
bool IsVerified () const
 
std::string CharStarToString (const char *cstr)
 
- Public Member Functions inherited from garana::FlatG4Tree
 FlatG4Tree ()
 
 FlatG4Tree (TTree *tree)
 
 FlatG4Tree (TTree *tree, char opt)
 
const UInt_t NSim () const override
 number of particles More...
 
const UInt_t NPoints (const UInt_t &iparticle) const override
 number of G4 steps (i.e. trajectory points) More...
 
const UInt_t NRegions (const UInt_t &iparticle) const override
 number of regions traversed by particle More...
 
const Int_t Region (const UInt_t &iparticle, const UInt_t &iregion) const override
 region number More...
 
const vector< const TLorentzVector * > * SimMomEnter (const UInt_t &iparticle) const override
 particle 4-momentum at entry point, all regions More...
 
const vector< const TLorentzVector * > * SimMomExit (const UInt_t &iparticle) const override
 particle 4-momentum at exit point, all regions More...
 
const vector< const TLorentzVector * > * SimPosEnter (const UInt_t &iparticle) const override
 particle 4-position at entry point, all regions More...
 
const vector< const TLorentzVector * > * SimPosExit (const UInt_t &iparticle) const override
 particle 4-position at exit point, all regions More...
 
const TLorentzVector * SimMomEnter (const UInt_t &iparticle, const UInt_t &iregion) const override
 particle 4-momentum at entry point in region More...
 
const TLorentzVector * SimMomExit (const UInt_t &iparticle, const UInt_t &iregion) const override
 particle 4-momentum at exit point in region More...
 
const TLorentzVector * SimPosEnter (const UInt_t &iparticle, const UInt_t &iregion) const override
 particle 4-position at entry point in region More...
 
const TLorentzVector * SimPosExit (const UInt_t &iparticle, const UInt_t &iregion) const override
 particle 4-position at exit point in region More...
 
const bool IsPrimary (const UInt_t &iparticle) const override
 did particle come from generator? More...
 
const Int_t PDG (const UInt_t &iparticle) const override
 particle PDG code More...
 
const int ParentPDG (const UInt_t &iparticle) const override
 parent particle's PDG code More...
 
const int ProgenitorPDG (const UInt_t &iparticle) const override
 PDG of primary that led this one. More...
 
const int TrackID (const UInt_t &iparticle) const override
 G4 track ID (can be <0 if it fell below trking threshold) More...
 
const int ParentTrackID (const UInt_t &iparticle) const override
 G4 track ID of parent particle. More...
 
const int ProgenitorTrackID (const UInt_t &iparticle) const override
 G4 track ID of primary that led this one. More...
 
const Int_t ProcessI (const UInt_t &iparticle) const override
 code for process that created this one More...
 
const Int_t ProcessF (const UInt_t &iparticle) const override
 code for process that killed this one More...
 
void GetEntry (const UInt_t &ientry) override
 
const UInt_t NSubEntries () const
 
- Public Member Functions inherited from garana::G4Tree
virtual ~G4Tree ()
 
UInt_t const GetTruthIndex (UInt_t iparticle) const
 index in gen tree subentry to truth match to this More...
 
const UInt_t NPrimary () const
 
bool HasPassedTPC (const UInt_t &iparticle) const
 did the G4Particle pass through any TPC drift volume(s)? More...
 
bool HasPassedCalo (const UInt_t &iparticle) const
 did the G4Particle pass through any active ECal volume(s)? More...
 
bool IsStoppedTPC (const UInt_t &iparticle) const
 did the G4Particle stop/decay in any TPC drift volume(s)? More...
 
bool IsStoppedCalo (const UInt_t &iparticle) const
 did the G4Particle stop/decay in any active ECal volume(s)? More...
 
bool IsContainedTPC (const UInt_t &iparticle) const
 if the G4Particle was produced in any TPC drift volume, does it remain in either drift volume? More...
 
bool IsContainedCalo (const UInt_t &iparticle) const
 if the G4Particle was produced in any active ECal volume, does it remain there? More...
 
bool IsCathodeCrosser (const UInt_t &iparticle) const
 did the G4Particle cross the TPC central cathode? More...
 
bool IsContainedTPCEvent () const
 do all particles produced in any TPC drift volume in this event remain in either volume? More...
 
bool IsContainedTPCPrimaries () const
 do all primaries produced in any TPC drift volume in this event remain in either volume? More...
 
bool IsContainedCaloEvent () const
 do all particles produced in any active ECal volume in this event remain there? More...
 
bool IsContainedCaloPrimaries () const
 do all primaries produced in any active ECal volume in this event remain there? More...
 
const TLorentzVector * SimMomBegin (const UInt_t &iparticle) const
 
const TLorentzVector * SimMomEnd (const UInt_t &iparticle) const
 
const TLorentzVector * SimPosBegin (const UInt_t &iparticle) const
 
const TLorentzVector * SimPosEnd (const UInt_t &iparticle) const
 
- Public Member Functions inherited from garana::TreeReader
virtual ~TreeReader ()
 
void SetupRead (TTree *tree)
 
TTree * GetInputTree ()
 
size_t NEntries () const
 
Int_t Event () const
 
const TObjArray * GetBranchList () const
 
void Fill ()
 
void Write ()
 
void CheckOpt (char opt)
 
bool BlockWrite () const
 

Private Types

enum  G4Branch { kEvent, kG4Particles, kG4TruthIndex }
 

Private Member Functions

bool VerifyBranches () override
 

Private Attributes

StructuredG4TreefG4In = nullptr
 
std::map< std::string, G4BranchnameToG4Branch
 
std::map< G4Branch, boolbranchToDrawOpt
 

Additional Inherited Members

- Protected Member Functions inherited from garana::FlatG4Tree
bool SetBranchAddresses () override
 
void SetVecs ()
 
void ClearVecs ()
 
void SetLimits ()
 
void FillIndexMap ()
 
const UInt_t LocalToGlobalIndex (const UInt_t &iparticle) const
 
- Protected Attributes inherited from garana::Mill
bool fIsVerified = false
 
TTree * fTreeOut = nullptr
 
TFile * fOutfile = nullptr
 
- Protected Attributes inherited from garana::FlatG4Tree
std::map< UInt_t, std::pair< UInt_t, UInt_t > > fLimits
 for each array for a given particle More...
 
std::map< UInt_t, UInt_t > fLocalToGlobalIndex
 
UInt_t fNSim = UINT_MAX
 number of G4 particles per event More...
 
vector< UInt_t > * fNPts = nullptr
 number of 4-vector "snapshots" (G4 steps) More...
 
vector< UInt_t > * fNRegions = nullptr
 number of regions of interest cross by the particle More...
 
vector< Int_t > * fRegions = nullptr
 region IDs More...
 
vector< Int_t > * fTrkID = nullptr
 particle's G4 trackID More...
 
vector< Int_t > * fPDG = nullptr
 particle's PDG code More...
 
vector< Int_t > * fParentPdg = nullptr
 particle parent's PDG code More...
 
vector< Int_t > * fProgenitorPdg = nullptr
 FS particle from gen stage that led to this one. More...
 
vector< Int_t > * fParentTrackId = nullptr
 particle's parent's trackID More...
 
vector< Int_t > * fProgenitorTrackId = nullptr
 FS particle from gen stage that led to this one. More...
 
vector< Int_t > * fProcessI = nullptr
 process that produced the particle More...
 
vector< Int_t > * fProcessF = nullptr
 process that killed the particle More...
 
vector< Float_t > * fX = nullptr
 particle's x-position in lab frame [cm] More...
 
vector< Float_t > * fY = nullptr
 particle's y-position in lab frame [cm] More...
 
vector< Float_t > * fZ = nullptr
 particle's z-position in lab frame [cm] More...
 
vector< Float_t > * fT = nullptr
 particle's time in lab frame [ns] More...
 
vector< Float_t > * fPx = nullptr
 particle's x-momentum in lab frame [GeV/c] More...
 
vector< Float_t > * fPy = nullptr
 particle's y-momentum in lab frame [GeV/c] More...
 
vector< Float_t > * fPz = nullptr
 particle's z-momentum in lab frame [GeV/c] More...
 
vector< Float_t > * fE = nullptr
 particle's total energy in lab frame [GeV] More...
 
TBranch * b_NSim = nullptr
 
TBranch * b_NPts = nullptr
 
TBranch * b_NRegions = nullptr
 
TBranch * b_Regions = nullptr
 
TBranch * b_TrkID = nullptr
 
TBranch * b_PDG = nullptr
 
TBranch * b_ParentPdg = nullptr
 
TBranch * b_ProgenitorPdg = nullptr
 
TBranch * b_ParentTrackId = nullptr
 
TBranch * b_ProgenitorTrackId = nullptr
 
TBranch * b_ProcessI = nullptr
 
TBranch * b_ProcessF = nullptr
 
TBranch * b_X = nullptr
 
TBranch * b_Y = nullptr
 
TBranch * b_Z = nullptr
 
TBranch * b_T = nullptr
 
TBranch * b_Px = nullptr
 
TBranch * b_Py = nullptr
 
TBranch * b_Pz = nullptr
 
TBranch * b_E = nullptr
 
- Protected Attributes inherited from garana::G4Tree
vector< UInt_t > * fG4TruthIndex = nullptr
 
vector< UInt_t > * fG4FSIndex = nullptr
 
TBranch * b_G4TruthIndex = nullptr
 
TBranch * b_G4FSIndex = nullptr
 
- Protected Attributes inherited from garana::TreeReader
const std::string treename
 
char fOpt = 'r'
 
TTree * fTreeIn = nullptr
 pointer to the analyzed TTree or TChain More...
 
UInt_t fCurrentEntry = UINT_MAX
 
TBranch * b_Event = nullptr
 
Int_t fEvent = -1
 event number for tree entry More...
 

Detailed Description

Definition at line 16 of file MillG4Tree.h.

Member Enumeration Documentation

enum garana::MillG4Tree::G4Branch
private
Enumerator
kEvent 
kG4Particles 
kG4TruthIndex 

Definition at line 34 of file MillG4Tree.h.

Constructor & Destructor Documentation

garana::MillG4Tree::MillG4Tree ( )
inline

Definition at line 20 of file MillG4Tree.h.

20 {};
MillG4Tree::MillG4Tree ( TTree *  treeIn,
TTree *  treeOut 
)

Definition at line 20 of file MillG4Tree.cxx.

21 {
22  fG4In = new StructuredG4Tree(treeIn);
23 
24  fTreeIn = treeOut;
25  fOpt='w';
26  this->VerifyBranches();
27  this->SetVecs();
28  this->SetBranchAddresses();
29  this->MillTrees();
30 
31 }//constructor()
bool VerifyBranches() override
Definition: MillG4Tree.cxx:117
TTree * fTreeIn
pointer to the analyzed TTree or TChain
Definition: TreeReader.h:51
void MillTrees() override
Definition: MillG4Tree.cxx:34
StructuredG4Tree * fG4In
Definition: MillG4Tree.h:30
bool SetBranchAddresses() override
Definition: FlatG4Tree.cxx:47

Member Function Documentation

void MillG4Tree::MillTrees ( )
overridevirtual

Implements garana::Mill.

Definition at line 34 of file MillG4Tree.cxx.

34  {
35 
36  if(!IsVerified()){
37  std::cerr << "WARNING(MillG4Tree::MillTrees): "
38  << "trying to mill trees that have not been verified"
39  << std::endl;
40  return;
41  }
42 
43  std::cout << "MillG4Tree: loop over " << fG4In->NEntries() << " gen entries" << std::endl;
44 
45  //loop over input g4Tree events (entries)
46  for(size_t ientry=0; ientry<fG4In->NEntries(); ientry++){
47 
48  ClearVecs(); //clear previous entry's data (if any)
49  fG4In->GetEntry(ientry);
50 
51  if(branchToDrawOpt[kEvent]) {
52  fEvent = fG4In->Event();
53  }
54 
56  fNSim = fG4In->NSim();
57  std::cout << "MillG4: output NG4 = " << fNSim << std::endl;
58 
59  //loop over g4 entries
60  std::cout << "MillG4Tree: loop over " << fG4In->NSim() << " isim" <<std::endl;
61  for(size_t isim=0; isim<fG4In->NSim(); isim++){
62 
63  auto posenter = fG4In->SimPosEnter(isim); // 4-position for particle at entry, all regions
64  auto momenter = fG4In->SimMomEnter(isim); // 4-momentum for particle at entry, all regions
65  auto posexit = fG4In->SimPosExit(isim); // 4-position for particle at exit/end, all regions
66  auto momexit = fG4In->SimMomExit(isim); // 4-momentum for particle at exit, all regions
67 
68  for(size_t ireg=0; ireg<fG4In->NRegions(isim); ireg++){
69  for(size_t i=0; i<2; i++){
70  fNPts ->push_back(fG4In->NPoints(isim));
71  fTrkID ->push_back(fG4In->TrackID(isim));
72  fPDG ->push_back(fG4In->PDG(isim));
73  fParentPdg ->push_back(fG4In->ParentPDG(isim));
74  fProgenitorPdg ->push_back(fG4In->ProgenitorPDG(isim));
75  fParentTrackId ->push_back(fG4In->ParentTrackID(isim));
76  fProgenitorTrackId ->push_back(fG4In->ProgenitorTrackID(isim));
77  fProcessI ->push_back(fG4In->ProcessI(isim));
78  fProcessF ->push_back(fG4In->ProcessF(isim));
79  if(i==0) {
80  fX ->push_back(posenter->at(ireg)->X());
81  fY ->push_back(posenter->at(ireg)->Y());
82  fZ ->push_back(posenter->at(ireg)->Z());
83  fT ->push_back(posenter->at(ireg)->T());
84  fPx ->push_back(momenter->at(ireg)->Px());
85  fPy ->push_back(momenter->at(ireg)->Py());
86  fPz ->push_back(momenter->at(ireg)->Pz());
87  fE ->push_back(momenter->at(ireg)->E());
88  }
89  else {
90  fX ->push_back(posexit->at(ireg)->X());
91  fY ->push_back(posexit->at(ireg)->Y());
92  fZ ->push_back(posexit->at(ireg)->Z());
93  fT ->push_back(posexit->at(ireg)->T());
94  fPx ->push_back(momexit->at(ireg)->Px());
95  fPy ->push_back(momexit->at(ireg)->Py());
96  fPz ->push_back(momexit->at(ireg)->Pz());
97  fE ->push_back(momexit->at(ireg)->E());
98  }
99  }
100  }// for regions
101 
103  fG4TruthIndex->push_back(fG4In->GetTruthIndex(isim));
104  }
105 
106  }//for g4 entries
107  }//if branch present
108 
109  fTreeIn->Fill(); //actually our fTreeOut, but it's called fTreeIn in FlatG4Tree.h, fill once per event
110 
111  }//for genTree entries
112 
113  fTreeIn->Write();
114 
115 }//Mill()
vector< Int_t > * fTrkID
particle&#39;s G4 trackID
Definition: FlatG4Tree.h:76
const int ParentPDG(const UInt_t &iparticle) const override
parent particle&#39;s PDG code
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
vector< Int_t > * fProcessI
process that produced the particle
Definition: FlatG4Tree.h:82
const UInt_t NSim() const override
number of particles
const int ParentTrackID(const UInt_t &iparticle) const override
G4 track ID of parent particle.
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
vector< UInt_t > * fNPts
number of 4-vector "snapshots" (G4 steps)
Definition: FlatG4Tree.h:73
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
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 ProcessF(const UInt_t &iparticle) const override
code for process that killed this one
const vector< const TLorentzVector * > * SimMomExit(const UInt_t &iparticle) const override
particle 4-momentum at exit point, all regions
const UInt_t NRegions(const UInt_t &iparticle) const override
number of regions traversed by particle
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
UInt_t fNSim
number of G4 particles per event
Definition: FlatG4Tree.h:72
bool IsVerified() const
Definition: Mill.h:28
Int_t Event() const
Definition: TreeReader.cxx:30
const Int_t ProcessI(const UInt_t &iparticle) const override
code for process that created this one
vector< Float_t > * fY
particle&#39;s y-position in lab frame [cm]
Definition: FlatG4Tree.h:85
const Int_t PDG(const UInt_t &iparticle) const override
particle PDG code
const vector< const TLorentzVector * > * SimPosEnter(const UInt_t &iparticle) const override
particle 4-position at entry point, all regions
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
vector< Int_t > * fProcessF
process that killed the particle
Definition: FlatG4Tree.h:83
std::map< G4Branch, bool > branchToDrawOpt
Definition: MillG4Tree.h:47
vector< Int_t > * fProgenitorTrackId
FS particle from gen stage that led to this one.
Definition: FlatG4Tree.h:81
vector< Int_t > * fPDG
particle&#39;s PDG code
Definition: FlatG4Tree.h:77
const int TrackID(const UInt_t &iparticle) const override
G4 track ID (can be <0 if it fell below trking threshold)
UInt_t const GetTruthIndex(UInt_t iparticle) const
index in gen tree subentry to truth match to this
Definition: G4Tree.cxx:12
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.
const int ProgenitorPDG(const UInt_t &iparticle) const override
PDG of primary that led this one.
virtual void GetEntry(const UInt_t &ientry)
Definition: TreeReader.cxx:39
Int_t fEvent
event number for tree entry
Definition: TreeReader.h:55
StructuredG4Tree * fG4In
Definition: MillG4Tree.h:30
vector< Float_t > * fPx
particle&#39;s x-momentum in lab frame [GeV/c]
Definition: FlatG4Tree.h:88
size_t NEntries() const
Definition: TreeReader.cxx:35
QTextStream & endl(QTextStream &s)
vector< Float_t > * fX
particle&#39;s x-position in lab frame [cm]
Definition: FlatG4Tree.h:84
bool MillG4Tree::VerifyBranches ( )
overrideprivatevirtual

Implements garana::Mill.

Definition at line 117 of file MillG4Tree.cxx.

117  {
118 
119  // get list of branches and check it matches what we expect
120  const TObjArray* branches = fG4In->GetBranchList();
121  std::cout << "got ObjArray of branches from fTreeIn" << std::endl;
122  try {
123  if(!branches || branches->GetEntries()==0 )
124  throw branches;
125  }
126  catch(TObjArray* branches){
127  std::cerr << "ERROR(MillG4Tree::VerifyBranches): no branches found in passed input tree"
128  << std::endl;
129  return false;
130  }
131 
132  if(branches->GetEntriesFast() != (Int_t)nameToG4Branch.size())
133  std::cout << "WARNING(MillG4Tree::VerifyBranches): Mismatch in number of branches (expected "
134  << nameToG4Branch.size() << " but found " << branches->GetEntriesFast()
135  << ")" << std::endl;
136  else
137  std::cout << "found genTree with " << branches->GetEntriesFast() << " branches" << std::endl;
138 
139  // loop over branches
140  TIter next(branches);
141  TBranch* branch = nullptr;
142  while( (branch=(TBranch*)next())) {
143 
144  // check if branch is expected
145  if(nameToG4Branch.find(CharStarToString(branch->GetFullName()))!=nameToG4Branch.end()) {
146 
147  std::cout << " chopping branch '" << branch->GetFullName() << "'" << std::endl;
148 
149  if(nameToG4Branch[CharStarToString(branch->GetFullName())] == kEvent)
150  branchToDrawOpt[kEvent] = true;
151 
152  if(nameToG4Branch[CharStarToString(branch->GetFullName())] == kG4Particles)
154 
155  if(nameToG4Branch[CharStarToString(branch->GetFullName())] == kG4TruthIndex)
157 
158  }//endif known branch
159 
160  else{
161  std::cout << "WARNING(MillG4Tree): ignoring unknown branch '"
162  << branch->GetFullName() << "'" << std::endl;
163  }//else
164 
165  }//for branches
166 
167  fIsVerified = true;
168  return true;
169 
170 }//VerifyBranches()
std::string CharStarToString(const char *cstr)
Definition: Mill.cxx:12
bool fIsVerified
Definition: Mill.h:33
const TObjArray * GetBranchList() const
Definition: TreeReader.cxx:47
std::map< std::string, G4Branch > nameToG4Branch
Definition: MillG4Tree.h:40
std::map< G4Branch, bool > branchToDrawOpt
Definition: MillG4Tree.h:47
StructuredG4Tree * fG4In
Definition: MillG4Tree.h:30
QTextStream & endl(QTextStream &s)

Member Data Documentation

std::map<G4Branch,bool> garana::MillG4Tree::branchToDrawOpt
private
Initial value:
= {
{kEvent, false},
{kG4Particles, false},
{kG4TruthIndex, false}
}

Definition at line 47 of file MillG4Tree.h.

StructuredG4Tree* garana::MillG4Tree::fG4In = nullptr
private

Definition at line 30 of file MillG4Tree.h.

std::map<std::string,G4Branch> garana::MillG4Tree::nameToG4Branch
private
Initial value:
= {
{"Event", kEvent},
{"G4Particles", kG4Particles},
{"G4TruthIndex", kG4TruthIndex}
}

Definition at line 40 of file MillG4Tree.h.


The documentation for this class was generated from the following files: