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