-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot-mass
executable file
·296 lines (256 loc) · 10 KB
/
plot-mass
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
#!/usr/bin/env python
from rootpy.io import root_open
from rootpy.plotting import Hist, Canvas, Legend, Graph
from rootpy.plotting.utils import get_limits, draw
from rootpy.plotting.style.atlas import ATLAS_label
from mva.cmd import get_parser
from mva.analysis import get_analysis
from mva.samples import Higgs
from mva.categories import (
Category_Preselection,
Category_Cuts_Boosted_Preselection, Category_Cuts_VBF_Preselection,
Category_VBF, Category_Boosted)
from mva.variables import VARIABLES
from mva.defaults import TARGET_REGION
from mva import MMC_MASS, log
import ROOT
def fwhm(h1):
bin1 = h1.FindFirstBinAbove(h1.max() / 2)
bin2 = h1.FindLastBinAbove(h1.max() / 2)
return h1.GetBinCenter(bin2) - h1.GetBinCenter(bin1)
def plot_mass(ztt, higgs, category):
print "FWHM:"
print " Ztt %.1f" % fwhm(ztt)
print " Htt %.1f" % fwhm(higgs)
_, _, _, ymax = get_limits([ztt, higgs], ypadding=(0.3, 0))
plot = Canvas()
ztt.Draw()
ztt.yaxis.title = 'Fraction of Events / 5 GeV'
ztt.xaxis.title = '%s [GeV]' % VARIABLES[MMC_MASS]['root']
ztt.yaxis.SetLimits(0, ymax)
ztt.yaxis.SetRangeUser(0, ymax)
ztt.xaxis.SetNdivisions(507, True)
higgs.Draw('same')
leg = Legend(2, pad=plot,
entryheight=0.04,
margin=0.2,
textsize=22 )
leg.AddEntry(ztt, style='L')
leg.AddEntry(higgs, style='L')
leg.Draw()
if args.year == 2011:
sqrts = 7
elif args.year == 2012:
sqrts = 8
else:
sqrts= None
ATLAS_label(plot.GetLeftMargin()+0.03, 0.89,
sep=0.14, pad=plot, sqrts=sqrts,
text="Internal", textsize=22)
label = ROOT.TLatex(
plot.GetLeftMargin() + 0.03, 0.83,
category.label)
label.SetNDC()
label.SetTextFont(43)
label.SetTextSize(22)
label.Draw()
for fmt in args.output_formats:
plot.SaveAs('plots/mass_%s%s.%s' % (category.name, output_suffix, fmt))
def plot_mmc_col_masses(ztt_mmc, higgs_mmc, ztt_col, higgs_col, category):
_, _, _, ymax = get_limits([ztt_mmc,ztt_col, higgs_mmc,higgs_col], ypadding=(0.3, 0))
plot = Canvas()
ztt_mmc.Draw()
ztt_mmc.yaxis.title = 'Fraction of Events / 5 GeV'
ztt_mmc.xaxis.title = 'm_{#tau#tau} [GeV]'
ztt_mmc.yaxis.SetLimits(0, ymax)
ztt_mmc.yaxis.SetRangeUser(0, ymax)
ztt_mmc.xaxis.SetNdivisions(507, True)
ztt_col.Draw('same')
higgs_mmc.Draw('same')
higgs_col.Draw('same')
leg_mmc = Legend(2, pad=plot,
entryheight=0.04,
margin=0.2,
textsize=22 )
leg_mmc.AddEntry(ztt_mmc, style='L')
leg_mmc.AddEntry(higgs_mmc, style='L')
leg_mmc.SetHeader('MMC')
leg_col = Legend(2, pad=plot,
entryheight=0.04,
margin=0.2,
textsize=22 )
leg_col.SetHeader('Collinear')
leg_col.AddEntry(ztt_col, style='L')
leg_col.AddEntry(higgs_col, style='L')
leg_mmc.Draw()
leg_col.Draw()
if args.year == 2011:
sqrts = 7
elif args.year == 2012:
sqrts = 8
else:
sqrts= None
ATLAS_label(plot.GetLeftMargin()+0.03, 0.89,
sep=0.14, pad=plot, sqrts=sqrts,
text="Internal", textsize=22)
label = ROOT.TLatex( plot.GetLeftMargin() + 0.03, 0.83,
category.label )
label.SetNDC()
label.SetTextFont(43)
label.SetTextSize(22)
label.Draw()
for fmt in args.output_formats:
plot.SaveAs('plots/mmc_col_masses_%s%s.%s' % (category.name, output_suffix, fmt))
def mmc_resolution_graph(year, category, x_shift=0):
"""
Return a Graph() of fitted mmc mass as a
function of m_H. The error correspond to the gaussian fit
sigma value.
-- parameters
category: analysis Category where the Higgs samples are taken
x_shift: Shift to apply on the position of the graph points (to overlay several graphs)
"""
gr_res = Graph(len(Higgs.MASSES))
gr_res.name = 'graph_res_' + category.name
for im, mass in enumerate(Higgs.MASSES):
higgs = Higgs(year=year, mass=mass)
template = Hist(40, 0, 200, linewidth=3, drawstyle='hist')
higgs_mmc = template.Clone(name="mmc_%d"% mass)
higgs.draw(MMC_MASS, higgs_mmc, category, TARGET_REGION)
higgs_fit = higgs_mmc.Fit('gaus', 'S')
if mass == 125:
plot_mmc_fit(higgs_mmc, higgs_fit, higgs, category)
gr_res.SetPoint(im, mass + x_shift, higgs_fit.Parameter(1))
gr_res.SetPointError(im, 0, 0, higgs_fit.Parameter(2), higgs_fit.Parameter(2))
return gr_res
def plot_mmc_fit(higgs_mmc, higgs_fit, sample=None, category=None ):
_, _, _, ymax = get_limits([higgs_mmc], ypadding=(0.2, 0))
plot = Canvas()
higgs_mmc.xaxis.title = '%s [GeV]' % VARIABLES[MMC_MASS]["root"]
higgs_mmc.yaxis.title = 'Fraction of Events / 5 GeV'
higgs_mmc.yaxis.SetRangeUser(0, ymax)
higgs_mmc.xaxis.SetNdivisions(507, True)
higgs_mmc.Draw('HIST')
gaus_fit = ROOT.TF1("fit", "gaus(0)",
higgs_fit.Parameter(1)-3*higgs_fit.Parameter(2),
higgs_fit.Parameter(1)+3*higgs_fit.Parameter(2))
gaus_fit.SetParameters(higgs_fit.Parameter(0),
higgs_fit.Parameter(1),
higgs_fit.Parameter(2))
gaus_fit.SetLineColor(ROOT.kRed)
gaus_fit.Draw('same')
gaus_label = ROOT.TLatex(
plot.GetLeftMargin() + 0.08, 0.53,
"#splitline{{Gaussian Fit:}}{{#mu={0:.1f} #sigma={1:.1f}}}".format(
higgs_fit.Parameter(1),
higgs_fit.Parameter(2)))
gaus_label.SetNDC()
gaus_label.SetTextFont(43)
gaus_label.SetTextSize(22)
gaus_label.SetTextColor(ROOT.kRed)
gaus_label.Draw()
sample_name = None
sample_label = None
if sample is not None:
sample_name = sample.name
sample_label = sample.label
category_name = None
category_label = None
if category is not None:
category_name = category.name
category_label = category.label
if args.year == 2011:
sqrts = 7
elif args.year == 2012:
sqrts = 8
else:
sqrts= None
ATLAS_label(plot.GetLeftMargin()+0.03, 0.89,
sep=0.14, pad=plot, sqrts=sqrts,
text="Internal", textsize=22)
label = ROOT.TLatex(plot.GetLeftMargin() + 0.03, 0.83,
category_label )
label.SetNDC()
label.SetTextFont(43)
label.SetTextSize(22)
label.Draw()
label_1 = ROOT.TLatex( plot.GetLeftMargin() + 0.03, 0.77,
sample_label )
label_1.SetNDC()
label_1.SetTextFont(43)
label_1.SetTextSize(22)
label_1.Draw()
for fmt in args.output_formats:
plot.SaveAs('./plots/mmc_fit_%s_%s%s.%s' % (sample_name,category_name,output_suffix,fmt) )
def plot_resolution(year):
colors = ('black', 'blue', 'red')
styles = ('circle', 'square', 'triangle')
categories = (Category_Preselection, Category_Boosted, Category_VBF)
x_shifts = (-1., 0, 1.)
graphs = []
for category,linecolor,markerstyle,x_shift in zip(categories,colors,styles,x_shifts):
log.info( 'Fit MMC in '+category.name )
graph_cat = mmc_resolution_graph(year, category, x_shift)
graph_cat.linecolor = linecolor
graph_cat.markerstyle = markerstyle
graph_cat.markercolor = linecolor
graph_cat.drawstyle = 'P'
graphs.append(graph_cat)
plot = Canvas()
plot.cd()
draw(graphs, pad=plot,
xtitle='#font[52]{m}_{H} [GeV]',
ytitle='<%s> [GeV]' % VARIABLES[MMC_MASS]['root'],
ypadding = (0.2, 0.1),
xpadding=(0.05, 0.05),
xdivisions=206,
snap=False)
leg = Legend(len(categories),
pad=plot,
entryheight=0.04,
margin=0.2,
textsize=22 )
for category,graph in zip(categories,graphs):
leg.AddEntry(graph,category.label,'PL')
leg.Draw('same')
if args.year == 2011:
sqrts = 7
elif args.year == 2012:
sqrts = 8
else:
sqrts= None
ATLAS_label(plot.GetLeftMargin()+0.03, 0.89,
sep=0.14, pad=plot, sqrts=sqrts,
text="Internal", textsize=22)
for fmt in args.output_formats:
plot.SaveAs('plots/resolution%s.%s' % (output_suffix, fmt))
# --------------------------------
# --- MAIN DRIVER
# --------------------------------
args = get_parser(actions=False).parse_args()
analysis = get_analysis(args, systematics=False)
output_suffix = analysis.get_suffix()
categories = [Category_Preselection, Category_Boosted, Category_VBF]
plot_resolution(args.year)
template = Hist(40, 0, 200, linewidth=3, drawstyle='hist')
with root_open('mmc_hadhad_histos.root', 'recreate') as out:
for category in categories:
ztt_mmc = template.Clone(name="mmc_%s_ztt" % category.name, title=analysis.ztautau.label)
ztt_col = template.Clone(name="col_%s_ztt" % category.name, title=analysis.ztautau.label, linestyle='dashed')
higgs_mmc = template.Clone(name="mmc_%s_htt" % category.name, title=analysis.higgs_125.label, linecolor='red' )
higgs_col = template.Clone(name="col_%s_htt" % category.name, title=analysis.higgs_125.label, linecolor='red', linestyle='dashed')
analysis.ztautau.draw(MMC_MASS, ztt_mmc, category, TARGET_REGION)
analysis.higgs_125.draw(MMC_MASS, higgs_mmc, category, TARGET_REGION)
COL_MASS = 'mass_collinear_tau1_tau2'
analysis.ztautau.draw(COL_MASS, ztt_col, category, TARGET_REGION)
analysis.higgs_125.draw(COL_MASS, higgs_col, category, TARGET_REGION)
# normalize
ztt_mmc /= ztt_mmc.integral()
higgs_mmc /= higgs_mmc.integral()
ztt_col /= ztt_col.integral()
higgs_col /= higgs_col.integral()
# plot the mass distributions
plot_mass(ztt_mmc, higgs_mmc, category)
plot_mmc_col_masses(ztt_mmc, higgs_mmc, ztt_col, higgs_col, category)
ztt_mmc.Write()
higgs_mmc.Write()