Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IndexedSurfacesGeneratorTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file IndexedSurfacesGeneratorTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2023 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 
29 
30 #include <array>
31 #include <cmath>
32 #include <cstddef>
33 #include <memory>
34 #include <set>
35 #include <tuple>
36 #include <utility>
37 #include <vector>
38 
39 using namespace Acts;
40 using namespace Acts::Test;
41 using namespace Acts::Experimental;
42 using namespace Acts::Experimental::detail;
43 
46 
47 BOOST_AUTO_TEST_SUITE(Detector)
48 
49 BOOST_AUTO_TEST_CASE(RingDisc1D) {
50  // A single ring
52  auto rSurfaces = cGeometry.surfacesRing(dStore, 6.4, 12.4, 36., 0.125, 0.,
53  55., 0., 2., 22u);
54 
56  rSurfaces, {}, {binPhi}};
57 
58  GridAxisGenerators::EqClosed aGenerator{{-M_PI, M_PI}, 44u};
60 
61  auto indexedRing = irSurfaces(tContext, aGenerator, rGenerator);
62 
63  using GridType = decltype(aGenerator)::grid_type<std::vector<std::size_t>>;
64  using DelegateType =
66 
67  const auto* instance = indexedRing.instance();
68  auto castedDelegate = dynamic_cast<const DelegateType*>(instance);
69 
70  BOOST_CHECK(castedDelegate != nullptr);
71 
72  const auto& chainedUpdators = castedDelegate->updators;
73  const auto& indexedSurfaces =
74  std::get<IndexedSurfacesImpl<GridType>>(chainedUpdators);
75  const auto& grid = indexedSurfaces.grid;
76 
77  // Check that surfaces 10, 11, 12 build the bins at phi == 0
78  std::vector<size_t> reference = {10, 11, 12};
79  GridType::point_t p = {0.05};
80 
81  BOOST_CHECK(grid.atPosition(p) == reference);
82 
83  // Check that surfaces 0, 1, 21 build the bins at phi == -M_PI + epsilon
84  reference = {0, 1, 21};
85  p = {-M_PI + 0.05};
86  BOOST_CHECK(grid.atPosition(p) == reference);
87 }
88 
89 BOOST_AUTO_TEST_CASE(RingDisc1DWithSupport) {
90  // A single ring
92  auto rSurfaces = cGeometry.surfacesRing(dStore, 6.4, 12.4, 36., 0.125, 0.,
93  55., 0., 2., 22u);
94 
95  auto rBounds = std::make_shared<RadialBounds>(20., 20.);
96  auto dSurface = Surface::makeShared<DiscSurface>(Transform3::Identity(),
98  rSurfaces.push_back(dSurface.get());
99 
101  rSurfaces, {rSurfaces.size() - 1u}, {binPhi}};
102 
103  GridAxisGenerators::EqClosed aGenerator{{-M_PI, M_PI}, 44u};
105 
106  auto indexedRing = irSurfaces(tContext, aGenerator, rGenerator);
107 
108  using GridType = decltype(aGenerator)::grid_type<std::vector<std::size_t>>;
109 
110  using DelegateType =
112 
113  const auto* instance = indexedRing.instance();
114  auto castedDelegate = dynamic_cast<const DelegateType*>(instance);
115 
116  BOOST_CHECK(castedDelegate != nullptr);
117 
118  const auto& chainedUpdators = castedDelegate->updators;
119  const auto& indexedSurfaces =
120  std::get<IndexedSurfacesImpl<GridType>>(chainedUpdators);
121  const auto& grid = indexedSurfaces.grid;
122 
123  // Check that surfaces 10, 11, 12 build the bins at phi == 0
124  // Support disk now appears as 22
125  std::vector<size_t> reference = {10, 11, 12, 22};
126  GridType::point_t p = {0.05};
127  BOOST_CHECK(grid.atPosition(p) == reference);
128 
129  // Check that surfaces 0, 1, 21 build the bins at phi == -M_PI + epsilon
130  reference = {0, 1, 21, 22};
131  p = {-M_PI + 0.05};
132  BOOST_CHECK(grid.atPosition(p) == reference);
133 }
134 
135 BOOST_AUTO_TEST_CASE(RingDisc2D) {
136  // Two rings to make a disc
138  auto rSurfacesR0 = cGeometry.surfacesRing(dStore, 6.4, 12.4, 18., 0.125, 0.,
139  42., 0., 2., 22u);
140 
141  auto rSurfacesR1 = cGeometry.surfacesRing(dStore, 12.4, 20.4, 30., 0.125, 0.,
142  80., 0., 2., 22u);
143 
144  decltype(rSurfacesR0) rSurfaces = rSurfacesR0;
145  rSurfaces.insert(rSurfaces.end(), rSurfacesR1.begin(), rSurfacesR1.end());
146 
148  rSurfaces, {}, {binR, binPhi}};
149 
151  {24., 74., 110.}, {-M_PI, M_PI}, 44u};
153 
154  auto indexedRing = irSurfaces(tContext, aGenerator, rGenerator);
155 
156  using GridType = decltype(aGenerator)::grid_type<std::vector<std::size_t>>;
157 
158  using DelegateType =
160 
161  const auto* instance = indexedRing.instance();
162  auto castedDelegate = dynamic_cast<const DelegateType*>(instance);
163 
164  BOOST_CHECK(castedDelegate != nullptr);
165 
166  const auto& chainedUpdators = castedDelegate->updators;
167  const auto& indexedSurfaces =
168  std::get<IndexedSurfacesImpl<GridType>>(chainedUpdators);
169  const auto& grid = indexedSurfaces.grid;
170 
171  // Check that now two rows of surfaces are given
172  std::vector<size_t> reference = {16, 17, 38, 39};
173  GridType::point_t p = {65., M_PI * 0.49};
174  BOOST_CHECK(grid.atPosition(p) == reference);
175 }
176 
177 BOOST_AUTO_TEST_CASE(RingDisc2DFine) {
178  // Three rings to make a disc
180  auto rSurfacesR0 = cGeometry.surfacesRing(dStore, 6.4, 12.4, 18., 0.125, 0.,
181  42., 0., 2., 22u);
182 
183  auto rSurfacesR1 = cGeometry.surfacesRing(dStore, 12.4, 20.4, 30., 0.125, 0.,
184  80., 0., 2., 22u);
185 
186  auto rSurfacesR2 = cGeometry.surfacesRing(dStore, 18.4, 28.4, 30., 0.125, 0.,
187  122., 0., 2., 36u);
188 
189  decltype(rSurfacesR0) rSurfaces = rSurfacesR0;
190  rSurfaces.insert(rSurfaces.end(), rSurfacesR1.begin(), rSurfacesR1.end());
191  rSurfaces.insert(rSurfaces.end(), rSurfacesR2.begin(), rSurfacesR2.end());
192 
194  rSurfaces, {}, {binR, binPhi}};
195 
197  {24., 152}, 8u, {-M_PI, M_PI}, 88u};
198 
200 
201  auto indexedRing = irSurfaces(tContext, aGenerator, rGenerator);
202 
203  using GridType = decltype(aGenerator)::grid_type<std::vector<std::size_t>>;
204 
205  using DelegateType =
207 
208  const auto* instance = indexedRing.instance();
209  auto castedDelegate = dynamic_cast<const DelegateType*>(instance);
210 
211  BOOST_CHECK(castedDelegate != nullptr);
212 
213  const auto& chainedUpdators = castedDelegate->updators;
214  const auto& indexedSurfaces =
215  std::get<IndexedSurfacesImpl<GridType>>(chainedUpdators);
216  const auto& grid = indexedSurfaces.grid;
217 
218  // Fine binning created fewer candidates
219  std::vector<size_t> reference = {38, 39};
220  GridType::point_t p = {80., M_PI * 0.49};
221  BOOST_CHECK(grid.atPosition(p) == reference);
222 }
223 
224 BOOST_AUTO_TEST_CASE(RingDisc2DFineExpanded) {
225  // Three rings to make a disc
227  auto rSurfacesR0 = cGeometry.surfacesRing(dStore, 6.4, 12.4, 18., 0.125, 0.,
228  42., 0., 2., 22u);
229 
230  auto rSurfacesR1 = cGeometry.surfacesRing(dStore, 12.4, 20.4, 30., 0.125, 0.,
231  80., 0., 2., 22u);
232 
233  auto rSurfacesR2 = cGeometry.surfacesRing(dStore, 18.4, 28.4, 30., 0.125, 0.,
234  122., 0., 2., 36u);
235 
236  decltype(rSurfacesR0) rSurfaces = rSurfacesR0;
237  rSurfaces.insert(rSurfaces.end(), rSurfacesR1.begin(), rSurfacesR1.end());
238  rSurfaces.insert(rSurfaces.end(), rSurfacesR2.begin(), rSurfacesR2.end());
239 
241  rSurfaces, {}, {binR, binPhi}, {2u, 4u}};
242 
244  {24., 152}, 8u, {-M_PI, M_PI}, 88u};
246 
247  auto indexedRing = irSurfaces(tContext, aGenerator, rGenerator);
248 
249  using GridType = decltype(aGenerator)::grid_type<std::vector<std::size_t>>;
250  using DelegateType =
252 
253  const auto* instance = indexedRing.instance();
254  auto castedDelegate = dynamic_cast<const DelegateType*>(instance);
255 
256  BOOST_CHECK(castedDelegate != nullptr);
257 
258  const auto& chainedUpdators = castedDelegate->updators;
259  const auto& indexedSurfaces =
260  std::get<IndexedSurfacesImpl<GridType>>(chainedUpdators);
261  const auto& grid = indexedSurfaces.grid;
262 
263  // Bin expansion created again more elements
264  std::vector<size_t> reference = {38, 39};
265  GridType::point_t p = {80., M_PI * 0.49};
266  BOOST_CHECK(grid.atPosition(p).size() > 2u);
267 }
268 
269 BOOST_AUTO_TEST_CASE(Cylinder2D) {
271  auto surfaces = cGeometry.surfacesCylinder(dStore, 8.4, 36., 0.15, 0.145,
272  116., 3., 2., {52, 14});
273 
275  surfaces, {}, {binZ, binPhi}, {1u, 1u}};
276 
278  {-500., 500}, 28, {-M_PI, M_PI}, 52u};
280 
281  auto indexedCylinder = icSurfaces(tContext, aGenerator, rGenerator);
282 
283  using GridType = decltype(aGenerator)::grid_type<std::vector<std::size_t>>;
284  using DelegateType =
286 
287  const auto* instance = indexedCylinder.instance();
288  auto castedDelegate = dynamic_cast<const DelegateType*>(instance);
289 
290  BOOST_CHECK(castedDelegate != nullptr);
291 
292  const auto& chainedUpdators = castedDelegate->updators;
293  const auto& indexedSurfaces =
294  std::get<IndexedSurfacesImpl<GridType>>(chainedUpdators);
295  const auto& grid = indexedSurfaces.grid;
296 
297  // Bin expansion created again more elements
298  std::vector<size_t> reference = {676, 677, 725, 726, 727};
299  GridType::point_t p = {490., M_PI * 0.99};
300  BOOST_CHECK(grid.atPosition(p) == reference);
301 }
302 
303 BOOST_AUTO_TEST_SUITE_END()