Belle II Software development
fit_functions.py
1
8
9import numpy as np
10import pandas as pd
11
12
13def landau(x, a, mu, sigma):
14 # A simple landau with thee capability to use lists as input
15 if isinstance(x, np.ndarray):
16 return np.array([landau(xi, a, mu, sigma) for xi in x])
17 elif isinstance(x, pd.Series):
18 return np.array([landau(xi, a, mu, sigma) for xi in x.values])
19 else:
20 from ROOT import TMath
21 return a * TMath.Landau(x, mu, sigma, False)
22
23
24def landau_with_gaus(x, a, mu, sigma, b, c, d):
25 # A landau convoluted with a gauss. Needs a list as input
26 if isinstance(x, np.ndarray):
27 from ROOT import TMath
28 return np.convolve([a * TMath.Landau(xi, mu, sigma, False)
29 for xi in x], [b * TMath.Gaus(xi, c, d, False) for xi in x], "same")
30 else:
31 raise ValueError()
32
33
34def gumbel(x, mu, sigma, a):
35 # A gumbel function
36 z = (x - mu) / sigma
37 return a * 1 / sigma * np.exp(- (z + np.exp(-z)))
38
39
40def norm(x, a, mu, sigma):
41 # A simple gauss
42 return a * np.exp(-(x - mu) ** 2 / (2 * sigma ** 2))
43
44
45def bifur_norm(x, a, mu, sigma_l, sigma_r):
46 # A bifurcated gauss
47 if isinstance(x, np.ndarray):
48 return np.array([bifur_norm(xi, a, mu, sigma_l, sigma_r) for xi in x])
49 else:
50 arg = x - mu
51 if arg < 0:
52 return norm(x, a, mu, sigma_l)
53 else:
54 return norm(x, a, mu, sigma_r)
55
56
57def double_norm(x, a, mu, sigma, b, mu2, sigma2):
58 # A sum of two gauss
59 return norm(x, a, mu, sigma) + norm(x, b, mu2, sigma2)
60
61
62def norm_plus_lin(x, a, mu, sigma, b, c):
63 # A gauss plus a linear function
64 return norm(x, a, mu, sigma) + b * x + c
65
66
67def inverse_squared(x, a, b, c, d):
68 # A 1/x^2 function
69 return a / (x - b) ** 2 + c + d * x
70
71
72def inverse_sqrt(x, a, b, c, d):
73 return a / (np.sqrt(x - b)) + c + d * x