ATLAS Offline Software
Functions | Variables
plotting.yearwise_luminosity Namespace Reference

Functions

def main ()
 
def channel_comparison (years)
 
def zcounting_vs_atlas (channel, years)
 

Variables

 parser = argparse.ArgumentParser()
 
 type
 
 str
 
 help
 
 action
 
 args = parser.parse_args()
 
 year = args.year
 
 channel = args.channel
 
 absolute = args.absolute
 
 indir = args.indir
 
 outdir = args.outdir
 
 outcsv = args.outcsv
 
float yval = 0.85
 
float xval = 0.2
 
 ymin
 
 ymax
 
list years = ["22", "23", "24"]
 
string out_tag = "run3"
 
string time_format = "%m/%y"
 
string xtitle = 'Month / Year'
 
string date_tag = "Run 3, #sqrt{s} = 13.6 TeV"
 
int labelsize = 44
 
string norm_type = "Run3"
 

Function Documentation

◆ channel_comparison()

def plotting.yearwise_luminosity.channel_comparison (   years)

Definition at line 63 of file yearwise_luminosity.py.

63 def channel_comparison(years):
64 
65  print("Lumi Channel Comparison vs Time for years: ", years)
66 
67  dict_zlumi = {}
68  for year in years:
69 
70  grl = pt.get_grl(year)
71 
72  for channel in ["Zee", "Zmumu"]:
73 
74  for run in grl:
75  livetime, zlumi, zerr, olumi, timestamp, dfz_small = pt.get_dfz(args.indir, year, run, channel)
76  # Cut out short runs
77  if livetime < pt.runlivetimecut:
78  if livetime >= 0.: print(f"Skip Run {run} because of live time {livetime/60:.1f} min")
79  continue
80 
81  dict_zlumi[channel, run] = (zlumi, zerr, timestamp)
82 
83  vec_times = array('d')
84  vec_ratio = array('d')
85  vec_ratio_err = array('d')
86  keys = [key[1] for key in dict_zlumi if "Zee" in key]
87 
88  # If plotting vs. date simply calculate integrated lumi per run and fill array
89  for key in sorted(keys):
90  try:
91  ratio = dict_zlumi["Zee", key][0]/dict_zlumi["Zmumu", key][0]
92  error = ratio * math.sqrt( pow(dict_zlumi["Zee", key][1]/dict_zlumi["Zee", key][0], 2) + pow(dict_zlumi["Zmumu", key][1]/dict_zlumi["Zmumu", key][0], 2) )
93  date = dict_zlumi["Zee", key][2]
94 
95  if ratio < ymin or ratio > ymax:
96  print("WARNING: Run", key, "has Zee/Zmumu ratio", ratio, ", outside of y-axis range")
97  else:
98  vec_times.append(date)
99  vec_ratio.append(ratio)
100  vec_ratio_err.append(error)
101  except KeyError:
102  print("Cannot do ratio for", key)
103 
104  tg = R.TGraphErrors(len(vec_times), vec_times, vec_ratio, R.nullptr, vec_ratio_err)
105  leg = R.TLegend(0.645, 0.72, 0.805, 0.91)
106  leg.SetFillStyle(0)
107 
108  # Depending if we're plotting over whole Run-3, change canvas size
109  if out_tag == "run3":
110  c1 = R.TCanvas("c1", "c1", 2000, 1000)
111  else:
112  c1 = R.TCanvas()
113 
114  tg.Draw('ap')
115  tg.GetYaxis().SetTitle('L_{Z #rightarrow ee} / L_{Z #rightarrow #mu#mu}')
116  tg.Fit('pol0', '0q')
117  tg.GetFunction('pol0').SetLineColor(R.kRed)
118 
119  mean = tg.GetFunction('pol0').GetParameter(0)
120 
121  # Plot 68% percentile band
122  stdev = np.percentile(abs(vec_ratio - np.median(vec_ratio)), 68)
123  line1 = pt.make_bands(vec_times, stdev, mean)
124  line1.Draw("same 3")
125  tg.GetFunction('pol0').Draw("same l")
126  tg.Draw('same ep')
127 
128  print("Pol0 fit mean +- 68% percentile = ", round(mean,3), " +- ", round(stdev, 3))
129 
130  leg.SetBorderSize(0)
131  leg.SetTextSize(0.05)
132  leg.AddEntry(tg, "L_{Z #rightarrow ee}/L_{Z #rightarrow #mu#mu}", "ep")
133  leg.AddEntry(tg.GetFunction("pol0"), "Mean = " + str(round(mean, 3)), "l")
134  leg.AddEntry(line1, "68% band", "f")
135  leg.Draw()
136 
137  pt.drawAtlasLabel(xval, 0.88, "Internal")
138  pt.drawText(xval, 0.82, date_tag, size=labelsize)
139 
140  new_trig_line = R.TLine(1683743066.0, 0.95, 1683743066.0, 1.05)
141 
142  new_trig_line.SetLineColor(R.kBlue)
143  new_trig_line.SetLineWidth(1)
144  new_trig_line.SetLineStyle(2)
145  new_trig_line.Draw("same")
146  R.gPad.Update()
147 
148  tg.GetYaxis().SetRangeUser(ymin, ymax)
149  tg.GetXaxis().SetTitle(xtitle)
150  tg.GetXaxis().SetTimeDisplay(2)
151  tg.GetXaxis().SetNdivisions(9,R.kFALSE)
152  tg.GetXaxis().SetTimeFormat(time_format)
153  tg.GetXaxis().SetTimeOffset(0,"gmt")
154 
155  if years == ["22", "23", "24"]:
156  plot_title = "Ratio of Electron and Muon channel Z-counting Luminosities across Run 3"
157  else:
158  plot_title = "Ratio of Electron and Muon channel Z-counting Luminosities across 20" + years[0]
159 
160  tg.SetTitle(plot_title)
161  c1.Update()
162  c1.SaveAs(outdir + "ZeeZmm_ratio_vs_time_"+out_tag+".pdf")
163 
164 

