File indexing completed on 2025-01-18 09:12:44
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/Detector/Detector.hpp"
0013 #include "Acts/Detector/DetectorVolume.hpp"
0014 #include "Acts/Detector/GeometryIdGenerator.hpp"
0015 #include "Acts/Detector/PortalGenerators.hpp"
0016 #include "Acts/Geometry/CylinderVolumeBounds.hpp"
0017 #include "Acts/Geometry/GeometryContext.hpp"
0018 #include "Acts/Navigation/DetectorVolumeFinders.hpp"
0019 #include "Acts/Navigation/InternalNavigation.hpp"
0020 #include "Acts/Navigation/NavigationState.hpp"
0021 #include "Acts/Utilities/Axis.hpp"
0022 #include "Acts/Utilities/AxisDefinitions.hpp"
0023 #include "Acts/Utilities/BinningType.hpp"
0024 #include "Acts/Utilities/Grid.hpp"
0025
0026 #include <array>
0027 #include <cstddef>
0028 #include <memory>
0029 #include <stdexcept>
0030 #include <tuple>
0031 #include <utility>
0032 #include <vector>
0033
0034
0035 Acts::GeometryContext tContext;
0036
0037 Acts::Experimental::NavigationState nState;
0038
0039 double r0 = 0.;
0040 double r1 = 10.;
0041 double r2 = 100.;
0042 double r3 = 200.;
0043 double zHalfL = 200.;
0044
0045 Acts::Transform3 nominal = Acts::Transform3::Identity();
0046
0047
0048 auto cyl0Bounds = std::make_unique<Acts::CylinderVolumeBounds>(r0, r1, zHalfL);
0049
0050 auto cyl1Bounds = std::make_unique<Acts::CylinderVolumeBounds>(r1, r2, zHalfL);
0051
0052 auto cyl2Bounds = std::make_unique<Acts::CylinderVolumeBounds>(r2, r3, zHalfL);
0053
0054 auto portalGenerator = Acts::Experimental::defaultPortalGenerator();
0055
0056 auto cyl0 = Acts::Experimental::DetectorVolumeFactory::construct(
0057 portalGenerator, tContext, "Cyl0", nominal, std::move(cyl0Bounds),
0058 Acts::Experimental::tryAllPortals());
0059
0060 auto cyl1 = Acts::Experimental::DetectorVolumeFactory::construct(
0061 portalGenerator, tContext, "Cyl1", nominal, std::move(cyl1Bounds),
0062 Acts::Experimental::tryAllPortals());
0063
0064 auto cyl2 = Acts::Experimental::DetectorVolumeFactory::construct(
0065 portalGenerator, tContext, "Cyl2", nominal, std::move(cyl2Bounds),
0066 Acts::Experimental::tryAllPortals());
0067
0068 std::vector<std::shared_ptr<Acts::Experimental::DetectorVolume>> volumes012 = {
0069 cyl0, cyl1, cyl2};
0070
0071 Acts::Experimental::GeometryIdGenerator::Config generatorConfig;
0072 Acts::Experimental::GeometryIdGenerator generator(
0073 generatorConfig,
0074 Acts::getDefaultLogger("SequentialIdGenerator", Acts::Logging::VERBOSE));
0075
0076 BOOST_AUTO_TEST_SUITE(Experimental)
0077
0078
0079 BOOST_AUTO_TEST_CASE(RootVolumeFinder) {
0080 auto cache = generator.generateCache();
0081 for (auto& vol : volumes012) {
0082 generator.assignGeometryId(cache, *vol);
0083 }
0084
0085 auto det012 = Acts::Experimental::Detector::makeShared(
0086 "Det012", volumes012, Acts::Experimental::tryRootVolumes());
0087
0088 nState.currentDetector = det012.get();
0089 Acts::Experimental::RootVolumeFinder rvf;
0090
0091 nState.position = Acts::Vector3(5., 0., 0.);
0092 rvf.update(tContext, nState);
0093 BOOST_CHECK_EQUAL(nState.currentVolume, cyl0.get());
0094
0095 nState.position = Acts::Vector3(50., 0., 0.);
0096 rvf.update(tContext, nState);
0097 BOOST_CHECK_EQUAL(nState.currentVolume, cyl1.get());
0098
0099 nState.position = Acts::Vector3(150., 0., 0.);
0100 rvf.update(tContext, nState);
0101 BOOST_CHECK_EQUAL(nState.currentVolume, cyl2.get());
0102
0103 nState.currentDetector = nullptr;
0104 BOOST_CHECK_THROW(rvf.update(tContext, nState), std::runtime_error);
0105 }
0106
0107
0108 BOOST_AUTO_TEST_CASE(IndexedDetectorVolumeFinder) {
0109 auto cache = generator.generateCache();
0110 for (auto& vol : volumes012) {
0111 generator.assignGeometryId(cache, *vol);
0112 }
0113
0114 auto det012 = Acts::Experimental::Detector::makeShared(
0115 "Det012", volumes012, Acts::Experimental::tryRootVolumes());
0116
0117 nState.currentDetector = det012.get();
0118
0119 using SingleIndex = std::size_t;
0120
0121 using Axis =
0122 Acts::Axis<Acts::AxisType::Variable, Acts::AxisBoundaryType::Bound>;
0123 using Grid = Acts::Grid<SingleIndex, Axis>;
0124
0125 std::vector<double> b = {r0, r1, r2, r3};
0126 Axis a(b);
0127 Grid g(std::make_tuple(a));
0128
0129 g.atPosition(std::array<double, 1u>{5.}) = 0u;
0130 g.atPosition(std::array<double, 1u>{50.}) = 1u;
0131 g.atPosition(std::array<double, 1u>{150.}) = 2u;
0132
0133 Acts::Experimental::IndexedDetectorVolumesImpl<decltype(g)> idv(
0134 std::move(g), {Acts::AxisDirection::AxisR});
0135
0136
0137 nState.position = Acts::Vector3(5., 0., 0.);
0138 idv.update(tContext, nState);
0139 BOOST_CHECK_EQUAL(nState.currentVolume, cyl0.get());
0140
0141 nState.position = Acts::Vector3(50., 0., 0.);
0142 idv.update(tContext, nState);
0143 BOOST_CHECK_EQUAL(nState.currentVolume, cyl1.get());
0144
0145 nState.position = Acts::Vector3(150., 0., 0.);
0146 idv.update(tContext, nState);
0147 BOOST_CHECK_EQUAL(nState.currentVolume, cyl2.get());
0148
0149 nState.currentDetector = nullptr;
0150 BOOST_CHECK_THROW(idv.update(tContext, nState), std::runtime_error);
0151 }
0152
0153 BOOST_AUTO_TEST_SUITE_END()