Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:11:18

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