EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GainMatrixSmootherTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file GainMatrixSmootherTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019 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 
17 
18 #include <memory>
19 
20 #include <boost/optional/optional_io.hpp>
21 
22 namespace Acts {
23 namespace Test {
24 
25 using Jacobian = BoundMatrix;
27 using SourceLink = MinimalSourceLink;
28 template <BoundIndices... params>
30 
31 // Create a test context
33 
34 BOOST_AUTO_TEST_CASE(gain_matrix_smoother) {
35  // Make dummy measurement
36  auto plane1 = Surface::makeShared<PlaneSurface>(Vector3D::UnitX() * 1,
37  Vector3D::UnitX());
38  auto plane2 = Surface::makeShared<PlaneSurface>(Vector3D::UnitX() * 2,
39  Vector3D::UnitX());
40  auto plane3 = Surface::makeShared<PlaneSurface>(Vector3D::UnitX() * 3,
41  Vector3D::UnitX());
42 
44  cov << 0.04, 0, 0, 0.1;
47  plane1, {}, std::move(cov), -0.1, 0.45));
48 
49  cov << 0.04, 0, 0, 0.1;
52  plane2, {}, std::move(cov), -0.2, 0.35));
53 
54  cov << 0.04, 0, 0, 0.1;
57  plane3, {}, std::move(cov), -0.05, 0.25));
58 
60 
61  size_t ts_idx;
62 
63  ts_idx = traj.addTrackState(TrackStatePropMask::All);
64  auto ts = traj.getTrackState(ts_idx);
65  ts.setReferenceSurface(plane1);
66 
67  // Make dummy track parameter
68  Covariance covTrk;
69  covTrk.setIdentity();
70  covTrk.diagonal() << 0.08, 0.3, 1, 1, 1, 1;
71  BoundVector parValues;
72  parValues << 0.3, 0.5, 0.5 * M_PI, 0., 1 / 100., 0.;
73 
74  ts.predicted() = parValues;
75  ts.predictedCovariance() = covTrk;
76 
77  parValues << 0.301, 0.503, 0.5 * M_PI, 0., 1 / 100., 0.;
78 
79  ts.filtered() = parValues;
80  ts.filteredCovariance() = covTrk;
81  ts.pathLength() = 1.;
82  ts.jacobian().setIdentity();
83 
84  ts_idx = traj.addTrackState(TrackStatePropMask::All, ts_idx);
85  ts = traj.getTrackState(ts_idx);
86  ts.setReferenceSurface(plane2);
87 
88  parValues << 0.2, 0.5, 0.5 * M_PI, 0., 1 / 100., 0.;
89  ts.predicted() = parValues;
90  ts.predictedCovariance() = covTrk;
91 
92  parValues << 0.27, 0.53, 0.5 * M_PI, 0., 1 / 100., 0.;
93  ts.filtered() = parValues;
94  ts.filteredCovariance() = covTrk;
95  ts.pathLength() = 2.;
96  ts.jacobian().setIdentity();
97 
98  ts_idx = traj.addTrackState(TrackStatePropMask::All, ts_idx);
99  ts = traj.getTrackState(ts_idx);
100  ts.setReferenceSurface(plane3);
101 
102  parValues << 0.35, 0.49, 0.5 * M_PI, 0., 1 / 100., 0.;
103  ts.predicted() = parValues;
104  ts.predictedCovariance() = covTrk;
105 
106  parValues << 0.33, 0.43, 0.5 * M_PI, 0., 1 / 100., 0.;
107  ts.filtered() = parValues;
108  ts.filteredCovariance() = covTrk;
109  ts.pathLength() = 3.;
110  ts.jacobian().setIdentity();
111 
112  // "smooth" these three track states
113 
114  GainMatrixSmoother gms;
115  BOOST_CHECK(gms(tgContext, traj, ts_idx).ok());
116 
117  // Regression tests, only tests very basic correctness of the math, but tests
118  // for regressions in the result.
119 
120  auto ts1 = traj.getTrackState(0);
121  BOOST_CHECK(ts1.hasSmoothed());
122  BOOST_CHECK_NE(ts1.filtered(), ts1.smoothed());
123 
124  double tol = 1e-6;
125 
126  BoundVector expPars;
127  expPars << 0.3510000, 0.4730000, 1.5707963, 0.0000000, 0.0100000, 0.0000000;
128  CHECK_CLOSE_ABS(ts1.smoothed(), expPars, tol);
129  Covariance expCov;
130  expCov.setIdentity();
131  expCov.diagonal() << 0.0800000, 0.3000000, 1.0000000, 1.0000000, 1.0000000,
132  1.0000000;
133  CHECK_CLOSE_ABS(ts1.smoothedCovariance(), expCov, tol);
134 
135  auto ts2 = traj.getTrackState(1);
136  BOOST_CHECK(ts2.hasSmoothed());
137  BOOST_CHECK_NE(ts2.filtered(), ts2.smoothed());
138 
139  expPars << 0.2500000, 0.4700000, 1.5707963, 0.0000000, 0.0100000, 0.0000000;
140  CHECK_CLOSE_ABS(ts2.smoothed(), expPars, tol);
141  CHECK_CLOSE_ABS(ts2.smoothedCovariance(), expCov, tol);
142 
143  auto ts3 = traj.getTrackState(2);
144  BOOST_CHECK(ts3.hasSmoothed());
145  // last one, smoothed == filtered
146  BOOST_CHECK_EQUAL(ts3.filtered(), ts3.smoothed());
147 
148  expPars << 0.3300000, 0.4300000, 1.5707963, 0.0000000, 0.0100000, 0.0000000;
149  CHECK_CLOSE_ABS(ts3.smoothed(), expPars, tol);
150  CHECK_CLOSE_ABS(ts3.smoothedCovariance(), expCov, tol);
151 }
152 
153 } // namespace Test
154 } // namespace Acts