Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pyirf/cut_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def optimize_cuts(
fill_value = signal['gh_score'].max()

sensitivities = []
cut_indicies = []
cut_indices = []
n_theta_cuts = len(theta_cut_efficiencies)
n_gh_cuts = len(gh_cut_efficiencies)
n_cuts = len(multiplicity_cuts) * n_theta_cuts * n_gh_cuts
Expand Down Expand Up @@ -156,7 +156,7 @@ def optimize_cuts(
signal_hist, background_hist, alpha=alpha,
**kwargs,
)
cut_indicies.append((multiplicity_index, theta_index, gh_index))
cut_indices.append((multiplicity_index, theta_index, gh_index))
sensitivities.append(sensitivity)
bar.update(1)

Expand Down Expand Up @@ -192,7 +192,7 @@ def optimize_cuts(
# if all are invalid, just use the first one
best = 0

multiplicity_index, theta_index, gh_index = cut_indicies[best]
multiplicity_index, theta_index, gh_index = cut_indices[best]

best_sensitivity[bin_id] = sensitivities[best][bin_id]

Expand Down
34 changes: 34 additions & 0 deletions pyirf/tests/test_cuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,37 @@ def test_calculate_percentile_cuts_table():
[dist1.ppf(0.68), dist2.ppf(0.68)],
rtol=0.1,
)




def test_calculate_percentile_cuts_multiple():
from pyirf.cuts import calculate_percentile_cut

np.random.seed(0)

dist1 = norm(0, 1)
dist2 = norm(10, 1)
N = int(1e4)

values = np.append(dist1.rvs(size=N), dist2.rvs(size=N)) * u.deg
bin_values = np.append(np.zeros(N), np.ones(N)) * u.m
# add some values outside of binning to test that under/overflow are ignored
bin_values[10] = 5 * u.m
bin_values[30] = -1 * u.m

bins = [-0.5, 0.5, 1.5] * u.m

cuts = calculate_percentile_cut(values, bin_values, bins, fill_value=np.nan * u.deg, percentile=[50, 68, 95])
assert np.all(cuts["low"] == bins[:-1])
assert np.all(cuts["high"] == bins[1:])

np.testing.assert_allclose(
cuts["cut"].to_value(u.deg),
[
[dist1.ppf(0.5), dist1.ppf(0.68), dist1.ppf(0.95)],
[dist2.ppf(0.5), dist2.ppf(0.68), dist2.ppf(0.95)],
],
rtol=0.1,
atol=0.1, # dist1.ppf(0.5) == 0, so we also need a non-zero atol
)
Loading