◆ main()

def plotting.yearwise_luminosity.main ( )

Definition at line 57 of file yearwise_luminosity.py.

57 def main():
58  if args.comp:
59  channel_comparison(years)
60  else:
61  zcounting_vs_atlas(channel, years)
62 

◆ zcounting_vs_atlas()

def plotting.yearwise_luminosity.zcounting_vs_atlas (   channel,
  years 
)
Plot normalised comparison of Z-counting luminosity to ATLAS luminosity.
This can be done as a function of time and pileup.

Definition at line 165 of file yearwise_luminosity.py.

165 def zcounting_vs_atlas(channel, years):
166  """
167  Plot normalised comparison of Z-counting luminosity to ATLAS luminosity.
168  This can be done as a function of time and pileup.
169  """
170 
171  zstring = pt.plotlabel[channel]+" counting"
172  ytitle = "L_{"+pt.plotlabel[channel]+"}/L_{ATLAS}"
173  if args.absolute:
174  leg_entry = "L_{"+pt.plotlabel[channel]+"}"
175  else:
176  leg_entry = "L_{"+pt.plotlabel[channel]+"}^{"+norm_type+"-normalised}/L_{ATLAS}"
177 
178  print("Channel", channel, "comparison to ATLAS vs time for years: ", years)
179 
180  arr_date = []
181  arr_olumi = []
182  arr_zlumi = []
183  arr_zerr = []
184  run_num = []
185  fill_num = []
186 
187  for year in years:
188 
189  grl = pt.get_grl(year)
190 
191  for run in grl:
192  livetime, zlumi, zerr, olumi, timestamp, dfz_small = pt.get_dfz(args.indir, year, run, channel)
193 
194  # Cut out short runs
195  if livetime < pt.runlivetimecut:
196  if livetime >= 0.: print(f"Skip Run {run} because of live time {livetime/60:.1f} min")
197  continue
198 
199  prelratio = zlumi/olumi
200  if prelratio < ymin or prelratio > ymax:
201  print("WARNING: Run", run, "has", channel, "/ATLAS ratio", prelratio, ", outside of y-axis range")
202 
203  # If plotting vs. date simply fill the arrays here
204  arr_date.append(timestamp)
205  arr_olumi.append(olumi)
206  arr_zlumi.append(zlumi)
207  arr_zerr.append(zerr)
208  run_num.append(run)
209  fill = dfz_small['FillNum'].median()
210  fill_num.append(int(fill))
211 
212 
213  # for ROOT plotting we need Python arrays
214  arr_date = array('d', arr_date)
215  # convert lists to numpy arrays
216  arr_olumi = np.array(arr_olumi)
217  arr_zlumi = np.array(arr_zlumi)
218  arr_zerr = np.array(arr_zerr)
219  total_lumi = arr_olumi.sum()/1000000
220  total_lumi_string = "Official DQ "
221  if year == "24": total_lumi_string = "Preliminary DQ "
222  total_lumi_string += str(round(total_lumi, 1)) + " fb^{-1}"
223 
224  #-----------Normalisation------------
225 
226  # Calculate and apply overall normalisation
227  if args.absolute:
228  normalisation = 1.0
229  else:
230  normalisation = np.sum(arr_zlumi) / np.sum(arr_olumi)
231 
232  # do normalisation to period integral
233  arr_zlumi /= normalisation
234  arr_zerr /= normalisation
235 
236  # calculate ratio to ATLAS preferred lumi
237  arr_zlumi_ratio = arr_zlumi/arr_olumi
238  arr_zerr_ratio = arr_zerr/arr_olumi
239 
240 #-----------Normalisation------------
241 
242  tg = R.TGraphErrors(len(arr_date), arr_date, array('d',arr_zlumi_ratio), R.nullptr, array('d',arr_zerr_ratio))
243 
244  # Depending if we're plotting over whole Run-3, change canvas size
245  if out_tag == "run3":
246  c1 = R.TCanvas("c1", "c1", 2000, 1000)
247  else:
248  c1 = R.TCanvas()
249 
250  tg.Draw('ap')
251  tg.GetYaxis().SetRangeUser(ymin, ymax)
252  if args.absolute:
253  plot_title = "Absolute L_{"+ zstring +"} to ATLAS across " + norm_type
254  else:
255  plot_title = "Normalised L_{"+ zstring +"} to ATLAS across " + norm_type
256 
257  # Plot 68% percentile band
258  stdev = np.percentile(abs(arr_zlumi_ratio - np.median(arr_zlumi_ratio)), 68)
259  print("68% band =", stdev)
260  tg.Fit('pol0', '0q')
261  mean = tg.GetFunction('pol0').GetParameter(0)
262  print("const of pol0 fit", mean)
263  print("median", np.median(arr_zlumi_ratio))
264  print("mean", np.mean(arr_zlumi_ratio))
265 
266  line1 = pt.make_bands(arr_date, stdev, np.median(arr_zlumi_ratio))
267  line1.Draw("same 3")
268  tg.Draw('same ep')
269 
270  leg = R.TLegend(0.55, 0.20, 0.69, 0.45)
271  leg.SetFillStyle(0)
272  leg.SetBorderSize(0)
273  leg.SetTextSize(0.05)
274  leg.AddEntry(tg, leg_entry, "ep")
275  leg.AddEntry(line1, "68% band", "f")
276  leg.Draw()
277 
278  pt.drawAtlasLabel(xval, yval-0.47, "Internal")
279  pt.drawText(xval, yval-0.53, date_tag, size=labelsize)
280  pt.drawText(xval, yval-0.59, zstring, size=labelsize)
281  pt.drawText(xval, yval-0.65, "OflLumi-Run3-005", size=labelsize)
282  pt.drawText(xval, yval-0.04, total_lumi_string, size=labelsize)
283 
284  pt.drawText(xval, 0.88, plot_title, size=labelsize)
285 
286  tg.GetXaxis().SetTitle(xtitle)
287  tg.GetYaxis().SetTitle(ytitle)
288  tg.GetYaxis().SetRangeUser(ymin, ymax)
289  tg.GetXaxis().SetTimeDisplay(2)
290  tg.GetXaxis().SetNdivisions(9,R.kFALSE)
291  tg.GetXaxis().SetTimeFormat(time_format)
292  tg.GetXaxis().SetTimeOffset(0,"gmt")
293 
294  c1.Update()
295  c1.Modified()
296 
297  filename = outdir + channel + "ATLAS_ratio_vs_time_"+out_tag
298  if args.absolute:
299  c1.SaveAs(filename+"_abs.pdf")
300  else:
301  c1.SaveAs(filename+".pdf")
302 
303  if outcsv:
304  if args.absolute:
305  csvfile = open(filename+"_abs.csv", 'w')
306  else:
307  csvfile = open(filename+".csv", 'w')
308  csvwriter = csv.writer(csvfile, delimiter=',')
309  csvwriter.writerow(['FillNum','RunNum','Time','OffLumi','ZLumi','ZLumiErr','OffZlumi','OffZlumiErr'])
310  for i in range(len(run_num)):
311  csvwriter.writerow([fill_num[i], run_num[i], arr_date[i], arr_olumi[i], arr_zlumi[i], arr_zerr[i], arr_zlumi_ratio[i], arr_zerr_ratio[i]])
312  csvfile.close()
313 
314 
315 

