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/KdtSurfacesProvider.hpp"
0013 #include "Acts/Geometry/Extent.hpp"
0014 #include "Acts/Geometry/GeometryContext.hpp"
0015 #include "Acts/Geometry/LayerCreator.hpp"
0016 #include "Acts/Surfaces/Surface.hpp"
0017 #include "Acts/Tests/CommonHelpers/CylindricalTrackingGeometry.hpp"
0018 #include "Acts/Utilities/BinningType.hpp"
0019 #include "Acts/Utilities/Enumerate.hpp"
0020 #include "Acts/Utilities/GridAxisGenerators.hpp"
0021 
0022 #include <algorithm>
0023 #include <cstddef>
0024 #include <iterator>
0025 #include <memory>
0026 #include <utility>
0027 #include <vector>
0028 
0029 using namespace Acts;
0030 using namespace Acts::Test;
0031 using namespace Acts::Experimental;
0032 
0033 GeometryContext tContext;
0034 CylindricalTrackingGeometry cGeometry = CylindricalTrackingGeometry(tContext);
0035 
0036 namespace {
0037 /// Helper method that allows to use the already existing testing
0038 /// infrastructure with the new const-correct detector design
0039 ///
0040 std::vector<std::shared_ptr<Acts::Surface>> unpackSurfaces(
0041     const std::vector<const Acts::Surface*>& surfaces) {
0042   std::vector<std::shared_ptr<Acts::Surface>> uSurfaces;
0043   uSurfaces.reserve(surfaces.size());
0044   for (const auto& s : surfaces) {
0045     Surface* ncs = const_cast<Surface*>(s);
0046     uSurfaces.push_back(ncs->getSharedPtr());
0047   }
0048   return uSurfaces;
0049 }
0050 
0051 std::vector<std::shared_ptr<Acts::Surface>> pixelSurfaces(
0052     CylindricalTrackingGeometry::DetectorStore& dStore) {
0053   // The surfaces for the KDTree structure
0054   std::vector<std::shared_ptr<Acts::Surface>> pixelSurfaces;
0055   // Fill Discs
0056   std::vector<Acts::ActsScalar> pixelDiscs = {-800., -700., -600.,
0057                                               600.,  700.,  800.};
0058   for (const auto& z : pixelDiscs) {
0059     auto rSurfaces = cGeometry.surfacesRing(dStore, 6.4, 12.4, 36., 0.125, 0.,
0060                                             55., z, 2., 22u);
0061     auto urSurfaces = unpackSurfaces(rSurfaces);
0062     pixelSurfaces.insert(pixelSurfaces.end(), urSurfaces.begin(),
0063                          urSurfaces.end());
0064   }
0065   // Fill Barrels
0066   std::vector<Acts::ActsScalar> pixelBarrels = {32., 72., 116., 172.};
0067   std::vector<std::pair<int, int>> pixelBinning = {
0068       {16, 14}, {32, 14}, {52, 14}, {78, 14}};
0069   for (auto [ir, r] : enumerate(pixelBarrels)) {
0070     auto cSurfaces = cGeometry.surfacesCylinder(dStore, 8.4, 36., 0.15, 0.145,
0071                                                 r, 3., 2., pixelBinning[ir]);
0072 
0073     auto ucSurfaces = unpackSurfaces(cSurfaces);
0074     pixelSurfaces.insert(pixelSurfaces.end(), ucSurfaces.begin(),
0075                          ucSurfaces.end());
0076   }
0077   return pixelSurfaces;
0078 }
0079 
0080 }  // namespace
0081 
0082 BOOST_AUTO_TEST_SUITE(Detector)
0083 
0084 // Test only the KDT infrastructure
0085 BOOST_AUTO_TEST_CASE(KdtSurfacesProvider_misconfigured) {
0086   Acts::Extent region;
0087   BOOST_CHECK_THROW(
0088       Acts::Experimental::KdtSurfacesProvider<> end3(nullptr, region),
0089       std::invalid_argument);
0090 }
0091 
0092 // Test only the KDT infrastructure
0093 BOOST_AUTO_TEST_CASE(KdtSurfacesProvider) {
0094   // Detector store
0095   CylindricalTrackingGeometry::DetectorStore dStore;
0096   auto pSurfaces = pixelSurfaces(dStore);
0097   // Count the number of surfacees
0098   std::size_t refNumber = 6u * 22u + 14u * (16u + 32u + 52u + 78u);
0099   BOOST_CHECK_EQUAL(pSurfaces.size(), refNumber);
0100 
0101   using KDTS = Acts::Experimental::KdtSurfaces<>;
0102   auto skdt = std::make_shared<KDTS>(KDTS(tContext, pSurfaces, {binZ, binR}));
0103 
0104   // query: Negative disc 3, it should yield 22 surfaces
0105   Acts::Extent regionND3;
0106   regionND3.set(binZ, -820, -780);
0107   regionND3.set(binR, 0., 200.);
0108   Acts::Experimental::KdtSurfacesProvider<> end3(skdt, regionND3);
0109 
0110   auto nd3 = end3.surfaces(tContext);
0111   BOOST_CHECK_EQUAL(nd3.size(), 22u);
0112 
0113   // query: 2nd Pixel barrel
0114   Acts::Extent regionB1;
0115   regionB1.set(binZ, -580, 580);
0116   regionB1.set(binR, 60., 80.);
0117 
0118   Acts::Experimental::KdtSurfacesProvider<> ba1(skdt, regionB1);
0119 
0120   auto b1 = ba1.surfaces(tContext);
0121   refNumber = 32u * 14u;
0122   BOOST_CHECK_EQUAL(b1.size(), refNumber);
0123 }
0124 
0125 BOOST_AUTO_TEST_SUITE_END()