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
30CONTACT = "oliver.frost@desy.de"
31
32n_toys = 10000
33
34radius = 1
35center_x = 1
36center_y = 1
37center_phi = np.arctan2(center_y, center_x)
38
39n_points = 50
40
41# Position variance
42pos_var = 0.0001
43
44# Reconstruction variance
45pos_var = 0.0001
46
47chi2s = []
48curvature_estimates = []
49curvature_variances = []
50
51
52def main():
53 for i_toy in range(n_toys):
54 chi_random = False
55 if chi_random:
56 chis = np.random.uniform(0, np.pi, n_points)
57 else:
58 # equally spaced points
59 chis = np.linspace(0, np.pi, n_points)
60
61 ls = np.random.normal(0, 10 * np.sqrt(pos_var), n_points)
62 dls = np.random.normal(0, np.sqrt(pos_var), n_points)
63
64 xs = (radius + ls + dls) * np.cos(chis + center_phi - np.pi) + center_x
65 ys = (radius + ls + dls) * np.sin(chis + center_phi - np.pi) + center_y
66
68
69 for x, y, l in zip(xs, ys, ls):
70 weight = 1 / pos_var
71 observations.fill(x, y, l, weight)
72
74 trajectory = fitter.fit(observations)
75
76 circle = trajectory.getGlobalCircle()
77 if circle.curvature() < 0:
78 circle.reverse()
79
80 curvature_estimates.append(circle.curvature())
81 curvature_variances.append(trajectory.getLocalVariance(0))
82 chi2s.append(trajectory.getChi2())
83
84 circle_points = [circle.atArcLength(chi * radius) for chi in np.linspace(0, np.pi, 50)]
85 circle_xs = [p.x() for p in circle_points]
86 circle_ys = [p.y() for p in circle_points]
87
88 continue
89 plt.plot(circle_xs, circle_ys)
90 plt.scatter(xs, ys)
91
92 plt.show()
93
94 curvature_residuals = np.array(curvature_estimates) - 1 / radius
95
96 plt.hist(curvature_residuals, bins=100)
97 plt.title("Curvature residual")
98 plt.show()
99
100 plt.hist(curvature_residuals / np.sqrt(curvature_variances), bins=100, normed=True)
101
102 normal_xs = np.linspace(-4, 4, 50)
103 normal_ys = np.exp(-normal_xs * normal_xs / 2) / np.sqrt(2 * np.pi)
104 plt.plot(normal_xs, normal_ys)
105 plt.title("Curvature pull")
106 plt.show()
107
108 plt.hist(chi2s, bins=100)
109 plt.show()
110
111 ndfs = n_points - 3
112 p_values = prob(chi2s, ndfs)
113 plt.hist(p_values, bins=100, normed=True)
114 plt.plot([0, 1], [1, 1])
115 plt.show()
116
117
118if __name__ == "__main__":
119 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