ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/dhidas/OSUAnalysis/Tools/scripts/plotToplike.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

# User Rev Content
1 dhidas 1.1 # A version of plotMttbar.py that has code for plotting the top-like histograms. This file probably requires
2     # modification before use.
3    
4     from __future__ import division
5    
6     from tdrStyle import *
7     from ROOT import *
8    
9     canvases = []
10     scanvases = []
11     counter = 0
12    
13     def plotMttbar():
14     tdrstyle = setTDRStyle();
15     gStyle.SetHatchesSpacing(1.0);
16     # lumi = 36.135;#3.06 + 1.37 + 2.53 + 0.26;
17     lumi = 203.8;
18     oldLumi = 203.8;
19     # oldLumi = 36.135;
20     scale = lumi / oldLumi;
21     qcdScale = {'default':1.72, 'withMETAndAsymJets': 3.03};
22     # data = TFile.Open("data2.9pb_fullSetOfVars.root");
23     #data = TFile.Open("Run2010_35pb_PFElectron_PF2PATJets_PFMET.root");
24     data = TFile.Open("Run_203.8pb_PFElectron_PF2PATJets_PFMET.root");
25     ttbar = TFile.Open("TT_Tune_203.8pb_PFElectron_PF2PATJets_PFMET.root");
26     WprimeTToTTD_M1000 = TFile.Open("WprimeTToTTD_M1000_203.8pb_PFElectron_PF2PATJets_PFMET.root");
27     WprimeTToTTD_M600 = TFile.Open("WprimeTToTTD_M600_203.8pb_PFElectron_PF2PATJets_PFMET.root");
28     # ttbar = TFile.Open("TTJets_36.145pb_PFElectron_PF2PATJets_PFMET.root");
29     # wjets = TFile.Open("WJets_35pb_PFElectron_PF2PATJets_PFMET.root");
30     # zjets = TFile.Open("DYJets_35pb_PFElectron_PF2PATJets_PFMET.root");
31     # bce1 = TFile.Open("QCD_Pt-20to30_BCtoE_35pb_PFElectron_PF2PATJets_PFMET.root");
32     # bce2 = TFile.Open("QCD_Pt-30to80_BCtoE_35pb_PFElectron_PF2PATJets_PFMET.root");
33     # bce3 = TFile.Open("QCD_Pt-80to170_BCtoE_35pb_PFElectron_PF2PATJets_PFMET.root");
34     # enri1 = TFile.Open("QCD_Pt-20to30_EMEnriched_35pb_PFElectron_PF2PATJets_PFMET.root");
35     # enri2 = TFile.Open("QCD_Pt-30to80_EMEnriched_35pb_PFElectron_PF2PATJets_PFMET.root");
36     # enri3 = TFile.Open("QCD_Pt-80to170_EMEnriched_35pb_PFElectron_PF2PATJets_PFMET.root");
37     # zjets = TFile.Open("DYJets_35pb_PFElectron_PF2PATJets_PFMET.root");
38     # pj1 = TFile.Open("pj1_36.145pb_PFElectron_PF2PATJets_PFMET.root");
39     # pj2 = TFile.Open("pj2_36.145pb_PFElectron_PF2PATJets_PFMET.root");
40     # pj3 = TFile.Open("pj3_36.145pb_PFElectron_PF2PATJets_PFMET.root");
41     # tW = TFile.Open("tW_36.145pb_PFElectron_PF2PATJets_PFMET.root");
42     # tchan = TFile.Open("tchan_36.145pb_PFElectron_PF2PATJets_PFMET.root");
43     # vqq = TFile.Open("vqq_7.22pb_V4PFCalo.root__fullSetOfVars.root");
44     # Zprime500 = TFile.Open("/storage/workspace/BristolAnalysisTools/outputfiles/Zprime_M500GeV_W5GeV_36.135pb.root");
45     # Zprime750 = TFile.Open("/storage/workspace/BristolAnalysisTools/outputfiles/Zprime_M750GeV_W7500MeV_36.135pb.root");
46     # Zprime1000 = TFile.Open("/storage/workspace/BristolAnalysisTools/outputfiles/Zprime_M1TeV_W10GeV_36.135pb.root");
47     # Zprime1250 = TFile.Open("/storage/workspace/BristolAnalysisTools/outputfiles/Zprime_M1250GeV_W12500MeV_36.135pb.root");
48     # Zprime1500 = TFile.Open("/storage/workspace/BristolAnalysisTools/outputfiles/Zprime_M1500GeV_W15GeV_36.135pb.root");
49    
50     hists = [];
51     # hists.append('mttbar_QCDEnriched')
52     # hists.append('mttbar_conversions')
53     # hists.append('mttbar_conversions_withMETCut')
54     # hists.append('mttbar_conversions_withMETAndAsymJets')
55     # hists.append('mttbar_conversions_withAsymJetsCut')
56    
57     hists.append("mttbar");
58     # hists.append("tPrimeMass");
59     # hists.append("tPrimepT");
60     # hists.append("tPrimeHT");
61     # hists.append("tPrime_pt");
62     # hists.append("tPrime_px");
63     # hists.append("tPrime_py");
64     # hists.append("tPrime_pz");
65     # hists.append("mLeptonicTopLone");
66     # hists.append("mHadronicTopLone");
67     # hists.append("mLepTopLoneNM");
68     # hists.append("mHadTopLoneNM");
69     # # hists.append("chiHadronicTop");
70     # hists.append("chiLeptonicTop");
71     # hists.append("chiGlobal");
72     # hists.append("chiTotal");
73     # hists.append("lepTopDeltaR");
74     # hists.append("hadTopDeltaR");
75     # hists.append("lepTopDeltaRNM");
76     # hists.append("hadTopDeltaRNM");
77     # hists.append("lepTopLep");
78     # hists.append("hadTopHad");
79     # hists.append("numHadTopMCMatches");
80     # hists.append("numLepTopMCMatches");
81     # hists.append("numHadTopCorrectID");
82     # hists.append("numLepTopCorrectID");
83     # hists.append("numHadTopMCMatchesNM");
84     # hists.append("numLepTopMCMatchesNM");
85     # hists.append("numHadTopCorrectIDNM");
86     # hists.append("numLepTopCorrectIDNM");
87     # hists.append("mttbar_2ndSolution");
88     # hists.append("mttbar_3rdSolution");
89     # hists.append("mttbar_allSolutions");
90     ##
91     # hists.append("mttbar_withMETCut");
92     # hists.append("mttbar_2ndSolution_withMETCut");
93     # hists.append("mttbar_3rdSolution_withMETCut");
94     # hists.append("mttbar_allSolutions_withMETCut");
95     #
96     # hists.append("mttbar_withMETAndAsymJets");
97     # hists.append("mttbar_2ndSolution_withMETAndAsymJets");
98     # hists.append("mttbar_3rdSolution_withMETAndAsymJets");
99     # hists.append("mttbar_allSolutions_withMETAndAsymJets");
100     #
101     # hists.append("mttbar_withAsymJetsCut");
102     # hists.append("mttbar_2ndSolution_withAsymJetsCut");
103     # hists.append("mttbar_3rdSolution_withAsymJetsCut");
104     # hists.append("mttbar_allSolutions_withAsymJetsCut");
105     #
106     # hists.append("ttbar_pt");
107     # hists.append("ttbar_pt_2ndSolution");
108     # hists.append("ttbar_pt_3rdSolution");
109     # hists.append("ttbar_pt_allSolutions");
110     #
111     # hists.append("ttbar_pt_withMETCut");
112     # hists.append("ttbar_pt_2ndSolution_withMETCut");
113     # hists.append("ttbar_pt_3rdSolution_withMETCut");
114     # hists.append("ttbar_pt_allSolutions_withMETCut");
115     #
116     # hists.append("ttbar_pt_withMETAndAsymJets");
117     # hists.append("ttbar_pt_2ndSolution_withMETAndAsymJets");
118     # hists.append("ttbar_pt_3rdSolution_withMETAndAsymJets");
119     # hists.append("ttbar_pt_allSolutions_withMETAndAsymJets");
120     #
121     # hists.append("ttbar_pt_withAsymJetsCut");
122     # hists.append("ttbar_pt_2ndSolution_withAsymJetsCut");
123     # hists.append("ttbar_pt_3rdSolution_withAsymJetsCut");
124     # # hists.append("ttbar_pt_allSolutions_withAsymJetsCut");
125     # hists.append("angleTops");
126     # hists.append("angleTops_withMETCut");
127     # hists.append("angleTops_withMETAndAsymJets");
128     # hists.append("angleTops_withAsymJetsCut");
129     #
130     hists.append("pt_leadingTop");
131     # hists.append("pt_leadingTop_withMETCut");
132     # hists.append("pt_leadingTop_withMETAndAsymJets");
133     # hists.append("pt_leadingTop_withAsymJetsCut");
134     #
135     hists.append("pt_NextToLeadingTop");
136     # hists.append("pt_NextToLeadingTop_withMETCut");
137     # hists.append("pt_NextToLeadingTop_withMETAndAsymJets");
138     # hists.append("pt_NextToLeadingTop_withAsymJetsCut");
139     #
140     hists.append("mLeptonicTop");
141     hists.append("mHadronicTop");
142     hists.append("mAllTop");
143     #
144     # hists.append("ttbar_px");
145     # hists.append("ttbar_py");
146     # hists.append("ttbar_pz");
147     #
148     # hists.append("m3");
149     # hists.append("HT");
150     # hists.append("MET");
151     # hists.append("leadingJetMass");
152     # hists.append("mtW");
153     # hists.append("neutrino_pz");
154     # suffixes = ["allBtags",
155     suffixes = ["0orMoreBtag",
156     "1orMoreBtag",
157     "2orMoreBtags",
158     "3orMoreBtags",'4orMoreBtags' ]
159     hists = [hist + '_' + suffix for hist in hists for suffix in suffixes]
160    
161     # jetBinned = ["allJets",
162     # "1orMoreJets",
163     # "2orMoreJets",
164     # "3orMoreJets" , "4orMoreJets"]
165     # jetBinnedhists = []
166     # jetBinnedhists.append("QCDest_CombRelIso")
167     # jetBinnedhists.append("QCDest_CombRelIso_1btag")
168     # jetBinnedhists.append("QCDest_CombRelIso_2btag")
169     # jetBinnedhists.append("QCDest_CombRelIso_controlRegion")
170     # jetBinnedhists.append("QCDest_CombRelIso_controlRegion_1btag")
171     # jetBinnedhists.append("QCDest_CombRelIso_controlRegion_2btag")
172     #
173     # jetBinnedhists.append("QCDest_PFIsolation")
174     # jetBinnedhists.append("QCDest_PFIsolation_WithMETCut")
175     # jetBinnedhists.append("QCDest_PFIsolation_WithMETCutAndAsymJetCuts")
176     # jetBinnedhists.append("QCDest_PFIsolation_WithAsymJetCuts")
177    
178     # jetBinnedhists.append("QCDest_PFIsolation_1btag")
179     # jetBinnedhists.append("QCDest_PFIsolation_2btag")
180     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion")
181     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion_1btag")
182     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion_2btag")
183     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion2")
184     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion2_WithMETCut")
185     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion2_WithMETCutAndAsymJetCuts")
186     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion2_WithAsymJetCuts")
187     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion2_1btag")
188     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion2_2btag")
189    
190     # jetBinnedhists = [hist + '_' + suffix for hist in jetBinnedhists for suffix in jetBinned]
191     # hists.extend(jetBinnedhists)
192     gcd = gROOT.cd
193    
194     for histname in hists:
195     currentSelection = 'default'
196     if 'withMETAndAsymJets' in histname:
197     currentSelection = 'withMETAndAsymJets'
198     gcd()
199     print histname
200     hist_data = data.Get(histname);
201    
202     # hist_data2;
203     # if (histname == "mttbar_rebinned")
204     # hist_data2 = data2.Get(histname);
205     # else
206     # hist_data2 = TH1F(*hist_data);
207     # hist_data.Sumw2();
208     # hist_data2.Sumw2();
209     hist_ttbar = ttbar.Get(histname);
210     hist_wpm1000 = WprimeTToTTD_M1000.Get(histname);
211     hist_wpm600 = WprimeTToTTD_M600.Get(histname);
212     # hist_wjets = wjets.Get(histname);
213     # hist_zjets = zjets.Get(histname);
214    
215     # hist_bce1 = bce1.Get(histname);
216     # hist_bce2 = bce2.Get(histname);
217     # # hist_bce3 = bce3.Get(histname);
218     # hist_enri1 = enri1.Get(histname);
219     # hist_enri2 = enri2.Get(histname);
220     # hist_enri3 = enri3.Get(histname);
221     # hist_pj1 = pj1.Get(histname);
222     # hist_pj2 = pj2.Get(histname);
223     # hist_pj3 = pj3.Get(histname);
224     # hist_singleTop = tW.Get(histname)
225     # hist_singleTop.Add(tchan.Get(histname))
226    
227     # hist_Zprime500 = Zprime500.Get(histname);
228     # hist_Zprime750 = Zprime750.Get(histname);
229     # hist_Zprime1000 = Zprime1000.Get(histname);
230     # hist_Zprime1250 = Zprime1250.Get(histname);
231     # hist_Zprime1500 = Zprime1500.Get(histname);
232    
233     hist_ttbar.Scale(scale);
234     hist_wpm1000.Scale(scale);
235     hist_wpm600.Scale(scale);
236     # hist_wjets.Scale(scale);
237     # hist_zjets.Scale(scale);
238    
239     # hist_bce1.Scale(scale);
240     # hist_bce2.Scale(scale);
241     # hist_bce3.Scale(scale);
242    
243     # hist_enri1.Scale(scale);
244     # hist_enri2.Scale(scale);
245     # hist_enri3.Scale(scale);
246    
247     # hist_pj1.Scale(scale);
248     # hist_pj2.Scale(scale);
249     # hist_pj3.Scale(scale);
250    
251     # hist_Zprime500.Scale(scale);
252     # hist_Zprime750.Scale(scale);
253     # hist_Zprime1000.Scale(scale);
254     # hist_Zprime1250.Scale(scale);
255     # hist_Zprime1500.Scale(scale);
256    
257     # hist_qcd = hist_bce1.Clone("qcd")#TH1F(*hist_bce1);
258     # hist_qcd.Add(hist_bce2);
259     # hist_qcd.Add(hist_bce3);
260     # hist_qcd.Add(hist_enri1);
261     # hist_qcd.Add(hist_enri2);
262     # hist_qcd.Add(hist_enri3);
263     # hist_qcd.Add(hist_pj1);
264     # hist_qcd.Add(hist_pj2);
265     # hist_qcd.Add(hist_pj3);
266     # hist_qcd.Scale(qcdScale[currentSelection]);
267     # ndata = hist_data.Integral();
268     # ntop = hist_ttbar.Integral();
269     # nwj = hist_wjets.Integral();
270     # nzj = hist_zjets.Integral();
271     # nqcd = hist_qcd.Integral();
272     # sumMC = ntop + nwj + nzj + nqcd;
273     # cout << ndata << " " << sumMC << endl;
274     # hist_wjets.Scale(ndata / sumMC);
275     # hist_ttbar.Scale(ndata / sumMC);
276     # hist_zjets.Scale(ndata / sumMC);
277     # hist_qcd.Scale(ndata / sumMC);
278     # mttbars = ['mttbar_' + suffix for suffix in suffixes]
279     # mttbars2 = ['mttbar_withMETAndAsymJets_' + suffix for suffix in suffixes]
280     # if histname in mttbars or histname in mttbars2:
281     # print "taking QCD shape from DATA"
282     # name = histname.replace('mttbar', 'mttbar_conversions')
283     # hist_qcd = data.Get(name)
284     # if( hist_qcd.Integral() > 0):
285     # hist_qcd.Scale(nqcd/hist_qcd.Integral())
286     # hist_mc = hist_qcd.Clone("all_mc")
287     # hist_mc = hist_ttbar.Clone("all_mc")
288     # hist_mc.Add(hist_ttbar);
289     # hist_mc.Add(hist_zjets);
290     # hist_mc.Add(hist_wjets);
291     # hist_mc.Add(hist_singleTop);
292    
293     rebin = 1;
294     Urange = (0,5000)
295     Yrange = (0,0)
296     if ("mttbar" in histname):
297     hist_data.SetXTitle("M_{t#bar{t}}/GeV");
298     hist_data.SetYTitle("Events/(100 GeV)");
299     rebin = 100;
300     Urange = (0, 2200)
301     elif ("tPrimeMass" in histname):
302     hist_data.SetXTitle("T' mass/GeV");
303     hist_data.SetYTitle("Events/(100 GeV)");
304     rebin = 10;
305     Urange = (0, 2000)
306     elif ("tPrimepT" in histname):
307     hist_data.SetXTitle("T' pT/GeV");
308     hist_data.SetYTitle("Events/(8 GeV)");
309     rebin = 5;
310     Urange = (0, 200)
311     elif ("tPrimeHT" in histname):
312     hist_data.SetXTitle("T' HT");
313     hist_data.SetYTitle("Events");
314     rebin = 5;
315     Urange = (0, 1.5)
316     elif ("m3" in histname):
317     hist_data.SetXTitle("M3/GeV");
318     hist_data.SetYTitle("Events/(50 GeV)");
319     rebin = 50;
320     Urange = (0, 1500)
321     elif (histname == "electron_et"):
322     hist_data.SetXTitle("electron p_{T}/GeV");
323     hist_data.SetYTitle("Events/(5 GeV)");
324     rebin = 5;
325     elif ("ttbar_pt" in histname):
326     hist_data.SetXTitle("p_{T} of t#bar{t} system/GeV");
327     hist_data.SetYTitle("Events/(10 GeV)");
328     rebin = 10;
329     Urange = (0, 500)
330     elif ("ttbar_px" in histname):
331     hist_data.SetXTitle("p_{x} of t#bar{t} system/GeV");
332     hist_data.SetYTitle("Events/(10 GeV)");
333     rebin = 10;
334     Urange = (0, 500)
335     elif ("ttbar_py" in histname):
336     hist_data.SetXTitle("p_{y} of t#bar{t} system/GeV");
337     hist_data.SetYTitle("Events/(10 GeV)");
338     rebin = 10;
339     Urange = (0, 500)
340     elif ("ttbar_pz" in histname):
341     hist_data.SetXTitle("p_{z} of t#bar{t} system/GeV");
342     hist_data.SetYTitle("Events/(50 GeV)");
343     rebin = 50;
344     Urange = (0, 2000)
345     elif ("tPrime_pt" in histname):
346     hist_data.SetXTitle("p_{T} of T' system/GeV");
347     hist_data.SetYTitle("Events/(20 GeV)");
348     rebin = 20;
349     Urange = (0, 200)
350     elif ("tPrime_px" in histname):
351     hist_data.SetXTitle("p_{x} of T' system/GeV");
352     hist_data.SetYTitle("Events/(20 GeV)");
353     rebin = 20;
354     Urange = (0, 200)
355     elif ("tPrime_py" in histname):
356     hist_data.SetXTitle("p_{y} of T' system/GeV");
357     hist_data.SetYTitle("Events/(20 GeV)");
358     rebin = 20;
359     Urange = (0, 200)
360     elif ("tPrime_pz" in histname):
361     hist_data.SetXTitle("p_{z} of T' system/GeV");
362     hist_data.SetYTitle("Events/(100 GeV)");
363     rebin = 20;
364     Urange = (0, 1800)
365     elif ("HT" in histname):
366     hist_data.SetXTitle("#Sigma p_{T}/GeV");
367     hist_data.SetYTitle("Events/(50 GeV)");
368     rebin = 50;
369     Urange = (0, 2000)
370     elif (histname == "numberOfJets"):
371     hist_data.SetXTitle("number of jets");
372     hist_data.SetYTitle("Events");
373     elif (histname == "numberOfBJets"):
374     hist_data.SetXTitle("number of b-tagged jets (SSVHE medium)");
375     hist_data.SetYTitle("Events");
376     elif ('MET_' in histname):
377     hist_data.SetXTitle("MET/GeV");
378     hist_data.SetYTitle("Events/(10 GeV)");
379     rebin = 2;
380     Urange = (0, 500)
381     elif ("leadingJetMass" in histname):
382     hist_data.SetXTitle("leading jet mass/GeV");
383     hist_data.SetYTitle("Events/(5 GeV)");
384     rebin = 5;
385     Urange = (0, 150)
386     elif ("mtW" in histname):
387     hist_data.SetXTitle("transverse W-boson mass/GeV");
388     hist_data.SetYTitle("Events/(10 GeV)");
389     rebin = 10;
390     elif ("electronD0" in histname):
391     hist_data.SetXTitle("electron d_{0} / cm");
392     hist_data.SetYTitle("Events/(0.001 cm)");
393     rebin = 10;
394     elif ("angleTops" in histname):
395     hist_data.SetXTitle("angle between top quarks");
396     hist_data.SetYTitle("Events/(0.1 rad)");
397     rebin = 10;
398     elif ("neutrino_pz" in histname):
399     hist_data.SetXTitle("neutrino p_{Z} /GeV");
400     hist_data.SetYTitle("Events/(10 GeV)");
401     rebin = 10;
402     Urange = (-500, 500)
403     elif ('mHadronicTopLone' in histname or 'mHadTopLoneNM' in histname):
404     hist_data.SetXTitle("top mass /GeV");
405     hist_data.SetYTitle("Events/(25 GeV)");
406     rebin = 2;
407     Urange = (0, 400)
408     elif ('mLeptonicTopLone' in histname or 'mLepTopLoneNM' in histname):
409     hist_data.SetXTitle("top mass /GeV");
410     hist_data.SetYTitle("Events/(50 GeV)");
411     rebin = 2;
412     Urange = (0, 450)
413     elif ('chiHadronicTop' in histname or 'chiLeptonicTop' in histname):
414     hist_data.SetXTitle("top #chi^{2} /GeV");
415     hist_data.SetYTitle("Events/(1)");
416     rebin = 1;
417     Urange = (0, 30)
418     elif ('chiGlobal' in histname or 'chiTotal' in histname):
419     hist_data.SetXTitle("Event #chi^{2} /GeV");
420     hist_data.SetYTitle("Events/(100)");
421     rebin = 20;
422     elif ('numHadTopMCMatches' in histname or 'numLepTopMCMatches' in histname or 'numHadTopMCMatchesNM' in histname or 'numLepTopMCMatchesNM' in histname):
423     hist_data.SetXTitle("Number of MC-Truth Matches");
424     hist_data.SetYTitle("Events");
425     Yrange = (0, 150)
426     elif ('numHadTopCorrectID' in histname or 'numLepTopCorrectID' in histname or 'numLepTopCorrectIDNM' in histname or 'numHadTopCorrectIDNM' in histname):
427     hist_data.SetXTitle("Number of Reco Candidates Matched to MC-Truth Particles");
428     hist_data.SetYTitle("Events");
429     Yrange = (0, 150)
430     elif ('lepTopDeltaR' in histname or 'hadTopDeltaR' in histname or 'lepTopDeltaRNM' in histname or 'hadTopDeltaRNM' in histname):
431     hist_data.SetXTitle("#Delta R of MC truth top");
432     hist_data.SetYTitle("Events");
433     rebin = 5;
434     elif ('lepTopLep' in histname or 'hadTopHad' in histname):
435     hist_data.SetXTitle("top MC truth identity");
436     hist_data.SetYTitle("Events");
437     Urange = (0, 2)
438     elif ('mHadronicTop' in histname or 'mLeptonicTop' in histname or 'mAllTop' in histname):
439     hist_data.SetXTitle("top mass /GeV");
440     hist_data.SetYTitle("Events/(50 GeV)");
441     rebin = 50;
442     elif ('pt_leadingTop' in histname or 'pt_NextToLeadingTop' in histname):
443     hist_data.SetXTitle("top p_{T} /GeV");
444     hist_data.SetYTitle("Events/(20 GeV)");
445     rebin = 10;
446     Urange = (0, 700)
447     elif('QCDest_CombRelIso' in histname):
448     hist_data.SetXTitle("relative isolation");
449     hist_data.SetYTitle("Events/(0.1)");
450     rebin = 10;
451     Urange = (0, 2)
452     elif('QCDest_PFIsolation' in histname):
453     hist_data.SetXTitle("ParticleFlow isolation");
454     hist_data.SetYTitle("Events/(0.1)");
455     rebin = 10
456     Urange = (0, 2)
457    
458    
459     hist_data.Rebin(rebin);
460     hist_ttbar.Rebin(rebin);
461     hist_wpm1000.Rebin(rebin);
462     hist_wpm600.Rebin(rebin);
463     # hist_wjets.Rebin(rebin);
464     # hist_zjets.Rebin(rebin);
465     # hist_qcd.Rebin(rebin);
466     # hist_singleTop.Rebin(rebin)
467    
468     hist_data.SetAxisRange(Urange[0], Urange[1]);
469     hist_ttbar.SetAxisRange(Urange[0], Urange[1]);
470     hist_wpm1000.SetAxisRange(Urange[0], Urange[1]);
471     hist_wpm600.SetAxisRange(Urange[0], Urange[1]);
472     # hist_wjets.SetAxisRange(Urange[0], Urange[1]);
473     # hist_zjets.SetAxisRange(Urange[0], Urange[1]);
474     # hist_qcd.SetAxisRange(Urange[0], Urange[1]);
475     # hist_singleTop.SetAxisRange(Urange[0], Urange[1]);
476    
477     # hist_data.SetMarkerStyle(8);
478     # hist_data.SetMarkerSize(2.0);
479     hist_data.SetLineWidth(2);
480    
481     hist_ttbar.SetFillStyle(1001);
482     hist_ttbar.SetFillColor(kRed + 1);
483     # hist_wjets.SetFillStyle(1001);
484     # hist_wjets.SetFillColor(kGreen - 3);
485     # hist_zjets.SetFillStyle(1001);
486     # hist_zjets.SetFillColor(kAzure - 2);
487     # hist_qcd.SetFillStyle(1001);
488     # hist_qcd.SetFillColor(kYellow);
489     # hist_singleTop.SetFillStyle(1001);
490     # hist_singleTop.SetFillColor(kMagenta)
491     # nbins = hist_qcd.GetXaxis().GetNbins();
492     # binwidth = (hist_qcd.GetXaxis().GetXmax() - hist_qcd.GetXaxis().GetXmin()) / nbins;
493     # for i in range(1, nbins + 1):
494     # yvalue = hist_qcd.GetBinContent(i);
495     # # float xvalue = hist_qcd.GetBinCenter(i);
496     # # float ymin = yvalue - yvalue*0.5;
497     # # float ymax = yvalue + yvalue*0.5;
498     # # float xmin = xvalue - 0.5*binwidth;
499     # # float xmax = xvalue + 0.5*binwidth;
500     # error = yvalue * 0.5;
501     # hist_mc.SetBinError(i, error);
502     # # qcdUncert.SetPointError(i, xmin, xmax, ymin, ymax);
503     #
504     # qcdUncert = TGraphAsymmErrors(hist_mc);
505    
506     linewidth = 6;
507     hist_wpm1000.SetLineColor(kOrange + 1);
508     hist_wpm1000.SetLineWidth(linewidth);
509     hist_wpm600.SetLineColor(kGray + 3);
510     hist_wpm600.SetLineWidth(linewidth);
511     # hist_Zprime500.SetLineColor(kTeal - 9);
512     # hist_Zprime500.SetLineWidth(3);
513     # hist_Zprime500.SetFillStyle(0);
514     # hist_Zprime500.SetFillColor(kWhite);
515     #
516     # hist_Zprime750.SetLineColor(kBlue - 6);
517     # hist_Zprime750.SetLineWidth(3);
518     # hist_Zprime750.SetFillStyle(0);
519     # hist_Zprime750.SetFillColor(kWhite);
520     #
521     # hist_Zprime1000.SetLineColor(28);
522     # hist_Zprime1000.SetLineWidth(3);
523     # hist_Zprime1000.SetFillStyle(0);
524     # hist_Zprime1000.SetFillColor(kWhite);
525     #
526     # hist_Zprime1250.SetLineColor(kCyan - 5);
527     # hist_Zprime1250.SetLineWidth(3);
528     # hist_Zprime1250.SetFillStyle(0);
529     # hist_Zprime1250.SetFillColor(kWhite);
530     #
531     # hist_Zprime1500.SetLineColor(kOrange + 1);
532     # hist_Zprime1500.SetLineWidth(3);
533     # hist_Zprime1500.SetFillStyle(0);
534     # hist_Zprime1500.SetFillColor(kWhite);
535    
536     # qcdUncert.SetFillColor(kGray + 3);
537     # qcdUncert.SetFillStyle(3003);
538    
539     leg = TLegend(0.75, 0.75, 0.98, 0.98);
540     # leg = TLegend(0.696, 0.35, 0.94, 0.92);
541     leg.SetBorderSize(0);
542     leg.SetLineStyle(0);
543     leg.SetTextFont(42);
544     leg.SetFillStyle(0);
545    
546     # leg.AddEntry(hist_data, "data", "P");
547     leg.AddEntry(hist_data, "data", "L");
548     # leg.AddEntry(hist_data2, "data(no HLT)", "P");
549     leg.AddEntry(hist_ttbar, "t#bar{t}", "f");
550     leg.AddEntry(hist_wpm1000, "W' 1TeV (50 pb)", "L");
551     leg.AddEntry(hist_wpm600, "W' 600GeV (50 pb)", "L");
552     # leg.AddEntry(hist_wjets, "W#rightarrowl#nu", "f");
553     # leg.AddEntry(hist_zjets, "Z/#gamma*#rightarrowl^{+}l^{-}", "f");
554     # leg.AddEntry(hist_qcd, "QCD");
555     # leg.AddEntry(hist_qcd, "QCD/#gamma + jets");
556     # leg.AddEntry(hist_singleTop, "Single-Top")
557     # leg.AddEntry(hist_Zprime500, "Z' 0.5TeV (50pb)");
558     # leg.AddEntry(hist_Zprime750, "Z' 0.75TeV (50pb)");
559     # leg.AddEntry(hist_Zprime1000, "Z' 1TeV (50pb)");
560     # leg.AddEntry(hist_Zprime1250, "Z' 1.25TeV (50pb)");
561     # leg.AddEntry(hist_Zprime1500, "Z' 1.5TeV (50pb)");
562    
563    
564     canvases.append(TCanvas("cname" + histname, histname, 1200, 900))
565     canvases[-1].cd().SetRightMargin(0.04);
566     hs = THStack("MC", "MC");
567     # hs.Add(hist_qcd);
568     # hs.Add(hist_zjets);
569     # hs.Add(hist_wjets);
570     # hs.Add(hist_singleTop);
571     hs.Add(hist_ttbar);
572     max = 0
573     if hs.GetMaximum() > hist_data.GetMaximum():
574     max = hs.GetMaximum()*1.1
575     else:
576     max = hist_data.GetMaximum()*1.1
577    
578     hist_data.GetYaxis().SetRangeUser(0, max);
579     hist_data.SetStats(1);
580     # hist_data.Draw('axis');
581     hist_data.Draw('hist error');
582     hs.Draw("hist same");
583     hist_wpm1000.Draw("same");
584     hist_wpm600.Draw("same");
585     # hist_Zprime500.Draw("same");
586     # hist_Zprime750.Draw("same");
587     # hist_Zprime1000.Draw("same");
588     # hist_Zprime1250.Draw("same");
589     # hist_Zprime1500.Draw("same");
590     # qcdUncert.Draw("1 same");
591     # hist_data2.Draw("error same");
592     hist_data.Draw("hist error same");
593     leg.Draw();
594    
595     text1 = TLatex(3.570061, 23.08044, "CMS Preliminary");
596     text1.SetNDC();
597     text1.SetTextAlign(13);
598     text1.SetX(0.38);
599     text1.SetY(0.928);
600     #text1.SetLineWidth(2);
601     text1.SetTextFont(42);
602     text1.SetTextSizePixels(24);# dflt=28
603     text1.Draw();
604    
605     text2 = TLatex(3.570061, 23.08044, "~%.1f pb^{-1} at #sqrt{s} = 7 TeV" % lumi);
606     text2.SetNDC();
607     text2.SetTextAlign(13);
608     text2.SetX(0.38);
609     text2.SetY(0.88);
610     #text2.SetLineWidth(2);
611     text2.SetTextFont(42);
612     text2.SetTextSizePixels(24);# dflt=28
613     text2.Draw();
614     canvases[-1].SaveAs('plots/' + histname + '.png')
615     # canvases[-1].SaveAs('plots/' + histname + '.root')
616     # canvases[-1].SaveAs('/storage/results/' + histname + '.png')
617    
618     cu_hist_data = getCumulativePlot(hist_data, "data");
619     cu_hist_ttbar = getCumulativePlot(hist_ttbar, "ttbar");
620     # cu_hist_wjets = getCumulativePlot(hist_wjets, "wjets");
621     # cu_hist_zjets = getCumulativePlot(hist_zjets, "zjets");
622     # cu_hist_qcd = getCumulativePlot(hist_qcd, "qcd");
623     # cu_hist_singleTop = getCumulativePlot(hist_singleTop, "singleTop");
624     ## cu_hist_Zprime500 = getCumulativePlot(hist_Zprime500, "Zprime500");
625     ## cu_hist_Zprime750 = getCumulativePlot(hist_Zprime750, "Zprime750");
626     ## cu_hist_Zprime1000 = getCumulativePlot(hist_Zprime1000, "Zprime1000");
627     ## cu_hist_Zprime1250 = getCumulativePlot(hist_Zprime1250, "Zprime1250");
628     ## cu_hist_Zprime1500 = getCumulativePlot(hist_Zprime1500, "Zprime1500");
629     cu_hist_data.SetTitleSize(0.045, "X");
630     cu_hist_data.SetTitleSize(0.045, "Y");
631     cu_hist_data.SetYTitle("Integrated Events");
632     # cu_hist_data.SetYTitle("Integrated Events/(50 GeV)");
633     cu_hist_ttbar.SetYTitle("Integrated Events/(50 GeV)");
634     ##
635     #
636     cu_hist_data.SetAxisRange(Urange[0], Urange[1]);
637     cu_hist_ttbar.SetAxisRange(Urange[0], Urange[1]);
638     if (Yrange[1] > 0):
639     cu_hist_data.SetAxisRange(Yrange[0], Yrange[1], "Y");
640     cu_hist_ttbar.SetAxisRange(Yrange[0], Yrange[1], "Y");
641     # cu_hist_wjets.SetAxisRange(Urange[0], Urange[1]);
642     # cu_hist_zjets.SetAxisRange(Urange[0], Urange[1]);
643     # cu_hist_qcd.SetAxisRange(Urange[0], Urange[1]);
644     # cu_hist_singleTop.SetAxisRange(Urange[0], Urange[1]);
645    
646     # cu_hs = THStack("cu_MC", "cu_MC");
647     # cu_hs.Add(cu_hist_qcd);
648     # cu_hs.Add(cu_hist_zjets);
649     # cu_hs.Add(cu_hist_wjets);
650     # cu_hs.Add(cu_hist_ttbar);
651    
652     scanvases.append(TCanvas("cu_cname" + histname, histname + "(cu)", 1200, 900))
653     scanvases[-1].cd().SetRightMargin(0.04);
654     cu_hist_ttbar.Draw("error");
655     cu_hist_data.Draw("hist error");
656     # cu_hs.Draw("hist same");
657     ### cu_hist_Zprime500.Draw("same");
658     ### cu_hist_Zprime750.Draw("same");
659     ### cu_hist_Zprime1000.Draw("same");
660     ### cu_hist_Zprime1250.Draw("same");
661     ### cu_hist_Zprime1500.Draw("same");
662     ## # cu_hist_data2.Draw("error same");
663     cu_hist_data.Draw("hist error same");
664     cu_hist_ttbar.Draw("same");
665     leg.Draw();
666     ##
667     text1.Draw();
668     ##
669     text2.Draw();
670     # scanvases[-1].SaveAs('/storage/results/' + histname + '_integrated.png')
671     scanvases[-1].SaveAs('plots/' + histname + '_integrated.png')
672    
673    
674    
675     # tdrGrid: Turns the grid lines on (true) or off (false)
676    
677     #def tdrGrid(bool gridOn):
678     # tdrStyle.SetPadGridX(gridOn);
679     # tdrStyle.SetPadGridY(gridOn);
680     #
681    
682     # fixOverlay: Redraws the axis
683    
684     def fixOverlay():
685     gPad.RedrawAxis();
686    
687    
688     def getCumulativePlot(initial, type):
689     global counter
690     counter = counter + 1;
691     name = initial.GetName()
692     name = "cu_" + name + "_" + type + str(counter);
693     title = initial.GetTitle()
694     title = "cu_" + title + "_" + type;
695     xaxis = initial.GetXaxis().GetTitle();
696     yaxis = initial.GetYaxis().GetTitle();
697     nBins = initial.GetNbinsX();
698     cu = TH1F(name, title, nBins, initial.GetXaxis().GetXmin(), initial.GetXaxis().GetXmax());
699     for bin in range(1,nBins+1):
700     cu.SetBinContent(bin, initial.Integral(bin, nBins));
701    
702     cu.SetFillStyle(initial.GetFillStyle());
703     cu.SetFillColor(initial.GetFillColor());
704     cu.SetLineColor(initial.GetLineColor());
705     # cu.SetMarkerSize(initial.GetMarkerSize());
706     # cu.SetMarkerStyle(initial.GetMarkerStyle());
707     # cu.SetMarkerColor(initial.GetMarkerColor());
708     cu.SetLineWidth(initial.GetLineWidth());
709     cu.GetXaxis().SetTitle(xaxis);
710     cu.GetYaxis().SetTitle(yaxis);
711     return cu;
712    
713     if __name__ == "__main__":
714     gROOT.SetBatch(True)
715     gROOT.ProcessLine('gErrorIgnoreLevel = 1001;')
716     plotMttbar()
717     # print "press enter to quit"
718     # a = raw_input()