readNtuple.h
Go to the documentation of this file.
1 #ifndef readNtuple_h
2 #define readNtuple_h
3 
4 #include <TROOT.h>
5 #include <TChain.h>
6 #include <TFile.h>
7 #include "makeHists.h"
8 #include "iostream"
9 #include "fstream"
10 
11 #include "TMVA/Tools.h"
12 #include "TMVA/Reader.h"
13 #include "TMVA/MethodCuts.h"
14 
15 using namespace std;
16 
17 class readNtuple {
18  public :
19 
20  TChain *fChain; //!poInt_ter to the analyzed TChain or TChain
21  Int_t fCurrent; //!current Tree number in a TChain
22 
23  float nu_Vx;//true vertex X
24  float nu_Vy;//true vertex Y
25  float nu_Vz;//true vertex Z
26  float nu_truePx;//true Px
27  float nu_truePy;//true Py
28  float nu_truePz;//true Pz
29  float nu_trueE;//true E
30  int nu_ccnc;
31  int nu_PDG;
34  int nu_mode;
37  float nu_HadX;
38  float nu_HadY;
39  float nu_HadW;
40  float nu_Q2;
41 
42  //lepton info
43  int lep_PDG;
44  float lep_Px;
45  float lep_Py;
46  float lep_Pz;
47  float lep_E;
48 
49  //4-momentum for particles originating from the nu interaction vertex
51  int partPDG[100];
52  float partPx[100];
53  float partPy[100];
54  float partPz[100];
55  float partE[100];
56 
57  //GENIE reweights or cross section uncertainties
58  int Nweights;
59  float plus1sigma[68];
60  float plus2sigma[68];
61  float minus1sigma[68];
62  float minus2sigma[68];
63 
64 
65  readNtuple(const char* TypeNameIn, const char* TypeNameNu, const char* TypeNameInt, TChain *tree=0);
66  virtual ~readNtuple();
67  virtual void Init(TChain *tree);
68  virtual void Loop(const char* TypeNameNu, const char* TypeNameInt);
70 };
71 
72 #endif
73 
74 #ifdef readNtuple_cxx
75 readNtuple::readNtuple(const char* TypeNameIn, const char* TypeNameNu, const char* TypeNameInt, TChain *tree)
76 {
77  tree = new TChain("GenieTruth/GenieTruth");
78  ifstream fin(TypeNameIn,ios::in);
79  TString fstr;
80  while(fin>>fstr) tree->Add(fstr);
81 
82  Init(tree);
83  myhists = new makeHists();
84  TString histoname = (TString)TypeNameNu+"_"+(TString)TypeNameInt + "_results.root";
85  myhists->bookHists(histoname);
86 
87  cout<<"********************************************"<<endl;
88  cout<<"Input File is "<<TypeNameIn<<endl;
89  cout<<"Output File is "<<histoname<<endl;
90  cout<<"********************************************"<<endl;
91 }
92 
94 {
95  if (!fChain) return;
96  delete fChain->GetCurrentFile();
97 
98  if(myhists){
99  myhists->saveHists();
100  delete myhists;
101 
102  }
103 }
104 
105 void readNtuple::Init(TChain *tree)
106 {
107  if (!tree) return;
108  fChain = tree;
109 
110 
111  fChain->SetBranchAddress("nu_Vx",&nu_Vx);
112  fChain->SetBranchAddress("nu_Vy",&nu_Vy);
113  fChain->SetBranchAddress("nu_Vz",&nu_Vz);
114 
115  fChain->SetBranchAddress("nu_trueE",&nu_trueE);
116  fChain->SetBranchAddress("nu_truePx",&nu_truePx);
117  fChain->SetBranchAddress("nu_truePy",&nu_truePy);
118  fChain->SetBranchAddress("nu_truePz",&nu_truePz);
119 
120  fChain->SetBranchAddress("nu_ccnc",&nu_ccnc);
121  fChain->SetBranchAddress("nu_PDG",&nu_PDG);
122  fChain->SetBranchAddress("nu_origPDG",&nu_origPDG);
123  fChain->SetBranchAddress("nu_mode",&nu_mode);
124  fChain->SetBranchAddress("nu_intType",&nu_intType);
125  fChain->SetBranchAddress("nu_hitNucl",&nu_hitNucl);
126  fChain->SetBranchAddress("nu_HadX",&nu_HadX);
127  fChain->SetBranchAddress("nu_HadY",&nu_HadY);
128  fChain->SetBranchAddress("nu_HadW",&nu_HadW);
129  fChain->SetBranchAddress("nu_Q2",&nu_Q2);
130 
131  fChain->SetBranchAddress("lep_PDG",&lep_PDG);
132  fChain->SetBranchAddress("lep_E",&lep_E);
133  fChain->SetBranchAddress("lep_Px",&lep_Px);
134  fChain->SetBranchAddress("lep_Py",&lep_Py);
135  fChain->SetBranchAddress("lep_Pz",&lep_Pz);
136 
137  fChain->SetBranchAddress("Nparticles",&Nparticles);
138  fChain->SetBranchAddress("partPDG",&partPDG);
139  fChain->SetBranchAddress("partPx",&partPx);
140  fChain->SetBranchAddress("partPy",&partPy);
141  fChain->SetBranchAddress("partPz",&partPz);
142  fChain->SetBranchAddress("partE",&partE);
143 
144  fChain->SetBranchAddress("Nweights",&Nweights);
145  fChain->SetBranchAddress("plus1sigma",&plus1sigma);
146  fChain->SetBranchAddress("plus2sigma",&plus2sigma);
147  fChain->SetBranchAddress("minus1sigma",&minus1sigma);
148  fChain->SetBranchAddress("minus2sigma",&minus2sigma);
149 }
150 #endif // #ifdef readNtuple_cxx
151 
TString fin
Definition: Style.C:24
virtual void Init(TChain *tree)
float nu_trueE
Definition: readNtuple.h:29
int Nparticles
Definition: readNtuple.h:50
float nu_HadW
Definition: readNtuple.h:39
makeHists * myhists
Definition: readNtuple.h:69
int nu_origPDG
Definition: readNtuple.h:32
int Nweights
Definition: readNtuple.h:58
float lep_Px
Definition: readNtuple.h:44
readNtuple(const char *TypeNameIn, const char *TypeNameNu, const char *TypeNameInt, TChain *tree=0)
float nu_Q2
Definition: readNtuple.h:40
float nu_Vy
Definition: readNtuple.h:24
float lep_Py
Definition: readNtuple.h:45
float nu_HadY
Definition: readNtuple.h:38
float nu_truePx
Definition: readNtuple.h:26
int nu_intType
Definition: readNtuple.h:35
float nu_Vz
Definition: readNtuple.h:25
int nu_ccnc
Definition: readNtuple.h:30
int nu_mode
Definition: readNtuple.h:34
int nu_orig_parentPDG
Definition: readNtuple.h:33
float nu_truePy
Definition: readNtuple.h:27
float nu_HadX
Definition: readNtuple.h:37
TChain * fChain
float nu_truePz
Definition: readNtuple.h:28
void Init(void)
Definition: gXSecComp.cxx:138
TChain * fChain
Definition: readNtuple.h:20
OStream cout
Definition: OStream.cxx:6
virtual ~readNtuple()
int nu_PDG
Definition: readNtuple.h:31
ifstream in
Definition: comparison.C:7
int lep_PDG
Definition: readNtuple.h:43
float nu_Vx
current Tree number in a TChain
Definition: readNtuple.h:23
float lep_Pz
Definition: readNtuple.h:46
float lep_E
Definition: readNtuple.h:47
int nu_hitNucl
Definition: readNtuple.h:36
Int_t fCurrent
poInt_ter to the analyzed TChain or TChain
Definition: readNtuple.h:21