Skip to content

Commit 3f3e638

Browse files
committed
more aggressive cleanup
1 parent d95f821 commit 3f3e638

10 files changed

Lines changed: 392 additions & 580 deletions

File tree

Core/include/Acts/Geometry/SurfaceArrayCreator.hpp

Lines changed: 18 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,16 @@
1212
#include "Acts/Definitions/Units.hpp"
1313
#include "Acts/Geometry/GeometryContext.hpp"
1414
#include "Acts/Geometry/ProtoLayer.hpp"
15-
#include "Acts/Surfaces/RegularSurface.hpp"
1615
#include "Acts/Surfaces/Surface.hpp"
1716
#include "Acts/Surfaces/SurfaceArray.hpp"
18-
#include "Acts/Utilities/Axis.hpp"
1917
#include "Acts/Utilities/AxisDefinitions.hpp"
2018
#include "Acts/Utilities/BinningType.hpp"
19+
#include "Acts/Utilities/IAxis.hpp"
2120
#include "Acts/Utilities/Logger.hpp"
2221

2322
#include <cmath>
2423
#include <cstddef>
2524
#include <functional>
26-
#include <iterator>
2725
#include <memory>
2826
#include <numbers>
2927
#include <optional>
@@ -61,9 +59,6 @@ using V3Vector = std::vector<Vector3>;
6159
/// 3D points.
6260
using V3Matrix = std::vector<V3Vector>;
6361

