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