158 if ao.dim() != 2:
return
160 tgraphs[
'all'] = [r.TGraphAsymmErrors(), r.TGraphAsymmErrors(), r.TGraphAsymmErrors(), r.TGraphAsymmErrors()]
163 nbins = ao.numPoints()
164 corr = ao.annotation(
'ErrorBreakdown')
if '1.7' in yoda.version()
else yaml.load(ao.annotation(
'ErrorBreakdown'))
166 if len(corr) == 0:
return
167 systList = corr[0].keys()
169 all_up = [0
for i
in range(nbins)]
170 all_dn = [0
for i
in range(nbins)]
171 for sname
in systList:
172 tgu = r.TGraphAsymmErrors()
173 tgu_line = r.TGraphAsymmErrors()
174 tgd = r.TGraphAsymmErrors()
175 tgd_line = r.TGraphAsymmErrors()
178 for i
in range(nbins):
179 nominalx = ao.points()[i].x()
180 nominaly = ao.points()[i].y()
181 xerr = abs(nominalx - ao.points()[i].xMin())
182 tgu.SetPoint(pt, nominalx, 1)
183 tgd.SetPoint(pt, nominalx, 1)
184 if nominaly == 0:
continue
185 eup = 1 - (((corr[i][sname][
'up'])) + nominaly) / nominaly
186 edn = 1 - (((corr[i][sname][
'dn'])) + nominaly) / nominaly
187 all_up[i] = (all_up[i] ** 2 + eup ** 2) ** 0.5
188 all_dn[i] = (all_dn[i] ** 2 + edn ** 2) ** 0.5
189 if (abs(eup) > threshold): draw = 1
190 if (abs(edn) > threshold): draw = 1
191 if (abs(edn) > threshold): draw = 1
192 if abs(all_up[i]) > maxErr: maxErr = abs(all_up[i])
193 tgu.SetPointError(pt, xerr, xerr, 0, eup)
194 tgd.SetPointError(pt, xerr, xerr, 0, edn)
195 tgu_line.SetPoint(pt, nominalx, 1 + eup)
196 tgd_line.SetPoint(pt, nominalx, 1 + edn)
197 tgu_line.SetPointError(pt, xerr, xerr, 0, 0)
198 tgd_line.SetPointError(pt, xerr, xerr, 0, 0)
199 tgraphs[
'all'][0].SetPoint(pt, nominalx, nominaly / nominaly)
200 tgraphs[
'all'][1].SetPoint(pt, nominalx, nominaly / nominaly)
201 tgraphs[
'all'][2].SetPoint(pt, nominalx, 1 - all_dn[i])
202 tgraphs[
'all'][3].SetPoint(pt, nominalx, 1 + all_up[i])
203 tgraphs[
'all'][0].SetPointError(pt, xerr, xerr, 0, -1 * all_dn[i])
204 tgraphs[
'all'][1].SetPointError(pt, xerr, xerr, 0, all_up[i])
205 tgraphs[
'all'][2].SetPointError(pt, xerr, xerr, 0, 0)
206 tgraphs[
'all'][3].SetPointError(pt, xerr, xerr, 0, 0)
208 if (draw): tgraphs[sname] = [tgd, tgu, tgd_line, tgu_line]
210 tc = r.TCanvas(
"c",
"c", 500, 500)
213 leg = r.TLegend(.13, .6, .9, .8)
219 leg.SetTextSize(0.025)
221 for tgname, tg
in sorted(tgraphs.items(), key=
lambda x: abs(x[1][1].GetErrorYhigh(0)), reverse=
True):
223 isCorr =
not ((
'stat' in tgname)
or (
'all' in tgname))
224 if 'nominal' == tgname:
continue
225 if 'mc' == tgname:
continue
226 tg[0].SetFillColorAlpha(0 + itg, 0.3)
227 tg[1].SetFillColorAlpha(0 + itg, 0.3)
228 tg[0].SetMarkerColor(1)
229 tg[2].SetMarkerStyle(23)
230 tg[2].SetMarkerColor(0 + itg)
231 tg[2].SetLineColor(0 + itg)
232 tg[3].SetMarkerStyle(22)
233 tg[3].SetMarkerColor(0 + itg)
234 tg[3].SetLineColor(0 + itg)
235 leg.AddEntry(tg[0], tgname,
"f")
237 tg[0].Draw(
"p2 same")
238 tg[1].Draw(
"p2 same")
239 if isCorr: tg[2].Draw(
"P same")
240 if isCorr: tg[3].Draw(
"P same ")
242 tg[0].SetMaximum((1. + maxErr) * 1.33)
243 tg[0].SetMinimum(1. - maxErr)
245 tg[1].Draw(
"P2 same ")
246 if isCorr: tg[2].Draw(
"P same")
247 if isCorr: tg[3].Draw(
"P same")
253 lat.SetTextSize(0.05)
254 lat.DrawLatex(0.1, 0.91,
"#it{ATLAS} #bf{Internal}")
255 lat.SetTextSize(0.035)
256 lat.DrawLatex(0.13, 0.83,
"#bf{All variations >%1.1f%% anywhere in range:}" % (threshold * 100))
259 lat.SetTextSize(0.04)
260 lat.DrawLatex(0.9, 0.05,
"#bf{%s}" % xLabel.replace(
"$",
"").
replace(
"\\text",
""))
262 lat.DrawLatex(0.02, 0.9,
"#bf{Relative Uncertainty}")
263 outfile =
"%s/%s-variations" % (outdir, label)
264 tc.SaveAs(outfile +
".pdf")
265 tc.SaveAs(outfile +
".png")
338 nCols = matrix.shape[0]
339 nRows = matrix.shape[1]
340 assert(nCols == nRows)
344 lat.SetTextSize(0.02)
347 Red =
array(
'd', [1.0, 1.0, 0.0])
348 Grn =
array(
'd', [0.0, 1.0, 0.0])
349 Blu =
array(
'd', [0.0, 1.0, 1.0])
350 Length =
array(
'd', [0.0, 0.5, 1.0])
351 r.TColor.CreateGradientColorTable(len(Length), Length, Red, Grn, Blu, 50)
352 if (
'chi2' in outfile): nRows += 1
353 th2 = r.TH2D(outfile.split(
"/")[-1], outfile.split(
"/")[-1], nRows, 0, nRows, nBins, 0, nBins)
357 for j
in range(nBins):
358 th2.GetYaxis().SetBinLabel(j + 1,
"%d" % (nBins - j))
360 for i
in range(nBins):
361 th2.GetXaxis().SetBinLabel(i + 1,
"%d" % (i + 1))
362 th2.Fill(i, nBins - j - 1, matrix[i][j])
363 total += matrix[i][j]
364 totalOverall += total
365 if(
'chi2' in outfile): th2.Fill(nBins, nBins - j - 1, total)
366 if(
'chi2' in outfile): th2.GetXaxis().SetBinLabel(nBins + 1,
"TOTAL =%.2f" % totalOverall)
367 totalsPerRow.append(total)
368 tc = r.TCanvas(
"c",
"c", 500, 500)
369 tc.SetRightMargin(0.2)
370 if(
'covariance' in outfile): tc.SetLogz()
372 for j
in range(nBins):
373 for i
in range(nBins):
374 lat.DrawLatex(i + 0.5, nBins - j - 0.5,
"%.2f" % matrix[i][j])
375 if(
'chi2' in outfile): lat.DrawLatex(nBins + 0.5, nBins - j - 0.5,
"%.2f" % totalsPerRow[j])
376 th2.SetMaximum(
max(abs(th2.GetMaximum()), abs(th2.GetMinimum())))
377 th2.SetMinimum(-1 * (th2.GetMaximum()))
381 lat.SetTextSize(0.05)
382 lat.DrawLatex(0.1, 0.91,
"#it{ATLAS} #bf{Internal}")
383 lat.SetTextSize(0.035)
386 lat.SetTextSize(0.04)
387 lat.DrawLatex(0.9, 0.05,
"#bf{%s}" % xLabel.replace(
"$",
"").
replace(
"\\text",
""))
389 lat.DrawLatex(0.02, 0.9,
"#bf{%s}" % xLabel.replace(
"$",
"").
replace(
"\\text",
""))
390 tc.SaveAs(outfile +
".pdf")
391 tc.SaveAs(outfile +
".png")
490 aoOut = yoda.core.Scatter2D()
496 corrIn = aoIn.annotation(
'ErrorBreakdown')
if '1.7' in yoda.version()
else yaml.load(aoIn.annotation(
'ErrorBreakdown'))
497 if len(corrIn) == 0:
continue
498 for ipt
in range(aoIn.numPoints()):
499 for syst
in corrIn[ipt].keys():
500 if syst
not in allSystematics: allSystematics.append(syst)
502 for aoIn
in sorted(aoList, key=
lambda x: x.name):
503 corrIn = aoIn.annotation(
'ErrorBreakdown')
if '1.7' in yoda.version()
else yaml.load(aoIn.annotation(
'ErrorBreakdown'))
504 if len(corrIn) == 0:
continue
505 for ipt
in range(aoIn.numPoints()):
506 aoOut.addPoint(yoda.core.Point2D(pointCounter, aoIn.points()[ipt].y()))
508 for syst
in allSystematics:
509 if syst
in corrIn[ipt].keys():
510 corrOut.setdefault(pointCounter, {})[syst] = corrIn[ipt][syst]
511 totalErrorUp += corrIn[ipt][syst][
'up'] * corrIn[ipt][syst][
'up']
513 corrOut.setdefault(pointCounter, {})[syst] = {
'up': 0.0,
'dn': 0.0}
514 pointsOut.append(aoIn.points()[ipt])
516 for i
in range(aoOut.numPoints()):
517 if (verbosity) > 1:
print(
"[INFO] Super AO points ", aoOut.points()[i])
518 corrs = yaml.dump(corrOut, default_flow_style=
True, default_style=
'', width=1e6)
519 aoOut.setAnnotation(
"ErrorBreakdown", corrs)
520 name = aoList[0].path.replace(aoList[0].name,
"")
522 for ao
in sorted(aoList, key=
lambda x: x.name):
523 name +=
"_%s" % ao.name
524 aoOut.setAnnotation(
"Path", name)