studyAncestorsL.cc
Go to the documentation of this file.
1 // C++
2 #include <string>
3 #include <vector>
4 #include <fstream>
5 #include <iostream>
6 #include <iomanip>
7 #include <sstream>
8 
9 //ROOT
10 #include <TROOT.h>
11 #include <TChain.h>
12 #include <TFile.h>
13 #include <TRandom3.h>
14 
15 #include <TStyle.h>
16 
17 #include <string>
18 #include <iostream>
19 #include "TROOT.h"
20 #include "TH2D.h"
21 #include "TCanvas.h"
22 #include "TColor.h"
23 
24 #include "dk2nu/tree/dk2nu.h"
25 #include "dk2nu/tree/dkmeta.h"
26 
27 class ancestor {
28 public :
29 
30  TChain *fChain; //!pointer to the analyzed TTree or TChain
31  //TTree *fChain; //!pointer to the analyzed TTree or TChain
32  Int_t fCurrent; //!current Tree number in a TChain
33 
34  Double_t fTotalPOT; //total pot used for all files
35  std::string ffilename; //filename for saving histograms
36 
38  double detx; // detector location
39  double dety;
40  double detz;
41 
42  TRandom3 *rand3;
43 
44  // List of branches
45  bsim::Dk2Nu* dk2nu;
46 
47  ancestor();
48 
49  virtual ~ancestor();
50  virtual Int_t Cut(Long64_t entry);
51  virtual Int_t GetEntry(Long64_t entry);
52  virtual Long64_t LoadTree(Long64_t entry);
53  virtual void Init(TTree *tree);
54  virtual void Loop();
55  virtual Bool_t Notify();
56  virtual void Show(Long64_t entry = -1);
57 
58  private:
59 
60 
61 };
62 
64 {
65 
66  /*
67  // Otherwise Set detector coordinates based on requested detector location
68  if(location=="LBNEND") {
69  detx = 0.0;
70  dety = 0.0;
71  detz = 57400.0;
72  }
73 
74  else if(location=="LBNEFD") {
75  detx = 0.0;
76  dety = 0.0;
77  detz = 129700000.0;
78  }
79  */
80 
81  std::vector<std::string> fFileVec;
82 
83  fFileVec.push_back("/pnfs/dune/scratch/users/ljf26/fluxfiles/g4lbne/v3r5p4/QGSP_BERT/OptimizedEngineeredNov2017_NoSnout/neutrino/flux/g4lbne_v3r5p4_QGSP_BERT_OptimizedEngineeredNov2017_NoSnout_neutrino_00250.dk2nu.root");
84  fFileVec.push_back("/pnfs/dune/scratch/users/ljf26/fluxfiles/g4lbne/v3r5p4/QGSP_BERT/OptimizedEngineeredNov2017_NoSnout/neutrino/flux/g4lbne_v3r5p4_QGSP_BERT_OptimizedEngineeredNov2017_NoSnout_neutrino_00249.dk2nu.root");
85  fFileVec.push_back("/pnfs/dune/scratch/users/ljf26/fluxfiles/g4lbne/v3r5p4/QGSP_BERT/OptimizedEngineeredNov2017_NoSnout/neutrino/flux/g4lbne_v3r5p4_QGSP_BERT_OptimizedEngineeredNov2017_NoSnout_neutrino_00248.dk2nu.root");
86  fFileVec.push_back("/pnfs/dune/scratch/users/ljf26/fluxfiles/g4lbne/v3r5p4/QGSP_BERT/OptimizedEngineeredNov2017_NoSnout/neutrino/flux/g4lbne_v3r5p4_QGSP_BERT_OptimizedEngineeredNov2017_NoSnout_neutrino_00247.dk2nu.root");
87  fFileVec.push_back("/pnfs/dune/scratch/users/ljf26/fluxfiles/g4lbne/v3r5p4/QGSP_BERT/OptimizedEngineeredNov2017_NoSnout/neutrino/flux/g4lbne_v3r5p4_QGSP_BERT_OptimizedEngineeredNov2017_NoSnout_neutrino_00246.dk2nu.root");
88  fFileVec.push_back("/pnfs/dune/scratch/users/ljf26/fluxfiles/g4lbne/v3r5p4/QGSP_BERT/OptimizedEngineeredNov2017_NoSnout/neutrino/flux/g4lbne_v3r5p4_QGSP_BERT_OptimizedEngineeredNov2017_NoSnout_neutrino_00245.dk2nu.root");
89  fFileVec.push_back("/pnfs/dune/scratch/users/ljf26/fluxfiles/g4lbne/v3r5p4/QGSP_BERT/OptimizedEngineeredNov2017_NoSnout/neutrino/flux/g4lbne_v3r5p4_QGSP_BERT_OptimizedEngineeredNov2017_NoSnout_neutrino_00244.dk2nu.root");
90  fFileVec.push_back("/pnfs/dune/scratch/users/ljf26/fluxfiles/g4lbne/v3r5p4/QGSP_BERT/OptimizedEngineeredNov2017_NoSnout/neutrino/flux/g4lbne_v3r5p4_QGSP_BERT_OptimizedEngineeredNov2017_NoSnout_neutrino_00243.dk2nu.root");
91  fFileVec.push_back("/pnfs/dune/scratch/users/ljf26/fluxfiles/g4lbne/v3r5p4/QGSP_BERT/OptimizedEngineeredNov2017_NoSnout/neutrino/flux/g4lbne_v3r5p4_QGSP_BERT_OptimizedEngineeredNov2017_NoSnout_neutrino_00242.dk2nu.root");
92  fFileVec.push_back("/pnfs/dune/scratch/users/ljf26/fluxfiles/g4lbne/v3r5p4/QGSP_BERT/OptimizedEngineeredNov2017_NoSnout/neutrino/flux/g4lbne_v3r5p4_QGSP_BERT_OptimizedEngineeredNov2017_NoSnout_neutrino_00241.dk2nu.root");
93  fFileVec.push_back("/pnfs/dune/scratch/users/ljf26/fluxfiles/g4lbne/v3r5p4/QGSP_BERT/OptimizedEngineeredNov2017_NoSnout/neutrino/flux/g4lbne_v3r5p4_QGSP_BERT_OptimizedEngineeredNov2017_NoSnout_neutrino_00240.dk2nu.root");
94  fFileVec.push_back("/pnfs/dune/scratch/users/ljf26/fluxfiles/g4lbne/v3r5p4/QGSP_BERT/OptimizedEngineeredNov2017_NoSnout/neutrino/flux/g4lbne_v3r5p4_QGSP_BERT_OptimizedEngineeredNov2017_neutrino_00239.dk2nu.root");
95 
96 
97  std::string ntuple_name = "dk2nuTree";
98 
99 
100  fChain = new TChain(ntuple_name.c_str());
101  for(std::vector<std::string>::const_iterator sit = fFileVec.begin(); sit != fFileVec.end(); ++sit)
102  {
103  fChain -> Add(sit -> c_str());
104  }
105 
106  Init(fChain);
107 
108  // initialize random numbers used for oscillation calculations
109  rand3 = new TRandom3(0);
110 
111 }
112 
114 {
115  if (!fChain) return;
116  delete fChain->GetCurrentFile();
117 }
118 
119 Int_t ancestor::GetEntry(Long64_t entry)
120 {
121 // Read contents of entry.
122  if (!fChain) return 0;
123  return fChain->GetEntry(entry);
124 }
125 Long64_t ancestor::LoadTree(Long64_t entry)
126 {
127 // Set the environment to read one entry
128  if (!fChain) return -5;
129  Long64_t centry = fChain->LoadTree(entry);
130  if (centry < 0) return centry;
131  if (!fChain->InheritsFrom(TChain::Class())) return centry;
132  TChain *chain = (TChain*)fChain;
133  if (chain->GetTreeNumber() != fCurrent) {
134  fCurrent = chain->GetTreeNumber();
135  Notify();
136  }
137  return centry;
138 }
139 
140 void ancestor::Init(TTree *tree)
141 {
142  // The Init() function is called when the selector needs to initialize
143  // a new tree or chain. Typically here the branch addresses and branch
144  // pointers of the tree will be set.
145  // It is normally not necessary to make changes to the generated
146  // code, but the routine can be extended by the user if needed.
147  // Init() will be called many times when running on PROOF
148  // (once per file to be processed).
149 
150  // Set branch addresses and branch pointers
151 
152  fCurrent = -1;
153 
154  dk2nu = new bsim::Dk2Nu;
155  fChain->SetBranchAddress("dk2nu",&dk2nu);
156  fChain->GetEntry(0);
157 
158  Notify();
159 }
160 
162 {
163  // The Notify() function is called when a new file is opened. This
164  // can be either for a new TTree in a TChain or when when a new TTree
165  // is started when using PROOF. It is normally not necessary to make changes
166  // to the generated code, but the routine can be extended by the
167  // user if needed. The return value is currently not used.
168 
169  return kTRUE;
170 }
171 
172 void ancestor::Show(Long64_t entry)
173 {
174 // Print contents of entry.
175 // If entry is not specified, print current entry
176  if (!fChain) return;
177  fChain->Show(entry);
178 }
179 Int_t ancestor::Cut(Long64_t entry)
180 {
181 // This function may be called from Loop.
182 // returns 1 if entry is accepted.
183 // returns -1 otherwise.
184  return 1;
185 }
186 
187 void ancestor::Loop()
188 {
189 
190 
191  dk2nu = new bsim::Dk2Nu;
192  fChain->SetBranchAddress("dk2nu",&dk2nu);
193 
194  double z = 2267; // z position where you want to plot hadron parent distributions
195 
196  TH2D *h2_all = new TH2D("h_all","",20,-100,100,20,-100,100);
197  TH2D *h2_fardet = new TH2D("h_fardet","",20,-100,100,20,-100,100);
198  TH2D *h2_fardet_peak = new TH2D("h_fardet_peak","",20,-100,100,20,-100,100);
199  TH1D *hx_fardet = new TH1D("hx_fardet","",40,-100,100);
200  TH1D *hy_fardet = new TH1D("hy_fardet","",40,-100,100);
201 
202  TH2D *h_vxy_all = new TH2D("h_vxy_all","",20,-100,100,20,-100,100);
203  TH2D *h_vxy = new TH2D("h_vxy","",20,-100,100,20,-100,100);
204  TH2D *h_vxy_peak = new TH2D("h_vxy_peak","",20,-100,100,20,-100,100);
205  TH1D *h_vx = new TH1D("h_vx","",40,-100,100);
206  TH1D *h_vy = new TH1D("h_vy","",40,-100,100);
207  TH1D *h_vx_peak = new TH1D("h_vx_peak","",40,-100,100);
208  TH1D *h_vy_peak = new TH1D("h_vy_peak","",40,-100,100);
209 
210  TH1D *h_fluxfardet = new TH1D("h_fluxfardet","",40,0,20);
211 
212  TCanvas *c = new TCanvas();
213 
214  int iread = 0;
215  Long64_t nentries = fChain->GetEntries();
216  std::cout << "Total number of Entries = " << nentries << std::endl;
217 
218  double ancestors_tot = 0;
219  double ancestors_10 = 0;
220  double ancestors_20 = 0;
221  double ancestors_30 = 0;
222  double ancestors_40 = 0;
223  double ancestors_50 = 0;
224  double ancestors_60 = 0;
225  double ancestors_70 = 0;
226  double ancestors_77p5 = 0;
227  double ancestors_80 = 0;
228  double ancestors_90 = 0;
229  double ancestors_100 = 0;
230 
231  for (Long64_t jentry=0; jentry<nentries;jentry++)
232  {
233  fChain->GetEntry(jentry);
234  ++iread;
235 
236  if(iread % 10000 == 0)
237  {
238  std::cout << "Reading Entry " << iread << std::endl;
239  }
240 
241 
242  double Nimpwt = dk2nu->decay.nimpwt;
243  int Ntype = dk2nu->decay.ntype;
244  int Nancestors = dk2nu->ancestor.size();
245  double fardetwt = dk2nu->nuray[2].wgt;
246 
247  h_fluxfardet->Fill(dk2nu->nuray[2].E,Nimpwt*fardetwt);
248 
249  if(dk2nu->decay.vz>z-100 && dk2nu->decay.vz<z+100) {
250  h_vxy_all->Fill(dk2nu->decay.vx,dk2nu->decay.vy,Nimpwt);
251  h_vxy->Fill(dk2nu->decay.vx,dk2nu->decay.vy,Nimpwt*fardetwt);
252  h_vx->Fill(dk2nu->decay.vx,Nimpwt*fardetwt);
253  h_vy->Fill(dk2nu->decay.vy,Nimpwt*fardetwt);
254 
255  if(dk2nu->nuray[2].E > 0.5 &&
256  dk2nu->nuray[2].E < 4.0 &&
257  dk2nu->decay.ntype==14) {
258  h_vxy_peak->Fill(dk2nu->decay.vx,dk2nu->decay.vy,Nimpwt*fardetwt);
259  h_vx_peak->Fill(dk2nu->decay.vx,Nimpwt*fardetwt);
260  h_vy_peak->Fill(dk2nu->decay.vy,Nimpwt*fardetwt);
261  }
262  }
263 
264  for(int i = 0; i<Nancestors; i++) {
265  // Skip neutrinos -- they don't care if the snout is there
266  if(dk2nu->ancestor[i].pdg == 12 ||
267  dk2nu->ancestor[i].pdg == -12 ||
268  dk2nu->ancestor[i].pdg == 14 ||
269  dk2nu->ancestor[i].pdg == -14)
270  continue;
271 
272 
273  if(dk2nu->ancestor[i].startz <= z &&
274  (i+1 == Nancestors || dk2nu->ancestor[i+1].startz>z)) {
275  double projx = dk2nu->ancestor[i+1].startx - ((dk2nu->ancestor[i+1].startz-z)*dk2nu->ancestor[i].stoppx/dk2nu->ancestor[i].stoppz);
276  double projy = dk2nu->ancestor[i+1].starty - ((dk2nu->ancestor[i+1].startz-z)*dk2nu->ancestor[i].stoppy/dk2nu->ancestor[i].stoppz);
277  h2_all->Fill(projx,projy,Nimpwt);
278  h2_fardet->Fill(projx,projy,Nimpwt*fardetwt*1);
279  hx_fardet->Fill(projx,Nimpwt*fardetwt*1);
280  hy_fardet->Fill(projy,Nimpwt*fardetwt*1);
281 
282  if(dk2nu->nuray[2].E > 0.5 &&
283  dk2nu->nuray[2].E < 4.0 &&
284  dk2nu->decay.ntype==14) {
285  h2_fardet_peak->Fill(projx,projy,Nimpwt*fardetwt*1);
286  ancestors_tot += Nimpwt*fardetwt;
287  double radius = sqrt(projx*projx+projy*projy);
288  if(radius<10)
289  ancestors_10 += Nimpwt*fardetwt;
290  if(radius<20)
291  ancestors_20 += Nimpwt*fardetwt;
292  if(radius<30)
293  ancestors_30 += Nimpwt*fardetwt;
294  if(radius<40)
295  ancestors_40 += Nimpwt*fardetwt;
296  if(radius<50)
297  ancestors_50 += Nimpwt*fardetwt;
298  if(radius<60)
299  ancestors_60 += Nimpwt*fardetwt;
300  if(radius<70)
301  ancestors_70 += Nimpwt*fardetwt;
302  if(radius<77.5)
303  ancestors_77p5 += Nimpwt*fardetwt;
304  if(radius<80)
305  ancestors_80 += Nimpwt*fardetwt;
306  if(radius<90)
307  ancestors_90 += Nimpwt*fardetwt;
308  if(radius<100)
309  ancestors_100 += Nimpwt*fardetwt;
310  }
311 
312  }
313 
314  }
315 
316  }//end loop over entries
317 
318  std::cout<<"Total ancestors "<<ancestors_tot<<std::endl;
319  std::cout<<"Total within 10 cm "<<ancestors_10/ancestors_tot<<std::endl;
320  std::cout<<"Total within 20 cm "<<ancestors_20/ancestors_tot<<std::endl;
321  std::cout<<"Total within 30 cm "<<ancestors_30/ancestors_tot<<std::endl;
322  std::cout<<"Total within 40 cm "<<ancestors_40/ancestors_tot<<std::endl;
323  std::cout<<"Total within 50 cm "<<ancestors_50/ancestors_tot<<std::endl;
324  std::cout<<"Total within 60 cm "<<ancestors_60/ancestors_tot<<std::endl;
325  std::cout<<"Total within 70 cm "<<ancestors_70/ancestors_tot<<std::endl;
326  std::cout<<"Total within 77.5 cm "<<ancestors_77p5/ancestors_tot<<std::endl;
327  std::cout<<"Total within 80 cm "<<ancestors_80/ancestors_tot<<std::endl;
328  std::cout<<"Total within 90 cm "<<ancestors_90/ancestors_tot<<std::endl;
329  std::cout<<"Total within 100 cm "<<ancestors_100/ancestors_tot<<std::endl;
330 
331 
332  std::string str_z = std::to_string(z);
333  h2_all->SetTitle("All Neutrinos");
334  h2_fardet->SetTitle("Neutrinos at Far Detector");
335  h2_fardet_peak->SetTitle("Peak #nu_#mu neutrinos at Far Detector");
336  h_vxy_all->SetTitle("All Neutrino");
337  h_vxy->SetTitle("Neutrinos at Far Detector");
338  h_vx->SetTitle("Neutrinos at Far Detector");
339  h_vy->SetTitle("Neutrinos at Far Detector");
340  h_vxy_peak->SetTitle("Peak #nu_#mu neutrinos at Far Detector");
341  h_vx_peak->SetTitle("Peak #nu_#mu neutrinos at Far Detector");
342  h_vy_peak->SetTitle("Peak #nu_#mu neutrinos at Far Detector");
343  h2_all->GetXaxis()->SetTitle(("Ancestor X position (cm) at z = "+str_z).c_str());
344  h2_all->GetYaxis()->SetTitle(("Ancestor Y position (cm) at z = "+str_z).c_str());
345  h2_fardet->GetXaxis()->SetTitle(("Ancestor X position (cm) at z = "+str_z).c_str());
346  h2_fardet->GetYaxis()->SetTitle(("Ancestor Y position (cm) at z = "+str_z).c_str());
347  h2_fardet_peak->GetXaxis()->SetTitle(("Ancestor X position (cm) at z = "+str_z).c_str());
348  h2_fardet_peak->GetYaxis()->SetTitle(("Ancestor Y position (cm) at z = "+str_z).c_str());
349  h_vxy->GetXaxis()->SetTitle(("Neutrino parent decay X position (cm) at z = "+str_z).c_str());
350  h_vxy_all->GetXaxis()->SetTitle(("Neutrino parent decay X position (cm) at z = "+str_z).c_str());
351  h_vx->GetXaxis()->SetTitle(("Neutrino parent decay X position (cm) at z = "+str_z).c_str());
352  h_vy->GetXaxis()->SetTitle(("Neutrino parent decay Y position (cm) at z = "+str_z).c_str());
353  h_vxy->GetYaxis()->SetTitle(("Neutrino parent decay Y postion (cm) at z = "+str_z).c_str());
354  h_vxy_all->GetYaxis()->SetTitle(("Neutrino parent decay Y postion (cm) at z = "+str_z).c_str());
355  h_vxy_peak->GetXaxis()->SetTitle(("Neutrino parent decay position (cm) at z = "+str_z).c_str());
356  h_vx_peak->GetXaxis()->SetTitle(("Neutrino parent decay X position (cm) at z = "+str_z).c_str());
357  h_vy_peak->GetXaxis()->SetTitle(("Neutrino parent decay Y position at (cm) z = "+str_z).c_str());
358  h_vxy_peak->GetYaxis()->SetTitle(("Neutrino parent decay postion at (cm) z = "+str_z).c_str());
359 
360  gStyle->SetOptStat(0);
361  gStyle->SetPalette(56);
362 
363  h2_all->SetContour(99);
364  h2_all->Draw("COLZ");
365  c->Print("Ancestors_Through_Window_AllNu.eps");
366  c->Print("Ancestors_Through_Window_AllNu.png");
367  h2_fardet->Draw("COLZ");
368  c->Print("Ancestors_Through_Window_FarDetNu_2D.eps");
369  // c->Print("Ancestors_Through_Window_FarDetNu_2D.png");
370  h2_fardet_peak->Draw("COLZ");
371  c->Print("Ancestors_Through_Window_FarDetNuPeak_2D.eps");
372  //c->Print("Ancestors_Through_Window_FarDetNuPeak_2D.png");
373  hx_fardet->Draw();
374  c->Print("Ancestors_Through_Window_FarDetNu_x.eps");
375  c->Print("Ancestors_Through_Window_FarDetNu_x.png");
376  hy_fardet->Draw();
377  c->Print("Ancestors_Through_Window_FarDetNu_y.eps");
378  c->Print("Ancestors_Through_Window_FarDetNu_y.png");
379  h_fluxfardet->Draw();
380  c->Print("Flux_fardet.eps");
381  c->Print("Flux_fardet.png");
382 
383 
384  h_vxy->Draw("COLZ");
385  c->Print("Decay_Position_Near_Window_FarDetNu_2D.eps");
386  //c->Print("Decay_Position_Near_Window_FarDetNu_2D.png");
387 
388  h_vxy_all->Draw("COLZ");
389  c->Print("Decay_Position_Near_Window_AllNu_2D.eps");
390  c->Print("Decay_Position_Near_Window_AllNu_2D.png");
391 
392  h_vxy_peak->Draw("COLZ");
393  c->Print("Decay_Position_Near_Window_FarDetNuPeak_2D.eps");
394  //c->Print("Decay_Position_Near_Window_FarDetNuPeak_2D.png");
395 
396  h_vx->Draw("");
397  c->Print("Decay_Position_Near_Window_FarDetNu_x.eps");
398  c->Print("Decay_Position_Near_Window_FarDetNu_x.eps");
399  h_vy->Draw("");
400  c->Print("Decay_Position_Near_Window_FarDetNu_y.eps");
401  c->Print("Decay_Position_Near_Window_FarDetNu_y.eps");
402 
403  h_vx_peak->Draw("");
404  c->Print("Decay_Position_Near_Window_FarDetNuPeak_x.eps");
405  c->Print("Decay_Position_Near_Window_FarDetNuPeak_x.eps");
406  h_vy_peak->Draw("");
407  c->Print("Decay_Position_Near_Window_FarDetNuPeak_y.eps");
408  c->Print("Decay_Position_Near_Window_FarDetNuPeak_y.eps");
409 
410 }
411 
412 
413 
414 
415 int main(int argc, char* argv[]) {
416 
417  ancestor t;
418  std::cout<< "BLAH"<<std::endl;
419  t.Loop();
420 
421 }
double detx
Definition: ancestor.h:39
QList< Entry > entry
virtual void Init(TTree *tree)
std::string string
Definition: nybbler.cc:12
std::string ffilename
Definition: ancestor.h:36
intermediate_table::const_iterator const_iterator
virtual Int_t Cut(Long64_t entry)
double dety
Definition: ancestor.h:40
virtual Long64_t LoadTree(Long64_t entry)
virtual ~ancestor()
Int_t fCurrent
pointer to the analyzed TTree or TChain
Definition: ancestor.h:33
double detz
Definition: ancestor.h:41
double z
int iread
Definition: ancestorL.cc:26
int main(int argc, char *argv[])
virtual Bool_t Notify()
TChain * fChain
Definition: ancestor.h:31
Double_t fTotalPOT
current Tree number in a TChain
Definition: ancestor.h:35
TRandom3 * rand3
Definition: ancestor.h:43
virtual void Show(Long64_t entry=-1)
virtual void Loop()
Definition: ancestorL.cc:28
bsim::Dk2Nu * dk2nu
Definition: ancestor.h:46
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34
virtual Int_t GetEntry(Long64_t entry)
QTextStream & endl(QTextStream &s)
std::string detectorname
Definition: ancestor.h:38