ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/dhidas/OSUAnalysis/Tools/scripts/plotMttbar.py
Revision: 1.1
Committed: Thu Dec 1 16:28:48 2011 UTC (13 years, 5 months ago) by dhidas
Content type: text/x-python
Branch point for: dhidas, MAIN
Log Message:
Initial revision

File Contents

# User Rev Content
1 dhidas 1.1 from __future__ import division
2    
3     from tdrStyle import *
4     from ROOT import *
5    
6     canvases = []
7     scanvases = []
8    
9     def plotMttbar():
10     tdrstyle = setTDRStyle();
11     gStyle.SetHatchesSpacing(1.0);
12     lumi = 36.145;#3.06 + 1.37 + 2.53 + 0.26;
13     oldLumi = 36.145;
14     scale = lumi / oldLumi;
15     qcdScale = {'default':0.78, 'withMETAndAsymJets': 1.58};
16     # data = TFile.Open("data2.9pb_fullSetOfVars.root");
17     data = TFile.Open("/storage/results/outputfiles/Preapproval2/data_36.145pb_PFElectron_PF2PATJets_PFMET.root");
18     ttbar = TFile.Open("/storage/results/outputfiles/Preapproval2/ttjet_36.145pb_PFElectron_PF2PATJets_PFMET.root");
19     wjets = TFile.Open("/storage/results/outputfiles/Preapproval2/wj_36.145pb_PFElectron_PF2PATJets_PFMET.root");
20     zjets = TFile.Open("/storage/results/outputfiles/Preapproval2/zj_36.145pb_PFElectron_PF2PATJets_PFMET.root");
21     bce1 = TFile.Open("/storage/results/outputfiles/Preapproval2/bce1_36.145pb_PFElectron_PF2PATJets_PFMET.root");
22     bce2 = TFile.Open("/storage/results/outputfiles/Preapproval2/bce2_36.145pb_PFElectron_PF2PATJets_PFMET.root");
23     bce3 = TFile.Open("/storage/results/outputfiles/Preapproval2/bce3_36.145pb_PFElectron_PF2PATJets_PFMET.root");
24     enri1 = TFile.Open("/storage/results/outputfiles/Preapproval2/enri1_36.145pb_PFElectron_PF2PATJets_PFMET.root");
25     enri2 = TFile.Open("/storage/results/outputfiles/Preapproval2/enri2_36.145pb_PFElectron_PF2PATJets_PFMET.root");
26     enri3 = TFile.Open("/storage/results/outputfiles/Preapproval2/enri3_36.145pb_PFElectron_PF2PATJets_PFMET.root");
27     pj1 = TFile.Open("/storage/results/outputfiles/Preapproval2/pj1_36.145pb_PFElectron_PF2PATJets_PFMET.root");
28     pj2 = TFile.Open("/storage/results/outputfiles/Preapproval2/pj2_36.145pb_PFElectron_PF2PATJets_PFMET.root");
29     pj3 = TFile.Open("/storage/results/outputfiles/Preapproval2/pj3_36.145pb_PFElectron_PF2PATJets_PFMET.root");
30     tW = TFile.Open("/storage/results/outputfiles/Preapproval2/tW_36.145pb_PFElectron_PF2PATJets_PFMET.root");
31     tchan = TFile.Open("/storage/results/outputfiles/Preapproval2/tchan_36.145pb_PFElectron_PF2PATJets_PFMET.root");
32     # vqq = TFile.Open("vqq_7.22pb_V4PFCalo.root__fullSetOfVars.root");
33     # Zprime500 = TFile.Open("/storage/workspace/BristolAnalysisTools/outputfiles/Zprime_M500GeV_W5GeV_36.145pb.root");
34     # Zprime750 = TFile.Open("/storage/workspace/BristolAnalysisTools/outputfiles/Zprime_M750GeV_W7500MeV_36.145pb.root");
35     # Zprime1000 = TFile.Open("/storage/workspace/BristolAnalysisTools/outputfiles/Zprime_M1TeV_W10GeV_36.145pb.root");
36     # Zprime1250 = TFile.Open("/storage/workspace/BristolAnalysisTools/outputfiles/Zprime_M1250GeV_W12500MeV_36.145pb.root");
37     # Zprime1500 = TFile.Open("/storage/workspace/BristolAnalysisTools/outputfiles/Zprime_M1500GeV_W15GeV_36.145pb.root");
38    
39     hists = [];
40     # hists.append('mttbar_QCDEnriched')
41     hists.append('mttbar_conversions')
42     # hists.append('mttbar_conversions_withMETCut')
43     hists.append('mttbar_conversions_withMETAndAsymJets')
44     # hists.append('mttbar_conversions_withAsymJetsCut')
45     # hists.append('mttbar_controlRegion')
46     # hists.append("mttbar");
47     # hists.append("mttbar_2ndSolution");
48     # hists.append("mttbar_3rdSolution");
49     # hists.append("mttbar_allSolutions");
50    
51     # hists.append("mttbar_withMETCut");
52     # hists.append("mttbar_2ndSolution_withMETCut");
53     # hists.append("mttbar_3rdSolution_withMETCut");
54     # hists.append("mttbar_allSolutions_withMETCut");
55    
56     # hists.append("mttbar_withMETAndAsymJets");
57     # hists.append("mttbar_2ndSolution_withMETAndAsymJets");
58     # hists.append("mttbar_3rdSolution_withMETAndAsymJets");
59     # hists.append("mttbar_allSolutions_withMETAndAsymJets");
60    
61     # hists.append("mttbar_withAsymJetsCut");
62     # hists.append("mttbar_2ndSolution_withAsymJetsCut");
63     # hists.append("mttbar_3rdSolution_withAsymJetsCut");
64     # hists.append("mttbar_allSolutions_withAsymJetsCut");
65    
66     # hists.append("ttbar_pt");
67     # hists.append("ttbar_pt_2ndSolution");
68     # hists.append("ttbar_pt_3rdSolution");
69     # hists.append("ttbar_pt_allSolutions");
70     #
71     # hists.append("ttbar_pt_withMETCut");
72     # hists.append("ttbar_pt_2ndSolution_withMETCut");
73     # hists.append("ttbar_pt_3rdSolution_withMETCut");
74     # hists.append("ttbar_pt_allSolutions_withMETCut");
75     #
76     # hists.append("ttbar_pt_withMETAndAsymJets");
77     # hists.append("ttbar_pt_2ndSolution_withMETAndAsymJets");
78     # hists.append("ttbar_pt_3rdSolution_withMETAndAsymJets");
79     # hists.append("ttbar_pt_allSolutions_withMETAndAsymJets");
80     #
81     # hists.append("ttbar_pt_withAsymJetsCut");
82     # hists.append("ttbar_pt_2ndSolution_withAsymJetsCut");
83     # hists.append("ttbar_pt_3rdSolution_withAsymJetsCut");
84     # hists.append("ttbar_pt_allSolutions_withAsymJetsCut");
85     # hists.append("angleTops");
86     # hists.append("angleTops_withMETCut");
87     # hists.append("angleTops_withMETAndAsymJets");
88     # hists.append("angleTops_withAsymJetsCut");
89     #
90     # hists.append("pt_leadingTop");
91     # hists.append("pt_leadingTop_withMETCut");
92     # hists.append("pt_leadingTop_withMETAndAsymJets");
93     # hists.append("pt_leadingTop_withAsymJetsCut");
94     #
95     # hists.append("pt_NextToLeadingTop");
96     # hists.append("pt_NextToLeadingTop_withMETCut");
97     # hists.append("pt_NextToLeadingTop_withMETAndAsymJets");
98     # hists.append("pt_NextToLeadingTop_withAsymJetsCut");
99     #
100     # hists.append("mLeptonicTop");
101     # hists.append("mHadronicTop");
102     # hists.append("mAllTop");
103     #
104     # hists.append("ttbar_px");
105     # hists.append("ttbar_py");
106     # hists.append("ttbar_pz");
107     #
108     # hists.append("m3");
109     # hists.append("HT");
110     # hists.append("MET");
111     # hists.append("leadingJetMass");
112     # hists.append("mtW");
113     # hists.append("neutrino_pz");
114     suffixes = ["allBtags",
115     "1orMoreBtag",
116     "2orMoreBtags",
117     "3orMoreBtags",'4orMoreBtags' ]
118     hists = [hist + '_' + suffix for hist in hists for suffix in suffixes]
119    
120     jetBinned = ["allJets",
121     "1orMoreJets",
122     "2orMoreJets",
123     "3orMoreJets" , "4orMoreJets"]
124     jetBinnedhists = []
125     # jetBinnedhists.append('diElectronMass')
126     # jetBinnedhists.append("QCDest_CombRelIso")
127     # jetBinnedhists.append("QCDest_CombRelIso_1btag")
128     # jetBinnedhists.append("QCDest_CombRelIso_2btag")
129     # jetBinnedhists.append("QCDest_CombRelIso_controlRegion")
130     # jetBinnedhists.append("QCDest_CombRelIso_controlRegion_1btag")
131     # jetBinnedhists.append("QCDest_CombRelIso_controlRegion_2btag")
132     #
133     # jetBinnedhists.append("QCDest_PFIsolation")
134     # jetBinnedhists.append("QCDest_PFIsolation_WithMETCut")
135     # jetBinnedhists.append("QCDest_PFIsolation_WithMETCutAndAsymJetCuts")
136     # jetBinnedhists.append("QCDest_PFIsolation_WithAsymJetCuts")
137     #
138     # jetBinnedhists.append("QCDest_PFIsolation_1btag")
139     # jetBinnedhists.append("QCDest_PFIsolation_2btag")
140     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion")
141     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion_1btag")
142     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion_2btag")
143     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion2")
144     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion2_WithMETCut")
145     jetBinnedhists.append("QCDest_PFIsolation_controlRegion2_WithMETCutAndAsymJetCuts")
146     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion2_WithAsymJetCuts")
147     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion2_1btag")
148     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion2_2btag")
149    
150     jetBinnedhists = [hist + '_' + suffix for hist in jetBinnedhists for suffix in jetBinned]
151     hists.extend(jetBinnedhists)
152     gcd = gROOT.cd
153    
154     for histname in hists:
155     currentSelection = 'default'
156     if 'withMETAndAsymJets' in histname:
157     currentSelection = 'withMETAndAsymJets'
158     gcd()
159     print histname
160     hist_data = data.Get(histname);
161    
162     # hist_data2;
163     # if (histname == "mttbar_rebinned")
164     # hist_data2 = data2.Get(histname);
165     # else
166     # hist_data2 = TH1F(*hist_data);
167     # hist_data.Sumw2();
168     # hist_data2.Sumw2();
169     hist_ttbar = ttbar.Get(histname);
170     hist_wjets = wjets.Get(histname);
171     hist_zjets = zjets.Get(histname);
172    
173     hist_bce1 = bce1.Get(histname);
174     hist_bce2 = bce2.Get(histname);
175     hist_bce3 = bce3.Get(histname);
176     hist_enri1 = enri1.Get(histname);
177     hist_enri2 = enri2.Get(histname);
178     hist_enri3 = enri3.Get(histname);
179     hist_pj1 = pj1.Get(histname);
180     hist_pj2 = pj2.Get(histname);
181     hist_pj3 = pj3.Get(histname);
182     hist_singleTop = tW.Get(histname)
183     hist_singleTop.Add(tchan.Get(histname))
184    
185     # hist_Zprime500 = Zprime500.Get(histname);
186     # hist_Zprime750 = Zprime750.Get(histname);
187     # hist_Zprime1000 = Zprime1000.Get(histname);
188     # hist_Zprime1250 = Zprime1250.Get(histname);
189     # hist_Zprime1500 = Zprime1500.Get(histname);
190    
191     hist_ttbar.Scale(scale);
192     hist_wjets.Scale(scale);
193     hist_zjets.Scale(scale);
194    
195     hist_bce1.Scale(scale);
196     hist_bce2.Scale(scale);
197     hist_bce3.Scale(scale);
198    
199     hist_enri1.Scale(scale);
200     hist_enri2.Scale(scale);
201     hist_enri3.Scale(scale);
202    
203     hist_pj1.Scale(scale);
204     hist_pj2.Scale(scale);
205     hist_pj3.Scale(scale);
206    
207     # hist_Zprime500.Scale(scale);
208     # hist_Zprime750.Scale(scale);
209     # hist_Zprime1000.Scale(scale);
210     # hist_Zprime1250.Scale(scale);
211     # hist_Zprime1500.Scale(scale);
212    
213     hist_qcd = hist_bce1.Clone("qcd")#TH1F(*hist_bce1);
214     hist_qcd.Add(hist_bce2);
215     hist_qcd.Add(hist_bce3);
216     hist_qcd.Add(hist_enri1);
217     hist_qcd.Add(hist_enri2);
218     hist_qcd.Add(hist_enri3);
219     hist_qcd.Add(hist_pj1);
220     hist_qcd.Add(hist_pj2);
221     hist_qcd.Add(hist_pj3);
222     hist_qcd.Scale(qcdScale[currentSelection]);
223     # ndata = hist_data.Integral();
224     # ntop = hist_ttbar.Integral();
225     # nwj = hist_wjets.Integral();
226     # nzj = hist_zjets.Integral();
227     nqcd = hist_qcd.Integral();
228     # sumMC = ntop + nwj + nzj + nqcd;
229     # cout << ndata << " " << sumMC << endl;
230     # hist_wjets.Scale(ndata / sumMC);
231     # hist_ttbar.Scale(ndata / sumMC);
232     # hist_zjets.Scale(ndata / sumMC);
233     # hist_qcd.Scale(ndata / sumMC);
234     mttbars = ['mttbar_' + suffix for suffix in suffixes]
235     mttbars2 = ['mttbar_withMETAndAsymJets_' + suffix for suffix in suffixes]
236     if histname in mttbars or histname in mttbars2:
237     print "taking QCD shape from DATA"
238     name = histname.replace('mttbar', 'mttbar_conversions')
239     hist_qcd = data.Get(name)
240     if( hist_qcd.Integral() > 0):
241     hist_qcd.Scale(nqcd/hist_qcd.Integral())
242     hist_mc = hist_qcd.Clone("all_mc")
243     hist_mc.Add(hist_ttbar);
244     hist_mc.Add(hist_zjets);
245     hist_mc.Add(hist_wjets);
246     hist_mc.Add(hist_singleTop);
247    
248     rebin = 1;
249     Urange = (0,5000)
250     if ("mttbar" in histname):
251     hist_data.SetXTitle("m(t#bar{t})/GeV");
252     hist_data.SetYTitle("Events/(50 GeV)");
253     rebin = 50;
254     Urange = (300, 1800)
255     elif ("m3" in histname):
256     hist_data.SetXTitle("M3/GeV");
257     hist_data.SetYTitle("Events/(50 GeV)");
258     rebin = 50;
259     Urange = (0, 1500)
260     elif (histname == "electron_et"):
261     hist_data.SetXTitle("electron p_{T}/GeV");
262     hist_data.SetYTitle("Events/(5 GeV)");
263     rebin = 5;
264     elif ("ttbar_pt" in histname):
265     hist_data.SetXTitle("p_{T} of t#bar{t} system/GeV");
266     hist_data.SetYTitle("Events/(10 GeV)");
267     rebin = 10;
268     Urange = (0, 500)
269     elif ("ttbar_px" in histname):
270     hist_data.SetXTitle("p_{x} of t#bar{t} system/GeV");
271     hist_data.SetYTitle("Events/(10 GeV)");
272     rebin = 10;
273     Urange = (0, 500)
274     elif ("ttbar_py" in histname):
275     hist_data.SetXTitle("p_{y} of t#bar{t} system/GeV");
276     hist_data.SetYTitle("Events/(10 GeV)");
277     rebin = 10;
278     Urange = (0, 500)
279     elif ("ttbar_pz" in histname):
280     hist_data.SetXTitle("p_{z} of t#bar{t} system/GeV");
281     hist_data.SetYTitle("Events/(50 GeV)");
282     rebin = 50;
283     Urange = (0, 2000)
284     elif ("HT" in histname):
285     hist_data.SetXTitle("#Sigma p_{T}/GeV");
286     hist_data.SetYTitle("Events/(50 GeV)");
287     rebin = 50;
288     Urange = (0, 2000)
289     elif (histname == "numberOfJets"):
290     hist_data.SetXTitle("number of jets");
291     hist_data.SetYTitle("Events");
292     elif (histname == "numberOfBJets"):
293     hist_data.SetXTitle("number of b-tagged jets (SSVHE medium)");
294     hist_data.SetYTitle("Events");
295     elif ('MET_' in histname):
296     hist_data.SetXTitle("MET/GeV");
297     hist_data.SetYTitle("Events/(10 GeV)");
298     rebin = 2;
299     Urange = (0, 300)
300     elif ("leadingJetMass" in histname):
301     hist_data.SetXTitle("leading jet mass/GeV");
302     hist_data.SetYTitle("Events/(5 GeV)");
303     rebin = 5;
304     Urange = (0, 150)
305     elif ("mtW" in histname):
306     hist_data.SetXTitle("transverse W-boson mass/GeV");
307     hist_data.SetYTitle("Events/(10 GeV)");
308     rebin = 10;
309     elif ("electronD0" in histname):
310     hist_data.SetXTitle("electron d_{0} / cm");
311     hist_data.SetYTitle("Events/(0.001 cm)");
312     rebin = 10;
313     elif ("angleTops" in histname):
314     hist_data.SetXTitle("angle between top quarks");
315     hist_data.SetYTitle("Events/(0.1 rad)");
316     rebin = 20;
317     elif ("neutrino_pz" in histname):
318     hist_data.SetXTitle("neutrino p_{Z} /GeV");
319     hist_data.SetYTitle("Events/(10 GeV)");
320     rebin = 10;
321     Urange = (-500, 500)
322     elif ('mHadronicTop' in histname or 'mLeptonicTop' in histname or 'mAllTop' in histname):
323     hist_data.SetXTitle("top mass /GeV");
324     hist_data.SetYTitle("Events/(20 GeV)");
325     rebin = 20;
326     elif ('pt_leadingTop' in histname or 'pt_NextToLeadingTop' in histname):
327     hist_data.SetXTitle("top p_{T} /GeV");
328     hist_data.SetYTitle("Events/(20 GeV)");
329     rebin = 20;
330     elif('QCDest_CombRelIso' in histname):
331     hist_data.SetXTitle("relative isolation");
332     hist_data.SetYTitle("Events/(0.1)");
333     rebin = 10;
334     Urange = (0, 2)
335     elif('QCDest_PFIsolation' in histname):
336     hist_data.SetXTitle("Relative isolation");
337     hist_data.SetYTitle("Events/(0.1)");
338     rebin = 10
339     Urange = (0, 2)
340     elif('diElectron' in histname):
341     hist_data.SetXTitle("m(ee)");
342     hist_data.SetYTitle("Events/(1 GeV)");
343     rebin = 5
344     Urange = (0, 200)
345    
346    
347     hist_data.Rebin(rebin);
348     hist_ttbar.Rebin(rebin);
349     hist_wjets.Rebin(rebin);
350     hist_zjets.Rebin(rebin);
351     hist_qcd.Rebin(rebin);
352     hist_singleTop.Rebin(rebin)
353    
354     hist_data.SetAxisRange(Urange[0], Urange[1]);
355     hist_ttbar.SetAxisRange(Urange[0], Urange[1]);
356     hist_wjets.SetAxisRange(Urange[0], Urange[1]);
357     hist_zjets.SetAxisRange(Urange[0], Urange[1]);
358     hist_qcd.SetAxisRange(Urange[0], Urange[1]);
359     hist_singleTop.SetAxisRange(Urange[0], Urange[1]);
360    
361     hist_data.SetMarkerStyle(8);
362    
363     hist_ttbar.SetFillStyle(1001);
364     hist_ttbar.SetFillColor(kRed + 1);
365     hist_wjets.SetFillStyle(1001);
366     hist_wjets.SetFillColor(kGreen - 3);
367     hist_zjets.SetFillStyle(1001);
368     hist_zjets.SetFillColor(kAzure - 2);
369     hist_qcd.SetFillStyle(1001);
370     hist_qcd.SetFillColor(kYellow);
371     hist_singleTop.SetFillStyle(1001);
372     hist_singleTop.SetFillColor(kMagenta)
373    
374     # hist_Zprime500.SetLineColor(kTeal - 9);
375     # hist_Zprime500.SetFillStyle(0);
376     # hist_Zprime500.SetFillColor(kWhite);
377     #
378     # hist_Zprime750.SetLineColor(kBlue - 6);
379     # hist_Zprime750.SetFillStyle(0);
380     # hist_Zprime750.SetFillColor(kWhite);
381     #
382     # hist_Zprime1000.SetLineColor(28);
383     # hist_Zprime1000.SetFillStyle(0);
384     # hist_Zprime1000.SetFillColor(kWhite);
385     #
386     # hist_Zprime1250.SetLineColor(kCyan - 5);
387     # hist_Zprime1250.SetFillStyle(0);
388     # hist_Zprime1250.SetFillColor(kWhite);
389     #
390     # hist_Zprime1500.SetLineColor(kOrange + 1);
391     # hist_Zprime1500.SetFillStyle(0);
392     # hist_Zprime1500.SetFillColor(kWhite);
393    
394     # qcdUncert.SetFillColor(kGray + 3);
395     # qcdUncert.SetFillStyle(3003);
396    
397     leg = TLegend(0.696, 0.35, 0.94, 0.92);
398     leg.SetBorderSize(0);
399     leg.SetLineStyle(0);
400     leg.SetTextFont(42);
401     leg.SetFillStyle(0);
402    
403     leg.AddEntry(hist_data, "data", "P");
404     # leg.AddEntry(hist_data2, "data(no HLT)", "P");
405     leg.AddEntry(hist_ttbar, "t#bar{t}", "f");
406     leg.AddEntry(hist_wjets, "W#rightarrowl#nu", "f");
407     leg.AddEntry(hist_zjets, "Z/#gamma*#rightarrowl^{+}l^{-}", "f");
408     leg.AddEntry(hist_qcd, "QCD/#gamma + jets");
409     leg.AddEntry(hist_singleTop, "Single-Top")
410     # leg.AddEntry(hist_Zprime500, "Z' 0.5TeV (50pb)");
411     # leg.AddEntry(hist_Zprime750, "Z' 0.75TeV (50pb)");
412     # leg.AddEntry(hist_Zprime1000, "Z' 1TeV (50pb)");
413     # leg.AddEntry(hist_Zprime1250, "Z' 1.25TeV (50pb)");
414     # leg.AddEntry(hist_Zprime1500, "Z' 1.5TeV (50pb)");
415    
416    
417     canvases.append(TCanvas("cname" + histname, histname, 1200, 900))
418     canvases[-1].cd().SetRightMargin(0.04);
419     hs = THStack("MC", "MC");
420     hs.Add(hist_qcd);
421     hs.Add(hist_zjets);
422     hs.Add(hist_wjets);
423     hs.Add(hist_singleTop);
424     hs.Add(hist_ttbar);
425     max = 0
426     if hs.GetMaximum() > hist_data.GetMaximum():
427     max = hs.GetMaximum()*1.4
428     else:
429     max = hist_data.GetMaximum()*1.4
430    
431     hist_data.GetYaxis().SetRangeUser(0, max);
432     hist_data.Draw('error');
433     hs.Draw("hist same");
434     # hist_Zprime500.Draw("same");
435     # hist_Zprime750.Draw("same");
436     # hist_Zprime1000.Draw("same");
437     # hist_Zprime1250.Draw("same");
438     # hist_Zprime1500.Draw("same");
439     # qcdUncert.Draw("1 same");
440     # hist_data2.Draw("error same");
441     hist_data.Draw("error same");
442     leg.Draw();
443     text1 = add_cms_label(lumi, '4orMoreJets')
444     # text1 = TLatex(3.570061, 23.08044, "CMS Preliminary");
445     # text1.SetNDC();
446     # text1.SetTextAlign(13);
447     # text1.SetX(0.38);
448     # text1.SetY(0.928);
449     # #text1.SetLineWidth(2);
450     # text1.SetTextFont(42);
451     # text1.SetTextSizePixels(24);# dflt=28
452     text1.Draw();
453     #
454     # text2 = TLatex(3.570061, 23.08044, "~%.1f pb^{-1} at #sqrt{s} = 7 TeV" % lumi);
455     # text2.SetNDC();
456     # text2.SetTextAlign(13);
457     # text2.SetX(0.38);
458     # text2.SetY(0.88);
459     # #text2.SetLineWidth(2);
460     # text2.SetTextFont(42);
461     # text2.SetTextSizePixels(24);# dflt=28
462     # text2.Draw();
463     canvases[-1].SaveAs('/storage/results/' + histname + '.png')
464    
465     cu_hist_data = getCumulativePlot(hist_data, "data");
466     cu_hist_ttbar = getCumulativePlot(hist_ttbar, "ttbar");
467     cu_hist_wjets = getCumulativePlot(hist_wjets, "wjets");
468     cu_hist_zjets = getCumulativePlot(hist_zjets, "zjets");
469     cu_hist_qcd = getCumulativePlot(hist_qcd, "qcd");
470     cu_hist_singleTop = getCumulativePlot(hist_singleTop, "singleTop");
471     ## cu_hist_Zprime500 = getCumulativePlot(hist_Zprime500, "Zprime500");
472     ## cu_hist_Zprime750 = getCumulativePlot(hist_Zprime750, "Zprime750");
473     ## cu_hist_Zprime1000 = getCumulativePlot(hist_Zprime1000, "Zprime1000");
474     ## cu_hist_Zprime1250 = getCumulativePlot(hist_Zprime1250, "Zprime1250");
475     ## cu_hist_Zprime1500 = getCumulativePlot(hist_Zprime1500, "Zprime1500");
476     cu_hist_data.SetYTitle("Integrated Events/(50 GeV)");
477     ##
478     #
479     cu_hist_data.SetAxisRange(Urange[0], Urange[1]);
480     cu_hist_ttbar.SetAxisRange(Urange[0], Urange[1]);
481     cu_hist_wjets.SetAxisRange(Urange[0], Urange[1]);
482     cu_hist_zjets.SetAxisRange(Urange[0], Urange[1]);
483     cu_hist_qcd.SetAxisRange(Urange[0], Urange[1]);
484     cu_hist_singleTop.SetAxisRange(Urange[0], Urange[1]);
485    
486     cu_hs = THStack("cu_MC", "cu_MC");
487     cu_hs.Add(cu_hist_qcd);
488     cu_hs.Add(cu_hist_zjets);
489     cu_hs.Add(cu_hist_wjets);
490     cu_hs.Add(cu_hist_ttbar);
491    
492     scanvases.append(TCanvas("cu_cname" + histname, histname + "(cu)", 1200, 900))
493     scanvases[-1].cd().SetRightMargin(0.04);
494     cu_hist_data.Draw("error");
495     cu_hs.Draw("hist same");
496     ### cu_hist_Zprime500.Draw("same");
497     ### cu_hist_Zprime750.Draw("same");
498     ### cu_hist_Zprime1000.Draw("same");
499     ### cu_hist_Zprime1250.Draw("same");
500     ### cu_hist_Zprime1500.Draw("same");
501     ## # cu_hist_data2.Draw("error same");
502     cu_hist_data.Draw("error same");
503     leg.Draw();
504     ##
505     text1.Draw();
506     ##
507     # text2.Draw();
508     scanvases[-1].SaveAs('/storage/results/' + histname + '_integrated.png')
509    
510    
511    
512     # tdrGrid: Turns the grid lines on (true) or off (false)
513    
514     #def tdrGrid(bool gridOn):
515     # tdrStyle.SetPadGridX(gridOn);
516     # tdrStyle.SetPadGridY(gridOn);
517     #
518    
519     # fixOverlay: Redraws the axis
520    
521     def fixOverlay():
522     gPad.RedrawAxis();
523    
524    
525     def getCumulativePlot(initial, type):
526     name = initial.GetName()
527     name = "cu_" + name + "_" + type;
528     title = initial.GetTitle()
529     title = "cu_" + title + "_" + type;
530     xaxis = initial.GetXaxis().GetTitle();
531     yaxis = initial.GetYaxis().GetTitle();
532     nBins = initial.GetNbinsX();
533     cu = TH1F(name, title, nBins, initial.GetXaxis().GetXmin(), initial.GetXaxis().GetXmax());
534     for bin in range(1,nBins+1):
535     cu.SetBinContent(bin, initial.Integral(bin, nBins));
536    
537     cu.SetFillStyle(initial.GetFillStyle());
538     cu.SetFillColor(initial.GetFillColor());
539     cu.SetLineColor(initial.GetLineColor());
540     cu.SetMarkerSize(initial.GetMarkerSize());
541     cu.SetMarkerStyle(initial.GetMarkerStyle());
542     cu.SetMarkerColor(initial.GetMarkerColor());
543     cu.SetLineWidth(initial.GetLineWidth());
544     cu.GetXaxis().SetTitle(xaxis);
545     cu.GetYaxis().SetTitle(yaxis);
546     return cu;
547    
548     def add_cms_label( lumi, njet = "" ):
549     jetBinsLatex = {'0jet':'0 jet', 'allJets':'#geq 0 jets', '1jet':'1 jet', '1orMoreJets':'#geq 1 jet',
550     '2jets':'2 jets', '2orMoreJets':'#geq 2 jets', '3jets':'3 jets', '3orMoreJets':'#geq 3 jets',
551     '4orMoreJets':'#geq 4 jets'}
552    
553     mytext = TPaveText( 0.3, 0.8, 0.6, 0.93, "NDC" );
554     mytext.AddText( "CMS Preliminary" );
555     mytext.AddText( "%.1f pb^{-1} at #sqrt{s} = 7 TeV" % lumi );
556     if njet != "":
557     mytext.AddText( "e+jets, %s" % jetBinsLatex[njet] )
558    
559     mytext.SetFillStyle( 0 );
560     mytext.SetBorderSize( 0 );
561     mytext.SetTextFont( 42 );
562     mytext.SetTextAlign( 13 );
563     return mytext
564    
565     if __name__ == "__main__":
566     gROOT.SetBatch(True)
567     gROOT.ProcessLine('gErrorIgnoreLevel = 1001;')
568     plotMttbar()
569     # print "press enter to quit"
570     # a = raw_input()