ATLAS Offline Software
Functions | Variables
plotting.luminosity Namespace Reference

Functions

def main ()
 
def plot_channel (channel)
 
def plot_ratio ()
 

Variables

 parser = argparse.ArgumentParser()
 
 type
 
 str
 
 help
 
 action
 
 args = parser.parse_args()
 
 infilename = args.infile
 
 outdir = args.outdir
 

Function Documentation

◆ main()

def plotting.luminosity.main ( )

Definition at line 26 of file luminosity.py.

26 def main():
27  plot_channel('Zmumu')
28  plot_channel('Zee')
29  plot_channel('Zll')
30  plot_ratio()
31 

◆ plot_channel()

def plotting.luminosity.plot_channel (   channel)

Definition at line 32 of file luminosity.py.

32 def plot_channel(channel):
33  dfz = pd.read_csv(infilename, delimiter=',')
34  if dfz.empty:
35  print('No data in file', infilename, ', exiting.')
36  return
37 
38  run_number = dfz.RunNum[0]
39  lhc_fill = dfz.FillNum[0]
40 
41  if args.t0:
42  rfo = R.TFile.Open(os.path.join(outdir, 'zlumi.root'), 'RECREATE')
43 
44  Lumi = channel+'Lumi'
45  LumiErr = channel+'LumiErr'
46  LumiString = "Z #rightarrow "+channel[1:]
47  LumiString = LumiString.replace("mu", "#mu")
48 
49  # Drop LBs with no Z-counting information or short livetime
50  dfz0 = dfz.copy()
51  if args.dropzero:
52  dfz = dfz.drop(dfz[(dfz[Lumi] == 0)].index)
53  dfz = dfz.drop(dfz[(dfz['LBLive']<pt.lblivetimecut) | (dfz['PassGRL']==0)].index)
54  if len(dfz) == 0:
55  print("No valid LBs found. Exiting")
56  return
57 
58  # Calculate overall ratio against ATLAS
59  normalisation = dfz[Lumi].sum() / dfz['OffLumi'].sum()
60  print(f"{Lumi}/OffLumi mean ratio = {normalisation:.3f}")
61 
62  dfz['OffDelLumi'] = dfz['OffLumi']*dfz['LBFull']
63 
64  # Add by groups of 20 LBs or pileup bins: scale by livetime, square errors, add, unscale livetime
65  for entry in [Lumi, LumiErr, 'OffLumi']:
66  dfz[entry] *= dfz['LBLive']
67  dfz[LumiErr] *= dfz[LumiErr]
68  if args.usemu:
69  dfz['OffMu'] = dfz['OffMu'].astype(int)
70  dfz = dfz.groupby(['OffMu']).sum()
71  else:
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']
77 
78  if args.t0:
79  translist = []
80  timeformat = '%y/%m/%d %H:%M:%S'
81  import time
82  for k in range(len(dfz)):
83  thisrow = dfz.iloc[k]
84  lb = thisrow.name
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, # time-averaged instantaneous delivered lumi
93  'delLumi': thisrow['OffLumi']/1e3, # livetime * instantaneous delivered lumi
94  'ZDel': thisrow['ZmumuRate'] # after above, this variable is yield not rate
95  })
96  pdn = pd.DataFrame.from_records(translist)
97  pdn.to_csv(os.path.join(args.outdir, 'zrate.csv'), header=False, index=False)
98 
99  if args.usemu:
100  leg = R.TLegend(0.6, 0.33, 0.75, 0.5)
101  xtitle = "<#mu>"
102  outfile = channel+"ATLAS_vs_mu"
103  else:
104  leg = R.TLegend(0.62, 0.75, 0.75, 0.9)
105  xtitle = "Luminosity Block Number"
106  outfile = channel+"ATLAS_vs_lb"
107 
108  if args.absolute:
109  outfile += "_abs"
110  normalisation = 1.
111 
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'])
118 
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)
122 
123  ho.SetLineColor(R.kAzure)
124  ho.SetLineWidth(3)
125 
126  c1 = R.TCanvas()
127 
128  pad1 = R.TPad("pad1", "pad1", 0, 0, 1, 1)
129  pad1.SetBottomMargin(0.3)
130  pad1.SetFillStyle(4000)
131  pad1.Draw()
132  pad1.cd()
133  pad1.RedrawAxis()
134  hz.GetXaxis().SetLabelSize(0)
135 
136  xmin = hz.GetXaxis().GetXmin()
137  xmax = hz.GetXaxis().GetXmax()
138 
139  hz.SetMarkerStyle(4)
140  hz.Draw('ap')
141  ho.Draw("same L")
142  hz.Draw('same p')
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()
148  if not args.usemu:
149  hz.GetYaxis().SetRangeUser(ymin*0.8, ymax*1.4)
150 
151  leg.SetBorderSize(0)
152  leg.SetTextSize(0.055)
153  if args.absolute:
154  leg.AddEntry(hz, "L_{"+LumiString+"}", "ep")
155  else:
156  leg.AddEntry(hz, "L_{"+LumiString+"}^{normalised to L_{ATLAS}^{fill}}", "ep")
157  leg.AddEntry(ho, "L_{ATLAS}", "l")
158  leg.Draw()
159 
160  pad2 = R.TPad("pad2", "pad2", 0, 0, 1, 1)
161  pad2.SetTopMargin(0.72)
162  pad2.SetBottomMargin(0.1)
163  pad2.SetFillStyle(4000)
164  pad2.Draw()
165  pad2.cd()
166 
167  hr.Draw("ap0")
168  hr.GetYaxis().SetTitle("Ratio")
169  hr.GetXaxis().SetTitle(xtitle)
170  hr.GetXaxis().SetTitleOffset(0.865)
171 
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)
178 
179  line0 = R.TLine(xmin, 1.0, xmax, 1.0)
180  line0.SetLineStyle(2)
181  line0.Draw()
182 
183  line1 = R.TLine(xmin, (ymin+1.)/2., xmax, (ymin+1.)/2.)
184  line1.SetLineStyle(2)
185  line1.Draw()
186 
187  line2 = R.TLine(xmin, (ymax+1.)/2., xmax, (ymax+1.)/2.)
188  line2.SetLineStyle(2)
189  line2.Draw()
190 
191  hr.GetYaxis().SetNdivisions(3)
192 
193  if run_number < 427394:
194  yearsqrtstxt = "Data 20" + pt.get_year(run_number) + ", #sqrt{s} = 13 TeV"
195  else:
196  yearsqrtstxt = "Data 20" + pt.get_year(run_number) + ", #sqrt{s} = 13.6 TeV"
197 
198  pt.drawAtlasLabel(0.2, 0.88, "Internal")
199  if not args.t0:
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)
203 
204  line4 = pt.make_bands(arr_bins, spread, median)
205  line4.Draw("same 3")
206  hr.Draw("same ep0")
207 
208  if not args.t0:
209  c1.SaveAs(os.path.join(outdir, outfile + ".pdf"))
210  else:
211  rfo.WriteTObject(c1, outfile)
212  if channel == 'Zmumu':
213  rfo.WriteTObject(hz, 'z_lumi')
214  rfo.WriteTObject(hr, 'z_lumi_ratio')
215  c1.Clear()
216 
217 
218  #Plot ratio with fit
219  c2 = R.TCanvas()
220  hr.GetXaxis().SetTitleOffset(1)
221  hr.Draw('ap0')
222 
223  hr.Fit('pol0', 'q0')
224  hr.GetFunction('pol0').SetLineColor(R.kRed)
225 
226  hr.GetYaxis().SetTitle("Ratio")
227  hr.GetXaxis().SetTitle(xtitle)
228  hr.GetYaxis().SetRangeUser(0.9, 1.1)
229  hr.GetYaxis().SetNdivisions()
230 
231  mean = hr.GetFunction("pol0").GetParameter(0)
232  line0 = pt.make_bands(arr_bins, spread, median)
233  line0.Draw("same 3")
234  hr.Draw("same ep0")
235  hr.GetFunction('pol0').Draw('same l')
236 
237  pt.drawAtlasLabel(0.2, 0.88, "Internal")
238  if not args.t0:
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)
242 
243  leg = R.TLegend(0.17, 0.2, 0.90, 0.3)
244  leg.SetBorderSize(0)
245  leg.SetTextSize(0.05)
246  leg.SetNColumns(3)
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")
250  leg.Draw()
251 
252  if not args.t0:
253  c2.SaveAs(os.path.join(outdir, outfile+"_ratio.pdf"))
254  else:
255  rfo.WriteTObject(c2, f'{outfile}_ratio')
256 
257  return
258 

