From 5ba961504ae1ab35c5e341d54e52b16db370efa1 Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Tue, 27 Aug 2024 18:12:37 +0200 Subject: [PATCH] feat(geo): Add method to connect all outer links on portal This works for single cylinders and for cylinder stacks --- Core/include/Acts/Geometry/PortalShell.hpp | 4 ++ Core/src/Geometry/PortalShell.cpp | 10 ++++ .../Core/Geometry/PortalShellTests.cpp | 50 +++++++++++++++---- 3 files changed, 54 insertions(+), 10 deletions(-) diff --git a/Core/include/Acts/Geometry/PortalShell.hpp b/Core/include/Acts/Geometry/PortalShell.hpp index 3baaf43f69e..35b470d2d78 100644 --- a/Core/include/Acts/Geometry/PortalShell.hpp +++ b/Core/include/Acts/Geometry/PortalShell.hpp @@ -27,6 +27,8 @@ class PortalShellBase { virtual ~PortalShellBase() = default; + virtual void connectOuter(TrackingVolume& volume) = 0; + private: }; @@ -51,6 +53,8 @@ class CylinderPortalShell : public PortalShellBase { virtual const std::shared_ptr& portalPtr(Face face) = 0; virtual void setPortal(std::shared_ptr portal, Face face) = 0; + + void connectOuter(TrackingVolume& volume) override; }; class SingleCylinderPortalShell : public CylinderPortalShell { diff --git a/Core/src/Geometry/PortalShell.cpp b/Core/src/Geometry/PortalShell.cpp index 0811c5770c4..ecb96cbdd68 100644 --- a/Core/src/Geometry/PortalShell.cpp +++ b/Core/src/Geometry/PortalShell.cpp @@ -19,6 +19,16 @@ namespace Acts { +void CylinderPortalShell::connectOuter(TrackingVolume& volume) { + for (Face face : {PositiveDisc, NegativeDisc, OuterCylinder, InnerCylinder, + NegativePhiPlane, PositivePhiPlane}) { + auto* portalAtFace = portal(face); + if (portalAtFace != nullptr) { + portalAtFace->fill(volume); + } + } +} + SingleCylinderPortalShell::SingleCylinderPortalShell(TrackingVolume& volume) { if (volume.volumeBounds().type() != VolumeBounds::BoundsType::eCylinder) { throw std::invalid_argument("Invalid volume bounds type"); diff --git a/Tests/UnitTests/Core/Geometry/PortalShellTests.cpp b/Tests/UnitTests/Core/Geometry/PortalShellTests.cpp index 8a49b41f854..a9bbac95459 100644 --- a/Tests/UnitTests/Core/Geometry/PortalShellTests.cpp +++ b/Tests/UnitTests/Core/Geometry/PortalShellTests.cpp @@ -26,6 +26,19 @@ using namespace Acts::UnitLiterals; namespace Acts::Test { GeometryContext gctx; +std::size_t getVolumeIndex() { + static std::size_t i = 1; + return i++; +} + +auto makeVolume(auto&&... pars) { + TrackingVolume vol(Transform3::Identity(), + std::make_shared( + std::forward(pars)...)); + vol.setVolumeName("cyl" + std::to_string(getVolumeIndex())); + return std::move(vol); +}; + BOOST_AUTO_TEST_SUITE(PortalShellTests) BOOST_AUTO_TEST_CASE(ConstructionFromVolume) { @@ -35,15 +48,6 @@ BOOST_AUTO_TEST_CASE(ConstructionFromVolume) { // | rMin > 0 | 1 | 3 | // | rMin == 0 | 2 | 4 | - std::size_t i = 1; - auto makeVolume = [&](auto&&... pars) { - TrackingVolume vol(Transform3::Identity(), - std::make_shared( - std::forward(pars)...)); - vol.setVolumeName("cyl" + std::to_string(i++)); - return std::move(vol); - }; - auto cyl1 = makeVolume(30_mm, 40_mm, 100_mm); auto cyl2 = makeVolume(0_mm, 40_mm, 100_mm); auto cyl3 = makeVolume(30_mm, 40_mm, 100_mm, 45_degree); @@ -530,7 +534,33 @@ BOOST_AUTO_TEST_CASE(RDirection) { } } -// @TODO: Should CylinderStackPortalShell also do the fusing? +BOOST_AUTO_TEST_CASE(ConnectOuter) { + auto cyl1 = makeVolume(30_mm, 40_mm, 100_mm); + auto cyl2 = makeVolume(0_mm, 50_mm, 110_mm); + + SingleCylinderPortalShell shell{cyl1}; + + using enum CylinderPortalShell::Face; + BOOST_CHECK_EQUAL( + shell.portal(OuterCylinder)->getLink(Direction::AlongNormal), nullptr); + BOOST_CHECK_EQUAL( + shell.portal(InnerCylinder)->getLink(Direction::OppositeNormal), nullptr); + BOOST_CHECK_EQUAL(shell.portal(PositiveDisc)->getLink(Direction::AlongNormal), + nullptr); + BOOST_CHECK_EQUAL( + shell.portal(NegativeDisc)->getLink(Direction::OppositeNormal), nullptr); + + shell.connectOuter(cyl2); + + BOOST_CHECK_NE(shell.portal(OuterCylinder)->getLink(Direction::AlongNormal), + nullptr); + BOOST_CHECK_NE( + shell.portal(InnerCylinder)->getLink(Direction::OppositeNormal), nullptr); + BOOST_CHECK_NE(shell.portal(PositiveDisc)->getLink(Direction::AlongNormal), + nullptr); + BOOST_CHECK_NE(shell.portal(NegativeDisc)->getLink(Direction::OppositeNormal), + nullptr); +} BOOST_AUTO_TEST_SUITE_END() // CylinderStack BOOST_AUTO_TEST_SUITE_END()