11 #include <framework/dataobjects/UncertainHelix.h>
13 #include <boost/range/irange.hpp>
14 #include <framework/utilities/TestHelpers.h>
15 #include <gtest/gtest.h>
24 TEST(UncertainHelixTest, CartesianCovarianceRoundtripWithPerigeeOnOrigin)
26 TVector3 expectedMomentum(1.0, 0.0, 0.0);
27 TVector3 expectedPosition(0.0, 0.0, 0.0);
28 const double expectedCharge = -1;
30 const double pValue = 0.5;
32 TMatrixDSym expectedCov6(6);
34 expectedCov6(0, 0) = 0;
35 expectedCov6(1, 1) = 2;
36 expectedCov6(2, 2) = 3;
37 expectedCov6(3, 3) = 4;
38 expectedCov6(4, 4) = 5;
39 expectedCov6(5, 5) = 6;
48 const TVector3 position = uncertainHelix.getPerigee();
49 const TVector3 momentum = uncertainHelix.getMomentum(bZ);
50 const double charge = uncertainHelix.getChargeSign();
51 const TMatrixDSym cov6 = uncertainHelix.getCartesianCovariance(bZ);
53 EXPECT_NEAR(expectedPosition.X(), position.X(), 1e-7);
54 EXPECT_NEAR(expectedPosition.Y(), position.Y(), 1e-7);
55 EXPECT_NEAR(expectedPosition.Z(), position.Z(), 1e-7);
57 EXPECT_NEAR(expectedMomentum.X(), momentum.X(), 1e-7);
58 EXPECT_NEAR(expectedMomentum.Y(), momentum.Y(), 1e-7);
59 EXPECT_NEAR(expectedMomentum.Z(), momentum.Z(), 1e-7);
61 EXPECT_EQ(expectedCharge, charge);
63 for (
int i : irange(0, 6)) {
64 for (
int j : irange(0, 6)) {
65 EXPECT_NEAR(expectedCov6(i, j), cov6(i, j), 1e-7);
71 TEST(UncertainHelixTest, CartesianCovarianceRoundtripAtPerigeeBesidesOrigin)
73 TVector3 expectedMomentum(1.0, 0.0, 0.0);
74 TVector3 expectedPosition(0.0, 1.0, 0.0);
75 const double expectedCharge = -1;
77 const double pValue = 0.5;
79 TMatrixDSym expectedCov6(6);
81 expectedCov6(0, 0) = 0;
82 for (
int i : irange(1, 6)) {
83 for (
int j : irange(1, 6)) {
85 expectedCov6(i, j) = 1;
89 expectedCov6(1, 1) = 2;
90 expectedCov6(2, 2) = 3;
91 expectedCov6(3, 3) = 4;
92 expectedCov6(4, 4) = 5;
93 expectedCov6(5, 5) = 6;
102 const TVector3 position = uncertainHelix.getPerigee();
103 const TVector3 momentum = uncertainHelix.getMomentum(bZ);
104 const double charge = uncertainHelix.getChargeSign();
105 const TMatrixDSym cov6 = uncertainHelix.getCartesianCovariance(bZ);
107 EXPECT_NEAR(expectedPosition.X(), position.X(), 1e-7);
108 EXPECT_NEAR(expectedPosition.Y(), position.Y(), 1e-7);
109 EXPECT_NEAR(expectedPosition.Z(), position.Z(), 1e-7);
111 EXPECT_NEAR(expectedMomentum.X(), momentum.X(), 1e-7);
112 EXPECT_NEAR(expectedMomentum.Y(), momentum.Y(), 1e-7);
113 EXPECT_NEAR(expectedMomentum.Z(), momentum.Z(), 1e-7);
115 EXPECT_EQ(expectedCharge, charge);
118 TVectorD nullSpace(6);
119 const double factor =
120 (expectedPosition.X() * expectedMomentum.Y() - expectedPosition.Y() * expectedMomentum.X()) / expectedMomentum.Perp2();
121 nullSpace[0] = expectedMomentum.X();
122 nullSpace[1] = expectedMomentum.Y();
124 nullSpace[3] = factor * expectedMomentum.Y();
125 nullSpace[4] = - factor * expectedMomentum.X();
128 TVectorD nullVector = cov6 * nullSpace;
129 for (
int j : irange(0, 6)) {
130 EXPECT_NEAR(0, nullVector(j), 1e-7);
142 const TMatrixDSym cov6_2 = uncertainHelix2.getCartesianCovariance(bZ);
143 for (
int i : irange(0, 6)) {
144 for (
int j : irange(0, 6)) {
145 EXPECT_NEAR(cov6(i, j), cov6_2(i, j), 1e-7);
150 TEST(UncertainHelixTest, CartesianCovarianceRoundtripAtPerigeeBesidesOriginIndividualCoordinates)
152 TVector3 expectedMomentum(1.0, 0.0, 0.0);
153 TVector3 expectedPosition(0.0, 1.0, 0.0);
154 const double expectedCharge = -1;
156 const double pValue = 0.5;
158 for (
int i : irange(1, 6)) {
160 TMatrixDSym expectedCov6(6);
162 expectedCov6(0, 0) = 0;
164 expectedCov6(i, i) = 1;
173 const TVector3 position = uncertainHelix.getPerigee();
174 const TVector3 momentum = uncertainHelix.getMomentum(bZ);
175 const double charge = uncertainHelix.getChargeSign();
176 const TMatrixDSym cov6 = uncertainHelix.getCartesianCovariance(bZ);
178 EXPECT_NEAR(expectedPosition.X(), position.X(), 1e-7);
179 EXPECT_NEAR(expectedPosition.Y(), position.Y(), 1e-7);
180 EXPECT_NEAR(expectedPosition.Z(), position.Z(), 1e-7);
182 EXPECT_NEAR(expectedMomentum.X(), momentum.X(), 1e-7);
183 EXPECT_NEAR(expectedMomentum.Y(), momentum.Y(), 1e-7);
184 EXPECT_NEAR(expectedMomentum.Z(), momentum.Z(), 1e-7);
186 EXPECT_EQ(expectedCharge, charge);
189 TVectorD nullSpace(6);
190 const double factor =
191 (expectedPosition.X() * expectedMomentum.Y() - expectedPosition.Y() * expectedMomentum.X()) / expectedMomentum.Perp2();
192 nullSpace[0] = expectedMomentum.X();
193 nullSpace[1] = expectedMomentum.Y();
195 nullSpace[3] = factor * expectedMomentum.Y();
196 nullSpace[4] = - factor * expectedMomentum.X();
199 TVectorD nullVector = cov6 * nullSpace;
200 for (
int j : irange(0, 6)) {
201 EXPECT_NEAR(0, nullVector(j), 1e-7);
213 const TMatrixDSym cov6_2 = uncertainHelix2.getCartesianCovariance(bZ);
214 for (
int j : irange(0, 6)) {
215 for (
int k : irange(0, 6)) {
216 EXPECT_NEAR(cov6(j, k), cov6_2(j, k), 1e-7);
222 TEST(UncertainHelixTest, PerigeeCovarianceRoundtripAtPerigeeBesidesOriginIndividualCoordinates)
226 double omega = -0.005;
227 double tanLambda = 1;
231 const double pValue = 0.5;
233 for (
int i : irange(0, 5)) {
235 TMatrixDSym expectedCov5(5);
237 expectedCov5(i, i) = 1;
239 UncertainHelix uncertainHelix(d0, phi0, omega, z0, tanLambda, expectedCov5, pValue);
241 const TVector3 position = uncertainHelix.getPerigee();
242 const TVector3 momentum = uncertainHelix.getMomentum(bZ);
243 const double charge = uncertainHelix.getChargeSign();
244 const TMatrixDSym cov6 = uncertainHelix.getCartesianCovariance(bZ);
253 EXPECT_NEAR(d0, uncertainHelix2.getD0(), 1e-7);
254 EXPECT_NEAR(phi0, uncertainHelix2.getPhi0(), 1e-7);
255 EXPECT_NEAR(omega, uncertainHelix2.getOmega(), 1e-7);
257 EXPECT_NEAR(z0, uncertainHelix2.getZ0(), 1e-7);
258 EXPECT_NEAR(tanLambda, uncertainHelix2.getTanLambda(), 1e-7);
260 const TMatrixDSym& cov5 = uncertainHelix2.getCovariance();
261 EXPECT_EQ(-1, charge);
263 for (
int j : irange(0, 5)) {
264 for (
int k : irange(0, 5)) {
265 EXPECT_NEAR(expectedCov5(j, k), cov5(j, k), 1e-7);
271 TEST(UncertainHelixTest, RealPerigeeCovarianceRoundTrip)
273 const double bZ = 1.5;
274 const double pValue = 0.5;
276 std::vector<float> helixParams(5);
277 std::vector<float> helixCovariance(15);
279 helixParams[0] = 3.82384;
280 helixParams[1] = std::remainder(3.57559, 2 * M_PI);
281 helixParams[2] = 0.00530726;
282 helixParams[3] = -0.000317335;
283 helixParams[4] = 1.34536;
285 helixCovariance[0] = 0.000648818;
286 helixCovariance[1] = 6.357e-05;
287 helixCovariance[2] = 2.04344e-07;
288 helixCovariance[3] = -0.00101879;
289 helixCovariance[4] = 2.29407e-05;
291 helixCovariance[5] = 1.02934e-05;
292 helixCovariance[6] = 1.39609e-08;
293 helixCovariance[7] = 9.57685e-07;
294 helixCovariance[8] = 1.19863e-06;
296 helixCovariance[9] = 4.96093e-10;
297 helixCovariance[10] = -8.41612e-07;
298 helixCovariance[11] = 6.50684e-08;
300 helixCovariance[12] = 0.0317385;
301 helixCovariance[13] = -0.00065476;
303 helixCovariance[14] = 3.6521e-05;
305 TMatrixDSym expectedCov5(5);
306 unsigned int counter = 0;
307 for (
unsigned int i = 0; i < 5; ++i) {
308 for (
unsigned int j = i; j < 5; ++j) {
309 expectedCov5(i, j) = expectedCov5(j, i) = helixCovariance[counter];
322 const TVector3 position = uncertainHelix.getPerigee();
323 const TVector3 momentum = uncertainHelix.getMomentum(bZ);
324 const double charge = uncertainHelix.getChargeSign();
325 const TMatrixDSym cov6 = uncertainHelix.getCartesianCovariance(bZ);
334 EXPECT_NEAR(helixParams[0], uncertainHelix2.getD0(), 1e-7);
335 EXPECT_NEAR(helixParams[1], uncertainHelix2.getPhi0(), 1e-7);
336 EXPECT_NEAR(helixParams[2], uncertainHelix2.getOmega(), 1e-7);
338 EXPECT_NEAR(helixParams[3], uncertainHelix2.getZ0(), 1e-7);
339 EXPECT_NEAR(helixParams[4], uncertainHelix2.getTanLambda(), 1e-7);
341 const TMatrixDSym& cov5 = uncertainHelix2.getCovariance();
342 EXPECT_EQ(1, charge);
344 for (
int i : boost::irange(0, 5)) {
345 for (
int j : boost::irange(0, 5)) {
346 EXPECT_NEAR(expectedCov5(i, j), cov5(i, j), 1e-7);
352 TEST(UncertainHelixTest, Explicit_D0)
356 double omega = -0.005;
357 double tanLambda = 1;
361 const double pValue = 0.5;
363 TMatrixDSym expectedCov5(5);
365 expectedCov5(0, 0) = 1;
367 TMatrixDSym expectedCov6(6);
369 expectedCov6(1, 1) = 1;
371 UncertainHelix uncertainHelix(d0, phi0, omega, z0, tanLambda, expectedCov5, pValue);
373 const TMatrixDSym cov6 = uncertainHelix.getCartesianCovariance(bZ);
375 for (
int i : irange(0, 6)) {
376 for (
int j : irange(0, 6)) {
377 TEST_CONTEXT(
"Failed for index (" << i <<
", " << j <<
")");
378 EXPECT_NEAR(expectedCov6(i, j), cov6(i, j), 1e-7);
383 TEST(UncertainHelixTest, Explicit_Phi0)
387 double omega = -0.006;
388 double tanLambda = 0;
391 const double bZ = 1.5;
392 const double pValue = 0.5;
394 TMatrixDSym expectedCov5(5);
396 expectedCov5(1, 1) = 1;
398 UncertainHelix uncertainHelix(d0, phi0, omega, z0, tanLambda, expectedCov5, pValue);
400 const TVector3 position = uncertainHelix.getPerigee();
401 const TVector3 momentum = uncertainHelix.getMomentum(bZ);
402 const double charge = uncertainHelix.getChargeSign();
403 const TMatrixDSym cov6 = uncertainHelix.getCartesianCovariance(bZ);
405 double absMom2D = uncertainHelix.getTransverseMomentum(1.5);
407 TMatrixDSym expectedCov6(6);
409 expectedCov6(4, 4) = absMom2D * absMom2D;
411 for (
int i : irange(0, 6)) {
412 for (
int j : irange(0, 6)) {
413 TEST_CONTEXT(
"Failed for index (" << i <<
", " << j <<
")");
414 EXPECT_NEAR(expectedCov6(i, j), cov6(i, j), 1e-7);
425 EXPECT_NEAR(d0, uncertainHelix2.getD0(), 1e-7);
426 EXPECT_NEAR(phi0, uncertainHelix2.getPhi0(), 1e-7);
427 EXPECT_NEAR(omega, uncertainHelix2.getOmega(), 1e-7);
429 EXPECT_NEAR(z0, uncertainHelix2.getZ0(), 1e-7);
430 EXPECT_NEAR(tanLambda, uncertainHelix2.getTanLambda(), 1e-7);
432 const TMatrixDSym& cov5 = uncertainHelix2.getCovariance();
433 EXPECT_EQ(-1, charge);
435 for (
int i : irange(0, 5)) {
436 for (
int j : irange(0, 5)) {
437 TEST_CONTEXT(
"Failed for index (" << i <<
", " << j <<
")");
438 EXPECT_NEAR(expectedCov5(i, j), cov5(i, j), 1e-7);
443 TEST(UncertainHelixTest, MoveInCartesianVersusMoveInPerigeeCoordinates)
446 TVector3 moveBy(0.5, -1, 0.5);
450 double omega = -0.005;
451 double tanLambda = 1;
455 const double pValue = 0.5;
457 TMatrixDSym initialCov5(5);
459 for (
int i : irange(0, 5)) {
460 for (
int j : irange(0, 5)) {
461 initialCov5(i, j) = i + j;
465 UncertainHelix uncertainHelix(d0, phi0, omega, z0, tanLambda, initialCov5, pValue);
467 const TVector3 position = uncertainHelix.getPerigee();
468 const TVector3 momentum = uncertainHelix.getMomentum(bZ);
469 const double charge = uncertainHelix.getChargeSign();
470 const TMatrixDSym cov6 = uncertainHelix.getCartesianCovariance(bZ);
473 const TVector3 movedPosition = position - moveBy;
481 const TMatrixDSym& cov5 = movedUncertainHelix.getCovariance();
486 const TMatrixDSym expectedCov5 = expectedMovedUncertainHelix.
getCovariance();
489 EXPECT_NEAR(expectedMovedUncertainHelix.getD0(), movedUncertainHelix.getD0(), 1e-7);
490 EXPECT_NEAR(expectedMovedUncertainHelix.getPhi0(), movedUncertainHelix.getPhi0(), 1e-7);
491 EXPECT_NEAR(expectedMovedUncertainHelix.getOmega(), movedUncertainHelix.getOmega(), 1e-7);
492 EXPECT_NEAR(expectedMovedUncertainHelix.getZ0(), movedUncertainHelix.getZ0(), 1e-7);
493 EXPECT_NEAR(expectedMovedUncertainHelix.getTanLambda(), movedUncertainHelix.getTanLambda(), 1e-7);
495 for (
int i : irange(0, 5)) {
496 for (
int j : irange(0, 5)) {
497 TEST_CONTEXT(
"Failed for index (" << i <<
", " << j <<
")");
498 EXPECT_NEAR(expectedCov5(i, j), cov5(i, j), 1e-7);