6 from .
import python_tools
as pt
10 from array
import array
14 parser = argparse.ArgumentParser()
15 parser.add_argument(
'--infile', type=str, help=
'input file')
16 parser.add_argument(
'--outdir', type=str, help=
'output directory')
17 parser.add_argument(
'--usemu', action=
'store_true', help=
'Plot vs. mu. Default == LB')
18 parser.add_argument(
'--absolute', action=
'store_true', help=
'Use for official lumi absolute comparison')
19 parser.add_argument(
'--t0', action=
'store_true', help=
'Modifications for t0 operation')
20 parser.add_argument(
'--dropzero', action=
'store_true', help=
'Drop LBs with zero Z counting lumi in either channel')
22 args = parser.parse_args()
23 infilename = args.infile
33 dfz = pd.read_csv(infilename, delimiter=
',')
35 print(
'No data in file', infilename,
', exiting.')
38 run_number = dfz.RunNum[0]
39 lhc_fill = dfz.FillNum[0]
42 rfo = R.TFile.Open(os.path.join(outdir,
'zlumi.root'),
'RECREATE')
45 LumiErr = channel+
'LumiErr'
46 LumiString =
"Z #rightarrow "+channel[1:]
47 LumiString = LumiString.replace(
"mu",
"#mu")
52 dfz = dfz.drop(dfz[(dfz[Lumi] == 0)].index)
53 dfz = dfz.drop(dfz[(dfz[
'LBLive']<pt.lblivetimecut) | (dfz[
'PassGRL']==0)].index)
55 print(
"No valid LBs found. Exiting")
59 normalisation = dfz[Lumi].
sum() / dfz[
'OffLumi'].
sum()
60 print(f
"{Lumi}/OffLumi mean ratio = {normalisation:.3f}")
62 dfz[
'OffDelLumi'] = dfz[
'OffLumi']*dfz[
'LBFull']
65 for entry
in [Lumi, LumiErr,
'OffLumi']:
66 dfz[entry] *= dfz[
'LBLive']
67 dfz[LumiErr] *= dfz[LumiErr]
69 dfz[
'OffMu'] = dfz[
'OffMu'].astype(int)
70 dfz = dfz.groupby([
'OffMu']).
sum()
72 dfz[
'LBNum'] = (dfz[
'LBNum']//20)*20
73 dfz = dfz.groupby([
'LBNum']).
sum()
74 dfz[LumiErr] = np.sqrt(dfz[LumiErr])
75 for entry
in [Lumi, LumiErr,
'OffLumi']:
76 dfz[entry] /= dfz[
'LBLive']
80 timeformat =
'%y/%m/%d %H:%M:%S'
82 for k
in range(len(dfz)):
85 lbselector = (lb <= dfz0[
'LBNum']) & (dfz0[
'LBNum'] < lb+20)
86 translist.append({
'FillNum' : dfz0[lbselector][
'FillNum'].iloc[0],
87 'beginTime' : time.strftime(timeformat,
88 time.gmtime(dfz0[lbselector][
'LBStart'].iloc[0])),
89 'endTime': time.strftime(timeformat,
90 time.gmtime(dfz0[(dfz0[
'LBNum']//20)*20 == lb][
'LBEnd'].iloc[-1])),
91 'ZmumuRate': thisrow[
'ZmumuRate']/thisrow[
'LBLive'],
92 'instDelLumi': thisrow[
'OffDelLumi']/thisrow[
'LBFull']/1e3,
93 'delLumi': thisrow[
'OffLumi']/1e3,
94 'ZDel': thisrow[
'ZmumuRate']
96 pdn = pd.DataFrame.from_records(translist)
97 pdn.to_csv(os.path.join(args.outdir,
'zrate.csv'), header=
False, index=
False)
100 leg = R.TLegend(0.6, 0.33, 0.75, 0.5)
102 outfile = channel+
"ATLAS_vs_mu"
104 leg = R.TLegend(0.62, 0.75, 0.75, 0.9)
105 xtitle =
"Luminosity Block Number"
106 outfile = channel+
"ATLAS_vs_lb"
112 arr_bins =
array(
'd', dfz.index)
113 arr_zlumi =
array(
'd', dfz[Lumi] / normalisation)
114 arr_zlumi_err =
array(
'd', dfz[LumiErr] / normalisation)
115 arr_rat =
array(
'd', dfz[Lumi] / dfz[
'OffLumi'] / normalisation)
116 arr_rat_err =
array(
'd', dfz[LumiErr] / dfz[
'OffLumi'] / normalisation)
117 arr_olumi =
array(
'd', dfz[
'OffLumi'])
119 hz = R.TGraphErrors(len(arr_bins), arr_bins, arr_zlumi, R.nullptr, arr_zlumi_err)
120 ho = R.TGraphErrors(len(arr_bins), arr_bins, arr_olumi, R.nullptr, R.nullptr)
121 hr = R.TGraphErrors(len(arr_bins), arr_bins, arr_rat, R.nullptr, arr_rat_err)
123 ho.SetLineColor(R.kAzure)
128 pad1 = R.TPad(
"pad1",
"pad1", 0, 0, 1, 1)
129 pad1.SetBottomMargin(0.3)
130 pad1.SetFillStyle(4000)
134 hz.GetXaxis().SetLabelSize(0)
136 xmin = hz.GetXaxis().GetXmin()
137 xmax = hz.GetXaxis().GetXmax()
143 hz.GetYaxis().SetTitle(
"Luminosity [10^{33} cm^{-2}s^{-1}]")
144 hz.GetXaxis().SetTitle(xtitle)
145 hz.GetXaxis().SetTitleOffset(0.8)
146 ymax = hz.GetHistogram().GetMaximum()
147 ymin = hz.GetHistogram().GetMinimum()
149 hz.GetYaxis().SetRangeUser(ymin*0.8, ymax*1.4)
152 leg.SetTextSize(0.055)
154 leg.AddEntry(hz,
"L_{"+LumiString+
"}",
"ep")
156 leg.AddEntry(hz,
"L_{"+LumiString+
"}^{normalised to L_{ATLAS}^{fill}}",
"ep")
157 leg.AddEntry(ho,
"L_{ATLAS}",
"l")
160 pad2 = R.TPad(
"pad2",
"pad2", 0, 0, 1, 1)
161 pad2.SetTopMargin(0.72)
162 pad2.SetBottomMargin(0.1)
163 pad2.SetFillStyle(4000)
168 hr.GetYaxis().SetTitle(
"Ratio")
169 hr.GetXaxis().SetTitle(xtitle)
170 hr.GetXaxis().SetTitleOffset(0.865)
172 ymin, ymax = 0.95, 1.05
173 median = np.median(arr_rat)
174 spread = np.percentile(abs(arr_rat - median), 68)
175 if spread > 0.03: ymin, ymax = 0.9, 1.1
176 if args.absolute
and args.t0: ymin, ymax = 0.9, 1.1
177 hr.GetYaxis().SetRangeUser(ymin, ymax)
179 line0 = R.TLine(xmin, 1.0, xmax, 1.0)
180 line0.SetLineStyle(2)
183 line1 = R.TLine(xmin, (ymin+1.)/2., xmax, (ymin+1.)/2.)
184 line1.SetLineStyle(2)
187 line2 = R.TLine(xmin, (ymax+1.)/2., xmax, (ymax+1.)/2.)
188 line2.SetLineStyle(2)
191 hr.GetYaxis().SetNdivisions(3)
193 if run_number < 427394:
194 yearsqrtstxt =
"Data 20" + pt.get_year(run_number) +
", #sqrt{s} = 13 TeV"
196 yearsqrtstxt =
"Data 20" + pt.get_year(run_number) +
", #sqrt{s} = 13.6 TeV"
198 pt.drawAtlasLabel(0.2, 0.88,
"Internal")
200 pt.drawText(0.2, 0.82, yearsqrtstxt, size=22)
201 pt.drawText(0.2, 0.77,
"LHC Fill " +
str(lhc_fill), size=22)
202 pt.drawText(0.2, 0.72, LumiString +
" counting", size=22)
204 line4 = pt.make_bands(arr_bins, spread, median)
209 c1.SaveAs(os.path.join(outdir, outfile +
".pdf"))
211 rfo.WriteTObject(c1, outfile)
212 if channel ==
'Zmumu':
213 rfo.WriteTObject(hz,
'z_lumi')
214 rfo.WriteTObject(hr,
'z_lumi_ratio')
220 hr.GetXaxis().SetTitleOffset(1)
224 hr.GetFunction(
'pol0').SetLineColor(R.kRed)
226 hr.GetYaxis().SetTitle(
"Ratio")
227 hr.GetXaxis().SetTitle(xtitle)
228 hr.GetYaxis().SetRangeUser(0.9, 1.1)
229 hr.GetYaxis().SetNdivisions()
231 mean = hr.GetFunction(
"pol0").GetParameter(0)
232 line0 = pt.make_bands(arr_bins, spread, median)
235 hr.GetFunction(
'pol0').Draw(
'same l')
237 pt.drawAtlasLabel(0.2, 0.88,
"Internal")
239 pt.drawText(0.2, 0.82, yearsqrtstxt, size=22)
240 pt.drawText(0.2, 0.77,
"LHC Fill " +
str(lhc_fill), size=22)
241 pt.drawText(0.2, 0.72, LumiString +
" counting", size=22)
243 leg = R.TLegend(0.17, 0.2, 0.90, 0.3)
245 leg.SetTextSize(0.05)
247 leg.AddEntry(hr,
"L_{"+LumiString+
"}/L_{ATLAS}",
"ep")
248 leg.AddEntry(hr.GetFunction(
"pol0"), f
"Mean = {mean:.3f}",
"l")
249 leg.AddEntry(line0,
"68% band",
"f")
253 c2.SaveAs(os.path.join(outdir, outfile+
"_ratio.pdf"))
255 rfo.WriteTObject(c2, f
'{outfile}_ratio')
260 dfz = pd.read_csv(infilename, delimiter=
',')
262 print(
'No data in file', infilename,
', exiting.')
265 run_number = dfz.RunNum[0]
266 lhc_fill = dfz.FillNum[0]
269 rfo = R.TFile.Open(os.path.join(outdir,
'zlumi.root'),
'RECREATE')
271 dfz = dfz.drop(dfz[(dfz.ZeeLumi == 0) | (dfz.ZmumuLumi == 0)].index)
272 dfz = dfz.drop(dfz[(dfz[
'LBLive']<pt.lblivetimecut) | (dfz[
'PassGRL']==0)].index)
274 print(
"No valid LBs found. Exiting")
278 for entry
in [
'ZeeLumi',
'ZmumuLumi',
'ZeeLumiErr',
'ZmumuLumiErr']:
279 dfz[entry] *= dfz[
'LBLive']
280 for entry
in [
'ZeeLumiErr',
'ZmumuLumiErr']:
281 dfz[entry] *= dfz[entry]
283 dfz[
'OffMu'] = dfz[
'OffMu'].astype(int)
284 dfz = dfz.groupby([
'OffMu']).
sum()
286 dfz[
'LBNum'] = (dfz[
'LBNum']//20)*20
287 dfz = dfz.groupby([
'LBNum']).
sum()
288 for entry
in [
'ZeeLumiErr',
'ZmumuLumiErr']:
289 dfz[entry] = np.sqrt(dfz[entry])
290 for entry
in [
'ZeeLumi',
'ZmumuLumi',
'ZeeLumiErr',
'ZmumuLumiErr']:
291 dfz[entry] /= dfz[
'LBLive']
293 arr_bins =
array(
'd', dfz.index)
294 arr_rat =
array(
'd', dfz[
'ZeeLumi'] / dfz[
'ZmumuLumi'])
295 arr_rat_err =
array(
'd', (dfz[
'ZeeLumi'] / dfz[
'ZmumuLumi']) * np.sqrt(
pow(dfz[
'ZeeLumiErr']/dfz[
'ZeeLumi'], 2) +
pow(dfz[
'ZmumuLumiErr']/dfz[
'ZmumuLumi'], 2)))
297 gr = R.TGraphErrors(len(arr_rat), arr_bins, arr_rat, R.nullptr, arr_rat_err)
305 outfile =
"ZeeZmm_ratio_vs_mu.pdf"
307 xtitle =
"Luminosity Block Number"
308 outfile =
"ZeeZmm_ratio_vs_lb.pdf"
310 gr.GetXaxis().SetTitle(xtitle)
311 gr.GetYaxis().SetTitle(
"L_{Z #rightarrow ee} / L_{Z #rightarrow #mu#mu}")
313 ymin, ymax = 0.85, 1.15
314 median = np.median(arr_rat)
315 spread = np.percentile(abs(arr_rat - median), 68)
316 if spread > 0.05: ymin, ymax = 0.75, 1.25
317 gr.GetYaxis().SetRangeUser(ymin, ymax)
320 gr.GetFunction(
"pol0").SetLineColor(R.kRed)
322 mean = gr.GetFunction(
"pol0").GetParameter(0)
323 line1 = pt.make_bands(arr_bins, spread, median)
325 gr.GetFunction(
"pol0").Draw(
"same l")
328 if run_number < 427394:
329 yearsqrtstxt =
"Data 20" + pt.get_year(run_number) +
", #sqrt{s} = 13 TeV"
331 yearsqrtstxt =
"Data 20" + pt.get_year(run_number) +
", #sqrt{s} = 13.6 TeV"
333 pt.drawAtlasLabel(0.2, 0.88,
"Internal")
335 pt.drawText(0.2, 0.82, yearsqrtstxt, size=22)
336 pt.drawText(0.2, 0.77,
"LHC Fill " +
str(lhc_fill), size=22)
338 leg = R.TLegend(0.17, 0.2, 0.90, 0.3)
340 leg.SetTextSize(0.05)
342 leg.AddEntry(gr,
"L_{Z #rightarrow ee}/L_{Z #rightarrow #mu#mu}",
"ep")
343 leg.AddEntry(gr.GetFunction(
"pol0"), f
"Mean = {mean:.3f}",
"l")
344 leg.AddEntry(line1,
"68% band",
"f")
348 c1.SaveAs(os.path.join(outdir, outfile))
350 rfo.WriteTObject(c1,
'zeezmmratio')
352 if __name__ ==
"__main__":
354 R.gStyle.SetTitleOffset(1,
'xy')
355 R.gStyle.SetLabelSize(0.045,
'xy')
356 R.gStyle.SetTitleSize(0.052,
'xy')
357 R.gROOT.SetBatch(R.kTRUE)