ancestor.h
Go to the documentation of this file.
1 
2 //////////////////////////////////////////////////////////
3 // Created by L. Fields
4 //////////////////////////////////////////////////////////
5 
6 #ifndef ancestor_h
7 #define ancestor_h
8 
9 // C++
10 #include <string>
11 #include <vector>
12 #include <fstream>
13 #include <iostream>
14 #include <iomanip>
15 #include <sstream>
16 
17 //ROOT
18 #include <TROOT.h>
19 #include <TChain.h>
20 #include <TFile.h>
21 #include <TRandom3.h>
22 
23 // Dk2nu
24 //#ifndef __CINT__
25 #include "dk2nu/tree/dk2nu.h"
26 //#endif // ifndef __ CINT__
27 
28 class ancestor {
29 public :
30 
31  TChain *fChain; //!pointer to the analyzed TTree or TChain
32  //TTree *fChain; //!pointer to the analyzed TTree or TChain
33  Int_t fCurrent; //!current Tree number in a TChain
34 
35  Double_t fTotalPOT; //total pot used for all files
36  std::string ffilename; //filename for saving histograms
37 
39  double detx; // detector location
40  double dety;
41  double detz;
42 
43  TRandom3 *rand3;
44 
45  // List of branches
46  bsim::Dk2Nu* dk2nu;
47 
48  ancestor();
49 
50  virtual ~ancestor();
51  virtual Int_t Cut(Long64_t entry);
52  virtual Int_t GetEntry(Long64_t entry);
53  virtual Long64_t LoadTree(Long64_t entry);
54  virtual void Init(TTree *tree);
55  virtual void Loop();
56  virtual Bool_t Notify();
57  virtual void Show(Long64_t entry = -1);
58 
59  private:
60 
61 
62 };
63 
64 #endif
65 
66 #ifdef ancestor_cxx
67 
69 {
70 
71  /*
72  // Otherwise Set detector coordinates based on requested detector location
73  if(location=="LBNEND") {
74  detx = 0.0;
75  dety = 0.0;
76  detz = 57400.0;
77  }
78 
79  else if(location=="LBNEFD") {
80  detx = 0.0;
81  dety = 0.0;
82  detz = 129700000.0;
83  }
84  */
85 
86  std::vector<std::string> fFileVec;
87 
88  fFileVec.push_back("/pnfs/dune/persistent/users/ljf26/fluxfiles/g4lbne/v3r5p4/QGSP_BERT/OptimizedEngineeredNov2017/neutrino/flux/dk2nu/g4lbne_v3r5p4_QGSP_BERT_OptimizedEngineeredNov2017_neutrino_00250.dk2nu.root")
89 
90 
91  std::string ntuple_name = "dk2nuTree";
92 
93 
94  fChain = new TChain(ntuple_name.c_str());
95  for(std::vector<std::string>::const_iterator sit = fFileVec.begin(); sit != fFileVec.end(); ++sit)
96  {
97  fChain -> Add(sit -> c_str());
98  }
99 
100  Init(fChain);
101 
102  // initialize random numbers used for oscillation calculations
103  rand3 = new TRandom3(0);
104 
105 }
106 
108 {
109  if (!fChain) return;
110  delete fChain->GetCurrentFile();
111 }
112 
113 Int_t ancestor::GetEntry(Long64_t entry)
114 {
115 // Read contents of entry.
116  if (!fChain) return 0;
117  return fChain->GetEntry(entry);
118 }
119 Long64_t ancestor::LoadTree(Long64_t entry)
120 {
121 // Set the environment to read one entry
122  if (!fChain) return -5;
123  Long64_t centry = fChain->LoadTree(entry);
124  if (centry < 0) return centry;
125  if (!fChain->InheritsFrom(TChain::Class())) return centry;
126  TChain *chain = (TChain*)fChain;
127  if (chain->GetTreeNumber() != fCurrent) {
128  fCurrent = chain->GetTreeNumber();
129  Notify();
130  }
131  return centry;
132 }
133 
134 void ancestor::Init(TTree *tree)
135 {
136  // The Init() function is called when the selector needs to initialize
137  // a new tree or chain. Typically here the branch addresses and branch
138  // pointers of the tree will be set.
139  // It is normally not necessary to make changes to the generated
140  // code, but the routine can be extended by the user if needed.
141  // Init() will be called many times when running on PROOF
142  // (once per file to be processed).
143 
144  // Set branch addresses and branch pointers
145 
146  fCurrent = -1;
147 
148  dk2nu = new bsim::Dk2Nu;
149  fChain->SetBranchAddress("dk2nu",&dk2nu);
150  fChain->GetEntry(0);
151 
152  Notify();
153 }
154 
155 Bool_t ancestor::Notify()
156 {
157  // The Notify() function is called when a new file is opened. This
158  // can be either for a new TTree in a TChain or when when a new TTree
159  // is started when using PROOF. It is normally not necessary to make changes
160  // to the generated code, but the routine can be extended by the
161  // user if needed. The return value is currently not used.
162 
163  return kTRUE;
164 }
165 
166 void ancestor::Show(Long64_t entry)
167 {
168 // Print contents of entry.
169 // If entry is not specified, print current entry
170  if (!fChain) return;
171  fChain->Show(entry);
172 }
173 Int_t ancestor::Cut(Long64_t entry)
174 {
175 // This function may be called from Loop.
176 // returns 1 if entry is accepted.
177 // returns -1 otherwise.
178  return 1;
179 }
180 #endif // #ifdef eventRates_cxx
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
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
virtual Int_t GetEntry(Long64_t entry)
std::string detectorname
Definition: ancestor.h:38