Analysis Software
Documentation for sPHENIX simulation 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 
20 
21 #include <cmath>
22 #include <memory>
23 #include <optional>
24 #include <tuple>
25 #include <utility>
26 
27 namespace tt = boost::test_tools;
28 
29 namespace Acts {
30 namespace Test {
31 
33 using Jacobian = BoundMatrix;
34 
38 BOOST_AUTO_TEST_CASE(covariance_engine_test) {
39  // Create a test context
41 
43 
44  // Build a start vector
45  Vector3 position{1., 2., 3.};
46  double time = 4.;
47  Vector3 direction{sqrt(5. / 22.), 3. * sqrt(2. / 55.), 7. / sqrt(110.)};
48  double qop = 0.125;
49  FreeVector parameters, startParameters;
50  parameters << position[0], position[1], position[2], time, direction[0],
51  direction[1], direction[2], qop;
52  startParameters = parameters;
53 
54  // Build covariance matrix, jacobians and related components
55  Covariance covariance = Covariance::Identity();
56  Jacobian jacobian = 2. * Jacobian::Identity();
57  FreeMatrix transportJacobian = 3. * FreeMatrix::Identity();
58  FreeVector derivatives;
59  derivatives << 9., 10., 11., 12., 13., 14., 15., 16.;
60  BoundToFreeMatrix boundToFreeJacobian = 4. * BoundToFreeMatrix::Identity();
61 
62  // Covariance transport to curvilinear coordinates
63  detail::transportCovarianceToCurvilinear(covariance, jacobian,
64  transportJacobian, derivatives,
65  boundToFreeJacobian, direction);
66 
67  // Tests to see that the right components are (un-)changed
68  BOOST_CHECK_NE(covariance, Covariance::Identity());
69  BOOST_CHECK_NE(jacobian, 2. * Jacobian::Identity());
70  BOOST_CHECK_EQUAL(transportJacobian, FreeMatrix::Identity());
71  BOOST_CHECK_EQUAL(derivatives, FreeVector::Zero());
72  BOOST_CHECK_NE(boundToFreeJacobian, 4. * BoundToFreeMatrix::Identity());
73  BOOST_CHECK_EQUAL(
74  direction, Vector3(sqrt(5. / 22.), 3. * sqrt(2. / 55.), 7. / sqrt(110.)));
75 
76  // Reset
77  covariance = Covariance::Identity();
78  jacobian = 2. * Jacobian::Identity();
79  transportJacobian = 3. * FreeMatrix::Identity();
80  derivatives << 9., 10., 11., 12., 13., 14., 15., 16.;
81  boundToFreeJacobian = 4. * BoundToFreeMatrix::Identity();
82 
83  // Repeat transport to surface
84  FreeToBoundCorrection freeToBoundCorrection(false);
85  auto surface = Surface::makeShared<PlaneSurface>(position, direction);
87  tgContext, covariance, jacobian, transportJacobian, derivatives,
88  boundToFreeJacobian, parameters, *surface, freeToBoundCorrection);
89 
90  BOOST_CHECK_NE(covariance, Covariance::Identity());
91  BOOST_CHECK_NE(jacobian, 2. * Jacobian::Identity());
92  BOOST_CHECK_EQUAL(transportJacobian, FreeMatrix::Identity());
93  BOOST_CHECK_EQUAL(derivatives, FreeVector::Zero());
94  BOOST_CHECK_NE(boundToFreeJacobian, 4. * BoundToFreeMatrix::Identity());
95  BOOST_CHECK_EQUAL(parameters, startParameters);
96 
97  // Produce a curvilinear state without covariance matrix
98  auto covarianceBefore = covariance;
99  auto curvResult = detail::curvilinearState(
100  covariance, jacobian, transportJacobian, derivatives, boundToFreeJacobian,
101  parameters, particleHypothesis, false, 1337.);
102  BOOST_CHECK(std::get<0>(curvResult).covariance().has_value());
103  BOOST_CHECK_EQUAL(*(std::get<0>(curvResult).covariance()), covarianceBefore);
104  BOOST_CHECK_EQUAL(std::get<2>(curvResult), 1337.);
105 
106  // Reset
107  covariance = Covariance::Identity();
108  jacobian = 2. * Jacobian::Identity();
109  transportJacobian = 3. * FreeMatrix::Identity();
110  derivatives << 9., 10., 11., 12., 13., 14., 15., 16.;
111  boundToFreeJacobian = 4. * BoundToFreeMatrix::Identity();
112 
113  // Produce a curvilinear state with covariance matrix
114  curvResult = detail::curvilinearState(
115  covariance, jacobian, transportJacobian, derivatives, boundToFreeJacobian,
116  parameters, particleHypothesis, true, 1337.);
117  BOOST_CHECK(std::get<0>(curvResult).covariance().has_value());
118  BOOST_CHECK_NE(*(std::get<0>(curvResult).covariance()),
119  Covariance::Identity());
120  BOOST_CHECK_NE(std::get<1>(curvResult), 2. * Jacobian::Identity());
121  BOOST_CHECK_EQUAL(std::get<2>(curvResult), 1337.);
122 
123  // Produce a bound state without covariance matrix
124  covarianceBefore = covariance;
125  auto boundResult =
126  detail::boundState(tgContext, covariance, jacobian, transportJacobian,
127  derivatives, boundToFreeJacobian, parameters,
128  particleHypothesis, false, 1337., *surface,
129  freeToBoundCorrection)
130  .value();
131  BOOST_CHECK(std::get<0>(curvResult).covariance().has_value());
132  BOOST_CHECK_EQUAL(*(std::get<0>(curvResult).covariance()), covarianceBefore);
133  BOOST_CHECK_EQUAL(std::get<2>(boundResult), 1337.);
134 
135  // Reset
136  covariance = Covariance::Identity();
137  jacobian = 2. * Jacobian::Identity();
138  transportJacobian = 3. * FreeMatrix::Identity();
139  derivatives << 9., 10., 11., 12., 13., 14., 15., 16.;
140  boundToFreeJacobian = 4. * BoundToFreeMatrix::Identity();
141 
142  // Produce a bound state with covariance matrix
143  boundResult =
144  detail::boundState(tgContext, covariance, jacobian, transportJacobian,
145  derivatives, boundToFreeJacobian, parameters,
146  ParticleHypothesis::pion(), true, 1337., *surface,
147  freeToBoundCorrection)
148  .value();
149  BOOST_CHECK(std::get<0>(boundResult).covariance().has_value());
150  BOOST_CHECK_NE(*(std::get<0>(boundResult).covariance()),
151  Covariance::Identity());
152  BOOST_CHECK_NE(std::get<1>(boundResult), 2. * Jacobian::Identity());
153  BOOST_CHECK_EQUAL(std::get<2>(boundResult), 1337.);
154 
155  // Reset
156  freeToBoundCorrection.apply = true;
157 
158  // Produce a bound state with free to bound correction
159  boundResult =
160  detail::boundState(tgContext, covariance, jacobian, transportJacobian,
161  derivatives, boundToFreeJacobian, parameters,
162  ParticleHypothesis::pion(), true, 1337., *surface,
163  freeToBoundCorrection)
164  .value();
165  BOOST_CHECK(std::get<0>(boundResult).covariance().has_value());
166  BOOST_CHECK_NE(*(std::get<0>(boundResult).covariance()),
167  Covariance::Identity());
168 }
169 } // namespace Test
170 } // namespace Acts