Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:03:48

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<Acts::Surface*>& surfaces) {
0044   std::vector<std::shared_ptr<Acts::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 BOOST_AUTO_TEST_SUITE(Detector)
0055 
0056 // Test the creation of a ring like structure
0057 BOOST_AUTO_TEST_CASE(LayerStructureBuilder_creationRing) {
0058   // Detector store
0059   CylindricalTrackingGeometry::DetectorStore dStore;
0060   auto rSurfaces = cGeometry.surfacesRing(dStore, 6.4, 12.4, 36., 0.125, 0.,
0061                                           55., -800, 0., 22u);
0062 
0063   auto endcapSurfaces = std::make_shared<LayerStructureBuilder::SurfacesHolder>(
0064       unpackSurfaces(rSurfaces));
0065   // Configure the layer structure builder
0066   Acts::Experimental::LayerStructureBuilder::Config lsConfig;
0067   lsConfig.auxiliary = "*** Endcap with 22 surfaces ***";
0068   lsConfig.surfacesProvider = endcapSurfaces;
0069   lsConfig.binnings = {
0070       {DirectedProtoAxis(Acts::AxisDirection::AxisPhi,
0071                          Acts::AxisBoundaryType::Closed, -std::numbers::pi,
0072                          std::numbers::pi, 22u),
0073        1u}};
0074 
0075   auto endcapBuilder = Acts::Experimental::LayerStructureBuilder(
0076       lsConfig, Acts::getDefaultLogger("EndcapBuilder", Logging::VERBOSE));
0077 
0078   auto [surfaces0, volumes0, surfacesUpdater0, volumeUpdater0] =
0079       endcapBuilder.construct(tContext);
0080 
0081   BOOST_CHECK_EQUAL(surfaces0.size(), 22u);
0082   BOOST_CHECK(surfacesUpdater0.connected());
0083   BOOST_CHECK(volumes0.empty());
0084   BOOST_CHECK(volumeUpdater0.connected());
0085 
0086   // Define the layer support
0087   //
0088   // First test with one support disc
0089   using LayerSupport = Acts::Experimental::ProtoSupport;
0090   LayerSupport supportDisc;
0091   supportDisc.type = Acts::Surface::SurfaceType::Disc;
0092   supportDisc.offset = 15.;
0093   supportDisc.internalConstraints = {Acts::AxisDirection::AxisZ,
0094                                      Acts::AxisDirection::AxisR};
0095 
0096   lsConfig.auxiliary =
0097       "*** Endcap with 22 surfaces + 1 support disc, "
0098       "r/z - range/pos estimated from internals ***";
0099   lsConfig.supports = {supportDisc};
0100   endcapBuilder = Acts::Experimental::LayerStructureBuilder(
0101       lsConfig, Acts::getDefaultLogger("EndcapBuilder", Logging::VERBOSE));
0102 
0103   auto [surfaces1, volumes1, surfacesUpdater1, volumeUpdater1] =
0104       endcapBuilder.construct(tContext);
0105 
0106   BOOST_CHECK_EQUAL(surfaces1.size(), 22u + 1u);
0107 
0108   // Inspect the back surface
0109   const auto& supportSurface1 = (*surfaces1.back());
0110   BOOST_CHECK_EQUAL(supportSurface1.type(), Acts::Surface::SurfaceType::Disc);
0111   BOOST_CHECK_CLOSE(supportSurface1.transform(tContext).translation().z(),
0112                     -785., 1e-6);
0113 
0114   BOOST_CHECK(surfacesUpdater1.connected());
0115   BOOST_CHECK(volumes1.empty());
0116   BOOST_CHECK(volumeUpdater1.connected());
0117 
0118   // Redo and let r be estimated by a volume exetent with a [ 2_mm, 1_mm]
0119   // clearance: z is still from internals, but r is from the volume/external
0120   //
0121   // Second test with one support disc, but external constraint
0122   supportDisc.internalConstraints = {Acts::AxisDirection::AxisZ};
0123   supportDisc.volumeExtent.set(Acts::AxisDirection::AxisR, 10., 120.);
0124   supportDisc.volumeClearance[Acts::AxisDirection::AxisR] = {2., 1.};
0125 
0126   lsConfig.supports = {supportDisc};
0127 
0128   lsConfig.auxiliary =
0129       "*** Endcap with 22 surfaces + 1 support disc, "
0130       "z - pos estimated from internals,  "
0131       "r - range from external constraint  *** ";
0132 
0133   endcapBuilder = Acts::Experimental::LayerStructureBuilder(
0134       lsConfig, Acts::getDefaultLogger("EndcapBuilder", Logging::VERBOSE));
0135 
0136   auto [surfaces2, volumes2, surfacesUpdater2, volumeUpdater2] =
0137       endcapBuilder.construct(tContext);
0138 
0139   BOOST_CHECK_EQUAL(surfaces2.size(), 22u + 1u);
0140 
0141   // Inspect the back surface
0142   const auto& supportSurface2 = (*surfaces2.back());
0143   BOOST_CHECK_EQUAL(supportSurface2.type(), Acts::Surface::SurfaceType::Disc);
0144   BOOST_CHECK_CLOSE(supportSurface2.transform(tContext).translation().z(),
0145                     -785., 1e-6);
0146   const auto& supportBoundValues = supportSurface2.bounds().values();
0147   BOOST_CHECK_CLOSE(supportBoundValues[0u], 12., 1e-6);
0148   BOOST_CHECK_CLOSE(supportBoundValues[1u], 119., 1e-6);
0149 
0150   BOOST_CHECK(surfacesUpdater2.connected());
0151   BOOST_CHECK(volumes2.empty());
0152   BOOST_CHECK(volumeUpdater2.connected());
0153 
0154   // Redo with split
0155   //
0156   // Third test with splitting
0157   supportDisc.splits = 11u;
0158   lsConfig.supports = {supportDisc};
0159 
0160   lsConfig.auxiliary =
0161       "*** Endcap with 22 surfaces + 1 support -> split into 11 planes ***";
0162 
0163   endcapBuilder = Acts::Experimental::LayerStructureBuilder(
0164       lsConfig, Acts::getDefaultLogger("EndcapBuilder", Logging::VERBOSE));
0165 
0166   auto [surfaces3, volumes3, surfacesUpdater3, volumeUpdater3] =
0167       endcapBuilder.construct(tContext);
0168 
0169   BOOST_CHECK_EQUAL(surfaces3.size(), 22u + 11u);
0170   BOOST_CHECK_EQUAL(surfaces3.back()->type(),
0171                     Acts::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   Acts::Experimental::LayerStructureBuilder::Config lsConfig;
0188   lsConfig.auxiliary = "*** Barrel with 448 surfaces ***";
0189   lsConfig.surfacesProvider = barrelSurfaces;
0190   lsConfig.binnings = {
0191       {Acts::DirectedProtoAxis{Acts::AxisDirection::AxisZ,
0192                                Acts::AxisBoundaryType::Bound, -480., 480., 14u},
0193        1u},
0194       {Acts::DirectedProtoAxis(Acts::AxisDirection::AxisPhi,
0195                                Acts::AxisBoundaryType::Closed,
0196                                -std::numbers::pi, std::numbers::pi, 32u),
0197        1u}};
0198 
0199   auto barrelBuilder = Acts::Experimental::LayerStructureBuilder(
0200       lsConfig, Acts::getDefaultLogger("BarrelBuilder", Logging::VERBOSE));
0201 
0202   auto [surfaces0, volumes0, surfacesUpdater0, volumeUpdater0] =
0203       barrelBuilder.construct(tContext);
0204 
0205   BOOST_CHECK_EQUAL(surfaces0.size(), 448u);
0206   BOOST_CHECK(surfacesUpdater0.connected());
0207   BOOST_CHECK(volumes0.empty());
0208   BOOST_CHECK(volumeUpdater0.connected());
0209 
0210   using LayerSupport = Acts::Experimental::ProtoSupport;
0211 
0212   // First test with one support cylinder
0213   LayerSupport supportCylinder;
0214   supportCylinder.type = Acts::Surface::SurfaceType::Cylinder;
0215   supportCylinder.offset = 15.;
0216   supportCylinder.internalConstraints = {Acts::AxisDirection::AxisZ,
0217                                          Acts::AxisDirection::AxisR};
0218   lsConfig.supports = {supportCylinder};
0219   lsConfig.auxiliary =
0220       "*** Barrel with 448 surfaces + 1 support cylinder, r/z evaluated ***";
0221 
0222   barrelBuilder = Acts::Experimental::LayerStructureBuilder(
0223       lsConfig, Acts::getDefaultLogger("BarrelBuilder", Logging::VERBOSE));
0224 
0225   auto [surfaces1, volumes1, surfacesUpdater1, volumeUpdater1] =
0226       barrelBuilder.construct(tContext);
0227 
0228   BOOST_CHECK_EQUAL(surfaces1.size(), 448u + 1u);
0229   BOOST_CHECK(surfacesUpdater1.connected());
0230   BOOST_CHECK(volumes1.empty());
0231   BOOST_CHECK(volumeUpdater1.connected());
0232 
0233   // Second test: z-range externally given
0234   supportCylinder.internalConstraints = {Acts::AxisDirection::AxisR};
0235   supportCylinder.volumeExtent.set(Acts::AxisDirection::AxisZ, -600., 600.);
0236   supportCylinder.volumeClearance[Acts::AxisDirection::AxisZ] = {2., 2.};
0237   lsConfig.supports = {supportCylinder};
0238   lsConfig.auxiliary =
0239       "*** Barrel with 448 surfaces + 1 support cylinder, r evaluated, z given "
0240       "by external constraint ***";
0241 
0242   barrelBuilder = Acts::Experimental::LayerStructureBuilder(
0243       lsConfig, Acts::getDefaultLogger("BarrelBuilder", Logging::VERBOSE));
0244 
0245   auto [surfaces2, volumes2, surfacesUpdater2, volumeUpdater2] =
0246       barrelBuilder.construct(tContext);
0247 
0248   BOOST_CHECK_EQUAL(surfaces2.size(), 448u + 1u);
0249   BOOST_CHECK(surfacesUpdater2.connected());
0250   BOOST_CHECK(volumes2.empty());
0251   BOOST_CHECK(volumeUpdater2.connected());
0252   // Inspect the back surface
0253   const auto& supportSurface2 = (*surfaces2.back());
0254   BOOST_CHECK_EQUAL(supportSurface2.type(),
0255                     Acts::Surface::SurfaceType::Cylinder);
0256   const auto supportBoundValues = supportSurface2.bounds().values();
0257   BOOST_CHECK_CLOSE(supportBoundValues[1u], 598., 1e-6);
0258 
0259   // Third test: split
0260   supportCylinder.splits = 32u;
0261   lsConfig.supports = {supportCylinder};
0262   lsConfig.auxiliary =
0263       "*** Barrel with 448 surfaces + 1 support -> split into 32 planes ***";
0264 
0265   barrelBuilder = Acts::Experimental::LayerStructureBuilder(
0266       lsConfig, Acts::getDefaultLogger("BarrelBuilder", Logging::VERBOSE));
0267 
0268   auto [surfaces3, volumes3, surfacesUpdater3, volumeUpdater3] =
0269       barrelBuilder.construct(tContext);
0270 
0271   BOOST_CHECK_EQUAL(surfaces3.size(), 448u + 32u);
0272   BOOST_CHECK(surfacesUpdater3.connected());
0273   BOOST_CHECK(volumes3.empty());
0274   BOOST_CHECK(volumeUpdater3.connected());
0275 }
0276 
0277 BOOST_AUTO_TEST_SUITE_END()