@@ -44,7 +44,7 @@ def separate_sig_bkg_hists(hists: OrderedDict):
44
44
45
45
if not h_sig :
46
46
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 "
48
48
"signal processes" ,
49
49
)
50
50
if not h_bkg :
@@ -64,6 +64,8 @@ def plot_s_over_b(
64
64
yscale : str | None = "" ,
65
65
hide_errors : bool | None = None ,
66
66
sqrt_b : bool | None = None ,
67
+ cumsum : bool = False ,
68
+ reversed_cumsum : bool = False ,
67
69
process_settings : dict | None = None ,
68
70
variable_settings : dict | None = None ,
69
71
** kwargs ,
@@ -79,6 +81,9 @@ def plot_s_over_b(
79
81
--plot-function hbw.plotting.s_over_b.plot_s_over_b \
80
82
--general-settings sqrt_b
81
83
"""
84
+ if cumsum and reversed_cumsum :
85
+ raise Exception ("We can only do the cumulative cumsum in one direction at the time!" )
86
+
82
87
remove_residual_axis (hists , "shift" )
83
88
84
89
variable_inst = variable_insts [0 ]
@@ -97,6 +102,18 @@ def plot_s_over_b(
97
102
f"\n Integrated S over sqrtB: { round_sig (S_over_sqrtB )} " ,
98
103
)
99
104
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
+
100
117
# NOTE: this does not take into account the variances on the background stack
101
118
if sqrt_b :
102
119
h_out = h_sig / np .sqrt (h_bkg .values ())
0 commit comments