Skip to content

Commit

Permalink
lint with the proper black version
Browse files Browse the repository at this point in the history
  • Loading branch information
anigamova committed Dec 5, 2023
1 parent ed1cc7e commit 4ad1387
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,20 @@
"vhbb_Zee_250_400_13TeV",
"vhbb_Zee_gt400_13TeV",
]
hist = ROOT.TH2F(
"migration", "", len(signals), 0, len(signals), len(bins), 0, len(bins)
)
hist = ROOT.TH2F("migration", "", len(signals), 0, len(signals), len(bins), 0, len(bins))
for i, b in enumerate(bins):
total_signal = 0
for j, p in enumerate(signals):
procs = cb.cp().bin([b]).process([p]).GetRate()
procs += cb.cp().bin([b]).process([p.replace("ZH", "ggZH")]).GetRate()
procs += cb.cp().bin([b.replace("Zee", "Zmm")]).process([p]).GetRate()
procs += (
cb.cp()
.bin([b.replace("Zee", "Zmm")])
.process([p.replace("ZH", "ggZH")])
.GetRate()
)
procs += cb.cp().bin([b.replace("Zee", "Zmm")]).process([p.replace("ZH", "ggZH")]).GetRate()
total_signal += procs
hist.SetBinContent(j + 1, i + 1, procs)
hist.GetXaxis().SetBinLabel(j + 1, p)
hist.GetYaxis().SetBinLabel(i + 1, b.replace("Zee", "Zll"))
for j, p in enumerate(signals):
hist.SetBinContent(
j + 1, i + 1, hist.GetBinContent(j + 1, i + 1) / total_signal
)
hist.SetBinContent(j + 1, i + 1, hist.GetBinContent(j + 1, i + 1) / total_signal)

c1 = ROOT.TCanvas()
c1.cd()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@
meas_dict = json.load(json_file)["STXS"]

for i, p in enumerate(pois):
symm_err = (
float(meas_dict[p]["ErrorHi"]) + float(-1 * meas_dict[p]["ErrorLo"])
) / 2.0
symm_err = (float(meas_dict[p]["ErrorHi"]) + float(-1 * meas_dict[p]["ErrorLo"])) / 2.0
unfolded.SetBinContent(i + 2, meas_dict[p]["Val"] * sm_xs.GetBinContent(i + 2))
unfolded.SetBinError(i + 2, symm_err * sm_xs.GetBinContent(i + 2))
sm_xs.GetXaxis().SetBinLabel(i + 2, bin_labels_ZH[i])
Expand Down
57 changes: 14 additions & 43 deletions data/tutorials/tutorial_unfolding_2023/scripts/plot1DScan.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ def BuildScan(scan, param, files, color, yvals, ycut):

if graph.GetN() <= 1:
graph.Print()
raise RuntimeError(
"Attempting to build %s scan from TGraph with zero or one point (see above)"
% files
)
raise RuntimeError("Attempting to build %s scan from TGraph with zero or one point (see above)" % files)

bestfit = None
for i in range(graph.GetN()):
Expand Down Expand Up @@ -111,23 +108,13 @@ def BuildScan(scan, param, files, color, yvals, ycut):
parser = argparse.ArgumentParser()