64-
/// @brief Scalar type used for axis values in surface array binning
65-
using AxisScalar = Vector3::Scalar;
66-
6762
/// @class SurfaceArrayCreator
6863
///
6964
/// It is designed create sub surface arrays to be ordered on Surfaces
@@ -72,40 +67,6 @@ using AxisScalar = Vector3::Scalar;
7267
class SurfaceArrayCreator {
7368
public:
7469
friend struct ActsTests::SurfaceArrayCreatorFixture;
75-
friend class SurfaceArray;
76-
77-
/// Prototype axis definition for surface binning.
78-
struct ProtoAxis {
79-
/// Binning type (equidistant or variable)
80-
BinningType bType = BinningType::equidistant;
81-
/// Axis direction for binning
82-
AxisDirection axisDir = AxisDirection::AxisX;
83-
/// Number of bins
84-
std::size_t nBins = 0;
85-
/// Minimum value of the axis
86-
AxisScalar min = 0;
87-
/// Maximum value of the axis
88-
AxisScalar max = 0;
89-
/// Bin edges for variable binning
90-
std::vector<AxisScalar> binEdges;
91-
92-
/// Get the bin index for a given value
93-
/// @param x The value to find the bin for
94-
/// @return The bin index
95-
std::size_t getBin(AxisScalar x) const {
96-
if (binEdges.empty()) {
97-
// equidistant
98-
AxisScalar w = (max - min) / nBins;
99-
return static_cast<std::size_t>(std::floor((x - min) / w));
100-
} else {
101-
// variable
102-
const auto it = std::ranges::upper_bound(binEdges, x);
103-
return static_cast<std::size_t>(
104-
std::ranges::distance(binEdges.begin(), it)) -
105-
1;
106-
}
107-
}
108-
};
10970

11071
/// Configuration options for the surface array creator.
11172
struct Config {
@@ -156,7 +117,7 @@ class SurfaceArrayCreator {
156117
/// @param maxNeighborDistance Maximum next neighbor distance to be included in neighbor lookups
157118
///
158119
/// @return a unique pointer to a new SurfaceArray
159-
std::unique_ptr<SurfaceArray> surfaceArrayOnCylinder(
120+
SurfaceArray surfaceArrayOnCylinder(
160121
const GeometryContext& gctx,
161122
std::vector<std::shared_ptr<const Surface>> surfaces, std::size_t binsPhi,
162123
std::size_t binsZ, std::optional<ProtoLayer> protoLayerOpt = std::nullopt,
@@ -181,7 +142,7 @@ class SurfaceArrayCreator {
181142
/// @param maxNeighborDistance Maximum next neighbor distance to be included in neighbor lookups
182143
///
183144
/// @return a unique pointer a new SurfaceArray
184-
std::unique_ptr<SurfaceArray> surfaceArrayOnCylinder(
145+
SurfaceArray surfaceArrayOnCylinder(
185146
const GeometryContext& gctx,
186147
std::vector<std::shared_ptr<const Surface>> surfaces,
187148
BinningType bTypePhi = equidistant, BinningType bTypeZ = equidistant,
@@ -206,7 +167,7 @@ class SurfaceArrayCreator {
206167
/// @param maxNeighborDistance Maximum next neighbor distance to be included in neighbor lookups
207168
///
208169
/// @return a unique pointer a new SurfaceArray
209-
std::unique_ptr<SurfaceArray> surfaceArrayOnDisc(
170+
SurfaceArray surfaceArrayOnDisc(
210171
const GeometryContext& gctx,
211172
std::vector<std::shared_ptr<const Surface>> surfaces, std::size_t binsR,
212173
std::size_t binsPhi,
@@ -236,7 +197,7 @@ class SurfaceArrayCreator {
236197
/// @note If there is more than on R-Ring, number of phi bins
237198
/// will be set to lowest number of surfaces of any R-ring.
238199
/// This ignores bTypePhi and produces equidistant binning in phi
239-
std::unique_ptr<SurfaceArray> surfaceArrayOnDisc(
200+
SurfaceArray surfaceArrayOnDisc(
240201
const GeometryContext& gctx,
241202
std::vector<std::shared_ptr<const Surface>> surfaces, BinningType bTypeR,
242203
BinningType bTypePhi,
@@ -264,7 +225,7 @@ class SurfaceArrayCreator {
264225
/// @param maxNeighborDistance Maximum next neighbor distance to be included in neighbor lookups
265226
///
266227
/// @return a unique pointer a new SurfaceArray
267-
std::unique_ptr<SurfaceArray> surfaceArrayOnPlane(
228+
SurfaceArray surfaceArrayOnPlane(
268229
const GeometryContext& gctx,
269230
std::vector<std::shared_ptr<const Surface>> surfaces, std::size_t bins1,
270231
std::size_t bins2, AxisDirection aDir,
@@ -353,21 +314,22 @@ class SurfaceArrayCreator {
353314
/// @todo implement for x,y binning
354315
/// @param [in] gctx the geometry context for this call
355316
/// @param surfaces are the sensitive surfaces to be
317+
/// @param aBoundaryType the AxisBoundaryType for the axis to be created
356318
/// @param aDir the AxisDirection in which direction should be binned
357319
/// (currently possible: AxisPhi, AxisR, AxisZ)
358320
/// @param protoLayer Instance of @c ProtoLayer holding generic layer info
359321
/// @param transform is the (optional) additional transform applied
360322
/// @return Instance of @c ProtoAxis containing determined properties
361323
/// @note This only creates the @c ProtoAxis, this needs to be turned
362324
/// into an actual @c Axis object to be used
363-
ProtoAxis createVariableAxis(const GeometryContext& gctx,
364-
const std::vector<const Surface*>& surfaces,
365-
AxisDirection aDir, const ProtoLayer& protoLayer,
366-
Transform3& transform) const;
325+
std::unique_ptr<const IAxis> createVariableAxis(
326+
const GeometryContext& gctx, const std::vector<const Surface*>& surfaces,
327+
AxisBoundaryType aBoundaryType, AxisDirection aDir,
328+
const ProtoLayer& protoLayer, Transform3& transform) const;
367329

368330
/// SurfaceArrayCreator internal method
369331
/// Creates a equidistant @c ProtoAxis when the extrema and the bin number
370-
/// are
332+
/// are known.
371333
/// It loops through the surfaces and finds out the needed information
372334
/// First the surfaces are sorted in the binning direction and the so called
373335
/// "key" surfaces (surfaces with different positions in the binning
@@ -379,6 +341,7 @@ class SurfaceArrayCreator {
379341
/// @todo implement for x,y binning
380342
/// @param [in] gctx the geometry context for this call
381343
/// @param surfaces are the sensitive surfaces to be
344+
/// @param aBoundaryType the AxisBoundaryType for the axis to be created
382345
/// @param aDir the AxisDirection in which direction should be binned
383346
/// (currently possible: AxisPhi, AxisR, AxisZ)
384347
/// @param protoLayer Instance of @c ProtoLayer holding generic layer info
@@ -387,72 +350,11 @@ class SurfaceArrayCreator {
387350
/// @return Instance of @c ProtoAxis containing determined properties
388351
/// @note This only creates the @c ProtoAxis, this needs to be turned
389352
/// into an actual @c Axis object to be used
390-
ProtoAxis createEquidistantAxis(const GeometryContext& gctx,
391-
const std::vector<const Surface*>& surfaces,
392-
AxisDirection aDir,
393-
const ProtoLayer& protoLayer,
394-
Transform3& transform,
395-
std::size_t nBins = 0) const;
396-
397-
/// SurfaceArrayCreator internal method
398-
/// @brief Creates a SurfaceGridLookup instance within an any
399-
/// This is essentially a factory which absorbs some if/else logic
400-
/// that is required by the templating.
401-
/// @tparam bdtA AxisBoundaryType of axis A
402-
/// @tparam bdtB AxisBoundaryType of axis B
403-
/// @param surface the surface of the grid
404-
/// @param layerTolerance the layer tolerance
405-
/// @param pAxisA ProtoAxis object for axis A
406-
/// @param pAxisB ProtoAxis object for axis B
407-
/// @param maxNeighborDistance the maximum neighbor distance for the grid lookup
408-
template <AxisBoundaryType bdtA, AxisBoundaryType bdtB>
409-
static std::unique_ptr<SurfaceArray::ISurfaceGridLookup>
410-
makeSurfaceGridLookup2D(std::shared_ptr<RegularSurface> surface,
411-
double layerTolerance, const ProtoAxis& pAxisA,
412-
const ProtoAxis& pAxisB,
413-
std::uint8_t maxNeighborDistance) {
414-
using ISGL = SurfaceArray::ISurfaceGridLookup;
415-
std::unique_ptr<ISGL> ptr;
416-
417-
if (pAxisA.bType == equidistant && pAxisB.bType == equidistant) {
418-
Axis<AxisType::Equidistant, bdtA> axisA(pAxisA.min, pAxisA.max,
419-
pAxisA.nBins);
420-
Axis<AxisType::Equidistant, bdtB> axisB(pAxisB.min, pAxisB.max,
421-
pAxisB.nBins);
422-
423-
ptr = SurfaceArray::makeSurfaceGridLookup(
424-
std::move(surface), layerTolerance, std::tuple{axisA, axisB},
425-
maxNeighborDistance);
426-
427-
} else if (pAxisA.bType == equidistant && pAxisB.bType == arbitrary) {
428-
Axis<AxisType::Equidistant, bdtA> axisA(pAxisA.min, pAxisA.max,
429-
pAxisA.nBins);
430-
Axis<AxisType::Variable, bdtB> axisB(pAxisB.binEdges);
431-
432-
ptr = SurfaceArray::makeSurfaceGridLookup(
433-
std::move(surface), layerTolerance, std::tuple{axisA, axisB},
434-
maxNeighborDistance);
435-
436-
} else if (pAxisA.bType == arbitrary && pAxisB.bType == equidistant) {
437-
Axis<AxisType::Variable, bdtA> axisA(pAxisA.binEdges);
438-
Axis<AxisType::Equidistant, bdtB> axisB(pAxisB.min, pAxisB.max,
439-
pAxisB.nBins);
440-
441-
ptr = SurfaceArray::makeSurfaceGridLookup(
442-
std::move(surface), layerTolerance, std::tuple{axisA, axisB},
443-
maxNeighborDistance);
444-
445-
} else /*if (pAxisA.bType == arbitrary && pAxisB.bType == arbitrary)*/ {
446-
Axis<AxisType::Variable, bdtA> axisA(pAxisA.binEdges);
447-
Axis<AxisType::Variable, bdtB> axisB(pAxisB.binEdges);
448-
449-
ptr = SurfaceArray::makeSurfaceGridLookup(
450-
std::move(surface), layerTolerance, std::tuple{axisA, axisB},
451-
maxNeighborDistance);
452-
}
453-
454-
return ptr;
455-
}
353+
std::unique_ptr<const IAxis> createEquidistantAxis(
354+
const GeometryContext& gctx, const std::vector<const Surface*>& surfaces,
355+
AxisBoundaryType aBoundaryType, AxisDirection aDir,
356+
const ProtoLayer& protoLayer, Transform3& transform,
357+
std::size_t nBins = 0) const;
456358

457359
/// logging instance
458360
std::unique_ptr<const Logger> m_logger;

0 commit comments

Comments
 (0)