ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CovarianceEngineTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CovarianceEngineTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #include <boost/test/unit_test.hpp>
10 
13 
14 namespace tt = boost::test_tools;
15 
16 namespace Acts {
17 namespace Test {
18 
20 using Jacobian = BoundMatrix;
21 
25 BOOST_AUTO_TEST_CASE(covariance_engine_test) {
26  // Create a test context
28 
29  // Build a start vector
30  Vector3D position{1., 2., 3.};
31  double time = 4.;
32  Vector3D direction{sqrt(5. / 22.), 3. * sqrt(2. / 55.), 7. / sqrt(110.)};
33  double qop = 0.125;
34  FreeVector parameters, startParameters;
35  parameters << position[0], position[1], position[2], time, direction[0],
36  direction[1], direction[2], qop;
37  startParameters = parameters;
38 
39  // Build covariance matrix, jacobians and related components
40  Covariance covariance = Covariance::Identity();
41  Jacobian jacobian = 2. * Jacobian::Identity();
42  FreeMatrix transportJacobian = 3. * FreeMatrix::Identity();
43  FreeVector derivatives;
44  derivatives << 9., 10., 11., 12., 13., 14., 15., 16.;
45  BoundToFreeMatrix jacobianLocalToGlobal = 4. * BoundToFreeMatrix::Identity();
46 
47  // Covariance transport to curvilinear coordinates
48  detail::covarianceTransport(covariance, jacobian, transportJacobian,
49  derivatives, jacobianLocalToGlobal, direction);
50 
51  // Tests to see that the right components are (un-)changed
52  BOOST_TEST(covariance != Covariance::Identity());
53  BOOST_TEST(jacobian != 2. * Jacobian::Identity());
54  BOOST_TEST(transportJacobian == FreeMatrix::Identity());
55  BOOST_TEST(derivatives == FreeVector::Zero());
56  BOOST_TEST(jacobianLocalToGlobal != 4. * BoundToFreeMatrix::Identity());
57  BOOST_TEST(direction ==
58  Vector3D(sqrt(5. / 22.), 3. * sqrt(2. / 55.), 7. / sqrt(110.)));
59 
60  // Reset
61  covariance = Covariance::Identity();
62  jacobian = 2. * Jacobian::Identity();
63  transportJacobian = 3. * FreeMatrix::Identity();
64  derivatives << 9., 10., 11., 12., 13., 14., 15., 16.;
65  jacobianLocalToGlobal = 4. * BoundToFreeMatrix::Identity();
66 
67  // Repeat transport to surface
68  auto surface = Surface::makeShared<PlaneSurface>(position, direction);
69  detail::covarianceTransport(tgContext, covariance, jacobian,
70  transportJacobian, derivatives,
71  jacobianLocalToGlobal, parameters, *surface);
72 
73  BOOST_TEST(covariance != Covariance::Identity());
74  BOOST_TEST(jacobian != 2. * Jacobian::Identity());
75  BOOST_TEST(transportJacobian == FreeMatrix::Identity());
76  BOOST_TEST(derivatives == FreeVector::Zero());
77  BOOST_TEST(jacobianLocalToGlobal != 4. * BoundToFreeMatrix::Identity());
78  BOOST_TEST(parameters == startParameters);
79 
80  // Produce a curvilinear state without covariance matrix
81  auto curvResult = detail::curvilinearState(
82  covariance, jacobian, transportJacobian, derivatives,
83  jacobianLocalToGlobal, parameters, false, 1337.);
84  BOOST_TEST(!std::get<0>(curvResult).covariance().has_value());
85  BOOST_TEST(std::get<2>(curvResult) == 1337.);
86 
87  // Reset
88  covariance = Covariance::Identity();
89  jacobian = 2. * Jacobian::Identity();
90  transportJacobian = 3. * FreeMatrix::Identity();
91  derivatives << 9., 10., 11., 12., 13., 14., 15., 16.;
92  jacobianLocalToGlobal = 4. * BoundToFreeMatrix::Identity();
93 
94  // Produce a curvilinear state with covariance matrix
95  curvResult = detail::curvilinearState(covariance, jacobian, transportJacobian,
96  derivatives, jacobianLocalToGlobal,
97  parameters, true, 1337.);
98  BOOST_TEST(std::get<0>(curvResult).covariance().has_value());
99  BOOST_TEST(*(std::get<0>(curvResult).covariance()) != Covariance::Identity());
100  BOOST_TEST(std::get<1>(curvResult) != 2. * Jacobian::Identity());
101  BOOST_TEST(std::get<2>(curvResult) == 1337.);
102 
103  // Produce a bound state without covariance matrix
104  auto boundResult = detail::boundState(
105  tgContext, covariance, jacobian, transportJacobian, derivatives,
106  jacobianLocalToGlobal, parameters, false, 1337., *surface);
107  BOOST_TEST(!std::get<0>(boundResult).covariance().has_value());
108  BOOST_TEST(std::get<2>(boundResult) == 1337.);
109 
110  // Reset
111  covariance = Covariance::Identity();
112  jacobian = 2. * Jacobian::Identity();
113  transportJacobian = 3. * FreeMatrix::Identity();
114  derivatives << 9., 10., 11., 12., 13., 14., 15., 16.;
115  jacobianLocalToGlobal = 4. * BoundToFreeMatrix::Identity();
116 
117  // Produce a bound state with covariance matrix
118  boundResult = detail::boundState(
119  tgContext, covariance, jacobian, transportJacobian, derivatives,
120  jacobianLocalToGlobal, parameters, true, 1337., *surface);
121  BOOST_TEST(std::get<0>(boundResult).covariance().has_value());
122  BOOST_TEST(*(std::get<0>(boundResult).covariance()) !=
123  Covariance::Identity());
124  BOOST_TEST(std::get<1>(boundResult) != 2. * Jacobian::Identity());
125  BOOST_TEST(std::get<2>(boundResult) == 1337.);
126 }
127 } // namespace Test
128 } // namespace Acts