File indexing completed on 2025-12-06 08:57:52
0001
0002
0003
0004
0005
0006
0007
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
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
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
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
0074 BOOST_AUTO_TEST_CASE(MultiLayer_NavigationPolicy) {
0075
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
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
0102 MultiWireVolumeBuilder mwBuilder(mwCfg);
0103 std::unique_ptr<Acts::TrackingVolume> volume = mwBuilder.buildVolume();
0104
0105 SingleTrapezoidPortalShell portalShell(*volume);
0106 portalShell.applyToVolume();
0107
0108
0109
0110 BOOST_CHECK(volume->volumes().empty());
0111
0112
0113 BOOST_CHECK(volume->surfaces().size() == 60u);
0114
0115 BOOST_CHECK(volume->portals().size() == 6u);
0116
0117
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
0130 BOOST_CHECK_EQUAL(main.candidates().size(), 18u);
0131
0132
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
0140 double angle = std::numbers::pi / 4.;
0141 startDir = {std::cos(angle), std::sin(angle), 0.};
0142 args.direction = startDir;
0143
0144 main.candidates().clear();
0145 volume->initializeNavigationCandidates(tContext, args, stream, *logger);
0146
0147 BOOST_CHECK_EQUAL(main.candidates().size(), 18u);
0148 }
0149
0150 BOOST_AUTO_TEST_SUITE_END()
0151
0152 }