Skip to content

Commit a92d8dd

Browse files
committed
feat: Add check for SurfaceArray grid + transform handling improvement
1 parent 375b870 commit a92d8dd

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

Core/include/Acts/Surfaces/SurfaceArray.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,8 @@ class SurfaceArray {
558558
/// @return Reference to the surface grid lookup interface
559559
const ISurfaceGridLookup& gridLookup() const { return *p_gridLookup; }
560560

561+
void checkGrid(AnyGridConstView<SurfaceVector> grid);
562+
561563
private:
562564
std::unique_ptr<ISurfaceGridLookup> p_gridLookup;
563565
// this vector makes sure we have shared ownership over the surfaces

Core/src/Geometry/SurfaceArrayCreator.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ std::unique_ptr<SurfaceArray> SurfaceArrayCreator::surfaceArrayOnCylinder(
5757
const double layerTolerance = protoLayer.range(AxisDirection::AxisR) * 0.5;
5858

5959
auto surface = Surface::makeShared<CylinderSurface>(fullTransform, R, halfZ);
60+
ACTS_VERBOSE("- projection surface is: " << surface->toString(gctx));
6061
std::unique_ptr<SurfaceArray::ISurfaceGridLookup> sl =
6162
makeSurfaceGridLookup2D<AxisBoundaryType::Closed,
6263
AxisBoundaryType::Bound>(
@@ -150,8 +151,18 @@ std::unique_ptr<SurfaceArray> SurfaceArrayCreator::surfaceArrayOnDisc(
150151
const double Rmax = protoLayer.max(AxisDirection::AxisR, true);
151152
const double layerThickness = protoLayer.range(AxisDirection::AxisZ) * 0.5;
152153
ACTS_VERBOSE("- z-position of disc estimated as " << Z);
154+
ACTS_VERBOSE("- full transform is \n" << fullTransform.matrix());
155+
156+
if (fullTransform.translation().norm() < s_transformEquivalentTolerance) {
157+
ACTS_VERBOSE(
158+
"input transform does not have translation: putting projection surface "
159+
"at center of gravity in z");
160+
fullTransform.translate(Vector3::UnitZ() * Z);
161+
}
153162

154163
auto surface = Surface::makeShared<DiscSurface>(fullTransform, Rmin, Rmax);
164+
ACTS_VERBOSE("- projection surface is: " << surface->toString(gctx));
165+
155166
std::unique_ptr<SurfaceArray::ISurfaceGridLookup> sl =
156167
makeSurfaceGridLookup2D<AxisBoundaryType::Bound,
157168
AxisBoundaryType::Closed>(
@@ -253,6 +264,13 @@ std::unique_ptr<SurfaceArray> SurfaceArrayCreator::surfaceArrayOnDisc(
253264
const double layerThickness = protoLayer.range(AxisDirection::AxisZ) * 0.5;
254265
ACTS_VERBOSE("- z-position of disc estimated as " << Z);
255266

267+
if (fullTransform.translation().norm() < s_transformEquivalentTolerance) {
268+
ACTS_VERBOSE(
269+
"input transform does not have translation: putting projection surface "
270+
"at center of gravity in z");
271+
fullTransform.translate(Vector3::UnitZ() * Z);
272+
}
273+
256274
auto surface = Surface::makeShared<DiscSurface>(fullTransform, Rmin, Rmax);
257275
std::unique_ptr<SurfaceArray::ISurfaceGridLookup> sl =
258276
makeSurfaceGridLookup2D<AxisBoundaryType::Bound,

Core/src/Navigation/SurfaceArrayNavigationPolicy.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "Acts/Navigation/SurfaceArrayNavigationPolicy.hpp"
1010

1111
#include "Acts/Geometry/GeometryContext.hpp"
12+
#include "Acts/Geometry/ProtoLayer.hpp"
1213
#include "Acts/Geometry/SurfaceArrayCreator.hpp"
1314
#include "Acts/Geometry/TrackingVolume.hpp"
1415
#include "Acts/Navigation/NavigationStream.hpp"
@@ -118,7 +119,8 @@ SurfaceArrayNavigationPolicy::SurfaceArrayNavigationPolicy(
118119
throw std::runtime_error("Cannot create surface array with zero surfaces");
119120
}
120121

121-
ProtoLayer protoLayer(gctx, surfaces);
122+
ProtoLayer protoLayer(
123+
gctx, surfaces, Transform3{volume.localToGlobalTransform(gctx).linear()});
122124

123125
if (config.layerType == LayerType::Disc) {
124126
auto [binsR, binsPhi] = config.bins;

Core/src/Surfaces/SurfaceArray.cpp

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111
#include "Acts/Definitions/Algebra.hpp"
1212
#include "Acts/Geometry/SurfaceArrayCreator.hpp"
1313
#include "Acts/Utilities/Helpers.hpp"
14+
#include "Acts/Utilities/Ranges.hpp"
1415

16+
#include <ranges>
1517
#include <utility>
1618

19+
using namespace Acts::Ranges;
1720
namespace Acts {
1821

1922
// implementation for pure virtual destructor of ISurfaceGridLookup
@@ -25,7 +28,13 @@ SurfaceArray::SurfaceArray(std::unique_ptr<ISurfaceGridLookup> gridLookup,
2528
: p_gridLookup(std::move(gridLookup)),
2629
m_surfaces(std::move(surfaces)),
2730
m_surfacesRawPointers(unpackSmartPointers(m_surfaces)),
28-
m_transform(transform) {}
31+
m_transform(transform) {
32+
if (p_gridLookup != nullptr) {
33+
if (const auto& grid = p_gridLookup->getGridView()) {
34+
checkGrid(grid.value());
35+
}
36+
}
37+
}
2938

3039
SurfaceArray::SurfaceArray(std::shared_ptr<const Surface> srf)
3140
: p_gridLookup(std::make_unique<SingleElementLookup>(srf.get())),
@@ -74,4 +83,32 @@ std::ostream& SurfaceArray::toStream(const GeometryContext& /*gctx*/,
7483
return sl;
7584
}
7685

86+
void SurfaceArray::checkGrid(AnyGridConstView<SurfaceVector> grid) {
87+
std::set allSurfaces =
88+
m_surfaces |
89+
std::views::transform([](const auto& sp) { return sp.get(); }) |
90+
to<std::set>;
91+
std::set<const Surface*> seenSurface;
92+
auto bins = grid.numLocalBins();
93+
for (std::size_t i = 0; i <= bins.at(0); ++i) {
94+
for (std::size_t j = 0; j <= bins.at(1); ++j) {
95+
const auto& surfaces = grid.atLocalBins({i, j});
96+
for (const auto& srf : surfaces) {
97+
seenSurface.insert(srf);
98+
}
99+
}
100+
}
101+
102+
if (allSurfaces != seenSurface) {
103+
std::set<const Surface*> diff;
104+
std::ranges::set_difference(allSurfaces, seenSurface,
105+
std::inserter(diff, diff.begin()));
106+
107+
throw std::logic_error(
108+
std::format("SurfaceArray grid does not contain all surfaces provided! "
109+
"{} surfaces not seen",
110+
diff.size()));
111+
}
112+
}
113+
77114
} // namespace Acts

0 commit comments

Comments
 (0)