158 if args.sample ==
'':
159 if 'ttbar' in args.ref[0]: sample =
't#bar{t}'
160 if 'SingleMu' in args.ref[0]: sample =
'single #mu'
161 if 'SinglePi' in args.ref[0]: sample =
'single #pi'
162 if 'SingleEl' in args.ref[0]: sample =
'single e'
163 if 'pT10_' in args.ref[0]: sample +=
', p_{T} = 10 GeV'
164 if 'pT100' in args.ref[0]: sample +=
', p_{T} = 100 GeV'
165 if 'pT1_' in args.ref[0]: sample +=
', p_{T} = 1 GeV'
166 else: sample = args.sample
167 if args.particle !=
'': sample += f
', {args.particle}'
169 diffItkLayout = args.layoutTest != args.layoutRef
170 itklayout = f
"{args.layoutTest} vs {args.layoutRef}" if diffItkLayout
else f
"ITk Layout: {args.layout}"
171 subatlas = ROOT.TLatex(.2, .84,
"#splitline{#bf{#it{ATLAS}} Simulation Internal}{#splitline{#sqrt{s} = 14 TeV, HL-LHC}{#splitline{%s}{<#mu> = %s, %s}}}" %(itklayout, args.mu, sample))
172 if args.pu_comparison:
173 subatlas = ROOT.TLatex(.2, .84,
"#splitline{#bf{#it{ATLAS}} Simulation Internal}{#splitline{#sqrt{s} = 14 TeV, HL-LHC}{#splitline{%s}{%s}}}" %(itklayout,sample))
176 subatlas.SetTextFont(42)
177 subatlas.SetTextSize(0.05)
193 canv_heigh = sum(pad_heights)
194 pad_bottom = [(1-sum([pad_heights[j]
for j
in range(i+1)])/canv_heigh)
for i
in range(len(pad_heights))]
195 canv = ROOT.TCanvas(
"c",
"c",600,int(canv_heigh))
198 pad1 = ROOT.TPad(
"pad1",
"pad1",0,pad_bottom[0],1,1)
200 pad1.SetBottomMargin(0.05)
204 for r
in range(NRef):
205 ratio_pads.append(ROOT.TPad(f
"pad{r+2}",f
"pad{r+2}",0,pad_bottom[r+1],1,pad_bottom[r]))
206 ratio_pads[r].SetTopMargin(0.05)
207 ratio_pads[r].SetBottomMargin(0.05
if r!=(NRef-1)
else 1./3.)
208 ratio_pads[r].SetNumber(r+2)
210 if cfg[
'log'] ==
'x':
212 for r
in range(NRef): ratio_pads[r].SetLogx()
214 if cfg[
'log'] ==
'y':
217 if cfg[
'log'] ==
'xy':
220 for r
in range(NRef): ratio_pads[r].SetLogx()
224 for r
in range(NRef): ratio_pads[r].Draw()
230 scaleshift = canv.GetPad(1).GetHNDC()/canv.GetPad(2).GetHNDC()
232 level = 0.01
if 'rate' in type
else 2
233 xmin, xmax = h.GetXaxis().GetXmin(), h.GetXaxis().GetXmax()
234 ymax,ymin = h.GetMaximum(), h.GetMinimum()
236 requirement_line = (ROOT.TLine(xmin,level,xmax,level))
237 requirement_line.SetLineStyle(2)
238 requirement_line.SetLineColor(ROOT.kRed)
239 requirement_line.SetLineWidth(1)
241 shiftup = 0.01*scaleshift
if 'rate' not in type
else 0.01
242 shiftdn = 0.07*scaleshift
if 'rate' not in type
else 0.07
243 y = level + shiftup*(ymax-ymin)
if level < ymax
else ymax - shiftdn *(ymax-ymin)
244 x = (.63*(xmax-xmin)+xmin)
if not logx
else math.exp( math.log(xmin) + 0.63*(math.log(xmax) - math.log(xmin)) )
246 requirement_text = ROOT.TLatex(x,y, f
"#uparrow URD requirement = {level}" if level > ymax
else f
"URD requirement = {level}")
247 requirement_text.SetTextFont(42)
248 requirement_text.SetTextSize(0.04*scale
if 'rate' not in type
else 0.04)
249 requirement_text.SetTextColor(ROOT.kRed)
250 return requirement_line, requirement_text
254 h.SetLineColor(cfg[
'linecolor'])
255 h.SetLineStyle(cfg[
'linestyle'])
256 h.SetMarkerStyle(cfg[
'markstyle'])
257 h.SetMarkerColor(cfg[
'markcolor'])
265 if 'Efficiencies' in cfg[
'category']:
266 h.GetPaintedGraph().SetMaximum(1.2
if cfg[
'ymax']==0
else cfg[
'ymax'])
267 h.GetPaintedGraph().SetMinimum(0.7
if cfg[
'ymin']==0
else cfg[
'ymin'])
271 if 'y' in str(cfg[
'log']):
272 h.GetPaintedGraph().SetMaximum(10*
max(1,abs(math.log10(
max(h.GetPaintedGraph().GetY()))))*
max(h.GetPaintedGraph().GetY())
if cfg[
'ymax']==0
else cfg[
'ymax'])
273 h.GetPaintedGraph().SetMinimum(
max(1e-10,
min(h.GetPaintedGraph().GetY())*(0.9))
if cfg[
'ymin']==0
else cfg[
'ymin'])
276 h.GetPaintedGraph().SetMaximum(1.5*float(
max(h.GetPaintedGraph().GetY()))
if cfg[
'ymax']==0
else cfg[
'ymax'])
277 h.GetPaintedGraph().SetMinimum(0
if cfg[
'ymin']==0
else cfg[
'ymin'])
279 h.GetPaintedGraph().GetXaxis().SetTitleSize(0)
280 h.GetPaintedGraph().GetXaxis().SetLabelSize(0)
281 h.GetPaintedGraph().GetYaxis().SetLabelSize(0.05)
282 h.GetPaintedGraph().GetXaxis().SetTitleSize(0.05)
287 h.SetMaximum(1.5
if cfg[
'ymax']==0
else cfg[
'ymax'])
288 h.SetMinimum(0
if cfg[
'ymin']==0
else cfg[
'ymin'])
292 if 'y' in str(cfg[
'log']):
293 h.SetMaximum(1.5*
max(1,
max(1,abs(math.log10(h.GetMaximum()))))*h.GetMaximum()
if cfg[
'ymax']==0
else cfg[
'ymax'])
294 h.SetMinimum(
max(1e-10, h.GetMinimum()*(0.9))
if cfg[
'ymin']==0
else cfg[
'ymin'])
295 if 'avgNum' in cfg[
'histo']: h.SetMinimum(100
if cfg[
'ymin']==0
else cfg[
'ymin'])
298 h.SetMaximum(1.4*h.GetMaximum()
if cfg[
'ymax']==0
else cfg[
'ymax'])
299 h.SetMinimum(0
if cfg[
'ymin']==0
else cfg[
'ymin'])
301 h.GetXaxis().SetTitleSize(0)
302 h.GetXaxis().SetLabelSize(0)
303 h.GetYaxis().SetLabelSize(0.05)
304 h.GetYaxis().SetTitleSize(0.05)
306def setRatioStyle(ratio, cfg, color, linestyle, markstyle, ref='C000', multigraph=False, labelsizescale = 65./35., lastpad = False, splittitle = False):
307 if 'vs_truthMu' in cfg[
'histo']: ratio.GetXaxis().SetTitle(
'Truth <#mu>')
308 ratio.GetXaxis().SetTitleOffset(1.5)
309 ratio.GetYaxis().SetTitle(
'#splitline{Ratio wrt}{%s}' %ref
if splittitle
else 'Ratio wrt %s' %ref)
310 ratio.GetYaxis().SetTitleSize(0.05*labelsizescale)
311 ratio.GetYaxis().SetNdivisions(505)
312 ratio.GetYaxis().SetTitleOffset(1.3*1/labelsizescale)
314 if cfg[
'ratioyrange']
is None:
319 ratio.GetYaxis().SetRangeUser(
max(0.,
min(ratio.GetMinimum()-0.1,abs(1.9-ratio.GetMaximum()))),
max(ratio.GetMaximum()+0.1,abs(2-ratio.GetMinimum())))
322 ratio.GetYaxis().SetRangeUser(cfg[
'ratioyrange'][0],cfg[
'ratioyrange'][1])
324 ratio.GetXaxis().SetLabelSize(0.05*labelsizescale
if lastpad
else 0)
325 ratio.GetXaxis().SetTitleSize(0.05*labelsizescale
if lastpad
else 0)
326 ratio.GetYaxis().SetLabelSize(0.05*labelsizescale)
327 ratio.GetYaxis().SetTitleSize(0.05*labelsizescale)
331 ratio.SetLineColor(color)
332 ratio.SetLineStyle(linestyle)
333 ratio.SetMarkerStyle(markstyle)
334 ratio.SetMarkerColor(color)
335 ratio.SetMarkerSize(0.8)
339 xmin, xmax = histos[0].GetPaintedGraph().GetXaxis().GetXmin(), histos[0].GetPaintedGraph().GetXaxis().GetXmax()
340 g1 = ROOT.TGraphAsymmErrors(histos[0].GetPaintedGraph())
341 g2 = ROOT.TGraphAsymmErrors(histos[1].GetPaintedGraph())
342 title = g1.GetXaxis().GetTitle()
343 ratio = ROOT.TGraphAsymmErrors()
344 n, n_ref, n_test =
max(g1.GetN(),g2.GetN()), g1.GetN(), g2.GetN()
345 x_ref_arr, y_ref_arr = g1.GetX(), g1.GetY()
346 x_test_arr, y_test_arr = g2.GetX(), g2.GetY()
353 if i_test < n_test
and i_ref < n_ref:
355 x_ref, y_ref = x_ref_arr[i_ref], y_ref_arr[i_ref]
356 x_test, y_test = x_test_arr[i_test], y_test_arr[i_test]
357 err_ref_low, err_ref_high = g1.GetErrorYlow(i_ref), g1.GetErrorYhigh(i_ref)
358 err_test_low, err_test_high = g2.GetErrorYlow(i_test), g2.GetErrorYhigh(i_test)
362 y_ref, y_test = y_ref_arr[i_ref], y_test_arr[i_test]
368 y_ref, y_test = 0, y_test_arr[i_test]
373 y_test, y_ref = 0, y_ref_arr[i_ref]
376 r = y_test / y_ref
if y_ref != 0
else 1000
377 if y_test == 0
and y_ref == 0: r = 1
378 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)
379 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)
380 ratio.SetPoint(i, x_ref, r)
381 ratio.GetXaxis().SetTitle(title)
384 for i
in range(ratio.GetN()):
386 width = ratio.GetPointX(i+1)-ratio.GetPointX(i)
if i < ratio.GetN()-1
else ratio.GetPointX(i)-ratio.GetPointX(i-1)
387 ratio.SetPointError(i, width/2.,width/2., err_r_low[i], err_r_high[i])
389 ratio.GetXaxis().SetLimits(xmin, xmax)
397 for j,g
in enumerate(multigraphs[r].GetListOfGraphs()):
400 ymin = ROOT.gPad.GetFrame().GetY1()
401 ymax = ROOT.gPad.GetFrame().GetY2()
403 for i
in range(g.GetN()):
405 if g.GetPointY(i) > ymax:
406 markers[r].append(ROOT.TMarker(g.GetPointX(i), ymax-(ymax-ymin)*0.05, 26))
407 markers[r][outliers_index].SetMarkerColor(configs[j+NRef][
'linecolor'])
408 markers[r][outliers_index].SetMarkerSize(1.2)
409 markers[r][outliers_index].Draw(
'same')
412 if g.GetPointY(i) < ymin
and g.GetPointY(i) > 0:
413 markers[r].append(ROOT.TMarker(g.GetPointX(i), ymin+(ymax-ymin)*0.05, 32))
414 markers[r][outliers_index].SetMarkerColor(configs[j+NRef][
'linecolor'])
415 markers[r][outliers_index].SetMarkerSize(1.2)
416 markers[r][outliers_index].Draw(
'same')
423 for j,ratio
in enumerate(ratios):
425 ymin = ROOT.gPad.GetFrame().GetY1()
426 ymax = ROOT.gPad.GetFrame().GetY2()
428 for i
in range(ratio.GetNbinsX()):
430 if ratio.GetBinContent(i) > ymax:
431 markers[r].append(ROOT.TMarker(ratio.GetXaxis().GetBinCenter(i), ymax-(ymax-ymin)*0.05, 26))
432 markers[r][outliers_index].SetMarkerColor(configs[j+NRef][
'linecolor'])
433 markers[r][outliers_index].SetMarkerSize(1.2)
434 markers[r][outliers_index].Draw(
'same')
437 if ratio.GetBinContent(i) < ymin
and ratio.GetBinContent(i) > 0:
438 markers[r].append(ROOT.TMarker(ratio.GetXaxis().GetBinCenter(i), ymin+(ymax-ymin)*0.05, 32))
439 markers[r][outliers_index].SetMarkerColor(configs[j+NRef][
'linecolor'])
440 markers[r][outliers_index].SetMarkerSize(1.2)
441 markers[r][outliers_index].Draw(
'same')
452def draw(args, configs, tails=False, pu_comparison=False):
454 NRef = len(args.ref)
if not pu_comparison
else 1
457 legend =
getLegend(args.legend_coord[0],args.legend_coord[1],args.legend_coord[2],args.legend_coord[3])
458 doComparison = len(configs) > 1
459 isTEfficiencyObj =
False
463 for i,cfg
in enumerate(configs):
468 if not tails: h.Draw(
'same' if i!=0
else '')
470 else: h.Draw(
'sameHISTE' if i%2!=0
else 'samePE')
474 if doComparison
and cfg[
'dimension'] ==
'1D':
478 draw_option =
'l' if i%2!=0
else 'lp'
479 jet =
'b-Jet' if i%2==0
else 'LF-Jet'
480 legend.AddEntry(h, f
"{cfg['legend']} {jet}",draw_option)
482 else: legend.AddEntry(h, cfg[
'legend'],draw_option)
495 for r
in range(NRef):
497 labelsizescales = [canv.GetPad(1).GetHNDC()/canv.GetPad(i+2).GetHNDC()
for i
in range(NRef)]
500 multigraphs.append(ROOT.TMultiGraph())
503 if not tails
and not pu_comparison:
505 for i
in range(NRef, len(configs)):
506 ratio_histos = [histos[r]
if not isTProfile(histos[r])
else histos[r].ProjectionX(), histos[i]
if not isTProfile(histos[i])
else histos[i].ProjectionX()]
511 ratio = ratio_histos[1].Clone()
512 ratio.Divide(ratio_histos[0])
515 for i, ratio
in enumerate(ratios):
516 color = configs[i+NRef][
'linecolor']
517 linestyle = configs[i+1][
'linestyle']
518 markstyle = configs[i+1][
'markstyle']
519 setRatioStyle(ratio, configs[i], color, linestyle, markstyle, ref=configs[r][
'pipeline'], labelsizescale = labelsizescales[r], lastpad = (r==NRef-1), splittitle = (NRef>1))
522 multigraphs[r].Add(ratio,
'p')
528 xmin, xmax = ratios[0].GetXaxis().GetXmin(), ratios[0].GetXaxis().GetXmax()
529 setRatioStyle(multigraphs[r], configs[i], color, linestyle, markstyle, ref=configs[r][
'pipeline'], multigraph=
True, labelsizescale = labelsizescales[r], lastpad = (r==NRef-1), splittitle = (NRef>1))
530 multigraphs[r].Draw(
'a')
532 multigraphs[r].GetXaxis().SetLimits(xmin, xmax)
539 if args.type ==
'resolution' and not pu_comparison
and 'C000' in args.ref[0]:
540 requirement_line, requirement_text =
getURDRequirementLine(ratios[0],
'resolution', canv, labelsizescales[r], logx = (
'x' in args.log))
541 urd_lines.append(requirement_line)
542 urd_text.append(requirement_text)
543 urd_lines[r].Draw(
'same')
544 urd_text[r].Draw(
'same')
548 ratio_histos = [histos[i],histos[i+1]]
549 ratio = ratio_histos[0].Clone()
550 ratio.Divide(ratio_histos[1])
553 for i, ratio
in enumerate(ratios):
554 color = configs[i*2][
'linecolor']
555 linestyle = configs[i*2][
'linestyle']
556 markstyle = configs[i*2][
'markstyle']
557 setRatioStyle(ratio, configs[i], color, linestyle, markstyle, ref=configs[r][
'pipeline'],labelsizescale = labelsizescales[r], lastpad = (r==NRef-1))
558 ratio.GetYaxis().SetTitle(
'b-Jet / LF-Jet' if tails
else '<#mu> = 140/<#mu> = 200')
563 var = cfg[
'histo']
if not cfg[
'category'] ==
'Efficiencies/Technical' else cfg[
'histo'].
replace(
'eff',
'tech_eff')
564 canv.SaveAs(f
"{args.output}/{args.tag+'_' if args.tag != '' else ''}{var}.png")
570 inputTest = args.test
572 pipelinesRef = args.pipelineRef
573 pipelinesTest = args.pipelineTest
574 trkanalysesRef = args.trkAnalysisRef
575 trkanalysesTest = args.trkAnalysisTest
576 doTails = (args.type ==
'tails')
577 doPUComparison = args.pu_comparison
580 if not doTails
and not doPUComparison:
581 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]
582 linestyles = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
583 markstyles = [ 20, 21, 22, 23, 24, 25, 26, 27, 28, 30 ]
584 inputFiles = inputRef+inputTest
585 pipelines = pipelinesRef+pipelinesTest
586 trkanalyses = trkanalysesRef+trkanalysesTest
587 inputFiles = inputRef+inputTest
595 for i,pipeline
in enumerate(pipelines):
596 isReference = (i<len(pipelinesRef))
597 f = ROOT.TFile.Open(inputFiles[i],
'READ')
598 configs.append(
getConfig(f, chain, pipeline, trkanalyses[i], args, colors[i], markstyles[i], linestyles[i], isReference))
604 colors = [ROOT.kRed, ROOT.kRed, ROOT.kBlue, ROOT.kBlue]
605 linestyles = [2,1,2,1]
606 markstyles = [20,0,24,0]
if doTails
else [20, 24, 20, 24]
607 pipelines = args.pipelineRef+args.pipelineRef+args.pipelineTest+args.pipelineTest
if doTails
else args.pipelineRef+args.pipelineTest
608 trkanalyses = args.trkAnalysisRef
609 trkanalyses.extend(args.trkAnalysisTest)
610 inputFiles = inputRef+inputRef+inputTest+inputTest
if doTails
else inputRef+inputTest
613 for i,trkana
in enumerate(trkanalyses):
614 f = ROOT.TFile.Open(inputFiles[i],
'READ')
615 configs.append(
getConfig(f, chain, pipelines[i], trkanalyses[i], args, colors[i], markstyles[i], linestyles[i]))
617 draw(args, configs, tails=doTails,pu_comparison=doPUComparison)
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,...
setRatioStyle(ratio, cfg, color, linestyle, markstyle, ref='C000', multigraph=False, labelsizescale=65./35., lastpad=False, splittitle=False)