Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-23 08:24:03

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