Skip to content

Commit e2dbdf5

Browse files
authored
fix!: Propagate the alignable volume to the Multilayer navigation policy (#5224)
- Equip the IndexedGrid with a std::function to grep the transform - Construct the IndexedGrid with a function accessing the volume placement if set.
1 parent b71f678 commit e2dbdf5

File tree

6 files changed

+72
-15
lines changed

6 files changed

+72
-15
lines changed

Core/include/Acts/Geometry/IndexGrid.hpp

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <algorithm>
2222
#include <array>
23+
#include <functional>
2324
#include <set>
2425
#include <string>
2526
#include <vector>
@@ -233,17 +234,38 @@ class IndexGrid {
233234
/// These are the cast parameters - copied from constructor
234235
std::array<AxisDirection, grid_type::DIM> casts{};
235236

236-
/// A transform to be applied to the position
237-
Transform3 transform = Transform3::Identity();
237+
/// Abrivation of the delegate to transform the
238+
/// external point into the grid's coordinate system
239+
using Delegate_t =
240+
std::function<const Transform3&(const GeometryContext& gctx)>;
238241

239-
/// @brief Constructor for a grid based surface attacher
242+
/// Delegate to transform the external points into the grid's
243+
/// coordinate system
244+
Delegate_t toLocalFrame = nullptr;
245+
246+
/// Constructor for a grid based surface attacher
240247
/// @param igrid the grid that is moved into this attacher
241248
/// @param icasts is the cast values array
242249
/// @param itr a transform applied to the global position
243250
IndexGrid(grid_type&& igrid,
244251
const std::array<AxisDirection, grid_type::DIM>& icasts,
245252
const Transform3& itr = Transform3::Identity())
246-
: grid(std::move(igrid)), casts(icasts), transform(itr) {}
253+
: grid{std::move(igrid)},
254+
casts{icasts},
255+
toLocalFrame{
256+
[itr](const GeometryContext& /*gctx*/) -> const Transform3& {
257+
return itr;
258+
}} {}
259+
/// Constructor for a grid based surface attacher with alignable delegate
260+
/// @param igrid the grid that is moved into this attacher
261+
/// @param icasts is the cast values array
262+
/// @param trfFunc a transform applied to the global position
263+
IndexGrid(grid_type&& igrid,
264+
const std::array<AxisDirection, grid_type::DIM>& icasts,
265+
Delegate_t trfFunc)
266+
: grid{std::move(igrid)},
267+
casts{icasts},
268+
toLocalFrame{std::move(trfFunc)} {}
247269

248270
IndexGrid() = delete;
249271
};
@@ -299,7 +321,7 @@ struct IndexGridFiller {
299321
// Cast the transform according to the grid binning
300322
gridQueries.push_back(
301323
GridAccessHelpers::castPosition<decltype(iGrid.grid)>(
302-
iGrid.transform * ref, iGrid.casts));
324+
iGrid.toLocalFrame(gctx) * ref, iGrid.casts));
303325
}
304326
ACTS_DEBUG(gridQueries.size() << " reference points generated.");
305327
// These are now in the grid frame, can be expanded

