Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-29 07:55:17

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/Utilities/BinningData.hpp"
0020 #include "Acts/Utilities/BinningType.hpp"
0021 #include "Acts/Utilities/Logger.hpp"
0022 #include "ActsTests/CommonHelpers/CylindricalTrackingGeometry.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::Experimental;
0033 using namespace ActsTests;
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<Surface>> unpackSurfaces(
0043     const std::vector<Surface*>& surfaces) {
0044   std::vector<std::shared_ptr<Surface>> uSurfaces;
0045   uSurfaces.reserve(surfaces.size());
0046   for (auto* s : surfaces) {
0047     uSurfaces.push_back(s->getSharedPtr());
0048   }
0049   return uSurfaces;
0050 }
0051 
0052 }  // namespace
0053 
0054 namespace ActsTests {
0055 
0056 BOOST_AUTO_TEST_SUITE(DetectorSuite)
0057 
0058 // Test the creation of a ring like structure
0059 BOOST_AUTO_TEST_CASE(LayerStructureBuilder_creationRing) {
0060   // Detector store
0061   CylindricalTrackingGeometry::DetectorStore dStore;
0062   auto rSurfaces = cGeometry.surfacesRing(dStore, 6.4, 12.4, 36., 0.125, 0.,
0063                                           55., -800, 0., 22u);
0064 
0065   auto endcapSurfaces = std::make_shared<LayerStructureBuilder::SurfacesHolder>(
0066       unpackSurfaces(rSurfaces));
0067   // Configure the layer structure builder
0068   Experimental::LayerStructureBuilder::Config lsConfig;
0069   lsConfig.auxiliary = "*** Endcap with 22 surfaces ***";
0070   lsConfig.surfacesProvider = endcapSurfaces;
0071   lsConfig.binnings = {
0072       {DirectedProtoAxis(AxisDirection::AxisPhi, AxisBoundaryType::Closed,
0073                          -std::numbers::pi, std::numbers::pi, 22u),
0074        1u}};
0075 
0076   auto endcapBuilder = Experimental::LayerStructureBuilder(
0077       lsConfig, 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 = Experimental::ProtoSupport;
0091   LayerSupport supportDisc;
0092   supportDisc.type = Surface::SurfaceType::Disc;
0093   supportDisc.offset = 15.;
0094   supportDisc.internalConstraints = {AxisDirection::AxisZ,
0095                                      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 = Experimental::LayerStructureBuilder(
0102       lsConfig, 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(), 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 = {AxisDirection::AxisZ};
0124   supportDisc.volumeExtent.set(AxisDirection::AxisR, 10., 120.);
0125   supportDisc.volumeClearance[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 = Experimental::LayerStructureBuilder(
0135       lsConfig, 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(), 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 = Experimental::LayerStructureBuilder(
0165       lsConfig, 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(), Surface::SurfaceType::Plane);
0172   BOOST_CHECK(surfacesUpdater3.connected());
0173   BOOST_CHECK(volumes3.empty());
0174   BOOST_CHECK(volumeUpdater3.connected());
0175 }
0176 
0177 // Test the creation of a cylindrical structure
0178 BOOST_AUTO_TEST_CASE(LayerStructureBuilder_creationCylinder) {
0179   CylindricalTrackingGeometry::DetectorStore dStore;
0180   auto cSurfaces = cGeometry.surfacesCylinder(dStore, 8.4, 36., 0.15, 0.145, 72,
0181                                               3., 2., {32u, 14u});
0182 
0183   auto barrelSurfaces = std::make_shared<LayerStructureBuilder::SurfacesHolder>(
0184       unpackSurfaces(cSurfaces));
0185 
0186   // Configure the layer structure builder
0187   Experimental::LayerStructureBuilder::Config lsConfig;
0188   lsConfig.auxiliary = "*** Barrel with 448 surfaces ***";
0189   lsConfig.surfacesProvider = barrelSurfaces;
0190   lsConfig.binnings = {
0191       {DirectedProtoAxis{AxisDirection::AxisZ, AxisBoundaryType::Bound, -480.,
0192                          480., 14u},
0193        1u},
0194       {DirectedProtoAxis(AxisDirection::AxisPhi, AxisBoundaryType::Closed,
0195                          -std::numbers::pi, std::numbers::pi, 32u),
0196        1u}};
0197 
0198   auto barrelBuilder = Experimental::LayerStructureBuilder(
0199       lsConfig, getDefaultLogger("BarrelBuilder", Logging::VERBOSE));
0200 
0201   auto [surfaces0, volumes0, surfacesUpdater0, volumeUpdater0] =
0202       barrelBuilder.construct(tContext);
0203 
0204   BOOST_CHECK_EQUAL(surfaces0.size(), 448u);
0205   BOOST_CHECK(surfacesUpdater0.connected());
0206   BOOST_CHECK(volumes0.empty());
0207   BOOST_CHECK(volumeUpdater0.connected());
0208 
0209   using LayerSupport = Experimental::ProtoSupport;
0210 
0211   // First test with one support cylinder
0212   LayerSupport supportCylinder;
0213   supportCylinder.type = Surface::SurfaceType::Cylinder;
0214   supportCylinder.offset = 15.;
0215   supportCylinder.internalConstraints = {AxisDirection::AxisZ,
0216                                          AxisDirection::AxisR};
0217   lsConfig.supports = {supportCylinder};
0218   lsConfig.auxiliary =
0219       "*** Barrel with 448 surfaces + 1 support cylinder, r/z evaluated ***";
0220 
0221   barrelBuilder = Experimental::LayerStructureBuilder(
0222       lsConfig, getDefaultLogger("BarrelBuilder", Logging::VERBOSE));
0223 
0224   auto [surfaces1, volumes1, surfacesUpdater1, volumeUpdater1] =
0225       barrelBuilder.construct(tContext);
0226 
0227   BOOST_CHECK_EQUAL(surfaces1.size(), 448u + 1u);
0228   BOOST_CHECK(surfacesUpdater1.connected());
0229   BOOST_CHECK(volumes1.empty());
0230   BOOST_CHECK(volumeUpdater1.connected());
0231 
0232   // Second test: z-range externally given
0233   supportCylinder.internalConstraints = {AxisDirection::AxisR};
0234   supportCylinder.volumeExtent.set(AxisDirection::AxisZ, -600., 600.);
0235   supportCylinder.volumeClearance[AxisDirection::AxisZ] = {2., 2.};
0236   lsConfig.supports = {supportCylinder};
0237   lsConfig.auxiliary =
0238       "*** Barrel with 448 surfaces + 1 support cylinder, r evaluated, z given "
0239       "by external constraint ***";
0240 
0241   barrelBuilder = Experimental::LayerStructureBuilder(
0242       lsConfig, getDefaultLogger("BarrelBuilder", Logging::VERBOSE));
0243 
0244   auto [surfaces2, volumes2, surfacesUpdater2, volumeUpdater2] =
0245       barrelBuilder.construct(tContext);
0246 
0247   BOOST_CHECK_EQUAL(surfaces2.size(), 448u + 1u);
0248   BOOST_CHECK(surfacesUpdater2.connected());
0249   BOOST_CHECK(volumes2.empty());
0250   BOOST_CHECK(volumeUpdater2.connected());
0251   // Inspect the back surface
0252   const auto& supportSurface2 = (*surfaces2.back());
0253   BOOST_CHECK_EQUAL(supportSurface2.type(), Surface::SurfaceType::Cylinder);
0254   const auto supportBoundValues = supportSurface2.bounds().values();
0255   BOOST_CHECK_CLOSE(supportBoundValues[1u], 598., 1e-6);
0256 
0257   // Third test: split
0258   supportCylinder.splits = 32u;
0259   lsConfig.supports = {supportCylinder};
0260   lsConfig.auxiliary =
0261       "*** Barrel with 448 surfaces + 1 support -> split into 32 planes ***";
0262 
0263   barrelBuilder = Experimental::LayerStructureBuilder(
0264       lsConfig, getDefaultLogger("BarrelBuilder", Logging::VERBOSE));
0265 
0266   auto [surfaces3, volumes3, surfacesUpdater3, volumeUpdater3] =
0267       barrelBuilder.construct(tContext);
0268 
0269   BOOST_CHECK_EQUAL(surfaces3.size(), 448u + 32u);
0270   BOOST_CHECK(surfacesUpdater3.connected());
0271   BOOST_CHECK(volumes3.empty());
0272   BOOST_CHECK(volumeUpdater3.connected());
0273 }
0274 
0275 BOOST_AUTO_TEST_SUITE_END()
0276 
0277 }  // namespace ActsTests