Skip to content

Commit 2cb9e08

Browse files
authored
Merge pull request #71 from uhh-cms/feature/plot_updates
Feature/plot updates
2 parents 5f42e44 + c9b06c7 commit 2cb9e08

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

hbw/plotting/s_over_b.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def separate_sig_bkg_hists(hists: OrderedDict):
4444

4545
if not h_sig:
4646
raise Exception(
47-
"No signal processes given. Remember to add the 'is_signal' auxiliary to your "
47+
"No signal processes given. Remember to add the 'is_signal' tag to your "
4848
"signal processes",
4949
)
5050
if not h_bkg:
@@ -64,6 +64,8 @@ def plot_s_over_b(
6464
yscale: str | None = "",
6565
hide_errors: bool | None = None,
6666
sqrt_b: bool | None = None,
67+
cumsum: bool = False,
68+
reversed_cumsum: bool = False,
6769
process_settings: dict | None = None,
6870
variable_settings: dict | None = None,
6971
**kwargs,
@@ -79,6 +81,9 @@ def plot_s_over_b(
7981
--plot-function hbw.plotting.s_over_b.plot_s_over_b \
8082
--general-settings sqrt_b
8183
"""
84+
if cumsum and reversed_cumsum:
85+
raise Exception("We can only do the cumulative cumsum in one direction at the time!")
86+
8287
remove_residual_axis(hists, "shift")
8388

8489
variable_inst = variable_insts[0]
@@ -97,6 +102,18 @@ def plot_s_over_b(
97102
f"\n Integrated S over sqrtB: {round_sig(S_over_sqrtB)}",
98103
)
99104

105+
if cumsum or reversed_cumsum:
106+
# calculate the cumulative sum of the histograms
107+
for h in (h_sig, h_bkg):
108+
h_view = h.view()
109+
h_view.value = np.cumsum(h_view.value) if cumsum else np.cumsum(h_view.value[::-1])[::-1]
110+
111+
# TODO: implement correct variances; in the meantime, just set them to 0
112+
h_view.variance = [0] * len(h.view())
113+
114+
# overwrite view of original histograms
115+
h[...] = h_view
116+
100117
# NOTE: this does not take into account the variances on the background stack
101118
if sqrt_b:
102119
h_out = h_sig / np.sqrt(h_bkg.values())

hbw/tasks/plotting.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from columnflow.tasks.framework.plotting import (
2222
PlotBase, PlotBase1D, VariablePlotSettingMixin, ProcessPlotSettingMixin,
2323
)
24+
from columnflow.tasks.framework.decorators import view_output_plots
2425
from columnflow.tasks.plotting import PlotVariables1D
2526
# from columnflow.tasks.framework.remote import RemoteWorkflow
2627
from hbw.tasks.base import HBWTask
@@ -182,7 +183,10 @@ def plot_postfit_shapes(
182183
default_style_config = prepare_style_config(
183184
config_inst, category_inst, variable_inst, density, shape_norm, yscale,
184185
)
185-
default_style_config["ax_cfg"].pop("xlim")
186+
187+
# since we are rebinning, the xlim should be defined based on the histograms itself
188+
bin_edges = list(hists.values())[0].axes[0].edges
189+
default_style_config["ax_cfg"]["xlim"] = (bin_edges[0], bin_edges[-1])
186190

187191
style_config = law.util.merge_dicts(default_style_config, style_config, deep=True)
188192
if shape_norm:
@@ -235,6 +239,7 @@ def requires(self):
235239
def output(self):
236240
return {"plots": self.target("plots", dir=True)}
237241

242+
@view_output_plots
238243
def run(self):
239244
logger.warning(
240245
f"Note! It is important that the requested inference_model {self.inference_model} "

0 commit comments

Comments
 (0)