Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NavigationStateUpdatorsTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file NavigationStateUpdatorsTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2022 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/unit_test.hpp>
10 
17 #include "Acts/Utilities/IAxis.hpp"
19 
20 #include <algorithm>
21 #include <array>
22 #include <cstddef>
23 #include <memory>
24 #include <tuple>
25 #include <utility>
26 #include <vector>
27 
28 #include "../Surfaces/SurfaceStub.hpp"
29 
30 // A test context
32 
33 namespace Acts {
34 
35 namespace Experimental {
36 
37 class Detector;
38 
40 class DetectorVolume {
41  public:
42  const Detector* d = nullptr;
43  std::vector<const Surface*> sfs = {};
44  std::vector<const Portal*> prts = {};
45  const std::vector<const Surface*> surfaces() const { return sfs; }
46  const std::vector<const Portal*> portals() const { return prts; }
47  const Detector* detector() const { return d; };
48 };
49 
51 class Detector {
52  public:
53  std::vector<const DetectorVolume*> vs = {};
54  const std::vector<const DetectorVolume*> volumes() const { return vs; }
55 };
56 
58 struct AllPortalsExtractor {
64  inline static const std::vector<const Portal*> extract(
65  [[maybe_unused]] const GeometryContext& gctx,
66  const NavigationState& nState,
67  [[maybe_unused]] const std::vector<size_t>& indices = {}) {
68  return nState.currentVolume->portals();
69  }
70 };
71 
73 struct AllSurfacesExtractor {
79  inline static const std::vector<const Surface*> extract(
80  [[maybe_unused]] const GeometryContext& gctx,
81  const NavigationState& nState,
82  [[maybe_unused]] const std::vector<size_t>& indices = {}) {
83  return nState.currentVolume->surfaces();
84  }
85 };
86 
88 struct IndexedSurfacesExtractor {
94  inline static const std::vector<const Surface*> extract(
95  [[maybe_unused]] const GeometryContext& gctx,
96  const NavigationState& nState, const std::vector<size_t>& indices) {
97  // Get the surface container
98  const auto& surfaces = nState.currentVolume->surfaces();
99  // The extracted surfaces
100  std::vector<const Surface*> eSurfaces;
101  eSurfaces.reserve(indices.size());
102  std::for_each(indices.begin(), indices.end(),
103  [&](const auto& i) { eSurfaces.push_back(surfaces[i]); });
104  return eSurfaces;
105  }
106 };
107 
108 } // namespace Experimental
109 
110 class TestAxis : public IAxis {
111  public:
112  bool isEquidistant() const final { return true; }
113 
114  bool isVariable() const final { return false; }
115 
117  return detail::AxisBoundaryType::Closed;
118  }
119 
120  std::vector<ActsScalar> getBinEdges() const final { return {-1, 1}; }
121 
122  ActsScalar getMin() const final { return -1.; }
123 
124  ActsScalar getMax() const final { return 1.; }
125 
126  size_t getNBins() const final { return 1; };
127 };
128 
129 class MultiGrid1D {
130  public:
131  static constexpr size_t DIM = 1u;
132 
133  const std::vector<size_t>& atPosition(
134  const std::array<ActsScalar, 1u>& /*position*/) const {
135  return e;
136  }
137 
138  std::array<const IAxis*, DIM> axes() const { return {&ta}; }
140 
141  private:
142  std::vector<size_t> e = {0u, 1u};
143 };
144 
145 class MultiGrid2D {
146  public:
147  static constexpr size_t DIM = 2u;
148 
149  const std::vector<size_t>& atPosition(
150  const std::array<ActsScalar, 2u>& /*position*/) const {
151  return e;
152  }
153 
154  std::array<const IAxis*, DIM> axes() const { return {&ta, &ta}; };
155  TestAxis ta;
156 
157  private:
158  std::vector<size_t> e = {1u};
159 };
160 } // namespace Acts
161 
165 
169 
172 
173 auto surfaceA = Acts::Surface::makeShared<Acts::SurfaceStub>();
174 auto surfaceB = Acts::Surface::makeShared<Acts::SurfaceStub>();
175 auto surfaceC = Acts::Surface::makeShared<Acts::SurfaceStub>();
176 
177 auto pSurfaceA = Acts::Surface::makeShared<Acts::SurfaceStub>();
178 auto pSurfaceB = Acts::Surface::makeShared<Acts::SurfaceStub>();
181 
182 BOOST_AUTO_TEST_SUITE(Experimental)
183 
184 BOOST_AUTO_TEST_CASE(SingleDetectorVolumeUpdator) {
186 
187  // Create a single object and a single object updator
188  auto sVolume = std::make_shared<Acts::Experimental::DetectorVolume>();
189  SingleVolumeUpdator sVolumeUpdator(sVolume.get());
190 
191  // Update the volume and check that it is indeed updated
192  sVolumeUpdator.update(tContext, nState);
193  BOOST_CHECK(nState.currentVolume == sVolume.get());
194 }
195 
196 BOOST_AUTO_TEST_CASE(AllSurfaces) {
197  // Create a single object and a single object updator
198  auto dVolume = std::make_shared<Acts::Experimental::DetectorVolume>();
199  (*dVolume).sfs = {surfaceA.get(), surfaceB.get(), surfaceC.get()};
200  (*dVolume).prts = {portalA.get(), portalB.get()};
201 
203  nState.currentVolume = dVolume.get();
204  BOOST_CHECK(nState.surfaceCandidates.empty());
205  AllSurfacesProvider allSurfaces;
206  allSurfaces.update(tContext, nState);
207  BOOST_CHECK(nState.surfaceCandidates.size() == 3u);
208 }
209 
210 BOOST_AUTO_TEST_CASE(AllPortals) {
211  // Create a single object and a single object updator
212  auto dVolume = std::make_shared<Acts::Experimental::DetectorVolume>();
213  (*dVolume).sfs = {surfaceA.get(), surfaceB.get(), surfaceC.get()};
214  (*dVolume).prts = {portalA.get(), portalB.get()};
215 
217  nState.currentVolume = dVolume.get();
218  BOOST_CHECK(nState.surfaceCandidates.empty());
219  AllPortalsProvider allPortals;
220  allPortals.update(tContext, nState);
221  BOOST_CHECK(nState.surfaceCandidates.size() == 2u);
222 }
223 
224 BOOST_AUTO_TEST_CASE(AllPortalsAllSurfaces) {
225  // Create a single object and a single object updator
226  auto dVolume = std::make_shared<Acts::Experimental::DetectorVolume>();
227  (*dVolume).sfs = {surfaceA.get(), surfaceB.get(), surfaceC.get()};
228  (*dVolume).prts = {portalA.get(), portalB.get()};
229 
231  nState.currentVolume = dVolume.get();
232  BOOST_CHECK(nState.surfaceCandidates.empty());
233 
234  AllPortalsProvider allPortals;
235  AllSurfacesProvider allSurfaces;
236  auto allPortalsAllSurfaces =
239  std::tie(allPortals, allSurfaces));
240 
241  allPortalsAllSurfaces.update(tContext, nState);
242  BOOST_CHECK(nState.surfaceCandidates.size() == 5u);
243 }
244 
245 BOOST_AUTO_TEST_CASE(AllPortalsGrid1DSurfaces) {
246  // Create a single object and a single object updator
247  auto dVolume = std::make_shared<Acts::Experimental::DetectorVolume>();
248  (*dVolume).sfs = {surfaceA.get(), surfaceB.get(), surfaceC.get()};
249  (*dVolume).prts = {portalA.get(), portalB.get()};
250 
252  nState.currentVolume = dVolume.get();
253  BOOST_CHECK(nState.surfaceCandidates.empty());
254 
255  AllPortalsProvider allPortals;
257  using Grid1DSurfacesProvider = Acts::Experimental::IndexedUpdatorImpl<
260  auto grid1DSurfaces = Grid1DSurfacesProvider(std::move(grid), {Acts::binR});
261 
262  auto allPortalsGrid1DSurfaces =
264  Grid1DSurfacesProvider>(
265  std::tie(allPortals, grid1DSurfaces));
266 
267  allPortalsGrid1DSurfaces.update(tContext, nState);
268  BOOST_CHECK(nState.surfaceCandidates.size() == 4u);
269 }
270 
271 BOOST_AUTO_TEST_CASE(AllPortalsGrid2DSurfaces) {
272  // Create a single object and a single object updator
273  auto dVolume = std::make_shared<Acts::Experimental::DetectorVolume>();
274  (*dVolume).sfs = {surfaceA.get(), surfaceB.get(), surfaceC.get()};
275  (*dVolume).prts = {portalA.get(), portalB.get()};
276 
278  nState.currentVolume = dVolume.get();
279  BOOST_CHECK(nState.surfaceCandidates.empty());
280 
281  AllPortalsProvider allPortals;
283  using Grid2DSurfacesProvider = Acts::Experimental::IndexedUpdatorImpl<
286  auto grid2DSurfaces =
287  Grid2DSurfacesProvider(std::move(grid), {Acts::binR, Acts::binZ});
288 
289  auto allPortalsGrid2DSurfaces =
291  Grid2DSurfacesProvider>(
292  std::tie(allPortals, grid2DSurfaces));
293 
294  allPortalsGrid2DSurfaces.update(tContext, nState);
295  BOOST_CHECK(nState.surfaceCandidates.size() == 3u);
296 }
297 
298 BOOST_AUTO_TEST_SUITE_END()