/
example_fc_gauss_analytical.py
executable file
·50 lines (40 loc) · 1.32 KB
/
example_fc_gauss_analytical.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""Analytical solution for Gaussian with a boundary at
the origin. Produces Fig. 10 from the Feldman Cousins
paper."""
import numpy as np
import matplotlib.pyplot as plt
from astropy.utils.console import ProgressBar
from gammapy.stats import (
fc_find_acceptance_interval_gauss,
fc_fix_limits,
)
sigma = 1
n_sigma = 10
n_bins_x = 1000
step_width_mu = 0.005
mu_min = 0
mu_max = 8
cl = 0.90
x_bins = np.linspace(-n_sigma * sigma, n_sigma * sigma, n_bins_x, endpoint=True)
mu_bins = np.linspace(mu_min, mu_max, mu_max / step_width_mu + 1, endpoint=True)
print("Generating Feldman Cousins confidence belt for " + str(len(mu_bins)) +
" values of mu.")
UpperLimitAna = []
LowerLimitAna = []
for mu in ProgressBar(mu_bins):
goodChoice = fc_find_acceptance_interval_gauss(mu, sigma, x_bins, cl)
UpperLimitAna.append(goodChoice[0])
LowerLimitAna.append(goodChoice[1])
fc_fix_limits(LowerLimitAna, UpperLimitAna)
fig = plt.figure()
ax = fig.add_subplot(111)
plt.plot(LowerLimitAna, mu_bins, ls='-', color='red')
plt.plot(UpperLimitAna, mu_bins, ls='-', color='red')
plt.grid(True)
ax.xaxis.set_ticks(np.arange(-10, 10, 1))
ax.xaxis.set_ticks(np.arange(-10, 10, 0.2), True)
ax.yaxis.set_ticks(np.arange(0, 8, 0.2), True)
ax.set_xlabel(r'Measured Mean x')
ax.set_ylabel(r'Mean $\mu$')
plt.axis([-2, 4, 0, 6])
plt.show()