Skip to content

Commit 58283de

Browse files
compare ratio of weighted histograms (#1845)
* first attempt just from current knowledge runs but has two main issues observed 1. lots of runtime warnings about invalid division. This comes from 0/0 since 1/0 is converted to np.nan or np.inf 2. ratio uncertainty is crazy large, probably because the weights for the signal samples are also extreme * silence NumPy divide-by-zero warnings since the defaults are what we want * use poisson-ratio instead of raw poisson counts
1 parent f3d8611 commit 58283de

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

ComparePlots/_differ.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import uproot
1010
import numpy as np
1111
import hist.intervals
12+
import mplhep
1213

1314
# us
1415
from ._file import File
@@ -144,11 +145,19 @@ def plot1d(
144145
den_h, _den_art = raw_histograms[0]
145146
bins = den_h.axes[0].edges
146147
for num_h, num_art in raw_histograms[1:]:
147-
(den_h/num_h).plot1d(
148+
# NumPy nicely warns us when we divide by zero,
149+
# but its defaults are sensible to use
150+
# x/0 = inf, 0/0 = nan
151+
with np.errstate(divide="ignore", invalid="ignore"):
152+
ratio = num_h.values() / den_h.values()
153+
mplhep.histplot(
154+
ratio,
155+
bins = bins,
148156
ax = ratio_ax,
149157
yerr = hist.intervals.ratio_uncertainty(
150158
num = num_h.values(),
151-
denom = den_h.values()
159+
denom = den_h.values(),
160+
uncertainty_type = 'poisson-ratio'
152161
),
153162
histtype='errorbar',
154163
color = num_art[0].stairs.get_edgecolor()

0 commit comments

Comments
 (0)