ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/dhidas/OSUAnalysis/Tools/scripts/plot3overlay.py
Revision: 1.1.1.1 (vendor branch)
Committed: Thu Dec 1 16:28:48 2011 UTC (13 years, 5 months ago) by dhidas
Content type: text/x-python
Branch: dhidas, MAIN
CVS Tags: START, HEAD
Changes since 1.1: +0 -0 lines
Log Message:
osu copy modified

File Contents

# Content
1 from __future__ import division
2
3 from tdrStyle import *
4 from math import sqrt
5 from ROOT import *
6
7 canvases = []
8 scanvases = []
9 counter = 0
10 asymrange = 0.5
11
12 def plotMttbar():
13 tdrstyle = setTDRStyle();
14 gStyle.SetHatchesSpacing(1.0);
15 # gStyle.SetOptStat("emri"); # Print integral & usual stuff
16 lumi = 5000;
17 oldLumi = 5000;
18 scale = lumi / oldLumi;
19 qcdScale = {'default':1.72, 'withMETAndAsymJets': 3.03};
20 # data = TFile.Open("data2.9pb_fullSetOfVars.root");
21
22 ttbar0 = TFile.Open("v8metjecflat/TTJets_5000pb_PFElectron_PF2PATJets_PFMET.root");
23 ttbarup = TFile.Open("v8metjecup/TTJets_5000pb_PFElectron_PF2PATJets_PFMET.root");
24 ttbardown = TFile.Open("v8metjecdown/TTJets_5000pb_PFElectron_PF2PATJets_PFMET.root");
25 WprimeTToTTD_M600fl = TFile.Open("v8metjecflat/WprimeTToTTD_M600_5000pb_PFElectron_PF2PATJets_PFMET.root");
26 WprimeTToTTD_M600up = TFile.Open("v8metjecup/WprimeTToTTD_M600_5000pb_PFElectron_PF2PATJets_PFMET.root");
27 WprimeTToTTD_M600d = TFile.Open("v8metjecdown/WprimeTToTTD_M600_5000pb_PFElectron_PF2PATJets_PFMET.root");
28
29 hists = [];
30 # hists.append('mttbar_QCDEnriched')
31 # hists.append('mttbar_conversions')
32 # hists.append('mttbar_conversions_withMETCut')
33 # hists.append('mttbar_conversions_withMETAndAsymJets')
34 # hists.append('mttbar_conversions_withAsymJetsCut')
35 # hists.append('mttbar_controlRegion')
36 # hists.append("jet12vsjet13");
37 # hists.append("jet12vsjet23");
38 # hists.append("jet13vsjet23");
39 # hists.append("mttbar");
40 # hists.append("tPrimeMass");
41 # hists.append("tPrimepT");
42 # hists.append("tPrimeHT");
43 # hists.append("tPrime_pt");
44 # hists.append("tPrime_px");
45 # hists.append("tPrime_py");
46 # hists.append("tPrime_pz");
47 # hists.append("mLeptonicTopLone");
48 # hists.append("mLepTopLoneNM");
49 # hists.append("mHadTopLoneNM");
50 # hists.append("chiHadronicTop");
51 # hists.append("chiLeptonicTop");
52 # hists.append("chiGlobal");
53 # hists.append("chiTotal");
54 # hists.append("lepTopDeltaR");
55 # hists.append("hadTopDeltaR");
56 # hists.append("lepTopLep");
57 # hists.append("hadTopHad");
58 # hists.append("numHadTopMCMatches");
59 # hists.append("numLepTopMCMatches");
60 # hists.append("numHadTopCorrectID");
61 # hists.append("numLepTopCorrectID");
62 # hists.append("numHadTopMCMatches2top");
63 # hists.append("numLepTopMCMatches2top");
64 # hists.append("numHadTopCorrectID2top");
65 # hists.append("numLepTopCorrectID2top");
66 # hists.append("mttbar_2ndSolution");
67 # hists.append("mttbar_3rdSolution");
68 # hists.append("mttbar_allSolutions");
69 ##
70 # hists.append("mttbar_withMETCut");
71 # hists.append("mttbar_2ndSolution_withMETCut");
72 # hists.append("mttbar_3rdSolution_withMETCut");
73 # hists.append("mttbar_allSolutions_withMETCut");
74 #
75 # hists.append("mttbar_withMETAndAsymJets");
76 # hists.append("mttbar_2ndSolution_withMETAndAsymJets");
77 # hists.append("mttbar_3rdSolution_withMETAndAsymJets");
78 # hists.append("mttbar_allSolutions_withMETAndAsymJets");
79 #
80 # hists.append("mttbar_withAsymJetsCut");
81 # hists.append("mttbar_2ndSolution_withAsymJetsCut");
82 # hists.append("mttbar_3rdSolution_withAsymJetsCut");
83 # hists.append("mttbar_allSolutions_withAsymJetsCut");
84 #
85 # hists.append("ttbar_pt");
86 # hists.append("ttbar_pt_2ndSolution");
87 # hists.append("ttbar_pt_3rdSolution");
88 # hists.append("ttbar_pt_allSolutions");
89 #
90 # hists.append("ttbar_pt_withMETCut");
91 # hists.append("ttbar_pt_2ndSolution_withMETCut");
92 # hists.append("ttbar_pt_3rdSolution_withMETCut");
93 # hists.append("ttbar_pt_allSolutions_withMETCut");
94 #
95 # hists.append("ttbar_pt_withMETAndAsymJets");
96 # hists.append("ttbar_pt_2ndSolution_withMETAndAsymJets");
97 # hists.append("ttbar_pt_3rdSolution_withMETAndAsymJets");
98 # hists.append("ttbar_pt_allSolutions_withMETAndAsymJets");
99 #
100 # hists.append("ttbar_pt_withAsymJetsCut");
101 # hists.append("ttbar_pt_2ndSolution_withAsymJetsCut");
102 # hists.append("ttbar_pt_3rdSolution_withAsymJetsCut");
103 # # hists.append("ttbar_pt_allSolutions_withAsymJetsCut");
104 # hists.append("angleTops");
105 # hists.append("angleTops_withMETCut");
106 # hists.append("angleTops_withMETAndAsymJets");
107 # hists.append("angleTops_withAsymJetsCut");
108 #
109 hists.append("leadingJetPt");
110 hists.append("nextLeadingJetPt");
111 hists.append("trailingJetPt");
112 # hists.append("pt_leadingTop");
113 # hists.append("pt_loneLepTop");
114 # hists.append("pt_lepTop");
115 # hists.append("pt_hadTop");
116 # hists.append("pt_loneHadTop");
117 # hists.append("pt_leadingTop_withMETCut");
118 # hists.append("pt_leadingTop_withMETAndAsymJets");
119 # hists.append("pt_leadingTop_withAsymJetsCut");
120 #
121 # hists.append("pt_NextToLeadingTop");
122 # hists.append("pt_NextToLeadingTop_withMETCut");
123 # hists.append("pt_NextToLeadingTop_withMETAndAsymJets");
124 # hists.append("pt_NextToLeadingTop_withAsymJetsCut");
125 #
126 # hists.append("mAllTop");
127 #
128 # hists.append("ttbar_px");
129 # hists.append("ttbar_py");
130 # hists.append("ttbar_pz");
131 #
132 # hists.append("m3");
133 # hists.append("HT");
134 # hists.append("qkjet_eta");
135 # hists.append("qkjet_rapid");
136 # hists.append("leadjet_rap");
137 # hists.append("lepb_angle");
138 # hists.append("angleHadTopD");
139 # hists.append("MET");
140 # hists.append("METtopangle_ltop");
141 # hists.append("HT3jet_ltop");
142 # hists.append("HT4jet_ltop");
143 # hists.append("mt2jbothchglep4j");
144 # hists.append("mt2jbothchgelec4j");
145 # hists.append("mt2jbothchgmu4j");
146 # hists.append("mt2jbothchglep5j");
147 # hists.append("mt2jbothchgmu5j");
148 # hists.append("mt2jbothchgelec5j");
149 # hists.append("mt2jpluselec4j");
150 # hists.append("mt2jplusmu4j");
151 # hists.append("mt2jpluslep4j");
152 # hists.append("mt2jpluslep5j");
153 # hists.append("mt2jpluselec5j");
154 # hists.append("mt2jplusmu5j");
155 # hists.append("mt2jminuselec4j");
156 # hists.append("mt2jminusmu4j");
157 # hists.append("mt2jminuslep4j");
158 # hists.append("mt2jminuselec5j");
159 # hists.append("mt2jminusmu5j");
160 # hists.append("mt2jminuslep5j");
161 # hists.append("mt4jbothchglep4j");
162 # hists.append("mt4jbothchgelec4j");
163 # hists.append("mt4jbothchgmu4j");
164 # hists.append("mt4jbothchglep5j");
165 # hists.append("mt4jbothchgmu5j");
166 # hists.append("mt4jbothchgelec5j");
167 # hists.append("mt4jpluselec4j");
168 # hists.append("mt4jplusmu4j");
169 # hists.append("mt4jpluslep4j");
170 # hists.append("mt4jpluslep5j");
171 # hists.append("mt4jpluselec5j");
172 # hists.append("mt4jplusmu5j");
173 # hists.append("mt4jminuselec4j");
174 # hists.append("mt4jminusmu4j");
175 # hists.append("mt4jminuslep4j");
176 # hists.append("mt4jminuselec5j");
177 # hists.append("mt4jminusmu5j");
178 # hists.append("mt4jminuslep5j");
179 # hists.append("leadingJetMass");
180 # hists.append("mtW");
181 # hists.append("neutrino_pz");
182 # hists.append("lone_neutrino_pz");
183 suffixes = ["0orMoreBtag",
184 "1orMoreBtag",
185 "2orMoreBtags",
186 "3orMoreBtags",'4orMoreBtags' ]
187 hists = [hist + '_' + suffix for hist in hists for suffix in suffixes]
188
189 histslep = [];
190 # histslep.append("HT_ltop");
191 histslep.append("MET_ltop");
192 histslep.append("METpt_ltop");
193 # histslep.append("mass4jets");
194 # histslep.append("ST_ltop");
195 histslep.append("mLeptonicTop");
196 histslep.append("mHadronicTop");
197 histslep.append("mHadTopLone");
198 histslep.append("mLepTopLone");
199 histslep.append("mHadTopLonepos");
200 histslep.append("mLepTopLonepos");
201 histslep.append("mHadTopLoneneg");
202 histslep.append("mLepTopLoneneg");
203 histslep.append("wpmass");
204 histslep.append("wpnegmass");
205 histslep.append("wpnegmassbad");
206 histslep.append("wpnegmasspos");
207 histslep.append("wpnegmassneg");
208 histslep.append("wp1topmass");
209 histslep.append("wp1topmassbad");
210 histslep.append("wp1topmasspos");
211 histslep.append("wp1topmassbadpos");
212 histslep.append("wp1topmassneg");
213 histslep.append("wp1topmassbadneg");
214 # histslep.append("wpanglmass");
215 # histslep.append("numHadTopDauMCMatches");
216 # histslep.append("numLepTopDauMCMatches");
217 # histslep.append("transMasslm1b");
218 suffixes = ["elec", "mu", "lepton"]
219 histslep = [hist + '_' + suffix for hist in histslep for suffix in suffixes]
220
221 hists += histslep;
222 print hists
223
224 # jetBinned = ["allJets",
225 # "1orMoreJets",
226 # "2orMoreJets",
227 # "3orMoreJets" , "4orMoreJets"]
228 # jetBinnedhists = []
229 # jetBinnedhists.append("QCDest_CombRelIso")
230 # jetBinnedhists.append("QCDest_CombRelIso_1btag")
231 # jetBinnedhists.append("QCDest_CombRelIso_2btag")
232 # jetBinnedhists.append("QCDest_CombRelIso_controlRegion")
233 # jetBinnedhists.append("QCDest_CombRelIso_controlRegion_1btag")
234 # jetBinnedhists.append("QCDest_CombRelIso_controlRegion_2btag")
235 #
236 # jetBinnedhists.append("QCDest_PFIsolation")
237 # jetBinnedhists.append("QCDest_PFIsolation_WithMETCut")
238 # jetBinnedhists.append("QCDest_PFIsolation_WithMETCutAndAsymJetCuts")
239 # jetBinnedhists.append("QCDest_PFIsolation_WithAsymJetCuts")
240
241 # jetBinnedhists.append("QCDest_PFIsolation_1btag")
242 # jetBinnedhists.append("QCDest_PFIsolation_2btag")
243 # jetBinnedhists.append("QCDest_PFIsolation_controlRegion")
244 # jetBinnedhists.append("QCDest_PFIsolation_controlRegion_1btag")
245 # jetBinnedhists.append("QCDest_PFIsolation_controlRegion_2btag")
246 # jetBinnedhists.append("QCDest_PFIsolation_controlRegion2")
247 # jetBinnedhists.append("QCDest_PFIsolation_controlRegion2_WithMETCut")
248 # jetBinnedhists.append("QCDest_PFIsolation_controlRegion2_WithMETCutAndAsymJetCuts")
249 # jetBinnedhists.append("QCDest_PFIsolation_controlRegion2_WithAsymJetCuts")
250 # jetBinnedhists.append("QCDest_PFIsolation_controlRegion2_1btag")
251 # jetBinnedhists.append("QCDest_PFIsolation_controlRegion2_2btag")
252
253 # jetBinnedhists = [hist + '_' + suffix for hist in jetBinnedhists for suffix in jetBinned]
254 # hists.extend(jetBinnedhists)
255 gcd = gROOT.cd
256
257 for histname in hists:
258 currentSelection = 'default'
259 if 'withMETAndAsymJets' in histname:
260 currentSelection = 'withMETAndAsymJets'
261 gcd()
262 print histname
263 # hist_data = data.Get(histname);
264
265 # hist_data2;
266 # if (histname == "mttbar_rebinned")
267 # hist_data2 = data2.Get(histname);
268 # else
269 # hist_data2 = TH1F(*hist_data);
270 # hist_data.Sumw2();
271 # hist_data2.Sumw2();
272 hist_ttbar0 = ttbar0.Get(histname);
273 hist_ttbarup = ttbarup.Get(histname);
274 hist_ttbard = ttbardown.Get(histname);
275 hist_wpm600fl = WprimeTToTTD_M600fl.Get(histname);
276 hist_wpm600up = WprimeTToTTD_M600up.Get(histname);
277 hist_wpm600d = WprimeTToTTD_M600d.Get(histname);
278 # hist_wjets = wjets.Get(histname);
279 # hist_zjets = zjets.Get(histname);
280
281 # hist_bce1 = bce1.Get(histname);
282 # hist_bce2 = bce2.Get(histname);
283 # hist_bce3 = bce3.Get(histname);
284 # hist_enri1 = enri1.Get(histname);
285 # hist_enri2 = enri2.Get(histname);
286 # hist_enri3 = enri3.Get(histname);
287 # # hist_pj1 = pj1.Get(histname);
288 # # hist_pj2 = pj2.Get(histname);
289 # hist_pj3 = pj3.Get(histname);
290 # hist_singleTop = tW.Get(histname)
291 # hist_singleTop.Add(tchan.Get(histname))
292
293 # hist_Zprime500 = Zprime500.Get(histname);
294 # hist_Zprime750 = Zprime750.Get(histname);
295 # hist_Zprime1000 = Zprime1000.Get(histname);
296 # hist_Zprime1500 = Zprime1500.Get(histname);
297 # hist_Zprime2000 = Zprime2000.Get(histname);
298 # hist_Zprime4000 = Zprime4000.Get(histname);
299 # hist_Tprime300 = Tprime300.Get(histname);
300 # hist_Tprime350 = Tprime350.Get(histname);
301 # # hist_Zprime1250 = Zprime1250.Get(histname);
302 # hist_wpm400 = WprimeTToTTD_M400.Get(histname);
303
304 # hist_ttbar0.Sumw2(); # No good, must be done before filling
305
306 # if ('iso' in histname or 'jetmultip' in histname or 'DeltaR' in histname or ('num' in histname and 'Top' in histname)):
307 # if ('looseeleciso' in histname or 'tau' in histname or 'DeltaR' in # histname or ('num' in histname and 'Top' in histname)):
308 numevts = hist_ttbar0.Integral();
309 if (numevts > 0):
310 hist_ttbar0.Scale(1.0/numevts);
311 numevts = hist_ttbarup.Integral();
312 hist_ttbarup.Scale(1.0/numevts);
313 numevts = hist_ttbard.Integral();
314 hist_ttbard.Scale(1.0/numevts);
315 numevts = hist_wpm600fl.Integral();
316 hist_wpm600fl.Scale(1.0/numevts);
317 numevts = hist_wpm600d.Integral();
318 hist_wpm600d.Scale(1.0/numevts);
319 numevts = hist_wpm600up.Integral();
320 hist_wpm600up.Scale(1.0/numevts);
321
322
323 # hist_qcd = hist_bce1.Clone("qcd")#TH1F(*hist_bce1);
324 # hist_qcd.Add(hist_bce2);
325 # hist_qcd.Add(hist_bce3);
326 # hist_qcd.Add(hist_enri1);
327 # hist_qcd.Add(hist_enri2);
328 # hist_qcd.Add(hist_enri3);
329 # hist_qcd.Add(hist_pj1);
330 # hist_qcd.Add(hist_pj2);
331 # hist_qcd.Add(hist_pj3);
332 # hist_qcd.Scale(qcdScale[currentSelection]);
333 # ndata = hist_data.Integral();
334 # ntop = hist_ttbar0.Integral();
335 # nwj = hist_wjets.Integral();
336 # nzj = hist_zjets.Integral();
337 # nqcd = hist_qcd.Integral();
338 # sumMC = ntop + nwj + nzj + nqcd;
339 # cout << ndata << " " << sumMC << endl;
340 # hist_wjets.Scale(ndata / sumMC);
341 # hist_ttbar0.Scale(ndata / sumMC);
342 # hist_zjets.Scale(ndata / sumMC);
343 # hist_qcd.Scale(ndata / sumMC);
344 # mttbars = ['mttbar_' + suffix for suffix in suffixes]
345 # mttbars2 = ['mttbar_withMETAndAsymJets_' + suffix for suffix in suffixes]
346 # if histname in mttbars or histname in mttbars2:
347 # print "taking QCD shape from DATA"
348 # name = histname.replace('mttbar', 'mttbar_conversions')
349 # hist_qcd = data.Get(name)
350 # if( hist_qcd.Integral() > 0):
351 # hist_qcd.Scale(nqcd/hist_qcd.Integral())
352 # hist_mc = hist_qcd.Clone("all_mc")
353 # hist_mc.Add(hist_ttbar0);
354 # hist_mc.Add(hist_zjets);
355 # hist_mc.Add(hist_wjets);
356 # hist_mc.Add(hist_singleTop);
357
358 hist_data = hist_ttbar0.Clone("test");
359 rebin = 1;
360 Urange = (0,5000)
361 Yrange = (0,0)
362
363 if ("mttbar" in histname):
364 hist_data.SetXTitle("M_{t#bar{t}}/GeV");
365 hist_data.SetYTitle("Events/(100 GeV)");
366 rebin = 100;
367 Urange = (0, 2000)
368 elif ("tPrimeMass" in histname):
369 hist_data.SetXTitle("T' mass/GeV");
370 hist_data.SetYTitle("Events/(100 GeV)");
371 rebin = 200;
372 Urange = (0, 2000)
373 elif ("wpmass" in histname or "wpnegmass" in histname or "wpanglmass" in histname or "wp1top" in histname):
374 hist_data.SetXTitle("W' mass/GeV");
375 hist_data.SetYTitle("Events/(60 GeV)");
376 rebin = 60;
377 Urange = (0, 1500)
378 elif ("jet12" in histname or "jet13" in histname):
379 hist_data.SetXTitle("Jet mass/GeV");
380 hist_data.SetYTitle("Jet mass/GeV)");
381 elif ("tPrimepT" in histname):
382 hist_data.SetXTitle("T' pT/GeV");
383 hist_data.SetYTitle("Events/(8 GeV)");
384 rebin = 8;
385 Urange = (0, 200)
386 elif ("tPrimeHT" in histname):
387 hist_data.SetXTitle("T' HT");
388 hist_data.SetYTitle("Events");
389 rebin = 4;
390 Urange = (0, 1.5)
391 elif ("m3" in histname):
392 hist_data.SetXTitle("M3/GeV");
393 hist_data.SetYTitle("Events/(50 GeV)");
394 rebin = 50;
395 Urange = (0, 1500)
396 elif (histname == "electron_et"):
397 hist_data.SetXTitle("electron E_{T}/GeV");
398 hist_data.SetYTitle("Events/(10 GeV)");
399 rebin = 10;
400 Urange = (0, 300)
401 elif (histname == "electron_pt" or histname == "electminus_pt" or histname == "positron_pt"):
402 hist_data.SetXTitle("electron p_{T}/GeV");
403 hist_data.SetYTitle("Events/(10 GeV)");
404 rebin = 10;
405 Urange = (0, 300)
406 elif (histname == "muon_et"):
407 hist_data.SetXTitle("muon E_{T}/GeV");
408 hist_data.SetYTitle("Events/(10 GeV)");
409 rebin = 10;
410 Urange = (0, 300)
411 elif (histname == "muon_pt"):
412 hist_data.SetXTitle("muon p_{T}/GeV");
413 hist_data.SetYTitle("Events/(10 GeV)");
414 rebin = 10;
415 Urange = (0, 300)
416 elif ("ttbar_pt" in histname):
417 hist_data.SetXTitle("p_{T} of t#bar{t} system/GeV");
418 hist_data.SetYTitle("Events/(10 GeV)");
419 rebin = 10;
420 Urange = (0, 500)
421 elif ("ttbar_px" in histname):
422 hist_data.SetXTitle("p_{x} of t#bar{t} system/GeV");
423 hist_data.SetYTitle("Events/(10 GeV)");
424 rebin = 10;
425 Urange = (0, 500)
426 elif ("ttbar_py" in histname):
427 hist_data.SetXTitle("p_{y} of t#bar{t} system/GeV");
428 hist_data.SetYTitle("Events/(10 GeV)");
429 rebin = 10;
430 Urange = (0, 500)
431 elif ("ttbar_pz" in histname):
432 hist_data.SetXTitle("p_{z} of t#bar{t} system/GeV");
433 hist_data.SetYTitle("Events/(50 GeV)");
434 rebin = 50;
435 Urange = (0, 2000)
436 elif ("METpt_ltop" in histname):
437 hist_data.SetXTitle("MET p_{T}/GeV");
438 hist_data.SetYTitle("Events/(20 GeV)");
439 rebin = 20;
440 Urange = (0, 400)
441 elif ("tPrime_pt" in histname):
442 hist_data.SetXTitle("p_{T} of T' system/GeV");
443 hist_data.SetYTitle("Events/(20 GeV)");
444 rebin = 20;
445 Urange = (0, 200)
446 elif ("tPrime_px" in histname):
447 hist_data.SetXTitle("p_{x} of T' system/GeV");
448 hist_data.SetYTitle("Events/(20 GeV)");
449 rebin = 20;
450 Urange = (0, 200)
451 elif ("tPrime_py" in histname):
452 hist_data.SetXTitle("p_{y} of T' system/GeV");
453 hist_data.SetYTitle("Events/(20 GeV)");
454 rebin = 20;
455 Urange = (0, 200)
456 elif ("tPrime_pz" in histname):
457 hist_data.SetXTitle("p_{z} of T' system/GeV");
458 hist_data.SetYTitle("Events/(100 GeV)");
459 rebin = 200;
460 Urange = (0, 1800)
461 elif ("HT_" in histname):
462 hist_data.SetXTitle("#Sigma p_{T}/GeV");
463 hist_data.SetYTitle("Events/(20 GeV)");
464 rebin = 20;
465 Urange = (0, 2000)
466 elif ("ST" in histname):
467 hist_data.SetXTitle("ST/GeV");
468 hist_data.SetYTitle("Events/(30 GeV)");
469 rebin = 30;
470 Urange = (0, 1000)
471 elif ("HT3jet_ltop" in histname):
472 hist_data.SetXTitle("#Sigma p_{T} of leading 3 jets/GeV");
473 hist_data.SetYTitle("Events/(20 GeV)");
474 rebin = 20;
475 Urange = (0, 1000)
476 elif ("HT4jet_ltop" in histname):
477 hist_data.SetXTitle("#Sigma p_{T} of leading 4 jets/GeV");
478 hist_data.SetYTitle("Events/(50 GeV)");
479 rebin = 50;
480 Urange = (0, 1200)
481 elif (histname == "numberOfJets"):
482 hist_data.SetXTitle("number of jets");
483 hist_data.SetYTitle("Events");
484 elif (histname == "numberOfBJets"):
485 hist_data.SetXTitle("number of b-tagged jets (SSVHE medium)");
486 hist_data.SetYTitle("Events");
487 elif ('MET_' in histname and 'MET_ltop' not in histname):
488 hist_data.SetXTitle("MET/GeV");
489 hist_data.SetYTitle("Events/(5 GeV)");
490 rebin = 5;
491 Urange = (0, 400)
492 elif ('MET_ltop' in histname):
493 hist_data.SetXTitle("MET/GeV");
494 hist_data.SetYTitle("Events/(20 GeV)");
495 rebin = 20;
496 Urange = (0, 400)
497 elif ("leadingJetMass" in histname):
498 hist_data.SetXTitle("leading jet mass/GeV");
499 hist_data.SetYTitle("Events/(5 GeV)");
500 rebin = 5;
501 Urange = (0, 150)
502 elif ("mtW" in histname):
503 hist_data.SetXTitle("transverse W-boson mass/GeV");
504 hist_data.SetYTitle("Events/(10 GeV)");
505 rebin = 10;
506 elif ("both" in histname or "plus" in histname or "minus" in histname):
507 hist_data.SetXTitle("transverse mass/GeV");
508 hist_data.SetYTitle("Events/(100 GeV)");
509 rebin = 100;
510 Urange = (0, 2000)
511 elif ("transMasslm1b" in histname):
512 hist_data.SetXTitle("M_{T} (lep+MET+1b)/GeV");
513 hist_data.SetYTitle("Events/(50 GeV)");
514 rebin = 50;
515 Urange = (0, 700)
516 elif ("electronD0" in histname):
517 hist_data.SetXTitle("electron d_{0} / cm");
518 hist_data.SetYTitle("Events/(0.001 cm)");
519 rebin = 10;
520 elif ("angleTops" in histname or "deltaPhiTops" in histname):
521 hist_data.SetXTitle("angle between top quarks");
522 hist_data.SetYTitle("Events/(0.1 rad)");
523 rebin = 10;
524 elif ( "deltaphilep" in histname):
525 hist_data.SetXTitle("angle between lepton & leading jet");
526 hist_data.SetYTitle("Events/(0.2 rad)");
527 rebin = 20;
528 elif ("lepb_angle" in histname):
529 hist_data.SetXTitle("angle between electron and b jet");
530 hist_data.SetYTitle("Events/(0.1 rad)");
531 rebin = 10;
532 elif ("angleHadTopD" in histname):
533 hist_data.SetXTitle("angle between hadronic top and light jet");
534 hist_data.SetYTitle("Events/(0.2 rad)");
535 rebin = 20;
536 elif ("METtopangle_ltop" in histname):
537 hist_data.SetXTitle("angle between MET and top p_{T}");
538 hist_data.SetYTitle("Events/(0.1 rad)");
539 rebin = 10;
540 Urange = (-2, 2)
541 elif ("qkjet_eta" in histname):
542 hist_data.SetXTitle("#eta of b jet");
543 hist_data.SetYTitle("Events/(0.1 rad)");
544 Urange = (-3, 3)
545 rebin = 10;
546 elif ("_rap" in histname):
547 hist_data.SetXTitle("Jet Rapidity");
548 hist_data.SetYTitle("Events/(0.1 rad)");
549 Urange = (-3, 3)
550 rebin = 20;
551 elif ("neutrino_pz" in histname):
552 hist_data.SetXTitle("neutrino p_{Z} /GeV");
553 hist_data.SetYTitle("Events/(20 GeV)");
554 rebin = 20;
555 Urange = (-500, 500)
556 elif ('mHadTopLoneNM' in histname):
557 hist_data.SetXTitle("top mass /GeV");
558 hist_data.SetYTitle("Events/(10 GeV)");
559 rebin = 10;
560 Urange = (0, 400)
561 elif ('mass4jets' in histname):
562 hist_data.SetXTitle("4-jet mass /GeV");
563 hist_data.SetYTitle("Events/(50 GeV)");
564 rebin = 50;
565 Urange = (0, 1500)
566 elif ('mLepTopLoneNM' in histname):
567 hist_data.SetXTitle("top mass /GeV");
568 hist_data.SetYTitle("Events/(10 GeV)");
569 rebin = 10;
570 Urange = (0, 400)
571 elif ('chiHadronicTop' in histname or 'chiLeptonicTop' in histname):
572 hist_data.SetXTitle("top #chi^{2} /GeV");
573 hist_data.SetYTitle("Events/(1)");
574 rebin = 1;
575 Urange = (0, 30)
576 elif ('chiGlobal' in histname or 'chiTotal' in histname):
577 hist_data.SetXTitle("Event #chi^{2} /GeV");
578 hist_data.SetYTitle("Events/(100)");
579 rebin = 100;
580 elif ('numHadTopMCMatches' in histname or 'numLepTopMCMatches' in histname):
581 hist_data.SetXTitle("Number of Exact Decay-Chain Matches");
582 hist_data.SetYTitle("Events");
583 Yrange = (0, 1.1)
584 elif ('numHadTopDauMCMatches' in histname or 'numLepTopDauMCMatches' in histname):
585 hist_data.SetXTitle("Number of Top Daughter Matches");
586 hist_data.SetYTitle("Events");
587 Yrange = (0, 1.1)
588 elif ('numHadTopCorrectID' in histname or 'numLepTopCorrectID' in histname):
589 hist_data.SetXTitle("Number of Reco Candidates Matched to MC-Truth Particles");
590 hist_data.SetYTitle("Events");
591 Yrange = (0, 1.1)
592 elif ('lepTopDeltaR' in histname or 'hadTopDeltaR' in histname):
593 hist_data.SetXTitle("#Delta R of MC truth top");
594 hist_data.SetYTitle("Events");
595 rebin = 20;
596 # Urange = (0, 4)
597 elif ('lepTopLep' in histname or 'hadTopHad' in histname):
598 hist_data.SetXTitle("top MC truth identity");
599 hist_data.SetYTitle("Events");
600 Urange = (0, 2)
601 elif ('mHadTopLone' in histname or 'mHadronicTop' in histname or 'mAllTop' in histname):
602 hist_data.SetXTitle("top mass /GeV");
603 hist_data.SetYTitle("Events/(15 GeV)");
604 rebin = 15;
605 Urange = (0, 700)
606 elif ('mLepTopLone' in histname or 'mLeptonicTop' in histname):
607 hist_data.SetXTitle("top mass /GeV");
608 hist_data.SetYTitle("Events/(15 GeV)");
609 rebin = 15;
610 Urange = (0, 700)
611 elif ('pt_' in histname and 'Top' in histname):
612 hist_data.SetXTitle("top p_{T} /GeV");
613 hist_data.SetYTitle("Events/(50 GeV)");
614 rebin = 50;
615 Urange = (0, 500)
616 elif ('trailingJetPt' in histname):
617 hist_data.SetXTitle("Jet p_{T} /GeV");
618 hist_data.SetYTitle("Events/(25 GeV)");
619 rebin = 30;
620 Urange = (0, 270)
621 elif ('JetPt' in histname):
622 hist_data.SetXTitle("Jet p_{T} /GeV");
623 hist_data.SetYTitle("Events/(50 GeV)");
624 rebin = 50;
625 Urange = (0, 600)
626 elif('QCDest_CombRelIso' in histname):
627 hist_data.SetXTitle("relative isolation");
628 hist_data.SetYTitle("Events/(0.1)");
629 rebin = 10;
630 Urange = (0, 2)
631 elif('QCDest_PFIsolation' in histname):
632 hist_data.SetXTitle("ParticleFlow isolation");
633 hist_data.SetYTitle("Events/(0.1)");
634 rebin = 10
635 Urange = (0, 2)
636 elif('iso' in histname):
637 hist_data.SetXTitle("ParticleFlow Isolation");
638 hist_data.SetYTitle("Events/(0.02)");
639 rebin = 4
640 Urange = (0, 0.5)
641 elif('vertdist' in histname):
642 hist_data.SetXTitle("Steps from PV");
643 hist_data.SetYTitle("Events");
644 # rebin = 200
645 Urange = (0, 2)
646 elif('jetmultip' in histname):
647 hist_data.SetXTitle("Number of jets");
648 hist_data.SetYTitle("Events");
649 # rebin = 60
650 Urange = (0, 11)
651 elif('tausInJets' in histname):
652 hist_data.SetXTitle("Number of tau jets");
653 hist_data.SetYTitle("Events");
654 # rebin = 60
655 Urange = (0, 3)
656 elif('numTaus' in histname):
657 hist_data.SetXTitle("Number of taus");
658 hist_data.SetYTitle("Events");
659 # rebin = 60
660 Urange = (0, 15)
661 elif('numGenJets' in histname):
662 hist_data.SetXTitle("Number of GenJets");
663 hist_data.SetYTitle("Events");
664 # rebin = 60
665 Urange = (3, 15)
666 elif('numDiffJets' in histname):
667 hist_data.SetXTitle("Difference between Reco Jets & GenJets");
668 hist_data.SetYTitle("Events");
669 # rebin = 60
670 Urange = (-7, 4)
671 elif('miss' in histname and 'Jets' in histname):
672 if('miss' in histname and 'missGenJets' in histname):
673 hist_data.SetXTitle("Number of Unmatched Reco Jets");
674 else:
675 hist_data.SetXTitle("Number of Unmatched GenJets");
676 hist_data.SetYTitle("Events");
677 # rebin = 60
678 Urange = (0, 8)
679
680
681 hist_data.SetTitleOffset(1.5, "Y");
682 if ('jet1' in histname):
683 hist_data.Rebin2D();
684 hist_ttbar0.Rebin2D();
685 hist_Tprime300.Rebin2D();
686 hist_Tprime350.Rebin2D();
687 hist_data.SetAxisRange(0, 600, "X");
688 hist_data.SetAxisRange(0, 600, "Y");
689 hist_ttbar0.SetAxisRange(0, 600, "X");
690 hist_ttbar0.SetAxisRange(0, 600, "Y");
691 # hist_Tprime300.SetAxisRange(0, 600, "X");
692 # hist_Tprime300.SetAxisRange(0, 600, "Y");
693 # hist_Tprime350.SetAxisRange(0, 600, "X");
694 # hist_Tprime350.SetAxisRange(0, 600, "Y");
695 else:
696 hist_data.Rebin(rebin);
697 hist_ttbar0.Rebin(rebin);
698 hist_ttbarup.Rebin(rebin);
699 hist_ttbard.Rebin(rebin);
700 hist_wpm600fl.Rebin(rebin);
701 hist_wpm600up.Rebin(rebin);
702 hist_wpm600d.Rebin(rebin);
703
704 hist_data.SetAxisRange(Urange[0], Urange[1]);
705 hist_ttbar0.SetAxisRange(Urange[0], Urange[1]);
706 hist_ttbarup.SetAxisRange(Urange[0], Urange[1]);
707 hist_ttbard.SetAxisRange(Urange[0], Urange[1]);
708 hist_wpm600fl.SetAxisRange(Urange[0], Urange[1]);
709 hist_wpm600up.SetAxisRange(Urange[0], Urange[1]);
710 hist_wpm600d.SetAxisRange(Urange[0], Urange[1]);
711
712
713 hist_data.SetMarkerStyle(8);
714 # hist_data.SetMarkerSize(1.5);
715 hist_data.SetMarkerSize(0.1);
716 drawPlot(hist_data, hist_ttbar0, hist_ttbarup, hist_ttbard, histname + "ttbar");
717 drawPlot(hist_data, hist_wpm600fl, hist_wpm600up, hist_wpm600d, histname + "wp600");
718
719
720 def drawPlot(hist_data, hist_flat, hist_up, hist_down, histname):
721 linewidth = 6;
722 hist_flat.SetLineColor(kBlack);
723 hist_flat.SetLineWidth(linewidth);
724 hist_flat.SetLineStyle(2);
725 hist_up.SetLineColor(kGreen + 3);
726 hist_up.SetLineWidth(linewidth);
727 hist_up.SetLineStyle(9);
728 hist_down.SetLineColor(kRed + 2);
729 hist_down.SetLineStyle(7);
730 hist_down.SetLineWidth(linewidth);
731
732 leg = TLegend(0.696, 0.35, 0.95, 0.92);
733 leg.SetBorderSize(0);
734 leg.SetLineStyle(0);
735 leg.SetTextFont(42);
736 leg.SetFillStyle(0);
737
738 leg.AddEntry(hist_flat, "No adj.", "L");
739 leg.AddEntry(hist_up, "+ #sigma", "L");
740 leg.AddEntry(hist_down, "- #sigma", "L");
741
742
743 canvases.append(TCanvas("cname" + histname, histname, 1200, 900))
744
745 # if ('iso' in histname or 'jetmultip' in histname or 'num' in histname and 'Top' in histname):
746 canvases[-1].SetGrid();
747 canvases[-1].cd().SetRightMargin(0.04);
748
749 max = 0
750 max = hist_up.GetMaximum()*1.1
751 max2 = hist_down.GetMaximum()*1.1
752 if (max2 > max):
753 max = max2
754
755 if (false and 'wp1topmass' in histname):
756 hist_data.GetYaxis().SetRangeUser(0, 310);
757 elif (false and 'mLepTopLone' in histname):
758 hist_data.GetYaxis().SetRangeUser(0, 510);
759 elif (false and 'mHadTopLone' in histname):
760 hist_data.GetYaxis().SetRangeUser(0, 400);
761 elif ('jetmultip' in histname):
762 hist_data.GetYaxis().SetRangeUser(0, 1600);
763 elif ('looseeleciso' in histname):
764 hist_data.GetYaxis().SetRangeUser(0, 0.2);
765 else:
766 hist_data.GetYaxis().SetRangeUser(0, max);
767 # hist_data.SetStats(1); # SetOptStat at start turns on stats
768 # hist_data.Draw('error');
769 # if ('iso' in histname):
770 # canvases[-1].SetLogy();
771 hist_data.Draw("axis");
772 hist_data.SetMarkerStyle(8);
773 hist_flat.Draw("hist same");
774 hist_up.Draw("hist same");
775 hist_down.Draw("hist same");
776 leg.Draw();
777
778 text1 = TLatex(3.570061, 23.08044, "CMS Preliminary");
779 text1.SetNDC();
780 text1.SetTextAlign(13);
781 text1.SetX(0.38);
782 text1.SetY(0.928);
783 #text1.SetLineWidth(2);
784 text1.SetTextFont(42);
785 text1.SetTextSizePixels(24);# dflt=28
786 text1.SetTextSize(0.03);
787 text1.Draw();
788
789 text2 = TLatex(3.570061, 23.08044, "5.0 fb^{-1} at #sqrt{s} = 7 TeV");
790 text2.SetNDC();
791 text2.SetTextAlign(13);
792 text2.SetX(0.38);
793 text2.SetY(0.88);
794 #text2.SetLineWidth(2);
795 text2.SetTextFont(42);
796 text2.SetTextSizePixels(24);# dflt=28
797 text2.SetTextSize(0.03);
798 text2.Draw();
799 # canvases[-1].SaveAs('plots/' + histname + '.png')
800 if (false and 'iso' in histname):
801 canvases[-1].SaveAs('plots/' + histname + '.root')
802 else:
803 canvases[-1].SaveAs('plots/' + histname + '.png')
804
805
806 # tdrGrid: Turns the grid lines on (true) or off (false)
807
808 #def tdrGrid(bool gridOn):
809 # tdrStyle.SetPadGridX(gridOn);
810 # tdrStyle.SetPadGridY(gridOn);
811 #
812
813 # fixOverlay: Redraws the axis
814
815 def setCorrErrs(hist_good, hist_bad, hist_diff):
816 nbins = hist_diff.GetXaxis().GetNbins();
817 for i in range(1, nbins):
818 goodval = hist_good.GetBinContent(i);
819 badval = hist_bad.GetBinContent(i);
820 gooderr = hist_good.GetBinError(i);
821 baderr = hist_bad.GetBinError(i);
822 errsum = goodval + badval;
823 if errsum > 0:
824 # print 'evts err ', goodval, gooderr;
825 goodprod = goodval * baderr;
826 badprod = gooderr * badval;
827 tot = (goodprod * goodprod) + (badprod * badprod);
828 # Assume 90% correlation
829 tot = tot - (1.8 * goodprod * badprod);
830 if tot > 0:
831 tot = 4.0 * sqrt(tot) / (errsum * errsum);
832 hist_diff.SetBinError(i, tot);
833
834
835
836 def setUncorrErrs(hist_good, hist_bad, hist_diff):
837 nbins = hist_diff.GetXaxis().GetNbins();
838 for i in range(1, nbins):
839 goodval = hist_good.GetBinContent(i);
840 badval = hist_bad.GetBinContent(i);
841 err = goodval + badval;
842 err = err * err * err;
843 if err > 0:
844 err = 4.0 * sqrt((goodval * badval) / err);
845 hist_diff.SetBinError(i, err);
846
847
848 def asymmetryplot(hist_good, hist_bad, histname):
849 hist_total = hist_good.Clone("test");
850 # hist_total.Sumw2();
851 hist_total.Add(hist_bad);
852 hist_diff = hist_good.Clone("test");
853 # hist_diff.Sumw2();
854 hist_diff.Add(hist_bad, -1);
855 hist_total.Scale(0.5);
856 hist_diff.Divide(hist_total);
857 # setCorrErrs(hist_good, hist_bad, hist_diff);
858 hist_diff.SetXTitle("W' mass/GeV");
859 hist_diff.SetYTitle("Asymmetry");
860 hist_diff.SetAxisRange(200, 1100);
861 hist_diff.SetLineWidth(4);
862 # hist_diff.SetFillStyle(1001);
863 hist_diff.SetFillStyle(3001);
864 hist_diff.SetFillColor(kRed);
865 canvases[-1].SetGridy();
866 hist_diff.GetYaxis().SetRangeUser(-asymrange, asymrange);
867 hist_diff.Draw("hist E1");
868 canvases[-1].SaveAs('plots/' + histname + '.png')
869
870
871 def asymmetry2plot(ttbar_good, ttbar_bad, wp_good, wp_bad, histname):
872 hist_total = ttbar_good.Clone("test");
873 # hist_total.Sumw2();
874 hist_total.Add(ttbar_bad);
875 hist_total.Add(wp_good);
876 hist_total.Add(wp_bad);
877 hist_total.Scale(0.5);
878 hist_diff = ttbar_good.Clone("test");
879 # hist_diff.Sumw2();
880 hist_diff.Add(wp_good);
881 hist_diff.Add(ttbar_bad, -1);
882 hist_diff.Add(wp_bad, -1);
883 hist_diff.Divide(hist_total);
884 # nbins = hist_diff.GetXaxis().GetNbins();
885 hist_good = ttbar_good.Clone("test");
886 hist_good.Add(wp_good);
887 hist_bad = ttbar_bad.Clone("test");
888 hist_bad.Add(wp_bad);
889 # setCorrErrs(hist_good, hist_bad, hist_diff);
890 hist_diff.SetXTitle("W' mass/GeV");
891 hist_diff.SetYTitle("Asymmetry");
892 hist_diff.SetAxisRange(200, 1100);
893 hist_diff.SetLineWidth(4);
894 # hist_diff.SetFillStyle(1001);
895 hist_diff.SetFillStyle(3001);
896 hist_diff.SetFillColor(kRed);
897 canvases[-1].SetGridy();
898 hist_diff.GetYaxis().SetRangeUser(-asymrange, asymrange);
899 hist_diff.Draw("hist E1");
900 canvases[-1].SaveAs('plots/' + histname + '.png')
901
902
903
904 def plusminuscmp(hist_pos, hist_neg, hist_name, sign):
905 hist_neg.SetXTitle("Reco W' mass/GeV");
906 hist_neg.SetYTitle("Events/(60 GeV)");
907 hist_pos.SetLineColor(kGray + 3);
908 hist_neg.SetLineColor(kRed);
909 hist_neg.SetFillStyle(0);
910 hist_pos.SetFillStyle(0);
911 linewidth = 6;
912 hist_pos.SetLineWidth(linewidth);
913 hist_neg.SetLineWidth(linewidth);
914 leg = TLegend(0.696, 0.35, 0.95, 0.92);
915 leg.SetBorderSize(0);
916 leg.SetLineStyle(0);
917 leg.SetTextFont(42);
918 leg.SetFillStyle(0);
919 if sign == 1:
920 leg.AddEntry(hist_pos, "W't+ .6TeV (8 pb)", "L");
921 leg.AddEntry(hist_neg, "W't- .6TeV (8 pb)", "L");
922 else:
923 leg.AddEntry(hist_pos, "W't bad .6TeV (8 pb)", "L");
924 leg.AddEntry(hist_neg, "W't good .6TeV (8 pb)", "L");
925 hist_pos.SetStats(1);
926 hist_neg.Draw("hist E1");
927 hist_pos.Draw("hist same");
928 leg.Draw();
929 canvases[-1].SaveAs('plots/' + hist_name + '.png')
930
931
932 def fixOverlay():
933 gPad.RedrawAxis();
934
935
936 def getCumulativePlot(initial, type):
937 global counter
938 counter = counter + 1;
939 name = initial.GetName()
940 name = "cu_" + name + "_" + type + str(counter);
941 title = initial.GetTitle()
942 title = "cu_" + title + "_" + type;
943 xaxis = initial.GetXaxis().GetTitle();
944 yaxis = initial.GetYaxis().GetTitle();
945 nBins = initial.GetNbinsX();
946 cu = TH1F(name, title, nBins, initial.GetXaxis().GetXmin(), initial.GetXaxis().GetXmax());
947 for bin in range(1,nBins+1):
948 cu.SetBinContent(bin, initial.Integral(bin, nBins));
949
950 cu.SetFillStyle(initial.GetFillStyle());
951 cu.SetFillColor(initial.GetFillColor());
952 cu.SetLineColor(initial.GetLineColor());
953 cu.SetMarkerSize(initial.GetMarkerSize());
954 cu.SetMarkerStyle(initial.GetMarkerStyle());
955 cu.SetMarkerColor(initial.GetMarkerColor());
956 cu.SetLineWidth(initial.GetLineWidth());
957 cu.GetXaxis().SetTitle(xaxis);
958 cu.GetYaxis().SetTitle(yaxis);
959 return cu;
960
961 if __name__ == "__main__":
962 gROOT.SetBatch(True)
963 gROOT.ProcessLine('gErrorIgnoreLevel = 1001;')
964 plotMttbar()
965 # print "press enter to quit"
966 # a = raw_input()