ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NavigatorTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file NavigatorTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2018-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/data/test_case.hpp>
10 #include <boost/test/tools/output_test_stream.hpp>
11 #include <boost/test/unit_test.hpp>
12 
13 #include <memory>
14 
27 #include "Acts/Utilities/Units.hpp"
28 
29 namespace bdata = boost::unit_test::data;
30 namespace tt = boost::test_tools;
31 using namespace Acts::UnitLiterals;
33 
34 namespace Acts {
35 namespace Test {
36 
37 // Create a test context
39 
42 struct PropagatorState {
44  struct Stepper {
45  // comply with concept
48  using BoundState = std::tuple<BoundParameters, Jacobian, double>;
49  using CurvilinearState =
50  std::tuple<CurvilinearParameters, Jacobian, double>;
51  using BField = int;
52 
53  template <typename, typename>
55 
58  struct State {
60  Vector3D pos = Vector3D(0., 0., 0.);
61 
63  Vector3D dir = Vector3D(1., 0., 0.);
64 
66  double p;
67 
69  double q;
70 
72  double t;
73 
76 
77  // accummulated path length cache
78  double pathAccumulated = 0.;
79 
80  // adaptive sep size of the runge-kutta integration
82 
83  // Previous step size for overstep estimation (ignored here)
84  double previousStepSize = 0.;
85 
87  double tolerance = s_onSurfaceTolerance;
88 
90  };
91 
93  Vector3D position(const State& state) const { return state.pos; }
94 
96  Vector3D direction(const State& state) const { return state.dir; }
97 
99  double momentum(const State& state) const { return state.p; }
100 
102  double charge(const State& state) const { return state.q; }
103 
105  double time(const State& state) const { return state.t; }
106 
108  double overstepLimit(const State& /*state*/) const {
109  return s_onSurfaceTolerance;
110  }
111 
112  Intersection::Status updateSurfaceStatus(
113  State& state, const Surface& surface,
114  const BoundaryCheck& bcheck) const {
115  return detail::updateSingleSurfaceStatus<Stepper>(*this, state, surface,
116  bcheck);
117  }
118 
119  template <typename object_intersection_t>
120  void updateStepSize(State& state,
121  const object_intersection_t& oIntersection,
122  bool release = true) const {
123  detail::updateSingleStepSize<Stepper>(state, oIntersection, release);
124  }
125 
126  void setStepSize(
127  State& state, double stepSize,
129  state.previousStepSize = state.stepSize;
130  state.stepSize.update(stepSize, stype, true);
131  }
132 
133  void releaseStepSize(State& state) const {
135  }
136 
137  std::string outputStepSize(const State& state) const {
138  return state.stepSize.toString();
139  }
140 
141  BoundState boundState(State& state, const Surface& surface) const {
142  BoundParameters parameters(tgContext, std::nullopt, state.pos,
143  state.p * state.dir, state.q, state.t,
144  surface.getSharedPtr());
145  BoundState bState{std::move(parameters), Jacobian::Identity(),
146  state.pathAccumulated};
147  return bState;
148  }
149 
151  CurvilinearParameters parameters(std::nullopt, state.pos,
152  state.p * state.dir, state.q, state.t);
153  // Create the bound state
154  CurvilinearState curvState{std::move(parameters), Jacobian::Identity(),
155  state.pathAccumulated};
156  return curvState;
157  }
158 
159  void update(State& /*state*/, const BoundParameters& /*pars*/) const {}
160 
161  void update(State& /*state*/, const Vector3D& /*uposition*/,
162  const Vector3D& /*udirection*/, double /*up*/,
163  double /*time*/) const {}
164 
165  void covarianceTransport(State& /*state*/) const {}
166 
167  void covarianceTransport(State& /*unused*/,
168  const Surface& /*surface*/) const {}
169 
170  Vector3D getField(State& /*state*/, const Vector3D& /*pos*/) const {
171  // get the field from the cell
172  return Vector3D(0., 0., 0.);
173  }
174  };
175 
176  static_assert(StepperConcept<Stepper>,
177  "Dummy stepper does not fulfill concept");
178 
180  struct Options {
183  bool debug = false;
184  std::string debugString = "";
186  size_t debugPfxWidth = 30;
187  size_t debugMsgWidth = 50;
188  };
189 
191  const Surface* startSurface = nullptr;
192 
194  const Surface* currentSurface = nullptr;
195 
197  const Surface* targetSurface = nullptr;
198  bool targetReached = false;
199 
201  Options options;
202 
205 
208 
209  // The context cache for this propagation
211 };
212 
213 template <typename stepper_state_t>
214 void step(stepper_state_t& sstate) {
215  // update the cache position
216  sstate.pos = sstate.pos + sstate.stepSize * sstate.dir;
217  // create navigation parameters
218  return;
219 }
220 
221 // the surface cache & the creation of the geometry
222 
223 CylindricalTrackingGeometry cGeometry(tgContext);
224 auto tGeometry = cGeometry();
225 
226 // the debug boolean
227 bool debug = true;
228 
229 BOOST_AUTO_TEST_CASE(Navigator_methods) {
230  // create a navigator
232  navigator.trackingGeometry = tGeometry;
233  navigator.resolveSensitive = true;
234  navigator.resolveMaterial = true;
235  navigator.resolvePassive = false;
236 
237  // position and direction vector
238  Vector3D position(0., 0., 0);
239  Vector3D momentum(1., 1., 0);
240 
241  // the propagator cache
242  PropagatorState state;
243  state.options.debug = debug;
244 
245  // the stepper cache
246  state.stepping.pos = position;
247  state.stepping.dir = momentum.normalized();
248 
249  // foward navigation ----------------------------------------------
250  if (debug) {
251  std::cout << "<<<<<<<<<<<<<<<<<<<<< FORWARD NAVIGATION >>>>>>>>>>>>>>>>>>"
252  << std::endl;
253  }
254 
255  // Stepper
257 
258  // (1) Initialization navigation from start point
259  // - this will call resolveLayers() as well
260  // - and thus should call a return to the stepper
261  navigator.status(state, stepper);
262  // Check that the currentVolume is set
263  BOOST_CHECK_NE(state.navigation.currentVolume, nullptr);
264  // Check that the currentVolume is the startVolume
265  BOOST_CHECK_EQUAL(state.navigation.currentVolume,
266  state.navigation.startVolume);
267  // Check that the currentSurface is reset to:
268  BOOST_CHECK_EQUAL(state.navigation.currentSurface, nullptr);
269  // No layer has been found
270  BOOST_CHECK_EQUAL(state.navigation.navLayers.size(), 0u);
271  // ACTORS-ABORTERS-TARGET
272  navigator.target(state, stepper);
273  // A layer has been found
274  BOOST_CHECK_EQUAL(state.navigation.navLayers.size(), 1u);
275  // The iterator should points to the begin
276  BOOST_CHECK(state.navigation.navLayerIter ==
277  state.navigation.navLayers.begin());
278  // Cache the beam pipe radius
279  double beamPipeR = perp(state.navigation.navLayerIter->intersection.position);
280  // step size has been updated
281  CHECK_CLOSE_ABS(state.stepping.stepSize, beamPipeR, s_onSurfaceTolerance);
282  if (debug) {
283  std::cout << "<<< Test 1a >>> initialize at "
284  << toString(state.stepping.pos) << std::endl;
285  std::cout << state.options.debugString << std::endl;
286  // Clear the debug string for the next test
287  state.options.debugString = "";
288  }
289 
290  // Do the step towards the beam pipe
291  step(state.stepping);
292 
293  // (2) re-entering navigator:
294  // STATUS
295  navigator.status(state, stepper);
296  // Check that the currentVolume is the still startVolume
297  BOOST_CHECK_EQUAL(state.navigation.currentVolume,
298  state.navigation.startVolume);
299  // The layer number has not changed
300  BOOST_CHECK_EQUAL(state.navigation.navLayers.size(), 1u);
301  // The iterator still points to the begin
302  BOOST_CHECK(
303  (state.navigation.navLayerIter == state.navigation.navLayers.begin()));
304  // ACTORS-ABORTERS-TARGET
305  navigator.target(state, stepper);
306 
307  if (debug) {
308  std::cout << "<<< Test 1b >>> step to the BeamPipe at "
309  << toString(state.stepping.pos) << std::endl;
310  std::cout << state.options.debugString << std::endl;
311  state.options.debugString = "";
312  }
313 
314  // Do the step towards the boundary
315  step(state.stepping);
316 
317  // (3) re-entering navigator:
318  // STATUS
319  navigator.status(state, stepper);
320  // ACTORS-ABORTERS-TARGET
321  navigator.target(state, stepper);
322 
323  if (debug) {
324  std::cout << "<<< Test 1c >>> step to the Boundary at "
325  << toString(state.stepping.pos) << std::endl;
326  std::cout << state.options.debugString << std::endl;
327  state.options.debugString = "";
328  }
329 
330  // positive return: do the step
331  step(state.stepping);
332  // (4) re-entering navigator:
333  // STATUS
334  navigator.status(state, stepper);
335  // ACTORS-ABORTERS-TARGET
336  navigator.target(state, stepper);
337 
338  if (debug) {
339  std::cout << "<<< Test 1d >>> step to 1st layer at "
340  << toString(state.stepping.pos) << std::endl;
341  std::cout << state.options.debugString << std::endl;
342  state.options.debugString = "";
343  }
344 
345  // Step through the surfaces on first layer
346  for (size_t isf = 0; isf < 5; ++isf) {
347  step(state.stepping);
348  // (5-9) re-entering navigator:
349  // STATUS
350  navigator.status(state, stepper);
351  // ACTORS-ABORTERS-TARGET
352  navigator.target(state, stepper);
353 
354  if (debug) {
355  std::cout << "<<< Test 1e-1i >>> step within 1st layer at "
356  << toString(state.stepping.pos) << std::endl;
357  std::cout << state.options.debugString << std::endl;
358  state.options.debugString = "";
359  }
360  }
361 
362  // positive return: do the step
363  step(state.stepping);
364  // (10) re-entering navigator:
365  // STATUS
366  navigator.status(state, stepper);
367  // ACTORS-ABORTERS-TARGET
368  navigator.target(state, stepper);
369 
370  if (debug) {
371  std::cout << "<<< Test 1j >>> step to 2nd layer at "
372  << toString(state.stepping.pos) << std::endl;
373  std::cout << state.options.debugString << std::endl;
374  state.options.debugString = "";
375  }
376 
377  // Step through the surfaces on second layer
378  for (size_t isf = 0; isf < 5; ++isf) {
379  step(state.stepping);
380  // (11-15) re-entering navigator:
381  // STATUS
382  navigator.status(state, stepper);
383  // ACTORS-ABORTERS-TARGET
384  navigator.target(state, stepper);
385 
386  if (debug) {
387  std::cout << "<<< Test 1k-1o >>> step within 2nd layer at "
388  << toString(state.stepping.pos) << std::endl;
389  std::cout << state.options.debugString << std::endl;
390  state.options.debugString = "";
391  }
392  }
393 
394  // positive return: do the step
395  step(state.stepping);
396  // (16) re-entering navigator:
397  // STATUS
398  navigator.status(state, stepper);
399  // ACTORS-ABORTERS-TARGET
400  navigator.target(state, stepper);
401 
402  if (debug) {
403  std::cout << "<<< Test 1p >>> step to 3rd layer at "
404  << toString(state.stepping.pos) << std::endl;
405  std::cout << state.options.debugString << std::endl;
406  state.options.debugString = "";
407  }
408 
409  // Step through the surfaces on third layer
410  for (size_t isf = 0; isf < 3; ++isf) {
411  step(state.stepping);
412  // (17-19) re-entering navigator:
413  // STATUS
414  navigator.status(state, stepper);
415  // ACTORS-ABORTERS-TARGET
416  navigator.target(state, stepper);
417 
418  if (debug) {
419  std::cout << "<<< Test 1q-1s >>> step within 3rd layer at "
420  << toString(state.stepping.pos) << std::endl;
421  std::cout << state.options.debugString << std::endl;
422  state.options.debugString = "";
423  }
424  }
425 
426  // positive return: do the step
427  step(state.stepping);
428  // (20) re-entering navigator:
429  // STATUS
430  navigator.status(state, stepper);
431  // ACTORS-ABORTERS-TARGET
432  navigator.target(state, stepper);
433 
434  if (debug) {
435  std::cout << "<<< Test 1t >>> step to 4th layer at "
436  << toString(state.stepping.pos) << std::endl;
437  std::cout << state.options.debugString << std::endl;
438  state.options.debugString = "";
439  }
440 
441  // Step through the surfaces on second layer
442  for (size_t isf = 0; isf < 3; ++isf) {
443  step(state.stepping);
444  // (21-23) re-entering navigator:
445  // STATUS
446  navigator.status(state, stepper);
447  // ACTORS-ABORTERS-TARGET
448  navigator.target(state, stepper);
449 
450  if (debug) {
451  std::cout << "<<< Test 1t-1v >>> step within 4th layer at "
452  << toString(state.stepping.pos) << std::endl;
453  std::cout << state.options.debugString << std::endl;
454  state.options.debugString = "";
455  }
456  }
457 
458  // positive return: do the step
459  step(state.stepping);
460  // (24) re-entering navigator:
461  // STATUS
462  navigator.status(state, stepper);
463  // ACTORS-ABORTERS-TARGET
464  navigator.target(state, stepper);
465 
466  if (debug) {
467  std::cout << "<<< Test 1w >>> step to boundary at "
468  << toString(state.stepping.pos) << std::endl;
469  std::cout << state.options.debugString << std::endl;
470  state.options.debugString = "";
471  }
472 }
473 
474 } // namespace Test
475 } // namespace Acts