Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-03 07:53:23

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/unit_test.hpp>
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Detector/detail/IndexedSurfacesGenerator.hpp"
0013 #include "Acts/Detector/detail/ReferenceGenerators.hpp"
0014 #include "Acts/Geometry/GeometryContext.hpp"
0015 #include "Acts/Geometry/LayerCreator.hpp"
0016 #include "Acts/Navigation/InternalNavigation.hpp"
0017 #include "Acts/Navigation/NavigationDelegates.hpp"
0018 #include "Acts/Navigation/NavigationStateUpdaters.hpp"
0019 #include "Acts/Surfaces/DiscSurface.hpp"
0020 #include "Acts/Surfaces/RadialBounds.hpp"
0021 #include "Acts/Surfaces/Surface.hpp"
0022 #include "Acts/Tests/CommonHelpers/CylindricalTrackingGeometry.hpp"
0023 #include "Acts/Utilities/AxisDefinitions.hpp"
0024 #include "Acts/Utilities/BinningType.hpp"
0025 #include "Acts/Utilities/Delegate.hpp"
0026 #include "Acts/Utilities/Enumerate.hpp"
0027 #include "Acts/Utilities/Grid.hpp"
0028 #include "Acts/Utilities/ProtoAxis.hpp"
0029 
0030 #include <array>
0031 #include <cmath>
0032 #include <cstddef>
0033 #include <memory>
0034 #include <numbers>
0035 #include <set>
0036 #include <tuple>
0037 #include <utility>
0038 #include <vector>
0039 
0040 using namespace Acts;
0041 using namespace Acts::Test;
0042 using namespace Acts::Experimental;
0043 using namespace Acts::Experimental::detail;
0044 
0045 GeometryContext tContext;
0046 CylindricalTrackingGeometry cGeometry = CylindricalTrackingGeometry(tContext);
0047 
0048 BOOST_AUTO_TEST_SUITE(Detector)
0049 
0050 BOOST_AUTO_TEST_CASE(RingDisc1D) {
0051   // A single ring
0052   CylindricalTrackingGeometry::DetectorStore dStore;
0053   auto rSurfaces = cGeometry.surfacesRing(dStore, 6.4, 12.4, 36., 0.125, 0.,
0054                                           55., 0., 2., 22u);
0055   // Polyhedron reference generator
0056   PolyhedronReferenceGenerator<1u, true> rGenerator;
0057   // A single proto axis clused in phi with 44 bins
0058   DirectedProtoAxis pAxis(AxisDirection::AxisPhi, AxisBoundaryType::Closed,
0059                           -std::numbers::pi, std::numbers::pi, 44u);
0060 
0061   auto indexedRing =
0062       Acts::detail::IndexedSurfacesGenerator::createInternalNavigation<
0063           IndexedSurfacesNavigation, decltype(rSurfaces), decltype(rGenerator)>(
0064           tContext, rSurfaces, rGenerator, pAxis, 0u);
0065 
0066   using GridType =
0067       Grid<std::vector<std::size_t>,
0068            Axis<Acts::AxisType::Equidistant, Acts::AxisBoundaryType::Closed>>;
0069   using DelegateType =
0070       IndexedSurfacesAllPortalsNavigation<GridType, IndexedSurfacesNavigation>;
0071 
0072   const auto* instance = indexedRing.instance();
0073   auto castedDelegate = dynamic_cast<const DelegateType*>(instance);
0074 
0075   BOOST_REQUIRE_NE(castedDelegate, nullptr);
0076 
0077   const auto& chainedUpdaters = castedDelegate->updators;
0078   const auto& indexedSurfaces =
0079       std::get<IndexedSurfacesNavigation<GridType>>(chainedUpdaters);
0080   const auto& grid = indexedSurfaces.grid;
0081 
0082   // Check that surfaces 10, 11, 12 build the bins at phi == 0
0083   std::vector<std::size_t> reference = {10, 11, 12};
0084   GridType::point_t p = {0.05};
0085 
0086   BOOST_CHECK(grid.atPosition(p) == reference);
0087 
0088   // Check that surfaces 0, 1, 21 build the bins at phi == -pi + epsilon
0089   reference = {0, 1, 21};
0090   p = {-std::numbers::pi + 0.05};
0091   BOOST_CHECK(grid.atPosition(p) == reference);
0092 }
0093 
0094 BOOST_AUTO_TEST_CASE(RingDisc1DWithSupport) {
0095   // A single ring
0096   CylindricalTrackingGeometry::DetectorStore dStore;
0097   auto rSurfaces = cGeometry.surfacesRing(dStore, 6.4, 12.4, 36., 0.125, 0.,
0098                                           55., 0., 2., 22u);
0099 
0100   auto rBounds = std::make_shared<RadialBounds>(10., 20.);
0101   auto dSurface = Surface::makeShared<DiscSurface>(Transform3::Identity(),
0102                                                    std::move(rBounds));
0103   rSurfaces.push_back(dSurface.get());
0104 
0105   // Polyhedron reference generator
0106   PolyhedronReferenceGenerator<1u, true> rGenerator;
0107   // A single proto axis clused in phi with 44 bins
0108   DirectedProtoAxis pAxis(AxisDirection::AxisPhi, AxisBoundaryType::Closed,
0109                           -std::numbers::pi, std::numbers::pi, 44u);
0110   auto indexedRing =
0111       Acts::detail::IndexedSurfacesGenerator::createInternalNavigation<
0112           Experimental::IndexedSurfacesNavigation>(
0113           tContext, rSurfaces, rGenerator, pAxis, 0u, {rSurfaces.size() - 1u});
0114 
0115   using GridType =
0116       Grid<std::vector<std::size_t>,
0117            Axis<Acts::AxisType::Equidistant, Acts::AxisBoundaryType::Closed>>;
0118 
0119   using DelegateType =
0120       IndexedSurfacesAllPortalsNavigation<GridType, IndexedSurfacesNavigation>;
0121 
0122   const auto* instance = indexedRing.instance();
0123   auto castedDelegate = dynamic_cast<const DelegateType*>(instance);
0124 
0125   BOOST_REQUIRE_NE(castedDelegate, nullptr);
0126 
0127   const auto& chainedUpdaters = castedDelegate->updators;
0128   const auto& indexedSurfaces =
0129       std::get<IndexedSurfacesNavigation<GridType>>(chainedUpdaters);
0130   const auto& grid = indexedSurfaces.grid;
0131 
0132   // Check that surfaces 10, 11, 12 build the bins at phi == 0
0133   // Support disk now appears as 22
0134   std::vector<std::size_t> reference = {10, 11, 12, 22};
0135   GridType::point_t p = {0.05};
0136   BOOST_CHECK(grid.atPosition(p) == reference);
0137 
0138   // Check that surfaces 0, 1, 21 build the bins at phi == -pi + epsilon
0139   reference = {0, 1, 21, 22};
0140   p = {-std::numbers::pi + 0.05};
0141   BOOST_CHECK(grid.atPosition(p) == reference);
0142 }
0143 
0144 BOOST_AUTO_TEST_CASE(RingDisc2D) {
0145   // Two rings to make a disc
0146   CylindricalTrackingGeometry::DetectorStore dStore;
0147   auto rSurfacesR0 = cGeometry.surfacesRing(dStore, 6.4, 12.4, 18., 0.125, 0.,
0148                                             42., 0., 2., 22u);
0149 
0150   auto rSurfacesR1 = cGeometry.surfacesRing(dStore, 12.4, 20.4, 30., 0.125, 0.,
0151                                             80., 0., 2., 22u);
0152 
0153   decltype(rSurfacesR0) rSurfaces = rSurfacesR0;
0154   rSurfaces.insert(rSurfaces.end(), rSurfacesR1.begin(), rSurfacesR1.end());
0155 
0156   DirectedProtoAxis pAxisR(AxisDirection::AxisR, AxisBoundaryType::Bound,
0157                            {24., 74., 110});
0158   DirectedProtoAxis pAxisPhi(AxisDirection::AxisPhi, AxisBoundaryType::Closed,
0159                              -std::numbers::pi, std::numbers::pi, 44u);
0160 
0161   PolyhedronReferenceGenerator<1u, true> rGenerator;
0162 
0163   auto indexedRing =
0164       Acts::detail::IndexedSurfacesGenerator::createInternalNavigation<
0165           Experimental::IndexedSurfacesNavigation>(
0166           tContext, rSurfaces, rGenerator, pAxisR, 0u, pAxisPhi, 0u);
0167 
0168   using GridType =
0169       Grid<std::vector<std::size_t>,
0170            Axis<Acts::AxisType::Variable, Acts::AxisBoundaryType::Bound>,
0171            Axis<Acts::AxisType::Equidistant, Acts::AxisBoundaryType::Closed>>;
0172 
0173   using DelegateType =
0174       IndexedSurfacesAllPortalsNavigation<GridType, IndexedSurfacesNavigation>;
0175 
0176   const auto* instance = indexedRing.instance();
0177   auto castedDelegate = dynamic_cast<const DelegateType*>(instance);
0178 
0179   BOOST_REQUIRE_NE(castedDelegate, nullptr);
0180 
0181   const auto& chainedUpdaters = castedDelegate->updators;
0182   const auto& indexedSurfaces =
0183       std::get<IndexedSurfacesNavigation<GridType>>(chainedUpdaters);
0184   const auto& grid = indexedSurfaces.grid;
0185 
0186   // Check that now two rows of surfaces are given
0187   std::vector<std::size_t> reference = {16, 17, 38, 39};
0188   GridType::point_t p = {65., std::numbers::pi * 0.49};
0189   BOOST_CHECK(grid.atPosition(p) == reference);
0190 }
0191 
0192 BOOST_AUTO_TEST_CASE(RingDisc2DFine) {
0193   // Three rings to make a disc
0194   CylindricalTrackingGeometry::DetectorStore dStore;
0195   auto rSurfacesR0 = cGeometry.surfacesRing(dStore, 6.4, 12.4, 18., 0.125, 0.,
0196                                             42., 0., 2., 22u);
0197 
0198   auto rSurfacesR1 = cGeometry.surfacesRing(dStore, 12.4, 20.4, 30., 0.125, 0.,
0199                                             80., 0., 2., 22u);
0200 
0201   auto rSurfacesR2 = cGeometry.surfacesRing(dStore, 18.4, 28.4, 30., 0.125, 0.,
0202                                             122., 0., 2., 36u);
0203 
0204   decltype(rSurfacesR0) rSurfaces = rSurfacesR0;
0205   rSurfaces.insert(rSurfaces.end(), rSurfacesR1.begin(), rSurfacesR1.end());
0206   rSurfaces.insert(rSurfaces.end(), rSurfacesR2.begin(), rSurfacesR2.end());
0207 
0208   DirectedProtoAxis pAxisR(AxisDirection::AxisR, AxisBoundaryType::Bound, 24.,
0209                            152, 8u);
0210   DirectedProtoAxis pAxisPhi(AxisDirection::AxisPhi, AxisBoundaryType::Closed,
0211                              -std::numbers::pi, std::numbers::pi, 88u);
0212 
0213   PolyhedronReferenceGenerator<1u, true> rGenerator;
0214 
0215   auto indexedRing =
0216       Acts::detail::IndexedSurfacesGenerator::createInternalNavigation<
0217           Experimental::IndexedSurfacesNavigation>(
0218           tContext, rSurfaces, rGenerator, pAxisR, 0u, pAxisPhi, 0u);
0219 
0220   using GridType =
0221       Grid<std::vector<std::size_t>,
0222            Axis<Acts::AxisType::Equidistant, Acts::AxisBoundaryType::Bound>,
0223            Axis<Acts::AxisType::Equidistant, Acts::AxisBoundaryType::Closed>>;
0224 
0225   using DelegateType =
0226       IndexedSurfacesAllPortalsNavigation<GridType, IndexedSurfacesNavigation>;
0227 
0228   const auto* instance = indexedRing.instance();
0229   auto castedDelegate = dynamic_cast<const DelegateType*>(instance);
0230 
0231   BOOST_REQUIRE_NE(castedDelegate, nullptr);
0232 
0233   const auto& chainedUpdaters = castedDelegate->updators;
0234   const auto& indexedSurfaces =
0235       std::get<IndexedSurfacesNavigation<GridType>>(chainedUpdaters);
0236   const auto& grid = indexedSurfaces.grid;
0237 
0238   // Fine binning created fewer candidates
0239   std::vector<std::size_t> reference = {38, 39};
0240   GridType::point_t p = {80., std::numbers::pi * 0.49};
0241   BOOST_CHECK(grid.atPosition(p) == reference);
0242 }
0243 
0244 BOOST_AUTO_TEST_CASE(RingDisc2DFineExpanded) {
0245   // Three rings to make a disc
0246   CylindricalTrackingGeometry::DetectorStore dStore;
0247   auto rSurfacesR0 = cGeometry.surfacesRing(dStore, 6.4, 12.4, 18., 0.125, 0.,
0248                                             42., 0., 2., 22u);
0249 
0250   auto rSurfacesR1 = cGeometry.surfacesRing(dStore, 12.4, 20.4, 30., 0.125, 0.,
0251                                             80., 0., 2., 22u);
0252 
0253   auto rSurfacesR2 = cGeometry.surfacesRing(dStore, 18.4, 28.4, 30., 0.125, 0.,
0254                                             122., 0., 2., 36u);
0255 
0256   decltype(rSurfacesR0) rSurfaces = rSurfacesR0;
0257   rSurfaces.insert(rSurfaces.end(), rSurfacesR1.begin(), rSurfacesR1.end());
0258   rSurfaces.insert(rSurfaces.end(), rSurfacesR2.begin(), rSurfacesR2.end());
0259 
0260   PolyhedronReferenceGenerator<1u, true> rGenerator;
0261 
0262   DirectedProtoAxis pAxisR(AxisDirection::AxisR, AxisBoundaryType::Bound, 24.,
0263                            152, 8u);
0264   DirectedProtoAxis pAxisPhi(AxisDirection::AxisPhi, AxisBoundaryType::Closed,
0265                              -std::numbers::pi, std::numbers::pi, 88u);
0266 
0267   auto indexedRing =
0268       Acts::detail::IndexedSurfacesGenerator::createInternalNavigation<
0269           Experimental::IndexedSurfacesNavigation>(
0270           tContext, rSurfaces, rGenerator, pAxisR, 2u, pAxisPhi, 4u);
0271 
0272   using GridType =
0273       Grid<std::vector<std::size_t>,
0274            Axis<Acts::AxisType::Equidistant, Acts::AxisBoundaryType::Bound>,
0275            Axis<Acts::AxisType::Equidistant, Acts::AxisBoundaryType::Closed>>;
0276 
0277   using DelegateType =
0278       IndexedSurfacesAllPortalsNavigation<GridType, IndexedSurfacesNavigation>;
0279 
0280   const auto* instance = indexedRing.instance();
0281   auto castedDelegate = dynamic_cast<const DelegateType*>(instance);
0282 
0283   BOOST_REQUIRE_NE(castedDelegate, nullptr);
0284 
0285   const auto& chainedUpdaters = castedDelegate->updators;
0286   const auto& indexedSurfaces =
0287       std::get<IndexedSurfacesNavigation<GridType>>(chainedUpdaters);
0288   const auto& grid = indexedSurfaces.grid;
0289 
0290   // Bin expansion created again more elements
0291   std::vector<std::size_t> reference = {38, 39};
0292   GridType::point_t p = {80., std::numbers::pi * 0.49};
0293   BOOST_CHECK_GT(grid.atPosition(p).size(), 2u);
0294 }
0295 
0296 BOOST_AUTO_TEST_CASE(Cylinder2D) {
0297   CylindricalTrackingGeometry::DetectorStore dStore;
0298   auto surfaces = cGeometry.surfacesCylinder(dStore, 8.4, 36., 0.15, 0.145,
0299                                              116., 3., 2., {52, 14});
0300 
0301   DirectedProtoAxis pAxisZ(AxisDirection::AxisZ, AxisBoundaryType::Bound, -500.,
0302                            500., 28u);
0303   DirectedProtoAxis pAxisPhi(AxisDirection::AxisPhi, AxisBoundaryType::Closed,
0304                              -std::numbers::pi, std::numbers::pi, 52u);
0305   PolyhedronReferenceGenerator<1u, true> rGenerator;
0306 
0307   auto indexedCylinder =
0308       Acts::detail::IndexedSurfacesGenerator::createInternalNavigation<
0309           Experimental::IndexedSurfacesNavigation>(
0310           tContext, surfaces, rGenerator, pAxisZ, 1u, pAxisPhi, 1u);
0311 
0312   using GridType =
0313       Grid<std::vector<std::size_t>,
0314            Axis<Acts::AxisType::Equidistant, Acts::AxisBoundaryType::Bound>,
0315            Axis<Acts::AxisType::Equidistant, Acts::AxisBoundaryType::Closed>>;
0316 
0317   using DelegateType =
0318       IndexedSurfacesAllPortalsNavigation<GridType, IndexedSurfacesNavigation>;
0319 
0320   const auto* instance = indexedCylinder.instance();
0321   auto castedDelegate = dynamic_cast<const DelegateType*>(instance);
0322 
0323   BOOST_REQUIRE_NE(castedDelegate, nullptr);
0324 
0325   const auto& chainedUpdaters = castedDelegate->updators;
0326   const auto& indexedSurfaces =
0327       std::get<IndexedSurfacesNavigation<GridType>>(chainedUpdaters);
0328   const auto& grid = indexedSurfaces.grid;
0329 
0330   // Bin expansion created again more elements
0331   std::vector<std::size_t> reference = {676, 677, 725, 726, 727};
0332   GridType::point_t p = {490., std::numbers::pi * 0.99};
0333   BOOST_CHECK(grid.atPosition(p) == reference);
0334 }
0335 
0336 BOOST_AUTO_TEST_SUITE_END()