pidata_H2.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////
2 // Created by L. Loiacono
3 // Modified by L. Fields
4 //////////////////////////////////////////////////////////
5 
6 #ifndef pidata_H2_h
7 #define pidata_H2_h
8 
9 // C++
10 #include <string>
11 #include <vector>
12 #include <fstream>
13 #include <iostream>
14 #include <iomanip>
15 #include <sstream>
16 #include <TH2.h>
17 
18 //ROOT
19 #include <TROOT.h>
20 #include <TChain.h>
21 #include <TFile.h>
22 #include <TRandom3.h>
23 
24 class pidata_H2 {
25 public :
26 
27  TChain *fChain; //!pointer to the analyzed TTree or TChain
28  //TTree *fChain; //!pointer to the analyzed TTree or TChain
29  Int_t fCurrent; //!current Tree number in a TChain
30 
31  Double_t fTotalPOT; //total pot used for all files
32  std::string ffilename; //filename for saving histograms
34  std::string detectorname; // name for det location
35  double detx; // detector location
36  double dety;
37  double detz;
38 int tot = 0,piplus,piminus = 0,nproton = 0,nelectron = 0, kplus = 0, kminus = 0, numu = 0, nue = 0, nutau = 0, numubar = 0, nuebar = 0, nutaubar = 0,neutron = 0, muon =
39 0, rest = 0;
40 int pptot = 0, pmtot = 0, ptot = 0, etot = 0, kptot = 0, kmtot = 0, numutot = 0,
41 numubartot = 0, nuebartot = 0, nuetot = 0, ntot = 0, mutot = 0, rtot = 0, ntott = 0, neutot = 0;
42  TRandom3 *rand3;
43  // Declaration of leaf types
44  Int_t nH2P;
45  Int_t trackID;
46  Int_t pdgCode;
47  Double_t H2ImpWeight;
48  Double_t H2positionX;
49  Double_t H2positionY;
50  Double_t H2positionZ;
51  Double_t H2momentumdirX;
52  Double_t H2momentumdirY;
53  Double_t H2momentumdirZ;
54  Double_t mass;
55  Double_t energy;
56  Double_t H2momentumX;
57  Double_t H2momentumY;
58  Double_t H2momentumZ;
59  Double_t H2PXPZ;
60  Double_t H2PYPZ;
61  Double_t H2PProductionX;
62  Double_t H2PProductionY;
63  Double_t H2PProductionZ;
64  Double_t H2PmomentumdirX;
65  Double_t H2PmomentumdirY;
66  Double_t H2PmomentumdirZ;
67  Int_t nH1P;
68 
69 /* Double_t DPPProductionX;
70  Double_t DPPProductionY;
71  Double_t DPPProductionZ;
72  Int_t DPPtrackID;
73  Int_t DPParentID;
74  Double_t DPenergy;
75  Double_t DPpositionX;
76  Double_t DPpositionY;
77  Double_t DPpositionZ;
78  Double_t DPmomentumX;
79  Double_t DPmomentumY;
80  Double_t DPmomentumZ;
81  Int_t DPpdgCode;*/
82 
83  // List of branches
84  TBranch *b_fH2NParticles; //!
85  TBranch *b_fH2TrackID; //!
86  TBranch *b_fH2ParticlePDG; //!
87  TBranch *b_fNImpWt; //!
88  TBranch *b_fH2ParticleX; //!
89  TBranch *b_fH2ParticleY; //!
90  TBranch *b_fH2ParticleZ; //!
91  TBranch *b_fH2ParticleDX; //!
92  TBranch *b_fH2ParticleDY; //!
93  TBranch *b_fH2ParticleDZ; //!
94  TBranch *b_fH2ParticleMass; //!
95  TBranch *b_fH2ParticleEnergy; //!
96  TBranch *b_fH2ParticlePX; //!
97  TBranch *b_fH2ParticlePY; //!
98  TBranch *b_fH2ParticlePZ; //!
99  TBranch *b_fH2ParticlePXPZ; //!
100  TBranch *b_fH2ParticlePYPZ; //!
101  TBranch *b_fH2PProductionX; //!
102  TBranch *b_fH2PProductionY; //!
103  TBranch *b_fH2PProductionZ; //!
104  TBranch *b_fH2PmomentumdirX; //!
105  TBranch *b_fH2PmomentumdirY; //!
106  TBranch *b_fH2PmomentumdirZ; //!
107 
108  /* TBranch *b_fDPPProductionX; //!
109  TBranch *b_fDPPProductionY; //!
110  TBranch *b_fDPPProductionZ; //!
111  TBranch *b_fDPTrackID; //!
112  TBranch *b_fDPParentID; //!
113  TBranch *b_fDPParticleEnergy; //!
114  TBranch *b_fDPParticleX; //!
115  TBranch *b_fDPParticleY; //!
116  TBranch *b_fDPParticleZ; //!
117  TBranch *b_fDPParticlePX; //!
118  TBranch *b_fDPParticlePY; //!
119  TBranch *b_fDPParticlePZ; //!
120  TBranch *b_fDPParticlePDG; //!
121  */
122  pidata_H2(TTree *t=0);
123  virtual ~pidata_H2();
124  virtual Int_t Cut(Long64_t entry);
125  virtual Int_t GetEntry(Long64_t entry);
126  virtual Long64_t LoadTree(Long64_t entry);
127  virtual void Init(TTree *tree);
128  virtual void Loop();
129  virtual Bool_t Notify();
130  virtual void Show(Long64_t entry = -1);
131 void SetTitles1(TH1* h,
132  const std::string &xtitle = "",
133  const std::string &ytitle = "");
134 void SetTitles2(TH2* h,
135  const std::string &xtitle = "",
136  const std::string &ytitle = "");
137 
138 
139 };
140 
141 #endif
142 
143 #ifdef pidata_H2_cxx
145 {
146 
147 //????????????????????????????
148 //????????????????????????????
149 //
150  //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
151  //
152  //Add files here
153  //
154  std::vector<std::string> fFileVec;
155  fFileVec.push_back("g4lbne_example_010.root");
156  fFileVec.push_back("g4lbne_example_011.root");
157 
158  //
159  //set number of pot per file !!!!!!!!!!!!!!!!!!!!!!!!!!!!
160  //
161  double potperfile = 10000.0;
162  fTotalPOT = potperfile*(double)fFileVec.size();
163 
164  //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
165  //set the filename prefix for saving histogram plots
166  //
167  ffilename = "g4lbne_fluxexample_pion.root";
168 
169 
170 //
171 //????????????????????????????
172 //????????????????????????????
173 
174  fChain = new TChain("H2trackingdata");
175  for(std::vector<std::string>::const_iterator sit = fFileVec.begin(); sit != fFileVec.end(); ++sit)
176  {
177  fChain -> Add(sit -> c_str());
178  }
179 
180  Init(fChain);
181 
182 
183 }
184 /*
185 pidata_H2::pidata_H2(TTree *tree)
186 {
187 // if parameter tree is not specified (or zero), connect the file
188 // used to generate this class and read the Tree.
189  if (tree == 0) {
190  TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject("g4lbne_example_le010z185i_NumiDPHelium_010.root");
191  if (!f) {
192  f = new TFile("g4lbne_example_le010z185i_NumiDPHelium_010.root");
193  }
194  tree = (TTree*)gDirectory->Get("pidata_H2");
195 
196  }
197  Init(tree);
198 }
199 */
200 
201 
203 {
204  if (!fChain) return;
205  delete fChain->GetCurrentFile();
206 }
207 
208 Int_t pidata_H2::GetEntry(Long64_t entry)
209 {
210 // Read contents of entry.
211  if (!fChain) return 0;
212  return fChain->GetEntry(entry);
213 }
214 Long64_t pidata_H2::LoadTree(Long64_t entry)
215 {
216 // Set the environment to read one entry
217  if (!fChain) return -5;
218  Long64_t centry = fChain->LoadTree(entry);
219  if (centry < 0) return centry;
220  if (!fChain->InheritsFrom(TChain::Class())) return centry;
221  TChain *chain = (TChain*)fChain;
222  if (chain->GetTreeNumber() != fCurrent) {
223  fCurrent = chain->GetTreeNumber();
224  Notify();
225  }
226  return centry;
227 }
228 
229 
230 void pidata_H2::Init(TTree *tree)
231 {
232  // The Init() function is called when the selector needs to initialize
233  // a new tree or chain. Typically here the branch addresses and branch
234  // pointers of the tree will be set.
235  // It is normally not necessary to make changes to the generated
236  // code, but the routine can be extended by the user if needed.
237  // Init() will be called many times when running on PROOF
238  // (once per file to be processed).
239 
240  // Set branch addresses and branch pointers
241 
242  fCurrent = -1;
243  fChain->SetMakeClass(1);
244 
245  fChain->SetBranchAddress("nH2P", &nH2P, &b_fH2NParticles);
246  fChain->SetBranchAddress("trackID", &trackID, &b_fH2TrackID);
247  fChain->SetBranchAddress("pdgCode", &pdgCode, &b_fH2ParticlePDG);
248  fChain->SetBranchAddress("H2ImpWeight", &H2ImpWeight, &b_fNImpWt);
249  fChain->SetBranchAddress("H2positionX", &H2positionX, &b_fH2ParticleX);
250  fChain->SetBranchAddress("H2positionY", &H2positionY, &b_fH2ParticleY);
251  fChain->SetBranchAddress("H2positionZ", &H2positionZ, &b_fH2ParticleZ);
252  fChain->SetBranchAddress("H2momentumdirX", &H2momentumdirX, &b_fH2ParticleDX);
253  fChain->SetBranchAddress("H2momentumdirY", &H2momentumdirY, &b_fH2ParticleDY);
254  fChain->SetBranchAddress("H2momentumdirZ", &H2momentumdirZ, &b_fH2ParticleDZ);
255  fChain->SetBranchAddress("mass", &mass, &b_fH2ParticleMass);
256  fChain->SetBranchAddress("energy", &energy, &b_fH2ParticleEnergy);
257  fChain->SetBranchAddress("H2momentumX", &H2momentumX, &b_fH2ParticlePX);
258  fChain->SetBranchAddress("H2momentumY", &H2momentumY, &b_fH2ParticlePY);
259  fChain->SetBranchAddress("H2momentumZ", &H2momentumZ, &b_fH2ParticlePZ);
260  fChain->SetBranchAddress("H2PXPZ", &H2PXPZ, &b_fH2ParticlePXPZ);
261  fChain->SetBranchAddress("H2PYPZ", &H2PYPZ, &b_fH2ParticlePYPZ);
262  fChain->SetBranchAddress("H2PProductionX", &H2PProductionX, &b_fH2PProductionX);
263  fChain->SetBranchAddress("H2PProductionY", &H2PProductionY, &b_fH2PProductionY);
264  fChain->SetBranchAddress("H2PProductionZ", &H2PProductionZ, &b_fH2PProductionZ);
265  fChain->SetBranchAddress("H2PmomentumdirX",&H2PmomentumdirX,&b_fH2PmomentumdirX);
266  fChain->SetBranchAddress("H2PmomentumdirY",&H2PmomentumdirY,&b_fH2PmomentumdirY);
267  fChain->SetBranchAddress("H2PmomentumdirZ",&H2PmomentumdirZ,&b_fH2PmomentumdirZ);
268 /* fChain->SetBranchAddress("DPPProductionX", &DPPProductionX, &b_fDPPProductionX);
269  fChain->SetBranchAddress("DPPProductionY", &DPPProductionY, &b_fDPPProductionY);
270  fChain->SetBranchAddress("DPPProductionZ", &DPPProductionZ, &b_fDPPProductionZ);
271  fChain->SetBranchAddress("DPPtrackID", &DPPtrackID, &b_fDPTrackID);
272  fChain->SetBranchAddress("DPParentID", &DPParentID, &b_fDPParentID);
273  fChain->SetBranchAddress("DPenergy", &DPenergy, &b_fDPParticleEnergy);
274  fChain->SetBranchAddress("DPpositionX", &DPpositionX, &b_fDPParticleX);
275  fChain->SetBranchAddress("DPpositionY", &DPpositionY, &b_fDPParticleY);
276  fChain->SetBranchAddress("DPpositionZ", &DPpositionZ, &b_fDPParticleZ);
277  fChain->SetBranchAddress("DPmomentumX", &DPmomentumX, &b_fDPParticlePX);
278  fChain->SetBranchAddress("DPmomentumY", &DPmomentumY, &b_fDPParticlePY);
279  fChain->SetBranchAddress("DPmomentumZ", &DPmomentumZ, &b_fDPParticlePZ);
280  fChain->SetBranchAddress("DPpdgCode", &DPpdgCode, &b_fDPParticlePDG);*/
281  Notify();
282 }
283 
284 Bool_t pidata_H2::Notify()
285 {
286  // The Notify() function is called when a new file is opened. This
287  // can be either for a new TTree in a TChain or when when a new TTree
288  // is started when using PROOF. It is normally not necessary to make changes
289  // to the generated code, but the routine can be extended by the
290  // user if needed. The return value is currently not used.
291 
292  return kTRUE;
293 }
294 
295 void pidata_H2::Show(Long64_t entry)
296 {
297 // Print contents of entry.
298 // If entry is not specified, print current entry
299  if (!fChain) return;
300  fChain->Show(entry);
301 }
302 Int_t pidata_H2::Cut(Long64_t entry)
303 {
304 // This function may be called from Loop.
305 // returns 1 if entry is accepted.
306 // returns -1 otherwise.
307  return 1;
308 }
309 #endif // #ifdef pidata_H2_cxx
std::string filename
Definition: pidata_H2.h:33
void SetTitles1(TH1 *h, const std::string &xtitle="", const std::string &ytitle="")
Double_t H2positionY
Definition: pidata_H2.h:49
Double_t H2positionX
Definition: pidata_H2.h:48
int piplus
Definition: pidata_H2.h:38
TBranch * b_fH2NParticles
Definition: pidata_H2.h:84
int kptot
Definition: pidata_H2.h:40
std::string detectorname
Definition: pidata_H2.h:34
std::string ffilename
Definition: pidata_H2.h:32
virtual Int_t Cut(Long64_t entry)
QList< Entry > entry
int nproton
Definition: pidata_H2.h:38
int numutot
Definition: pidata_H2.h:40
int ptot
Definition: pidata_H2.h:40
TBranch * b_fH2ParticlePDG
Definition: pidata_H2.h:86
Int_t fCurrent
pointer to the analyzed TTree or TChain
Definition: pidata_H2.h:29
int numubar
Definition: pidata_H2.h:38
std::string string
Definition: nybbler.cc:12
Double_t mass
Definition: pidata_H2.h:54
TBranch * b_fH2ParticleDX
Definition: pidata_H2.h:91
Double_t H2momentumdirZ
Definition: pidata_H2.h:53
virtual Bool_t Notify()
int nuetot
Definition: pidata_H2.h:41
TBranch * b_fH2ParticleEnergy
Definition: pidata_H2.h:95
TBranch * b_fH2PProductionZ
Definition: pidata_H2.h:103
virtual Int_t GetEntry(Long64_t entry)
Double_t fTotalPOT
current Tree number in a TChain
Definition: pidata_H2.h:31
int kplus
Definition: pidata_H2.h:38
TBranch * b_fH2ParticlePYPZ
Definition: pidata_H2.h:100
TBranch * b_fH2ParticlePXPZ
Definition: pidata_H2.h:99
TBranch * b_fH2PmomentumdirY
Definition: pidata_H2.h:105
int nuebartot
Definition: pidata_H2.h:41
intermediate_table::const_iterator const_iterator
int numu
Definition: pidata_H2.h:38
Double_t H2ImpWeight
Definition: pidata_H2.h:47
Double_t H2momentumZ
Definition: pidata_H2.h:58
Int_t nH1P
Definition: pidata_H2.h:67
Int_t pdgCode
Definition: pidata_H2.h:46
virtual void Loop()
Double_t H2momentumY
Definition: pidata_H2.h:57
Double_t H2PmomentumdirX
Definition: pidata_H2.h:64
Int_t nH2P
Definition: pidata_H2.h:44
Int_t trackID
Definition: pidata_H2.h:45
int piminus
Definition: pidata_H2.h:38
int ntott
Definition: pidata_H2.h:41
TBranch * b_fNImpWt
Definition: pidata_H2.h:87
int ntot
Definition: pidata_H2.h:41
int rest
Definition: pidata_H2.h:39
int mutot
Definition: pidata_H2.h:41
TBranch * b_fH2TrackID
Definition: pidata_H2.h:85
Double_t H2momentumdirX
Definition: pidata_H2.h:51
virtual void Init(TTree *tree)
TBranch * b_fH2PProductionY
Definition: pidata_H2.h:102
virtual ~pidata_H2()
Double_t H2PXPZ
Definition: pidata_H2.h:59
Double_t H2momentumdirY
Definition: pidata_H2.h:52
int numubartot
Definition: pidata_H2.h:41
Double_t energy
Definition: pidata_H2.h:55
TBranch * b_fH2ParticleDZ
Definition: pidata_H2.h:93
int nelectron
Definition: pidata_H2.h:38
int tot
Definition: pidata_H2.h:38
pidata_H2(TTree *t=0)
int nutaubar
Definition: pidata_H2.h:38
TBranch * b_fH2PmomentumdirX
Definition: pidata_H2.h:104
void SetTitles2(TH2 *h, const std::string &xtitle="", const std::string &ytitle="")
double detz
Definition: pidata_H2.h:37
double detx
Definition: pidata_H2.h:35
double dety
Definition: pidata_H2.h:36
TBranch * b_fH2ParticlePZ
Definition: pidata_H2.h:98
TBranch * b_fH2ParticleDY
Definition: pidata_H2.h:92
TBranch * b_fH2ParticleX
Definition: pidata_H2.h:88
int nuebar
Definition: pidata_H2.h:38
int pptot
Definition: pidata_H2.h:40
Double_t H2PmomentumdirZ
Definition: pidata_H2.h:66
TBranch * b_fH2ParticleZ
Definition: pidata_H2.h:90
TBranch * b_fH2PmomentumdirZ
Definition: pidata_H2.h:106
int nue
Definition: pidata_H2.h:38
Double_t H2PProductionZ
Definition: pidata_H2.h:63
int pmtot
Definition: pidata_H2.h:40
virtual Long64_t LoadTree(Long64_t entry)
Double_t H2PYPZ
Definition: pidata_H2.h:60
Double_t H2positionZ
Definition: pidata_H2.h:50
TBranch * b_fH2ParticleY
Definition: pidata_H2.h:89
TBranch * b_fH2ParticlePX
Definition: pidata_H2.h:96
virtual void Show(Long64_t entry=-1)
TBranch * b_fH2ParticleMass
Definition: pidata_H2.h:94
int kminus
Definition: pidata_H2.h:38
TBranch * b_fH2PProductionX
Definition: pidata_H2.h:101
Double_t H2PmomentumdirY
Definition: pidata_H2.h:65
int etot
Definition: pidata_H2.h:40
TChain * fChain
Definition: pidata_H2.h:27
int neutot
Definition: pidata_H2.h:41
int kmtot
Definition: pidata_H2.h:40
int nutau
Definition: pidata_H2.h:38
int muon
Definition: pidata_H2.h:38
Double_t H2momentumX
Definition: pidata_H2.h:56
int neutron
Definition: pidata_H2.h:38
int rtot
Definition: pidata_H2.h:41
h
training ###############################
Definition: train_cnn.py:186
TBranch * b_fH2ParticlePY
Definition: pidata_H2.h:97
Double_t H2PProductionY
Definition: pidata_H2.h:62
Double_t H2PProductionX
Definition: pidata_H2.h:61
TRandom3 * rand3
Definition: pidata_H2.h:42