From 10a68ee64f2dc52dcd151e6bc84ca675aa58cb6c Mon Sep 17 00:00:00 2001 From: Johannes Junggeburth Date: Mon, 9 Mar 2026 21:13:55 +0100 Subject: [PATCH 1/6] Attempt to fix the multi layer navigation policy --- Core/include/Acts/Geometry/IndexGrid.hpp | 17 ++++++++++++++--- .../Acts/Geometry/MultiWireVolumeBuilder.hpp | 3 +-- Core/src/Geometry/AlignablePortalVisitor.cpp | 14 +++++++++++++- .../Navigation/MultiLayerNavigationPolicy.cpp | 16 ++++++++++++++-- .../src/IndexGridNavigationJsonConverter.cpp | 4 ++-- 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/Core/include/Acts/Geometry/IndexGrid.hpp b/Core/include/Acts/Geometry/IndexGrid.hpp index 8edec67c0c7..7cc15fd7672 100644 --- a/Core/include/Acts/Geometry/IndexGrid.hpp +++ b/Core/include/Acts/Geometry/IndexGrid.hpp @@ -23,6 +23,7 @@ #include #include #include +#include namespace Acts { @@ -233,8 +234,14 @@ class IndexGrid { /// These are the cast parameters - copied from constructor std::array casts{}; + + + using Delegate_t = std::function; + + + Delegate_t toLocalFrame = nullptr; /// A transform to be applied to the position - Transform3 transform = Transform3::Identity(); + // Transform3 transform = Transform3::Identity(); /// @brief Constructor for a grid based surface attacher /// @param igrid the grid that is moved into this attacher @@ -243,7 +250,11 @@ class IndexGrid { IndexGrid(grid_type&& igrid, const std::array& icasts, const Transform3& itr = Transform3::Identity()) - : grid(std::move(igrid)), casts(icasts), transform(itr) {} + : grid{std::move(igrid)}, casts{icasts}, + toLocalFrame {[itr](const GeometryContext& /*gctx*/) -> const Transform3& { + return itr; + }}{ + } IndexGrid() = delete; }; @@ -299,7 +310,7 @@ struct IndexGridFiller { // Cast the transform according to the grid binning gridQueries.push_back( GridAccessHelpers::castPosition( - iGrid.transform * ref, iGrid.casts)); + iGrid.toLocalFrame(gctx) * ref, iGrid.casts)); } ACTS_DEBUG(gridQueries.size() << " reference points generated."); // These are now in the grid frame, can be expanded diff --git a/Core/include/Acts/Geometry/MultiWireVolumeBuilder.hpp b/Core/include/Acts/Geometry/MultiWireVolumeBuilder.hpp index a387ed47798..35ddc87b63f 100644 --- a/Core/include/Acts/Geometry/MultiWireVolumeBuilder.hpp +++ b/Core/include/Acts/Geometry/MultiWireVolumeBuilder.hpp @@ -58,8 +58,7 @@ class MultiWireVolumeBuilder { /// @brief Creates a multilayer navigation policy factory that can be used for the trackingVolume /// or attached to a blueprint node /// @return Unique pointer to the created navigation policy factory - std::unique_ptr createNavigationPolicyFactory() - const; + std::unique_ptr createNavigationPolicyFactory() const; private: Config m_config; diff --git a/Core/src/Geometry/AlignablePortalVisitor.cpp b/Core/src/Geometry/AlignablePortalVisitor.cpp index c480bc2080c..b94be475a63 100644 --- a/Core/src/Geometry/AlignablePortalVisitor.cpp +++ b/Core/src/Geometry/AlignablePortalVisitor.cpp @@ -63,7 +63,7 @@ void AlignablePortalVisitor::visitVolume(TrackingVolume& volume) { assert(alignable.back() != nullptr); } ACTS_DEBUG("AlignablePortalVisitor() - Associate " - << alignable.size() << " porttals with the volume."); + << alignable.size() << " portals with the volume."); std::vector portalTrfBefore{}; // If the visitor is in inspection mode, cache the transforms of the // unaligned portals @@ -94,6 +94,18 @@ void AlignablePortalVisitor::visitVolume(TrackingVolume& volume) { } // Ensure that the portal remain where they were supposed to be for (std::size_t p = 0; p < alignable.size(); ++p) { + if (!alignable[p]->isAlignable()) { + ACTS_ERROR("AlignablePortalVisitor() - the " + << p << "-the portal remains not alignable"); + throw std::runtime_error( + "AlignablePortalVisitor() - The portal alignment failed"); + } + if (alignable[p]->isSensitive()) { + ACTS_ERROR("AlignablePortalVisitor() - the " + << p << "-the portal became sensitive"); + throw std::runtime_error( + "AlignablePortalVisitor() - The portal alignment failed"); + } if (!isSame(alignable[p]->localToGlobalTransform(m_gctx), portalTrfBefore[p])) { ACTS_ERROR("AlignablePortalVisitor() - the " diff --git a/Core/src/Navigation/MultiLayerNavigationPolicy.cpp b/Core/src/Navigation/MultiLayerNavigationPolicy.cpp index 320ce0e0dd2..949ea953eaa 100644 --- a/Core/src/Navigation/MultiLayerNavigationPolicy.cpp +++ b/Core/src/Navigation/MultiLayerNavigationPolicy.cpp @@ -12,6 +12,16 @@ #include "Acts/Surfaces/detail/IntersectionHelper2D.hpp" #include "Acts/Utilities/GridAccessHelpers.hpp" +namespace{ + std::string printCandidates(const std::vector& surfaces) { + std::stringstream sstr{}; + for (const auto* surf : surfaces) { + sstr<<" --- "<geometryId()< rphi = { Acts::AxisDirection::AxisR, Acts::AxisDirection::AxisPhi}; auto pVertex = Acts::GridAccessHelpers::castPosition< - Acts::RegularDiscIndexGrid>(indexGrid.transform * vertex, rphi); + Acts::RegularDiscIndexGrid>(indexGrid.toLocalFrame(gctx) * vertex, rphi); // Update reference range referenceRange[0] = std::min(referenceRange[0], pVertex[0]); referenceRange[1] = std::max(referenceRange[1], pVertex[0]); @@ -61,7 +61,7 @@ void writeSurfacesAndProjections( // Write the projected vertices jProjectedSurface.push_back( Acts::GridAccessHelpers::castPosition( - indexGrid.transform * vertex, indexGrid.casts)); + indexGrid.toLocalFrame(gctx) * vertex, indexGrid.casts)); } } jProjectedSurfaces.push_back(jProjectedSurface); From a5683d81449da30f950dd5525cb17c1c8e22a189 Mon Sep 17 00:00:00 2001 From: Johannes Junggeburth Date: Mon, 9 Mar 2026 22:49:55 +0100 Subject: [PATCH 2/6] Setup delegate constructor --- Core/include/Acts/Geometry/IndexGrid.hpp | 24 ++++++++++++------- .../Navigation/IndexGridNavigationPolicy.hpp | 2 +- Core/src/Geometry/MultiWireVolumeBuilder.cpp | 13 ++++++++-- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/Core/include/Acts/Geometry/IndexGrid.hpp b/Core/include/Acts/Geometry/IndexGrid.hpp index 7cc15fd7672..583d423576f 100644 --- a/Core/include/Acts/Geometry/IndexGrid.hpp +++ b/Core/include/Acts/Geometry/IndexGrid.hpp @@ -235,15 +235,15 @@ class IndexGrid { std::array casts{}; - + /// Abrivation of the delegate to transform the + /// external point into the grid's coordinate system using Delegate_t = std::function; - + /// Delegate to transform the external points into the grid's + /// coordinate system Delegate_t toLocalFrame = nullptr; - /// A transform to be applied to the position - // Transform3 transform = Transform3::Identity(); - - /// @brief Constructor for a grid based surface attacher + + /// Constructor for a grid based surface attacher /// @param igrid the grid that is moved into this attacher /// @param icasts is the cast values array /// @param itr a transform applied to the global position @@ -253,8 +253,16 @@ class IndexGrid { : grid{std::move(igrid)}, casts{icasts}, toLocalFrame {[itr](const GeometryContext& /*gctx*/) -> const Transform3& { return itr; - }}{ - } + }}{} + /// Constructor for a grid based surface attacher with alignable delegate + /// @param igrid the grid that is moved into this attacher + /// @param icasts is the cast values array + /// @param trfFunc a transform applied to the global position + IndexGrid(grid_type&& igrid, + const std::array& icasts, + Delegate_t trfFunc) + : grid{std::move(igrid)}, casts{icasts}, + toLocalFrame{trfFunc}{} IndexGrid() = delete; }; diff --git a/Core/include/Acts/Navigation/IndexGridNavigationPolicy.hpp b/Core/include/Acts/Navigation/IndexGridNavigationPolicy.hpp index f59c1fb5cff..5367afcffa9 100644 --- a/Core/include/Acts/Navigation/IndexGridNavigationPolicy.hpp +++ b/Core/include/Acts/Navigation/IndexGridNavigationPolicy.hpp @@ -105,7 +105,7 @@ class IndexGridNavigationPolicy : public INavigationPolicy { const auto& surfaces = m_volume.surfaces(); const auto& indices = m_indexGrid.grid.atPosition(GridAccessHelpers::castPosition( - m_indexGrid.transform * position, m_indexGrid.casts)); + m_indexGrid.toLocalFrame(gctx) * position, m_indexGrid.casts)); // Fill the navigation stream with the container for (const auto& idx : indices) { stream.addSurfaceCandidate(surfaces[idx], args.tolerance); diff --git a/Core/src/Geometry/MultiWireVolumeBuilder.cpp b/Core/src/Geometry/MultiWireVolumeBuilder.cpp index c7e02ec12ec..23d30f00039 100644 --- a/Core/src/Geometry/MultiWireVolumeBuilder.cpp +++ b/Core/src/Geometry/MultiWireVolumeBuilder.cpp @@ -97,10 +97,19 @@ MultiWireVolumeBuilder::createNavigationPolicyFactory() const { axisB); // The indexed grid to be filled from the navigation policy - IndexGrid indexedGrid( + const auto* placement = m_config.alignablePlacement; + auto indexedGrid = placement == nullptr ? + IndexGrid{ std::move(grid), {protoAxisA.getAxisDirection(), protoAxisB.getAxisDirection()}, - m_config.transform.inverse()); + m_config.transform.inverse()} : + IndexGrid{ + std::move(grid), + {protoAxisA.getAxisDirection(), protoAxisB.getAxisDirection()}, + [placement](const GeometryContext& gctx) -> const Transform3&{ + return placement->localToGlobalTransform(gctx); + } }; + ; TryAllNavigationPolicy::Config tryAllConfig; tryAllConfig.portals = true; From e64e217a2b59499f014535b1ff7338a6f3597a58 Mon Sep 17 00:00:00 2001 From: Johannes Junggeburth Date: Tue, 10 Mar 2026 07:49:38 +0100 Subject: [PATCH 3/6] Attempt --- Core/src/Geometry/MultiWireVolumeBuilder.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/src/Geometry/MultiWireVolumeBuilder.cpp b/Core/src/Geometry/MultiWireVolumeBuilder.cpp index 23d30f00039..32353a1f1cd 100644 --- a/Core/src/Geometry/MultiWireVolumeBuilder.cpp +++ b/Core/src/Geometry/MultiWireVolumeBuilder.cpp @@ -106,10 +106,10 @@ MultiWireVolumeBuilder::createNavigationPolicyFactory() const { IndexGrid{ std::move(grid), {protoAxisA.getAxisDirection(), protoAxisB.getAxisDirection()}, - [placement](const GeometryContext& gctx) -> const Transform3&{ + [placement](const GeometryContext& gctx) -> const Transform3& { return placement->localToGlobalTransform(gctx); } }; - ; + TryAllNavigationPolicy::Config tryAllConfig; tryAllConfig.portals = true; From 4b578d3412c2162628eff47318257ff20bbed4b9 Mon Sep 17 00:00:00 2001 From: Johannes Junggeburth Date: Tue, 10 Mar 2026 08:01:02 +0100 Subject: [PATCH 4/6] Pre commit --- Core/include/Acts/Geometry/IndexGrid.hpp | 27 ++++++++++--------- .../Acts/Geometry/MultiWireVolumeBuilder.hpp | 3 ++- Core/src/Geometry/AlignablePortalVisitor.cpp | 8 +++--- Core/src/Geometry/MultiWireVolumeBuilder.cpp | 24 ++++++++--------- .../Navigation/MultiLayerNavigationPolicy.cpp | 27 ++++++++++--------- .../src/IndexGridNavigationJsonConverter.cpp | 3 ++- 6 files changed, 48 insertions(+), 44 deletions(-) diff --git a/Core/include/Acts/Geometry/IndexGrid.hpp b/Core/include/Acts/Geometry/IndexGrid.hpp index 583d423576f..9b4bbcf21bf 100644 --- a/Core/include/Acts/Geometry/IndexGrid.hpp +++ b/Core/include/Acts/Geometry/IndexGrid.hpp @@ -20,10 +20,10 @@ #include #include +#include #include #include #include -#include namespace Acts { @@ -234,15 +234,15 @@ class IndexGrid { /// These are the cast parameters - copied from constructor std::array casts{}; - /// Abrivation of the delegate to transform the /// external point into the grid's coordinate system - using Delegate_t = std::function; - - /// Delegate to transform the external points into the grid's + using Delegate_t = + std::function; + + /// Delegate to transform the external points into the grid's /// coordinate system Delegate_t toLocalFrame = nullptr; - + /// Constructor for a grid based surface attacher /// @param igrid the grid that is moved into this attacher /// @param icasts is the cast values array @@ -250,19 +250,20 @@ class IndexGrid { IndexGrid(grid_type&& igrid, const std::array& icasts, const Transform3& itr = Transform3::Identity()) - : grid{std::move(igrid)}, casts{icasts}, - toLocalFrame {[itr](const GeometryContext& /*gctx*/) -> const Transform3& { - return itr; - }}{} - /// Constructor for a grid based surface attacher with alignable delegate + : grid{std::move(igrid)}, + casts{icasts}, + toLocalFrame{ + [itr](const GeometryContext& /*gctx*/) -> const Transform3& { + return itr; + }} {} + /// Constructor for a grid based surface attacher with alignable delegate /// @param igrid the grid that is moved into this attacher /// @param icasts is the cast values array /// @param trfFunc a transform applied to the global position IndexGrid(grid_type&& igrid, const std::array& icasts, Delegate_t trfFunc) - : grid{std::move(igrid)}, casts{icasts}, - toLocalFrame{trfFunc}{} + : grid{std::move(igrid)}, casts{icasts}, toLocalFrame{trfFunc} {} IndexGrid() = delete; }; diff --git a/Core/include/Acts/Geometry/MultiWireVolumeBuilder.hpp b/Core/include/Acts/Geometry/MultiWireVolumeBuilder.hpp index 35ddc87b63f..a387ed47798 100644 --- a/Core/include/Acts/Geometry/MultiWireVolumeBuilder.hpp +++ b/Core/include/Acts/Geometry/MultiWireVolumeBuilder.hpp @@ -58,7 +58,8 @@ class MultiWireVolumeBuilder { /// @brief Creates a multilayer navigation policy factory that can be used for the trackingVolume /// or attached to a blueprint node /// @return Unique pointer to the created navigation policy factory - std::unique_ptr createNavigationPolicyFactory() const; + std::unique_ptr createNavigationPolicyFactory() + const; private: Config m_config; diff --git a/Core/src/Geometry/AlignablePortalVisitor.cpp b/Core/src/Geometry/AlignablePortalVisitor.cpp index b94be475a63..5e99cd6ffe5 100644 --- a/Core/src/Geometry/AlignablePortalVisitor.cpp +++ b/Core/src/Geometry/AlignablePortalVisitor.cpp @@ -95,15 +95,15 @@ void AlignablePortalVisitor::visitVolume(TrackingVolume& volume) { // Ensure that the portal remain where they were supposed to be for (std::size_t p = 0; p < alignable.size(); ++p) { if (!alignable[p]->isAlignable()) { - ACTS_ERROR("AlignablePortalVisitor() - the " + ACTS_ERROR("AlignablePortalVisitor() - the " << p << "-the portal remains not alignable"); - throw std::runtime_error( + throw std::runtime_error( "AlignablePortalVisitor() - The portal alignment failed"); } if (alignable[p]->isSensitive()) { - ACTS_ERROR("AlignablePortalVisitor() - the " + ACTS_ERROR("AlignablePortalVisitor() - the " << p << "-the portal became sensitive"); - throw std::runtime_error( + throw std::runtime_error( "AlignablePortalVisitor() - The portal alignment failed"); } if (!isSame(alignable[p]->localToGlobalTransform(m_gctx), diff --git a/Core/src/Geometry/MultiWireVolumeBuilder.cpp b/Core/src/Geometry/MultiWireVolumeBuilder.cpp index 32353a1f1cd..a88caa55431 100644 --- a/Core/src/Geometry/MultiWireVolumeBuilder.cpp +++ b/Core/src/Geometry/MultiWireVolumeBuilder.cpp @@ -98,18 +98,18 @@ MultiWireVolumeBuilder::createNavigationPolicyFactory() const { // The indexed grid to be filled from the navigation policy const auto* placement = m_config.alignablePlacement; - auto indexedGrid = placement == nullptr ? - IndexGrid{ - std::move(grid), - {protoAxisA.getAxisDirection(), protoAxisB.getAxisDirection()}, - m_config.transform.inverse()} : - IndexGrid{ - std::move(grid), - {protoAxisA.getAxisDirection(), protoAxisB.getAxisDirection()}, - [placement](const GeometryContext& gctx) -> const Transform3& { - return placement->localToGlobalTransform(gctx); - } }; - + auto indexedGrid = + placement == nullptr + ? IndexGrid{std::move(grid), + {protoAxisA.getAxisDirection(), + protoAxisB.getAxisDirection()}, + m_config.transform.inverse()} + : IndexGrid{ + std::move(grid), + {protoAxisA.getAxisDirection(), protoAxisB.getAxisDirection()}, + [placement](const GeometryContext& gctx) -> const Transform3& { + return placement->localToGlobalTransform(gctx); + }}; TryAllNavigationPolicy::Config tryAllConfig; tryAllConfig.portals = true; diff --git a/Core/src/Navigation/MultiLayerNavigationPolicy.cpp b/Core/src/Navigation/MultiLayerNavigationPolicy.cpp index 949ea953eaa..e771ad917fd 100644 --- a/Core/src/Navigation/MultiLayerNavigationPolicy.cpp +++ b/Core/src/Navigation/MultiLayerNavigationPolicy.cpp @@ -11,16 +11,16 @@ #include "Acts/Geometry/ReferenceGenerators.hpp" #include "Acts/Surfaces/detail/IntersectionHelper2D.hpp" #include "Acts/Utilities/GridAccessHelpers.hpp" - -namespace{ - std::string printCandidates(const std::vector& surfaces) { - std::stringstream sstr{}; - for (const auto* surf : surfaces) { - sstr<<" --- "<geometryId()<& surfaces) { + std::stringstream sstr{}; + for (const auto* surf : surfaces) { + sstr << " --- " << surf->geometryId() << std::endl; + } + return sstr.str(); } +} // namespace namespace Acts::Experimental { @@ -49,10 +49,11 @@ void MultiLayerNavigationPolicy::initializeCandidates( const GeometryContext& gctx, const NavigationArguments& args, NavigationPolicyState& /*state*/, AppendOnlyNavigationStream& stream, const Logger& logger) const { - const Transform3& itransform = m_volume.globalToLocalTransform(gctx); ACTS_VERBOSE("MultiLayerNavigationPolicy Candidates initialization for volume" - << m_volume.volumeName()); - + << m_volume.volumeName() << " @ " + << m_volume.localToGlobalTransform(gctx)); + + const Transform3& itransform = m_volume.globalToLocalTransform(gctx); const Vector3 locPosition = itransform * args.position; const Vector3 locDirection = itransform.linear() * args.direction; @@ -73,7 +74,7 @@ void MultiLayerNavigationPolicy::initializeCandidates( ACTS_VERBOSE("MultiLayerNavigationPolicy Candidates reported " << surfCandidates.size() << " candidates. " - <<"\n "< rphi = { Acts::AxisDirection::AxisR, Acts::AxisDirection::AxisPhi}; auto pVertex = Acts::GridAccessHelpers::castPosition< - Acts::RegularDiscIndexGrid>(indexGrid.toLocalFrame(gctx) * vertex, rphi); + Acts::RegularDiscIndexGrid>( + indexGrid.toLocalFrame(gctx) * vertex, rphi); // Update reference range referenceRange[0] = std::min(referenceRange[0], pVertex[0]); referenceRange[1] = std::max(referenceRange[1], pVertex[0]); From fe5042da098284089edd92ca55e21412bb888f94 Mon Sep 17 00:00:00 2001 From: Johannes Junggeburth Date: Tue, 10 Mar 2026 08:07:11 +0100 Subject: [PATCH 5/6] Typo --- Core/src/Navigation/MultiLayerNavigationPolicy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/src/Navigation/MultiLayerNavigationPolicy.cpp b/Core/src/Navigation/MultiLayerNavigationPolicy.cpp index e771ad917fd..240007d747e 100644 --- a/Core/src/Navigation/MultiLayerNavigationPolicy.cpp +++ b/Core/src/Navigation/MultiLayerNavigationPolicy.cpp @@ -51,7 +51,7 @@ void MultiLayerNavigationPolicy::initializeCandidates( const Logger& logger) const { ACTS_VERBOSE("MultiLayerNavigationPolicy Candidates initialization for volume" << m_volume.volumeName() << " @ " - << m_volume.localToGlobalTransform(gctx)); + << toString(m_volume.localToGlobalTransform(gctx))); const Transform3& itransform = m_volume.globalToLocalTransform(gctx); const Vector3 locPosition = itransform * args.position; From f66b797b8585bda9291ca729832fa4ae4ea1b4b6 Mon Sep 17 00:00:00 2001 From: Johannes Junggeburth Date: Tue, 10 Mar 2026 08:18:42 +0100 Subject: [PATCH 6/6] Clang tidy --- Core/include/Acts/Geometry/IndexGrid.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Core/include/Acts/Geometry/IndexGrid.hpp b/Core/include/Acts/Geometry/IndexGrid.hpp index 9b4bbcf21bf..2c49139d79f 100644 --- a/Core/include/Acts/Geometry/IndexGrid.hpp +++ b/Core/include/Acts/Geometry/IndexGrid.hpp @@ -263,7 +263,9 @@ class IndexGrid { IndexGrid(grid_type&& igrid, const std::array& icasts, Delegate_t trfFunc) - : grid{std::move(igrid)}, casts{icasts}, toLocalFrame{trfFunc} {} + : grid{std::move(igrid)}, + casts{icasts}, + toLocalFrame{std::move(trfFunc)} {} IndexGrid() = delete; };