EDepSimKinemPassThrough.hh
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////
2 // A singleton class to pass through generator mc-truth information
3 // used input for detsim.
4 //////////////////////////////////////////////////////////////////
5 #ifndef EDepSim_KinemPassThrough_hh
6 #define EDepSim_KinemPassThrough_hh
7 
8 #include <iostream>
9 #include <string>
10 #include <map>
11 #include <vector>
12 
13 #include "TFile.h"
14 #include "TTree.h"
15 #include "TObjArray.h"
16 #include "TChain.h"
17 
18 
19 /// Stores generator mc-truth pass-through information used as input into
20 /// detsim. This class is a singleton which allows a single tree to persist
21 /// throughout multiple instantiations of the neutrino primary vertex
22 /// generators. This is so an exact copy of only the mc-truth information
23 /// (associated with all primary vertices) used as input for the detsim
24 /// detector simulation can be made. These primary vertices can come from
25 /// multiple input files and this class also records bookkeeping information
26 /// pertaining to the type and name and other useful information, such as POT
27 /// normalisation, about the input tree and the input file used.
28 ///
29 /// The following illistrates how the entries are copied: First add input
30 /// trees to TChain by calling,
31 ///
32 /// \code
33 /// EDepSim::KinemPassThrough::AddInputTree("file1.root", treePtr1) ,
34 /// \endcode
35 ///
36 /// and then adding a second tree,
37 ///
38 /// \code
39 /// EDepSim::KinemPassThrough::AddInputTree("file2.root", treePtr2) ,
40 /// \endcode
41 ///
42 /// for two trees with N_1 and N_2 events and stored in file1 and file2
43 /// respectively. These trees corresponding to the trees pointed at in
44 /// detsim by treePtr1 and treePtr2 respectively. Now calling
45 ///
46 /// \code
47 /// EDepSim::KinemPassThrough::AddEntry(i, treePtrX) ,
48 /// \endcode
49 ///
50 /// (where X can be 1 or 2) will copy the i'th entry from the TChain when X
51 /// = 1 and the (N_1 + i)'th entry when X = 2. There is no limit to the
52 /// number of input trees.
53 namespace EDepSim {class KinemPassThrough;}
55 public:
56  /// for relating input tree pointers to the input file.
57  typedef std::map<const TTree *, int> TreeToInt;
58 
60 
61  /// Returns (or initialises if first time) the instance
62  /// of the singleton.
64 
65  /// Add an input tree to the TChain of input trees that rootracker
66  /// entries will be copied from. A map between the tree pointer that
67  /// detsim is using and the correct segment of the TChain is also made.
68  bool AddInputTree(const TTree * inputTreePtr,
69  const char * inputFileName,
70  const char* generatorName);
71 
72  /// Copy the i'th entry from segment of the TChain corresponding to the
73  /// input tree pointed at (in detsim) by inputTreePtr.
74  bool AddEntry(const TTree * inputTreePtr, const int origEntry);
75 
76  /// Return the position (entry number) that the most recent entry to be
77  /// copied to the pass-through tree will have.
78  int LastEntryNumber();
79 
80 private:
81  /// Private constructor.
83 
84  /// Static pointer to singleton instance.
86 
87  /// Create the bookkeeping and file list trees. This also creates the
88  /// directory.
89  void CreateInternalTrees();
90 
91  /// Clean up all of the allocated pointers.
92  void CleanUp();
93 
94  /// Set default values for all fields.
95  void Init();
96 
97  /// Set the name of the input file being read.
99 
100  /// Persistent tree that stores entries from multiple temp trees.
102 
103  /// TChain to store input trees.
105 
106  /// Store the first tree name.
108 
109  /// for relating input tree pointers to the input file.
110  TreeToInt fInputTreeMap;
111 
112  /// for relating input tree to first entry in TChain.
113  TreeToInt fFirstEntryMap;
114 
115  /// Used to store list of files before they are written to tree.
116  std::vector<std::string> fFileList;
117 
118  // =====================================
119  /// Tree relating all events in the persistent tree to an input file
121 
122  /// Used to fill the bookkeeping tree "inputFileNum" field. This is
123  /// the entry number of the input file in the input file tree.
125 
126  /// Used to fill the bookkeeping tree "origEntryNum" field. This is the
127  /// entry number of the event in the original tree.
129 
130  // =====================================
131  /// Tree containing list of input files.
133 
134  /// Used to fill input file list tree with input file name.
135  char fInputFileName[1024];
136 
137  /// Used to fill the name of the generator for this file.
139 
140  /// Used to fill the name of the tree for this file.
142 
143  /// Used to fill input file list tree "filePOT" field.
145 
146  /// Used to fill input file list tree "nEntriesTot" field. This is the
147  /// total number of entries in the input tree.
149 };
150 #endif
char fInputFileTreeName[128]
Used to fill the name of the tree for this file.
static QCString name
Definition: declinfo.cpp:673
TTree * fInputKinemTree
Tree relating all events in the persistent tree to an input file.
std::string fFirstTreeName
Store the first tree name.
TChain * fInputTreeChain
TChain to store input trees.
TreeToInt fFirstEntryMap
for relating input tree to first entry in TChain.
static EDepSim::KinemPassThrough * fKinemPassThrough
Static pointer to singleton instance.
std::vector< std::string > fFileList
Used to store list of files before they are written to tree.
std::string string
Definition: nybbler.cc:12
void CleanUp()
Clean up all of the allocated pointers.
double fInputFilePOT
Used to fill input file list tree "filePOT" field.
std::map< const TTree *, int > TreeToInt
for relating input tree pointers to the input file.
std::string SetInputFileName(std::string name)
Set the name of the input file being read.
KinemPassThrough()
Private constructor.
char fInputFileName[1024]
Used to fill input file list tree with input file name.
bool AddEntry(const TTree *inputTreePtr, const int origEntry)
static EDepSim::KinemPassThrough * GetInstance()
Construct a module from components.
Definition: TG4HitSegment.h:10
TreeToInt fInputTreeMap
for relating input tree pointers to the input file.
TTree * fInputFilesTree
Tree containing list of input files.
bool AddInputTree(const TTree *inputTreePtr, const char *inputFileName, const char *generatorName)
char fInputFileGenerator[128]
Used to fill the name of the generator for this file.
void Init()
Set default values for all fields.
TTree * fPersistentTree
Persistent tree that stores entries from multiple temp trees.