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_CHECK_NE(covariance, Covariance::Identity());
53  BOOST_CHECK_NE(jacobian, 2. * Jacobian::Identity());
54  BOOST_CHECK_EQUAL(transportJacobian, FreeMatrix::Identity());
55  BOOST_CHECK_EQUAL(derivatives, FreeVector::Zero());
56  BOOST_CHECK_NE(jacobianLocalToGlobal, 4. * BoundToFreeMatrix::Identity());
57  BOOST_CHECK_EQUAL(direction, Vector3D(sqrt(5. / 22.), 3. * sqrt(2. / 55.),
58  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_CHECK_NE(covariance, Covariance::Identity());
74  BOOST_CHECK_NE(jacobian, 2. * Jacobian::Identity());
75  BOOST_CHECK_EQUAL(transportJacobian, FreeMatrix::Identity());
76  BOOST_CHECK_EQUAL(derivatives, FreeVector::Zero());
77  BOOST_CHECK_NE(jacobianLocalToGlobal, 4. * BoundToFreeMatrix::Identity());
78  BOOST_CHECK_EQUAL(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_CHECK(!std::get<0>(curvResult).covariance().has_value());
85  BOOST_CHECK_EQUAL(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_CHECK(std::get<0>(curvResult).covariance().has_value());
99  BOOST_CHECK_NE(*(std::get<0>(curvResult).covariance()),
100  Covariance::Identity());
101  BOOST_CHECK_NE(std::get<1>(curvResult), 2. * Jacobian::Identity());
102  BOOST_CHECK_EQUAL(std::get<2>(curvResult), 1337.);
103 
104  // Produce a bound state without covariance matrix
105  auto boundResult = detail::boundState(
106  tgContext, covariance, jacobian, transportJacobian, derivatives,
107  jacobianLocalToGlobal, parameters, false, 1337., *surface);
108  BOOST_CHECK(!std::get<0>(boundResult).covariance().has_value());
109  BOOST_CHECK_EQUAL(std::get<2>(boundResult), 1337.);
110 
111  // Reset
112  covariance = Covariance::Identity();
113  jacobian = 2. * Jacobian::Identity();
114  transportJacobian = 3. * FreeMatrix::Identity();
115  derivatives << 9., 10., 11., 12., 13., 14., 15., 16.;
116  jacobianLocalToGlobal = 4. * BoundToFreeMatrix::Identity();
117 
118  // Produce a bound state with covariance matrix
119  boundResult = detail::boundState(
120  tgContext, covariance, jacobian, transportJacobian, derivatives,
121  jacobianLocalToGlobal, parameters, true, 1337., *surface);
122  BOOST_CHECK(std::get<0>(boundResult).covariance().has_value());
123  BOOST_CHECK_NE(*(std::get<0>(boundResult).covariance()),
124  Covariance::Identity());
125  BOOST_CHECK_NE(std::get<1>(boundResult), 2. * Jacobian::Identity());
126  BOOST_CHECK_EQUAL(std::get<2>(boundResult), 1337.);
127 }
128 } // namespace Test
129 } // namespace Acts