/
test.py
executable file
·257 lines (220 loc) · 8.44 KB
/
test.py
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#!/bin/env python
#!/bin/env python
from DukePlotALot import *
from plotlib import HistStorage,getColorList,getDictValue,HistStorageContainer
import matplotlib.pyplot as plt
from configobj import ConfigObj
try:
from collections import OrderedDict
except ImportError:
from ordered import OrderedDict
from rootpy.plotting.views import ScaleView
from rootpy.io import File
def get_binning_from_hist(file_name, hist_name, plot_range, debug=False, min_binning = 1):
res_file = File(file_name, "read")
res_hist = res_file.Get(hist_name)
binning = [plot_range[0]]
value = plot_range[0]
while(binning[-1] < plot_range[1]):
value = res_hist.Eval(binning[-1])
value *= binning[-1]
if value < min_binning:
if debug:
print('appending %f, last value: %f'%(min_binning,binning[-1]))
binning.append(binning[-1]+min_binning)
else:
if debug:
print('appending %f, last value: %f'%(round(value),binning[-1]))
binning.append(binning[-1]+round(value))
if binning[-1] > plot_range[1]:
binning[-1] = plot_range[1]
res_file.Close()
if debug:
print(binning)
return binning
# output2015_7_29_14_53 -> data
#
# output2015_7_30_14_0 -> data
# output2015_7_31_10_28 -> data
#
# output2015_7_31_11_21 -> data
#
# output2015_8_3_17_34 -> data
# output2015_8_4_17_55 -> MC
# basedir="/disk1/erdweg/out/output2015_7_21_14_52/merged/"
basedir="/disk1/erdweg/out/output2015_8_19_18_16/merged/"
lumi = 40.028
lumisc = float(lumi)/float(1000)
xs= ConfigObj("/disk1/erdweg/plotting/xs_Phys14.cfg")
bghists=HistStorage(xs,lumi,xstype=None,path=basedir)
bglist=OrderedDict()
# bglist["DY"]=[
# 'DYJetsToLL_M-10to50_13TeV-FXFX_MC',
# 'DYJetsToLL_M-50_13TeV-FXFX_MC',
# 'DYJetsToLL_M-100to200_13TeV-FXFX_MC',
# 'DYJetsToLL_M-200to400_13TeV-FXFX_MC',
# 'DYJetsToLL_M-400to500_13TeV-FXFX_MC',
# 'DYJetsToLL_M-500to700_13TeV-FXFX_MC',
# 'DYJetsToLL_M-700to800_13TeV-FXFX_MC',
# 'DYJetsToLL_M-800to1000_13TeV-FXFXRaw_MC',
# 'DYJetsToLL_M-1000to1500_13TeV-FXFX_MC',
# 'DYJetsToLL_M-1500to2000_13TeV-FXFX_MC',
# 'DYJetsToLL_M-2000to3000_13TeV-FXFX_MC',
# ]
# bglist["W"]=[
# 'WJetsToLNu_13TeV-FXFX_MC',
# 'WJetsToLNu_HT-100To200_13TeVMLM_MG',
# 'WJetsToLNu_HT-200To400_13TeVMLM_MG',
# 'WJetsToLNu_HT-400To600_13TeVMLM_MG',
# 'WJetsToLNu_HT-600ToInf_13TeVMLM_MG',
# ]
# bglist["single Top"]=[
# 'ST_t-channel_4f_leptonDecays_13TeV-_MC',
# 'ST_tW_top_5f_inclusiveDecays_13TeV_PH',
# 'ST_t-channel_5f_leptonDecays_13TeV-_MC',
# 'ST_s-channel_4f_leptonDecays_13TeV-_MC',
# 'ST_tW_antitop_5f_inclusiveDecays_13TeV_PH',
# ]
# bglist["QCD jet"]=[
# 'QCD_Pt-15to20_MuEnrichedPt5_13TeV_P8',
# 'QCD_Pt-20to30_MuEnrichedPt5_13TeV_P8',
# 'QCD_Pt-20toInf_MuEnrichedPt15_13TeV_P8',
# 'QCD_Pt-30to50_MuEnrichedPt5_13TeV_P8',
# 'QCD_Pt-50to80_MuEnrichedPt5_13TeV_P8',
# 'QCD_Pt-80to120_MuEnrichedPt5_13TeV_P8',
# 'QCD_Pt-120to170_MuEnrichedPt5_13TeV_P8',
# 'QCD_Pt-170to300_MuEnrichedPt5_13TeV_P8',
# 'QCD_Pt-300to470_MuEnrichedPt5_13TeV_P8',
# 'QCD_Pt-470to600_MuEnrichedPt5_13TeV_P8',
# 'QCD_Pt-600to800_MuEnrichedPt5_13TeV_P8',
# 'QCD_Pt-800to1000_MuEnrichedPt5_13TeV_P8',
# 'QCD_Pt-1000toInf_MuEnrichedPt5_13TeV_P8',
# ]
# bglist["Diboson"]=[
# 'WW_13TeV_P8',
# 'WZ_13TeV_P8',
# 'ZZ_13TeV_P8'
# ]
bglist["TTbar"]=[
'TT_13TeV_PH',
'TT_Mtt-1000toInf_13TeV_MCRUN2_74_V9_ext1-v2_PH',
]
colorList={}
colorList["W"]="lightblue"
colorList["Diboson"]="y"
colorList["single Top"]="darkmagenta"
colorList["QCD jet"]="darkblue"
colorList["TTbar"]="chartreuse"
colorList["WW"]="green"
colorList["DY"]="pink"
colorList['RPV M=500']="magenta"
colorList['RPV M=1000']="red"
bghists.additionalWeight = {
'DYJetsToLL_M-10to50_13TeV-FXFX_MC':lumisc,
'DYJetsToLL_M-50_13TeV-FXFX_MC':lumisc,
'DYJetsToLL_M-100to200_13TeV-FXFX_MC':lumisc,
'DYJetsToLL_M-200to400_13TeV-FXFX_MC':lumisc,
'DYJetsToLL_M-400to500_13TeV-FXFX_MC':lumisc,
'DYJetsToLL_M-500to700_13TeV-FXFX_MC':lumisc,
'DYJetsToLL_M-700to800_13TeV-FXFX_MC':lumisc,
'DYJetsToLL_M-800to1000_13TeV-FXFXRaw_MC':lumisc,
'DYJetsToLL_M-1000to1500_13TeV-FXFX_MC':lumisc,
'DYJetsToLL_M-1500to2000_13TeV-FXFX_MC':lumisc,
'DYJetsToLL_M-2000to3000_13TeV-FXFX_MC':lumisc,
'WJetsToLNu_13TeV-FXFX_MC':lumisc,
'WJetsToLNu_HT-100To200_13TeVMLM_MG':lumisc,
'WJetsToLNu_HT-200To400_13TeVMLM_MG':lumisc,
'WJetsToLNu_HT-400To600_13TeVMLM_MG':lumisc,
'WJetsToLNu_HT-600ToInf_13TeVMLM_MG':lumisc,
'ST_t-channel_4f_leptonDecays_13TeV-_MC':lumisc,
'ST_tW_top_5f_inclusiveDecays_13TeV_PH':lumisc,
'ST_t-channel_5f_leptonDecays_13TeV-_MC':lumisc,
'ST_s-channel_4f_leptonDecays_13TeV-_MC':lumisc,
'ST_tW_antitop_5f_inclusiveDecays_13TeV_PH':lumisc,
'QCD_Pt-15to20_MuEnrichedPt5_13TeV_P8':lumisc,
'QCD_Pt-20to30_MuEnrichedPt5_13TeV_P8':lumisc,
'QCD_Pt-20toInf_MuEnrichedPt15_13TeV_P8':lumisc,
'QCD_Pt-30to50_MuEnrichedPt5_13TeV_P8':lumisc,
'QCD_Pt-50to80_MuEnrichedPt5_13TeV_P8':lumisc,
'QCD_Pt-80to120_MuEnrichedPt5_13TeV_P8':lumisc,
'QCD_Pt-120to170_MuEnrichedPt5_13TeV_P8':lumisc,
'QCD_Pt-170to300_MuEnrichedPt5_13TeV_P8':lumisc,
'QCD_Pt-300to470_MuEnrichedPt5_13TeV_P8':lumisc,
'QCD_Pt-470to600_MuEnrichedPt5_13TeV_P8':lumisc,
'QCD_Pt-600to800_MuEnrichedPt5_13TeV_P8':lumisc,
'QCD_Pt-800to1000_MuEnrichedPt5_13TeV_P8':lumisc,
'QCD_Pt-1000toInf_MuEnrichedPt5_13TeV_P8':lumisc,
'WW_13TeV_P8':lumisc,
'WZ_13TeV_P8':lumisc,
'ZZ_13TeV_P8':lumisc,
'TT_13TeV_PH':lumisc,
'TT_Mtt-1000toInf_13TeV_MCRUN2_74_V9_ext1-v2_PH':lumisc,
}
bghists.addFileList(bglist)
#
# dat_hist=HistStorage(xs,lumi,path='/disk1/erdweg/out/output2015_8_20_17_27/merged/',isData=True)
# dat_hist.addFile("Data_251027_251883_SingleMuon_v2")
#
# basedir="/disk1/erdweg/out/output2015_6_2_17_17/merged/"
# sghist=HistStorage(xs,lumi,path=basedir)
# sglist=OrderedDict()
#
# sglist['RPV M=500']=[
# 'RPVresonantToEMu_M-500_LLE_LQD_001_TuneCUETP8M1_13TeV-calchep-pythia8',
# ]
# sglist['RPV M=1000']=[
# 'RPVresonantToEMu_M-1000_LLE_LQD_001_TuneCUETP8M1_13TeV-calchep-pythia8',
# ]
# sghist.additionalWeight = {'RPVresonantToEMu_M-500_LLE_LQD_001_TuneCUETP8M1_13TeV-calchep-pythia8':lumisc}
# sghist.additionalWeight.update({'RPVresonantToEMu_M-1000_LLE_LQD_001_TuneCUETP8M1_13TeV-calchep-pythia8':lumisc})
# sghist.addFileList(sglist)
histContainer=HistStorageContainer(bg=bghists)
bghists.initStyle(style="bg",colors=colorList)
# sghist.initStyle(style="sg",colors=colorList)
def main():
hists=[
'emu/Stage_0/h1_0_emu_Mass',
]
binning={
"Taus/h1_2_Tau_pt":10,
}
binning.update({"emu/Stage_0/h1_0_emu_Mass":get_binning_from_hist('res_unc.root','func',[0,4000],min_binning = 5)})
xranges={
"emu/Stage_0/h1_0_emu_Mass":[50,3000],
}
for hist in hists:
print("Now plotting: " + hist)
histContainer.getHist(hist)
binf=getDictValue(hist,binning)
if binf is not None:
# dat_hist.rebin(width=1,vector=binf)
bghists.rebin(width=1,vector=binf)
# sghist.rebin(width=1,vector=binf)
hist_style = sc.style_container(style = 'CMS', useRoot = False,cms=13,lumi=lumi, cmsPositon = 'upper left')
dummy = bghists.getAllAdded()
dummy.xaxis.SetTitle('')
dummy.yaxis.SetTitle('')
dummy.SaveAs('plots/' + hist.replace("/","") + '.root')
test = plotter(hist=bghists.getHistList(),style=hist_style)
# test.Add_data(dat_hist.getHistList()[0])
hist_style.Set_error_bands_fcol(['gray','orange'])
hist_style.Set_error_bands_ecol(['black','black'])
hist_style.Set_error_bands_labl(['Systematics','Statistic'])
if hist == 'emu/Stage_0/h1_0_emu_Mass':
sys_file=File('syst/for_plotting.root', "read")
test.Add_error_hist([sys_file.Get('Sys'),sys_file.Get('MC statistic')], band_center = 'ref', stacking = 'Nosum')
# test.Add_error_hist([sys_file.Get('MC statistic')], band_center = 'ref', stacking = 'Nosum')
# test.Add_plot('Diff',pos=0, height=12)
#
# test.Add_plot('DiffRatio',pos=1, height=12)
# test.Add_plot('Signi',pos=2, height=12)
if hist in xranges.keys():
test.Set_axis(logx=True,logy=True,xmin=xranges[hist][0],xmax=xranges[hist][1],ymin=1e-6,ymax=1e3)
name=hist.replace("/","")
test.create_plot()
# test.Get_axis0().set_ylim(ymin = -1.2, ymax = 1.7)
# test.Get_axis2().set_ylim(ymin = -3, ymax = 13)
# test.Get_axis3().set_ylim(ymin = -2, ymax = 2.0)
test.SavePlot('plots/test.pdf')
return 42
main()