EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LoopProtectionTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file LoopProtectionTests.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 
23 #include "Acts/Utilities/Units.hpp"
24 
25 namespace bdata = boost::unit_test::data;
26 namespace tt = boost::test_tools;
27 using namespace Acts::UnitLiterals;
28 
29 namespace Acts {
30 
31 using namespace detail;
32 
33 namespace Test {
34 
35 // Create a test context
38 
40 struct SteppingState {
42  Vector3D pos = Vector3D(0., 0., 0.);
43  Vector3D dir = Vector3D(0., 0., 1);
44  double p = 100_MeV;
45 
47 };
48 
50 struct Stepper {
51  Vector3D field = Vector3D(0., 0., 2_T);
52 
60  Vector3D getField(SteppingState& /*unused*/,
61  const Vector3D& /*unused*/) const {
62  // get the field from the cell
63  return field;
64  }
65 
67  Vector3D position(const SteppingState& state) const { return state.pos; }
68 
70  Vector3D direction(const SteppingState& state) const { return state.dir; }
71 
73  double momentum(const SteppingState& state) const { return state.p; }
74 };
75 
78  bool navigationBreak = false;
79 };
80 
82 struct Options {
84  double pathLimit = std::numeric_limits<double>::max();
85  bool loopProtection = true;
86  double loopFraction = 0.5;
87 
88  bool debug = false;
89  std::string debugString;
90  int debugMsgWidth = 60;
91  int debugPfxWidth = 30;
92 
95 
97 };
98 
100 struct PropagatorState {
107 };
108 
109 // This test case checks that no segmentation fault appears
110 // - this tests the collection of surfaces
112  loop_aborter_test,
113  bdata::random(
114  (bdata::seed = 21,
115  bdata::distribution = std::uniform_real_distribution<>(-M_PI, M_PI))) ^
116  bdata::random((bdata::seed = 22,
117  bdata::distribution =
118  std::uniform_real_distribution<>(-M_PI, M_PI))) ^
119  bdata::xrange(1),
120  phi, deltaPhi, index) {
121  (void)index;
122  (void)deltaPhi;
123 
124  PropagatorState pState;
125  pState.stepping.dir = Vector3D(cos(phi), sin(phi), 0.);
126  pState.stepping.p = 100_MeV;
127 
128  Stepper pStepper;
129 
130  auto initialLimit =
131  pState.options.abortList.get<PathLimitReached>().internalLimit;
132 
134  lProtection(pState, pStepper);
135 
136  auto updatedLimit =
137  pState.options.abortList.get<PathLimitReached>().internalLimit;
138  BOOST_CHECK_LT(updatedLimit, initialLimit);
139 }
140 
141 using BField = ConstantBField;
144 
145 const int ntests = 100;
146 const int skip = 0;
147 
148 // This test case checks that the propagator with loop LoopProtection
149 // stops where expected
151  propagator_loop_protection_test,
152  bdata::random((bdata::seed = 20,
153  bdata::distribution =
154  std::uniform_real_distribution<>(0.5_GeV, 10_GeV))) ^
155  bdata::random((bdata::seed = 21,
156  bdata::distribution =
157  std::uniform_real_distribution<>(-M_PI, M_PI))) ^
158  bdata::random((bdata::seed = 22,
159  bdata::distribution =
160  std::uniform_real_distribution<>(1.0, M_PI - 1.0))) ^
161  bdata::random(
162  (bdata::seed = 23,
163  bdata::distribution = std::uniform_int_distribution<>(0, 1))) ^
165  pT, phi, theta, charge, index) {
166  if (index < skip) {
167  return;
168  }
169 
170  double px = pT * cos(phi);
171  double py = pT * sin(phi);
172  double pz = pT / tan(theta);
173  double p = pT / sin(theta);
174  double q = -1 + 2 * charge;
175 
176  const double Bz = 2_T;
177  BField bField(0, 0, Bz);
178  EigenStepper estepper(bField);
179  EigenPropagator epropagator(std::move(estepper));
180 
181  // define start parameters
182  CurvilinearTrackParameters start(Vector4D(0, 0, 0, 42), phi, theta, p, q);
183 
186  options.maxSteps = 1e6;
187  const auto& result = epropagator.propagate(start, options).value();
188 
189  // this test assumes state.options.loopFraction = 0.5
190  CHECK_CLOSE_REL(px, -result.endParameters->momentum().x(), 1e-2);
191  CHECK_CLOSE_REL(py, -result.endParameters->momentum().y(), 1e-2);
192  CHECK_CLOSE_REL(pz, result.endParameters->momentum().z(), 1e-2);
193 }
194 
195 } // namespace Test
196 } // namespace Acts