parser.add_argument("main", help="Main input file for the scan")
parser.add_argument(
"--y-cut", type=float, default=7.0, help="Remove points with y > y-cut"
)
parser.add_argument("--y-cut", type=float, default=7.0, help="Remove points with y > y-cut")
parser.add_argument("--y-max", type=float, default=8.0, help="y-axis maximum")
parser.add_argument(
"--output", "-o", help="output name without file extension", default="scan"
)
parser.add_argument("--output", "-o", help="output name without file extension", default="scan")
parser.add_argument("--POI", help="use this parameter of interest", default="r")
parser.add_argument(
"--translate", default=None, help="json file with POI name translation"
)
parser.add_argument(
"--main-label", default="Observed", type=str, help="legend label for the main scan"
)
parser.add_argument(
"--main-color", default=1, type=int, help="line and marker color for main scan"
)
parser.add_argument("--translate", default=None, help="json file with POI name translation")
parser.add_argument("--main-label", default="Observed", type=str, help="legend label for the main scan")
parser.add_argument("--main-color", default=1, type=int, help="line and marker color for main scan")
parser.add_argument(
"--others",
nargs="*",
Expand Down Expand Up @@ -155,9 +142,7 @@ def BuildScan(scan, param, files, color, yvals, ycut):
yvals = [1.0, 4.0]


main_scan = BuildScan(
args.output, args.POI, [args.main], args.main_color, yvals, args.y_cut
)
main_scan = BuildScan(args.output, args.POI, [args.main], args.main_color, yvals, args.y_cut)

other_scans = []
other_scans_opts = []
Expand Down Expand Up @@ -201,9 +186,7 @@ def BuildScan(scan, param, files, color, yvals, ycut):
if min(mins) < main_scan["graph"].GetX()[0]:
new_min = min(mins) - (main_scan["graph"].GetX()[0] - new_min)
if max(maxs) > main_scan["graph"].GetX()[main_scan["graph"].GetN() - 1]:
new_max = max(maxs) + (
new_max - main_scan["graph"].GetX()[main_scan["graph"].GetN() - 1]
)
new_max = max(maxs) + (new_max - main_scan["graph"].GetX()[main_scan["graph"].GetN() - 1])
axishist.GetXaxis().SetLimits(new_min, new_max)

for other in other_scans:
Expand Down Expand Up @@ -306,9 +289,7 @@ def BuildScan(scan, param, files, color, yvals, ycut):
pt.SetTextFont(42)
pt.Draw()

plot.DrawCMSLogo(
pads[0], args.logo, args.logo_sub, 11, 0.045, 0.035, 1.2, cmsTextSize=1.0
)
plot.DrawCMSLogo(pads[0], args.logo, args.logo_sub, 11, 0.045, 0.035, 1.2, cmsTextSize=1.0)

legend_l = 0.69
if len(other_scans) > 0:
Expand Down Expand Up @@ -352,31 +333,21 @@ def BuildScan(scan, param, files, color, yvals, ycut):
interval = other["other_1sig"][0]
js_extra["OtherLimit%sLo" % breakdown[oi + 1]] = interval["lo"]
js_extra["OtherLimit%sHi" % breakdown[oi + 1]] = interval["hi"]
js_extra["ValidOtherLimit%sLo" % breakdown[oi + 1]] = interval[
"valid_lo"
]
js_extra["ValidOtherLimit%sHi" % breakdown[oi + 1]] = interval[
"valid_hi"
]
js_extra["ValidOtherLimit%sLo" % breakdown[oi + 1]] = interval["valid_lo"]
js_extra["ValidOtherLimit%sHi" % breakdown[oi + 1]] = interval["valid_hi"]
if len(main_scan["other_2sig"]) >= 1:
interval = other["other_2sig"][0]
js_extra["2sig_OtherLimit%sLo" % breakdown[oi + 1]] = interval["lo"]
js_extra["2sig_OtherLimit%sHi" % breakdown[oi + 1]] = interval["hi"]
js_extra["2sig_ValidOtherLimit%sLo" % breakdown[oi + 1]] = interval[
"valid_lo"
]
js_extra["2sig_ValidOtherLimit%sHi" % breakdown[oi + 1]] = interval[
"valid_hi"
]
js_extra["2sig_ValidOtherLimit%sLo" % breakdown[oi + 1]] = interval["valid_lo"]
js_extra["2sig_ValidOtherLimit%sHi" % breakdown[oi + 1]] = interval["valid_hi"]
js[args.model][args.POI].update(js_extra)

with open(args.json, "w") as outfile:
json.dump(js, outfile, sort_keys=True, indent=4, separators=(",", ": "))


save_graph = main_scan["graph"].Clone()
save_graph.GetXaxis().SetTitle(
"%s = %.3f %+.3f/%+.3f" % (fixed_name, val_nom[0], val_nom[2], val_nom[1])
)
save_graph.GetXaxis().SetTitle("%s = %.3f %+.3f/%+.3f" % (fixed_name, val_nom[0], val_nom[2], val_nom[1]))
canv.Print(".pdf")
canv.Print(".png")
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@
for p2 in range(0, len(parameters_stxs)):
param1 = parameters_stxs[p1]
param2 = parameters_stxs[p2]
correlation_matrix_pruned.SetBinContent(
p1 + 1, p2 + 1, rfr.correlation(param1, param2)
)
correlation_matrix_pruned.SetBinContent(p1 + 1, p2 + 1, rfr.correlation(param1, param2))
correlation_matrix_pruned.GetXaxis().SetBinLabel(p1 + 1, parameters_stxs[p1])
correlation_matrix_pruned.GetYaxis().SetBinLabel(p1 + 1, parameters_stxs[p1])

Expand All @@ -80,9 +78,7 @@
c2.SetFixedAspectRatio()
pads[0].cd()
correlation_matrix_pruned.Draw("COLZTEXT")
plot.DrawCMSLogo(
pads[0], "CMS", "Material for Combine tutorial", 0.0, 0.15, 0.04, 1.0, "", 0.6
)
plot.DrawCMSLogo(pads[0], "CMS", "Material for Combine tutorial", 0.0, 0.15, 0.04, 1.0, "", 0.6)
plot.DrawTitle(pads[0], "", 3, textSize=0.4)

c2.SaveAs("%(outname)s_pois.pdf" % vars())
Expand Down

0 comments on commit 4ad1387

Please sign in to comment.