ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AbortListTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file AbortListTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-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 
17 #include "Acts/Utilities/Units.hpp"
19 
20 namespace bdata = boost::unit_test::data;
21 namespace tt = boost::test_tools;
22 using namespace Acts::UnitLiterals;
23 
24 namespace Acts {
25 
26 class Surface;
27 
28 namespace Test {
29 
30 // The path limit abort
32 
33 // The end of world abort
35 
36 // the constrained step class
37 
42  const Surface* startSurface = nullptr;
43 
45  const Surface* currentSurface = nullptr;
46 
48  const Surface* targetSurface = nullptr;
49 
51  bool targetReached = false;
52 };
53 
57  // This is a simple cache struct to mimic the
58  // Stepper cache in the propagation
59  struct StepperState {
60  // Accummulated path length cache
61  double pathAccumulated = 0.;
62  // Navigation direction
64  // adaptive sep size of the runge-kutta integration
66  };
67 
69  struct Options {
71  double pathLimit = std::numeric_limits<double>::max();
72 
74  double targetTolerance = 1_um;
75 
78  bool debug = true;
79  std::string debugString = "";
81  size_t debugPfxWidth = 30;
82  size_t debugMsgWidth = 50;
83  };
84 
87 
90 
93 };
94 
96 struct Stepper {};
97 
100 struct Result {};
101 
102 // This tests the implementation of the AbortList
103 // and the standard aborters
104 BOOST_AUTO_TEST_CASE(AbortListTest_PathLimit) {
105  PropagatorState state;
106  state.options.pathLimit = 1_m;
108  Result result;
109 
110  AbortList<PathLimit> abortList;
111  abortList.get<PathLimit>().internalLimit = state.options.pathLimit;
112 
113  // It should not abort yet
114  BOOST_CHECK(!abortList(result, state, stepper));
115  // The step size should be adapted to 1 meter now
116  BOOST_CHECK_EQUAL(state.stepping.stepSize, 1_m);
117  // Let's do a step of 90 cm now
118  state.stepping.pathAccumulated = 90_cm;
119  // Still no abort yet
120  BOOST_CHECK(!abortList(result, state, stepper));
121  // 10 cm are left
122  // The step size should be adapted to 10 cm now
123  BOOST_CHECK_EQUAL(state.stepping.stepSize, 10_cm);
124 
125  // Approach the target
126  while (!abortList(result, state, stepper)) {
127  state.stepping.pathAccumulated += 0.5 * state.stepping.stepSize;
128  }
129 
130  // now we need to be smaller than the tolerance
131  BOOST_CHECK_LT(state.stepping.stepSize, 1_um);
132 
133  // Check if you can expand the AbortList
134  EndOfWorld eow;
135  AbortList<PathLimit, EndOfWorld> pathWorld = abortList.append(eow);
136  auto& path = pathWorld.get<PathLimit>();
137  BOOST_CHECK(path(state, stepper));
138 }
139 
140 struct ActorA {
141  struct result_type {
142  int a_number{42};
143  };
144 
145  template <typename propagator_state_t, typename stepper_t>
146  void operator()(propagator_state_t&, const stepper_t&, result_type&) const {}
147 };
148 
149 struct ActorB {
150  struct result_type {
151  int a_number{42};
152  };
153 
154  template <typename propagator_state_t, typename stepper_t>
155  void operator()(propagator_state_t&, const stepper_t&, result_type&) const {}
156 };
157 
160 
161  template <typename propagator_state_t, typename stepper_t, typename result_t>
162  bool operator()(const propagator_state_t&, const stepper_t&,
163  const result_t&) const {
164  return true;
165  }
166 };
167 
170 
171  template <typename propagator_state_t, typename stepper_t>
172  bool operator()(const propagator_state_t&, const stepper_t&) const {
173  return true;
174  }
175 };
176 
179 
180  template <typename propagator_state_t, typename stepper_t, typename result_t>
181  bool operator()(const propagator_state_t&, const stepper_t&,
182  const result_t&) const {
183  return true;
184  }
185 
186  template <typename propagator_state_t, typename stepper_t>
187  bool operator()(const propagator_state_t&, const stepper_t&) const {
188  return true;
189  }
190 };
191 
193  template <typename propagator_state_t, typename stepper_t>
194  bool operator()(const propagator_state_t&, const stepper_t&) const {
195  return true;
196  }
197 };
198 
200  template <typename propagator_state_t, typename stepper_t, typename result_t>
201  bool operator()(const propagator_state_t&, const stepper_t&,
202  const result_t&) const {
203  return true;
204  }
205 };
206 
207 template <typename P, typename S, typename... As>
208 constexpr bool signature_check =
209  detail::all_of_v<concept ::abort_condition_signature_check_v<As, P, S>...>;
210 
211 BOOST_AUTO_TEST_CASE(AbortListSignatureTest) {
212  using P = PropagatorState;
213  using S = Stepper;
214 
215  static_assert(signature_check<P, S, AborterWithoutResult>, "failed");
216  static_assert(signature_check<P, S, AborterWithResultA>, "failed");
217  static_assert(signature_check<P, S, AborterWithResultB>, "failed");
218 
219  // combination of two valid aborters
222  "failed");
223 
224  // declares an `action_type`, but call operator is invalid since it has no
225  // result argument
226  static_assert(!signature_check<P, S, AborterWithResultInvalid>, "failed");
227  // does not declare an `action_type` but the call operator expects a result
228  // argument
229  static_assert(!signature_check<P, S, AborterWithoutResultInvalid>, "failed");
230 }
231 
232 } // namespace Test
233 
234 } // namespace Acts