ATLAS Offline Software
Loading...
Searching...
No Matches
PlotEFTrk.py
Go to the documentation of this file.
1#!/usr/bin/env python
2# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3# Authors: Calla Hinderks, Federica Piazza
4
5import ROOT
6import math
7
8ROOT.gROOT.SetStyle("ATLAS")
9ROOT.gROOT.SetBatch()
10
11
12
13category_dict = {
14
15 'eff' : 'Efficiencies',
16 'tech_eff' : 'Efficiencies/Technical',
17 'purity' : 'Efficiencies/Purities',
18 'resolution' : 'Resolutions',
19 'parameter' : 'Parameters',
20 'fakerate' : 'FakeRates',
21 'duplrate' : 'Duplicates',
22 'num' : 'Multiplicities',
23 'summary' : 'Multiplicities',
24 'hits' : 'HitsOnTracks',
25 'pixels' : 'PixelClusters',
26 'strips' : 'StripClusters',
27 'tails' : 'Parameters',
28}
29
30resolution_dict = {
31 'resHelp' : 'resHelper',
32 'pullHelp' : 'pullHelper',
33 'pullwidth' : 'pullwidth',
34 'pullmean' : 'pullmean',
35 'res' : 'resolution',
36 'resmean' : 'resmean',
37 'corr' : 'corr'
38}
39
41
42 from argparse import ArgumentParser
43 parser = ArgumentParser( description='Parser for IDTPM plotting' )
44 parser.add_argument( '--test', help="Input test ROOT files", nargs = '+')
45 parser.add_argument( '--ref', help="Input reference ROOT files", nargs = '+')
46 parser.add_argument( '-o', '--output', help="Output directory")
47 parser.add_argument( '--vertex','--pv','--vtx', help="Include this tag if plotting vertex parameters.", action='store_true', default = False)
48 parser.add_argument( '--vertexcategory', help="Type for vertex parameters if plotting vertex. Default is AllPrimary", default = "AllPrimary")
49 parser.add_argument( '--trkAnalysisTest', help='IDTPM TrackAnalysis for test (e.g. TrkAnaEF)', nargs = '+')
50 parser.add_argument( '--trkAnalysisRef', help='IDTPM TrackAnalysis for reference (e.g. TrkAnaEF)', nargs = '+')
51 parser.add_argument( '--chain', help="Trigger chain (or Offline)", default = 'Offline')
52 parser.add_argument( '-t','--type', help="type of plot (eff, tech_eff, purity, resolution, fakerate, duplrate, num, summary)")
53 parser.add_argument( '-p','--param', help="parameter (e.g pt/eta for efficiencies, d0_vs_truth_eta for resolutions, ...)")
54 parser.add_argument( '--resplot', help="which resolution plot ('resHelp','pullHelp','pullwidth','pullmean','res','resmean','corr')", default=None)
55 parser.add_argument( '--log', help="log scale on x axis, y axis or bot (x, y, xy)", default = '')
56 parser.add_argument( '--ymax', help="maximum value for y-axis ", default = 0)
57 parser.add_argument( '--ymin', help="minimum value for y-axis ", default = 0)
58 parser.add_argument( '--ratioyrange', help="range of ratio y-axis", default = None, nargs = '+', type = float)
59 parser.add_argument( '--dim', help="specify 1D or 2D ", default='1D')
60 parser.add_argument( '--pipelineTest', help="Tested pipeline", nargs = '+')
61 parser.add_argument( '--pipelineRef', help="Reference pipeline", nargs = '+')
62 parser.add_argument( '--norm', help="normalize to unit area", action='store_true')
63 parser.add_argument( '--pu-comparison', help="compare different PU samples", action='store_true')
64 parser.add_argument( '--mu', help="<mu> value (will be printed in ATLAS legend)", default = 200)
65 parser.add_argument( '--sample', help="Sample (e.g. 't#bar{t}' / 'single e, p_{T}>10 GeV', ...). Will be printed in ATLAS legend", default = '')
66 parser.add_argument( '--particle', help="Truth particle (e.g. B-hadrons / #tau, p_{T}>15 GeV). Will be printed in ATLAS legend", default = '')
67 parser.add_argument( '--legend-coord', help="xmin, ymin, xmax, ymax TLegend coordinates", default = [0.65,0.65,0.9,0.87], type = float, nargs = '+')
68 parser.add_argument( '--layout', '--l', help="ITk layout of samples (default 03-00-01)", default="03-00-01")
69 parser.add_argument( '--com', help="CoM (default 13.6)", default="13.6")
70 parser.add_argument( '--layoutTest', help = "ITk layout of test if different ITk layout", default = None)
71 parser.add_argument( '--layoutRef', help = "ITk layout of ref if different ITk layout", default = None)
72 parser.add_argument( '--tag', help="output file tag", default = '')
73 parser.print_help()
74 return parser.parse_args()
75
77 return obj.InheritsFrom("TEfficiency")
78
79def isTProfile(obj):
80 return obj.InheritsFrom("TProfile")
81
82def getHistoName(category, args):
83
84 par = args.param
85 if args.vertex:
86 match category:
87 case 'Parameters': return f"offl_vtx_{par}" if args.chain == 'Offline' else f"vtx_{par}"
88 case _: return 'None'
89 else:
90 match category:
91 case 'Parameters': return par
92 case 'Resolutions': return f"{resolution_dict[args.resplot]}_{par}"
93 case 'Efficiencies': return f"eff_vs_truth_{par}" if par!="truthMu" else "eff_vs_truthMu"
94 case 'Efficiencies/Technical': return f"eff_vs_truth_{par}" if par!="truthMu" else "eff_vs_truthMu"
95 case 'Efficiencies/Purities': return f"eff_vs_offl_{par}" if par!="truthMu" else "eff_vs_truthMu"
96 case 'FakeRates': return f"fakerate_vs_offl_{par}" if par!="truthMu" else "fakerate_vs_truthMu"
97 case 'Duplicates': return f"duplrate_vs_truth_{par}" if par!="truthMu" else "duplrate_vs_truthMu"
98 case 'Multiplicities': return par
99 case 'HitsOnTracks': return par
100 case 'PixelClusters': return par
101 case 'StripClusters': return par
102 case _: return 'None'
103
104def getHistoPath(cfg, args):
105 if args.vertex:
106 histopath = f"InDetTrackPerfMonPlots/{cfg['trkAnalysis']}/{cfg['chain']}/Vertices/{args.vertexcategory}/{cfg['category']}/{cfg['histo']}"
107 else:
108 histopath = f"InDetTrackPerfMonPlots/{cfg['trkAnalysis']}/{cfg['chain']}/Tracks/{cfg['category']}/{cfg['histo']}" if 'Clusters' not in cfg['category'] else f"InDetTrackPerfMonPlots/{cfg['trkAnalysis']}/Offline/{cfg['category']}/{cfg['histo']}"
109 h = cfg['input'].Get(histopath)
110 print(histopath)
111 if cfg['norm']: h.Scale(1./h.Integral())
112 print(cfg['input'])
113
114 return h
115
116def getConfig (input, chain, pipeline, trkana, args, color, markstyle, linestyle, isRef=False):
117
118 category = category_dict[args.type.split('_vs_')[0]] #Efficiencies, Resolutions, FakeRates, ...
119 histo = getHistoName(category, args)
120
121 config_dict = {
122 'pipeline' : pipeline,
123 'chain' : chain,
124 'isReference' : isRef,
125 'input' : input,
126 'trkAnalysis' : trkana,
127 'category' : category,
128 'histo' : histo,
129 'legend' : pipeline,
130 'linestyle' : linestyle,
131 'linecolor' : color,
132 'markstyle' : markstyle,
133 'markcolor' : color,
134 'log' : args.log,
135 'ymax' : float(args.ymax),
136 'ymin' : float(args.ymin),
137 'ratioyrange' : args.ratioyrange,
138 'dimension' : args.dim,
139 'norm' : args.norm,
140 }
141
142 return config_dict
143
144
145def getLegend(xmin,ymin,xmax,ymax):
146
147 leg = ROOT.TLegend(xmin,ymin,xmax,ymax)
148 leg.SetFillColor(0)
149 leg.SetLineColor(0)
150 leg.SetBorderSize(0)
151 leg.SetTextSize(0.05)
152 leg.SetTextFont(42)
153 leg.SetLineWidth(2)
154
155 return leg
156
158
159 sample = ''
160 if args.sample == '':
161 if 'ttbar' in args.ref[0]: sample = 't#bar{t}'
162 if 'SingleMu' in args.ref[0]: sample = 'single #mu'
163 if 'SinglePi' in args.ref[0]: sample = 'single #pi'
164 if 'SingleEl' in args.ref[0]: sample = 'single e'
165 if 'pT10_' in args.ref[0]: sample += ', p_{T} = 10 GeV'
166 if 'pT100' in args.ref[0]: sample += ', p_{T} = 100 GeV'
167 if 'pT1_' in args.ref[0]: sample += ', p_{T} = 1 GeV'
168 else: sample = args.sample
169 if args.particle != '': sample += f', {args.particle}'
170
171 diffItkLayout = args.layoutTest != args.layoutRef
172 itklayout = f"{args.layoutTest} vs {args.layoutRef}" if diffItkLayout else f"ITk Layout: {args.layout}"
173 com = args.com
174 subatlas = ROOT.TLatex(.2, .84, "#splitline{#bf{#it{ATLAS}} Simulation Internal}{#splitline{#sqrt{s} = %s TeV, HL-LHC}{#splitline{%s}{<#mu> = %s, %s}}}" %(com,itklayout, args.mu, sample))
175 if args.pu_comparison:
176 subatlas = ROOT.TLatex(.2, .84, "#splitline{#bf{#it{ATLAS}} Simulation Internal}{#splitline{#sqrt{s} = %s TeV, HL-LHC}{#splitline{%s}{%s}}}" %(com,itklayout,sample))
177
178 subatlas.SetNDC(1)
179 subatlas.SetTextFont(42)
180 subatlas.SetTextSize(0.05)
181
182 return subatlas
183
184def getPadSizes(args, NRef):
185
186 pad_heights = [600*0.65]
187
188 for nref in range(NRef-1): pad_heights.append(600*0.35 * (1-0.05-1/3))
189 pad_heights.append(600*0.35)
190
191 return pad_heights
192
193def getCanvas(args,cfg, NRef):
194
195 pad_heights = getPadSizes(args, NRef)
196 canv_heigh = sum(pad_heights)
197 pad_bottom = [(1-sum([pad_heights[j] for j in range(i+1)])/canv_heigh) for i in range(len(pad_heights))]
198 canv = ROOT.TCanvas("c","c",600,int(canv_heigh))
199
200 canv.cd()
201 pad1 = ROOT.TPad("pad1","pad1",0,pad_bottom[0],1,1)
202 pad1.SetNumber(1)
203 pad1.SetBottomMargin(0.05)
204
205 ratio_pads = []
206
207 for r in range(NRef):
208 ratio_pads.append(ROOT.TPad(f"pad{r+2}",f"pad{r+2}",0,pad_bottom[r+1],1,pad_bottom[r]))
209 ratio_pads[r].SetTopMargin(0.05)
210 ratio_pads[r].SetBottomMargin(0.05 if r!=(NRef-1) else 1./3.)
211 ratio_pads[r].SetNumber(r+2)
212
213 if cfg['log'] == 'x':
214 pad1.SetLogx()
215 for r in range(NRef): ratio_pads[r].SetLogx()
216
217 if cfg['log'] == 'y':
218 pad1.SetLogy()
219
220 if cfg['log'] == 'xy':
221 pad1.SetLogx()
222 pad1.SetLogy()
223 for r in range(NRef): ratio_pads[r].SetLogx()
224
225 pad1.Draw()
226
227 for r in range(NRef): ratio_pads[r].Draw()
228
229 return canv
230
231def getURDRequirementLine(h, type, canv, scale, logx = False):
232
233 scaleshift = canv.GetPad(1).GetHNDC()/canv.GetPad(2).GetHNDC()
234
235 level = 0.01 if 'rate' in type else 2
236 xmin, xmax = h.GetXaxis().GetXmin(), h.GetXaxis().GetXmax()
237 ymax,ymin = h.GetMaximum(), h.GetMinimum()
238
239 requirement_line = (ROOT.TLine(xmin,level,xmax,level))
240 requirement_line.SetLineStyle(2)
241 requirement_line.SetLineColor(ROOT.kRed)
242 requirement_line.SetLineWidth(1)
243
244 shiftup = 0.01*scaleshift if 'rate' not in type else 0.01
245 shiftdn = 0.07*scaleshift if 'rate' not in type else 0.07
246 y = level + shiftup*(ymax-ymin) if level < ymax else ymax - shiftdn *(ymax-ymin)
247 x = (.63*(xmax-xmin)+xmin) if not logx else math.exp( math.log(xmin) + 0.63*(math.log(xmax) - math.log(xmin)) )
248
249 requirement_text = ROOT.TLatex(x,y, f"#uparrow URD requirement = {level}" if level > ymax else f"URD requirement = {level}")
250 requirement_text.SetTextFont(42)
251 requirement_text.SetTextSize(0.04*scale if 'rate' not in type else 0.04)
252 requirement_text.SetTextColor(ROOT.kRed)
253 return requirement_line, requirement_text
254
255def setStyle(h, cfg):
256
257 h.SetLineColor(cfg['linecolor'])
258 h.SetLineStyle(cfg['linestyle'])
259 h.SetMarkerStyle(cfg['markstyle'])
260 h.SetMarkerColor(cfg['markcolor'])
261 h.SetMarkerSize(0.8)
262 h.SetLineWidth(2)
263
264 if isTEfficiency(h):
265
266 ROOT.gPad.Update()
267
268 if 'Efficiencies' in cfg['category']:
269 h.GetPaintedGraph().SetMaximum(1.2 if cfg['ymax']==0 else cfg['ymax'])
270 h.GetPaintedGraph().SetMinimum(0.7 if cfg['ymin']==0 else cfg['ymin'])
271
272 else:
273
274 if 'y' in str(cfg['log']):
275 h.GetPaintedGraph().SetMaximum(10*max(1,abs(math.log10(max(h.GetPaintedGraph().GetY()))))*max(h.GetPaintedGraph().GetY()) if cfg['ymax']==0 else cfg['ymax'])
276 h.GetPaintedGraph().SetMinimum(max(1e-10, min(h.GetPaintedGraph().GetY())*(0.9)) if cfg['ymin']==0 else cfg['ymin'])
277
278 else:
279 h.GetPaintedGraph().SetMaximum(1.5*float(max(h.GetPaintedGraph().GetY())) if cfg['ymax']==0 else cfg['ymax'])
280 h.GetPaintedGraph().SetMinimum(0 if cfg['ymin']==0 else cfg['ymin'])
281
282 h.GetPaintedGraph().GetXaxis().SetTitleSize(0)
283 h.GetPaintedGraph().GetXaxis().SetLabelSize(0)
284 h.GetPaintedGraph().GetYaxis().SetLabelSize(0.05)
285 h.GetPaintedGraph().GetXaxis().SetTitleSize(0.05)
286
287 else:
288
289 if cfg['norm']:
290 h.SetMaximum(1.5 if cfg['ymax']==0 else cfg['ymax'])
291 h.SetMinimum(0 if cfg['ymin']==0 else cfg['ymin'])
292
293 else:
294
295 if 'y' in str(cfg['log']):
296 h.SetMaximum(1.5*max(1,max(1,abs(math.log10(h.GetMaximum()))))*h.GetMaximum() if cfg['ymax']==0 else cfg['ymax'])
297 h.SetMinimum(max(1e-10, h.GetMinimum()*(0.9)) if cfg['ymin']==0 else cfg['ymin'])
298 if 'avgNum' in cfg['histo']: h.SetMinimum(100 if cfg['ymin']==0 else cfg['ymin'])
299
300 else:
301 h.SetMaximum(1.4*h.GetMaximum() if cfg['ymax']==0 else cfg['ymax'])
302 h.SetMinimum(0 if cfg['ymin']==0 else cfg['ymin'])
303
304 h.GetXaxis().SetTitleSize(0)
305 h.GetXaxis().SetLabelSize(0)
306 h.GetYaxis().SetLabelSize(0.05)
307 h.GetYaxis().SetTitleSize(0.05)
308
309def setRatioStyle(ratio, cfg, color, linestyle, markstyle, ref='C000', multigraph=False, labelsizescale = 65./35., lastpad = False, splittitle = False):
310 if 'vs_truthMu' in cfg['histo']: ratio.GetXaxis().SetTitle('Truth <#mu>')
311 ratio.GetXaxis().SetTitleOffset(1.5)
312 ratio.GetYaxis().SetTitle('#splitline{Ratio wrt}{%s}' %ref if splittitle else 'Ratio wrt %s' %ref)
313 ratio.GetYaxis().SetTitleSize(0.05*labelsizescale)
314 ratio.GetYaxis().SetNdivisions(505)
315 ratio.GetYaxis().SetTitleOffset(1.3*1/labelsizescale)
316
317 if cfg['ratioyrange'] is None:
318
319 if not multigraph:
320 ratio.SetMaximum()
321 ratio.SetMinimum()
322 ratio.GetYaxis().SetRangeUser(max(0.,min(ratio.GetMinimum()-0.1,abs(1.9-ratio.GetMaximum()))),max(ratio.GetMaximum()+0.1,abs(2-ratio.GetMinimum())))
323
324 else:
325 ratio.GetYaxis().SetRangeUser(cfg['ratioyrange'][0],cfg['ratioyrange'][1])
326
327 ratio.GetXaxis().SetLabelSize(0.05*labelsizescale if lastpad else 0)
328 ratio.GetXaxis().SetTitleSize(0.05*labelsizescale if lastpad else 0)
329 ratio.GetYaxis().SetLabelSize(0.05*labelsizescale)
330 ratio.GetYaxis().SetTitleSize(0.05*labelsizescale)
331
332 if not multigraph:
333
334 ratio.SetLineColor(color)
335 ratio.SetLineStyle(linestyle)
336 ratio.SetMarkerStyle(markstyle)
337 ratio.SetMarkerColor(color)
338 ratio.SetMarkerSize(0.8)
339
340def getRatio(histos):
341 ratio = histos[0].Clone()
342 ratio.Divide(histos[1])
343 for b in range(1, ratio.GetNbinsX()+1):
344 num = histos[0].GetBinContent(b)
345 den = histos[1].GetBinContent(b)
346 if ratio.GetBinContent(b) == 0:
347 if den == 0 and num == 0:
348 ratio.SetBinContent(b, 1)
349 elif den == 0 and num !=0:
350 ratio.SetBinContent(b, 1000)
351 return ratio
352
354
355 xmin, xmax = histos[0].GetPaintedGraph().GetXaxis().GetXmin(), histos[0].GetPaintedGraph().GetXaxis().GetXmax()
356 g1 = ROOT.TGraphAsymmErrors(histos[0].GetPaintedGraph())
357 g2 = ROOT.TGraphAsymmErrors(histos[1].GetPaintedGraph())
358 title = g1.GetXaxis().GetTitle()
359 ratio = ROOT.TGraphAsymmErrors()
360 n, n_ref, n_test = max(g1.GetN(),g2.GetN()), g1.GetN(), g2.GetN()
361 x_ref_arr, y_ref_arr = g1.GetX(), g1.GetY()
362 x_test_arr, y_test_arr = g2.GetX(), g2.GetY()
363 i_test, i_ref = 0, 0
364 err_r_low = []
365 err_r_high = []
366
367 for i in range(n):
368
369 if i_test < n_test and i_ref < n_ref:
370
371 x_ref, y_ref = x_ref_arr[i_ref], y_ref_arr[i_ref]
372 x_test, y_test = x_test_arr[i_test], y_test_arr[i_test]
373 err_ref_low, err_ref_high = g1.GetErrorYlow(i_ref), g1.GetErrorYhigh(i_ref)
374 err_test_low, err_test_high = g2.GetErrorYlow(i_test), g2.GetErrorYhigh(i_test)
375
376 # Check points matching between test and reference
377 if x_test==x_ref:
378 y_ref, y_test = y_ref_arr[i_ref], y_test_arr[i_test]
379 i_test += 1
380 i_ref += 1
381
382 if x_ref>x_test:
383 x_ref = x_test
384 y_ref, y_test = 0, y_test_arr[i_test]
385 i_test+= 1
386
387 if x_test>x_ref:
388 x_test = x_ref
389 y_test, y_ref = 0, y_ref_arr[i_ref]
390 i_ref += 1
391
392 r = y_test / y_ref if y_ref != 0 else 1000
393 if y_test == 0 and y_ref == 0: r = 1
394 err_r_low.append(r * math.sqrt((err_ref_low / y_ref)**2 + (err_test_low / y_test)**2) if y_ref > 0 and y_test > 0 else 0)
395 err_r_high.append(r * math.sqrt((err_ref_high / y_ref)**2 + (err_test_high / y_test)**2) if y_ref > 0 and y_test > 0 else 0)
396 ratio.SetPoint(i, x_ref, r)
397 ratio.GetXaxis().SetTitle(title)
398
399 # Set errors and final x axis range
400 for i in range(ratio.GetN()):
401
402 width = ratio.GetPointX(i+1)-ratio.GetPointX(i) if i < ratio.GetN()-1 else ratio.GetPointX(i)-ratio.GetPointX(i-1)
403 ratio.SetPointError(i, width/2.,width/2., err_r_low[i], err_r_high[i])
404
405 ratio.GetXaxis().SetLimits(xmin, xmax)
406
407 return ratio
408
409def drawTEfficiencyOutliers(r, configs, multigraphs, markers, NRef):
410
411 outliers_index = 0
412
413 for j,g in enumerate(multigraphs[r].GetListOfGraphs()):
414 markers.append([])
415 ROOT.gPad.Update()
416 ymin = ROOT.gPad.GetFrame().GetY1()
417 ymax = ROOT.gPad.GetFrame().GetY2()
418
419 for i in range(g.GetN()):
420
421 if g.GetPointY(i) > ymax:
422 markers[r].append(ROOT.TMarker(g.GetPointX(i), ymax-(ymax-ymin)*0.05, 26))
423 markers[r][outliers_index].SetMarkerColor(configs[j+NRef]['linecolor'])
424 markers[r][outliers_index].SetMarkerSize(1.2)
425 markers[r][outliers_index].Draw('same')
426 outliers_index += 1
427
428 if g.GetPointY(i) < ymin and g.GetPointY(i) > 0:
429 markers[r].append(ROOT.TMarker(g.GetPointX(i), ymin+(ymax-ymin)*0.05, 32))
430 markers[r][outliers_index].SetMarkerColor(configs[j+NRef]['linecolor'])
431 markers[r][outliers_index].SetMarkerSize(1.2)
432 markers[r][outliers_index].Draw('same')
433 outliers_index += 1
434
435def drawTHOutliers(r, configs, ratios, markers, NRef):
436
437 outliers_index = 0
438
439 for j,ratio in enumerate(ratios):
440 ROOT.gPad.Update()
441 ymin = ROOT.gPad.GetFrame().GetY1()
442 ymax = ROOT.gPad.GetFrame().GetY2()
443
444 for i in range(ratio.GetNbinsX()):
445
446 if ratio.GetBinContent(i) > ymax:
447 markers[r].append(ROOT.TMarker(ratio.GetXaxis().GetBinCenter(i), ymax-(ymax-ymin)*0.05, 26))
448 markers[r][outliers_index].SetMarkerColor(configs[j+NRef]['linecolor'])
449 markers[r][outliers_index].SetMarkerSize(1.2)
450 markers[r][outliers_index].Draw('same')
451 outliers_index += 1
452
453 if ratio.GetBinContent(i) < ymin and ratio.GetBinContent(i) > 0:
454 markers[r].append(ROOT.TMarker(ratio.GetXaxis().GetBinCenter(i), ymin+(ymax-ymin)*0.05, 32))
455 markers[r][outliers_index].SetMarkerColor(configs[j+NRef]['linecolor'])
456 markers[r][outliers_index].SetMarkerSize(1.2)
457 markers[r][outliers_index].Draw('same')
458 outliers_index += 1
459
460def drawRefLine(r, ratios, reflines):
461
462 reflines.append(ROOT.TLine(ratios[0].GetXaxis().GetXmin(),1,ratios[0].GetXaxis().GetXmax(),1))
463 reflines[r].SetLineStyle(2)
464 reflines[r].SetLineColor(ROOT.kBlack)
465 reflines[r].SetLineWidth(1)
466 reflines[r].Draw('same')
467
468def draw(args, configs, tails=False, pu_comparison=False):
469
470 NRef = len(args.ref) if not pu_comparison else 1
471 canv = getCanvas(args,configs[0], NRef)
472 ATLASLabel = getATLASLabel(args)
473 legend = getLegend(args.legend_coord[0],args.legend_coord[1],args.legend_coord[2],args.legend_coord[3])
474 doComparison = len(configs) > 1
475 isTEfficiencyObj = False
476 histos = []
477 canv.cd(1)
478
479 for i,cfg in enumerate(configs): # loop over the trkAnalysis to be compared (if single plot, there will be only 1 trkAnalysis)
480 h = getHistoPath(cfg,args)
481 isTEfficiencyObj = isTEfficiency(h)
482 histos.append(h)
483
484 if not tails: h.Draw('same' if i!=0 else '')
485
486 else: h.Draw('sameHISTE' if i%2!=0 else 'samePE')
487
488 setStyle(h, cfg)
489
490 if doComparison and cfg['dimension'] == '1D':
491 draw_option = 'lp'
492
493 if tails:
494 draw_option = 'l' if i%2!=0 else 'lp'
495 jet = 'b-Jet' if i%2==0 else 'LF-Jet'
496 legend.AddEntry(h, f"{cfg['legend']} {jet}",draw_option)
497
498 else: legend.AddEntry(h, cfg['legend'],draw_option)
499
500 legend.Draw()
501
502 ATLASLabel.Draw()
503
504 multigraphs = []
505 reflines = []
506 markers = []
507 urd_lines = []
508 urd_text = []
509
510 if 'rate' in args.type and 'C000' in args.ref[0] and args.param != 'truthMu':
511 requirement_line, requirement_text = getURDRequirementLine(histos[0].GetPaintedGraph(), 'rate', canv, 1)
512 requirement_line.Draw('same')
513 requirement_text.Draw('same')
514
515 # Loop over reference histograms to create one ratio per reference
516 for r in range(NRef):
517
518 labelsizescales = [canv.GetPad(1).GetHNDC()/canv.GetPad(i+2).GetHNDC() for i in range(NRef)]
519 canv.cd(r+2)
520 ratios = []
521 multigraphs.append(ROOT.TMultiGraph())
522 markers.append([])
523
524 if not tails and not pu_comparison:
525
526 for i in range(NRef, len(configs)):
527 ratio_histos = [histos[r] if not isTProfile(histos[r]) else histos[r].ProjectionX(), histos[i] if not isTProfile(histos[i]) else histos[i].ProjectionX()]
528
529 if isTEfficiencyObj: ratios.append(getTEfficiencyRatio(ratio_histos))
530
531 else:
532 ratio = getRatio(ratio_histos)
533 ratios.append(ratio)
534
535 for i, ratio in enumerate(ratios):
536 color = configs[i+NRef]['linecolor'] #if len(configs)>2 else ROOT.kBlack
537 linestyle = configs[i+1]['linestyle']# if len(configs)>2 else 1
538 markstyle = configs[i+1]['markstyle']# if len(configs)>2 else 20
539 setRatioStyle(ratio, configs[i], color, linestyle, markstyle, ref=configs[r]['pipeline'], labelsizescale = labelsizescales[r], lastpad = (r==NRef-1), splittitle = (NRef>1))
540
541 if isTEfficiencyObj:
542 multigraphs[r].Add(ratio,'p')
543 multigraphs[r].GetXaxis().SetTitle(ratio.GetXaxis().GetTitle())
544
545 else:
546 ratio.Draw('same')
547
548 if isTEfficiencyObj:
549 xmin, xmax = ratios[0].GetXaxis().GetXmin(), ratios[0].GetXaxis().GetXmax()
550 setRatioStyle(multigraphs[r], configs[i], color, linestyle, markstyle, ref=configs[r]['pipeline'], multigraph=True, labelsizescale = labelsizescales[r], lastpad = (r==NRef-1), splittitle = (NRef>1))
551 multigraphs[r].Draw('a')
552 drawTEfficiencyOutliers(r, configs, multigraphs, markers, NRef)
553 multigraphs[r].GetXaxis().SetLimits(xmin, xmax)
554
555 else:
556 drawTHOutliers(r, configs, ratios, markers, NRef)
557
558 drawRefLine(r, ratios, reflines)
559
560 if args.type == 'resolution' and not pu_comparison and 'C000' in args.ref[0]:
561 requirement_line, requirement_text = getURDRequirementLine(ratios[0], 'resolution', canv, labelsizescales[r], logx = ('x' in args.log))
562 urd_lines.append(requirement_line)
563 urd_text.append(requirement_text)
564 urd_lines[r].Draw('same')
565 urd_text[r].Draw('same')
566
567 else:
568 for i in [0,2]:
569 ratio_histos = [histos[i],histos[i+1]]
570 ratio = getRatio(ratio_histos)
571 ratios.append(ratio)
572
573 for i, ratio in enumerate(ratios):
574 color = configs[i*2]['linecolor']
575 linestyle = configs[i*2]['linestyle']
576 markstyle = configs[i*2]['markstyle']
577 setRatioStyle(ratio, configs[i], color, linestyle, markstyle, ref=configs[r]['pipeline'],labelsizescale = labelsizescales[r], lastpad = (r==NRef-1))
578 ratio.GetYaxis().SetTitle('b-Jet / LF-Jet' if tails else '<#mu> = 140/<#mu> = 200')
579 ratio.Draw('same')
580
581 drawRefLine(r, ratios, reflines)
582
583 var = cfg['histo'] if not cfg['category'] == 'Efficiencies/Technical' else cfg['histo'].replace('eff','tech_eff')
584 canv.SaveAs(f"{args.output}/{args.tag+'_' if args.tag != '' else ''}{var}.png")
585
586def main():
587
588 args = GetParserArgs()
589 chain = args.chain
590 inputTest = args.test
591 inputRef = args.ref
592 pipelinesRef = args.pipelineRef
593 pipelinesTest = args.pipelineTest
594 trkanalysesRef = args.trkAnalysisRef
595 trkanalysesTest = args.trkAnalysisTest
596 doTails = (args.type == 'tails')
597 doPUComparison = args.pu_comparison
598
599
600 if not doTails and not doPUComparison:
601 colors = [ ROOT.kRed, ROOT.kBlue, ROOT.kGreen+2, ROOT.kOrange+7, ROOT.kMagenta, ROOT.kCyan+1, ROOT.kViolet, ROOT.kTeal+2, ROOT.kPink+6, ROOT.kAzure+1]
602 linestyles = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
603 markstyles = [ 20, 21, 22, 23, 24, 25, 26, 27, 28, 30 ]
604 inputFiles = inputRef+inputTest
605 pipelines = pipelinesRef+pipelinesTest
606 trkanalyses = trkanalysesRef+trkanalysesTest
607 inputFiles = inputRef+inputTest
608
609 print(pipelines)
610 print(trkanalyses)
611 print(inputFiles)
612
613 configs = []
614
615 for i,pipeline in enumerate(pipelines):
616 isReference = (i<len(pipelinesRef))
617 f = ROOT.TFile.Open(inputFiles[i], 'READ')
618 configs.append(getConfig(f, chain, pipeline, trkanalyses[i], args, colors[i], markstyles[i], linestyles[i], isReference))
619
620 draw(args, configs)
621
622 else:
623
624 colors = [ROOT.kRed, ROOT.kRed, ROOT.kBlue, ROOT.kBlue]
625 linestyles = [2,1,2,1]
626 markstyles = [20,0,24,0] if doTails else [20, 24, 20, 24]
627 pipelines = args.pipelineRef+args.pipelineRef+args.pipelineTest+args.pipelineTest if doTails else args.pipelineRef+args.pipelineTest
628 trkanalyses = args.trkAnalysisRef
629 trkanalyses.extend(args.trkAnalysisTest)
630 inputFiles = inputRef+inputRef+inputTest+inputTest if doTails else inputRef+inputTest
631 configs = []
632
633 for i,trkana in enumerate(trkanalyses):
634 f = ROOT.TFile.Open(inputFiles[i], 'READ')
635 configs.append(getConfig(f, chain, pipelines[i], trkanalyses[i], args, colors[i], markstyles[i], linestyles[i]))
636
637 draw(args, configs, tails=doTails,pu_comparison=doPUComparison)
638
639if __name__ == "__main__":
640 main()
void print(char *figname, TCanvas *c1)
#define min(a, b)
Definition cfImp.cxx:40
#define max(a, b)
Definition cfImp.cxx:41
T * Get(TFile &f, const std::string &n, const std::string &dir="", const chainmap_t *chainmap=0, std::vector< std::string > *saved=0)
get a histogram given a path, and an optional initial directory if histogram is not found,...
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition hcg.cxx:312
getHistoPath(cfg, args)
Definition PlotEFTrk.py:104
isTProfile(obj)
Definition PlotEFTrk.py:79
draw(args, configs, tails=False, pu_comparison=False)
Definition PlotEFTrk.py:468
getLegend(xmin, ymin, xmax, ymax)
Definition PlotEFTrk.py:145
drawRefLine(r, ratios, reflines)
Definition PlotEFTrk.py:460
drawTEfficiencyOutliers(r, configs, multigraphs, markers, NRef)
Definition PlotEFTrk.py:409
getCanvas(args, cfg, NRef)
Definition PlotEFTrk.py:193
setStyle(h, cfg)
Definition PlotEFTrk.py:255
getConfig(input, chain, pipeline, trkana, args, color, markstyle, linestyle, isRef=False)
Definition PlotEFTrk.py:116
getURDRequirementLine(h, type, canv, scale, logx=False)
Definition PlotEFTrk.py:231
getTEfficiencyRatio(histos)
Definition PlotEFTrk.py:353
GetParserArgs()
Definition PlotEFTrk.py:40
getPadSizes(args, NRef)
Definition PlotEFTrk.py:184
setRatioStyle(ratio, cfg, color, linestyle, markstyle, ref='C000', multigraph=False, labelsizescale=65./35., lastpad=False, splittitle=False)
Definition PlotEFTrk.py:309
getATLASLabel(args)
Definition PlotEFTrk.py:157
drawTHOutliers(r, configs, ratios, markers, NRef)
Definition PlotEFTrk.py:435
isTEfficiency(obj)
Definition PlotEFTrk.py:76
getHistoName(category, args)
Definition PlotEFTrk.py:82
getRatio(histos)
Definition PlotEFTrk.py:340