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 
85  };
86 
89 
92 
95 };
96 
98 struct Stepper {};
99 
102 struct Result {};
103 
104 // This tests the implementation of the AbortList
105 // and the standard aborters
106 BOOST_AUTO_TEST_CASE(AbortListTest_PathLimit) {
107  PropagatorState state;
108  state.options.pathLimit = 1_m;
110  Result result;
111 
112  AbortList<PathLimit> abortList;
113  abortList.get<PathLimit>().internalLimit = state.options.pathLimit;
114 
115  // It should not abort yet
116  BOOST_CHECK(!abortList(result, state, stepper));
117  // The step size should be adapted to 1 meter now
118  BOOST_CHECK_EQUAL(state.stepping.stepSize, 1_m);
119  // Let's do a step of 90 cm now
120  state.stepping.pathAccumulated = 90_cm;
121  // Still no abort yet
122  BOOST_CHECK(!abortList(result, state, stepper));
123  // 10 cm are left
124  // The step size should be adapted to 10 cm now
125  BOOST_CHECK_EQUAL(state.stepping.stepSize, 10_cm);
126 
127  // Approach the target
128  while (!abortList(result, state, stepper)) {
129  state.stepping.pathAccumulated += 0.5 * state.stepping.stepSize;
130  }
131 
132  // now we need to be smaller than the tolerance
133  BOOST_CHECK_LT(state.stepping.stepSize, 1_um);
134 
135  // Check if you can expand the AbortList
136  EndOfWorld eow;
137  AbortList<PathLimit, EndOfWorld> pathWorld = abortList.append(eow);
138  auto& path = pathWorld.get<PathLimit>();
139  BOOST_CHECK(path(state, stepper));
140 }
141 
142 struct ActorA {
143  struct result_type {
144  int a_number{42};
145  };
146 
147  template <typename propagator_state_t, typename stepper_t>
148  void operator()(propagator_state_t&, const stepper_t&, result_type&) const {}
149 };
150 
151 struct ActorB {
152  struct result_type {
153  int a_number{42};
154  };
155 
156  template <typename propagator_state_t, typename stepper_t>
157  void operator()(propagator_state_t&, const stepper_t&, result_type&) const {}
158 };
159 
162 
163  template <typename propagator_state_t, typename stepper_t, typename result_t>
164  bool operator()(const propagator_state_t&, const stepper_t&,
165  const result_t&) const {
166  return true;
167  }
168 };
169 
172 
173  template <typename propagator_state_t, typename stepper_t>
174  bool operator()(const propagator_state_t&, const stepper_t&) const {
175  return true;
176  }
177 };
178 
181 
182  template <typename propagator_state_t, typename stepper_t, typename result_t>
183  bool operator()(const propagator_state_t&, const stepper_t&,
184  const result_t&) const {
185  return true;
186  }
187 
188  template <typename propagator_state_t, typename stepper_t>
189  bool operator()(const propagator_state_t&, const stepper_t&) const {
190  return true;
191  }
192 };
193 
195  template <typename propagator_state_t, typename stepper_t>
196  bool operator()(const propagator_state_t&, const stepper_t&) const {
197  return true;
198  }
199 };
200 
202  template <typename propagator_state_t, typename stepper_t, typename result_t>
203  bool operator()(const propagator_state_t&, const stepper_t&,
204  const result_t&) const {
205  return true;
206  }
207 };
208 
209 template <typename P, typename S, typename... As>
210 constexpr bool signature_check =
211  detail::all_of_v<Concepts ::abort_condition_signature_check_v<As, P, S>...>;
212 
213 BOOST_AUTO_TEST_CASE(AbortListSignatureTest) {
214  using P = PropagatorState;
215  using S = Stepper;
216 
217  static_assert(signature_check<P, S, AborterWithoutResult>, "failed");
218  static_assert(signature_check<P, S, AborterWithResultA>, "failed");
219  static_assert(signature_check<P, S, AborterWithResultB>, "failed");
220 
221  // combination of two valid aborters
224  "failed");
225 
226  // declares an `action_type`, but call operator is invalid since it has no
227  // result argument
228  static_assert(!signature_check<P, S, AborterWithResultInvalid>, "failed");
229  // does not declare an `action_type` but the call operator expects a result
230  // argument
231  static_assert(!signature_check<P, S, AborterWithoutResultInvalid>, "failed");
232 }
233 
234 } // namespace Test
235 
236 } // namespace Acts