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; //!pointer to the analyzed TChain or TChain
21  Int_t fCurrent; //!current Tree number in a TChain
22 
23  Int_t runnum;
24  Int_t subrunnum;
25  Int_t evtnum;
26  Double_t spillPOT;
27  Int_t Nslices;
28  Int_t goodSpill;
29  Double_t horncurrent;
30  Double_t posX;
31  Double_t posY;
32  Double_t widthX;
33  Double_t widthY;
35 
36  Int_t evt_year;
37  Int_t evt_month;
38  Int_t evt_day;
39  Int_t evt_hour;
40  Int_t evt_min;
41  Int_t evt_sec;
42 
43  Int_t Ndeaddcm;
52  Int_t Nouttimehits;
53  Int_t Nintimehits;
55 
56  readNtuple(const char* TypeNameIn, const char* TypeNameOut, TChain *tree=0);
57  virtual ~readNtuple();
58  virtual void Init(TChain *tree);
59  virtual void Loop(const char* TypeNameOut);
60  makeHists* myhists;
61 };
62 
63 #endif
64 
65 #ifdef readNtuple_cxx
66 readNtuple::readNtuple(const char* TypeNameIn, const char* TypeNameOut, TChain *tree)
67 {
68  tree = new TChain("NCAna/beamInfo");
69  ifstream fin(TypeNameIn,ios::in);
70  TString fstr;
71  while(fin>>fstr) tree->Add(fstr);
72 
73  Init(tree);
74  myhists = new makeHists();
75  TString histoname = (TString)TypeNameOut + ".root";
76  myhists->bookHists(histoname);
77 
78  cout<<"********************************************"<<endl;
79  cout<<"Input File is "<<TypeNameIn<<endl;
80  cout<<"Output File is "<<histoname<<endl;
81  cout<<"********************************************"<<endl;
82 }
83 
85 {
86  if (!fChain) return;
87  delete fChain->GetCurrentFile();
88 
89  if(myhists){
90  myhists->saveHists();
91  delete myhists;
92 
93  }
94 }
95 
96 void readNtuple::Init(TChain *tree)
97 {
98  if (!tree) return;
99  fChain = tree;
100 
101  fChain->SetBranchAddress("runnum",&runnum);
102  fChain->SetBranchAddress("subrunnum",&subrunnum);
103  fChain->SetBranchAddress("evtnum",&evtnum);
104  fChain->SetBranchAddress("Nslices",&Nslices);
105  fChain->SetBranchAddress("spillPOT",&spillPOT);
106  fChain->SetBranchAddress("goodSpill",&goodSpill);
107 
108  fChain->SetBranchAddress("horncurrent",&horncurrent);
109  fChain->SetBranchAddress("posX",&posX);
110  fChain->SetBranchAddress("posY",&posY);
111  fChain->SetBranchAddress("widthX",&widthX);
112  fChain->SetBranchAddress("widthY",&widthY);
113  fChain->SetBranchAddress("deltaspilltimensec",&deltaspilltimensec);
114 
115  fChain->SetBranchAddress("evt_year",&evt_year);
116  fChain->SetBranchAddress("evt_month",&evt_month);
117  fChain->SetBranchAddress("evt_day",&evt_day);
118  fChain->SetBranchAddress("evt_hour",&evt_hour);
119  fChain->SetBranchAddress("evt_min",&evt_min);
120  fChain->SetBranchAddress("evt_sec",&evt_sec);
121 
122  fChain->SetBranchAddress("Ndeaddcm",&Ndeaddcm);
123  fChain->SetBranchAddress("Nintimehits",&Nintimehits);
124  fChain->SetBranchAddress("Nouttimehits",&Nouttimehits);
125  fChain->SetBranchAddress("Ndb1apd_24cells",&Ndb1apd_24cells);
126  fChain->SetBranchAddress("Ndb2apd_24cells",&Ndb2apd_24cells);
127  fChain->SetBranchAddress("Ndb3apd_24cells",&Ndb3apd_24cells);
128  fChain->SetBranchAddress("Nmcapd_24cells",&Nmcapd_24cells);
129  fChain->SetBranchAddress("Ndb1apd_28cells",&Ndb1apd_28cells);
130  fChain->SetBranchAddress("Ndb2apd_28cells",&Ndb2apd_28cells);
131  fChain->SetBranchAddress("Ndb3apd_28cells",&Ndb3apd_28cells);
132  fChain->SetBranchAddress("Nmcapd_28cells",&Nmcapd_28cells);
133  fChain->SetBranchAddress("Fouttimehits_noisyapd",&Fouttimehits_noisyapd);
134 }
135 #endif // #ifdef readNtuple_cxx
136 
TString fin
Definition: Style.C:24
virtual void Init(TChain *tree)
Int_t Ndb1apd_24cells
Definition: readNtuple.h:44
Int_t goodSpill
Definition: readNtuple.h:28
Int_t runnum
current Tree number in a TChain
Definition: readNtuple.h:23
Int_t Ndb2apd_24cells
Definition: readNtuple.h:45
Int_t evt_day
Definition: readNtuple.h:38
Int_t Nintimehits
Definition: readNtuple.h:53
Int_t evt_year
Definition: readNtuple.h:36
readNtuple(const char *TypeNameIn, const char *TypeNameNu, const char *TypeNameInt, TChain *tree=0)
Float_t posY
Definition: plotDend.C:21
Int_t deltaspilltimensec
Definition: readNtuple.h:34
Int_t evt_sec
Definition: readNtuple.h:41
Double_t widthX
Definition: readNtuple.h:32
Int_t subrunnum
Definition: readNtuple.h:24
Int_t Ndb1apd_28cells
Definition: readNtuple.h:48
Double_t horncurrent
Definition: readNtuple.h:29
Int_t Nmcapd_28cells
Definition: readNtuple.h:51
TChain * fChain
Double_t widthY
Definition: readNtuple.h:33
Double_t spillPOT
Definition: readNtuple.h:26
void Init(void)
Definition: gXSecComp.cxx:138
Int_t evt_hour
Definition: readNtuple.h:39
OStream cout
Definition: OStream.cxx:6
virtual ~readNtuple()
Int_t Nouttimehits
Definition: readNtuple.h:52
Int_t Nslices
Definition: readNtuple.h:27
Int_t evt_month
Definition: readNtuple.h:37
Double_t posX
Definition: readNtuple.h:30
ifstream in
Definition: comparison.C:7
Double_t posY
Definition: readNtuple.h:31
Int_t Ndb2apd_28cells
Definition: readNtuple.h:49
Int_t Ndeaddcm
Definition: readNtuple.h:43
Float_t Fouttimehits_noisyapd
Definition: readNtuple.h:54
Int_t Ndb3apd_28cells
Definition: readNtuple.h:50
Int_t evt_min
Definition: readNtuple.h:40
Int_t evtnum
Definition: readNtuple.h:25
Float_t posX
Definition: plotDend.C:21
Int_t Ndb3apd_24cells
Definition: readNtuple.h:46
Int_t Nmcapd_24cells
Definition: readNtuple.h:47