def test_cash_errors(n_on, mu_bkg, result): stat = CashCountsStatistic(n_on, mu_bkg) errn = stat.compute_errn() errp = stat.compute_errp() assert_allclose(errn, result[0], atol=1e-5) assert_allclose(errp, result[1], atol=1e-5)
"""Example plot showing the profile of the Cash statistic and its connection to excess errors.""" import numpy as np import matplotlib.pyplot as plt from gammapy.stats import CashCountsStatistic count_statistic = CashCountsStatistic(n_on=13, mu_bkg=5.5) excess = count_statistic.excess errn = count_statistic.compute_errn(1.0) errp = count_statistic.compute_errp(1.0) errn_2sigma = count_statistic.compute_errn(2.0) errp_2sigma = count_statistic.compute_errp(2.0) # We compute the Cash statistic profile mu_signal = np.linspace(-1.5, 25, 100) stat_values = count_statistic._stat_fcn(mu_signal) xmin, xmax = -1.5, 25 ymin, ymax = -42, -28.0 plt.figure(figsize=(5, 5)) plt.plot(mu_signal, stat_values, color="k") plt.xlim(xmin, xmax) plt.ylim(ymin, ymax) plt.xlabel(r"Number of expected signal event, $\mu_{sig}$") plt.ylabel(r"Cash statistic value, TS ") plt.hlines( count_statistic.TS_max + 1, xmin=excess + errn, xmax=excess + errp,