ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ActionListTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ActionListTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2016-2018 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 
21 #include "Acts/Utilities/Units.hpp"
23 
24 namespace bdata = boost::unit_test::data;
25 namespace tt = boost::test_tools;
26 using namespace Acts::UnitLiterals;
27 
28 namespace Acts {
29 namespace Test {
30 
31 // the constrained step class
32 
35 struct PropagatorState {
36  // This is a simple cache struct to mimic the
37  // Stepper cache in the propagation
38  struct StepperState {
39  // accummulated path length cache
40  double pathAccumulated = 0.;
41 
42  // adaptive sep size of the runge-kutta integration
43  ConstrainedStep stepSize = std::numeric_limits<double>::max();
44  };
45 
47  struct Options {
50  bool debug = false;
51  std::string debugString = "";
53  size_t debugPfxWidth = 30;
54  size_t debugMsgWidth = 50;
55  };
56 
58  const Surface* startSurface = nullptr;
59 
61  const Surface* currentSurface = nullptr;
62 
64  const Surface* targetSurface = nullptr;
65  bool targetReached = false;
66 
68  Options options;
69 
71  StepperState stepping;
72 };
73 
75 struct Stepper {};
76 
79  double path_to_go = 100_mm;
80 
81  struct this_result {
82  double distance = std::numeric_limits<double>::max();
83  };
84 
86 
87  DistanceObserver(double ptg = 0.) : path_to_go(ptg) {}
88 
89  template <typename propagator_state_t, typename stepper_t>
90  void operator()(propagator_state_t& state, const stepper_t& /*unused*/,
91  result_type& result) const {
92  result.distance = path_to_go - state.stepping.pathAccumulated;
93  }
94 
95  template <typename propagator_state_t, typename stepper_t>
96  void operator()(propagator_state_t& /*unused*/,
97  const stepper_t& /*unused*/) const {}
98 };
99 
101 struct CallCounter {
102  struct this_result {
103  size_t calls = 0;
104  };
105 
107 
108  CallCounter() = default;
109 
110  template <typename propagator_state_t, typename stepper_t>
111  void operator()(propagator_state_t& /*unused*/, const stepper_t& /*unused*/,
112  result_type& r) const {
113  ++r.calls;
114  }
115 
116  template <typename propagator_state_t, typename stepper_t>
117  void operator()(propagator_state_t& /*unused*/,
118  const stepper_t& /*unused*/) const {}
119 };
120 
121 // This tests the implementation of the ActionList
122 // and the standard aborters
123 BOOST_AUTO_TEST_CASE(ActionListTest_Distance) {
124  // construct the (prop/step) cache and result
125  PropagatorState state;
127 
128  // Type of track parameters produced at the end of the propagation
129  using distance_result = typename DistanceObserver::result_type;
131 
132  ActionList<DistanceObserver> action_list;
133  action_list.get<DistanceObserver>().path_to_go = 100_mm;
134 
135  // observe and check
136  action_list(state, stepper, result);
137  BOOST_CHECK_EQUAL(result.get<distance_result>().distance, 100_mm);
138 
139  // now move the cache and check again
140  state.stepping.pathAccumulated = 50_mm;
141  action_list(state, stepper, result);
142  BOOST_CHECK_EQUAL(result.get<distance_result>().distance, 50_mm);
143 }
144 
145 // This tests the implementation of the ActionList
146 // and the standard aborters
147 BOOST_AUTO_TEST_CASE(ActionListTest_TwoActions) {
148  // construct the (prop/step) cache and result
149  PropagatorState state;
151 
152  // Type of track parameters produced at the end of the propagation
153  using distance_result = typename DistanceObserver::result_type;
154  using caller_result = typename CallCounter::result_type;
156  action_list.get<DistanceObserver>().path_to_go = 100_mm;
157 
159 
161  action_list(state, stepper, result);
162  BOOST_CHECK_EQUAL(result.get<distance_result>().distance, 100_mm);
163  BOOST_CHECK_EQUAL(result.get<caller_result>().calls, 1u);
164 
165  // now move the cache and check again
166  state.stepping.pathAccumulated = 50_mm;
167  action_list(state, stepper, result);
168  BOOST_CHECK_EQUAL(result.get<distance_result>().distance, 50_mm);
169  BOOST_CHECK_EQUAL(result.get<caller_result>().calls, 2u);
170 }
171 
172 } // namespace Test
173 } // namespace Acts