File indexing completed on 2025-04-04 07:59:18
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010 #include <boost/test/unit_test_suite.hpp>
0011
0012 #include "Acts/Definitions/Algebra.hpp"
0013 #include "Acts/Definitions/Units.hpp"
0014 #include "Acts/Geometry/CylinderVolumeBounds.hpp"
0015 #include "Acts/Geometry/GridPortalLink.hpp"
0016 #include "Acts/Geometry/Portal.hpp"
0017 #include "Acts/Geometry/TrackingVolume.hpp"
0018 #include "Acts/Geometry/TrapezoidPortalShell.hpp"
0019 #include "Acts/Geometry/TrapezoidVolumeBounds.hpp"
0020 #include "Acts/Geometry/TrivialPortalLink.hpp"
0021 #include "Acts/Utilities/AxisDefinitions.hpp"
0022
0023 using namespace Acts::UnitLiterals;
0024
0025 namespace Acts::Test {
0026 GeometryContext gctx;
0027
0028 std::size_t getVolumeIndex() {
0029 static std::size_t i = 1;
0030 return i++;
0031 }
0032
0033 auto makeVolume(auto&&... pars) {
0034 TrackingVolume vol(Transform3::Identity(),
0035 std::make_shared<TrapezoidVolumeBounds>(
0036 std::forward<decltype(pars)>(pars)...));
0037 vol.setVolumeName("trapezoid" + std::to_string(getVolumeIndex()));
0038 return vol;
0039 };
0040
0041 auto logger = Acts::getDefaultLogger("UnitTests", Acts::Logging::VERBOSE);
0042
0043 BOOST_AUTO_TEST_SUITE(TrapezoidPortalShellTests)
0044
0045 BOOST_AUTO_TEST_CASE(ConstructionFromVolume) {
0046
0047
0048 auto trapVol = makeVolume(20_cm, 10_cm, 15_cm, 15_cm);
0049
0050
0051
0052 TrackingVolume cylVolume(
0053 Transform3::Identity(),
0054 std::make_shared<CylinderVolumeBounds>(10_mm, 20_mm, 10_mm));
0055
0056 BOOST_CHECK_THROW(SingleTrapezoidPortalShell{cylVolume},
0057 std::invalid_argument);
0058
0059 SingleTrapezoidPortalShell trapShell{trapVol};
0060
0061
0062 BOOST_CHECK(trapShell.isValid());
0063 BOOST_CHECK_EQUAL(trapShell.size(), 6);
0064
0065
0066
0067 using enum TrapezoidVolumeBounds::Face;
0068
0069
0070 const auto* nXY = trapShell.portal(NegativeZFaceXY);
0071
0072 BOOST_REQUIRE_NE(nXY, nullptr);
0073 BOOST_CHECK_EQUAL(
0074 nXY->resolveVolume(gctx, Vector3{5_cm, 10_cm, -15_cm}, Vector3::UnitZ())
0075 .value(),
0076 &trapVol);
0077 BOOST_CHECK_EQUAL(
0078 nXY->resolveVolume(gctx, Vector3{5_cm, 10_cm, -15_cm}, -Vector3::UnitZ())
0079 .value(),
0080 nullptr);
0081
0082
0083 const auto* pXY = trapShell.portal(PositiveZFaceXY);
0084
0085 BOOST_REQUIRE_NE(pXY, nullptr);
0086
0087 BOOST_CHECK_EQUAL(
0088 pXY->resolveVolume(gctx, Vector3{5_cm, 10_cm, 15_cm}, -Vector3::UnitZ())
0089 .value(),
0090 &trapVol);
0091 BOOST_CHECK_EQUAL(
0092 pXY->resolveVolume(gctx, Vector3{5_cm, 10_cm, 15_cm}, Vector3::UnitZ())
0093 .value(),
0094 nullptr);
0095
0096
0097 const auto* nYZ = trapShell.portal(TrapezoidFaceAlpha);
0098 BOOST_REQUIRE_NE(nYZ, nullptr);
0099 BOOST_CHECK_EQUAL(
0100 nYZ->resolveVolume(gctx, Vector3{-15_cm, 0_cm, 0_cm}, Vector3::UnitX())
0101 .value(),
0102 &trapVol);
0103 BOOST_CHECK_EQUAL(
0104 nYZ->resolveVolume(gctx, Vector3{-15_cm, 0_cm, 0_cm}, -Vector3::UnitX())
0105 .value(),
0106 nullptr);
0107
0108
0109 const auto* pYZ = trapShell.portal(TrapezoidFaceBeta);
0110 BOOST_REQUIRE_NE(pYZ, nullptr);
0111 BOOST_CHECK_EQUAL(
0112 pYZ->resolveVolume(gctx, Vector3{15_cm, 0_cm, 0_cm}, -Vector3::UnitX())
0113 .value(),
0114 &trapVol);
0115 BOOST_CHECK_EQUAL(
0116 pYZ->resolveVolume(gctx, Vector3{15_cm, 0_cm, 0_cm}, Vector3::UnitX())
0117 .value(),
0118 nullptr);
0119
0120
0121 const auto* nZX = trapShell.portal(NegativeYFaceZX);
0122 BOOST_CHECK_NE(nZX, nullptr);
0123 BOOST_CHECK_EQUAL(
0124 nZX->resolveVolume(gctx, Vector3{0_cm, -15_cm, 0_cm}, Vector3::UnitY())
0125 .value(),
0126 &trapVol);
0127 BOOST_CHECK_EQUAL(
0128 nZX->resolveVolume(gctx, Vector3{0_cm, -15_cm, 0_cm}, -Vector3::UnitY())
0129 .value(),
0130 nullptr);
0131
0132
0133 const auto* pZX = trapShell.portal(PositiveYFaceZX);
0134 BOOST_CHECK_NE(pZX, nullptr);
0135 BOOST_CHECK_EQUAL(
0136 pZX->resolveVolume(gctx, Vector3{0_cm, 15_cm, 0_cm}, -Vector3::UnitY())
0137 .value(),
0138 &trapVol);
0139 BOOST_CHECK_EQUAL(
0140 pZX->resolveVolume(gctx, Vector3{0_cm, 15_cm, 0_cm}, Vector3::UnitY())
0141 .value(),
0142 nullptr);
0143 }
0144
0145 BOOST_AUTO_TEST_CASE(PortalAssignment) {
0146 using enum TrapezoidVolumeBounds::Face;
0147
0148
0149 auto trapVol = makeVolume(5_cm, 8_cm, 10_cm, 15_cm);
0150
0151 SingleTrapezoidPortalShell trapShell{trapVol};
0152
0153
0154 const auto* nXY = trapShell.portal(NegativeZFaceXY);
0155 const auto* pXY = trapShell.portal(PositiveZFaceXY);
0156
0157 const auto* nYZ = trapShell.portal(TrapezoidFaceAlpha);
0158 const auto* pYZ = trapShell.portal(TrapezoidFaceBeta);
0159
0160 auto* nZX = trapShell.portal(NegativeYFaceZX);
0161 auto* pZX = trapShell.portal(PositiveYFaceZX);
0162
0163
0164 BOOST_REQUIRE_NE(nZX, nullptr);
0165 BOOST_REQUIRE_NE(pZX, nullptr);
0166
0167 auto* pZXLink = dynamic_cast<const TrivialPortalLink*>(
0168 pZX->getLink(Direction::OppositeNormal()));
0169 BOOST_REQUIRE_NE(pZXLink, nullptr);
0170
0171 auto grid = pZXLink->makeGrid(AxisDirection::AxisY);
0172
0173 auto newPortalPZX =
0174 std::make_shared<Portal>(Direction::OppositeNormal(), std::move(grid));
0175 trapShell.setPortal(newPortalPZX, PositiveYFaceZX);
0176 BOOST_CHECK_EQUAL(trapShell.portal(PositiveYFaceZX), newPortalPZX.get());
0177
0178 auto* nZXLink = dynamic_cast<const TrivialPortalLink*>(
0179 nZX->getLink(Direction::AlongNormal()));
0180 BOOST_REQUIRE_NE(nZXLink, nullptr);
0181
0182 grid = nZXLink->makeGrid(AxisDirection::AxisY);
0183
0184 auto newPortalNZX =
0185 std::make_shared<Portal>(Direction::AlongNormal(), std::move(grid));
0186 trapShell.setPortal(newPortalNZX, NegativeYFaceZX);
0187 BOOST_CHECK_EQUAL(trapShell.portal(NegativeYFaceZX), newPortalNZX.get());
0188
0189
0190 BOOST_CHECK_EQUAL(trapShell.portal(NegativeZFaceXY), nXY);
0191 BOOST_CHECK_EQUAL(trapShell.portal(PositiveZFaceXY), pXY);
0192 BOOST_CHECK_EQUAL(trapShell.portal(TrapezoidFaceAlpha), nYZ);
0193 BOOST_CHECK_EQUAL(trapShell.portal(TrapezoidFaceBeta), pYZ);
0194 }
0195
0196 BOOST_AUTO_TEST_CASE(Fill) {
0197 using enum TrapezoidVolumeBounds::Face;
0198
0199 auto trapVol = makeVolume(5_cm, 10_cm, 10_cm, 10_cm);
0200
0201 SingleTrapezoidPortalShell trapShell{trapVol};
0202
0203
0204
0205 BOOST_CHECK_EQUAL(
0206 trapShell.portal(NegativeZFaceXY)->getLink(Direction::OppositeNormal()),
0207 nullptr);
0208
0209
0210
0211 TrackingVolume trapVol2(
0212 Transform3::Identity() * Translation3(Vector3::UnitZ() * 15_cm),
0213 std::make_shared<TrapezoidVolumeBounds>(5_cm, 10_cm, 10_cm, 5_cm),
0214 "trapVol2");
0215
0216 trapShell.fill(trapVol2);
0217
0218 BOOST_CHECK_NE(
0219 trapShell.portal(NegativeZFaceXY)->getLink(Direction::OppositeNormal()),
0220 nullptr);
0221 }
0222
0223 BOOST_AUTO_TEST_CASE(ApplyToVolume) {
0224 using enum TrapezoidVolumeBounds::Face;
0225
0226 auto trapVol = makeVolume(5_cm, 10_cm, 10_cm, 10_cm);
0227
0228 SingleTrapezoidPortalShell trapShell{trapVol};
0229
0230
0231 BOOST_CHECK_EQUAL(trapVol.portals().size(), 0);
0232
0233 trapShell.applyToVolume();
0234
0235
0236 BOOST_CHECK_EQUAL(trapVol.portals().size(), 6);
0237 }
0238
0239 BOOST_AUTO_TEST_SUITE_END()
0240
0241 }