ECCE @ 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/optional/optional_io.hpp>
10 #include <boost/test/unit_test.hpp>
11 
12 #include <memory>
13 
21 
22 namespace Acts {
23 namespace Test {
24 
27 
29 
30 template <ParID_t... params>
31 using MeasurementType = Measurement<SourceLink, params...>;
33 
34 // Create a test context
36 
37 BOOST_AUTO_TEST_CASE(gain_matrix_smoother) {
38  // Make dummy measurement
39  auto plane1 = Surface::makeShared<PlaneSurface>(Vector3D::UnitX() * 1,
40  Vector3D::UnitX());
41  auto plane2 = Surface::makeShared<PlaneSurface>(Vector3D::UnitX() * 2,
42  Vector3D::UnitX());
43  auto plane3 = Surface::makeShared<PlaneSurface>(Vector3D::UnitX() * 3,
44  Vector3D::UnitX());
45 
47  cov << 0.04, 0, 0, 0.1;
50  plane1, {}, std::move(cov), -0.1, 0.45));
51 
52  cov << 0.04, 0, 0, 0.1;
55  plane2, {}, std::move(cov), -0.2, 0.35));
56 
57  cov << 0.04, 0, 0, 0.1;
60  plane3, {}, std::move(cov), -0.05, 0.25));
61 
63 
64  size_t ts_idx;
65 
67  auto ts = traj.getTrackState(ts_idx);
68  ts.setReferenceSurface(plane1);
69 
70  // Make dummy track parameter
71  Covariance covTrk;
72  covTrk.setIdentity();
73  covTrk.diagonal() << 0.08, 0.3, 1, 1, 1, 1;
74  BoundVector parValues;
75  parValues << 0.3, 0.5, 0.5 * M_PI, 0., 1 / 100., 0.;
76 
77  ts.predicted() = parValues;
78  ts.predictedCovariance() = covTrk;
79 
80  parValues << 0.301, 0.503, 0.5 * M_PI, 0., 1 / 100., 0.;
81 
82  ts.filtered() = parValues;
83  ts.filteredCovariance() = covTrk;
84  ts.pathLength() = 1.;
85  ts.jacobian().setIdentity();
86 
87  ts_idx = traj.addTrackState(TrackStatePropMask::All, ts_idx);
88  ts = traj.getTrackState(ts_idx);
89  ts.setReferenceSurface(plane2);
90 
91  parValues << 0.2, 0.5, 0.5 * M_PI, 0., 1 / 100., 0.;
92  ts.predicted() = parValues;
93  ts.predictedCovariance() = covTrk;
94 
95  parValues << 0.27, 0.53, 0.5 * M_PI, 0., 1 / 100., 0.;
96  ts.filtered() = parValues;
97  ts.filteredCovariance() = covTrk;
98  ts.pathLength() = 2.;
99  ts.jacobian().setIdentity();
100 
101  ts_idx = traj.addTrackState(TrackStatePropMask::All, ts_idx);
102  ts = traj.getTrackState(ts_idx);
103  ts.setReferenceSurface(plane3);
104 
105  parValues << 0.35, 0.49, 0.5 * M_PI, 0., 1 / 100., 0.;
106  ts.predicted() = parValues;
107  ts.predictedCovariance() = covTrk;
108 
109  parValues << 0.33, 0.43, 0.5 * M_PI, 0., 1 / 100., 0.;
110  ts.filtered() = parValues;
111  ts.filteredCovariance() = covTrk;
112  ts.pathLength() = 3.;
113  ts.jacobian().setIdentity();
114 
115  // "smooth" these three track states
116 
118  BOOST_CHECK(gms(tgContext, traj, ts_idx).ok());
119 
120  // Regression tests, only tests very basic correctness of the math, but tests
121  // for regressions in the result.
122 
123  auto ts1 = traj.getTrackState(0);
124  BOOST_CHECK(ts1.hasSmoothed());
125  BOOST_CHECK_NE(ts1.filtered(), ts1.smoothed());
126 
127  double tol = 1e-6;
128 
129  BoundVector expPars;
130  expPars << 0.3510000, 0.4730000, 1.5707963, 0.0000000, 0.0100000, 0.0000000;
131  CHECK_CLOSE_ABS(ts1.smoothed(), expPars, tol);
132  Covariance expCov;
133  expCov.setIdentity();
134  expCov.diagonal() << 0.0800000, 0.3000000, 1.0000000, 1.0000000, 1.0000000,
135  1.0000000;
136  CHECK_CLOSE_ABS(ts1.smoothedCovariance(), expCov, tol);
137 
138  auto ts2 = traj.getTrackState(1);
139  BOOST_CHECK(ts2.hasSmoothed());
140  BOOST_CHECK_NE(ts2.filtered(), ts2.smoothed());
141 
142  expPars << 0.2500000, 0.4700000, 1.5707963, 0.0000000, 0.0100000, 0.0000000;
143  CHECK_CLOSE_ABS(ts2.smoothed(), expPars, tol);
144  CHECK_CLOSE_ABS(ts2.smoothedCovariance(), expCov, tol);
145 
146  auto ts3 = traj.getTrackState(2);
147  BOOST_CHECK(ts3.hasSmoothed());
148  // last one, smoothed == filtered
149  BOOST_CHECK_EQUAL(ts3.filtered(), ts3.smoothed());
150 
151  expPars << 0.3300000, 0.4300000, 1.5707963, 0.0000000, 0.0100000, 0.0000000;
152  CHECK_CLOSE_ABS(ts3.smoothed(), expPars, tol);
153  CHECK_CLOSE_ABS(ts3.smoothedCovariance(), expCov, tol);
154 }
155 
156 } // namespace Test
157 } // namespace Acts