Variable Documentation

◆ absolute

plotting.yearwise_luminosity.absolute = args.absolute

Definition at line 29 of file yearwise_luminosity.py.

◆ action

plotting.yearwise_luminosity.action

Definition at line 20 of file yearwise_luminosity.py.

◆ args

plotting.yearwise_luminosity.args = parser.parse_args()

Definition at line 26 of file yearwise_luminosity.py.

◆ channel

plotting.yearwise_luminosity.channel = args.channel

Definition at line 28 of file yearwise_luminosity.py.

◆ date_tag

string plotting.yearwise_luminosity.date_tag = "Run 3, #sqrt{s} = 13.6 TeV"

Definition at line 45 of file yearwise_luminosity.py.

◆ help

plotting.yearwise_luminosity.help

Definition at line 18 of file yearwise_luminosity.py.

◆ indir

plotting.yearwise_luminosity.indir = args.indir

Definition at line 30 of file yearwise_luminosity.py.

◆ labelsize

int plotting.yearwise_luminosity.labelsize = 44

Definition at line 46 of file yearwise_luminosity.py.

◆ norm_type

string plotting.yearwise_luminosity.norm_type = "Run3"

Definition at line 47 of file yearwise_luminosity.py.

◆ out_tag

string plotting.yearwise_luminosity.out_tag = "run3"

