-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotStack.py
More file actions
98 lines (82 loc) · 2.06 KB
/
plotStack.py
File metadata and controls
98 lines (82 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python
from ROOT import *
import CMS_lumi
CMS_lumi.lumi_13TeV = "4.2 fb^{-1}"
#CMS_lumi.writeExtraText = 1
#CMS_lumi.writeExtraText2 = 1
CMS_lumi.extraText = "Preliminary"
import sys
gROOT.ProcessLine(".L ~/tdrStyle.C");
setTDRStyle()
gStyle.SetOptStat(0)
mc=sys.argv[1]
data=sys.argv[2]
var=sys.argv[3]
ptbin=sys.argv[4]
selection=sys.argv[5]
normalize=sys.argv[6]
mcfile = TFile(mc)
datafile = TFile(data)
print var+"__"+ptbin+"_l"+selection
hl = mcfile.Get(var+"__"+ptbin+"_l"+selection)
hl.SetFillColor(4)
hl.SetLineColor(4)
hc = mcfile.Get(var+"__"+ptbin+"_c"+selection)
hc.SetFillColor(3)
hc.SetLineColor(3)
hb = mcfile.Get(var+"__"+ptbin+"_b"+selection)
hb.SetFillColor(2)
hb.SetLineColor(2)
htotalmc = hl.Clone()
htotalmc.Add(hc)
htotalmc.Add(hb)
if normalize != None:
hl.Scale(1./htotalmc.Integral())
hc.Scale(1./htotalmc.Integral())
hb.Scale(1./htotalmc.Integral())
htotalmc.Scale(1./htotalmc.Integral())
stack = THStack()
stack.Add(hl)
stack.Add(hc)
stack.Add(hb)
hdata=datafile.Get(var+"__"+ptbin+""+selection)
hdata.SetMarkerStyle(20)
hdata.SetLineWidth(2)
legend=TLegend(0.7, 0.7, 0.9, 0.9)
legend.SetBorderSize(0)
legend.SetFillColor(0)
legend.AddEntry(hb, "b jets", "f")
legend.AddEntry(hc, "c jets", "f")
legend.AddEntry(hl, "light jets", "f")
legend.AddEntry(hdata, "data", "lp")
if normalize != None:
hdata.Scale(1./hdata.Integral())
hratio=hdata.Clone()
hratio.Divide(htotalmc)
c = TCanvas()
pad1 = TPad("pad1", "pad1", 0, 1-0.72, 1, 1)
pad1.Draw()
pad1.cd()
stack.Draw("HIST")
hdata.Draw("sames")
legend.Draw("same")
CMS_lumi.CMS_lumi(pad1, 4, 11)
pad1.RedrawAxis()
c.cd()
pad2 = TPad("pad2", "pad2",0,0,1,1-0.72)
pad2.SetTopMargin(0.000)
pad2.SetBottomMargin(0.392)
pad2.Draw()
pad2.cd()
oneLine = TLine(hratio.GetXaxis().GetXmin(), 1, hratio.GetXaxis().GetXmax(), 1);
oneLine.SetLineStyle(3)
oneLine.SetLineWidth(3)
hratio.GetXaxis().SetLabelSize(0.15)
hratio.GetYaxis().SetLabelSize(0.15)
hratio.Draw()
oneLine.Draw("same")
pad2.SetGridy()
pad2.RedrawAxis()
gPad.Update()
c.SaveAs("pics/"+var+"__"+ptbin+""+selection+".png")
#a=raw_input("ciao")