5 Plot trigger and reconstruction efficiencies over entire data-periods.
9 import python_tools
as pt
10 import ZLumiScripts.tools.zlumi_mc_cf
as dq_cf
12 from array
import array
15 parser = argparse.ArgumentParser()
16 parser.add_argument(
'--year', type=str, help=
'A year number (15-24) or run3 for full Run3')
17 parser.add_argument(
'--channel', type=str, help=
'Zee or Zmumu')
18 parser.add_argument(
'--indir', type=str, help=
'Input directory for CSV files')
19 parser.add_argument(
'--outdir', type=str, help=
'Output directory for plots')
21 args = parser.parse_args()
23 channel = args.channel
28 years = [
"22",
"23",
"24"]
32 xtitle =
'Month / Year'
33 date_tag =
"Run 3, #sqrt{s} = 13.6 TeV"
34 if channel
is not None:
46 xtitle =
'Date in 20' + year
47 date_tag =
"Data 20" + year +
", #sqrt{s} = 13.6 TeV"
65 vec_comb_err =
array(
'd')
68 grl = pt.get_grl(year)
71 livetime, zlumi, zerr, olumi, timestamp, dfz_small = pt.get_dfz(args.indir, year, run, channel)
74 if livetime < pt.runlivetimecut:
75 if livetime >= 0.:
print(f
"Skip Run {run} because of live time {livetime/60:.1f} min")
78 dfz_small[
'CombEff'] = dfz_small[channel +
'EffComb']
79 dfz_small[
'CombErr'] = dfz_small[channel +
'ErrComb']
83 dfz_small[
'CombEff'] *= dq_cf.correction(dfz_small[
'OffMu'], channel, campaign,
int(run))
84 dfz_small[
'CombErr'] *= dq_cf.correction(dfz_small[
'OffMu'], channel, campaign,
int(run))
86 for index, event
in dfz_small.iterrows():
87 pileup =
int(event.OffMu)
89 weight_comb = 1/
pow(event.CombErr, 2)
90 if pileup
not in dict_mu:
91 dict_mu[pileup] = pileup
92 dict_comb[pileup] = weight_comb * event.CombEff
93 dict_comb_err[pileup] = weight_comb
95 dict_comb[pileup] += weight_comb * event.CombEff
96 dict_comb_err[pileup] += weight_comb
99 print(
"File has no filled lumi blocks!")
102 for pileup
in dict_mu:
103 comb_weighted_average = dict_comb[pileup]/dict_comb_err[pileup]
104 comb_error = sqrt(1/dict_comb_err[pileup])
105 vec_comb.append(comb_weighted_average)
106 vec_comb_err.append(comb_error)
108 vec_mu.append(pileup)
110 all_graphs.append((year, R.TGraphErrors(len(vec_comb), vec_mu, vec_comb, R.nullptr, vec_comb_err)))
114 leg = R.TLegend(0.645, 0.7, 0.805, 0.9)
116 ymin, ymax = 0.52, 0.74
117 elif channel ==
"Zmumu":
118 ymin, ymax = 0.74, 0.84
121 for igraph
in range(len(all_graphs)):
122 comb_graph = all_graphs[igraph][1]
123 comb_graph.SetMarkerSize(1)
124 comb_graph.SetMarkerColor(R.kBlack+igraph)
125 comb_graph.SetMarkerStyle(R.kFullCircle+igraph)
127 comb_graph.Draw(
"ap")
128 comb_graph.GetHistogram().SetYTitle(
"#varepsilon_{event}^{"+pt.plotlabel[channel]+
"}#times F^{MC}")
129 comb_graph.GetHistogram().GetYaxis().SetRangeUser(ymin, ymax)
130 comb_graph.GetHistogram().GetXaxis().SetLimits(xmin, xmax)
131 comb_graph.GetHistogram().SetXTitle(
"Pileup (#mu)")
133 comb_graph.Draw(
"p same")
135 leg.SetTextSize(0.07)
136 leg.AddEntry(comb_graph,
"Data 20"+all_graphs[igraph][0],
"ep")
140 pt.drawAtlasLabel(0.6, ymax-0.46,
"Internal")
141 pt.drawText(0.2, ymax-0.46, date_tag)
142 pt.drawText(0.2, ymax-0.52, pt.plotlabel[channel] +
" counting")
143 elif channel ==
"Zmumu":
144 pt.drawAtlasLabel(0.6, ymax-0.56,
"Internal")
145 pt.drawText(0.2, ymax-0.62, pt.plotlabel[channel] +
" counting")
147 c1.SaveAs(outdir + channel +
"_eventeff_vs_mu_"+out_tag+
".pdf")
149 if __name__ ==
"__main__":
151 R.gROOT.SetBatch(R.kTRUE)