ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/csander/HEPTutorial/MyAnalysis.C
Revision: 1.21
Committed: Fri Jun 1 14:04:28 2012 UTC (12 years, 11 months ago) by csander
Content type: text/plain
Branch: MAIN
Changes since 1.20: +57 -24 lines
Log Message:
small fixes

File Contents

# User Rev Content
1 csander 1.1 #define MyAnalysis_cxx
2     // The class definition in MyAnalysis.h has been generated automatically
3     // by the ROOT utility TTree::MakeSelector(). This class is derived
4     // from the ROOT class TSelector. For more information on the TSelector
5     // framework see $ROOTSYS/README/README.SELECTOR or the ROOT User Manual.
6    
7     // The following methods are defined in this file:
8     // Begin(): called every time a loop on the tree starts,
9     // a convenient place to create your histograms.
10     // SlaveBegin(): called after Begin(), when on PROOF called only on the
11     // slave servers.
12     // Process(): called for each event, in this function you decide what
13     // to read and fill your histograms.
14     // SlaveTerminate: called at the end of the loop on the tree, when on PROOF
15     // called only on the slave servers.
16     // Terminate(): called at the end of the loop on the tree,
17     // a convenient place to draw/fit your histograms.
18     //
19     // To use this file, try the following session on your Tree T:
20     //
21     // Root > T->Process("MyAnalysis.C")
22     // Root > T->Process("MyAnalysis.C","some options")
23     // Root > T->Process("MyAnalysis.C+")
24     //
25    
26     #include "MyAnalysis.h"
27 csander 1.3 #include <iostream>
28 csander 1.2 #include <TH1F.h>
29 csander 1.9 #include <TLatex.h>
30 csander 1.1
31 csander 1.3 using namespace std;
32    
33     void MyAnalysis::BuildEvent() {
34 csander 1.21
35 csander 1.19 Jets.clear();
36     for (int i = 0; i < NJet; ++i) {
37     MyJet jet(Jet_Px[i], Jet_Py[i], Jet_Pz[i], Jet_E[i]);
38     jet.SetBTagDiscriminator(Jet_btag[i]);
39     jet.SetJetID(Jet_ID[i]);
40 csander 1.20 jet.SetMatchedGenJet(Jet_Px_gen[i], Jet_Py_gen[i], Jet_Pz_gen[i], Jet_E_gen[i]);
41 csander 1.19 jet.SetFlavor(Jet_Flavor_gen[i]);
42     Jets.push_back(jet);
43     }
44     Muons.clear();
45     for (int i = 0; i < NMuon; ++i) {
46     MyMuon muon(Muon_Px[i], Muon_Py[i], Muon_Pz[i], Muon_E[i]);
47     muon.SetIsolation(Muon_Iso[i]);
48     muon.SetCharge(Muon_Charge[i]);
49     muon.SetChargeGen(Muon_Charge_gen[i]);
50 csander 1.20 muon.SetMatchedGenMuon(Muon_Px_gen[i], Muon_Py_gen[i], Muon_Pz_gen[i], Muon_E_gen[i]);
51 csander 1.19 Muons.push_back(muon);
52     }
53     Electrons.clear();
54     for (int i = 0; i < NElectron; ++i) {
55 csander 1.20 MyElectron electron(Electron_Px[i], Electron_Py[i], Electron_Pz[i], Electron_E[i]);
56 csander 1.19 electron.SetIsolation(Electron_Iso[i]);
57     electron.SetCharge(Electron_Charge[i]);
58     electron.SetChargeGen(Electron_Charge_gen[i]);
59 csander 1.20 electron.SetMatchedGenElectron(Electron_Px_gen[i], Electron_Py_gen[i], Electron_Pz_gen[i], Electron_E_gen[i]);
60 csander 1.19 Electrons.push_back(electron);
61     }
62     Photons.clear();
63     for (int i = 0; i < NPhoton; ++i) {
64     MyPhoton photon(Photon_Px[i], Photon_Py[i], Photon_Pz[i], Photon_E[i]);
65     photon.SetIsolation(Photon_Iso[i]);
66 csander 1.20 photon.SetMatchedGenPhoton(Photon_Px_gen[i], Photon_Py_gen[i], Photon_Pz_gen[i], Photon_E_gen[i]);
67 csander 1.19 Photons.push_back(photon);
68     }
69     Taus.clear();
70     for (int i = 0; i < NTau; ++i) {
71     MyTau tau(Tau_Px[i], Tau_Py[i], Tau_Pz[i], Tau_E[i]);
72 csander 1.21 tau.SetTauID(Tau_ID[i]);
73 csander 1.20 tau.SetMatchedGenJet(Tau_Px_gen[i], Tau_Py_gen[i], Tau_Pz_gen[i], Tau_E_gen[i]);
74 csander 1.19 Taus.push_back(tau);
75     }
76     met.SetXYZM(MET_px, MET_py, 0., 0.);
77     genmet.SetXYZM(MET_px_gen, MET_py_gen, 0., 0.);
78    
79     if (EventWeight < 1.e-5)
80     EventWeight = 1.;
81     EventWeight *= weight_factor;
82 csander 1.9
83 csander 1.21 EventWeight = 1.;
84    
85 csander 1.3 }
86    
87 csander 1.2 void MyAnalysis::Begin(TTree * /*tree*/) {
88 csander 1.19 // The Begin() function is called at the start of the query.
89     // When running with PROOF Begin() is only called on the client.
90     // The tree argument is deprecated (on PROOF 0 is passed).
91 csander 1.1
92 csander 1.19 TString option = GetOption();
93 csander 1.1
94     }
95    
96 csander 1.2 void MyAnalysis::SlaveBegin(TTree * /*tree*/) {
97 csander 1.19 // The SlaveBegin() function is called after the Begin() function.
98     // When running with PROOF SlaveBegin() is called on each slave server.
99     // The tree argument is deprecated (on PROOF 0 is passed).
100    
101     TString option = GetOption();
102    
103     h_Mmumu = new TH1F("Mmumu", "Invariant di-muon mass", 100, 0, 1000);
104     h_Mmumu->SetXTitle("m_{#mu#mu}");
105     h_Mmumu->Sumw2();
106    
107     h_NJet = new TH1F("NJet", "Number of jets", 20, 0, 20);
108     h_NJet->SetXTitle("NJet");
109     h_NJet->Sumw2();
110    
111     h_NBJet = new TH1F("NBJet", "Number of b-jets", 5, 0, 5);
112     h_NBJet->SetXTitle("NBJet");
113     h_NBJet->Sumw2();
114    
115 csander 1.20 h_Jet1_Pt = new TH1F("Jet1Pt", "Pt of jet1", 50, 0, 1000);
116 csander 1.19 h_Jet1_Pt->SetXTitle("p_{T} [GeV]");
117     h_Jet1_Pt->Sumw2();
118    
119 csander 1.20 h_Jet2_Pt = new TH1F("Jet2Pt", "Pt of jet2", 50, 0, 1000);
120 csander 1.19 h_Jet2_Pt->SetXTitle("p_{T} [GeV]");
121     h_Jet2_Pt->Sumw2();
122    
123 csander 1.20 h_Jet3_Pt = new TH1F("Jet3Pt", "Pt of jet3", 50, 0, 1000);
124 csander 1.19 h_Jet3_Pt->SetXTitle("p_{T} [GeV]");
125     h_Jet3_Pt->Sumw2();
126    
127     h_Jet1_Eta = new TH1F("Jet1Eta", "#eta of jet1", 50, -5, 5);
128     h_Jet1_Eta->SetXTitle("#eta");
129     h_Jet1_Eta->Sumw2();
130    
131     h_Jet2_Eta = new TH1F("Jet2Eta", "#eta of jet2", 50, -5, 5);
132     h_Jet2_Eta->SetXTitle("#eta");
133     h_Jet2_Eta->Sumw2();
134    
135     h_Jet3_Eta = new TH1F("Jet3Eta", "#eta of jet3", 50, -5, 5);
136     h_Jet3_Eta->SetXTitle("#eta");
137     h_Jet3_Eta->Sumw2();
138    
139 csander 1.20 h_BJet1_Pt = new TH1F("BJet1Pt", "Pt of b-jet1", 50, 0, 1000);
140 csander 1.19 h_BJet1_Pt->SetXTitle("p_{T} [GeV]");
141     h_BJet1_Pt->Sumw2();
142    
143 csander 1.20 h_BJet2_Pt = new TH1F("BJet2Pt", "Pt of b-jet2", 50, 0, 1000);
144 csander 1.19 h_BJet2_Pt->SetXTitle("p_{T} [GeV]");
145     h_BJet2_Pt->Sumw2();
146    
147 csander 1.20 h_BJet1_Eta = new TH1F("BJet1Eta", "#eta of b-jet1", 50, -5, 5);
148 csander 1.19 h_BJet1_Eta->SetXTitle("#eta");
149     h_BJet1_Eta->Sumw2();
150    
151 csander 1.20 h_BJet2_Eta = new TH1F("BJet2Eta", "#eta of b-jet2", 50, -5, 5);
152 csander 1.19 h_BJet2_Eta->SetXTitle("#eta");
153     h_BJet2_Eta->Sumw2();
154    
155 csander 1.20 h_MET = new TH1F("MET", "MET", 50, 0, 2000);
156 csander 1.19 h_MET->SetXTitle("MET");
157     h_MET->Sumw2();
158    
159 csander 1.20 h_MHT = new TH1F("MHT", "MHT", 50, 0, 2000);
160 csander 1.19 h_MHT->SetXTitle("MHT");
161     h_MHT->Sumw2();
162    
163 csander 1.20 h_HT = new TH1F("HT", "HT", 50, 0, 5000);
164 csander 1.19 h_HT->SetXTitle("HT");
165     h_HT->Sumw2();
166 csander 1.20
167     h_DeltaPhiJet1Jet2 = new TH1F("DeltaPhiJet1Jet2", "DeltaPhiJet1Jet2", 100, -TMath::Pi(), TMath::Pi());
168     h_DeltaPhiJet1Jet2->SetXTitle("DeltaPhiJet1Jet2");
169     h_DeltaPhiJet1Jet2->Sumw2();
170    
171     h_Jet1OverHT = new TH1F("h_Jet1OverHT", "h_Jet1OverHT", 50, 0, 1.0);
172     h_Jet1OverHT->SetXTitle("h_Jet1OverHT");
173     h_Jet1OverHT->Sumw2();
174    
175     h_Jet2OverHT = new TH1F("h_Jet2OverHT", "h_Jet2OverHT", 50, 0, 1.0);
176     h_Jet2OverHT->SetXTitle("h_Jet2OverHT");
177     h_Jet2OverHT->Sumw2();
178    
179     h_Jet12OverHT = new TH1F("h_Jet12OverHT", "h_Jet12OverHT", 50, 0, 1.0);
180     h_Jet12OverHT->SetXTitle("h_Jet12OverHT");
181     h_Jet12OverHT->Sumw2();
182    
183     h_MHTOverHT = new TH1F("h_MHTOverHT", "h_MHTOverHT", 50, 0, 1.0);
184     h_MHTOverHT->SetXTitle("h_MHTOverHT");
185     h_MHTOverHT->Sumw2();
186    
187     h_Muon1_Pt = new TH1F("Muon1Pt", "Pt of muon1", 50, 0, 1000);
188     h_Muon1_Pt->SetXTitle("p_{T} [GeV]");
189     h_Muon1_Pt->Sumw2();
190    
191     h_Electron1_Pt = new TH1F("Electron1Pt", "Pt of electron1", 50, 0, 1000);
192     h_Electron1_Pt->SetXTitle("p_{T} [GeV]");
193     h_Electron1_Pt->Sumw2();
194 csander 1.1 }
195    
196 csander 1.2 Bool_t MyAnalysis::Process(Long64_t entry) {
197 csander 1.19 // The Process() function is called for each entry in the tree (or possibly
198     // keyed object in the case of PROOF) to be processed. The entry argument
199     // specifies which entry in the currently loaded tree is to be processed.
200     // It can be passed to either MyAnalysis::GetEntry() or TBranch::GetEntry()
201     // to read either all or the required parts of the data. When processing
202     // keyed objects with PROOF, the object is already loaded and is available
203     // via the fObject pointer.
204     //
205     // This function should contain the "body" of the analysis. It can contain
206     // simple or elaborate selection criteria, run algorithms on the data
207     // of the event and typically fill histograms.
208     //
209     // The processing can be stopped by calling Abort().
210     //
211     // Use fStatus to set the return value of TTree::Process().
212     //
213     // The return value is currently not used.
214    
215     ++TotalEvents;
216    
217     GetEntry(entry);
218    
219     Event event(EventNumber, LumiNumber, RunNumber);
220    
221     if (TotalEvents % 10000 == 0)
222     cout << "Next event -----> " << TotalEvents << endl;
223    
224     if (EventList != 0) {
225     if (!EventList->IsInList(event))
226     return 0;
227     }
228    
229     BuildEvent();
230    
231 csander 1.21 // cout << "Jets: " << endl;
232     // for (vector<MyJet>::iterator it = Jets.begin(); it != Jets.end(); ++it) {
233     // cout << "pt, eta, phi, btag: " << it->Pt() << ", " << it->Eta() << ", " << it->Phi() << ", " << it->IsBTagged() << endl;
234     // }
235     // cout << "Muons: " << endl;
236     // for (vector<MyMuon>::iterator it = Muons.begin(); it != Muons.end(); ++it) {
237     // cout << "pt, eta, phi, iso, charge: " << it->Pt() << ", " << it->Eta() << ", " << it->Phi() << ", " << it->GetIsolation() << ", " << it->GetCharge()
238     // << endl;
239     // }
240     // cout << "Electrons: " << endl;
241     // for (vector<MyElectron>::iterator it = Electrons.begin(); it != Electrons.end(); ++it) {
242     // cout << "pt, eta, phi, iso, charge: " << it->Pt() << ", " << it->Eta() << ", " << it->Phi() << ", " << it->GetIsolation() << ", " << it->GetCharge()
243     // << endl;
244     // }
245     // cout << "Photons: " << endl;
246     // for (vector<MyPhoton>::iterator it = Photons.begin(); it != Photons.end(); ++it) {
247     // cout << "pt, eta, phi, iso: " << it->Pt() << ", " << it->Eta() << ", " << it->Phi() << ", " << it->GetIsolation() << endl;
248     // }
249     // cout << "Taus: " << endl;
250     // for (vector<MyTau>::iterator it = Taus.begin(); it != Taus.end(); ++it) {
251     // cout << "pt, eta, phi, ID: " << it->Pt() << ", " << it->Eta() << ", " << it->Phi() << ", " << it->GetTauID() << endl;
252     // }
253 csander 1.19
254     //////////////////////////////
255     int N_BJet = 0;
256     int N_Jet = 0;
257     double HT = 0;
258     TLorentzVector MHT(0, 0, 0, 0);
259    
260     for (vector<MyJet>::iterator it = Jets.begin(); it != Jets.end(); ++it) {
261     ++N_Jet;
262    
263     if (!it->GetJetID() && it->Pt() > 30)
264     return 0;
265    
266     if (it->Pt() > 30)
267     MHT += *it;
268    
269     if (it->Pt() > 50 && fabs(it->Eta()) < 2.5)
270     HT += it->Pt();
271    
272     if (N_Jet == 1) {
273     h_Jet1_Pt->Fill(it->Pt(), EventWeight);
274     h_Jet1_Eta->Fill(it->Eta(), EventWeight);
275     } else if (N_Jet == 2) {
276     h_Jet2_Pt->Fill(it->Pt(), EventWeight);
277     h_Jet2_Eta->Fill(it->Eta(), EventWeight);
278     } else if (N_Jet == 3) {
279     h_Jet3_Pt->Fill(it->Pt(), EventWeight);
280     h_Jet3_Eta->Fill(it->Eta(), EventWeight);
281     }
282     if (it->IsBTagged()) {
283     ++N_BJet;
284     if (N_BJet == 1) {
285     h_BJet1_Pt->Fill(it->Pt(), EventWeight);
286     h_BJet1_Eta->Fill(it->Eta(), EventWeight);
287     } else if (N_BJet == 2) {
288     h_BJet2_Pt->Fill(it->Pt(), EventWeight);
289     h_BJet2_Eta->Fill(it->Eta(), EventWeight);
290     }
291     }
292     }
293     h_NBJet->Fill(N_BJet, EventWeight);
294     h_NJet->Fill(N_Jet, EventWeight);
295    
296     h_MET->Fill(met.Pt(), EventWeight);
297     h_MHT->Fill(MHT.Pt(), EventWeight);
298     h_HT->Fill(HT, EventWeight);
299     //////////////////////////////
300    
301     //////////////////////////////
302 csander 1.20 if (Jets.size() > 1) {
303     h_DeltaPhiJet1Jet2->Fill(Jets.at(0).DeltaPhi(Jets.at(1)), EventWeight);
304     h_Jet2OverHT->Fill(Jets.at(1).Pt() / HT, EventWeight);
305     h_Jet12OverHT->Fill((Jets.at(0).Pt() + Jets.at(1).Pt()) / HT, EventWeight);
306     }
307 csander 1.21 if (HT > 0)
308     h_Jet1OverHT->Fill(Jets.at(0).Pt() / HT, EventWeight);
309     if (HT > 0)
310     h_MHTOverHT->Fill(MHT.Pt() / HT, EventWeight);
311 csander 1.20 //////////////////////////////
312    
313     //////////////////////////////
314     if (NMuon > 0) {
315     if (Muons.at(0).IsIsolated()) {
316     h_Muon1_Pt->Fill(Muons.at(0).Pt(), EventWeight);
317     }
318     }
319     if (NElectron > 0) {
320     if (Electrons.at(0).IsIsolated()) {
321     h_Electron1_Pt->Fill(Electrons.at(0).Pt(), EventWeight);
322     }
323     }
324     //////////////////////////////
325    
326     //////////////////////////////
327 csander 1.19 if (NMuon > 1) {
328 csander 1.20 if (Muons.at(0).GetCharge() * Muons.at(1).GetCharge() < 1 && Muons.at(0).IsIsolated() && Muons.at(1).IsIsolated()) {
329 csander 1.19 h_Mmumu->Fill((Muons.at(0) + Muons.at(1)).M(), EventWeight);
330     }
331     }
332     //////////////////////////////
333 csander 1.8
334 csander 1.21 // int NGoodTau = 0;
335     // for (vector<MyTau>::iterator it = Taus.begin(); it != Taus.end(); ++it) {
336     // if (it->GetTauID())
337     // cout << it->Pt() << ", " << it->GetTauID() << endl;
338     // if (it->GetTauID() && it->Pt() > 15.)
339     // ++NGoodTau;
340     // }
341     // int NGoodElectron = 0;
342     // for (vector<MyElectron>::iterator it = Electrons.begin(); it != Electrons.end(); ++it) {
343     // if (it->IsIsolated() && it->Pt() > 10.)
344     // ++NGoodElectron;
345     // }
346     // int NGoodMuon = 0;
347     // for (vector<MyMuon>::iterator it = Muons.begin(); it != Muons.end(); ++it) {
348     // if (it->IsIsolated() && it->Pt() > 10.)
349     // ++NGoodMuon;
350     // }
351     // if (NGoodTau == 1) {
352     // if (HT > 600 && MHT.Pt() > 400) {
353     // if (NGoodElectron == 0 && NGoodMuon == 0) {
354     // ++TauEvents;
355     // } else {
356     // ++TauEventsWithLeptons;
357     // }
358     // }
359     // }
360    
361 csander 1.19 return kTRUE;
362 csander 1.1 }
363    
364 csander 1.2 void MyAnalysis::SlaveTerminate() {
365 csander 1.19 // The SlaveTerminate() function is called after all entries or objects
366     // have been processed. When running with PROOF SlaveTerminate() is called
367     // on each slave server.
368 csander 1.1
369     }
370    
371 csander 1.2 void MyAnalysis::Terminate() {
372 csander 1.19 // The Terminate() function is the last function to be called during
373     // a query. It always runs on the client, it can be used to present
374     // the results graphically or save the results to file.
375 csander 1.1
376     }