Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-06 08:57:52

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/Geometry/GeometryContext.hpp"
0013 #include "Acts/Geometry/MultiWireVolumeBuilder.hpp"
0014 #include "Acts/Geometry/TrapezoidPortalShell.hpp"
0015 #include "Acts/Geometry/TrapezoidVolumeBounds.hpp"
0016 #include "Acts/Surfaces/StrawSurface.hpp"
0017 #include "Acts/Surfaces/Surface.hpp"
0018 #include "ActsTests/CommonHelpers/DetectorElementStub.hpp"
0019 
0020 #include <memory>
0021 #include <numbers>
0022 #include <string>
0023 #include <vector>
0024 
0025 using namespace Acts;
0026 using namespace Acts::Experimental;
0027 using namespace Acts::detail;
0028 
0029 GeometryContext tContext;
0030 constexpr std::size_t nSurfacesX = 15;
0031 constexpr std::size_t nSurfacesY = 4;
0032 constexpr double radius = 15.0;
0033 constexpr double halfZ = 250.0;
0034 
0035 namespace ActsTests {
0036 
0037 BOOST_AUTO_TEST_SUITE(NavigationSuite)
0038 auto logger = getDefaultLogger("MultiWireNavigationTests", Logging::VERBOSE);
0039 
0040 // a function that constructs and returns detector elements for straw surfaces
0041 void generateStrawSurfaces(
0042     std::size_t nStraws, std::size_t nLayers, double radius, double halfZ,
0043     std::vector<std::shared_ptr<Surface>>& strawSurfaces,
0044     std::vector<std::unique_ptr<DetectorElementStub>>& elements) {
0045   // The transform of the 1st surface
0046   Vector3 ipos = {-0.5 * nStraws * 2 * radius + radius,
0047                   -0.5 * nLayers * 2 * radius + radius, 0.};
0048 
0049   Vector3 pos = ipos;
0050   auto lineBounds = std::make_shared<LineBounds>(radius, halfZ);
0051   int id = 1;
0052 
0053   // Generate the surfaces
0054   for (std::size_t i = 0; i < nLayers; i++) {
0055     for (std::size_t j = 0; j < nStraws; j++) {
0056       pos.x() = ipos.x() + 2 * j * radius;
0057 
0058       auto& element =
0059           elements.emplace_back(std::make_unique<DetectorElementStub>(
0060               Transform3(Translation3(pos)), lineBounds, 0));
0061 
0062       element->surface().assignGeometryId(GeometryIdentifier(id++));
0063 
0064       element->surface().assignDetectorElement(*element);
0065 
0066       strawSurfaces.push_back(element->surface().getSharedPtr());
0067     }
0068 
0069     pos.y() = ipos.y() + 2 * (i + 1) * radius;
0070   }
0071 }
0072 
0073 // This tests the multilayer navigation policy for gen3 geometry interface
0074 BOOST_AUTO_TEST_CASE(MultiLayer_NavigationPolicy) {
0075   // Create the surfaces
0076   std::vector<std::shared_ptr<Surface>> strawSurfaces = {};
0077   std::vector<std::unique_ptr<DetectorElementStub>> detElements = {};
0078 
0079   generateStrawSurfaces(nSurfacesX, nSurfacesY, radius, halfZ, strawSurfaces,
0080                         detElements);
0081 
0082   std::vector<double> vBounds = {0.5 * nSurfacesX * 2 * radius,
0083                                  0.5 * nSurfacesX * 2 * radius,
0084                                  0.5 * nSurfacesY * 2 * radius, halfZ};
0085   // Create the multi wire volume (tracking volume this time!)
0086   MultiWireVolumeBuilder::Config mwCfg;
0087   mwCfg.name = "MultiWireVolume";
0088   mwCfg.mlSurfaces = strawSurfaces;
0089   mwCfg.binning = {
0090       {DirectedProtoAxis(AxisDirection::AxisX, AxisBoundaryType::Bound,
0091                          -vBounds[0], vBounds[0], nSurfacesX),
0092        1u},
0093       {DirectedProtoAxis(AxisDirection::AxisY, AxisBoundaryType::Bound,
0094                          -vBounds[2], vBounds[2], nSurfacesY),
0095        0u}};
0096   auto boundsPtr = std::make_shared<Acts::TrapezoidVolumeBounds>(
0097       vBounds[0], vBounds[1], vBounds[2], vBounds[3]);
0098   mwCfg.bounds = boundsPtr;
0099   mwCfg.transform = Transform3(Translation3(Vector3(0., 0., 0.)));
0100 
0101   // Build the volume
0102   MultiWireVolumeBuilder mwBuilder(mwCfg);
0103   std::unique_ptr<Acts::TrackingVolume> volume = mwBuilder.buildVolume();
0104 
0105   SingleTrapezoidPortalShell portalShell(*volume);
0106   portalShell.applyToVolume();
0107 
0108   // Check the volume
0109   // we do not except any children volumes
0110   BOOST_CHECK(volume->volumes().empty());
0111 
0112   // we expect 15*4 = 60 surfaces
0113   BOOST_CHECK(volume->surfaces().size() == 60u);
0114 
0115   BOOST_CHECK(volume->portals().size() == 6u);
0116 
0117   // check the navigation policy
0118   NavigationStream main;
0119   AppendOnlyNavigationStream stream{main};
0120   Vector3 startPos = {0., -59., 0.};
0121   Vector3 startDir = {0., 1., 0.};
0122   NavigationArguments args{startPos, startDir};
0123 
0124   auto navFactory = mwBuilder.createNavigationPolicyFactory();
0125   volume->setNavigationPolicy(navFactory->build(tContext, *volume, *logger));
0126 
0127   volume->initializeNavigationCandidates(tContext, args, stream, *logger);
0128 
0129   // we expect 18 candidates (12 surfaces + 6 portals)
0130   BOOST_CHECK_EQUAL(main.candidates().size(), 18u);
0131 
0132   // check if we have duplicated surface candidates
0133   auto it = std::unique(main.candidates().begin(), main.candidates().end(),
0134                         [](const auto& lhs, const auto& rhs) {
0135                           return lhs.surface() == rhs.surface();
0136                         });
0137   BOOST_CHECK(it == main.candidates().end());
0138 
0139   // try with a different direction
0140   double angle = std::numbers::pi / 4.;
0141   startDir = {std::cos(angle), std::sin(angle), 0.};
0142   args.direction = startDir;
0143   // clear the candidates and re initialize with new arguments
0144   main.candidates().clear();
0145   volume->initializeNavigationCandidates(tContext, args, stream, *logger);
0146   // we expect 18 candidates (12 surfaces + 6 portals)
0147   BOOST_CHECK_EQUAL(main.candidates().size(), 18u);
0148 }
0149 
0150 BOOST_AUTO_TEST_SUITE_END()
0151 
0152 }  // namespace ActsTests