EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DirectNavigatorTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DirectNavigatorTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 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 
25 
26 #include <memory>
27 
28 namespace bdata = boost::unit_test::data;
29 namespace tt = boost::test_tools;
30 using namespace Acts::UnitLiterals;
31 
32 namespace Acts {
33 namespace Test {
34 
35 // Create a test context
38 
39 CylindricalTrackingGeometry cGeometry(tgContext);
41 
42 // Create a navigator for this tracking geometry
45 
50 
51 const double Bz = 2_T;
52 BField bField(0, 0, Bz);
55 
56 ReferencePropagator rpropagator(std::move(estepper), std::move(navigator));
57 DirectPropagator dpropagator(std::move(dstepper), std::move(dnavigator));
58 
59 const int ntests = 1000;
60 const int skip = 0;
61 bool debugMode = false;
62 bool referenceTiming = false;
63 bool oversteppingTest = false;
65 
79 template <typename rpropagator_t, typename dpropagator_t>
80 void runTest(const rpropagator_t& rprop, const dpropagator_t& dprop, double pT,
81  double phi, double theta, int charge, double time, int index) {
82  double dcharge = -1 + 2 * charge;
83 
84  if (index < skip) {
85  return;
86  }
87 
88  // Define start parameters from ranom input
89  double p = pT / sin(theta);
90  CurvilinearTrackParameters start(Vector4D(0, 0, 0, time), phi, theta,
91  dcharge / p);
92 
94 
95  // Action list and abort list
96  using RefereceActionList = ActionList<MaterialInteractor, SurfaceCollector<>>;
97  using ReferenceAbortList = AbortList<EndOfWorld>;
98 
99  // Options definition
102  if (oversteppingTest) {
103  pOptions.maxStepSize = oversteppingMaxStepSize;
104  }
105 
106  // Surface collector configuration
107  auto& sCollector = pOptions.actionList.template get<SurfaceCollector<>>();
108  sCollector.selector.selectSensitive = true;
109  sCollector.selector.selectMaterial = true;
110 
111  // Result is immediately used, non-valid result would indicate failure
112  const auto& pResult = rprop.propagate(start, pOptions).value();
113  auto& cSurfaces = pResult.template get<SurfaceCollector<>::result_type>();
114  auto& cMaterial = pResult.template get<MaterialInteractor::result_type>();
115  const Surface& destination = pResult.endParameters->referenceSurface();
116 
117  std::cout << " - the standard navigator yielded "
118  << cSurfaces.collected.size() << " collected surfaces" << std::endl;
119 
120  if (not referenceTiming) {
121  // Create the surface sequence
122  std::vector<const Surface*> surfaceSequence;
123  surfaceSequence.reserve(cSurfaces.collected.size());
124  for (auto& cs : cSurfaces.collected) {
125  surfaceSequence.push_back(cs.surface);
126  }
127 
128  // Action list for direct navigator with its initalizer
129  using DirectActionList = ActionList<DirectNavigator::Initializer,
131 
132  // Direct options definition
134  DirectOptions dOptions(tgContext, mfContext, getDummyLogger());
135  // Set the surface sequence
136  auto& dInitializer =
137  dOptions.actionList.get<DirectNavigator::Initializer>();
138  dInitializer.navSurfaces = surfaceSequence;
139  // Surface collector configuration
140  auto& dCollector = dOptions.actionList.template get<SurfaceCollector<>>();
141  dCollector.selector.selectSensitive = true;
142  dCollector.selector.selectMaterial = true;
143 
144  // Now redo the propagation with the direct propagator
145  const auto& ddResult =
146  dprop.propagate(start, destination, dOptions).value();
147  auto& ddSurfaces = ddResult.template get<SurfaceCollector<>::result_type>();
148  auto& ddMaterial = ddResult.template get<MaterialInteractor::result_type>();
149 
150  // CHECK if you have as many surfaces collected as the default navigator
151  BOOST_CHECK_EQUAL(cSurfaces.collected.size(), ddSurfaces.collected.size());
152  CHECK_CLOSE_REL(cMaterial.materialInX0, ddMaterial.materialInX0, 1e-3);
153 
154  // Now redo the propagation with the direct propagator - without destination
155  const auto& dwResult = dprop.propagate(start, dOptions).value();
156  auto& dwSurfaces = dwResult.template get<SurfaceCollector<>::result_type>();
157 
158  // CHECK if you have as many surfaces collected as the default navigator
159  BOOST_CHECK_EQUAL(cSurfaces.collected.size(), dwSurfaces.collected.size());
160  }
161 }
162 
163 // This test case checks that no segmentation fault appears
164 // - this tests the collection of surfaces
166  test_direct_navigator,
167  bdata::random((bdata::seed = 20,
168  bdata::distribution =
169  std::uniform_real_distribution<>(0.15_GeV, 10_GeV))) ^
170  bdata::random((bdata::seed = 21,
171  bdata::distribution =
172  std::uniform_real_distribution<>(-M_PI, M_PI))) ^
173  bdata::random((bdata::seed = 22,
174  bdata::distribution =
175  std::uniform_real_distribution<>(1.0, M_PI - 1.0))) ^
176  bdata::random(
177  (bdata::seed = 23,
178  bdata::distribution = std::uniform_int_distribution<>(0, 1))) ^
179  bdata::random(
180  (bdata::seed = 24,
181  bdata::distribution = std::uniform_int_distribution<>(0, 100))) ^
183  pT, phi, theta, charge, time, index) {
184  // Run the test
186 }
187 
188 } // namespace Test
189 } // namespace Acts