-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSTOM_higgs_tools.py
78 lines (58 loc) · 2.43 KB
/
STOM_higgs_tools.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(1)
N_b = 10e5 # Number of background events, used in generation and in fit.
b_tau = 30. # Spoiler.
def generate_data(n_signals = 400):
'''
Generate a set of values for signal and background. Input arguement sets
the number of signal events, and can be varied (default to higgs-like at
announcement).
The background amplitude is fixed to 9e5 events, and is modelled as an exponential,
hard coded width. The signal is modelled as a gaussian on top (again, hard
coded width and mu).
'''
vals = []
vals += generate_signal( n_signals, 125., 1.5)
vals += generate_background( N_b, b_tau)
return vals
def generate_signal(N, mu, sig):
'''
Generate N values according to a gaussian distribution.
'''
return np.random.normal(loc = mu, scale = sig, size = N).tolist()
def generate_background(N, tau):
'''
Generate N values according to an exp distribution.
'''
return np.random.exponential(scale = tau, size = int(N)).tolist()
def get_B_chi(vals, mass_range, nbins, A, lamb):
'''
Calculates the chi-square value of the no-signal hypothesis (i.e background
only) for the passed values. Need an expectation - use the analyic form,
using the hard coded scale of the exp. That depends on the binning, so pass
in as argument. The mass range must also be set - otherwise, its ignored.
'''
bin_heights, bin_edges = np.histogram(vals, range = mass_range, bins = nbins)
half_bin_width = 0.5*(bin_edges[1] - bin_edges[0])
ys_expected = get_B_expectation(bin_edges + half_bin_width, A, lamb)
chi = 0
# Loop over bins - all of them for now.
for i in range( len(bin_heights) ):
chi_nominator = (bin_heights[i] - ys_expected[i])**2
chi_denominator = ys_expected[i]
chi += chi_nominator / chi_denominator
return chi/float(nbins-2) # B has 2 parameters.
def get_B_expectation(xs, A, lamb):
'''
Return a set of expectation values for the background distribution for the
passed in x values.
'''
return [A*np.exp(-x/lamb) for x in xs]
def signal_gaus(x, mu, sig, signal_amp):
return signal_amp/(np.sqrt(2.*np.pi)*sig)*np.exp(-np.power((x - mu)/sig, 2.)/2)
def get_SB_expectation(xs, A, lamb, mu, sig, signal_amp):
ys = []
for x in xs:
ys.append(A*np.exp(-x/lamb) + signal_gaus(x, mu, sig, signal_amp))
return ys