ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/csander/HEPTutorial/MyAnalysis.h
Revision: 1.21
Committed: Fri Jul 6 08:19:52 2012 UTC (12 years, 9 months ago) by csander
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.20: +58 -3 lines
Log Message:
v1.0, including a small ntupler for further skimming

File Contents

# Content
1 //////////////////////////////////////////////////////////
2 // This class has been automatically generated on
3 // Wed Feb 1 07:53:21 2012 by ROOT version 5.32/00
4 // from TTree data/
5 // found on file: data.root
6 //////////////////////////////////////////////////////////
7
8 #ifndef MyAnalysis_h
9 #define MyAnalysis_h
10
11 #include <TROOT.h>
12 #include <TFile.h>
13 #include <TChain.h>
14 #include <TSelector.h>
15 #include <TH1F.h>
16 #include <TLorentzVector.h>
17
18 #include "MyJet.h"
19 #include "MyMuon.h"
20 #include "MyElectron.h"
21 #include "MyPhoton.h"
22 #include "MyTau.h"
23 #include "MyParton.h"
24
25 #include "EventSelectorByList.h"
26
27 using namespace std;
28
29 // Header file for the classes stored in the TTree if any.
30
31 // Fixed size dimensions of array or collections stored in the TTree if any.
32
33 class MyAnalysis: public TSelector {
34 public:
35 TTree *fChain; //!pointer to the analyzed TTree or TChain
36
37 // Declaration of leaf types
38 Int_t NJet;
39 Float_t Jet_Px[20]; //[NJet]
40 Float_t Jet_Py[20]; //[NJet]
41 Float_t Jet_Pz[20]; //[NJet]
42 Float_t Jet_E[20]; //[NJet]
43 Float_t Jet_btag[20]; //[NJet]
44 Bool_t Jet_ID[20]; //[NJet]
45 Float_t Jet_Px_gen[20]; //[NJet]
46 Float_t Jet_Py_gen[20]; //[NJet]
47 Float_t Jet_Pz_gen[20]; //[NJet]
48 Float_t Jet_E_gen[20]; //[NJet]
49 Int_t Jet_Flavor_gen[20]; //[NJet]
50 Int_t NMuon;
51 Float_t Muon_Px[5]; //[NMuon]
52 Float_t Muon_Py[5]; //[NMuon]
53 Float_t Muon_Pz[5]; //[NMuon]
54 Float_t Muon_E[5]; //[NMuon]
55 Int_t Muon_Charge[5]; //[NMuon]
56 Float_t Muon_Iso[5]; //[NMuon]
57 Float_t Muon_Px_gen[5]; //[NMuon]
58 Float_t Muon_Py_gen[5]; //[NMuon]
59 Float_t Muon_Pz_gen[5]; //[NMuon]
60 Float_t Muon_E_gen[5]; //[NMuon]
61 Int_t Muon_Charge_gen[5]; //[NMuon]
62 Int_t NElectron;
63 Float_t Electron_Px[5]; //[NElectron]
64 Float_t Electron_Py[5]; //[NElectron]
65 Float_t Electron_Pz[5]; //[NElectron]
66 Float_t Electron_E[5]; //[NElectron]
67 Int_t Electron_Charge[5]; //[NElectron]
68 Float_t Electron_Iso[5]; //[NElectron]
69 Float_t Electron_Px_gen[5]; //[NElectron]
70 Float_t Electron_Py_gen[5]; //[NElectron]
71 Float_t Electron_Pz_gen[5]; //[NElectron]
72 Float_t Electron_E_gen[5]; //[NElectron]
73 Int_t Electron_Charge_gen[5]; //[NElectron]
74 Int_t NPhoton;
75 Float_t Photon_Px[5]; //[NPhoton]
76 Float_t Photon_Py[5]; //[NPhoton]
77 Float_t Photon_Pz[5]; //[NPhoton]
78 Float_t Photon_E[5]; //[NPhoton]
79 Float_t Photon_Iso[5]; //[NPhoton]
80 Float_t Photon_Px_gen[5]; //[NPhoton]
81 Float_t Photon_Py_gen[5]; //[NPhoton]
82 Float_t Photon_Pz_gen[5]; //[NPhoton]
83 Float_t Photon_E_gen[5]; //[NPhoton]
84 Int_t NTau;
85 Float_t Tau_Px[5]; //[NTau]
86 Float_t Tau_Py[5]; //[NTau]
87 Float_t Tau_Pz[5]; //[NTau]
88 Float_t Tau_E[5]; //[NTau]
89 Bool_t Tau_ID[5]; //[NTau]
90 Float_t Tau_Px_gen[5]; //[NTau]
91 Float_t Tau_Py_gen[5]; //[NTau]
92 Float_t Tau_Pz_gen[5]; //[NTau]
93 Float_t Tau_E_gen[5]; //[NTau]
94 Int_t NParton;
95 Float_t Parton_Px[40]; //[NParton]
96 Float_t Parton_Py[40]; //[NParton]
97 Float_t Parton_Pz[40]; //[NParton]
98 Float_t Parton_E[40]; //[NParton]
99 Int_t Parton_Pid[40]; //[NParton]
100 Int_t Parton_No[40]; //[NParton]
101 Float_t MET_px;
102 Float_t MET_py;
103 Float_t MET_px_gen;
104 Float_t MET_py_gen;
105 Int_t NPrimaryVertices;
106 Bool_t trigger;
107 Float_t EventWeight;
108 Long_t EventNumber;
109 Int_t LumiNumber;
110 Int_t RunNumber;
111
112 // List of branches
113 TBranch *b_NJet; //!
114 TBranch *b_Jet_Px; //!
115 TBranch *b_Jet_Py; //!
116 TBranch *b_Jet_Pz; //!
117 TBranch *b_Jet_E; //!
118 TBranch *b_Jet_btag; //!
119 TBranch *b_Jet_ID; //!
120 TBranch *b_Jet_Px_gen; //!
121 TBranch *b_Jet_Py_gen; //!
122 TBranch *b_Jet_Pz_gen; //!
123 TBranch *b_Jet_E_gen; //!
124 TBranch *b_Jet_Flavor_gen; //!
125 TBranch *b_NMuon; //!
126 TBranch *b_Muon_Px; //!
127 TBranch *b_Muon_Py; //!
128 TBranch *b_Muon_Pz; //!
129 TBranch *b_Muon_E; //!
130 TBranch *b_Muon_Charge; //!
131 TBranch *b_Muon_Iso; //!
132 TBranch *b_Muon_Px_gen; //!
133 TBranch *b_Muon_Py_gen; //!
134 TBranch *b_Muon_Pz_gen; //!
135 TBranch *b_Muon_E_gen; //!
136 TBranch *b_Muon_Charge_gen; //!
137 TBranch *b_NElectron; //!
138 TBranch *b_Electron_Px; //!
139 TBranch *b_Electron_Py; //!
140 TBranch *b_Electron_Pz; //!
141 TBranch *b_Electron_E; //!
142 TBranch *b_Electron_Charge; //!
143 TBranch *b_Electron_Iso; //!
144 TBranch *b_Electron_Px_gen; //!
145 TBranch *b_Electron_Py_gen; //!
146 TBranch *b_Electron_Pz_gen; //!
147 TBranch *b_Electron_E_gen; //!
148 TBranch *b_Electron_Charge_gen; //!
149 TBranch *b_NPhoton; //!
150 TBranch *b_Photon_Px; //!
151 TBranch *b_Photon_Py; //!
152 TBranch *b_Photon_Pz; //!
153 TBranch *b_Photon_E; //!
154 TBranch *b_Photon_Iso; //!
155 TBranch *b_Photon_Px_gen; //!
156 TBranch *b_Photon_Py_gen; //!
157 TBranch *b_Photon_Pz_gen; //!
158 TBranch *b_Photon_E_gen; //!
159 TBranch *b_NTau; //!
160 TBranch *b_Tau_Px; //!
161 TBranch *b_Tau_Py; //!
162 TBranch *b_Tau_Pz; //!
163 TBranch *b_Tau_E; //!
164 TBranch *b_Tau_ID; //!
165 TBranch *b_Tau_Px_gen; //!
166 TBranch *b_Tau_Py_gen; //!
167 TBranch *b_Tau_Pz_gen; //!
168 TBranch *b_Tau_E_gen; //!
169 TBranch *b_NParton; //!
170 TBranch *b_Parton_Px; //!
171 TBranch *b_Parton_Py; //!
172 TBranch *b_Parton_Pz; //!
173 TBranch *b_Parton_E; //!
174 TBranch *b_Parton_Pid; //!
175 TBranch *b_Parton_No; //!
176 TBranch *b_MET_px; //!
177 TBranch *b_MET_py; //!
178 TBranch *b_MET_px_gen; //!
179 TBranch *b_MET_py_gen; //!
180 TBranch *b_NPrimaryVertices; //!
181 TBranch *b_trigger; //!
182 TBranch *b_EventWeight; //!
183 TBranch *b_EventNumber; //!
184 TBranch *b_LumiNumber; //!
185 TBranch *b_RunNumber; //!
186
187 MyAnalysis(std::string s = std::string("data.root"), bool is = false, float wf = 1., EventSelectorByList * el = 0, TTree * /*tree*/= 0) :
188 fChain(0) {
189 weight_factor = wf;
190 EventList = el;
191 isSUSY = is;
192 process = s;
193 }
194 virtual ~MyAnalysis() {
195 }
196 virtual Int_t Version() const {
197 return 2;
198 }
199 virtual void Begin(TTree *tree);
200 virtual void SlaveBegin(TTree *tree);
201 virtual void Init(TTree *tree);
202 virtual Bool_t Notify();
203 virtual Bool_t Process(Long64_t entry);
204 virtual Int_t GetEntry(Long64_t entry, Int_t getall = 0) {
205 return fChain ? fChain->GetTree()->GetEntry(entry, getall) : 0;
206 }
207 virtual void SetOption(const char *option) {
208 fOption = option;
209 }
210 virtual void SetObject(TObject *obj) {
211 fObject = obj;
212 }
213 virtual void SetInputList(TList *input) {
214 fInput = input;
215 }
216 virtual TList *GetOutputList() const {
217 return fOutput;
218 }
219 virtual void SlaveTerminate();
220 virtual void Terminate();
221
222 void BuildEvent();
223
224 int TotalEvents;
225 int TauEvents, TauEventsWithLeptons;
226 vector<MyJet> Jets;
227 vector<MyMuon> Muons;
228 vector<MyElectron> Electrons;
229 vector<MyPhoton> Photons;
230 vector<MyTau> Taus;
231 vector<MyParton> Partons;
232
233 TLorentzVector met, genmet, MHT;
234 double HT;
235 int Jet_Mult;
236 int BJet_Mult;
237 int IsoEle_Mult;
238 int IsoMu_Mult;
239 int IsoPho_Mult;
240 double DeltaPhiJet1MHT, DeltaPhiJet2MHT, DeltaPhiJet3MHT;
241 bool hasBadJet, deltaPhiCut;
242
243 double weight_factor;
244 bool isSUSY;
245 std::string process;
246
247 //// Output variables for small NTuple
248 TFile *file;
249 TTree *ReweightTree;
250 float mTele, mTmu, HTf, MHTf;
251 float *dRmin_Muon;
252 float *pTrel_Muon;
253 float *relIso_Muon;
254 float *Pt_Muon;
255 float *Eta_Muon;
256 float *dRmin_Electron;
257 float *pTrel_Electron;
258 float *relIso_Electron;
259 float *Pt_Electron;
260 float *Eta_Electron;
261
262 TH1F *h_Mmumu;
263 TH1F *h_NJet;
264 TH1F *h_NBJet;
265 TH1F *h_Jet1_Pt, *h_Jet1_Eta;
266 TH1F *h_Jet2_Pt, *h_Jet2_Eta;
267 TH1F *h_Jet3_Pt, *h_Jet3_Eta;
268 TH1F *h_BJet1_Pt, *h_BJet1_Eta;
269 TH1F *h_BJet2_Pt, *h_BJet2_Eta;
270 TH1F *h_MET, *h_MHT, *h_HT;
271 TH1F *h_DeltaPhiJet1Jet2;
272 TH1F *h_DeltaPhiJet1MHT, *h_DeltaPhiJet2MHT, *h_DeltaPhiJet3MHT;
273 TH1F *h_Jet1OverHT, *h_Jet2OverHT, *h_Jet12OverHT;
274 TH1F *h_MHTOverHT;
275 TH1F *h_Muon1_Pt, *h_Electron1_Pt;
276 TH1F *h_Muon1_Iso, *h_Electron1_Iso;
277 TH1F *h_Muon_MT, *h_Electron_MT;
278
279 vector<TH1F*> histograms;
280
281 EventSelectorByList* EventList;
282
283 };
284
285 #endif
286
287 #ifdef MyAnalysis_cxx
288 void MyAnalysis::Init(TTree *tree)
289 {
290 // The Init() function is called when the selector needs to initialize
291 // a new tree or chain. Typically here the branch addresses and branch
292 // pointers of the tree will be set.
293 // It is normally not necessary to make changes to the generated
294 // code, but the routine can be extended by the user if needed.
295 // Init() will be called many times when running on PROOF
296 // (once per file to be processed).
297
298 // Set branch addresses and branch pointers
299 if (!tree) return;
300 fChain = tree;
301 fChain->SetMakeClass(1);
302
303 fChain->SetBranchAddress("NJet", &NJet, &b_NJet);
304 fChain->SetBranchAddress("Jet_Px", Jet_Px, &b_Jet_Px);
305 fChain->SetBranchAddress("Jet_Py", Jet_Py, &b_Jet_Py);
306 fChain->SetBranchAddress("Jet_Pz", Jet_Pz, &b_Jet_Pz);
307 fChain->SetBranchAddress("Jet_E", Jet_E, &b_Jet_E);
308 fChain->SetBranchAddress("Jet_btag", Jet_btag, &b_Jet_btag);
309 fChain->SetBranchAddress("Jet_ID", Jet_ID, &b_Jet_ID);
310 fChain->SetBranchAddress("Jet_Px_gen", Jet_Px_gen, &b_Jet_Px_gen);
311 fChain->SetBranchAddress("Jet_Py_gen", Jet_Py_gen, &b_Jet_Py_gen);
312 fChain->SetBranchAddress("Jet_Pz_gen", Jet_Pz_gen, &b_Jet_Pz_gen);
313 fChain->SetBranchAddress("Jet_E_gen", Jet_E_gen, &b_Jet_E_gen);
314 fChain->SetBranchAddress("Jet_Flavor_gen", Jet_Flavor_gen, &b_Jet_Flavor_gen);
315 fChain->SetBranchAddress("NMuon", &NMuon, &b_NMuon);
316 fChain->SetBranchAddress("Muon_Px", &Muon_Px, &b_Muon_Px);
317 fChain->SetBranchAddress("Muon_Py", &Muon_Py, &b_Muon_Py);
318 fChain->SetBranchAddress("Muon_Pz", &Muon_Pz, &b_Muon_Pz);
319 fChain->SetBranchAddress("Muon_E", &Muon_E, &b_Muon_E);
320 fChain->SetBranchAddress("Muon_Charge", &Muon_Charge, &b_Muon_Charge);
321 fChain->SetBranchAddress("Muon_Iso", &Muon_Iso, &b_Muon_Iso);
322 fChain->SetBranchAddress("Muon_Px_gen", &Muon_Px_gen, &b_Muon_Px_gen);
323 fChain->SetBranchAddress("Muon_Py_gen", &Muon_Py_gen, &b_Muon_Py_gen);
324 fChain->SetBranchAddress("Muon_Pz_gen", &Muon_Pz_gen, &b_Muon_Pz_gen);
325 fChain->SetBranchAddress("Muon_E_gen", &Muon_E_gen, &b_Muon_E_gen);
326 fChain->SetBranchAddress("Muon_Charge_gen", &Muon_Charge_gen, &b_Muon_Charge_gen);
327 fChain->SetBranchAddress("NElectron", &NElectron, &b_NElectron);
328 fChain->SetBranchAddress("Electron_Px", &Electron_Px, &b_Electron_Px);
329 fChain->SetBranchAddress("Electron_Py", &Electron_Py, &b_Electron_Py);
330 fChain->SetBranchAddress("Electron_Pz", &Electron_Pz, &b_Electron_Pz);
331 fChain->SetBranchAddress("Electron_E", &Electron_E, &b_Electron_E);
332 fChain->SetBranchAddress("Electron_Charge", &Electron_Charge, &b_Electron_Charge);
333 fChain->SetBranchAddress("Electron_Iso", &Electron_Iso, &b_Electron_Iso);
334 fChain->SetBranchAddress("Electron_Px_gen", &Electron_Px_gen, &b_Electron_Px_gen);
335 fChain->SetBranchAddress("Electron_Py_gen", &Electron_Py_gen, &b_Electron_Py_gen);
336 fChain->SetBranchAddress("Electron_Pz_gen", &Electron_Pz_gen, &b_Electron_Pz_gen);
337 fChain->SetBranchAddress("Electron_E_gen", &Electron_E_gen, &b_Electron_E_gen);
338 fChain->SetBranchAddress("Electron_Charge_gen", &Electron_Charge_gen, &b_Electron_Charge_gen);
339 fChain->SetBranchAddress("NPhoton", &NPhoton, &b_NPhoton);
340 fChain->SetBranchAddress("Photon_Px", &Photon_Px, &b_Photon_Px);
341 fChain->SetBranchAddress("Photon_Py", &Photon_Py, &b_Photon_Py);
342 fChain->SetBranchAddress("Photon_Pz", &Photon_Pz, &b_Photon_Pz);
343 fChain->SetBranchAddress("Photon_E", &Photon_E, &b_Photon_E);
344 fChain->SetBranchAddress("Photon_Iso", &Photon_Iso, &b_Photon_Iso);
345 fChain->SetBranchAddress("Photon_Px_gen", &Photon_Px_gen, &b_Photon_Px_gen);
346 fChain->SetBranchAddress("Photon_Py_gen", &Photon_Py_gen, &b_Photon_Py_gen);
347 fChain->SetBranchAddress("Photon_Pz_gen", &Photon_Pz_gen, &b_Photon_Pz_gen);
348 fChain->SetBranchAddress("Photon_E_gen", &Photon_E_gen, &b_Photon_E_gen);
349 fChain->SetBranchAddress("NTau", &NTau, &b_NTau);
350 fChain->SetBranchAddress("Tau_Px", Tau_Px, &b_Tau_Px);
351 fChain->SetBranchAddress("Tau_Py", Tau_Py, &b_Tau_Py);
352 fChain->SetBranchAddress("Tau_Pz", Tau_Pz, &b_Tau_Pz);
353 fChain->SetBranchAddress("Tau_E", Tau_E, &b_Tau_E);
354 fChain->SetBranchAddress("Tau_ID", Tau_ID, &b_Tau_ID);
355 fChain->SetBranchAddress("Tau_Px_gen", Tau_Px_gen, &b_Tau_Px_gen);
356 fChain->SetBranchAddress("Tau_Py_gen", Tau_Py_gen, &b_Tau_Py_gen);
357 fChain->SetBranchAddress("Tau_Pz_gen", Tau_Pz_gen, &b_Tau_Pz_gen);
358 fChain->SetBranchAddress("Tau_E_gen", Tau_E_gen, &b_Tau_E_gen);
359 fChain->SetBranchAddress("NParton", &NParton, &b_NParton);
360 fChain->SetBranchAddress("Parton_Px", Parton_Px, &b_Parton_Px);
361 fChain->SetBranchAddress("Parton_Py", Parton_Py, &b_Parton_Py);
362 fChain->SetBranchAddress("Parton_Pz", Parton_Pz, &b_Parton_Pz);
363 fChain->SetBranchAddress("Parton_E", Parton_E, &b_Parton_E);
364 fChain->SetBranchAddress("Parton_Pid", Parton_Pid, &b_Parton_Pid);
365 if (isSUSY)
366 fChain->SetBranchAddress("Parton_No", Parton_No, &b_Parton_No);
367 fChain->SetBranchAddress("MET_px", &MET_px, &b_MET_px);
368 fChain->SetBranchAddress("MET_py", &MET_py, &b_MET_py);
369 fChain->SetBranchAddress("MET_px_gen", &MET_px_gen, &b_MET_px_gen);
370 fChain->SetBranchAddress("MET_py_gen", &MET_py_gen, &b_MET_py_gen);
371 fChain->SetBranchAddress("NPrimaryVertices", &NPrimaryVertices, &b_NPrimaryVertices);
372 fChain->SetBranchAddress("trigger", &trigger, &b_trigger);
373 fChain->SetBranchAddress("EventWeight", &EventWeight, &b_EventWeight);
374 fChain->SetBranchAddress("EventNumber", &EventNumber, &b_EventNumber);
375 fChain->SetBranchAddress("LumiNumber", &LumiNumber, &b_LumiNumber);
376 fChain->SetBranchAddress("RunNumber", &RunNumber, &b_RunNumber);
377
378 TotalEvents = 0;
379
380 //// Output Branches for small ntuple used for MC weight determination
381
382 dRmin_Muon = new float[5];
383 pTrel_Muon = new float[5];
384 relIso_Muon = new float[5];
385 Pt_Muon = new float[5];
386 Eta_Muon = new float[5];
387 dRmin_Electron = new float[5];
388 pTrel_Electron = new float[5];
389 relIso_Electron = new float[5];
390 Pt_Electron = new float[5];
391 Eta_Electron = new float[5];
392
393 file = new TFile(process.c_str(), "RECREATE");
394 file->cd();
395 ReweightTree = new TTree("events", "");
396 ReweightTree->SetDirectory(file);
397 ReweightTree->Branch("HT", &HTf, "HT/F");
398 ReweightTree->Branch("MHT", &MHTf, "MHT/F");
399 ReweightTree->Branch("NJet", &Jet_Mult, "NJet/I");
400 ReweightTree->Branch("NBJet", &BJet_Mult, "NBJet/I");
401 ReweightTree->Branch("NMuon", &NMuon, "NMuon/I");
402 ReweightTree->Branch("Muon_Pt", Pt_Muon, "Muon_Pt[NMuon]/F");
403 ReweightTree->Branch("Muon_Eta", Eta_Muon, "Muon_Eta[NMuon]/F");
404 ReweightTree->Branch("Muon_DeltaRJet", dRmin_Muon, "Muon_DeltaRJet[NMuon]/F");
405 ReweightTree->Branch("Muon_PtRel", pTrel_Muon, "Muon_PTrel[NMuon]/F");
406 ReweightTree->Branch("Muon_RelIso", relIso_Muon, "Muon_RelIso[NMuon]/F");
407 ReweightTree->Branch("Muon_MT", &mTmu, "Muon_MT[NMuon]/F");
408 ReweightTree->Branch("NElectron", &NElectron, "NElectron/I");
409 ReweightTree->Branch("Electron_Pt", Pt_Electron, "Electron_Pt[NElectron]/F");
410 ReweightTree->Branch("Electron_Eta", Eta_Electron, "Electron_Eta[NElectron]/F");
411 ReweightTree->Branch("Electron_DeltaRJet", dRmin_Electron, "Electron_DeltaRJet[NElectron]/F");
412 ReweightTree->Branch("Electron_PtRel", pTrel_Electron, "Electron_PTrel[NElectron]/F");
413 ReweightTree->Branch("Electron_RelIso", relIso_Electron, "Electron_RelIso[NElectron]/F");
414 ReweightTree->Branch("Electron_MT", &mTele, "MElectron_MT[NElectron]/F");
415 ReweightTree->Branch("EventWeight", &EventWeight, "EventWeight/F");
416
417 }
418
419 Bool_t MyAnalysis::Notify()
420 {
421 // The Notify() function is called when a new file is opened. This
422 // can be either for a new TTree in a TChain or when when a new TTree
423 // is started when using PROOF. It is normally not necessary to make changes
424 // to the generated code, but the routine can be extended by the
425 // user if needed. The return value is currently not used.
426
427 return kTRUE;
428 }
429
430 #endif // #ifdef MyAnalysis_cxx