Belle II Software development
riemannFitToy.py
1
8
9import logging
10from tracking.validation.utilities import prob
11from ROOT import Belle2 # make Belle2 namespace available
12from ROOT import gSystem
13import matplotlib.pyplot as plt
14import numpy as np
15import numpy.random
16
17import matplotlib as mpl
18mpl.use('Agg')
19
20
21gSystem.Load('libframework')
22gSystem.Load('libtracking')
23gSystem.Load('libtracking_trackFindingCDC')
24
25
26def get_logger():
27 return logging.getLogger(__name__)
28
29
30n_toys = 10000
31
32radius = 1
33center_x = 1
34center_y = 1
35center_phi = np.arctan2(center_y, center_x)
36
37n_points = 50
38
39# Position variance
40pos_var = 0.0001
41
42# Reconstruction variance
43pos_var = 0.0001
44
45chi2s = []
46curvature_estimates = []
47curvature_variances = []
48
49
50def main():
51 for i_toy in range(n_toys):
52 chi_random = False
53 if chi_random:
54 chis = np.random.uniform(0, np.pi, n_points)
55 else:
56 # equally spaced points
57 chis = np.linspace(0, np.pi, n_points)
58
59 ls = np.random.normal(0, 10 * np.sqrt(pos_var), n_points)
60 dls = np.random.normal(0, np.sqrt(pos_var), n_points)
61
62 xs = (radius + ls + dls) * np.cos(chis + center_phi - np.pi) + center_x
63 ys = (radius + ls + dls) * np.sin(chis + center_phi - np.pi) + center_y
64
66
67 for x, y, l in zip(xs, ys, ls):
68 weight = 1 / pos_var
69 observations.fill(x, y, l, weight)
70
72 trajectory = fitter.fit(observations)
73
74 circle = trajectory.getGlobalCircle()
75 if circle.curvature() < 0:
76 circle.reverse()
77
78 curvature_estimates.append(circle.curvature())
79 curvature_variances.append(trajectory.getLocalVariance(0))
80 chi2s.append(trajectory.getChi2())
81
82 circle_points = [circle.atArcLength(chi * radius) for chi in np.linspace(0, np.pi, 50)]
83 circle_xs = [p.x() for p in circle_points]
84 circle_ys = [p.y() for p in circle_points]
85
86 continue
87 plt.plot(circle_xs, circle_ys)
88 plt.scatter(xs, ys)
89
90 plt.show()
91
92 curvature_residuals = np.array(curvature_estimates) - 1 / radius
93
94 plt.hist(curvature_residuals, bins=100)
95 plt.title("Curvature residual")
96 plt.show()
97
98 plt.hist(curvature_residuals / np.sqrt(curvature_variances), bins=100, normed=True)
99
100 normal_xs = np.linspace(-4, 4, 50)
101 normal_ys = np.exp(-normal_xs * normal_xs / 2) / np.sqrt(2 * np.pi)
102 plt.plot(normal_xs, normal_ys)
103 plt.title("Curvature pull")
104 plt.show()
105
106 plt.hist(chi2s, bins=100)
107 plt.show()
108
109 ndfs = n_points - 3
110 p_values = prob(chi2s, ndfs)
111 plt.hist(p_values, bins=100, normed=True)
112 plt.plot([0, 1], [1, 1])
113 plt.show()
114
115
116if __name__ == "__main__":
117 main()
Class serving as a storage of observed drift circles to present to the Riemann fitter.
static const CDCRiemannFitter & getFitter()
Static getter for a general Riemann fitter.
Definition: main.py:1