◆ plot_ratio()

def plotting.luminosity.plot_ratio ( )

Definition at line 259 of file luminosity.py.

259 def plot_ratio():
260  dfz = pd.read_csv(infilename, delimiter=',')
261  if dfz.empty:
262  print('No data in file', infilename, ', exiting.')
263  return
264 
265  run_number = dfz.RunNum[0]
266  lhc_fill = dfz.FillNum[0]
267 
268  if args.t0:
269  rfo = R.TFile.Open(os.path.join(outdir, 'zlumi.root'), 'RECREATE')
270 
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)
273  if len(dfz) == 0:
274  print("No valid LBs found. Exiting")
275  return
276 
277  # Add by groups of 20 LBs or pileup bins: scale by livetime, square errors, add, unscale livetime
278  for entry in ['ZeeLumi','ZmumuLumi','ZeeLumiErr','ZmumuLumiErr']:
279  dfz[entry] *= dfz['LBLive']
280  for entry in ['ZeeLumiErr','ZmumuLumiErr']:
281  dfz[entry] *= dfz[entry]
282  if args.usemu:
283  dfz['OffMu'] = dfz['OffMu'].astype(int)
284  dfz = dfz.groupby(['OffMu']).sum()
285  else:
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']
292 
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)))
296 
297  gr = R.TGraphErrors(len(arr_rat), arr_bins, arr_rat, R.nullptr, arr_rat_err)
298 
299  c1 = R.TCanvas()
300  gr.SetTitle("")
301  gr.Draw("ap")
302 
303  if args.usemu:
304  xtitle = "<#mu>"
305  outfile = "ZeeZmm_ratio_vs_mu.pdf"
306  else:
307  xtitle = "Luminosity Block Number"
308  outfile = "ZeeZmm_ratio_vs_lb.pdf"
309 
310  gr.GetXaxis().SetTitle(xtitle)
311  gr.GetYaxis().SetTitle("L_{Z #rightarrow ee} / L_{Z #rightarrow #mu#mu}")
312 
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)
318 
319  gr.Fit("pol0", "q0")
320  gr.GetFunction("pol0").SetLineColor(R.kRed)
321 
322  mean = gr.GetFunction("pol0").GetParameter(0)
323  line1 = pt.make_bands(arr_bins, spread, median)
324  line1.Draw("same 3")
325  gr.GetFunction("pol0").Draw("same l")
326  gr.Draw("same ep")
327 
328  if run_number < 427394:
329  yearsqrtstxt = "Data 20" + pt.get_year(run_number) + ", #sqrt{s} = 13 TeV"
330  else:
331  yearsqrtstxt = "Data 20" + pt.get_year(run_number) + ", #sqrt{s} = 13.6 TeV"
332 
333  pt.drawAtlasLabel(0.2, 0.88, "Internal")
334  if not args.t0:
335  pt.drawText(0.2, 0.82, yearsqrtstxt, size=22)
336  pt.drawText(0.2, 0.77, "LHC Fill " + str(lhc_fill), size=22)
337 
338  leg = R.TLegend(0.17, 0.2, 0.90, 0.3)
339  leg.SetBorderSize(0)
340  leg.SetTextSize(0.05)
341  leg.SetNColumns(3)
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")
345  leg.Draw()
346 
347  if not args.t0:
348  c1.SaveAs(os.path.join(outdir, outfile))
349  else:
350  rfo.WriteTObject(c1, 'zeezmmratio')
351 

Variable Documentation

◆ action

plotting.luminosity.action

Definition at line 17 of file luminosity.py.

◆ args

plotting.luminosity.args = parser.parse_args()

Definition at line 22 of file luminosity.py.

◆ help

plotting.luminosity.help

Definition at line 15 of file luminosity.py.

◆ infilename

plotting.luminosity.infilename = args.infile

Definition at line 23 of file luminosity.py.

◆ outdir

plotting.luminosity.outdir = args.outdir

Definition at line 24 of file luminosity.py.

◆ parser

plotting.luminosity.parser = argparse.ArgumentParser()

Definition at line 14 of file luminosity.py.

◆ str

plotting.luminosity.str

Definition at line 15 of file luminosity.py.

◆ type

plotting.luminosity.type

Definition at line 15 of file luminosity.py.

convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
array
str
Definition: BTagTrackIpAccessor.cxx:11
plotting.luminosity.main
def main()
Definition: luminosity.py:26
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15
plotting.luminosity.plot_channel
def plot_channel(channel)
Definition: luminosity.py:32
plotting.luminosity.plot_ratio
def plot_ratio()
Definition: luminosity.py:259