Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-12 07:53:02

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/DetectorComponents.hpp"
0013 #include "Acts/Detector/LayerStructureBuilder.hpp"
0014 #include "Acts/Detector/PortalGenerators.hpp"
0015 #include "Acts/Geometry/GeometryContext.hpp"
0016 #include "Acts/Geometry/LayerCreator.hpp"
0017 #include "Acts/Navigation/NavigationDelegates.hpp"
0018 #include "Acts/Surfaces/Surface.hpp"
0019 #include "Acts/Tests/CommonHelpers/CylindricalTrackingGeometry.hpp"
0020 #include "Acts/Utilities/BinningData.hpp"
0021 #include "Acts/Utilities/BinningType.hpp"
0022 #include "Acts/Utilities/Logger.hpp"
0023 
0024 #include <cmath>
0025 #include <functional>
0026 #include <memory>
0027 #include <numbers>
0028 #include <string>
0029 #include <vector>
0030 
0031 using namespace Acts;
0032 using namespace Acts::Test;
0033 using namespace Acts::Experimental;
0034 
0035 GeometryContext tContext;
0036 CylindricalTrackingGeometry cGeometry = CylindricalTrackingGeometry(tContext);
0037 
0038 namespace {
0039 /// Helper method that allows to use the already existing testing
0040 /// infrastructure with the new const-correct detector design
0041 ///
0042 std::vector<std::shared_ptr<Acts::Surface>> unpackSurfaces(
0043     const std::vector<const Acts::Surface*>& surfaces) {
0044   std::vector<std::shared_ptr<Acts::Surface>> uSurfaces;
0045   uSurfaces.reserve(surfaces.size());
0046   for (const auto& s : surfaces) {
0047     Surface* ncs = const_cast<Surface*>(s);
0048     uSurfaces.push_back(ncs->getSharedPtr());
0049   }
0050   return uSurfaces;
0051 }
0052 
0053 }  // namespace
0054 
0055 BOOST_AUTO_TEST_SUITE(Detector)
0056 
0057 // Test the creation of a ring like structure
0058 BOOST_AUTO_TEST_CASE(LayerStructureBuilder_creationRing) {
0059   // Detector store
0060   CylindricalTrackingGeometry::DetectorStore dStore;
0061   auto rSurfaces = cGeometry.surfacesRing(dStore, 6.4, 12.4, 36., 0.125, 0.,
0062                                           55., -800, 0., 22u);
0063 
0064   auto endcapSurfaces = std::make_shared<LayerStructureBuilder::SurfacesHolder>(
0065       unpackSurfaces(rSurfaces));
0066   // Configure the layer structure builder
0067   Acts::Experimental::LayerStructureBuilder::Config lsConfig;
0068   lsConfig.auxiliary = "*** Endcap with 22 surfaces ***";
0069   lsConfig.surfacesProvider = endcapSurfaces;
0070   lsConfig.binnings = {
0071       {DirectedProtoAxis(Acts::AxisDirection::AxisPhi,
0072                          Acts::AxisBoundaryType::Closed, -std::numbers::pi,
0073                          std::numbers::pi, 22u),
0074        1u}};
0075 
0076   auto endcapBuilder = Acts::Experimental::LayerStructureBuilder(
0077       lsConfig, Acts::getDefaultLogger("EndcapBuilder", Logging::VERBOSE));
0078 
0079   auto [surfaces0, volumes0, surfacesUpdater0, volumeUpdater0] =
0080       endcapBuilder.construct(tContext);
0081 
0082   BOOST_CHECK_EQUAL(surfaces0.size(), 22u);
0083   BOOST_CHECK(surfacesUpdater0.connected());
0084   BOOST_CHECK(volumes0.empty());
0085   BOOST_CHECK(volumeUpdater0.connected());
0086 
0087   // Define the layer support
0088   //
0089   // First test with one support disc
0090   using LayerSupport = Acts::Experimental::ProtoSupport;
0091   LayerSupport supportDisc;
0092   supportDisc.type = Acts::Surface::SurfaceType::Disc;
0093   supportDisc.offset = 15.;
0094   supportDisc.internalConstraints = {Acts::AxisDirection::AxisZ,
0095                                      Acts::AxisDirection::AxisR};
0096 
0097   lsConfig.auxiliary =
0098       "*** Endcap with 22 surfaces + 1 support disc, "
0099       "r/z - range/pos estimated from internals ***";
0100   lsConfig.supports = {supportDisc};
0101   endcapBuilder = Acts::Experimental::LayerStructureBuilder(
0102       lsConfig, Acts::getDefaultLogger("EndcapBuilder", Logging::VERBOSE));
0103 
0104   auto [surfaces1, volumes1, surfacesUpdater1, volumeUpdater1] =
0105       endcapBuilder.construct(tContext);
0106 
0107   BOOST_CHECK_EQUAL(surfaces1.size(), 22u + 1u);
0108 
0109   // Inspect the back surface
0110   const auto& supportSurface1 = (*surfaces1.back());
0111   BOOST_CHECK_EQUAL(supportSurface1.type(), Acts::Surface::SurfaceType::Disc);
0112   BOOST_CHECK_CLOSE(supportSurface1.transform(tContext).translation().z(),
0113                     -785., 1e-6);
0114 
0115   BOOST_CHECK(surfacesUpdater1.connected());
0116   BOOST_CHECK(volumes1.empty());
0117   BOOST_CHECK(volumeUpdater1.connected());
0118 
0119   // Redo and let r be estimated by a volume exetent with a [ 2_mm, 1_mm]
0120   // clearance: z is still from internals, but r is from the volume/external
0121   //
0122   // Second test with one support disc, but external constraint
0123   supportDisc.internalConstraints = {Acts::AxisDirection::AxisZ};
0124   supportDisc.volumeExtent.set(Acts::AxisDirection::AxisR, 10., 120.);
0125   supportDisc.volumeClearance[Acts::AxisDirection::AxisR] = {2., 1.};
0126 
0127   lsConfig.supports = {supportDisc};
0128 
0129   lsConfig.auxiliary =
0130       "*** Endcap with 22 surfaces + 1 support disc, "
0131       "z - pos estimated from internals,  "
0132       "r - range from external constraint  *** ";
0133 
0134   endcapBuilder = Acts::Experimental::LayerStructureBuilder(
0135       lsConfig, Acts::getDefaultLogger("EndcapBuilder", Logging::VERBOSE));
0136 
0137   auto [surfaces2, volumes2, surfacesUpdater2, volumeUpdater2] =
0138       endcapBuilder.construct(tContext);
0139 
0140   BOOST_CHECK_EQUAL(surfaces2.size(), 22u + 1u);
0141 
0142   // Inspect the back surface
0143   const auto& supportSurface2 = (*surfaces2.back());
0144   BOOST_CHECK_EQUAL(supportSurface2.type(), Acts::Surface::SurfaceType::Disc);
0145   BOOST_CHECK_CLOSE(supportSurface2.transform(tContext).translation().z(),
0146                     -785., 1e-6);
0147   const auto& supportBoundValues = supportSurface2.bounds().values();
0148   BOOST_CHECK_CLOSE(supportBoundValues[0u], 12., 1e-6);
0149   BOOST_CHECK_CLOSE(supportBoundValues[1u], 119., 1e-6);
0150 
0151   BOOST_CHECK(surfacesUpdater2.connected());
0152   BOOST_CHECK(volumes2.empty());
0153   BOOST_CHECK(volumeUpdater2.connected());
0154 
0155   // Redo with split
0156   //
0157   // Third test with splitting
0158   supportDisc.splits = 11u;
0159   lsConfig.supports = {supportDisc};
0160 
0161   lsConfig.auxiliary =
0162       "*** Endcap with 22 surfaces + 1 support -> split into 11 planes ***";
0163 
0164   endcapBuilder = Acts::Experimental::LayerStructureBuilder(
0165       lsConfig, Acts::getDefaultLogger("EndcapBuilder", Logging::VERBOSE));
0166 
0167   auto [surfaces3, volumes3, surfacesUpdater3, volumeUpdater3] =
0168       endcapBuilder.construct(tContext);
0169 
0170   BOOST_CHECK_EQUAL(surfaces3.size(), 22u + 11u);
0171   BOOST_CHECK_EQUAL(surfaces3.back()->type(),
0172                     Acts::Surface::SurfaceType::Plane);
0173   BOOST_CHECK(surfacesUpdater3.connected());
0174   BOOST_CHECK(volumes3.empty());
0175   BOOST_CHECK(volumeUpdater3.connected());
0176 }
0177 
0178 // Test the creation of a cylindrical structure
0179 BOOST_AUTO_TEST_CASE(LayerStructureBuilder_creationCylinder) {
0180   CylindricalTrackingGeometry::DetectorStore dStore;
0181   auto cSurfaces = cGeometry.surfacesCylinder(dStore, 8.4, 36., 0.15, 0.145, 72,
0182                                               3., 2., {32u, 14u});
0183 
0184   auto barrelSurfaces = std::make_shared<LayerStructureBuilder::SurfacesHolder>(
0185       unpackSurfaces(cSurfaces));
0186 
0187   // Configure the layer structure builder
0188   Acts::Experimental::LayerStructureBuilder::Config lsConfig;
0189   lsConfig.auxiliary = "*** Barrel with 448 surfaces ***";
0190   lsConfig.surfacesProvider = barrelSurfaces;
0191   lsConfig.binnings = {
0192       {Acts::DirectedProtoAxis{Acts::AxisDirection::AxisZ,
0193                                Acts::AxisBoundaryType::Bound, -480., 480., 14u},
0194        1u},
0195       {Acts::DirectedProtoAxis(Acts::AxisDirection::AxisPhi,
0196                                Acts::AxisBoundaryType::Closed,
0197                                -std::numbers::pi, std::numbers::pi, 32u),
0198        1u}};
0199 
0200   auto barrelBuilder = Acts::Experimental::LayerStructureBuilder(
0201       lsConfig, Acts::getDefaultLogger("BarrelBuilder", Logging::VERBOSE));
0202 
0203   auto [surfaces0, volumes0, surfacesUpdater0, volumeUpdater0] =
0204       barrelBuilder.construct(tContext);
0205 
0206   BOOST_CHECK_EQUAL(surfaces0.size(), 448u);
0207   BOOST_CHECK(surfacesUpdater0.connected());
0208   BOOST_CHECK(volumes0.empty());
0209   BOOST_CHECK(volumeUpdater0.connected());
0210 
0211   using LayerSupport = Acts::Experimental::ProtoSupport;
0212 
0213   // First test with one support cylinder
0214   LayerSupport supportCylinder;
0215   supportCylinder.type = Acts::Surface::SurfaceType::Cylinder;
0216   supportCylinder.offset = 15.;
0217   supportCylinder.internalConstraints = {Acts::AxisDirection::AxisZ,
0218                                          Acts::AxisDirection::AxisR};
0219   lsConfig.supports = {supportCylinder};
0220   lsConfig.auxiliary =
0221       "*** Barrel with 448 surfaces + 1 support cylinder, r/z evaluated ***";
0222 
0223   barrelBuilder = Acts::Experimental::LayerStructureBuilder(
0224       lsConfig, Acts::getDefaultLogger("BarrelBuilder", Logging::VERBOSE));
0225 
0226   auto [surfaces1, volumes1, surfacesUpdater1, volumeUpdater1] =
0227       barrelBuilder.construct(tContext);
0228 
0229   BOOST_CHECK_EQUAL(surfaces1.size(), 448u + 1u);
0230   BOOST_CHECK(surfacesUpdater1.connected());
0231   BOOST_CHECK(volumes1.empty());
0232   BOOST_CHECK(volumeUpdater1.connected());
0233 
0234   // Second test: z-range externally given
0235   supportCylinder.internalConstraints = {Acts::AxisDirection::AxisR};
0236   supportCylinder.volumeExtent.set(Acts::AxisDirection::AxisZ, -600., 600.);
0237   supportCylinder.volumeClearance[Acts::AxisDirection::AxisZ] = {2., 2.};
0238   lsConfig.supports = {supportCylinder};
0239   lsConfig.auxiliary =
0240       "*** Barrel with 448 surfaces + 1 support cylinder, r evaluated, z given "
0241       "by external constraint ***";
0242 
0243   barrelBuilder = Acts::Experimental::LayerStructureBuilder(
0244       lsConfig, Acts::getDefaultLogger("BarrelBuilder", Logging::VERBOSE));
0245 
0246   auto [surfaces2, volumes2, surfacesUpdater2, volumeUpdater2] =
0247       barrelBuilder.construct(tContext);
0248 
0249   BOOST_CHECK_EQUAL(surfaces2.size(), 448u + 1u);
0250   BOOST_CHECK(surfacesUpdater2.connected());
0251   BOOST_CHECK(volumes2.empty());
0252   BOOST_CHECK(volumeUpdater2.connected());
0253   // Inspect the back surface
0254   const auto& supportSurface2 = (*surfaces2.back());
0255   BOOST_CHECK_EQUAL(supportSurface2.type(),
0256                     Acts::Surface::SurfaceType::Cylinder);
0257   const auto supportBoundValues = supportSurface2.bounds().values();
0258   BOOST_CHECK_CLOSE(supportBoundValues[1u], 598., 1e-6);
0259 
0260   // Third test: split
0261   supportCylinder.splits = 32u;
0262   lsConfig.supports = {supportCylinder};
0263   lsConfig.auxiliary =
0264       "*** Barrel with 448 surfaces + 1 support -> split into 32 planes ***";
0265 
0266   barrelBuilder = Acts::Experimental::LayerStructureBuilder(
0267       lsConfig, Acts::getDefaultLogger("BarrelBuilder", Logging::VERBOSE));
0268 
0269   auto [surfaces3, volumes3, surfacesUpdater3, volumeUpdater3] =
0270       barrelBuilder.construct(tContext);
0271 
0272   BOOST_CHECK_EQUAL(surfaces3.size(), 448u + 32u);
0273   BOOST_CHECK(surfacesUpdater3.connected());
0274   BOOST_CHECK(volumes3.empty());
0275   BOOST_CHECK(volumeUpdater3.connected());
0276 }
0277 
0278 BOOST_AUTO_TEST_SUITE_END()