Belle II Software development
UncertainPerigeeCircle.test.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <tracking/trackFindingCDC/geometry/UncertainPerigeeCircle.h>
10#include <tracking/trackFindingCDC/geometry/Vector2D.h>
11
12#include <gtest/gtest.h>
13
14
15using namespace Belle2;
16using namespace TrackFindingCDC;
17
18TEST(TrackFindingCDCTest, geometry_PerigeeCircle_passiveMoveByJacobian_identity)
19{
20 for (double curvature : { -1.0, 0.0, 1.0}) {
21 PerigeeCircle circle(curvature, -M_PI / 2, 0.5);
22
23 PerigeeJacobian moveByZeroJacobian = circle.passiveMoveByJacobian(Vector2D(0.0, 0.0));
24 EXPECT_NEAR(1.0, moveByZeroJacobian(0, 0), 10e-7);
25 EXPECT_NEAR(0.0, moveByZeroJacobian(0, 1), 10e-7);
26 EXPECT_NEAR(0.0, moveByZeroJacobian(0, 2), 10e-7);
27
28 EXPECT_NEAR(0.0, moveByZeroJacobian(1, 0), 10e-7);
29 EXPECT_NEAR(1.0, moveByZeroJacobian(1, 1), 10e-7);
30 EXPECT_NEAR(0.0, moveByZeroJacobian(1, 2), 10e-7);
31
32 EXPECT_NEAR(0.0, moveByZeroJacobian(2, 0), 10e-7);
33 EXPECT_NEAR(0.0, moveByZeroJacobian(2, 1), 10e-7);
34 EXPECT_NEAR(1.0, moveByZeroJacobian(2, 2), 10e-7);
35 }
36}
37
38TEST(TrackFindingCDCTest, geometry_PerigeeCircle_passiveMoveByJacobian_roundtrip)
39{
40 for (double curvature : { -1.0, 0.0, 1.0}) {
41 PerigeeCircle circle(curvature, -M_PI / 2, 0.5);
42 Vector2D by(0.1, 1.0);
43
44 PerigeeJacobian moveByOneJacobian = circle.passiveMoveByJacobian(by);
45
46 circle.passiveMoveBy(by);
47
48 PerigeeJacobian moveOneBackJacobian = circle.passiveMoveByJacobian(-by);
49 {
50 PerigeeJacobian moveByZeroJacobian = moveByOneJacobian * moveOneBackJacobian;
51
52 EXPECT_NEAR(1.0, moveByZeroJacobian(0, 0), 10e-7);
53 EXPECT_NEAR(0.0, moveByZeroJacobian(0, 1), 10e-7);
54 EXPECT_NEAR(0.0, moveByZeroJacobian(0, 2), 10e-7);
55
56 EXPECT_NEAR(0.0, moveByZeroJacobian(1, 0), 10e-7);
57 EXPECT_NEAR(1.0, moveByZeroJacobian(1, 1), 10e-7);
58 EXPECT_NEAR(0.0, moveByZeroJacobian(1, 2), 10e-7);
59
60 EXPECT_NEAR(0.0, moveByZeroJacobian(2, 0), 10e-7);
61 EXPECT_NEAR(0.0, moveByZeroJacobian(2, 1), 10e-7);
62 EXPECT_NEAR(1.0, moveByZeroJacobian(2, 2), 10e-7);
63 }
64 {
65 PerigeeJacobian moveByZeroJacobian = moveOneBackJacobian * moveByOneJacobian;
66
67 EXPECT_NEAR(1.0, moveByZeroJacobian(0, 0), 10e-7);
68 EXPECT_NEAR(0.0, moveByZeroJacobian(0, 1), 10e-7);
69 EXPECT_NEAR(0.0, moveByZeroJacobian(0, 2), 10e-7);
70
71 EXPECT_NEAR(0.0, moveByZeroJacobian(1, 0), 10e-7);
72 EXPECT_NEAR(1.0, moveByZeroJacobian(1, 1), 10e-7);
73 EXPECT_NEAR(0.0, moveByZeroJacobian(1, 2), 10e-7);
74
75 EXPECT_NEAR(0.0, moveByZeroJacobian(2, 0), 10e-7);
76 EXPECT_NEAR(0.0, moveByZeroJacobian(2, 1), 10e-7);
77 EXPECT_NEAR(1.0, moveByZeroJacobian(2, 2), 10e-7);
78 }
79 }
80}
81
82TEST(TrackFindingCDCTest, geometry_PerigeeCircle_passiveMoveByJacobian)
83{
84 PerigeeCircle circle(1.0, -M_PI / 2, 0);
85
86 PerigeeJacobian moveByOneJacobian = circle.passiveMoveByJacobian(Vector2D(-1.0, 0.0));
87 EXPECT_NEAR(1.0, moveByOneJacobian(0, 0), 10e-7);
88 EXPECT_NEAR(0.0, moveByOneJacobian(0, 1), 10e-7);
89 EXPECT_NEAR(0.0, moveByOneJacobian(0, 2), 10e-7);
90
91 EXPECT_NEAR(0.0, moveByOneJacobian(1, 0), 10e-7);
92 EXPECT_NEAR(1.0 / 2.0, moveByOneJacobian(1, 1), 10e-7);
93 EXPECT_NEAR(0.0, moveByOneJacobian(1, 2), 10e-7);
94
95 EXPECT_NEAR(0.0, moveByOneJacobian(2, 0), 10e-7);
96 EXPECT_NEAR(0.0, moveByOneJacobian(2, 1), 10e-7);
97 EXPECT_NEAR(1.0, moveByOneJacobian(2, 2), 10e-7);
98
99 PerigeeJacobian moveByTwoYJacobian = circle.passiveMoveByJacobian(Vector2D(0.0, -2.0));
100
101 // Hand caluclated intermediate quantities;
102 double deltaParallel = 2;
103 double A = 4;
104 double u = 1;
105
106 double nu = 1;
107 // double xi = 1.0 / 5.0;
108 double lambda = 1.0 / (5.0 + 3.0 * sqrt(5.0));
109 double mu = sqrt(5.0) / 10.0;
110 double zeta = 4;
111
112 EXPECT_NEAR(1.0, moveByTwoYJacobian(0, 0), 10e-7);
113 EXPECT_NEAR(0.0, moveByTwoYJacobian(0, 1), 10e-7);
114 EXPECT_NEAR(0.0, moveByTwoYJacobian(0, 2), 10e-7);
115
116 EXPECT_NEAR(2.0 / 5.0, moveByTwoYJacobian(1, 0), 10e-7);
117 EXPECT_NEAR(1.0 / 5.0, moveByTwoYJacobian(1, 1), 10e-7);
118 EXPECT_NEAR(-2.0 / 5.0, moveByTwoYJacobian(1, 2), 10e-7);
119
120 EXPECT_NEAR(mu * zeta - A * lambda, moveByTwoYJacobian(2, 0), 10e-7);
121 EXPECT_NEAR(2.0 * mu * u * deltaParallel, moveByTwoYJacobian(2, 1), 10e-7);
122 EXPECT_NEAR(2.0 * mu * nu, moveByTwoYJacobian(2, 2), 10e-7);
123}
124
125TEST(TrackFindingCDCTest, geometry_PerigeeCircle_passiveMovedCovarianceBy)
126{
127 PerigeeCovariance perigeeVariance;
128 perigeeVariance(0, 0) = 1.0;
129 perigeeVariance(0, 1) = 0.0;
130 perigeeVariance(0, 2) = 0.0;
131
132 perigeeVariance(1, 0) = 0.0;
133 perigeeVariance(1, 1) = 0.0;
134 perigeeVariance(1, 2) = 0.0;
135
136 perigeeVariance(2, 0) = 0.0;
137 perigeeVariance(2, 1) = 0.0;
138 perigeeVariance(2, 2) = 0.0;
139
140 UncertainPerigeeCircle circle(1.0, -M_PI / 2, 0.0, PerigeeCovariance(perigeeVariance));
141
142 {
143 PerigeeCovariance noMoveVariance = circle.passiveMovedCovarianceBy(Vector2D(0.0, 0.0));
144
145 EXPECT_NEAR(1.0, noMoveVariance(0, 0), 10e-7);
146 EXPECT_NEAR(0.0, noMoveVariance(0, 1), 10e-7);
147 EXPECT_NEAR(0.0, noMoveVariance(0, 2), 10e-7);
148
149 EXPECT_NEAR(0.0, noMoveVariance(1, 0), 10e-7);
150 EXPECT_NEAR(0.0, noMoveVariance(1, 1), 10e-7);
151 EXPECT_NEAR(0.0, noMoveVariance(1, 2), 10e-7);
152
153 EXPECT_NEAR(0.0, noMoveVariance(2, 0), 10e-7);
154 EXPECT_NEAR(0.0, noMoveVariance(2, 1), 10e-7);
155 EXPECT_NEAR(0.0, noMoveVariance(2, 2), 10e-7);
156 }
157
158 {
159 PerigeeCovariance noChangeMoveVariance = circle.passiveMovedCovarianceBy(Vector2D(-1.0, 0.0));
160
161 EXPECT_NEAR(1.0, noChangeMoveVariance(0, 0), 10e-7);
162 EXPECT_NEAR(0.0, noChangeMoveVariance(0, 1), 10e-7);
163 EXPECT_NEAR(0.0, noChangeMoveVariance(0, 2), 10e-7);
164
165 EXPECT_NEAR(0.0, noChangeMoveVariance(1, 0), 10e-7);
166 EXPECT_NEAR(0.0, noChangeMoveVariance(1, 1), 10e-7);
167 EXPECT_NEAR(0.0, noChangeMoveVariance(1, 2), 10e-7);
168
169 EXPECT_NEAR(0.0, noChangeMoveVariance(2, 0), 10e-7);
170 EXPECT_NEAR(0.0, noChangeMoveVariance(2, 1), 10e-7);
171 EXPECT_NEAR(0.0, noChangeMoveVariance(2, 2), 10e-7);
172 }
173
174 {
175 PerigeeCovariance transformedVariance = circle.passiveMovedCovarianceBy(Vector2D(2.0, 0.0));
176
177 EXPECT_NEAR(1.0, transformedVariance(0, 0), 10e-7);
178
179 EXPECT_NEAR(2.0, transformedVariance(2, 0), 10e-7);
180 EXPECT_NEAR(2.0, transformedVariance(0, 2), 10e-7);
181 EXPECT_NEAR(4.0, transformedVariance(2, 2), 10e-7);
182
183 // Variances in phi should vanish
184 EXPECT_NEAR(0.0, transformedVariance(1, 1), 10e-7);
185
186 EXPECT_NEAR(0.0, transformedVariance(0, 1), 10e-7);
187 EXPECT_NEAR(0.0, transformedVariance(1, 0), 10e-7);
188
189 EXPECT_NEAR(0.0, transformedVariance(1, 2), 10e-7);
190 EXPECT_NEAR(0.0, transformedVariance(2, 1), 10e-7);
191 }
192
193 {
194 // Should be same as before
195 PerigeeCovariance transformedVariance = circle.passiveMovedCovarianceBy(Vector2D(2.5, 0.0));
196
197 EXPECT_NEAR(1, transformedVariance(0, 0), 10e-7);
198
199 EXPECT_NEAR(2, transformedVariance(2, 0), 10e-7);
200 EXPECT_NEAR(2, transformedVariance(0, 2), 10e-7);
201 EXPECT_NEAR(4, transformedVariance(2, 2), 10e-7);
202
203 // Variances in phi should vanish
204 EXPECT_NEAR(0, transformedVariance(1, 1), 10e-7);
205
206 EXPECT_NEAR(0, transformedVariance(0, 1), 10e-7);
207 EXPECT_NEAR(0, transformedVariance(1, 0), 10e-7);
208
209 EXPECT_NEAR(0, transformedVariance(1, 2), 10e-7);
210 EXPECT_NEAR(0, transformedVariance(2, 1), 10e-7);
211 }
212}
213
214TEST(TrackFindingCDCTest, geometry_PerigeeCircle_passiveMove)
215{
216
217 PerigeeCovariance perigeeVariance;
218 perigeeVariance(0, 0) = 1.0;
219 perigeeVariance(0, 1) = 0.3;
220 perigeeVariance(0, 2) = 0.5;
221
222 perigeeVariance(1, 0) = 0.3;
223 perigeeVariance(1, 1) = 0.7;
224 perigeeVariance(1, 2) = 0.6;
225
226 perigeeVariance(2, 0) = 0.5;
227 perigeeVariance(2, 1) = 0.6;
228 perigeeVariance(2, 2) = 1;
229
230 UncertainPerigeeCircle circle(1.0, -M_PI / 4, 1.0, PerigeeCovariance(perigeeVariance));
231
232 // circle.perigeeCovariance().Print();
233
234 // Test if the move commutes
235 circle.passiveMoveBy(Vector2D(0.0, -1.0));
236
237 // circle.perigeeCovariance().Print();
238
239 circle.passiveMoveBy(Vector2D(0.0, 1.0));
240
241 // circle.perigeeCovariance().Print();
242
243 PerigeeCovariance twiceMovedVariance = circle.perigeeCovariance();
244
245 EXPECT_NEAR(perigeeVariance(0, 0), twiceMovedVariance(0, 0), 10e-7);
246 EXPECT_NEAR(perigeeVariance(0, 1), twiceMovedVariance(0, 1), 10e-7);
247 EXPECT_NEAR(perigeeVariance(0, 2), twiceMovedVariance(0, 2), 10e-7);
248
249 EXPECT_NEAR(perigeeVariance(1, 0), twiceMovedVariance(1, 0), 10e-7);
250 EXPECT_NEAR(perigeeVariance(1, 1), twiceMovedVariance(1, 1), 10e-7);
251 EXPECT_NEAR(perigeeVariance(1, 2), twiceMovedVariance(1, 2), 10e-7);
252
253 EXPECT_NEAR(perigeeVariance(2, 0), twiceMovedVariance(2, 0), 10e-7);
254 EXPECT_NEAR(perigeeVariance(2, 1), twiceMovedVariance(2, 1), 10e-7);
255 EXPECT_NEAR(perigeeVariance(2, 2), twiceMovedVariance(2, 2), 10e-7);
256}
Extension of the generalized circle also caching the perigee coordinates.
Definition: PerigeeCircle.h:36
A matrix implementation to be used as an interface typ through out the track finder.
Definition: PlainMatrix.h:40
Adds an uncertainty matrix to the circle in perigee parameterisation.
A two dimensional vector which is equipped with functions for correct handeling of orientation relat...
Definition: Vector2D.h:32
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
Abstract base class for different kinds of events.