-
Notifications
You must be signed in to change notification settings - Fork 1
/
print_cutflow_plots.py
executable file
·198 lines (168 loc) · 10.1 KB
/
print_cutflow_plots.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
#!/usr/bin/env python
"""
Print cutflow plots
"""
from __future__ import print_function, division
import os
os.nice(10)
import sys
import argparse
import ROOT
from MyStyle import My_Style
from comparator import Contribution, Plot
My_Style.cd()
# my packages
import common_utils as cu
import qg_common as qgc
import qg_general_plots as qgp
# ROOT.gErrorIgnoreLevel = ROOT.kWarning
ROOT.PyConfig.IgnoreCommandLineOptions = True
ROOT.gROOT.SetBatch(1)
ROOT.TH1.SetDefaultSumw2()
def plot_cutflow_hist(hist, output_filename, title='', has_data=False):
"""Plot one cutflow histogram. Normalises so bins are fractions of the first"""
frac_hist = hist.Clone()
first_bin = hist.GetBinContent(1)
for i in range(1, frac_hist.GetNbinsX()+1):
frac_hist.SetBinContent(i, hist.GetBinContent(i) / first_bin)
frac_hist.SetBinError(i, hist.GetBinError(i) / first_bin)
col = ROOT.kBlue
entry = [Contribution(frac_hist, label='',
line_color=col, line_width=2, line_style=1,
marker_color=col, marker_size=0.75, marker_style=cu.Marker.get('circle'),
normalise_hist=False)]
hmax = frac_hist.GetMaximum()
hmin = frac_hist.GetMinimum(0)
hdiff = hmax-hmin
ymin = max(0, hmin - (hdiff*0.1))
ymax = hmax + (hdiff*0.25)
plot = Plot(entry, 'hist',
xtitle='',
ytitle='Fraction',
title=title,
ylim=(ymin, ymax),
legend=False,
has_data=has_data)
plot.default_canvas_size = (800, 600)
plot.plot("NOSTACK HISTE")
plot.save(output_filename)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("source",
help="Source file")
parser.add_argument("--outputDir",
help="Output dir (default is source dir)")
args = parser.parse_args()
if not os.path.isfile(args.source):
raise IOError("source file doesn't exist")
in_tfile = cu.TFileCacher(args.source)
is_data = '.DATA.' in os.path.basename(args.source)
is_dijet = '_QCD.root' in os.path.basename(args.source) or '_JetHT_ZeroBias.root' in os.path.basename(args.source)
if not args.outputDir:
in_dir = os.path.dirname(args.source)
args.outputDir = os.path.join(in_dir, 'cutflow_plots')
if is_data:
args.outputDir += "_data"
else:
args.outputDir += "_MC"
if is_dijet:
args.outputDir += "_dijet"
else:
args.outputDir += "_zpj"
print("Plots produced in", args.outputDir)
jet_str = "AK4 PUPPI jets"
if 'ak8puppi' in args.source:
jet_str = "AK8 PUPPI jets"
# DIJET
if is_dijet:
if not is_data:
# Plot dijet reco cutflow, having passed gen selection (i.e. why inefficient)
plot_cutflow_hist(in_tfile.Get("cf_DijetSelTighterPassGenCutFlow"),
output_filename=os.path.join(args.outputDir, 'cutflow_dijet_reco_sel_tighter_passGen.pdf'),
title='Dijet reco selection cutflow, having passed gen selection\n%s' % (jet_str),
has_data=False)
# Plot reco cutflow (no gen requirements)
plot_cutflow_hist(in_tfile.Get("cf_DijetSelTighterCutFlow"),
output_filename=os.path.join(args.outputDir, 'cutflow_dijet_reco_sel_tighter.pdf'),
title='Dijet reco selection cutflow (no requirements on gen selection)\n%s' % (jet_str),
has_data=False)
# Plot dijet gen cutflow, having passed reco selection (i.e. why fakes)
plot_cutflow_hist(in_tfile.Get("cf_DijetGenSelPassRecoCutFlow"),
output_filename=os.path.join(args.outputDir, 'cutflow_dijet_gen_sel_passReco.pdf'),
title='Dijet gen selection cutflow, having passed reco selection\n%s' % (jet_str),
has_data=False)
# Plot dijet gen cutflow (no reco requirements)
plot_cutflow_hist(in_tfile.Get("cf_DijetGenSelCutFlow"),
output_filename=os.path.join(args.outputDir, 'cutflow_dijet_gen_sel.pdf'),
title='Dijet gen selection cutflow (no requirements on reco selection)\n%s' % (jet_str),
has_data=False)
# Plot unfolding fakes cause
for region in ['central', 'forward']:
plot_cutflow_hist(in_tfile.Get("Dijet_QG_Unfold_%s_tighter/fakes_counter" % (region)),
output_filename=os.path.join(args.outputDir, 'cutflow_dijet_unfold_%s_fakes.pdf' % (region)),
title='Dijet (%s) unfolding fakes (ungroomed, charged+neutral vars)\n%s' % (region, jet_str),
has_data=False)
plot_cutflow_hist(in_tfile.Get("Dijet_QG_Unfold_%s_tighter/fakes_countercharged_" % (region)),
output_filename=os.path.join(args.outputDir, 'cutflow_dijet_unfold_%s_charged_fakes.pdf' % (region)),
title='Dijet (%s) unfolding fakes (ungroomed, charged-only vars)\n%s' % (region, jet_str),
has_data=False)
plot_cutflow_hist(in_tfile.Get("Dijet_QG_Unfold_%s_tighter_groomed/fakes_counter" % (region)),
output_filename=os.path.join(args.outputDir, 'cutflow_dijet_unfold_%s_groomed_fakes.pdf' % (region)),
title='Dijet (%s) unfolding fakes (groomed, charged+neutral vars)\n%s' % (region, jet_str),
has_data=False)
plot_cutflow_hist(in_tfile.Get("Dijet_QG_Unfold_%s_tighter_groomed/fakes_countercharged_" % (region)),
output_filename=os.path.join(args.outputDir, 'cutflow_dijet_unfold_%s_groomed_charged_fakes.pdf' % (region)),
title='Dijet (%s) unfolding fakes (groomed, charged-only vars)\n%s' % (region, jet_str),
has_data=False)
else:
# Plot reco cutflow (no gen requirements)
plot_cutflow_hist(in_tfile.Get("cf_DijetSelTighterCutFlow"),
output_filename=os.path.join(args.outputDir, 'cutflow_dijet_reco_sel_tighter.pdf'),
title='Dijet reco selection cutflow\n%s' % (jet_str),
has_data=True)
# Z+Jet
else:
if not is_data:
# Plot dijet reco cutflow, having passed gen selection (i.e. why inefficient)
plot_cutflow_hist(in_tfile.Get("cf_ZPlusJetsSelPassGenCutFlow"),
output_filename=os.path.join(args.outputDir, 'cutflow_ZPlusJets_reco_sel_passGen.pdf'),
title='Z+jet reco selection cutflow, having passed gen selection\n%s' % (jet_str),
has_data=False)
# Plot reco cutflow (no gen requirements)
plot_cutflow_hist(in_tfile.Get("cf_ZPlusJetsSelCutFlow"),
output_filename=os.path.join(args.outputDir, 'cutflow_ZPlusJets_reco_sel.pdf'),
title='Z+jet reco selection cutflow (no requirements on gen selection)\n%s' % (jet_str),
has_data=False)
# Plot dijet gen cutflow, having passed reco selection (i.e. why fakes)
plot_cutflow_hist(in_tfile.Get("cf_ZPlusJetsGenSelPassRecoCutFlow"),
output_filename=os.path.join(args.outputDir, 'cutflow_ZPlusJets_gen_sel_passReco.pdf'),
title='Z+jet gen selection cutflow, having passed reco selection\n%s' % (jet_str),
has_data=False)
# Plot dijet gen cutflow (no reco requirements)
plot_cutflow_hist(in_tfile.Get("cf_ZPlusJetsGenSelCutFlow"),
output_filename=os.path.join(args.outputDir, 'cutflow_ZPlusJets_gen_sel.pdf'),
title='Z+jet gen selection cutflow (no requirements on reco selection)\n%s' % (jet_str),
has_data=False)
# Plot unfolding fakes cause
plot_cutflow_hist(in_tfile.Get("ZPlusJets_QG_Unfold_tighter/fakes_counter"),
output_filename=os.path.join(args.outputDir, 'cutflow_ZPlusJets_unfold_fakes.pdf'),
title='Z+jet unfolding fakes (ungroomed, charged+neutral vars)\n%s' % (jet_str),
has_data=False)
plot_cutflow_hist(in_tfile.Get("ZPlusJets_QG_Unfold_tighter/fakes_countercharged_"),
output_filename=os.path.join(args.outputDir, 'cutflow_ZPlusJets_unfold_charged_fakes.pdf'),
title='Z+jet unfolding fakes (ungroomed, charged-only vars)\n%s' % (jet_str),
has_data=False)
plot_cutflow_hist(in_tfile.Get("ZPlusJets_QG_Unfold_tighter_groomed/fakes_counter"),
output_filename=os.path.join(args.outputDir, 'cutflow_ZPlusJets_unfold_groomed_fakes.pdf'),
title='Z+jet unfolding fakes (groomed, charged+neutral vars)\n%s' % (jet_str),
has_data=False)
plot_cutflow_hist(in_tfile.Get("ZPlusJets_QG_Unfold_tighter_groomed/fakes_countercharged_"),
output_filename=os.path.join(args.outputDir, 'cutflow_ZPlusJets_unfold_groomed_charged_fakes.pdf'),
title='Z+jet unfolding fakes (groomed, charged-only vars)\n%s' % (jet_str),
has_data=False)
else:
# Plot reco cutflow (no gen requirements)
plot_cutflow_hist(in_tfile.Get("cf_ZPlusJetsSelCutFlow"),
output_filename=os.path.join(args.outputDir, 'cutflow_ZPlusJets_reco_sel.pdf'),
title='Z+jet reco selection cutflow\n%s' % (jet_str),
has_data=True)