Core/include/Acts/Navigation/IndexGridNavigationPolicy.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class IndexGridNavigationPolicy : public INavigationPolicy {
105105
const auto& surfaces = m_volume.surfaces();
106106
const auto& indices =
107107
m_indexGrid.grid.atPosition(GridAccessHelpers::castPosition<GridType>(
108-
m_indexGrid.transform * position, m_indexGrid.casts));
108+
m_indexGrid.toLocalFrame(gctx) * position, m_indexGrid.casts));
109109
// Fill the navigation stream with the container
110110
for (const auto& idx : indices) {
111111
stream.addSurfaceCandidate(surfaces[idx], args.tolerance);

Core/src/Geometry/AlignablePortalVisitor.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void AlignablePortalVisitor::visitVolume(TrackingVolume& volume) {
6363
assert(alignable.back() != nullptr);
6464
}
6565
ACTS_DEBUG("AlignablePortalVisitor() - Associate "
66-
<< alignable.size() << " porttals with the volume.");
66+
<< alignable.size() << " portals with the volume.");
6767
std::vector<Transform3> portalTrfBefore{};
6868
// If the visitor is in inspection mode, cache the transforms of the
6969
// unaligned portals
@@ -94,6 +94,18 @@ void AlignablePortalVisitor::visitVolume(TrackingVolume& volume) {
9494
}
9595
// Ensure that the portal remain where they were supposed to be
9696
for (std::size_t p = 0; p < alignable.size(); ++p) {
97+
if (!alignable[p]->isAlignable()) {
98+
ACTS_ERROR("AlignablePortalVisitor() - the "
99+
<< p << "-the portal remains not alignable");
100+
throw std::runtime_error(
101+
"AlignablePortalVisitor() - The portal alignment failed");
102+
}
103+
if (alignable[p]->isSensitive()) {
104+
ACTS_ERROR("AlignablePortalVisitor() - the "
105+
<< p << "-the portal became sensitive");
106+
throw std::runtime_error(
107+
"AlignablePortalVisitor() - The portal alignment failed");
108+
}
97109
if (!isSame(alignable[p]->localToGlobalTransform(m_gctx),
98110
portalTrfBefore[p])) {
99111
ACTS_ERROR("AlignablePortalVisitor() - the "

Core/src/Geometry/MultiWireVolumeBuilder.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,19 @@ MultiWireVolumeBuilder::createNavigationPolicyFactory() const {
9797
axisB);
9898

9999
// The indexed grid to be filled from the navigation policy
100-
IndexGrid<decltype(grid)> indexedGrid(
101-
std::move(grid),
102-
{protoAxisA.getAxisDirection(), protoAxisB.getAxisDirection()},
103-
m_config.transform.inverse());
100+
const auto* placement = m_config.alignablePlacement;
101+
auto indexedGrid =
102+
placement == nullptr
103+
? IndexGrid<decltype(grid)>{std::move(grid),
104+
{protoAxisA.getAxisDirection(),
105+
protoAxisB.getAxisDirection()},
106+
m_config.transform.inverse()}
107+
: IndexGrid<decltype(grid)>{
108+
std::move(grid),
109+
{protoAxisA.getAxisDirection(), protoAxisB.getAxisDirection()},
110+
[placement](const GeometryContext& gctx) -> const Transform3& {
111+
return placement->localToGlobalTransform(gctx);
112+
}};
104113

105114
TryAllNavigationPolicy::Config tryAllConfig;
106115
tryAllConfig.portals = true;

Core/src/Navigation/MultiLayerNavigationPolicy.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@
1111
#include "Acts/Geometry/ReferenceGenerators.hpp"
1212
#include "Acts/Surfaces/detail/IntersectionHelper2D.hpp"
1313
#include "Acts/Utilities/GridAccessHelpers.hpp"
14+
#include "Acts/Utilities/StringHelpers.hpp"
15+
namespace {
16+
std::string printCandidates(const std::vector<const Acts::Surface*>& surfaces) {
17+
std::stringstream sstr{};
18+
for (const auto* surf : surfaces) {
19+
sstr << " --- " << surf->geometryId() << std::endl;
20+
}
21+
return sstr.str();
22+
}
23+
} // namespace
1424

1525
namespace Acts::Experimental {
1626

@@ -40,7 +50,9 @@ void MultiLayerNavigationPolicy::initializeCandidates(
4050
NavigationPolicyState& /*state*/, AppendOnlyNavigationStream& stream,
4151
const Logger& logger) const {
4252
ACTS_VERBOSE("MultiLayerNavigationPolicy Candidates initialization for volume"
43-
<< m_volume.volumeName());
53+
<< m_volume.volumeName() << " @ "
54+
<< toString(m_volume.localToGlobalTransform(gctx)));
55+
4456
const Transform3& itransform = m_volume.globalToLocalTransform(gctx);
4557
const Vector3 locPosition = itransform * args.position;
4658
const Vector3 locDirection = itransform.linear() * args.direction;
@@ -61,7 +73,8 @@ void MultiLayerNavigationPolicy::initializeCandidates(
6173
}
6274

6375
ACTS_VERBOSE("MultiLayerNavigationPolicy Candidates reported "
64-
<< surfCandidates.size() << " candidates");
76+
<< surfCandidates.size() << " candidates. "
77+
<< "\n " << printCandidates(surfCandidates));
6578

6679
// fill the navigation stream with the container
6780
for (const auto* surf : surfCandidates) {

Plugins/Json/src/IndexGridNavigationJsonConverter.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ void writeSurfacesAndProjections(
5050
std::array<Acts::AxisDirection, 2u> rphi = {
5151
Acts::AxisDirection::AxisR, Acts::AxisDirection::AxisPhi};
5252
auto pVertex = Acts::GridAccessHelpers::castPosition<
53-
Acts::RegularDiscIndexGrid>(indexGrid.transform * vertex, rphi);
53+
Acts::RegularDiscIndexGrid>(
54+
indexGrid.toLocalFrame(gctx) * vertex, rphi);
5455
// Update reference range
5556
referenceRange[0] = std::min(referenceRange[0], pVertex[0]);
5657
referenceRange[1] = std::max(referenceRange[1], pVertex[0]);
@@ -61,7 +62,7 @@ void writeSurfacesAndProjections(
6162
// Write the projected vertices
6263
jProjectedSurface.push_back(
6364
Acts::GridAccessHelpers::castPosition<decltype(indexGrid.grid)>(
64-
indexGrid.transform * vertex, indexGrid.casts));
65+
indexGrid.toLocalFrame(gctx) * vertex, indexGrid.casts));
6566
}
6667
}
6768
jProjectedSurfaces.push_back(jProjectedSurface);

0 commit comments

Comments
 (0)