Skip to content
Snippets Groups Projects
Commit 008fbd34 authored by Marcel Rieger's avatar Marcel Rieger
Browse files

Fix multi limit plots with mixed unblinding flags.

parent 54353181
No related branches found
No related tags found
No related merge requests found
Pipeline #3559430 passed
......@@ -347,6 +347,7 @@ def plot_limit_scans(
def check_values(values):
_values = []
for v in values:
if v is not None:
if isinstance(v, np.ndarray):
v = {key: v[key] for key in v.dtype.names}
assert "limit" in v
......@@ -363,7 +364,7 @@ def plot_limit_scans(
if observed_values:
assert len(observed_values) == n_graphs
observed_values = check_values(observed_values)
has_obs = True
has_obs = any(v is not None for v in observed_values)
scan_values = expected_values[0][scan_parameter]
has_thy = theory_values is not None
has_thy_err = False
......@@ -441,8 +442,8 @@ def plot_limit_scans(
scan_values.min(), scan_values.max())
# observed graph
if has_obs:
ov = observed_values[i]
if ov is not None:
obs_mask = ~np.isnan(ov["limit"])
obs_limit_values = ov["limit"][obs_mask]
obs_scan_values = ov[scan_parameter][obs_mask]
......@@ -645,6 +646,7 @@ def plot_limit_points(
x_max_value = max(x_max_value, max(d["expected"]))
if "observed" in d:
assert isinstance(d["observed"], (float, int))
if not np.isnan(d["observed"]) and d["observed"] is not None:
has_obs = True
x_min_value = min(x_min_value, d["observed"])
x_max_value = max(x_max_value, d["observed"])
......@@ -819,7 +821,7 @@ def plot_limit_points(
fmt = lambda v: "{{:.{}f}} {{}}".format(get_digits(v)).format(v, xsec_unit)
else:
fmt = lambda v: "{{:.{}f}}".format(get_digits(v)).format(v)
if obs is None:
if obs is None or np.isnan(obs[0]):
return y_label_tmpl % (label, fmt(exp))
else:
return y_label_tmpl_obs % (label, fmt(exp), fmt(obs[0]))
......
......
......@@ -294,7 +294,9 @@ class PlotMultipleGoodnessOfFits(PlotGoodnessOfFit, POIMultiTask, MultiDatacardT
def requires(self):
return [
MergeGoodnessOfFit.req(self, datacards=datacards, toys=t, toys_per_branch=tpb, **kwargs)
for datacards, t, tpb, kwargs in zip(self.multi_datacards, self.toys, self.toys_per_branch, self.get_multi_task_kwargs())
for datacards, t, tpb, kwargs in zip(
self.multi_datacards, self.toys, self.toys_per_branch, self.get_multi_task_kwargs(),
)
]
def output(self):
......
......
......@@ -662,14 +662,12 @@ class PlotMultipleUpperLimits(PlotUpperLimits, POIMultiTask, MultiDatacardTask):
names = [names[i] for i in self.datacard_order]
# prepare observed values
obs_values = None
if self.unblinded:
obs_values = [
{
self.scan_parameter: _limit_values[self.scan_parameter],
"limit": _limit_values["observed"],
}
for _limit_values in limit_values
} if mkwargs["unblinded"] else None
for _limit_values, mkwargs in zip(limit_values, self.get_multi_task_kwargs())
]
# call the plot function
......@@ -807,14 +805,12 @@ class PlotMultipleUpperLimitsByModel(PlotUpperLimits, POIMultiTask, MultiHHModel
names = [names[i] for i in self.hh_model_order]
# prepare observed values
obs_values = None
if self.unblinded:
obs_values = [
{
self.scan_parameter: _limit_values[self.scan_parameter],
"limit": _limit_values["observed"],
}
for _limit_values in limit_values
} if mkwargs["unblinded"] else None
for _limit_values, mkwargs in zip(limit_values, self.get_multi_task_kwargs())
]
# call the plot function
......@@ -992,11 +988,11 @@ class PlotUpperLimitsAtPoint(UpperLimitsBase, POIPlotTask, POIMultiTask, MultiDa
# load limit values
names = ["limit", "limit_p1", "limit_m1", "limit_p2", "limit_m2"]
if self.unblinded:
if any(self.unblinded):
names.append("observed")
limit_values = np.array(
[
self.load_limits(coll["collection"][0], unblinded=self.unblinded)
self.load_limits(coll["collection"][0], unblinded=any(self.unblinded))
for coll in self.input()
],
dtype=[(name, np.float32) for name in names],
......@@ -1051,7 +1047,7 @@ class PlotUpperLimitsAtPoint(UpperLimitsBase, POIPlotTask, POIMultiTask, MultiDa
"expected": record.tolist()[:5],
"theory": thy_value and thy_value[0].tolist()[1:],
}
if self.unblinded:
if any(self.unblinded):
entry["observed"] = float(record[5])
data.append(entry)
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment