ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/dhidas/OSUAnalysis/Tools/scripts/plotWpriNoDataStack.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 from __future__ import division
2    
3     from tdrStyle import *
4     from ROOT import *
5    
6     canvases = []
7     scanvases = []
8     counter = 0
9    
10     def plotMttbar():
11     tdrstyle = setTDRStyle();
12     gStyle.SetHatchesSpacing(1.0);
13     lumi = 1000;
14     oldLumi = 1000;
15     scale = lumi / oldLumi;
16     qcdScale = {'default':1.72, 'withMETAndAsymJets': 3.03};
17     # data = TFile.Open("data2.9pb_fullSetOfVars.root");
18    
19     # data = TFile.Open("Run_1000pb_PFElectron_PF2PATJets_PFMET.root");
20     ttbar = TFile.Open("TTJets_1000pb_PFElectron_PF2PATJets_PFMET.root");
21     # ttbar = TFile.Open("TT_Tune_1000pb_PFElectron_PF2PATJets_PFMET.root");
22     wjets = TFile.Open("WJetsToLNu_1000pb_PFElectron_PF2PATJets_PFMET.root");
23     # wjets = TFile.Open("WToENu_1000pb_PFElectron_PF2PATJets_PFMET.root");
24     zjets = TFile.Open("DYJetsToLL_1000pb_PFElectron_PF2PATJets_PFMET.root");
25     # bce1 = TFile.Open("QCD_Pt-20to30_BCtoE_1000pb_PFElectron_PF2PATJets_PFMET.root");
26     # bce2 = TFile.Open("QCD_Pt-30to80_BCtoE_1000pb_PFElectron_PF2PATJets_PFMET.root");
27     # bce3 = TFile.Open("QCD_Pt-80to170_BCtoE_1000pb_PFElectron_PF2PATJets_PFMET.root");
28     # enri1 = TFile.Open("QCD_Pt-20to30_EMEnriched_35.9pb_PFElectron_PF2PATJets_PFMET.root");
29     # enri2 = TFile.Open("QCD_Pt-30to80_EMEnriched_35.9pb_PFElectron_PF2PATJets_PFMET.root");
30     # enri3 = TFile.Open("QCD_Pt-80to170_EMEnriched_35.9pb_PFElectron_PF2PATJets_PFMET.root");
31     # zjets = TFile.Open("DYJets_35.9pb_PFElectron_PF2PATJets_PFMET.root");
32     # Zprime500 = TFile.Open("Zprime_M500GeV_W50GeV_1000pb_PFElectron_PF2PATJets_PFMET.root");
33     # Zprime1500 = TFile.Open("Zprime_M1500GeV_W15GeV_1000pb_PFElectron_PF2PATJets_PFMET.root");
34     # Zprime750 = TFile.Open("Zprime_M750GeV_W7500MeV_35.9pb_PFElectron_PF2PATJets_PFMET.root");
35     # Zprime1000 = TFile.Open("Zprime_M1000GeV_W10GeV_35.9pb_PFElectron_PF2PATJets_PFMET.root");
36     # Zprime2000 = TFile.Open("Zprime_M2000GeV_W20GeV_35.9pb_PFElectron_PF2PATJets_PFMET.root");
37     # Zprime4000 = TFile.Open("Zprime_M4000GeV_W400GeV_1000pb_PFElectron_PF2PATJets_PFMET.root");
38     # Tprime300 = TFile.Open("TprimeToWb_M300_35.9pb_PFElectron_PF2PATJets_PFMET.root");
39     # Tprime350 = TFile.Open("TprimeToWb_M350_35.9pb_PFElectron_PF2PATJets_PFMET.root");
40     # WprimeTToTTD_M1000 = TFile.Open("WprimeTToTTD_M1000_1000pb_PFElectron_PF2PATJets_PFMET.root");
41     WprimeTToTTD_M600 = TFile.Open("WprimeTToTTD_M600_1000pb_PFElectron_PF2PATJets_PFMET.root");
42     # WprimeToTTBbar_M1000 = TFile.Open("WprimeToTBbar_M-1000_1000pb_PFElectron_PF2PATJets_PFMET.root");
43    
44     # pj1 = TFile.Open("pj1_36.145pb_PFElectron_PF2PATJets_PFMET.root");
45     # pj2 = TFile.Open("pj2_36.145pb_PFElectron_PF2PATJets_PFMET.root");
46     # pj3 = TFile.Open("pj3_36.145pb_PFElectron_PF2PATJets_PFMET.root");
47     # tW = TFile.Open("tW_36.145pb_PFElectron_PF2PATJets_PFMET.root");
48     # tchan = TFile.Open("tchan_36.145pb_PFElectron_PF2PATJets_PFMET.root");
49     # vqq = TFile.Open("vqq_7.22pb_V4PFCalo.root__fullSetOfVars.root");
50     # Zprime1250 = TFile.Open("/storage/workspace/BristolAnalysisTools/outputfiles/Zprime_M1250GeV_W12500MeV_36.135pb.root");
51     # Zprime1500 = TFile.Open("/storage/workspace/BristolAnalysisTools/outputfiles/Zprime_M1500GeV_W15GeV_36.135pb.root");
52    
53     hists = [];
54     # hists.append('mttbar_QCDEnriched')
55     # hists.append('mttbar_conversions')
56     # hists.append('mttbar_conversions_withMETCut')
57     # hists.append('mttbar_conversions_withMETAndAsymJets')
58     # hists.append('mttbar_conversions_withAsymJetsCut')
59     # hists.append('mttbar_controlRegion')
60     # hists.append("jet12vsjet13");
61     # hists.append("jet12vsjet23");
62     # hists.append("jet13vsjet23");
63     hists.append("mttbar");
64     # hists.append("tPrimeMass");
65     # hists.append("tPrimepT");
66     # hists.append("tPrimeHT");
67     # hists.append("tPrime_pt");
68     # hists.append("tPrime_px");
69     # hists.append("tPrime_py");
70     # hists.append("tPrime_pz");
71     # hists.append("mLeptonicTopLone");
72     hists.append("mLepTopLone");
73     # hists.append("mLepTopLoneNM");
74     # hists.append("mHadTopLoneNM");
75     # hists.append("mHadronicTopLone");
76     # hists.append("chiHadronicTop");
77     # hists.append("chiLeptonicTop");
78     # hists.append("chiGlobal");
79     # hists.append("chiTotal");
80     # hists.append("lepTopDeltaR");
81     # hists.append("hadTopDeltaR");
82     # hists.append("lepTopLep");
83     # hists.append("hadTopHad");
84     # hists.append("numHadTopMCMatches");
85     # hists.append("numLepTopMCMatches");
86     # hists.append("numHadTopCorrectID");
87     # hists.append("numLepTopCorrectID");
88     # hists.append("mttbar_2ndSolution");
89     # hists.append("mttbar_3rdSolution");
90     # hists.append("mttbar_allSolutions");
91     ##
92     # hists.append("mttbar_withMETCut");
93     # hists.append("mttbar_2ndSolution_withMETCut");
94     # hists.append("mttbar_3rdSolution_withMETCut");
95     # hists.append("mttbar_allSolutions_withMETCut");
96     #
97     # hists.append("mttbar_withMETAndAsymJets");
98     # hists.append("mttbar_2ndSolution_withMETAndAsymJets");
99     # hists.append("mttbar_3rdSolution_withMETAndAsymJets");
100     # hists.append("mttbar_allSolutions_withMETAndAsymJets");
101     #
102     # hists.append("mttbar_withAsymJetsCut");
103     # hists.append("mttbar_2ndSolution_withAsymJetsCut");
104     # hists.append("mttbar_3rdSolution_withAsymJetsCut");
105     # hists.append("mttbar_allSolutions_withAsymJetsCut");
106     #
107     # hists.append("ttbar_pt");
108     # hists.append("ttbar_pt_2ndSolution");
109     # hists.append("ttbar_pt_3rdSolution");
110     # hists.append("ttbar_pt_allSolutions");
111     #
112     # hists.append("ttbar_pt_withMETCut");
113     # hists.append("ttbar_pt_2ndSolution_withMETCut");
114     # hists.append("ttbar_pt_3rdSolution_withMETCut");
115     # hists.append("ttbar_pt_allSolutions_withMETCut");
116     #
117     # hists.append("ttbar_pt_withMETAndAsymJets");
118     # hists.append("ttbar_pt_2ndSolution_withMETAndAsymJets");
119     # hists.append("ttbar_pt_3rdSolution_withMETAndAsymJets");
120     # hists.append("ttbar_pt_allSolutions_withMETAndAsymJets");
121     #
122     # hists.append("ttbar_pt_withAsymJetsCut");
123     # hists.append("ttbar_pt_2ndSolution_withAsymJetsCut");
124     # hists.append("ttbar_pt_3rdSolution_withAsymJetsCut");
125     # # hists.append("ttbar_pt_allSolutions_withAsymJetsCut");
126     # hists.append("angleTops");
127     # hists.append("angleTops_withMETCut");
128     # hists.append("angleTops_withMETAndAsymJets");
129     # hists.append("angleTops_withAsymJetsCut");
130     #
131     # hists.append("pt_leadingTop");
132     hists.append("pt_loneLepTop");
133     hists.append("pt_lepTop");
134     hists.append("pt_hadTop");
135     # hists.append("pt_loneHadTop");
136     # hists.append("pt_leadingTop_withMETCut");
137     # hists.append("pt_leadingTop_withMETAndAsymJets");
138     # hists.append("pt_leadingTop_withAsymJetsCut");
139     #
140     # hists.append("pt_NextToLeadingTop");
141     # hists.append("pt_NextToLeadingTop_withMETCut");
142     # hists.append("pt_NextToLeadingTop_withMETAndAsymJets");
143     # hists.append("pt_NextToLeadingTop_withAsymJetsCut");
144     #
145     hists.append("mLeptonicTop");
146     hists.append("mHadronicTop");
147     # hists.append("mAllTop");
148     #
149     # hists.append("ttbar_px");
150     # hists.append("ttbar_py");
151     # hists.append("ttbar_pz");
152     #
153     # hists.append("m3");
154     # hists.append("HT");
155     hists.append("HT_ltop");
156     # hists.append("qkjet_eta");
157     # hists.append("qkjet_rapid");
158     # hists.append("leadjet_rap");
159     # hists.append("lepb_angle");
160     hists.append("angleHadTopD");
161     hists.append("wpmass");
162     # hists.append("MET");
163     hists.append("MET_ltop");
164     # hists.append("METtopangle_ltop");
165     hists.append("METpt_ltop");
166     hists.append("HT3jet_ltop");
167     hists.append("HT4jet_ltop");
168     hists.append("mass4jets");
169     hists.append("ST_ltop");
170     hists.append("mtbothchg4j");
171     hists.append("mtbothchg5j");
172     hists.append("mtplus4j");
173     hists.append("mtplus5j");
174     hists.append("mtminus4j");
175     hists.append("mtminus5j");
176     # hists.append("leadingJetMass");
177     # hists.append("mtW");
178     # hists.append("neutrino_pz");
179     hists.append("lone_neutrino_pz");
180     suffixes = ["0orMoreBtag",
181     "1orMoreBtag",
182     "2orMoreBtags",
183     "3orMoreBtags",'4orMoreBtags' ]
184     hists = [hist + '_' + suffix for hist in hists for suffix in suffixes]
185    
186     # jetBinned = ["allJets",
187     # "1orMoreJets",
188     # "2orMoreJets",
189     # "3orMoreJets" , "4orMoreJets"]
190     # jetBinnedhists = []
191     # jetBinnedhists.append("QCDest_CombRelIso")
192     # jetBinnedhists.append("QCDest_CombRelIso_1btag")
193     # jetBinnedhists.append("QCDest_CombRelIso_2btag")
194     # jetBinnedhists.append("QCDest_CombRelIso_controlRegion")
195     # jetBinnedhists.append("QCDest_CombRelIso_controlRegion_1btag")
196     # jetBinnedhists.append("QCDest_CombRelIso_controlRegion_2btag")
197     #
198     # jetBinnedhists.append("QCDest_PFIsolation")
199     # jetBinnedhists.append("QCDest_PFIsolation_WithMETCut")
200     # jetBinnedhists.append("QCDest_PFIsolation_WithMETCutAndAsymJetCuts")
201     # jetBinnedhists.append("QCDest_PFIsolation_WithAsymJetCuts")
202    
203     # jetBinnedhists.append("QCDest_PFIsolation_1btag")
204     # jetBinnedhists.append("QCDest_PFIsolation_2btag")
205     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion")
206     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion_1btag")
207     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion_2btag")
208     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion2")
209     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion2_WithMETCut")
210     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion2_WithMETCutAndAsymJetCuts")
211     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion2_WithAsymJetCuts")
212     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion2_1btag")
213     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion2_2btag")
214    
215     # jetBinnedhists = [hist + '_' + suffix for hist in jetBinnedhists for suffix in jetBinned]
216     # hists.extend(jetBinnedhists)
217     gcd = gROOT.cd
218    
219     for histname in hists:
220     currentSelection = 'default'
221     if 'withMETAndAsymJets' in histname:
222     currentSelection = 'withMETAndAsymJets'
223     gcd()
224     print histname
225     # hist_data = data.Get(histname);
226    
227     # hist_data2;
228     # if (histname == "mttbar_rebinned")
229     # hist_data2 = data2.Get(histname);
230     # else
231     # hist_data2 = TH1F(*hist_data);
232     # hist_data.Sumw2();
233     # hist_data2.Sumw2();
234     hist_ttbar = ttbar.Get(histname);
235     hist_wjets = wjets.Get(histname);
236     hist_zjets = zjets.Get(histname);
237    
238     # hist_bce1 = bce1.Get(histname);
239     # hist_bce2 = bce2.Get(histname);
240     # hist_bce3 = bce3.Get(histname);
241     # hist_enri1 = enri1.Get(histname);
242     # hist_enri2 = enri2.Get(histname);
243     # hist_enri3 = enri3.Get(histname);
244     # # hist_pj1 = pj1.Get(histname);
245     # # hist_pj2 = pj2.Get(histname);
246     # hist_pj3 = pj3.Get(histname);
247     # hist_singleTop = tW.Get(histname)
248     # hist_singleTop.Add(tchan.Get(histname))
249    
250     # hist_Zprime500 = Zprime500.Get(histname);
251     # hist_Zprime750 = Zprime750.Get(histname);
252     # hist_Zprime1000 = Zprime1000.Get(histname);
253     # hist_Zprime1500 = Zprime1500.Get(histname);
254     # hist_Zprime2000 = Zprime2000.Get(histname);
255     # hist_Zprime4000 = Zprime4000.Get(histname);
256     # hist_Tprime300 = Tprime300.Get(histname);
257     # hist_Tprime350 = Tprime350.Get(histname);
258     # # hist_Zprime1250 = Zprime1250.Get(histname);
259     # hist_wpm1000 = WprimeTToTTD_M1000.Get(histname);
260     hist_wpm600 = WprimeTToTTD_M600.Get(histname);
261     # hist_wptb1000 = WprimeToTTBbar_M1000.Get(histname);
262    
263     hist_ttbar.Scale(scale);
264     hist_wjets.Scale(scale);
265     hist_zjets.Scale(scale);
266    
267     # hist_bce1.Scale(scale);
268     # hist_bce2.Scale(scale);
269     # hist_bce3.Scale(scale);
270    
271     # hist_enri1.Scale(scale);
272     # hist_enri2.Scale(scale);
273     # hist_enri3.Scale(scale);
274    
275     # hist_pj1.Scale(scale);
276     # hist_pj2.Scale(scale);
277     # hist_pj3.Scale(scale);
278    
279     # scale = scale * 10.0;
280     # hist_Zprime500.Scale(scale);
281     # hist_Zprime750.Scale(scale);
282     # hist_Zprime1000.Scale(scale);
283     # hist_Zprime2000.Scale(scale);
284     # hist_Zprime1500.Scale(scale);
285     # hist_Zprime4000.Scale(scale);
286     # hist_Tprime300.Scale(scale);
287     # hist_Tprime350.Scale(scale);
288     # hist_Zprime1250.Scale(scale);
289     # hist_wpm1000.Scale(scale);
290     hist_wpm600.Scale(scale);
291     # hist_wptb1000.Scale(scale);
292    
293     # hist_qcd = hist_bce1.Clone("qcd")#TH1F(*hist_bce1);
294     # hist_qcd.Add(hist_bce2);
295     # hist_qcd.Add(hist_bce3);
296     # hist_qcd.Add(hist_enri1);
297     # hist_qcd.Add(hist_enri2);
298     # hist_qcd.Add(hist_enri3);
299     # hist_qcd.Add(hist_pj1);
300     # hist_qcd.Add(hist_pj2);
301     # hist_qcd.Add(hist_pj3);
302     # hist_qcd.Scale(qcdScale[currentSelection]);
303     # ndata = hist_data.Integral();
304     # ntop = hist_ttbar.Integral();
305     # nwj = hist_wjets.Integral();
306     # nzj = hist_zjets.Integral();
307     # nqcd = hist_qcd.Integral();
308     # sumMC = ntop + nwj + nzj + nqcd;
309     # cout << ndata << " " << sumMC << endl;
310     # hist_wjets.Scale(ndata / sumMC);
311     # hist_ttbar.Scale(ndata / sumMC);
312     # hist_zjets.Scale(ndata / sumMC);
313     # hist_qcd.Scale(ndata / sumMC);
314     # mttbars = ['mttbar_' + suffix for suffix in suffixes]
315     # mttbars2 = ['mttbar_withMETAndAsymJets_' + suffix for suffix in suffixes]
316     # if histname in mttbars or histname in mttbars2:
317     # print "taking QCD shape from DATA"
318     # name = histname.replace('mttbar', 'mttbar_conversions')
319     # hist_qcd = data.Get(name)
320     # if( hist_qcd.Integral() > 0):
321     # hist_qcd.Scale(nqcd/hist_qcd.Integral())
322     # hist_mc = hist_qcd.Clone("all_mc")
323     hist_mc = hist_ttbar.Clone("all_mc")
324     hist_mc.Add(hist_ttbar);
325     hist_mc.Add(hist_zjets);
326     hist_mc.Add(hist_wjets);
327     hist_mc.Add(hist_wpm600);
328     # hist_mc.Add(hist_singleTop);
329    
330     hist_data = hist_ttbar.Clone("test");
331     rebin = 1;
332     Urange = (0,5000)
333     if ("mttbar" in histname):
334     hist_data.SetXTitle("M_{t#bar{t}}/GeV");
335     hist_data.SetYTitle("Events/(100 GeV)");
336     rebin = 100;
337     Urange = (0, 2000)
338     elif ("tPrimeMass" in histname):
339     hist_data.SetXTitle("T' mass/GeV");
340     hist_data.SetYTitle("Events/(100 GeV)");
341     rebin = 200;
342     Urange = (0, 2000)
343     elif ("wpmass" in histname):
344     hist_data.SetXTitle("W' mass/GeV");
345     hist_data.SetYTitle("Events/(60 GeV)");
346     rebin = 60;
347     Urange = (0, 1200)
348     elif ("jet12" in histname or "jet13" in histname):
349     hist_data.SetXTitle("Jet mass/GeV");
350     hist_data.SetYTitle("Jet mass/GeV)");
351     elif ("tPrimepT" in histname):
352     hist_data.SetXTitle("T' pT/GeV");
353     hist_data.SetYTitle("Events/(8 GeV)");
354     rebin = 8;
355     Urange = (0, 200)
356     elif ("tPrimeHT" in histname):
357     hist_data.SetXTitle("T' HT");
358     hist_data.SetYTitle("Events");
359     rebin = 4;
360     Urange = (0, 1.5)
361     elif ("m3" in histname):
362     hist_data.SetXTitle("M3/GeV");
363     hist_data.SetYTitle("Events/(50 GeV)");
364     rebin = 50;
365     Urange = (0, 1500)
366     elif (histname == "electron_et"):
367     hist_data.SetXTitle("electron p_{T}/GeV");
368     hist_data.SetYTitle("Events/(5 GeV)");
369     rebin = 5;
370     elif ("ttbar_pt" in histname):
371     hist_data.SetXTitle("p_{T} of t#bar{t} system/GeV");
372     hist_data.SetYTitle("Events/(10 GeV)");
373     rebin = 10;
374     Urange = (0, 500)
375     elif ("ttbar_px" in histname):
376     hist_data.SetXTitle("p_{x} of t#bar{t} system/GeV");
377     hist_data.SetYTitle("Events/(10 GeV)");
378     rebin = 10;
379     Urange = (0, 500)
380     elif ("ttbar_py" in histname):
381     hist_data.SetXTitle("p_{y} of t#bar{t} system/GeV");
382     hist_data.SetYTitle("Events/(10 GeV)");
383     rebin = 10;
384     Urange = (0, 500)
385     elif ("ttbar_pz" in histname):
386     hist_data.SetXTitle("p_{z} of t#bar{t} system/GeV");
387     hist_data.SetYTitle("Events/(50 GeV)");
388     rebin = 50;
389     Urange = (0, 2000)
390     elif ("METpt_ltop" in histname):
391     hist_data.SetXTitle("MET p_{T}/GeV");
392     hist_data.SetYTitle("Events/(10 GeV)");
393     rebin = 10;
394     Urange = (0, 400)
395     elif ("tPrime_pt" in histname):
396     hist_data.SetXTitle("p_{T} of T' system/GeV");
397     hist_data.SetYTitle("Events/(20 GeV)");
398     rebin = 20;
399     Urange = (0, 200)
400     elif ("tPrime_px" in histname):
401     hist_data.SetXTitle("p_{x} of T' system/GeV");
402     hist_data.SetYTitle("Events/(20 GeV)");
403     rebin = 20;
404     Urange = (0, 200)
405     elif ("tPrime_py" in histname):
406     hist_data.SetXTitle("p_{y} of T' system/GeV");
407     hist_data.SetYTitle("Events/(20 GeV)");
408     rebin = 20;
409     Urange = (0, 200)
410     elif ("tPrime_pz" in histname):
411     hist_data.SetXTitle("p_{z} of T' system/GeV");
412     hist_data.SetYTitle("Events/(100 GeV)");
413     rebin = 200;
414     Urange = (0, 1800)
415     elif ("HT_" in histname):
416     hist_data.SetXTitle("#Sigma p_{T}/GeV");
417     hist_data.SetYTitle("Events/(20 GeV)");
418     rebin = 20;
419     Urange = (0, 2000)
420     elif ("ST" in histname):
421     hist_data.SetXTitle("ST/GeV");
422     hist_data.SetYTitle("Events/(30 GeV)");
423     rebin = 30;
424     Urange = (0, 1000)
425     elif ("HT3jet_ltop" in histname):
426     hist_data.SetXTitle("#Sigma p_{T} of leading 3 jets/GeV");
427     hist_data.SetYTitle("Events/(20 GeV)");
428     rebin = 20;
429     Urange = (0, 1000)
430     elif ("HT4jet_ltop" in histname):
431     hist_data.SetXTitle("#Sigma p_{T} of leading 4 jets/GeV");
432     hist_data.SetYTitle("Events/(50 GeV)");
433     rebin = 50;
434     Urange = (0, 1200)
435     elif (histname == "numberOfJets"):
436     hist_data.SetXTitle("number of jets");
437     hist_data.SetYTitle("Events");
438     elif (histname == "numberOfBJets"):
439     hist_data.SetXTitle("number of b-tagged jets (SSVHE medium)");
440     hist_data.SetYTitle("Events");
441     elif ('MET_' in histname and 'MET_ltop' not in histname):
442     hist_data.SetXTitle("MET/GeV");
443     hist_data.SetYTitle("Events/(10 GeV)");
444     rebin = 2;
445     Urange = (0, 400)
446     elif ('MET_ltop' in histname):
447     hist_data.SetXTitle("MET/GeV");
448     hist_data.SetYTitle("Events/(10 GeV)");
449     rebin = 20;
450     Urange = (0, 400)
451     elif ("leadingJetMass" in histname):
452     hist_data.SetXTitle("leading jet mass/GeV");
453     hist_data.SetYTitle("Events/(5 GeV)");
454     rebin = 5;
455     Urange = (0, 150)
456     elif ("mtW" in histname):
457     hist_data.SetXTitle("transverse W-boson mass/GeV");
458     hist_data.SetYTitle("Events/(10 GeV)");
459     rebin = 10;
460     elif ("mtboth" in histname or "mtplus" in histname or "mtminu" in histname):
461     hist_data.SetXTitle("transverse mass/GeV");
462     hist_data.SetYTitle("Events/(60 GeV)");
463     rebin = 60;
464     Urange = (0, 2000)
465     elif ("electronD0" in histname):
466     hist_data.SetXTitle("electron d_{0} / cm");
467     hist_data.SetYTitle("Events/(0.001 cm)");
468     rebin = 10;
469     elif ("angleTops" in histname):
470     hist_data.SetXTitle("angle between top quarks");
471     hist_data.SetYTitle("Events/(0.1 rad)");
472     rebin = 10;
473     elif ("lepb_angle" in histname):
474     hist_data.SetXTitle("angle between electron and b jet");
475     hist_data.SetYTitle("Events/(0.1 rad)");
476     rebin = 10;
477     elif ("angleHadTopD" in histname):
478     hist_data.SetXTitle("angle between hadronic top and light jet");
479     hist_data.SetYTitle("Events/(0.2 rad)");
480     rebin = 20;
481     elif ("METtopangle_ltop" in histname):
482     hist_data.SetXTitle("angle between MET and top p_{T}");
483     hist_data.SetYTitle("Events/(0.1 rad)");
484     rebin = 10;
485     Urange = (-2, 2)
486     elif ("qkjet_eta" in histname):
487     hist_data.SetXTitle("#eta of b jet");
488     hist_data.SetYTitle("Events/(0.1 rad)");
489     Urange = (-3, 3)
490     rebin = 10;
491     elif ("_rap" in histname):
492     hist_data.SetXTitle("Jet Rapidity");
493     hist_data.SetYTitle("Events/(0.1 rad)");
494     Urange = (-3, 3)
495     rebin = 20;
496     elif ("neutrino_pz" in histname):
497     hist_data.SetXTitle("neutrino p_{Z} /GeV");
498     hist_data.SetYTitle("Events/(20 GeV)");
499     rebin = 20;
500     Urange = (-500, 500)
501     elif ('mHadronicTopLone' in histname or 'mHadTopLoneNM' in histname):
502     hist_data.SetXTitle("top mass /GeV");
503     hist_data.SetYTitle("Events/(25 GeV)");
504     rebin = 25;
505     Urange = (0, 300)
506     elif ('mass4jets' in histname):
507     hist_data.SetXTitle("4-jet mass /GeV");
508     hist_data.SetYTitle("Events/(50 GeV)");
509     rebin = 50;
510     Urange = (0, 1500)
511     elif ('mLeptonicTopLone' in histname or 'mLepTopLoneNM' in histname or 'mLepTopLone' in histname):
512     hist_data.SetXTitle("top mass /GeV");
513     hist_data.SetYTitle("Events/(10 GeV)");
514     rebin = 10;
515     Urange = (0, 700)
516     elif ('chiHadronicTop' in histname or 'chiLeptonicTop' in histname):
517     hist_data.SetXTitle("top #chi^{2} /GeV");
518     hist_data.SetYTitle("Events/(1)");
519     rebin = 1;
520     Urange = (0, 30)
521     elif ('chiGlobal' in histname or 'chiTotal' in histname):
522     hist_data.SetXTitle("Event #chi^{2} /GeV");
523     hist_data.SetYTitle("Events/(100)");
524     rebin = 100;
525     elif ('numHadTopMCMatches' in histname or 'numLepTopMCMatches' in histname):
526     hist_data.SetXTitle("Number of MC-Truth Matches");
527     hist_data.SetYTitle("Events");
528     elif ('numHadTopCorrectID' in histname or 'numLepTopCorrectID' in histname):
529     hist_data.SetXTitle("Number of Reco Candidates Matched to MC-Truth Particles");
530     hist_data.SetYTitle("Events");
531     elif ('lepTopDeltaR' in histname or 'hadTopDeltaR' in histname):
532     hist_data.SetXTitle("#Delta R of MC truth top");
533     hist_data.SetYTitle("Events");
534     rebin = 2;
535     elif ('lepTopLep' in histname or 'hadTopHad' in histname):
536     hist_data.SetXTitle("top MC truth identity");
537     hist_data.SetYTitle("Events");
538     Urange = (0, 2)
539     elif ('mHadronicTop' in histname or 'mAllTop' in histname):
540     hist_data.SetXTitle("top mass /GeV");
541     hist_data.SetYTitle("Events/(40 GeV)");
542     rebin = 40;
543     Urange = (0, 800)
544     elif ('mLeptonicTop' in histname):
545     hist_data.SetXTitle("top mass /GeV");
546     hist_data.SetYTitle("Events/(25 GeV)");
547     rebin = 25;
548     elif ('pt_' in histname and 'Top' in histname):
549     hist_data.SetXTitle("top p_{T} /GeV");
550     hist_data.SetYTitle("Events/(50 GeV)");
551     rebin = 50;
552     Urange = (0, 500)
553     elif('QCDest_CombRelIso' in histname):
554     hist_data.SetXTitle("relative isolation");
555     hist_data.SetYTitle("Events/(0.1)");
556     rebin = 10;
557     Urange = (0, 2)
558     elif('QCDest_PFIsolation' in histname):
559     hist_data.SetXTitle("ParticleFlow isolation");
560     hist_data.SetYTitle("Events/(0.1)");
561     rebin = 10
562     Urange = (0, 2)
563    
564    
565     hist_data.SetTitleOffset(1.3, "Y");
566     if ('jet1' in histname):
567     hist_data.Rebin2D();
568     hist_ttbar.Rebin2D();
569     hist_Tprime300.Rebin2D();
570     hist_Tprime350.Rebin2D();
571     hist_data.SetAxisRange(0, 600, "X");
572     hist_data.SetAxisRange(0, 600, "Y");
573     hist_ttbar.SetAxisRange(0, 600, "X");
574     hist_ttbar.SetAxisRange(0, 600, "Y");
575     # hist_Tprime300.SetAxisRange(0, 600, "X");
576     # hist_Tprime300.SetAxisRange(0, 600, "Y");
577     # hist_Tprime350.SetAxisRange(0, 600, "X");
578     # hist_Tprime350.SetAxisRange(0, 600, "Y");
579     else:
580     hist_data.Rebin(rebin);
581     hist_ttbar.Rebin(rebin);
582     hist_wjets.Rebin(rebin);
583     hist_zjets.Rebin(rebin);
584     # hist_qcd.Rebin(rebin);
585     # hist_Zprime500.Rebin(rebin);
586     # hist_Zprime1500.Rebin(rebin);
587     # hist_Zprime750.Rebin(rebin);
588     # hist_Zprime1000.Rebin(rebin);
589     # hist_Zprime2000.Rebin(rebin);
590     # hist_Zprime4000.Rebin(rebin);
591     # hist_Tprime300.Rebin(rebin);
592     # hist_Tprime350.Rebin(rebin);
593     # hist_singleTop.Rebin(rebin)
594     # hist_wpm1000.Rebin(rebin);
595     hist_wpm600.Rebin(rebin);
596     # hist_wptb1000.Rebin(rebin);
597    
598     hist_data.SetAxisRange(Urange[0], Urange[1]);
599     hist_ttbar.SetAxisRange(Urange[0], Urange[1]);
600     hist_wjets.SetAxisRange(Urange[0], Urange[1]);
601     hist_zjets.SetAxisRange(Urange[0], Urange[1]);
602     # hist_qcd.SetAxisRange(Urange[0], Urange[1]);
603     # hist_Zprime500.SetAxisRange(Urange[0], Urange[1]);
604     # hist_Zprime750.SetAxisRange(Urange[0], Urange[1]);
605     # hist_Zprime1000.SetAxisRange(Urange[0], Urange[1]);
606     # hist_Zprime1500.SetAxisRange(Urange[0], Urange[1]);
607     # hist_Zprime2000.SetAxisRange(Urange[0], Urange[1]);
608     # hist_Zprime4000.SetAxisRange(Urange[0], Urange[1]);
609     # hist_Tprime300.SetAxisRange(Urange[0], Urange[1]);
610     # hist_Tprime350.SetAxisRange(Urange[0], Urange[1]);
611     # hist_singleTop.SetAxisRange(Urange[0], Urange[1]);
612     # hist_wpm1000.SetAxisRange(Urange[0], Urange[1]);
613     hist_wpm600.SetAxisRange(Urange[0], Urange[1]);
614     # hist_wptb1000.SetAxisRange(Urange[0], Urange[1]);
615    
616     hist_data.SetMarkerStyle(8);
617     # hist_data.SetMarkerSize(1.5);
618     hist_data.SetMarkerSize(0.1);
619    
620     # hist_data.SetFillStyle(1001);
621     # hist_data.SetFillColor(kRed);
622     hist_ttbar.SetFillStyle(1001);
623     hist_ttbar.SetFillColor(kRed);
624     hist_wjets.SetFillStyle(1001);
625     hist_wjets.SetFillColor(4);
626     hist_zjets.SetFillStyle(1001);
627     hist_zjets.SetFillColor(8);
628     # hist_qcd.SetFillStyle(1001);
629     # hist_qcd.SetFillColor(kYellow);
630     # hist_qcd.SetFillColor(12);
631     # hist_singleTop.SetFillStyle(1001);
632     # hist_singleTop.SetFillColor(kMagenta)
633     # nbins = hist_qcd.GetXaxis().GetNbins();
634     # binwidth = (hist_qcd.GetXaxis().GetXmax() - hist_qcd.GetXaxis().GetXmin()) / nbins;
635     # for i in range(1, nbins + 1):
636     # yvalue = hist_qcd.GetBinContent(i);
637     # # float xvalue = hist_qcd.GetBinCenter(i);
638     # # float ymin = yvalue - yvalue*0.5;
639     # # float ymax = yvalue + yvalue*0.5;
640     # # float xmin = xvalue - 0.5*binwidth;
641     # # float xmax = xvalue + 0.5*binwidth;
642     # error = yvalue * 0.5;
643     # hist_mc.SetBinError(i, error);
644     # # qcdUncert.SetPointError(i, xmin, xmax, ymin, ymax);
645     #
646     # qcdUncert = TGraphAsymmErrors(hist_mc);
647    
648     linewidth = 6;
649     # hist_Zprime500.SetLineColor(6);
650     # hist_Zprime500.SetLineWidth(linewidth);
651     # hist_Zprime500.SetFillStyle(0);
652     # hist_Zprime500.SetFillColor(kWhite);
653    
654     # hist_Zprime750.SetLineColor(5);
655     # hist_Zprime750.SetLineWidth(linewidth);
656     # hist_Zprime750.SetFillStyle(0);
657     # hist_Zprime750.SetFillColor(kWhite);
658    
659     # hist_Zprime1000.SetLineColor(7);
660     # hist_Zprime1000.SetLineWidth(linewidth);
661     # hist_Zprime1000.SetFillStyle(0);
662     # hist_Zprime1000.SetFillColor(kWhite);
663     # hist_Zprime2000.SetLineColor(42);
664     # hist_Zprime2000.SetLineWidth(linewidth);
665     # hist_Zprime2000.SetFillStyle(0);
666     # hist_Zprime2000.SetFillColor(kWhite);
667     # # hist_Zprime4000.SetLineColor(50);
668     # hist_Zprime4000.SetLineWidth(linewidth);
669     # hist_Zprime4000.SetFillStyle(0);
670     # hist_Zprime4000.SetFillColor(kWhite);
671    
672     # hist_Tprime300.SetLineColor(kOrange + 1);
673     # hist_Tprime300.SetLineWidth(linewidth);
674     # hist_Tprime350.SetLineColor(kGray + 3);
675     # hist_Tprime350.SetLineWidth(linewidth);
676     #
677     # hist_Zprime1250.SetLineColor(kCyan - 5);
678     # hist_Zprime1250.SetLineWidth(linewidth);
679     # hist_Zprime1250.SetFillStyle(0);
680     # hist_Zprime1250.SetFillColor(kWhite);
681     #
682     # hist_Zprime1500.SetLineColor(42);
683     # hist_Zprime1500.SetLineWidth(linewidth);
684     # hist_Zprime1500.SetFillStyle(0);
685     # hist_Zprime1500.SetFillColor(kWhite);
686    
687     # hist_wpm1000.SetLineColor(kOrange + 1);
688     # hist_wpm1000.SetLineWidth(linewidth);
689     # hist_wpm600.SetLineColor(kGray + 3);
690     # hist_wpm600.SetLineWidth(linewidth);
691     hist_wpm600.SetFillStyle(1001);
692     hist_wpm600.SetFillColor(kGray + 3);
693     # hist_wptb1000.SetLineColor(kCyan);
694     # hist_wptb1000.SetLineWidth(linewidth);
695    
696     # qcdUncert.SetFillColor(kGray + 3);
697     # qcdUncert.SetFillStyle(3003);
698    
699     leg = TLegend(0.696, 0.35, 0.94, 0.92);
700     leg.SetBorderSize(0);
701     leg.SetLineStyle(0);
702     leg.SetTextFont(42);
703     leg.SetFillStyle(0);
704    
705     # leg.AddEntry(hist_data, "data", "P");
706     # leg.AddEntry(hist_data2, "data(no HLT)", "P");
707     leg.AddEntry(hist_ttbar, "t#bar{t}", "f");
708     leg.AddEntry(hist_wjets, "W#rightarrowl#nu", "f");
709     leg.AddEntry(hist_zjets, "Z/#gamma*#rightarrowl^{+}l^{-}", "f");
710     # leg.AddEntry(hist_qcd, "QCD", "F");
711     # leg.AddEntry(hist_qcd, "QCD/#gamma + jets");
712     # leg.AddEntry(hist_singleTop, "Single-Top")
713     # leg.AddEntry(hist_Zprime500, "Z' 0.5TeV (50 pb)", "L");
714     # leg.AddEntry(hist_Zprime750, "Z' 0.75TeV", "L");
715     # leg.AddEntry(hist_Zprime1000, "Z' 1TeV", "L");
716     # leg.AddEntry(hist_Zprime1500, "Z' 1.5TeV (50 pb)", "L");
717     # leg.AddEntry(hist_Zprime2000, "Z' 2TeV", "L");
718     # leg.AddEntry(hist_Zprime4000, "Z' 4TeV (50 pb)", "L");
719     # leg.AddEntry(hist_Tprime300, "T' 300GeV", "L");
720     # leg.AddEntry(hist_Tprime350, "T' 350GeV", "L");
721     # leg.AddEntry(hist_Zprime1250, "Z' 1.25TeV");
722     leg.AddEntry(hist_wpm600, "W't 600GeV (8 pb)", "F");
723     # leg.AddEntry(hist_wpm1000, "W't 1TeV (0.72 pb)", "L");
724     # leg.AddEntry(hist_wptb1000, "W'-> tb 1TeV (8 pb)", "L");
725    
726    
727     canvases.append(TCanvas("cname" + histname, histname, 1200, 900))
728     canvases[-1].cd().SetRightMargin(0.04);
729     if ('jet1' in histname):
730     hist_data.SetMarkerStyle(8);
731     hist_ttbar.SetMarkerStyle(21);
732     hist_ttbar.SetMarkerColor(kRed);
733     hist_Tprime300.SetMarkerColor(kOrange + 1);
734     hist_Tprime300.SetMarkerStyle(22);
735     hist_Tprime350.SetMarkerColor(kGray + 3);
736     hist_Tprime350.SetMarkerStyle(3);
737     else:
738     hs = THStack("MC", "MC");
739     # hs.Add(hist_qcd);
740     hs.Add(hist_zjets);
741     hs.Add(hist_wjets);
742     # hs.Add(hist_singleTop);
743     hs.Add(hist_ttbar);
744     hs.Add(hist_wpm600);
745     max = 0
746     if hs.GetMaximum() > hist_data.GetMaximum():
747     max = hs.GetMaximum()*1.1
748     else:
749     max = hist_data.GetMaximum()*1.1
750    
751     hist_data.GetYaxis().SetRangeUser(0, max);
752     hist_data.SetStats(1);
753     # hist_data.Draw('error');
754     hist_data.Draw();
755     hist_data.SetMarkerStyle(8);
756     if ('jet1' in histname):
757     hist_ttbar.Draw("same");
758     else:
759     hs.Draw("hist same");
760     # hist_Zprime500.Draw("same");
761     # hist_Zprime750.Draw("same");
762     # hist_Zprime1000.Draw("same");
763     # hist_Zprime2000.Draw("same");
764     # hist_Zprime4000.Draw("same");
765     # hist_Tprime300.Draw("same");
766     # hist_Tprime350.Draw("same");
767     # hist_Zprime1250.Draw("same");
768     # hist_Zprime1500.Draw("same");
769     # hist_wpm1000.Draw("same");
770     # hist_wpm600.Draw("same");
771     # hist_wptb1000.Draw("same");
772     # qcdUncert.Draw("1 same");
773     # hist_data2.Draw("error same");
774     # hist_data.Draw("error same");
775     # hist_data.Draw("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.Draw();
787    
788     text2 = TLatex(3.570061, 23.08044, "~%.1f pb^{-1} at #sqrt{s} = 7 TeV" % lumi);
789     text2.SetNDC();
790     text2.SetTextAlign(13);
791     text2.SetX(0.38);
792     text2.SetY(0.88);
793     #text2.SetLineWidth(2);
794     text2.SetTextFont(42);
795     text2.SetTextSizePixels(24);# dflt=28
796     text2.Draw();
797     canvases[-1].SaveAs('plots/' + histname + '.png')
798     # canvases[-1].SaveAs('plots/' + histname + '.root')
799     # canvases[-1].SaveAs('/storage/results/' + histname + '.png')
800    
801     cu_hist_data = getCumulativePlot(hist_data, "data");
802     cu_hist_ttbar = getCumulativePlot(hist_ttbar, "ttbar");
803     cu_hist_wjets = getCumulativePlot(hist_wjets, "wjets");
804     cu_hist_zjets = getCumulativePlot(hist_zjets, "zjets");
805     # cu_hist_qcd = getCumulativePlot(hist_qcd, "qcd");
806     # cu_hist_singleTop = getCumulativePlot(hist_singleTop, "singleTop");
807     # cu_hist_wpm1000 = getCumulativePlot(hist_wpm1000, "Wprimet1000");
808     cu_hist_wpm600 = getCumulativePlot(hist_wpm600, "Wprimet600");
809     # cu_hist_wptb1000 = getCumulativePlot(hist_wptb1000, "Wprimetb1000");
810     # cu_hist_Zprime500 = getCumulativePlot(hist_Zprime500, "Zprime500");
811     # cu_hist_Zprime750 = getCumulativePlot(hist_Zprime750, "Zprime750");
812     # cu_hist_Zprime1000 = getCumulativePlot(hist_Zprime1000, "Zprime1000");
813     # cu_hist_Zprime2000 = getCumulativePlot(hist_Zprime2000, "Zprime2000");
814     # cu_hist_Zprime4000 = getCumulativePlot(hist_Zprime4000, "Zprime4000");
815     # cu_hist_Tprime300 = getCumulativePlot(hist_Tprime300, "Tprime300");
816     # cu_hist_Tprime350 = getCumulativePlot(hist_Tprime350, "Tprime350");
817     ## cu_hist_Zprime1250 = getCumulativePlot(hist_Zprime1250, "Zprime1250");
818     ## cu_hist_Zprime1500 = getCumulativePlot(hist_Zprime1500, "Zprime1500");
819     cu_hist_data.SetYTitle("Integrated Events/(50 GeV)");
820     ##
821     #
822     cu_hist_data.SetAxisRange(Urange[0], Urange[1]);
823     cu_hist_ttbar.SetAxisRange(Urange[0], Urange[1]);
824     cu_hist_wjets.SetAxisRange(Urange[0], Urange[1]);
825     cu_hist_zjets.SetAxisRange(Urange[0], Urange[1]);
826     # cu_hist_qcd.SetAxisRange(Urange[0], Urange[1]);
827     # cu_hist_singleTop.SetAxisRange(Urange[0], Urange[1]);
828     # cu_hist_wpm1000.SetAxisRange(Urange[0], Urange[1]);
829     cu_hist_wpm600.SetAxisRange(Urange[0], Urange[1]);
830     # cu_hist_wptb1000.SetAxisRange(Urange[0], Urange[1]);
831    
832     cu_hs = THStack("cu_MC", "cu_MC");
833     # cu_hs.Add(cu_hist_qcd);
834     cu_hs.Add(cu_hist_zjets);
835     cu_hs.Add(cu_hist_wjets);
836     cu_hs.Add(cu_hist_ttbar);
837    
838     scanvases.append(TCanvas("cu_cname" + histname, histname + "(cu)", 1200, 900))
839     scanvases[-1].cd().SetRightMargin(0.04);
840     cu_hist_data.Draw("error");
841     cu_hs.Draw("hist same");
842     # cu_hist_wpm1000.Draw("same");
843     # cu_hist_wpm600.Draw("same");
844     # cu_hist_wptb1000.Draw("same");
845     # cu_hist_Zprime500.Draw("same");
846     # cu_hist_Zprime750.Draw("same");
847     # cu_hist_Zprime1000.Draw("same");
848     # cu_hist_Zprime2000.Draw("same");
849     # cu_hist_Zprime4000.Draw("same");
850     # cu_hist_Tprime300.Draw("same");
851     # cu_hist_Tprime350.Draw("same");
852     ### cu_hist_Zprime1250.Draw("same");
853     ### cu_hist_Zprime1500.Draw("same");
854     ## # cu_hist_data2.Draw("error same");
855     # cu_hist_data.Draw("error same");
856     leg.Draw();
857     ##
858     text1.Draw();
859     ##
860     text2.Draw();
861     # scanvases[-1].SaveAs('/storage/results/' + histname + '_integrated.png')
862     scanvases[-1].SaveAs('plots/' + histname + '_integrated.png')
863    
864    
865    
866     # tdrGrid: Turns the grid lines on (true) or off (false)
867    
868     #def tdrGrid(bool gridOn):
869     # tdrStyle.SetPadGridX(gridOn);
870     # tdrStyle.SetPadGridY(gridOn);
871     #
872    
873     # fixOverlay: Redraws the axis
874    
875     def fixOverlay():
876     gPad.RedrawAxis();
877    
878    
879     def getCumulativePlot(initial, type):
880     global counter
881     counter = counter + 1;
882     name = initial.GetName()
883     name = "cu_" + name + "_" + type + str(counter);
884     title = initial.GetTitle()
885     title = "cu_" + title + "_" + type;
886     xaxis = initial.GetXaxis().GetTitle();
887     yaxis = initial.GetYaxis().GetTitle();
888     nBins = initial.GetNbinsX();
889     cu = TH1F(name, title, nBins, initial.GetXaxis().GetXmin(), initial.GetXaxis().GetXmax());
890     for bin in range(1,nBins+1):
891     cu.SetBinContent(bin, initial.Integral(bin, nBins));
892    
893     cu.SetFillStyle(initial.GetFillStyle());
894     cu.SetFillColor(initial.GetFillColor());
895     cu.SetLineColor(initial.GetLineColor());
896     cu.SetMarkerSize(initial.GetMarkerSize());
897     cu.SetMarkerStyle(initial.GetMarkerStyle());
898     cu.SetMarkerColor(initial.GetMarkerColor());
899     cu.SetLineWidth(initial.GetLineWidth());
900     cu.GetXaxis().SetTitle(xaxis);
901     cu.GetYaxis().SetTitle(yaxis);
902     return cu;
903    
904     if __name__ == "__main__":
905     gROOT.SetBatch(True)
906     gROOT.ProcessLine('gErrorIgnoreLevel = 1001;')
907     plotMttbar()
908     # print "press enter to quit"
909     # a = raw_input()