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