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')