1 |
#ifndef NtupleSkim_h
|
2 |
#define NtupleSkim_h
|
3 |
|
4 |
#include <TROOT.h>
|
5 |
#include <TChain.h>
|
6 |
#include <TFile.h>
|
7 |
#include <TH1.h>
|
8 |
#include <TH2.h>
|
9 |
#include <TH3.h>
|
10 |
#include <vector>
|
11 |
#include <iostream>
|
12 |
#include "TObject.h"
|
13 |
|
14 |
class NtupleSkim {
|
15 |
public :
|
16 |
|
17 |
TH1D *h_d0;
|
18 |
TH1D *h_d0bs;
|
19 |
TH1D *h_sigmad0;
|
20 |
TH1D *h_z0;
|
21 |
TH1D *h_pt;
|
22 |
TH1D *h_normChi2;
|
23 |
TH1D *h_nPixelHit;
|
24 |
TH1D *h_nStripHit;
|
25 |
TProfile *h_d0_phi;
|
26 |
TProfile *h_d0bs_phi;
|
27 |
TProfile *h_vx_dz;
|
28 |
TProfile *h_vy_dz;
|
29 |
|
30 |
TTree *fChain; //!pointer to the analyzed TTree or TChain
|
31 |
Int_t fCurrent; //!current Tree number in a TChain
|
32 |
|
33 |
// Declaration of leave types
|
34 |
Float_t run;
|
35 |
Float_t event;
|
36 |
Double_t pt;
|
37 |
Double_t d0;
|
38 |
Double_t d0bs;
|
39 |
Double_t phi0;
|
40 |
Double_t sigmad0;
|
41 |
Double_t z0;
|
42 |
Double_t vx;
|
43 |
Double_t vy;
|
44 |
//Double_t sigmaz0;
|
45 |
|
46 |
UInt_t nPixelHit;
|
47 |
UInt_t nStripHit;
|
48 |
Double_t normchi2;
|
49 |
Double_t eta;
|
50 |
|
51 |
// List of branches
|
52 |
TBranch *b_run;
|
53 |
TBranch *b_event;
|
54 |
TBranch *b_vx;
|
55 |
TBranch *b_vy;
|
56 |
TBranch *b_pt;
|
57 |
TBranch *b_d0;
|
58 |
TBranch *b_d0bs;
|
59 |
TBranch *b_phi0;
|
60 |
TBranch *b_sigmad0;
|
61 |
TBranch *b_z0;
|
62 |
TBranch *b_sigmaz0;
|
63 |
|
64 |
TBranch *b_nPixelHit;
|
65 |
TBranch *b_nStripHit;
|
66 |
TBranch *b_normchi2;
|
67 |
TBranch *b_eta;
|
68 |
|
69 |
NtupleSkim(const char* fname ,TTree *tree=0);
|
70 |
virtual ~NtupleSkim();
|
71 |
virtual Int_t Cut(Long64_t entry);
|
72 |
virtual Int_t GetEntry(Long64_t entry);
|
73 |
virtual Long64_t LoadTree(Long64_t entry);
|
74 |
virtual void Init(TTree *tree);
|
75 |
virtual void Loop(int maxEvents= 0);
|
76 |
virtual Bool_t Notify();
|
77 |
virtual void Show(Long64_t entry = -1);
|
78 |
virtual void Book();
|
79 |
ClassDef(NtupleSkim,1)
|
80 |
};
|
81 |
|
82 |
#endif
|
83 |
#ifdef NtupleSkim_cc
|
84 |
NtupleSkim::NtupleSkim(const char* fname,TTree *tree)
|
85 |
{
|
86 |
// if parameter tree is not specified (or zero), connect the file
|
87 |
// used to generate this class and read the Tree.
|
88 |
if (tree == 0) {
|
89 |
TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject(fname);
|
90 |
if (!f) {
|
91 |
f = new TFile(fname);
|
92 |
}
|
93 |
tree = (TTree*)gDirectory->Get("mytree");
|
94 |
std::cout << "[NtupleSkim] got tree " << std::endl;
|
95 |
//tree = (TTree*)gDirectory->Get("mytree"); // for reco ntuple
|
96 |
|
97 |
}
|
98 |
Init(tree);
|
99 |
}
|
100 |
|
101 |
NtupleSkim::~NtupleSkim()
|
102 |
{
|
103 |
if (!fChain) return;
|
104 |
delete fChain->GetCurrentFile();
|
105 |
}
|
106 |
|
107 |
Int_t NtupleSkim::GetEntry(Long64_t entry)
|
108 |
{
|
109 |
// Read contents of entry.
|
110 |
if (!fChain) return 0;
|
111 |
return fChain->GetEntry(entry);
|
112 |
}
|
113 |
Long64_t NtupleSkim::LoadTree(Long64_t entry)
|
114 |
{
|
115 |
// Set the environment to read one entry
|
116 |
if (!fChain) return -5;
|
117 |
Long64_t centry = fChain->LoadTree(entry);
|
118 |
if (centry < 0) return centry;
|
119 |
if (fChain->IsA() != TChain::Class()) return centry;
|
120 |
TChain *chain = (TChain*)fChain;
|
121 |
if (chain->GetTreeNumber() != fCurrent) {
|
122 |
fCurrent = chain->GetTreeNumber();
|
123 |
Notify();
|
124 |
}
|
125 |
return centry;
|
126 |
}
|
127 |
|
128 |
void NtupleSkim::Init(TTree *tree)
|
129 |
{
|
130 |
// The Init() function is called when the selector needs to initialize
|
131 |
// a new tree or chain. Typically here the branch addresses of the tree
|
132 |
// will be set. It is normaly not necessary to make changes to the
|
133 |
// generated code, but the routine can be extended by the user if needed.
|
134 |
// Init() will be called many times when running with PROOF.
|
135 |
|
136 |
// Set branch addresses
|
137 |
if (tree == 0) return;
|
138 |
fChain = tree;
|
139 |
fCurrent = -1;
|
140 |
fChain->SetMakeClass(1);
|
141 |
|
142 |
//fChain->SetBranchAddress("run",&run);
|
143 |
//fChain->SetBranchAddress("event",&event);
|
144 |
fChain->SetBranchAddress("pt",&pt);
|
145 |
fChain->SetBranchAddress("d0",&d0);
|
146 |
fChain->SetBranchAddress("d0_bs",&d0bs);
|
147 |
fChain->SetBranchAddress("phi0",&phi0);
|
148 |
fChain->SetBranchAddress("sigmad0",&sigmad0);
|
149 |
fChain->SetBranchAddress("z0",&z0);
|
150 |
//fChain->SetBranchAddress("sigmaz0",&sigmaz0);
|
151 |
fChain->SetBranchAddress("vx",&vx);
|
152 |
fChain->SetBranchAddress("vy",&vy);
|
153 |
fChain->SetBranchAddress("normchi2",&normchi2);
|
154 |
fChain->SetBranchAddress("eta",&eta);
|
155 |
fChain->SetBranchAddress("nStripHit",&nStripHit);
|
156 |
fChain->SetBranchAddress("nPixelHit",&nPixelHit);
|
157 |
|
158 |
std::cout << "[NtupleSkim] tree initialized " << std::endl;
|
159 |
Notify();
|
160 |
}
|
161 |
|
162 |
Bool_t NtupleSkim::Notify()
|
163 |
{
|
164 |
// The Notify() function is called when a new file is opened. This
|
165 |
// can be either for a new TTree in a TChain or when when a new TTree
|
166 |
// is started when using PROOF. Typically here the branch pointers
|
167 |
// will be retrieved. It is normaly not necessary to make changes
|
168 |
// to the generated code, but the routine can be extended by the
|
169 |
// user if needed.
|
170 |
|
171 |
// Get branch pointers
|
172 |
//b_run = fChain->GetBranch("run");
|
173 |
//b_event = fChain->GetBranch("event");
|
174 |
b_pt = fChain->GetBranch("pt");
|
175 |
b_d0 = fChain->GetBranch("d0");
|
176 |
b_d0bs = fChain->GetBranch("d0bs");
|
177 |
b_phi0 = fChain->GetBranch("phi0");
|
178 |
b_sigmad0 = fChain->GetBranch("sigmad0");
|
179 |
b_z0 = fChain->GetBranch("z0");
|
180 |
//b_sigmaz0 = fChain->GetBranch("sigmaz0");
|
181 |
b_vx = fChain->GetBranch("vx");
|
182 |
b_vy = fChain->GetBranch("vy");
|
183 |
b_normchi2 = fChain->GetBranch("normchi2");
|
184 |
b_eta = fChain->GetBranch("eta");
|
185 |
b_nPixelHit = fChain->GetBranch("nPixelHit");
|
186 |
b_nStripHit = fChain->GetBranch("nStripHit");
|
187 |
|
188 |
std::cout << "[NtupleSkim] branches notified" << std::endl;
|
189 |
return kTRUE;
|
190 |
}
|
191 |
|
192 |
void NtupleSkim::Show(Long64_t entry)
|
193 |
{
|
194 |
// Print contents of entry.
|
195 |
// If entry is not specified, print current entry
|
196 |
if (!fChain) return;
|
197 |
fChain->Show(entry);
|
198 |
}
|
199 |
Int_t NtupleSkim::Cut(Long64_t entry)
|
200 |
{
|
201 |
// This function may be called from Loop.
|
202 |
// returns 1 if entry is accepted.
|
203 |
// returns -1 otherwise.
|
204 |
return 1;
|
205 |
}
|
206 |
#endif // #ifdef NtupleSkim_cc
|