157 def plotVariations(ao, outdir, label, threshold=0.05, xLabel=None, title=None):
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")