ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/dhidas/OSUAnalysis/Tools/scripts/plotWpriNoData.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 math import sqrt
5     from ROOT import *
6    
7     canvases = []
8     scanvases = []
9     counter = 0
10     asymrange = 0.5
11    
12     def plotMttbar():
13     tdrstyle = setTDRStyle();
14     gStyle.SetHatchesSpacing(1.0);
15     gStyle.SetOptStat("emri"); # Print integral & usual stuff
16     lumi = 5000;
17     oldLumi = 5000;
18     scale = lumi / oldLumi;
19     qcdScale = {'default':1.72, 'withMETAndAsymJets': 3.03};
20     # data = TFile.Open("data2.9pb_fullSetOfVars.root");
21    
22     # data = TFile.Open("Run_4000pb_PFElectron_PF2PATJets_PFMET.root");
23     ttbar = TFile.Open("TTJets_5000pb_PFElectron_PF2PATJets_PFMET.root");
24     # ttbar = TFile.Open("TT_Tune_4000pb_PFElectron_PF2PATJets_PFMET.root");
25     # wjets = TFile.Open("WJetsToLNu_5000pb_PFElectron_PF2PATJets_PFMET.root");
26     # wjets = TFile.Open("WToENu_4000pb_PFElectron_PF2PATJets_PFMET.root");
27     # zjets = TFile.Open("DYJetsToLL_4000pb_PFElectron_PF2PATJets_PFMET.root");
28     # bce1 = TFile.Open("QCD_Pt-20to30_BCtoE_4000pb_PFElectron_PF2PATJets_PFMET.root");
29     # bce2 = TFile.Open("QCD_Pt-30to80_BCtoE_4000pb_PFElectron_PF2PATJets_PFMET.root");
30     # bce3 = TFile.Open("QCD_Pt-80to170_BCtoE_4000pb_PFElectron_PF2PATJets_PFMET.root");
31     # enri1 = TFile.Open("QCD_Pt-20to30_EMEnriched_35.9pb_PFElectron_PF2PATJets_PFMET.root");
32     # enri2 = TFile.Open("QCD_Pt-30to80_EMEnriched_35.9pb_PFElectron_PF2PATJets_PFMET.root");
33     # enri3 = TFile.Open("QCD_Pt-80to170_EMEnriched_35.9pb_PFElectron_PF2PATJets_PFMET.root");
34     # zjets = TFile.Open("DYJets_35.9pb_PFElectron_PF2PATJets_PFMET.root");
35     # Zprime500 = TFile.Open("Zprime_M500GeV_W50GeV_4000pb_PFElectron_PF2PATJets_PFMET.root");
36     # Zprime1500 = TFile.Open("Zprime_M1500GeV_W15GeV_4000pb_PFElectron_PF2PATJets_PFMET.root");
37     # Zprime750 = TFile.Open("Zprime_M750GeV_W7500MeV_35.9pb_PFElectron_PF2PATJets_PFMET.root");
38     # Zprime1000 = TFile.Open("Zprime_M1000GeV_W10GeV_35.9pb_PFElectron_PF2PATJets_PFMET.root");
39     # Zprime2000 = TFile.Open("Zprime_M2000GeV_W20GeV_35.9pb_PFElectron_PF2PATJets_PFMET.root");
40     # Zprime4000 = TFile.Open("Zprime_M4000GeV_W400GeV_4000pb_PFElectron_PF2PATJets_PFMET.root");
41     # Tprime300 = TFile.Open("TprimeToWb_M300_35.9pb_PFElectron_PF2PATJets_PFMET.root");
42     # Tprime350 = TFile.Open("TprimeToWb_M350_35.9pb_PFElectron_PF2PATJets_PFMET.root");
43     # WprimeTToTTD_M400 = TFile.Open("WprimeTToTTD_M400_5000pb_PFElectron_PF2PATJets_PFMET.root");
44     WprimeTToTTD_M600 = TFile.Open("WprimeTToTTD_M600_5000pb_PFElectron_PF2PATJets_PFMET.root");
45     # WprimeTToTTD_M800 = TFile.Open("WprimeTToTTD_M800_5000pb_PFElectron_PF2PATJets_PFMET.root");
46     # WprimeTToTTD_M1000 = TFile.Open("WprimeTToTTD_M1000_5000pb_PFElectron_PF2PATJets_PFMET.root");
47     # WprimeToTTBbar_M1000 = TFile.Open("WprimeToTBbar_M-1000_4000pb_PFElectron_PF2PATJets_PFMET.root");
48    
49     # pj1 = TFile.Open("pj1_36.145pb_PFElectron_PF2PATJets_PFMET.root");
50     # pj2 = TFile.Open("pj2_36.145pb_PFElectron_PF2PATJets_PFMET.root");
51     # pj3 = TFile.Open("pj3_36.145pb_PFElectron_PF2PATJets_PFMET.root");
52     # tW = TFile.Open("tW_36.145pb_PFElectron_PF2PATJets_PFMET.root");
53     # tchan = TFile.Open("tchan_36.145pb_PFElectron_PF2PATJets_PFMET.root");
54     # vqq = TFile.Open("vqq_7.22pb_V4PFCalo.root__fullSetOfVars.root");
55     # Zprime1250 = TFile.Open("/storage/workspace/BristolAnalysisTools/outputfiles/Zprime_M1250GeV_W12500MeV_36.135pb.root");
56     # Zprime1500 = TFile.Open("/storage/workspace/BristolAnalysisTools/outputfiles/Zprime_M1500GeV_W15GeV_36.135pb.root");
57    
58     hists = [];
59     # hists.append('mttbar_QCDEnriched')
60     # hists.append('mttbar_conversions')
61     # hists.append('mttbar_conversions_withMETCut')
62     # hists.append('mttbar_conversions_withMETAndAsymJets')
63     # hists.append('mttbar_conversions_withAsymJetsCut')
64     # hists.append('mttbar_controlRegion')
65     # hists.append("jet12vsjet13");
66     # hists.append("jet12vsjet23");
67     # hists.append("jet13vsjet23");
68     # hists.append("mttbar");
69     # hists.append("tPrimeMass");
70     # hists.append("tPrimepT");
71     # hists.append("tPrimeHT");
72     # hists.append("tPrime_pt");
73     # hists.append("tPrime_px");
74     # hists.append("tPrime_py");
75     # hists.append("tPrime_pz");
76     # hists.append("mLeptonicTopLone");
77     # hists.append("mLepTopLoneNM");
78     # hists.append("mHadTopLoneNM");
79     # hists.append("chiHadronicTop");
80     # hists.append("chiLeptonicTop");
81     # hists.append("chiGlobal");
82     # hists.append("chiTotal");
83     # hists.append("lepTopDeltaR");
84     # hists.append("hadTopDeltaR");
85     # hists.append("lepTopLep");
86     # hists.append("hadTopHad");
87     # hists.append("numHadTopMCMatches");
88     # hists.append("numLepTopMCMatches");
89     # hists.append("numHadTopCorrectID");
90     # hists.append("numLepTopCorrectID");
91     # hists.append("numHadTopMCMatches2top");
92     # hists.append("numLepTopMCMatches2top");
93     # hists.append("numHadTopCorrectID2top");
94     # hists.append("numLepTopCorrectID2top");
95     # hists.append("mttbar_2ndSolution");
96     # hists.append("mttbar_3rdSolution");
97     # hists.append("mttbar_allSolutions");
98     ##
99     # hists.append("mttbar_withMETCut");
100     # hists.append("mttbar_2ndSolution_withMETCut");
101     # hists.append("mttbar_3rdSolution_withMETCut");
102     # hists.append("mttbar_allSolutions_withMETCut");
103     #
104     # hists.append("mttbar_withMETAndAsymJets");
105     # hists.append("mttbar_2ndSolution_withMETAndAsymJets");
106     # hists.append("mttbar_3rdSolution_withMETAndAsymJets");
107     # hists.append("mttbar_allSolutions_withMETAndAsymJets");
108     #
109     # hists.append("mttbar_withAsymJetsCut");
110     # hists.append("mttbar_2ndSolution_withAsymJetsCut");
111     # hists.append("mttbar_3rdSolution_withAsymJetsCut");
112     # hists.append("mttbar_allSolutions_withAsymJetsCut");
113     #
114     # hists.append("ttbar_pt");
115     # hists.append("ttbar_pt_2ndSolution");
116     # hists.append("ttbar_pt_3rdSolution");
117     # hists.append("ttbar_pt_allSolutions");
118     #
119     # hists.append("ttbar_pt_withMETCut");
120     # hists.append("ttbar_pt_2ndSolution_withMETCut");
121     # hists.append("ttbar_pt_3rdSolution_withMETCut");
122     # hists.append("ttbar_pt_allSolutions_withMETCut");
123     #
124     # hists.append("ttbar_pt_withMETAndAsymJets");
125     # hists.append("ttbar_pt_2ndSolution_withMETAndAsymJets");
126     # hists.append("ttbar_pt_3rdSolution_withMETAndAsymJets");
127     # hists.append("ttbar_pt_allSolutions_withMETAndAsymJets");
128     #
129     # hists.append("ttbar_pt_withAsymJetsCut");
130     # hists.append("ttbar_pt_2ndSolution_withAsymJetsCut");
131     # hists.append("ttbar_pt_3rdSolution_withAsymJetsCut");
132     # # hists.append("ttbar_pt_allSolutions_withAsymJetsCut");
133     # hists.append("angleTops");
134     # hists.append("angleTops_withMETCut");
135     # hists.append("angleTops_withMETAndAsymJets");
136     # hists.append("angleTops_withAsymJetsCut");
137     #
138     hists.append("leadingJetPt");
139     hists.append("nextLeadingJetPt");
140     hists.append("trailingJetPt");
141     # hists.append("pt_leadingTop");
142     # hists.append("pt_loneLepTop");
143     # hists.append("pt_lepTop");
144     # hists.append("pt_hadTop");
145     # hists.append("pt_loneHadTop");
146     # hists.append("pt_leadingTop_withMETCut");
147     # hists.append("pt_leadingTop_withMETAndAsymJets");
148     # hists.append("pt_leadingTop_withAsymJetsCut");
149     #
150     # hists.append("pt_NextToLeadingTop");
151     # hists.append("pt_NextToLeadingTop_withMETCut");
152     # hists.append("pt_NextToLeadingTop_withMETAndAsymJets");
153     # hists.append("pt_NextToLeadingTop_withAsymJetsCut");
154     #
155     # hists.append("mAllTop");
156     #
157     # hists.append("ttbar_px");
158     # hists.append("ttbar_py");
159     # hists.append("ttbar_pz");
160     #
161     # hists.append("m3");
162     # hists.append("HT");
163     # hists.append("qkjet_eta");
164     # hists.append("qkjet_rapid");
165     # hists.append("leadjet_rap");
166     # hists.append("lepb_angle");
167     # hists.append("angleHadTopD");
168     hists.append("wpmassplus");
169     hists.append("wpmassminus");
170     # hists.append("MET");
171     # hists.append("METtopangle_ltop");
172     # hists.append("HT3jet_ltop");
173     # hists.append("HT4jet_ltop");
174     # hists.append("mt2jbothchglep4j");
175     # hists.append("mt2jbothchgelec4j");
176     # hists.append("mt2jbothchgmu4j");
177     # hists.append("mt2jbothchglep5j");
178     # hists.append("mt2jbothchgmu5j");
179     # hists.append("mt2jbothchgelec5j");
180     # hists.append("mt2jpluselec4j");
181     # hists.append("mt2jplusmu4j");
182     # hists.append("mt2jpluslep4j");
183     # hists.append("mt2jpluslep5j");
184     # hists.append("mt2jpluselec5j");
185     # hists.append("mt2jplusmu5j");
186     # hists.append("mt2jminuselec4j");
187     # hists.append("mt2jminusmu4j");
188     # hists.append("mt2jminuslep4j");
189     # hists.append("mt2jminuselec5j");
190     # hists.append("mt2jminusmu5j");
191     # hists.append("mt2jminuslep5j");
192     # hists.append("mt4jbothchglep4j");
193     # hists.append("mt4jbothchgelec4j");
194     # hists.append("mt4jbothchgmu4j");
195     # hists.append("mt4jbothchglep5j");
196     # hists.append("mt4jbothchgmu5j");
197     # hists.append("mt4jbothchgelec5j");
198     # hists.append("mt4jpluselec4j");
199     # hists.append("mt4jplusmu4j");
200     # hists.append("mt4jpluslep4j");
201     # hists.append("mt4jpluslep5j");
202     # hists.append("mt4jpluselec5j");
203     # hists.append("mt4jplusmu5j");
204     # hists.append("mt4jminuselec4j");
205     # hists.append("mt4jminusmu4j");
206     # hists.append("mt4jminuslep4j");
207     # hists.append("mt4jminuselec5j");
208     # hists.append("mt4jminusmu5j");
209     # hists.append("mt4jminuslep5j");
210     # hists.append("leadingJetMass");
211     # hists.append("mtW");
212     # hists.append("neutrino_pz");
213     # hists.append("lone_neutrino_pz");
214     suffixes = ["0orMoreBtag",
215     "1orMoreBtag",
216     "2orMoreBtags",
217     "3orMoreBtags",'4orMoreBtags' ]
218     hists = [hist + '_' + suffix for hist in hists for suffix in suffixes]
219    
220     histslep = [];
221     # histslep.append("HT_ltop");
222     histslep.append("MET_ltop");
223     histslep.append("METpt_ltop");
224     # histslep.append("mass4jets");
225     # histslep.append("ST_ltop");
226     histslep.append("mLeptonicTop");
227     histslep.append("mHadronicTop");
228     histslep.append("mHadTopLone");
229     histslep.append("mLepTopLone");
230     histslep.append("mHadTopLonepos");
231     histslep.append("mLepTopLonepos");
232     histslep.append("mHadTopLoneneg");
233     histslep.append("mLepTopLoneneg");
234     histslep.append("wpmass");
235     histslep.append("wpnegmass");
236     histslep.append("wpnegmassbad");
237     histslep.append("wpnegmasspos");
238     histslep.append("wpnegmassneg");
239     histslep.append("wp1topmass");
240     histslep.append("wp1topmassbad");
241     histslep.append("wp1topmasspos");
242     histslep.append("wp1topmassbadpos");
243     histslep.append("wp1topmassneg");
244     histslep.append("wp1topmassbadneg");
245     # histslep.append("wpanglmass");
246     histslep.append("tausInJets");
247     histslep.append("numTaus");
248     histslep.append("deltaPhiTops");
249     histslep.append("deltaphilepjetpos");
250     histslep.append("deltaphilepdjetpos");
251     histslep.append("deltaphilepjetneg");
252     histslep.append("deltaphilepdjetneg");
253     # histslep.append("numHadTopDauMCMatches");
254     # histslep.append("numLepTopDauMCMatches");
255     histslep.append("numHadTopDauMCMatches2top");
256     histslep.append("numLepTopDauMCMatches2top");
257     histslep.append("numGenJets");
258     histslep.append("numDiffJets");
259     histslep.append("missGenJets");
260     histslep.append("missRecoJets");
261     # histslep.append("transMasslm1b");
262     suffixes = ["elec", "mu", "lepton"]
263     histslep = [hist + '_' + suffix for hist in histslep for suffix in suffixes]
264    
265     hists += histslep;
266     print hists
267     hists.append("eleciso");
268     hists.append("looseeleciso");
269     hists.append("muiso");
270     # hists.append("electron_et");
271     hists.append("elvertdist");
272     hists.append("muvertdist");
273     hists.append("jetmultip");
274     # hists.append("electminus_pt");
275     # hists.append("positron_pt");
276     hists.append("electron_pt");
277     # hists.append("muon_et");
278     hists.append("muon_pt");
279    
280     # jetBinned = ["allJets",
281     # "1orMoreJets",
282     # "2orMoreJets",
283     # "3orMoreJets" , "4orMoreJets"]
284     # jetBinnedhists = []
285     # jetBinnedhists.append("QCDest_CombRelIso")
286     # jetBinnedhists.append("QCDest_CombRelIso_1btag")
287     # jetBinnedhists.append("QCDest_CombRelIso_2btag")
288     # jetBinnedhists.append("QCDest_CombRelIso_controlRegion")
289     # jetBinnedhists.append("QCDest_CombRelIso_controlRegion_1btag")
290     # jetBinnedhists.append("QCDest_CombRelIso_controlRegion_2btag")
291     #
292     # jetBinnedhists.append("QCDest_PFIsolation")
293     # jetBinnedhists.append("QCDest_PFIsolation_WithMETCut")
294     # jetBinnedhists.append("QCDest_PFIsolation_WithMETCutAndAsymJetCuts")
295     # jetBinnedhists.append("QCDest_PFIsolation_WithAsymJetCuts")
296    
297     # jetBinnedhists.append("QCDest_PFIsolation_1btag")
298     # jetBinnedhists.append("QCDest_PFIsolation_2btag")
299     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion")
300     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion_1btag")
301     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion_2btag")
302     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion2")
303     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion2_WithMETCut")
304     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion2_WithMETCutAndAsymJetCuts")
305     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion2_WithAsymJetCuts")
306     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion2_1btag")
307     # jetBinnedhists.append("QCDest_PFIsolation_controlRegion2_2btag")
308    
309     # jetBinnedhists = [hist + '_' + suffix for hist in jetBinnedhists for suffix in jetBinned]
310     # hists.extend(jetBinnedhists)
311     gcd = gROOT.cd
312    
313     for histname in hists:
314     currentSelection = 'default'
315     if 'withMETAndAsymJets' in histname:
316     currentSelection = 'withMETAndAsymJets'
317     gcd()
318     print histname
319     # hist_data = data.Get(histname);
320    
321     # hist_data2;
322     # if (histname == "mttbar_rebinned")
323     # hist_data2 = data2.Get(histname);
324     # else
325     # hist_data2 = TH1F(*hist_data);
326     # hist_data.Sumw2();
327     # hist_data2.Sumw2();
328     hist_ttbar = ttbar.Get(histname);
329     # hist_wjets = wjets.Get(histname);
330     # hist_zjets = zjets.Get(histname);
331    
332     # hist_bce1 = bce1.Get(histname);
333     # hist_bce2 = bce2.Get(histname);
334     # hist_bce3 = bce3.Get(histname);
335     # hist_enri1 = enri1.Get(histname);
336     # hist_enri2 = enri2.Get(histname);
337     # hist_enri3 = enri3.Get(histname);
338     # # hist_pj1 = pj1.Get(histname);
339     # # hist_pj2 = pj2.Get(histname);
340     # hist_pj3 = pj3.Get(histname);
341     # hist_singleTop = tW.Get(histname)
342     # hist_singleTop.Add(tchan.Get(histname))
343    
344     # hist_Zprime500 = Zprime500.Get(histname);
345     # hist_Zprime750 = Zprime750.Get(histname);
346     # hist_Zprime1000 = Zprime1000.Get(histname);
347     # hist_Zprime1500 = Zprime1500.Get(histname);
348     # hist_Zprime2000 = Zprime2000.Get(histname);
349     # hist_Zprime4000 = Zprime4000.Get(histname);
350     # hist_Tprime300 = Tprime300.Get(histname);
351     # hist_Tprime350 = Tprime350.Get(histname);
352     # # hist_Zprime1250 = Zprime1250.Get(histname);
353     # hist_wpm400 = WprimeTToTTD_M400.Get(histname);
354     hist_wpm600 = WprimeTToTTD_M600.Get(histname);
355     # hist_wpm800 = WprimeTToTTD_M800.Get(histname);
356     # hist_wpm1000 = WprimeTToTTD_M1000.Get(histname);
357     # hist_wptb1000 = WprimeToTTBbar_M1000.Get(histname);
358    
359     # hist_ttbar.Sumw2(); # No good, must be done before filling
360    
361     # if ('iso' in histname or 'jetmultip' in histname or 'DeltaR' in histname or ('num' in histname and 'Top' in histname)):
362     if ('looseeleciso' in histname or 'tau' in histname or 'DeltaR' in histname or ('num' in histname and 'Top' in histname)):
363     numevts = hist_ttbar.Integral();
364     if (numevts > 0):
365     hist_ttbar.Scale(1.0/numevts);
366     # numevts = hist_wpm400.Integral();
367     # hist_wpm400.Scale(1.0/numevts);
368     numevts = hist_wpm600.Integral();
369     hist_wpm600.Scale(1.0/numevts);
370     # numevts = hist_wpm800.Integral();
371     # hist_wpm800.Scale(1.0/numevts);
372     # numevts = hist_wpm1000.Integral();
373     # hist_wpm1000.Scale(1.0/numevts);
374     else:
375     hist_ttbar.Scale(scale);
376     # hist_wpm400.Scale(scale);
377     hist_wpm600.Scale(scale);
378     # hist_wpm1000.Scale(scale);
379     # hist_wpm800.Scale(scale);
380     # hist_wjets.Scale(scale);
381    
382     # hist_wjets.Scale(scale);
383     # hist_zjets.Scale(scale);
384    
385     # hist_bce1.Scale(scale);
386     # hist_bce2.Scale(scale);
387     # hist_bce3.Scale(scale);
388    
389     # hist_enri1.Scale(scale);
390     # hist_enri2.Scale(scale);
391     # hist_enri3.Scale(scale);
392    
393     # hist_pj1.Scale(scale);
394     # hist_pj2.Scale(scale);
395     # hist_pj3.Scale(scale);
396    
397     # scale = scale * 10.0;
398     # hist_Zprime500.Scale(scale);
399     # hist_Zprime750.Scale(scale);
400     # hist_Zprime1000.Scale(scale);
401     # hist_Zprime2000.Scale(scale);
402     # hist_Zprime1500.Scale(scale);
403     # hist_Zprime4000.Scale(scale);
404     # hist_Tprime300.Scale(scale);
405     # hist_Tprime350.Scale(scale);
406     # hist_Zprime1250.Scale(scale);
407     # hist_wptb1000.Scale(scale);
408    
409    
410     # hist_qcd = hist_bce1.Clone("qcd")#TH1F(*hist_bce1);
411     # hist_qcd.Add(hist_bce2);
412     # hist_qcd.Add(hist_bce3);
413     # hist_qcd.Add(hist_enri1);
414     # hist_qcd.Add(hist_enri2);
415     # hist_qcd.Add(hist_enri3);
416     # hist_qcd.Add(hist_pj1);
417     # hist_qcd.Add(hist_pj2);
418     # hist_qcd.Add(hist_pj3);
419     # hist_qcd.Scale(qcdScale[currentSelection]);
420     # ndata = hist_data.Integral();
421     # ntop = hist_ttbar.Integral();
422     # nwj = hist_wjets.Integral();
423     # nzj = hist_zjets.Integral();
424     # nqcd = hist_qcd.Integral();
425     # sumMC = ntop + nwj + nzj + nqcd;
426     # cout << ndata << " " << sumMC << endl;
427     # hist_wjets.Scale(ndata / sumMC);
428     # hist_ttbar.Scale(ndata / sumMC);
429     # hist_zjets.Scale(ndata / sumMC);
430     # hist_qcd.Scale(ndata / sumMC);
431     # mttbars = ['mttbar_' + suffix for suffix in suffixes]
432     # mttbars2 = ['mttbar_withMETAndAsymJets_' + suffix for suffix in suffixes]
433     # if histname in mttbars or histname in mttbars2:
434     # print "taking QCD shape from DATA"
435     # name = histname.replace('mttbar', 'mttbar_conversions')
436     # hist_qcd = data.Get(name)
437     # if( hist_qcd.Integral() > 0):
438     # hist_qcd.Scale(nqcd/hist_qcd.Integral())
439     # hist_mc = hist_qcd.Clone("all_mc")
440     # hist_mc.Add(hist_ttbar);
441     # hist_mc.Add(hist_zjets);
442     # hist_mc.Add(hist_wjets);
443     # hist_mc.Add(hist_singleTop);
444    
445     hist_data = hist_ttbar.Clone("test");
446     rebin = 1;
447     Urange = (0,5000)
448     Yrange = (0,0)
449    
450     if ("mttbar" in histname):
451     hist_data.SetXTitle("M_{t#bar{t}}/GeV");
452     hist_data.SetYTitle("Events/(100 GeV)");
453     rebin = 100;
454     Urange = (0, 2000)
455     elif ("tPrimeMass" in histname):
456     hist_data.SetXTitle("T' mass/GeV");
457     hist_data.SetYTitle("Events/(100 GeV)");
458     rebin = 200;
459     Urange = (0, 2000)
460     elif ("wpmass" in histname or "wpnegmass" in histname or "wpanglmass" in histname or "wp1top" in histname):
461     hist_data.SetXTitle("W' mass/GeV");
462     hist_data.SetYTitle("Events/(60 GeV)");
463     rebin = 60;
464     Urange = (0, 1500)
465     elif ("jet12" in histname or "jet13" in histname):
466     hist_data.SetXTitle("Jet mass/GeV");
467     hist_data.SetYTitle("Jet mass/GeV)");
468     elif ("tPrimepT" in histname):
469     hist_data.SetXTitle("T' pT/GeV");
470     hist_data.SetYTitle("Events/(8 GeV)");
471     rebin = 8;
472     Urange = (0, 200)
473     elif ("tPrimeHT" in histname):
474     hist_data.SetXTitle("T' HT");
475     hist_data.SetYTitle("Events");
476     rebin = 4;
477     Urange = (0, 1.5)
478     elif ("m3" in histname):
479     hist_data.SetXTitle("M3/GeV");
480     hist_data.SetYTitle("Events/(50 GeV)");
481     rebin = 50;
482     Urange = (0, 1500)
483     elif (histname == "electron_et"):
484     hist_data.SetXTitle("electron E_{T}/GeV");
485     hist_data.SetYTitle("Events/(10 GeV)");
486     rebin = 10;
487     Urange = (0, 300)
488     elif (histname == "electron_pt" or histname == "electminus_pt" or histname == "positron_pt"):
489     hist_data.SetXTitle("electron p_{T}/GeV");
490     hist_data.SetYTitle("Events/(10 GeV)");
491     rebin = 10;
492     Urange = (0, 300)
493     elif (histname == "muon_et"):
494     hist_data.SetXTitle("muon E_{T}/GeV");
495     hist_data.SetYTitle("Events/(10 GeV)");
496     rebin = 10;
497     Urange = (0, 300)
498     elif (histname == "muon_pt"):
499     hist_data.SetXTitle("muon p_{T}/GeV");
500     hist_data.SetYTitle("Events/(10 GeV)");
501     rebin = 10;
502     Urange = (0, 300)
503     elif ("ttbar_pt" in histname):
504     hist_data.SetXTitle("p_{T} of t#bar{t} system/GeV");
505     hist_data.SetYTitle("Events/(10 GeV)");
506     rebin = 10;
507     Urange = (0, 500)
508     elif ("ttbar_px" in histname):
509     hist_data.SetXTitle("p_{x} of t#bar{t} system/GeV");
510     hist_data.SetYTitle("Events/(10 GeV)");
511     rebin = 10;
512     Urange = (0, 500)
513     elif ("ttbar_py" in histname):
514     hist_data.SetXTitle("p_{y} of t#bar{t} system/GeV");
515     hist_data.SetYTitle("Events/(10 GeV)");
516     rebin = 10;
517     Urange = (0, 500)
518     elif ("ttbar_pz" in histname):
519     hist_data.SetXTitle("p_{z} of t#bar{t} system/GeV");
520     hist_data.SetYTitle("Events/(50 GeV)");
521     rebin = 50;
522     Urange = (0, 2000)
523     elif ("METpt_ltop" in histname):
524     hist_data.SetXTitle("MET p_{T}/GeV");
525     hist_data.SetYTitle("Events/(20 GeV)");
526     rebin = 20;
527     Urange = (0, 400)
528     elif ("tPrime_pt" in histname):
529     hist_data.SetXTitle("p_{T} of T' system/GeV");
530     hist_data.SetYTitle("Events/(20 GeV)");
531     rebin = 20;
532     Urange = (0, 200)
533     elif ("tPrime_px" in histname):
534     hist_data.SetXTitle("p_{x} of T' system/GeV");
535     hist_data.SetYTitle("Events/(20 GeV)");
536     rebin = 20;
537     Urange = (0, 200)
538     elif ("tPrime_py" in histname):
539     hist_data.SetXTitle("p_{y} of T' system/GeV");
540     hist_data.SetYTitle("Events/(20 GeV)");
541     rebin = 20;
542     Urange = (0, 200)
543     elif ("tPrime_pz" in histname):
544     hist_data.SetXTitle("p_{z} of T' system/GeV");
545     hist_data.SetYTitle("Events/(100 GeV)");
546     rebin = 200;
547     Urange = (0, 1800)
548     elif ("HT_" in histname):
549     hist_data.SetXTitle("#Sigma p_{T}/GeV");
550     hist_data.SetYTitle("Events/(20 GeV)");
551     rebin = 20;
552     Urange = (0, 2000)
553     elif ("ST" in histname):
554     hist_data.SetXTitle("ST/GeV");
555     hist_data.SetYTitle("Events/(30 GeV)");
556     rebin = 30;
557     Urange = (0, 1000)
558     elif ("HT3jet_ltop" in histname):
559     hist_data.SetXTitle("#Sigma p_{T} of leading 3 jets/GeV");
560     hist_data.SetYTitle("Events/(20 GeV)");
561     rebin = 20;
562     Urange = (0, 1000)
563     elif ("HT4jet_ltop" in histname):
564     hist_data.SetXTitle("#Sigma p_{T} of leading 4 jets/GeV");
565     hist_data.SetYTitle("Events/(50 GeV)");
566     rebin = 50;
567     Urange = (0, 1200)
568     elif (histname == "numberOfJets"):
569     hist_data.SetXTitle("number of jets");
570     hist_data.SetYTitle("Events");
571     elif (histname == "numberOfBJets"):
572     hist_data.SetXTitle("number of b-tagged jets (SSVHE medium)");
573     hist_data.SetYTitle("Events");
574     elif ('MET_' in histname and 'MET_ltop' not in histname):
575     hist_data.SetXTitle("MET/GeV");
576     hist_data.SetYTitle("Events/(5 GeV)");
577     rebin = 5;
578     Urange = (0, 400)
579     elif ('MET_ltop' in histname):
580     hist_data.SetXTitle("MET/GeV");
581     hist_data.SetYTitle("Events/(20 GeV)");
582     rebin = 20;
583     Urange = (0, 400)
584     elif ("leadingJetMass" in histname):
585     hist_data.SetXTitle("leading jet mass/GeV");
586     hist_data.SetYTitle("Events/(5 GeV)");
587     rebin = 5;
588     Urange = (0, 150)
589     elif ("mtW" in histname):
590     hist_data.SetXTitle("transverse W-boson mass/GeV");
591     hist_data.SetYTitle("Events/(10 GeV)");
592     rebin = 10;
593     elif ("both" in histname or "plus" in histname or "minus" in histname):
594     hist_data.SetXTitle("transverse mass/GeV");
595     hist_data.SetYTitle("Events/(100 GeV)");
596     rebin = 100;
597     Urange = (0, 2000)
598     elif ("transMasslm1b" in histname):
599     hist_data.SetXTitle("M_{T} (lep+MET+1b)/GeV");
600     hist_data.SetYTitle("Events/(50 GeV)");
601     rebin = 50;
602     Urange = (0, 700)
603     elif ("electronD0" in histname):
604     hist_data.SetXTitle("electron d_{0} / cm");
605     hist_data.SetYTitle("Events/(0.001 cm)");
606     rebin = 10;
607     elif ("angleTops" in histname or "deltaPhiTops" in histname):
608     hist_data.SetXTitle("angle between top quarks");
609     hist_data.SetYTitle("Events/(0.1 rad)");
610     rebin = 10;
611     elif ( "deltaphilep" in histname):
612     hist_data.SetXTitle("angle between lepton & leading jet");
613     hist_data.SetYTitle("Events/(0.2 rad)");
614     rebin = 20;
615     elif ("lepb_angle" in histname):
616     hist_data.SetXTitle("angle between electron and b jet");
617     hist_data.SetYTitle("Events/(0.1 rad)");
618     rebin = 10;
619     elif ("angleHadTopD" in histname):
620     hist_data.SetXTitle("angle between hadronic top and light jet");
621     hist_data.SetYTitle("Events/(0.2 rad)");
622     rebin = 20;
623     elif ("METtopangle_ltop" in histname):
624     hist_data.SetXTitle("angle between MET and top p_{T}");
625     hist_data.SetYTitle("Events/(0.1 rad)");
626     rebin = 10;
627     Urange = (-2, 2)
628     elif ("qkjet_eta" in histname):
629     hist_data.SetXTitle("#eta of b jet");
630     hist_data.SetYTitle("Events/(0.1 rad)");
631     Urange = (-3, 3)
632     rebin = 10;
633     elif ("_rap" in histname):
634     hist_data.SetXTitle("Jet Rapidity");
635     hist_data.SetYTitle("Events/(0.1 rad)");
636     Urange = (-3, 3)
637     rebin = 20;
638     elif ("neutrino_pz" in histname):
639     hist_data.SetXTitle("neutrino p_{Z} /GeV");
640     hist_data.SetYTitle("Events/(20 GeV)");
641     rebin = 20;
642     Urange = (-500, 500)
643     elif ('mHadTopLoneNM' in histname):
644     hist_data.SetXTitle("top mass /GeV");
645     hist_data.SetYTitle("Events/(10 GeV)");
646     rebin = 10;
647     Urange = (0, 400)
648     elif ('mass4jets' in histname):
649     hist_data.SetXTitle("4-jet mass /GeV");
650     hist_data.SetYTitle("Events/(50 GeV)");
651     rebin = 50;
652     Urange = (0, 1500)
653     elif ('mLepTopLoneNM' in histname):
654     hist_data.SetXTitle("top mass /GeV");
655     hist_data.SetYTitle("Events/(10 GeV)");
656     rebin = 10;
657     Urange = (0, 400)
658     elif ('chiHadronicTop' in histname or 'chiLeptonicTop' in histname):
659     hist_data.SetXTitle("top #chi^{2} /GeV");
660     hist_data.SetYTitle("Events/(1)");
661     rebin = 1;
662     Urange = (0, 30)
663     elif ('chiGlobal' in histname or 'chiTotal' in histname):
664     hist_data.SetXTitle("Event #chi^{2} /GeV");
665     hist_data.SetYTitle("Events/(100)");
666     rebin = 100;
667     elif ('numHadTopMCMatches' in histname or 'numLepTopMCMatches' in histname):
668     hist_data.SetXTitle("Number of Exact Decay-Chain Matches");
669     hist_data.SetYTitle("Events");
670     Yrange = (0, 1.1)
671     elif ('numHadTopDauMCMatches' in histname or 'numLepTopDauMCMatches' in histname):
672     hist_data.SetXTitle("Number of Top Daughter Matches");
673     hist_data.SetYTitle("Events");
674     Yrange = (0, 1.1)
675     elif ('numHadTopCorrectID' in histname or 'numLepTopCorrectID' in histname):
676     hist_data.SetXTitle("Number of Reco Candidates Matched to MC-Truth Particles");
677     hist_data.SetYTitle("Events");
678     Yrange = (0, 1.1)
679     elif ('lepTopDeltaR' in histname or 'hadTopDeltaR' in histname):
680     hist_data.SetXTitle("#Delta R of MC truth top");
681     hist_data.SetYTitle("Events");
682     rebin = 20;
683     # Urange = (0, 4)
684     elif ('lepTopLep' in histname or 'hadTopHad' in histname):
685     hist_data.SetXTitle("top MC truth identity");
686     hist_data.SetYTitle("Events");
687     Urange = (0, 2)
688     elif ('mHadTopLone' in histname or 'mHadronicTop' in histname or 'mAllTop' in histname):
689     hist_data.SetXTitle("top mass /GeV");
690     hist_data.SetYTitle("Events/(15 GeV)");
691     rebin = 15;
692     Urange = (0, 700)
693     elif ('mLepTopLone' in histname or 'mLeptonicTop' in histname):
694     hist_data.SetXTitle("top mass /GeV");
695     hist_data.SetYTitle("Events/(15 GeV)");
696     rebin = 15;
697     Urange = (0, 700)
698     elif ('pt_' in histname and 'Top' in histname):
699     hist_data.SetXTitle("top p_{T} /GeV");
700     hist_data.SetYTitle("Events/(50 GeV)");
701     rebin = 50;
702     Urange = (0, 500)
703     elif ('trailingJetPt' in histname):
704     hist_data.SetXTitle("Jet p_{T} /GeV");
705     hist_data.SetYTitle("Events/(25 GeV)");
706     rebin = 30;
707     Urange = (0, 270)
708     elif ('JetPt' in histname):
709     hist_data.SetXTitle("Jet p_{T} /GeV");
710     hist_data.SetYTitle("Events/(50 GeV)");
711     rebin = 50;
712     Urange = (0, 600)
713     elif('QCDest_CombRelIso' in histname):
714     hist_data.SetXTitle("relative isolation");
715     hist_data.SetYTitle("Events/(0.1)");
716     rebin = 10;
717     Urange = (0, 2)
718     elif('QCDest_PFIsolation' in histname):
719     hist_data.SetXTitle("ParticleFlow isolation");
720     hist_data.SetYTitle("Events/(0.1)");
721     rebin = 10
722     Urange = (0, 2)
723     elif('iso' in histname):
724     hist_data.SetXTitle("ParticleFlow Isolation");
725     hist_data.SetYTitle("Events/(0.02)");
726     rebin = 4
727     Urange = (0, 0.5)
728     elif('vertdist' in histname):
729     hist_data.SetXTitle("Steps from PV");
730     hist_data.SetYTitle("Events");
731     # rebin = 200
732     Urange = (0, 2)
733     elif('jetmultip' in histname):
734     hist_data.SetXTitle("Number of jets");
735     hist_data.SetYTitle("Events");
736     # rebin = 60
737     Urange = (0, 11)
738     elif('tausInJets' in histname):
739     hist_data.SetXTitle("Number of tau jets");
740     hist_data.SetYTitle("Events");
741     # rebin = 60
742     Urange = (0, 3)
743     elif('numTaus' in histname):
744     hist_data.SetXTitle("Number of taus");
745     hist_data.SetYTitle("Events");
746     # rebin = 60
747     Urange = (0, 15)
748     elif('numGenJets' in histname):
749     hist_data.SetXTitle("Number of GenJets");
750     hist_data.SetYTitle("Events");
751     # rebin = 60
752     Urange = (3, 15)
753     elif('numDiffJets' in histname):
754     hist_data.SetXTitle("Difference between Reco Jets & GenJets");
755     hist_data.SetYTitle("Events");
756     # rebin = 60
757     Urange = (-7, 4)
758     elif('miss' in histname and 'Jets' in histname):
759     if('miss' in histname and 'missGenJets' in histname):
760     hist_data.SetXTitle("Number of Unmatched Reco Jets");
761     else:
762     hist_data.SetXTitle("Number of Unmatched GenJets");
763     hist_data.SetYTitle("Events");
764     # rebin = 60
765     Urange = (0, 8)
766    
767    
768     hist_data.SetTitleOffset(1.5, "Y");
769     if ('jet1' in histname):
770     hist_data.Rebin2D();
771     hist_ttbar.Rebin2D();
772     hist_Tprime300.Rebin2D();
773     hist_Tprime350.Rebin2D();
774     hist_data.SetAxisRange(0, 600, "X");
775     hist_data.SetAxisRange(0, 600, "Y");
776     hist_ttbar.SetAxisRange(0, 600, "X");
777     hist_ttbar.SetAxisRange(0, 600, "Y");
778     # hist_Tprime300.SetAxisRange(0, 600, "X");
779     # hist_Tprime300.SetAxisRange(0, 600, "Y");
780     # hist_Tprime350.SetAxisRange(0, 600, "X");
781     # hist_Tprime350.SetAxisRange(0, 600, "Y");
782     else:
783     hist_data.Rebin(rebin);
784     hist_ttbar.Rebin(rebin);
785     # hist_wjets.Rebin(rebin);
786     # hist_zjets.Rebin(rebin);
787     # hist_qcd.Rebin(rebin);
788     # hist_Zprime500.Rebin(rebin);
789     # hist_Zprime1500.Rebin(rebin);
790     # hist_Zprime750.Rebin(rebin);
791     # hist_Zprime1000.Rebin(rebin);
792     # hist_Zprime2000.Rebin(rebin);
793     # hist_Zprime4000.Rebin(rebin);
794     # hist_Tprime300.Rebin(rebin);
795     # hist_Tprime350.Rebin(rebin);
796     # hist_singleTop.Rebin(rebin)
797     # hist_wpm400.Rebin(rebin);
798     hist_wpm600.Rebin(rebin);
799     # hist_wpm800.Rebin(rebin);
800     # hist_wpm1000.Rebin(rebin);
801     # hist_wptb1000.Rebin(rebin);
802    
803     hist_data.SetAxisRange(Urange[0], Urange[1]);
804     hist_ttbar.SetAxisRange(Urange[0], Urange[1]);
805     # hist_wjets.SetAxisRange(Urange[0], Urange[1]);
806     # hist_zjets.SetAxisRange(Urange[0], Urange[1]);
807     # hist_qcd.SetAxisRange(Urange[0], Urange[1]);
808     # hist_Zprime500.SetAxisRange(Urange[0], Urange[1]);
809     # hist_Zprime750.SetAxisRange(Urange[0], Urange[1]);
810     # hist_Zprime1000.SetAxisRange(Urange[0], Urange[1]);
811     # hist_Zprime1500.SetAxisRange(Urange[0], Urange[1]);
812     # hist_Zprime2000.SetAxisRange(Urange[0], Urange[1]);
813     # hist_Zprime4000.SetAxisRange(Urange[0], Urange[1]);
814     # hist_Tprime300.SetAxisRange(Urange[0], Urange[1]);
815     # hist_Tprime350.SetAxisRange(Urange[0], Urange[1]);
816     # hist_singleTop.SetAxisRange(Urange[0], Urange[1]);
817     # hist_wpm400.SetAxisRange(Urange[0], Urange[1]);
818     hist_wpm600.SetAxisRange(Urange[0], Urange[1]);
819     # hist_wpm800.SetAxisRange(Urange[0], Urange[1]);
820     # hist_wpm1000.SetAxisRange(Urange[0], Urange[1]);
821     # hist_wptb1000.SetAxisRange(Urange[0], Urange[1]);
822    
823    
824     hist_data.SetMarkerStyle(8);
825     # hist_data.SetMarkerSize(1.5);
826     hist_data.SetMarkerSize(0.1);
827    
828     # hist_data.SetFillStyle(1001);
829     # hist_data.SetFillColor(kRed);
830     hist_ttbar.SetFillStyle(1001);
831     hist_ttbar.SetFillColor(kRed);
832     # hist_wjets.SetFillStyle(1001);
833     # hist_wjets.SetFillColor(4);
834     # hist_zjets.SetFillStyle(1001);
835     # hist_zjets.SetFillColor(8);
836     # hist_qcd.SetFillStyle(1001);
837     # hist_qcd.SetFillColor(kYellow);
838     # hist_qcd.SetFillColor(12);
839     # hist_singleTop.SetFillStyle(1001);
840     # hist_singleTop.SetFillColor(kMagenta)
841     # nbins = hist_qcd.GetXaxis().GetNbins();
842     # binwidth = (hist_qcd.GetXaxis().GetXmax() - hist_qcd.GetXaxis().GetXmin()) / nbins;
843     # for i in range(1, nbins + 1):
844     # yvalue = hist_qcd.GetBinContent(i);
845     # # float xvalue = hist_qcd.GetBinCenter(i);
846     # # float ymin = yvalue - yvalue*0.5;
847     # # float ymax = yvalue + yvalue*0.5;
848     # # float xmin = xvalue - 0.5*binwidth;
849     # # float xmax = xvalue + 0.5*binwidth;
850     # error = yvalue * 0.5;
851     # hist_mc.SetBinError(i, error);
852     # # qcdUncert.SetPointError(i, xmin, xmax, ymin, ymax);
853     #
854     # qcdUncert = TGraphAsymmErrors(hist_mc);
855    
856     linewidth = 6;
857     # hist_Zprime500.SetLineColor(6);
858     # hist_Zprime500.SetLineWidth(linewidth);
859     # hist_Zprime500.SetFillStyle(0);
860     # hist_Zprime500.SetFillColor(kWhite);
861    
862     # hist_Zprime750.SetLineColor(5);
863     # hist_Zprime750.SetLineWidth(linewidth);
864     # hist_Zprime750.SetFillStyle(0);
865     # hist_Zprime750.SetFillColor(kWhite);
866    
867     # hist_Zprime1000.SetLineColor(7);
868     # hist_Zprime1000.SetLineWidth(linewidth);
869     # hist_Zprime1000.SetFillStyle(0);
870     # hist_Zprime1000.SetFillColor(kWhite);
871     # hist_Zprime2000.SetLineColor(42);
872     # hist_Zprime2000.SetLineWidth(linewidth);
873     # hist_Zprime2000.SetFillStyle(0);
874     # hist_Zprime2000.SetFillColor(kWhite);
875     # # hist_Zprime4000.SetLineColor(50);
876     # hist_Zprime4000.SetLineWidth(linewidth);
877     # hist_Zprime4000.SetFillStyle(0);
878     # hist_Zprime4000.SetFillColor(kWhite);
879    
880     # hist_Tprime300.SetLineColor(kOrange + 1);
881     # hist_Tprime300.SetLineWidth(linewidth);
882     # hist_Tprime350.SetLineColor(kGray + 3);
883     # hist_Tprime350.SetLineWidth(linewidth);
884     #
885     # hist_Zprime1250.SetLineColor(kCyan - 5);
886     # hist_Zprime1250.SetLineWidth(linewidth);
887     # hist_Zprime1250.SetFillStyle(0);
888     # hist_Zprime1250.SetFillColor(kWhite);
889     #
890     # hist_Zprime1500.SetLineColor(42);
891     # hist_Zprime1500.SetLineWidth(linewidth);
892     # hist_Zprime1500.SetFillStyle(0);
893     # hist_Zprime1500.SetFillColor(kWhite);
894    
895     # hist_wpm400.SetLineColor(kGreen + 1);
896     # hist_wpm400.SetLineWidth(linewidth);
897     hist_wpm600.SetLineColor(kGray + 3);
898     hist_wpm600.SetLineWidth(linewidth);
899     # hist_wpm800.SetLineColor(kCyan);
900     # hist_wpm800.SetLineWidth(linewidth);
901     # hist_wpm1000.SetLineColor(kOrange + 1);
902     # hist_wpm1000.SetLineWidth(linewidth);
903     # hist_wptb1000.SetLineColor(kCyan);
904     # hist_wptb1000.SetLineWidth(linewidth);
905    
906     # qcdUncert.SetFillColor(kGray + 3);
907     # qcdUncert.SetFillStyle(3003);
908    
909     leg = TLegend(0.696, 0.35, 0.95, 0.92);
910     leg.SetBorderSize(0);
911     leg.SetLineStyle(0);
912     leg.SetTextFont(42);
913     leg.SetFillStyle(0);
914    
915     # leg.AddEntry(hist_data, "data", "P");
916     # leg.AddEntry(hist_data2, "data(no HLT)", "P");
917     leg.AddEntry(hist_ttbar, "t#bar{t}", "f");
918     # leg.AddEntry(hist_wjets, "W#rightarrowl#nu", "f");
919     # leg.AddEntry(hist_zjets, "Z/#gamma*#rightarrowl^{+}l^{-}", "f");
920     # leg.AddEntry(hist_qcd, "QCD", "F");
921     # leg.AddEntry(hist_qcd, "QCD/#gamma + jets");
922     # leg.AddEntry(hist_singleTop, "Single-Top")
923     # leg.AddEntry(hist_Zprime500, "Z' 0.5TeV (50 pb)", "L");
924     # leg.AddEntry(hist_Zprime750, "Z' 0.75TeV", "L");
925     # leg.AddEntry(hist_Zprime1000, "Z' 1TeV", "L");
926     # leg.AddEntry(hist_Zprime1500, "Z' 1.5TeV (50 pb)", "L");
927     # leg.AddEntry(hist_Zprime2000, "Z' 2TeV", "L");
928     # leg.AddEntry(hist_Zprime4000, "Z' 4TeV (50 pb)", "L");
929     # leg.AddEntry(hist_Tprime300, "T' 300GeV", "L");
930     # leg.AddEntry(hist_Tprime350, "T' 350GeV", "L");
931     # leg.AddEntry(hist_Zprime1250, "Z' 1.25TeV");
932     # if (not 'num' in histname or not 'Top' in histname):
933     # leg.AddEntry(hist_wpm400, "W't .4TeV (32 pb)", "L");
934     leg.AddEntry(hist_wpm600, "W't .6TeV (8 pb)", "L");
935     # if (not 'num' in histname or not 'Top' in histname):
936     # leg.AddEntry(hist_wpm800, "W't .8TeV (2.2 pb)", "L");
937     # leg.AddEntry(hist_wpm1000, "W't 1TeV (0.72 pb)", "L");
938     # leg.AddEntry(hist_wptb1000, "W'-> tb 1TeV (8 pb)", "L");
939    
940    
941     canvases.append(TCanvas("cname" + histname, histname, 1200, 900))
942    
943     # if ('iso' in histname or 'jetmultip' in histname or 'num' in histname and 'Top' in histname):
944     canvases[-1].SetGrid();
945     canvases[-1].cd().SetRightMargin(0.04);
946    
947     if ('jet1' in histname):
948     hist_data.SetMarkerStyle(8);
949     hist_ttbar.SetMarkerStyle(21);
950     hist_ttbar.SetMarkerColor(kRed);
951     hist_Tprime300.SetMarkerColor(kOrange + 1);
952     hist_Tprime300.SetMarkerStyle(22);
953     hist_Tprime350.SetMarkerColor(kGray + 3);
954     hist_Tprime350.SetMarkerStyle(3);
955     else:
956     hs = THStack("MC", "MC");
957     # hs.Add(hist_qcd);
958     # hs.Add(hist_zjets);
959     # hs.Add(hist_wjets);
960     # hs.Add(hist_singleTop);
961     hs.Add(hist_ttbar);
962     max = 0
963     if hs.GetMaximum() > hist_data.GetMaximum():
964     max = hs.GetMaximum()*1.1
965     else:
966     max = hist_data.GetMaximum()*1.1
967     if hist_wpm600.GetMaximum() > max :
968     max = hist_wpm600.GetMaximum() * 1.1
969     # if hist_wpm400.GetMaximum() > max :
970     # max = hist_wpm400.GetMaximum() * 1.1
971    
972     if (false and 'wp1topmass' in histname):
973     hist_data.GetYaxis().SetRangeUser(0, 310);
974     elif (false and 'mLepTopLone' in histname):
975     hist_data.GetYaxis().SetRangeUser(0, 510);
976     elif (false and 'mHadTopLone' in histname):
977     hist_data.GetYaxis().SetRangeUser(0, 400);
978     elif ('jetmultip' in histname):
979     hist_data.GetYaxis().SetRangeUser(0, 1600);
980     elif ('looseeleciso' in histname):
981     hist_data.GetYaxis().SetRangeUser(0, 0.2);
982     else:
983     hist_data.GetYaxis().SetRangeUser(0, max);
984     # hist_data.SetStats(1); # SetOptStat at start turns on stats
985     # hist_data.Draw('error');
986     # if ('iso' in histname):
987     # canvases[-1].SetLogy();
988     hist_data.Draw("hist");
989     hist_data.SetMarkerStyle(8);
990     if ('jet1' in histname):
991     hist_ttbar.Draw("same");
992     else:
993     hs.Draw("hist same");
994     # hist_Zprime500.Draw("same");
995     # hist_Zprime750.Draw("same");
996     # hist_Zprime1000.Draw("same");
997     # hist_Zprime2000.Draw("same");
998     # hist_Zprime4000.Draw("same");
999     # hist_Tprime300.Draw("same");
1000     # hist_Tprime350.Draw("same");
1001     # hist_Zprime1250.Draw("same");
1002     # hist_Zprime1500.Draw("same");
1003     hist_wpm600.Draw("hist same");
1004     # if (not 'num' in histname or not 'Top' in histname):
1005     #hist_wpm400.Draw("hist same");
1006     # hist_wpm800.Draw("hist same");
1007     # hist_wpm1000.Draw("hist same");
1008     # hist_wptb1000.Draw("same");
1009     # qcdUncert.Draw("1 same");
1010     # hist_data2.Draw("error same");
1011     # hist_data.Draw("error same");
1012     # hist_data.Draw("same");
1013     leg.Draw();
1014    
1015     text1 = TLatex(3.570061, 23.08044, "CMS Preliminary");
1016     text1.SetNDC();
1017     text1.SetTextAlign(13);
1018     text1.SetX(0.38);
1019     text1.SetY(0.928);
1020     #text1.SetLineWidth(2);
1021     text1.SetTextFont(42);
1022     text1.SetTextSizePixels(24);# dflt=28
1023     text1.SetTextSize(0.03);
1024     text1.Draw();
1025    
1026     text2 = TLatex(3.570061, 23.08044, "%d pb^{-1} at #sqrt{s} = 7 TeV" % lumi);
1027     text2.SetNDC();
1028     text2.SetTextAlign(13);
1029     text2.SetX(0.38);
1030     text2.SetY(0.88);
1031     #text2.SetLineWidth(2);
1032     text2.SetTextFont(42);
1033     text2.SetTextSizePixels(24);# dflt=28
1034     text2.SetTextSize(0.03);
1035     text2.Draw();
1036     # canvases[-1].SaveAs('plots/' + histname + '.png')
1037     if (false and 'iso' in histname):
1038     canvases[-1].SaveAs('plots/' + histname + '.root')
1039     else:
1040     canvases[-1].SaveAs('plots/' + histname + '.png')
1041    
1042     if (histname == "wpnegmass_lepton" or histname == "wp1topmass_lepton" or histname == "wp1topmasspos_lepton" or histname == "wp1topmassneg_lepton"):
1043     hist_ttbargood = hist_ttbar.Clone("test");
1044     # hist_ttbargood.Add(hist_wjets);
1045     hist_wprimegood = hist_wpm600.Clone("test");
1046     elif (histname == "wpnegmassbad_lepton" or histname == "wp1topmassbad_lepton" or histname == "wp1topmassbadpos_lepton" or histname == "wp1topmassbadneg_lepton"):
1047     if (histname == "wp1topmassbad_lepton"):
1048     suffix = "1top";
1049     elif (histname == "wp1topmassbadpos_lepton"):
1050     suffix = "1toppos";
1051     elif (histname == "wp1topmassbadneg_lepton"):
1052     suffix = "1topneg";
1053     else:
1054     suffix = "";
1055     ttbname = 'ttbarasym' + suffix;
1056     wpname = 'wprimeasym' + suffix;
1057     comasymname = 'wpttcombined' + suffix;
1058     wpgoodbad = "wpnegmassgoodbad" + suffix;
1059     ttbgoodbad = "ttbargoodbad" + suffix;
1060     totgoodbad = "wpnegmtotgoodbad" + suffix;
1061     # hist_ttbar.Add(hist_wjets);
1062     asymmetryplot(hist_ttbargood, hist_ttbar, ttbname);
1063     asymmetryplot(hist_wprimegood, hist_wpm600, wpname);
1064     asymmetry2plot(hist_ttbargood, hist_ttbar, hist_wprimegood, hist_wpm600, comasymname);
1065     plusminuscmp(hist_wpm600, hist_wprimegood, wpgoodbad, 0);
1066     plusminuscmp(hist_ttbar, hist_ttbargood, ttbgoodbad, 0);
1067     hist_wpm600.Add(hist_ttbar);
1068     hist_wprimegood.Add(hist_ttbargood);
1069     plusminuscmp(hist_wpm600, hist_wprimegood, totgoodbad, 0);
1070     elif (histname == "wpnegmasspos"):
1071     hist_wprimepos = hist_wpm600.Clone("test");
1072     elif (histname == "wpnegmassneg"):
1073     plusminuscmp(hist_wprimepos, hist_wpm600, 'wpmassplusminus', 1);
1074    
1075    
1076     # canvases[-1].SaveAs('plots/' + histname + '.png')
1077     # canvases[-1].SaveAs('/storage/results/' + histname + '.png')
1078    
1079     cu_hist_data = getCumulativePlot(hist_data, "data");
1080     cu_hist_ttbar = getCumulativePlot(hist_ttbar, "ttbar");
1081     # cu_hist_wjets = getCumulativePlot(hist_wjets, "wjets");
1082     # cu_hist_zjets = getCumulativePlot(hist_zjets, "zjets");
1083     # cu_hist_qcd = getCumulativePlot(hist_qcd, "qcd");
1084     # cu_hist_singleTop = getCumulativePlot(hist_singleTop, "singleTop");
1085     # cu_hist_wpm400 = getCumulativePlot(hist_wpm400, "Wprimet400");
1086     cu_hist_wpm600 = getCumulativePlot(hist_wpm600, "Wprimet600");
1087     # cu_hist_wpm800 = getCumulativePlot(hist_wpm800, "Wprimet800");
1088     # cu_hist_wpm1000 = getCumulativePlot(hist_wpm1000, "Wprimet1000");
1089     # cu_hist_wptb1000 = getCumulativePlot(hist_wptb1000, "Wprimetb1000");
1090     # cu_hist_Zprime500 = getCumulativePlot(hist_Zprime500, "Zprime500");
1091     # cu_hist_Zprime750 = getCumulativePlot(hist_Zprime750, "Zprime750");
1092     # cu_hist_Zprime1000 = getCumulativePlot(hist_Zprime1000, "Zprime1000");
1093     # cu_hist_Zprime2000 = getCumulativePlot(hist_Zprime2000, "Zprime2000");
1094     # cu_hist_Zprime4000 = getCumulativePlot(hist_Zprime4000, "Zprime4000");
1095     # cu_hist_Tprime300 = getCumulativePlot(hist_Tprime300, "Tprime300");
1096     # cu_hist_Tprime350 = getCumulativePlot(hist_Tprime350, "Tprime350");
1097     ## cu_hist_Zprime1250 = getCumulativePlot(hist_Zprime1250, "Zprime1250");
1098     ## cu_hist_Zprime1500 = getCumulativePlot(hist_Zprime1500, "Zprime1500");
1099    
1100     cu_hist_data.SetTitleSize(0.04, "X");
1101     cu_hist_data.SetTitleSize(0.04, "Y");
1102     cu_hist_data.SetYTitle("Integrated Events");
1103     cu_hist_data.SetTitleOffset(1.3, "X");
1104     cu_hist_data.SetTitleOffset(1.7, "Y");
1105     ##
1106     #
1107     cu_hist_data.SetAxisRange(Urange[0], Urange[1]);
1108     cu_hist_ttbar.SetAxisRange(Urange[0], Urange[1]);
1109     # cu_hist_wjets.SetAxisRange(Urange[0], Urange[1]);
1110     # cu_hist_zjets.SetAxisRange(Urange[0], Urange[1]);
1111     # cu_hist_qcd.SetAxisRange(Urange[0], Urange[1]);
1112     # cu_hist_singleTop.SetAxisRange(Urange[0], Urange[1]);
1113     # cu_hist_wpm400.SetAxisRange(Urange[0], Urange[1]);
1114     cu_hist_wpm600.SetAxisRange(Urange[0], Urange[1]);
1115     # cu_hist_wpm800.SetAxisRange(Urange[0], Urange[1]);
1116     # cu_hist_wpm1000.SetAxisRange(Urange[0], Urange[1]);
1117     # cu_hist_wptb1000.SetAxisRange(Urange[0], Urange[1]);
1118     if (Yrange[1] > 0):
1119     cu_hist_data.SetAxisRange(Yrange[0], Yrange[1], "Y");
1120     cu_hist_ttbar.SetAxisRange(Yrange[0], Yrange[1], "Y");
1121     cu_hist_wpm600.SetAxisRange(Yrange[0], Yrange[1], "Y");
1122    
1123     cu_hs = THStack("cu_MC", "cu_MC");
1124     # cu_hs.Add(cu_hist_qcd);
1125     # cu_hs.Add(cu_hist_zjets);
1126     # cu_hs.Add(cu_hist_wjets);
1127     cu_hs.Add(cu_hist_ttbar);
1128    
1129     scanvases.append(TCanvas("cu_cname" + histname, histname + "(cu)", 1200, 900))
1130    
1131     # if ('iso' in histname or 'jetmultip' in histname or 'num' in histname and 'Top' in histname):
1132     scanvases[-1].SetGrid();
1133     if ('muiso' in histname):
1134     scanvases[-1].SetLogy();
1135    
1136     scanvases[-1].cd().SetRightMargin(0.04);
1137     # cu_hist_data.Draw("error");
1138     # cu_hist_data.Draw("axis");
1139     cu_hist_data.Draw();
1140     cu_hs.Draw("hist same");
1141     cu_hist_wpm600.Draw("same");
1142     # if (not 'num' in histname or not 'Top' in histname):
1143     # cu_hist_wpm400.Draw("same");
1144     # cu_hist_wpm800.Draw("same");
1145     # cu_hist_wpm1000.Draw("same");
1146     # cu_hist_wptb1000.Draw("same");
1147     # cu_hist_Zprime500.Draw("same");
1148     # cu_hist_Zprime750.Draw("same");
1149     # cu_hist_Zprime1000.Draw("same");
1150     # cu_hist_Zprime2000.Draw("same");
1151     # cu_hist_Zprime4000.Draw("same");
1152     # cu_hist_Tprime300.Draw("same");
1153     # cu_hist_Tprime350.Draw("same");
1154     ### cu_hist_Zprime1250.Draw("same");
1155     ### cu_hist_Zprime1500.Draw("same");
1156     ## # cu_hist_data2.Draw("error same");
1157     # cu_hist_data.Draw("error same");
1158     leg.Draw();
1159     ##
1160     text1.Draw();
1161     ##
1162     text2.Draw();
1163     # scanvases[-1].SaveAs('/storage/results/' + histname + '_integrated.png')
1164     scanvases[-1].SaveAs('plots/' + histname + '_integrated.png')
1165    
1166    
1167    
1168     # tdrGrid: Turns the grid lines on (true) or off (false)
1169    
1170     #def tdrGrid(bool gridOn):
1171     # tdrStyle.SetPadGridX(gridOn);
1172     # tdrStyle.SetPadGridY(gridOn);
1173     #
1174    
1175     # fixOverlay: Redraws the axis
1176    
1177     def setCorrErrs(hist_good, hist_bad, hist_diff):
1178     nbins = hist_diff.GetXaxis().GetNbins();
1179     for i in range(1, nbins):
1180     goodval = hist_good.GetBinContent(i);
1181     badval = hist_bad.GetBinContent(i);
1182     gooderr = hist_good.GetBinError(i);
1183     baderr = hist_bad.GetBinError(i);
1184     errsum = goodval + badval;
1185     if errsum > 0:
1186     # print 'evts err ', goodval, gooderr;
1187     goodprod = goodval * baderr;
1188     badprod = gooderr * badval;
1189     tot = (goodprod * goodprod) + (badprod * badprod);
1190     # Assume 90% correlation
1191     tot = tot - (1.8 * goodprod * badprod);
1192     if tot > 0:
1193     tot = 4.0 * sqrt(tot) / (errsum * errsum);
1194     hist_diff.SetBinError(i, tot);
1195    
1196    
1197    
1198     def setUncorrErrs(hist_good, hist_bad, hist_diff):
1199     nbins = hist_diff.GetXaxis().GetNbins();
1200     for i in range(1, nbins):
1201     goodval = hist_good.GetBinContent(i);
1202     badval = hist_bad.GetBinContent(i);
1203     err = goodval + badval;
1204     err = err * err * err;
1205     if err > 0:
1206     err = 4.0 * sqrt((goodval * badval) / err);
1207     hist_diff.SetBinError(i, err);
1208    
1209    
1210     def asymmetryplot(hist_good, hist_bad, histname):
1211     hist_total = hist_good.Clone("test");
1212     # hist_total.Sumw2();
1213     hist_total.Add(hist_bad);
1214     hist_diff = hist_good.Clone("test");
1215     # hist_diff.Sumw2();
1216     hist_diff.Add(hist_bad, -1);
1217     hist_total.Scale(0.5);
1218     hist_diff.Divide(hist_total);
1219     # setCorrErrs(hist_good, hist_bad, hist_diff);
1220     hist_diff.SetXTitle("W' mass/GeV");
1221     hist_diff.SetYTitle("Asymmetry");
1222     hist_diff.SetAxisRange(200, 1100);
1223     hist_diff.SetLineWidth(4);
1224     # hist_diff.SetFillStyle(1001);
1225     hist_diff.SetFillStyle(3001);
1226     hist_diff.SetFillColor(kRed);
1227     canvases[-1].SetGridy();
1228     hist_diff.GetYaxis().SetRangeUser(-asymrange, asymrange);
1229     hist_diff.Draw("hist E1");
1230     canvases[-1].SaveAs('plots/' + histname + '.png')
1231    
1232    
1233     def asymmetry2plot(ttbar_good, ttbar_bad, wp_good, wp_bad, histname):
1234     hist_total = ttbar_good.Clone("test");
1235     # hist_total.Sumw2();
1236     hist_total.Add(ttbar_bad);
1237     hist_total.Add(wp_good);
1238     hist_total.Add(wp_bad);
1239     hist_total.Scale(0.5);
1240     hist_diff = ttbar_good.Clone("test");
1241     # hist_diff.Sumw2();
1242     hist_diff.Add(wp_good);
1243     hist_diff.Add(ttbar_bad, -1);
1244     hist_diff.Add(wp_bad, -1);
1245     hist_diff.Divide(hist_total);
1246     # nbins = hist_diff.GetXaxis().GetNbins();
1247     hist_good = ttbar_good.Clone("test");
1248     hist_good.Add(wp_good);
1249     hist_bad = ttbar_bad.Clone("test");
1250     hist_bad.Add(wp_bad);
1251     # setCorrErrs(hist_good, hist_bad, hist_diff);
1252     hist_diff.SetXTitle("W' mass/GeV");
1253     hist_diff.SetYTitle("Asymmetry");
1254     hist_diff.SetAxisRange(200, 1100);
1255     hist_diff.SetLineWidth(4);
1256     # hist_diff.SetFillStyle(1001);
1257     hist_diff.SetFillStyle(3001);
1258     hist_diff.SetFillColor(kRed);
1259     canvases[-1].SetGridy();
1260     hist_diff.GetYaxis().SetRangeUser(-asymrange, asymrange);
1261     hist_diff.Draw("hist E1");
1262     canvases[-1].SaveAs('plots/' + histname + '.png')
1263    
1264    
1265    
1266     def plusminuscmp(hist_pos, hist_neg, hist_name, sign):
1267     hist_neg.SetXTitle("Reco W' mass/GeV");
1268     hist_neg.SetYTitle("Events/(60 GeV)");
1269     hist_pos.SetLineColor(kGray + 3);
1270     hist_neg.SetLineColor(kRed);
1271     hist_neg.SetFillStyle(0);
1272     hist_pos.SetFillStyle(0);
1273     linewidth = 6;
1274     hist_pos.SetLineWidth(linewidth);
1275     hist_neg.SetLineWidth(linewidth);
1276     leg = TLegend(0.696, 0.35, 0.95, 0.92);
1277     leg.SetBorderSize(0);
1278     leg.SetLineStyle(0);
1279     leg.SetTextFont(42);
1280     leg.SetFillStyle(0);
1281     if sign == 1:
1282     leg.AddEntry(hist_pos, "W't+ .6TeV (8 pb)", "L");
1283     leg.AddEntry(hist_neg, "W't- .6TeV (8 pb)", "L");
1284     else:
1285     leg.AddEntry(hist_pos, "W't bad .6TeV (8 pb)", "L");
1286     leg.AddEntry(hist_neg, "W't good .6TeV (8 pb)", "L");
1287     hist_pos.SetStats(1);
1288     hist_neg.Draw("hist E1");
1289     hist_pos.Draw("hist same");
1290     leg.Draw();
1291     canvases[-1].SaveAs('plots/' + hist_name + '.png')
1292    
1293    
1294     def fixOverlay():
1295     gPad.RedrawAxis();
1296    
1297    
1298     def getCumulativePlot(initial, type):
1299     global counter
1300     counter = counter + 1;
1301     name = initial.GetName()
1302     name = "cu_" + name + "_" + type + str(counter);
1303     title = initial.GetTitle()
1304     title = "cu_" + title + "_" + type;
1305     xaxis = initial.GetXaxis().GetTitle();
1306     yaxis = initial.GetYaxis().GetTitle();
1307     nBins = initial.GetNbinsX();
1308     cu = TH1F(name, title, nBins, initial.GetXaxis().GetXmin(), initial.GetXaxis().GetXmax());
1309     for bin in range(1,nBins+1):
1310     cu.SetBinContent(bin, initial.Integral(bin, nBins));
1311    
1312     cu.SetFillStyle(initial.GetFillStyle());
1313     cu.SetFillColor(initial.GetFillColor());
1314     cu.SetLineColor(initial.GetLineColor());
1315     cu.SetMarkerSize(initial.GetMarkerSize());
1316     cu.SetMarkerStyle(initial.GetMarkerStyle());
1317     cu.SetMarkerColor(initial.GetMarkerColor());
1318     cu.SetLineWidth(initial.GetLineWidth());
1319     cu.GetXaxis().SetTitle(xaxis);
1320     cu.GetYaxis().SetTitle(yaxis);
1321     return cu;
1322    
1323     if __name__ == "__main__":
1324     gROOT.SetBatch(True)
1325     gROOT.ProcessLine('gErrorIgnoreLevel = 1001;')
1326     plotMttbar()
1327     # print "press enter to quit"
1328     # a = raw_input()