Skip to content

Commit

Permalink
fix: per-channel yield uncertainty contribution from staterror-stater…
Browse files Browse the repository at this point in the history
…ror terms (#324)

* fix calculation of per-channel yield uncertainties
* calculation was previously missing contributions from staterror-staterror terms
  • Loading branch information
alexander-held authored Feb 9, 2022
1 parent f34c73a commit ea3ee7d
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 8 deletions.
6 changes: 0 additions & 6 deletions src/cabinetry/model_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ def yield_stdev(
symmetric_unc = (up_variations_ak[i_par] - down_variations_ak[i_par]) / 2
total_variance = total_variance + symmetric_unc**2

labels = model.config.par_names()
# continue with off-diagonal contributions if there are any
if np.count_nonzero(corr_mat - np.diagflat(np.ones_like(parameters))) > 0:
# loop over pairs of parameters
Expand All @@ -300,11 +299,6 @@ def yield_stdev(
corr = corr_mat[i_par, j_par]
# an approximate calculation could be done here by requiring
# e.g. abs(corr) > 1e-5 to continue
if (
labels[i_par][0:10] == "staterror_"
and labels[j_par][0:10] == "staterror_"
):
continue # two different staterrors are orthogonal, no contribution
sym_unc_i = (up_variations_ak[i_par] - down_variations_ak[i_par]) / 2
sym_unc_j = (up_variations_ak[j_par] - down_variations_ak[j_par]) / 2
# factor of two below is there since loop is only over half the matrix
Expand Down
2 changes: 1 addition & 1 deletion tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def test_integration(tmp_path, ntuple_creator, caplog):
[[11.898333, 7.283185, 7.414715, 7.687922]],
rtol=1e-4,
)
assert np.allclose(model_postfit.total_stdev_model_channels, [20.329756], atol=1e-4)
assert np.allclose(model_postfit.total_stdev_model_channels, [20.439750], atol=1e-4)
_ = cabinetry.visualize.data_mc(model_postfit, data, close_figure=True)

# nuisance parameter ranking
Expand Down
2 changes: 1 addition & 1 deletion tests/test_model_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def test_yield_stdev(example_spec, example_spec_multibin):
model, parameters, uncertainty, corr_mat
)
expected_stdev_bin = [[8.056054, 1.670629], [2.775377]]
expected_stdev_chan = [9.585327, 2.775377]
expected_stdev_chan = [9.596340, 2.775377]
for i_reg in range(2):
assert np.allclose(total_stdev_bin[i_reg], expected_stdev_bin[i_reg])
assert np.allclose(total_stdev_chan[i_reg], expected_stdev_chan[i_reg])
Expand Down

0 comments on commit ea3ee7d

Please sign in to comment.