Definition at line 42 of file yearwise_luminosity.py.

◆ outcsv

plotting.yearwise_luminosity.outcsv = args.outcsv

Definition at line 32 of file yearwise_luminosity.py.

◆ outdir

plotting.yearwise_luminosity.outdir = args.outdir

Definition at line 31 of file yearwise_luminosity.py.

◆ parser

plotting.yearwise_luminosity.parser = argparse.ArgumentParser()

Definition at line 17 of file yearwise_luminosity.py.

◆ str

plotting.yearwise_luminosity.str

Definition at line 18 of file yearwise_luminosity.py.

◆ time_format

string plotting.yearwise_luminosity.time_format = "%m/%y"

Definition at line 43 of file yearwise_luminosity.py.

◆ type

plotting.yearwise_luminosity.type

Definition at line 18 of file yearwise_luminosity.py.

◆ xtitle

string plotting.yearwise_luminosity.xtitle = 'Month / Year'

Definition at line 44 of file yearwise_luminosity.py.

◆ xval

float plotting.yearwise_luminosity.xval = 0.2

Definition at line 36 of file yearwise_luminosity.py.

◆ year

plotting.yearwise_luminosity.year = args.year

Definition at line 27 of file yearwise_luminosity.py.

◆ years

list plotting.yearwise_luminosity.years = ["22", "23", "24"]

Definition at line 41 of file yearwise_luminosity.py.

◆ ymax

plotting.yearwise_luminosity.ymax

Definition at line 37 of file yearwise_luminosity.py.

◆ ymin

plotting.yearwise_luminosity.ymin

Definition at line 37 of file yearwise_luminosity.py.

◆ yval

float plotting.yearwise_luminosity.yval = 0.85

Definition at line 35 of file yearwise_luminosity.py.

CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
MuonGM::round
float round(const float toRound, const unsigned int decimals)
Definition: Mdt.cxx:27
InDet::median
float median(std::vector< float > &Vec)
Definition: BTagVrtSec.cxx:35
plotting.yearwise_luminosity.zcounting_vs_atlas
def zcounting_vs_atlas(channel, years)
Definition: yearwise_luminosity.py:165
plotting.yearwise_luminosity.channel_comparison
def channel_comparison(years)
Definition: yearwise_luminosity.py:63
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
array
Trk::open
@ open
Definition: BinningType.h:40
str
Definition: BTagTrackIpAccessor.cxx:11
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70
plotting.yearwise_luminosity.main
def main()
Definition: yearwise_luminosity.py:57