Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:33

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