Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 08:14:09

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/Detector.hpp"
0013 #include "Acts/Detector/DetectorVolume.hpp"
0014 #include "Acts/Detector/MultiWireStructureBuilder.hpp"
0015 #include "Acts/Geometry/MultiWireVolumeBuilder.hpp"
0016 #include "Acts/Geometry/TrapezoidPortalShell.hpp"
0017 #include "Acts/Geometry/TrapezoidVolumeBounds.hpp"
0018 #include "Acts/Navigation/DetectorVolumeFinders.hpp"
0019 #include "Acts/Navigation/InternalNavigation.hpp"
0020 #include "Acts/Navigation/NavigationState.hpp"
0021 #include "Acts/Navigation/NavigationStateFillers.hpp"
0022 #include "Acts/Navigation/NavigationStateUpdaters.hpp"
0023 #include "Acts/Surfaces/RectangleBounds.hpp"
0024 #include "Acts/Surfaces/StrawSurface.hpp"
0025 #include "Acts/Surfaces/Surface.hpp"
0026 #include "Acts/Tests/CommonHelpers/DetectorElementStub.hpp"
0027 #include "Acts/Utilities/Grid.hpp"
0028 #include "Acts/Utilities/VectorHelpers.hpp"
0029 
0030 #include <fstream>
0031 #include <memory>
0032 #include <numbers>
0033 #include <string>
0034 #include <vector>
0035 
0036 using namespace Acts;
0037 using namespace Acts::Experimental;
0038 using namespace Acts::detail;
0039 using namespace Acts::Test;
0040 
0041 GeometryContext tContext;
0042 constexpr std::size_t nSurfacesX = 15;
0043 constexpr std::size_t nSurfacesY = 4;
0044 constexpr double radius = 15.0;
0045 constexpr double halfZ = 250.0;
0046 
0047 BOOST_AUTO_TEST_SUITE(Experimental)
0048 auto logger = getDefaultLogger("MultiWireNavigationTests", Logging::VERBOSE);
0049 
0050 // a function that constructs and returns detector elements for straw surfaces
0051 void generateStrawSurfaces(
0052     std::size_t nStraws, std::size_t nLayers, double radius, double halfZ,
0053     std::vector<std::shared_ptr<Surface>>& strawSurfaces,
0054     std::vector<std::unique_ptr<DetectorElementStub>>& elements) {
0055   // The transform of the 1st surface
0056   Vector3 ipos = {-0.5 * nStraws * 2 * radius + radius,
0057                   -0.5 * nLayers * 2 * radius + radius, 0.};
0058 
0059   Vector3 pos = ipos;
0060   auto lineBounds = std::make_shared<LineBounds>(radius, halfZ);
0061   int id = 1;
0062 
0063   // Generate the surfaces
0064   for (std::size_t i = 0; i < nLayers; i++) {
0065     for (std::size_t j = 0; j < nStraws; j++) {
0066       pos.x() = ipos.x() + 2 * j * radius;
0067 
0068       auto& element =
0069           elements.emplace_back(std::make_unique<DetectorElementStub>(
0070               Transform3(Translation3(pos)), lineBounds, 0));
0071 
0072       element->surface().assignGeometryId(GeometryIdentifier(id++));
0073 
0074       element->surface().assignDetectorElement(*element);
0075 
0076       strawSurfaces.push_back(element->surface().getSharedPtr());
0077     }
0078 
0079     pos.y() = ipos.y() + 2 * (i + 1) * radius;
0080   }
0081 }
0082 
0083 BOOST_AUTO_TEST_CASE(Navigation_in_Indexed_Surfaces) {
0084   std::vector<std::shared_ptr<Surface>> strawSurfaces = {};
0085   std::vector<std::unique_ptr<DetectorElementStub>> detElements = {};
0086 
0087   generateStrawSurfaces(nSurfacesX, nSurfacesY, radius, halfZ, strawSurfaces,
0088                         detElements);
0089 
0090   std::vector<double> vBounds = {0.5 * nSurfacesX * 2 * radius,
0091                                  0.5 * nSurfacesX * 2 * radius,
0092                                  0.5 * nSurfacesY * 2 * radius, halfZ};
0093 
0094   MultiWireStructureBuilder::Config mlCfg;
0095   mlCfg.name = "Multi_Layer_With_Wires";
0096   mlCfg.mlSurfaces = strawSurfaces;
0097 
0098   mlCfg.mlBinning = {
0099       {DirectedProtoAxis(AxisDirection::AxisX, AxisBoundaryType::Bound,
0100                          -vBounds[0], vBounds[0], nSurfacesX),
0101        1u},
0102       {DirectedProtoAxis(AxisDirection::AxisY, AxisBoundaryType::Bound,
0103                          -vBounds[2], vBounds[2], nSurfacesY),
0104        0u}};
0105   auto boundsPtr = std::make_unique<TrapezoidVolumeBounds>(
0106       vBounds[0], vBounds[1], vBounds[2], vBounds[3]);
0107   mlCfg.mlBounds = boundsPtr->values();
0108 
0109   MultiWireStructureBuilder mlBuilder(mlCfg);
0110   auto [volumes, portals, roots] = mlBuilder.construct(tContext);
0111 
0112   Acts::Experimental::NavigationState nState;
0113   nState.position = Acts::Vector3(0., -59., 0.);
0114   nState.direction = Acts::Vector3(0., 1., 0.);
0115 
0116   nState.currentVolume = volumes.front().get();
0117   nState.currentVolume->updateNavigationState(tContext, nState);
0118 
0119   // check the surface candidates after update (12 surfaces + 6 portals but only
0120   // 4 surfaces are reachable (one of each layer and one portal)
0121   BOOST_CHECK_EQUAL(nState.surfaceCandidates.size(), 5u);
0122 }
0123 
0124 // This tests the multilayer navigation policy for gen3 geometry interface
0125 BOOST_AUTO_TEST_CASE(MultiLayer_NavigationPolicy) {
0126   // Create the surfaces
0127   std::vector<std::shared_ptr<Surface>> strawSurfaces = {};
0128   std::vector<std::unique_ptr<DetectorElementStub>> detElements = {};
0129 
0130   generateStrawSurfaces(nSurfacesX, nSurfacesY, radius, halfZ, strawSurfaces,
0131                         detElements);
0132 
0133   std::vector<double> vBounds = {0.5 * nSurfacesX * 2 * radius,
0134                                  0.5 * nSurfacesX * 2 * radius,
0135                                  0.5 * nSurfacesY * 2 * radius, halfZ};
0136   // Create the multi wire volume (tracking volume this time!)
0137   MultiWireVolumeBuilder::Config mwCfg;
0138   mwCfg.name = "MultiWireVolume";
0139   mwCfg.mlSurfaces = strawSurfaces;
0140   mwCfg.binning = {
0141       {DirectedProtoAxis(AxisDirection::AxisX, AxisBoundaryType::Bound,
0142                          -vBounds[0], vBounds[0], nSurfacesX),
0143        1u},
0144       {DirectedProtoAxis(AxisDirection::AxisY, AxisBoundaryType::Bound,
0145                          -vBounds[2], vBounds[2], nSurfacesY),
0146        0u}};
0147   auto boundsPtr = std::make_shared<Acts::TrapezoidVolumeBounds>(
0148       vBounds[0], vBounds[1], vBounds[2], vBounds[3]);
0149   mwCfg.bounds = boundsPtr;
0150   mwCfg.transform = Transform3(Translation3(Vector3(0., 0., 0.)));
0151 
0152   // Build the volume
0153   MultiWireVolumeBuilder mwBuilder(mwCfg);
0154   std::unique_ptr<Acts::TrackingVolume> volume = mwBuilder.buildVolume();
0155 
0156   SingleTrapezoidPortalShell portalShell(*volume);
0157   portalShell.applyToVolume();
0158 
0159   // Check the volume
0160   // we do not except any children volumes
0161   BOOST_CHECK(volume->volumes().empty());
0162 
0163   // we expect 15*4 = 60 surfaces
0164   BOOST_CHECK(volume->surfaces().size() == 60u);
0165 
0166   BOOST_CHECK(volume->portals().size() == 6u);
0167 
0168   // check the navigation policy
0169   NavigationStream main;
0170   AppendOnlyNavigationStream stream{main};
0171   Vector3 startPos = {0., -59., 0.};
0172   Vector3 startDir = {0., 1., 0.};
0173   NavigationArguments args{startPos, startDir};
0174 
0175   auto navFactory = mwBuilder.createNavigationPolicyFactory();
0176   volume->setNavigationPolicy(navFactory->build(tContext, *volume, *logger));
0177 
0178   volume->initializeNavigationCandidates(args, stream, *logger);
0179 
0180   // we expect 18 candidates (12 surfaces + 6 portals)
0181   BOOST_CHECK_EQUAL(main.candidates().size(), 18u);
0182 
0183   // check if we have duplicated surface candidates
0184   auto it = std::unique(main.candidates().begin(), main.candidates().end(),
0185                         [](const auto& lhs, const auto& rhs) {
0186                           return lhs.surface() == rhs.surface();
0187                         });
0188   BOOST_CHECK(it == main.candidates().end());
0189 
0190   // try with a different direction
0191   double angle = std::numbers::pi / 4.;
0192   startDir = {std::cos(angle), std::sin(angle), 0.};
0193   args.direction = startDir;
0194   // clear the candidates and re initialize with new arguments
0195   main.candidates().clear();
0196   volume->initializeNavigationCandidates(args, stream, *logger);
0197   // we expect 18 candidates (12 surfaces + 6 portals)
0198   BOOST_CHECK_EQUAL(main.candidates().size(), 18u);
0199 }
0200 
0201 BOOST_AUTO_TEST_SUITE_END()