ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StraightLineStepperTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file StraightLineStepperTests.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 
15 
16 namespace tt = boost::test_tools;
17 
18 namespace Acts {
19 namespace Test {
20 
22 using Jacobian = BoundMatrix;
23 
25 struct PropState {
31  struct {
32  double mass = 42.;
33  } options;
34 };
35 
37 BOOST_AUTO_TEST_CASE(straight_line_stepper_state_test) {
38  // Set up some variables
42  double stepSize = 123.;
43  double tolerance = 234.;
44 
45  Vector3D pos(1., 2., 3.);
46  Vector3D mom(4., 5., 6.);
47  double time = 7.;
48  double charge = -1.;
49 
50  // Test charged parameters without covariance matrix
51  CurvilinearParameters cp(std::nullopt, pos, mom, charge, time);
52  StraightLineStepper::State slsState(tgContext, mfContext, cp, ndir, stepSize,
53  tolerance);
54 
55  // Test the result & compare with the input/test for reasonable members
56  BOOST_TEST(slsState.jacToGlobal == BoundToFreeMatrix::Zero());
57  BOOST_TEST(slsState.jacTransport == FreeMatrix::Identity());
58  BOOST_TEST(slsState.derivative == FreeVector::Zero());
59  BOOST_TEST(!slsState.covTransport);
60  BOOST_TEST(slsState.cov == Covariance::Zero());
61  BOOST_TEST(slsState.pos == pos);
62  BOOST_TEST(slsState.dir == mom.normalized());
63  BOOST_TEST(slsState.p == mom.norm());
64  BOOST_TEST(slsState.q == charge);
65  BOOST_TEST(slsState.t == time);
66  BOOST_TEST(slsState.navDir == ndir);
67  BOOST_TEST(slsState.pathAccumulated == 0.);
68  BOOST_TEST(slsState.stepSize == ndir * stepSize);
69  BOOST_TEST(slsState.previousStepSize == 0.);
70  BOOST_TEST(slsState.tolerance == tolerance);
71 
72  // Test without charge and covariance matrix
73  NeutralCurvilinearParameters ncp(std::nullopt, pos, mom, time);
74  slsState = StraightLineStepper::State(tgContext, mfContext, ncp, ndir,
75  stepSize, tolerance);
76  BOOST_TEST(slsState.q == 0.);
77 
78  // Test with covariance matrix
79  Covariance cov = 8. * Covariance::Identity();
80  ncp = NeutralCurvilinearParameters(cov, pos, mom, time);
81  slsState = StraightLineStepper::State(tgContext, mfContext, ncp, ndir,
82  stepSize, tolerance);
83  BOOST_TEST(slsState.jacToGlobal != BoundToFreeMatrix::Zero());
84  BOOST_TEST(slsState.covTransport);
85  BOOST_TEST(slsState.cov == cov);
86 }
87 
90 BOOST_AUTO_TEST_CASE(straight_line_stepper_test) {
91  // Set up some variables for the state
95  double stepSize = 123.;
96  double tolerance = 234.;
97 
98  // Construct the parameters
99  Vector3D pos(1., 2., 3.);
100  Vector3D mom(4., 5., 6.);
101  double time = 7.;
102  double charge = -1.;
103  Covariance cov = 8. * Covariance::Identity();
104  CurvilinearParameters cp(cov, pos, mom, charge, time);
105 
106  // Build the state and the stepper
107  StraightLineStepper::State slsState(tgContext, mfContext, cp, ndir, stepSize,
108  tolerance);
110 
111  // Test the getters
112  BOOST_TEST(sls.position(slsState) == slsState.pos);
113  BOOST_TEST(sls.direction(slsState) == slsState.dir);
114  BOOST_TEST(sls.momentum(slsState) == slsState.p);
115  BOOST_TEST(sls.charge(slsState) == slsState.q);
116  BOOST_TEST(sls.time(slsState) == slsState.t);
117 
118  //~ BOOST_TEST(sls.overstepLimit(slsState) == tolerance);
119 
120  // Step size modifies
121  const std::string originalStepSize = slsState.stepSize.toString();
122 
123  sls.setStepSize(slsState, 1337.);
124  BOOST_TEST(slsState.previousStepSize == ndir * stepSize);
125  BOOST_TEST(slsState.stepSize == 1337.);
126 
127  sls.releaseStepSize(slsState);
128  BOOST_TEST(slsState.stepSize == -123.);
129  BOOST_TEST(sls.outputStepSize(slsState) == originalStepSize);
130 
131  // Test the curvilinear state construction
132  auto curvState = sls.curvilinearState(slsState);
133  auto curvPars = std::get<0>(curvState);
134  CHECK_CLOSE_ABS(curvPars.position(), cp.position(), 1e-6);
135  CHECK_CLOSE_ABS(curvPars.momentum(), cp.momentum(), 1e-6);
136  CHECK_CLOSE_ABS(curvPars.charge(), cp.charge(), 1e-6);
137  CHECK_CLOSE_ABS(curvPars.time(), cp.time(), 1e-6);
138  BOOST_TEST(curvPars.covariance().has_value());
139  BOOST_TEST(*curvPars.covariance() != cov);
140  CHECK_CLOSE_COVARIANCE(std::get<1>(curvState),
141  BoundMatrix(BoundMatrix::Identity()), 1e-6);
142  CHECK_CLOSE_ABS(std::get<2>(curvState), 0., 1e-6);
143 
144  // Test the update method
145  Vector3D newPos(2., 4., 8.);
146  Vector3D newMom(3., 9., 27.);
147  double newTime(321.);
148  sls.update(slsState, newPos, newMom.normalized(), newMom.norm(), newTime);
149  BOOST_TEST(slsState.pos == newPos);
150  BOOST_TEST(slsState.dir == newMom.normalized());
151  BOOST_TEST(slsState.p == newMom.norm());
152  BOOST_TEST(slsState.q == charge);
153  BOOST_TEST(slsState.t == newTime);
154 
155  // The covariance transport
156  slsState.cov = cov;
157  sls.covarianceTransport(slsState);
158  BOOST_TEST(slsState.cov != cov);
159  BOOST_TEST(slsState.jacToGlobal != BoundToFreeMatrix::Zero());
160  BOOST_TEST(slsState.jacTransport == FreeMatrix::Identity());
161  BOOST_TEST(slsState.derivative == FreeVector::Zero());
162 
163  // Perform a step without and with covariance transport
164  slsState.cov = cov;
165  PropState ps(slsState);
166 
167  ps.stepping.covTransport = false;
168  double h = sls.step(ps).value();
169  BOOST_TEST(ps.stepping.stepSize == ndir * stepSize);
170  BOOST_TEST(ps.stepping.stepSize == h);
171  CHECK_CLOSE_COVARIANCE(ps.stepping.cov, cov, 1e-6);
172  BOOST_TEST(ps.stepping.pos.norm() > newPos.norm());
173  BOOST_TEST(ps.stepping.dir == newMom.normalized());
174  BOOST_TEST(ps.stepping.p == newMom.norm());
175  BOOST_TEST(ps.stepping.q == charge);
176  BOOST_TEST(ps.stepping.t < newTime);
177  BOOST_TEST(ps.stepping.derivative == FreeVector::Zero());
178  BOOST_TEST(ps.stepping.jacTransport == FreeMatrix::Identity());
179 
180  ps.stepping.covTransport = true;
181  double h2 = sls.step(ps).value();
182  BOOST_TEST(ps.stepping.stepSize == ndir * stepSize);
183  BOOST_TEST(h2 == h);
184  CHECK_CLOSE_COVARIANCE(ps.stepping.cov, cov, 1e-6);
185  BOOST_TEST(ps.stepping.pos.norm() > newPos.norm());
186  BOOST_TEST(ps.stepping.dir == newMom.normalized());
187  BOOST_TEST(ps.stepping.p == newMom.norm());
188  BOOST_TEST(ps.stepping.q == charge);
189  BOOST_TEST(ps.stepping.t < newTime);
190  BOOST_TEST(ps.stepping.derivative != FreeVector::Zero());
191  BOOST_TEST(ps.stepping.jacTransport != FreeMatrix::Identity());
192 
194  auto plane = Surface::makeShared<PlaneSurface>(pos, mom.normalized());
195  BoundParameters bp(tgContext, cov, pos, mom, charge, time, plane);
196  slsState = StraightLineStepper::State(tgContext, mfContext, cp, ndir,
197  stepSize, tolerance);
198 
199  // Test the intersection in the context of a surface
200  auto targetSurface = Surface::makeShared<PlaneSurface>(
201  pos + ndir * 2. * mom.normalized(), mom.normalized());
202  sls.updateSurfaceStatus(slsState, *targetSurface, BoundaryCheck(false));
203  BOOST_TEST(slsState.stepSize.value(ConstrainedStep::actor), ndir * 2.);
204 
205  // Test the step size modification in the context of a surface
206  sls.updateStepSize(
207  slsState,
208  targetSurface->intersect(slsState.geoContext, slsState.pos,
209  slsState.navDir * slsState.dir, false),
210  false);
211  BOOST_TEST(slsState.stepSize == 2.);
212  slsState.stepSize = ndir * stepSize;
213  sls.updateStepSize(
214  slsState,
215  targetSurface->intersect(slsState.geoContext, slsState.pos,
216  slsState.navDir * slsState.dir, false),
217  true);
218  BOOST_TEST(slsState.stepSize == 2.);
219 
220  // Test the bound state construction
221  auto boundState = sls.boundState(slsState, *plane);
222  auto boundPars = std::get<0>(boundState);
223  CHECK_CLOSE_ABS(boundPars.position(), bp.position(), 1e-6);
224  CHECK_CLOSE_ABS(boundPars.momentum(), bp.momentum(), 1e-6);
225  CHECK_CLOSE_ABS(boundPars.charge(), bp.charge(), 1e-6);
226  CHECK_CLOSE_ABS(boundPars.time(), bp.time(), 1e-6);
227  BOOST_TEST(boundPars.covariance().has_value());
228  BOOST_TEST(*boundPars.covariance() != cov);
229  CHECK_CLOSE_COVARIANCE(std::get<1>(boundState),
230  BoundMatrix(BoundMatrix::Identity()), 1e-6);
231  CHECK_CLOSE_ABS(std::get<2>(boundState), 0., 1e-6);
232 
233  // Update in context of a surface
234  BoundParameters bpTarget(tgContext, 2. * cov, 2. * pos, 2. * mom,
235  -1. * charge, 2. * time, targetSurface);
236  sls.update(slsState, bpTarget);
237  BOOST_TEST(slsState.pos == 2. * pos);
238  BOOST_TEST(slsState.dir == mom.normalized());
239  BOOST_TEST(slsState.p == 2. * mom.norm());
240  BOOST_TEST(slsState.q == 1. * charge);
241  BOOST_TEST(slsState.t == 2. * time);
242  CHECK_CLOSE_COVARIANCE(slsState.cov, Covariance(2. * cov), 1e-6);
243 
244  // Transport the covariance in the context of a surface
245  sls.covarianceTransport(slsState, *plane);
246  BOOST_TEST(slsState.cov != cov);
247  BOOST_TEST(slsState.jacToGlobal != BoundToFreeMatrix::Zero());
248  BOOST_TEST(slsState.jacTransport == FreeMatrix::Identity());
249  BOOST_TEST(slsState.derivative == FreeVector::Zero());
250 }
251 } // namespace Test
252 } // namespace Acts