Skip to content
1 change: 0 additions & 1 deletion Core/include/Acts/Geometry/SurfaceArrayCreator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "Acts/Utilities/BinningType.hpp"
#include "Acts/Utilities/Logger.hpp"

#include <algorithm>
#include <cmath>
#include <cstddef>
#include <functional>
Expand Down
22 changes: 12 additions & 10 deletions Core/include/Acts/Utilities/Axis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@

/// get bin width
/// @return constant width for all bins
double getBinWidth(std::size_t /*bin*/ = 0) const { return m_width; }
double getBinWidth(std::size_t /*bin*/ = 0) const final { return m_width; }

Check warning on line 221 in Core/include/Acts/Utilities/Axis.hpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the default value for this parameter since the base class does not have a default value.

See more on https://sonarcloud.io/project/issues?id=acts-project_acts&issues=AZ6s9Q2BwBd4NUUf81yV&open=AZ6s9Q2BwBd4NUUf81yV&pullRequest=5531

/// get lower bound of bin
/// @param bin index of bin
Expand All @@ -229,7 +229,7 @@
///
/// @note Bin intervals have a closed lower bound, i.e. the lower boundary
/// belongs to the bin with the given bin index.
double getBinLowerBound(std::size_t bin) const {
double getBinLowerBound(std::size_t bin) const final {
return getMin() + (bin - 1) * getBinWidth();
}

Expand All @@ -240,7 +240,7 @@
/// i.e. \f$0 \le \text{bin} \le \text{nBins}\f$
/// @note Bin intervals have an open upper bound, i.e. the upper boundary
/// does @b not belong to the bin with the given bin index.
double getBinUpperBound(std::size_t bin) const {
double getBinUpperBound(std::size_t bin) const final {
return getMin() + bin * getBinWidth();
}

Expand All @@ -249,7 +249,7 @@
/// @return bin center position
/// @pre @c bin must be a valid bin index (excluding under-/overflow bins),
/// i.e. \f$1 \le \text{bin} \le \text{nBins}\f$
double getBinCenter(std::size_t bin) const {
double getBinCenter(std::size_t bin) const final {
return getMin() + (bin - 0.5) * getBinWidth();
}

Expand All @@ -271,7 +271,7 @@
/// @c false
/// @post If @c true is returned, the bin containing the given value is a
/// valid bin, i.e. it is neither the underflow nor the overflow bin.
bool isInside(double x) const { return (m_min <= x) && (x < m_max); }
bool isInside(double x) const final { return (m_min <= x) && (x < m_max); }

/// Return a vector of bin edges
/// @return Vector which contains the bin edges
Expand Down Expand Up @@ -503,7 +503,7 @@
/// @return width of given bin
/// @pre @c bin must be a valid bin index (excluding under-/overflow bins),
/// i.e. \f$1 \le \text{bin} \le \text{nBins}\f$
double getBinWidth(std::size_t bin) const {
double getBinWidth(std::size_t bin) const final {
return m_binEdges.at(bin) - m_binEdges.at(bin - 1);
}

Expand All @@ -514,7 +514,7 @@
/// i.e. \f$1 \le \text{bin} \le \text{nBins} + 1\f$
/// @note Bin intervals have a closed lower bound, i.e. the lower boundary
/// belongs to the bin with the given bin index.
double getBinLowerBound(std::size_t bin) const {
double getBinLowerBound(std::size_t bin) const final {
return m_binEdges.at(bin - 1);
}

Expand All @@ -525,14 +525,16 @@
/// i.e. \f$0 \le \text{bin} \le \text{nBins}\f$
/// @note Bin intervals have an open upper bound, i.e. the upper boundary
/// does @b not belong to the bin with the given bin index.
double getBinUpperBound(std::size_t bin) const { return m_binEdges.at(bin); }
double getBinUpperBound(std::size_t bin) const final {
return m_binEdges.at(bin);
}

/// get bin center
/// @param bin index of bin
/// @return bin center position
/// @pre @c bin must be a valid bin index (excluding under-/overflow bins),
/// i.e. \f$1 \le \text{bin} \le \text{nBins}\f$
double getBinCenter(std::size_t bin) const {
double getBinCenter(std::size_t bin) const final {
return 0.5 * (getBinLowerBound(bin) + getBinUpperBound(bin));
}

Expand All @@ -553,7 +555,7 @@
/// @return @c true if \f$\text{xmin} \le x < \text{xmax}\f$, otherwise @c false
/// @post If @c true is returned, the bin containing the given value is a
/// valid bin, i.e. it is neither the underflow nor the overflow bin.
bool isInside(double x) const {
bool isInside(double x) const final {
return (m_binEdges.front() <= x) && (x < m_binEdges.back());
}

Expand Down
120 changes: 58 additions & 62 deletions Core/include/Acts/Utilities/Grid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "Acts/Utilities/IAxis.hpp"
#include "Acts/Utilities/IGrid.hpp"
#include "Acts/Utilities/Interpolation.hpp"
#include "Acts/Utilities/MultiAxis.hpp"
#include "Acts/Utilities/TypeTag.hpp"
#include "Acts/Utilities/detail/MultiAxisHelper.hpp"

Expand Down Expand Up @@ -47,6 +48,8 @@ class Grid final : public IGrid {
/// number of dimensions of the grid
static constexpr std::size_t DIM = sizeof...(Axes);

/// multi axis type
using multi_axis_t = MultiAxis<Axes...>;
/// type of values stored
using value_type = T;
/// reference type to values stored
Expand Down Expand Up @@ -103,6 +106,34 @@ class Grid final : public IGrid {
m_values.resize(size());
}

/// @brief Constructor from const axis tuple, this will allow
/// creating a grid with a different value type from a template
/// grid object.
///
/// @param axes
explicit Grid(const multi_axis_t& axes) : m_axes(axes) {
m_values.resize(size());
}

/// @brief Move constructor from axis tuple
/// @param axes
explicit Grid(multi_axis_t&& axes) : m_axes(std::move(axes)) {
m_values.resize(size());
}

/// @brief constructor from parameters pack of axes and type tag
/// @param axes
explicit Grid(TypeTag<T> /*tag*/, const multi_axis_t& axes) : m_axes(axes) {
m_values.resize(size());
}

/// @brief constructor from parameters pack of axes and type tag
/// @param axes
explicit Grid(TypeTag<T> /*tag*/, multi_axis_t&& axes)
: m_axes(std::move(axes)) {
m_values.resize(size());
}

// Grid(TypeTag<T> /*tag*/, Axes&... axes) = delete;

/// @brief access value stored in bin for a given point
Expand Down Expand Up @@ -224,7 +255,7 @@ class Grid final : public IGrid {
/// @pre All local bin indices must be a valid index for the corresponding
/// axis (excluding the under-/overflow bins for each axis).
point_t binCenter(const index_t& localBins) const {
return detail::MultiAxisHelper::getBinCenter(localBins, m_axes);
return m_axes.getBinCenter(localBins);
}

AnyPointType binCenterAny(AnyIndexType indices) const override {
Expand Down Expand Up @@ -255,8 +286,7 @@ class Grid final : public IGrid {
/// @pre All local bin indices must be a valid index for the corresponding
/// axis (including the under-/overflow bin for this axis).
std::size_t globalBinFromLocalBins(const index_t& localBins) const {
return detail::MultiAxisHelper::getFlatIndexFromMultiIndex(localBins,
m_axes);
return m_axes.getFlatIndexFromMultiIndex(localBins);
}

/// @brief determine global bin index of the bin with the lower left edge
Expand Down Expand Up @@ -290,7 +320,8 @@ class Grid final : public IGrid {
/// @note This could be a under-/overflow bin along one or more axes.
template <class Point>
index_t localBinsFromPosition(const Point& point) const {
return detail::MultiAxisHelper::getMultiIndexFromPoint(point, m_axes);
return detail::MultiAxisHelper::getMultiIndexFromPoint(
point, m_axes.getAxesTuple());
}

/// @brief determine local bin index for each axis from global bin index
Expand All @@ -302,7 +333,7 @@ class Grid final : public IGrid {
/// @note Local bin indices can contain under-/overflow bins along the
/// corresponding axis.
index_t localBinsFromGlobalBin(std::size_t bin) const {
return detail::MultiAxisHelper::getMultiIndexFromFlatIndex(bin, m_axes);
return m_axes.getMultiIndexFromFlatIndex(bin);
}

/// @brief determine local bin index of the bin with the lower left edge
Expand All @@ -321,12 +352,12 @@ class Grid final : public IGrid {
template <class Point>
index_t localBinsFromLowerLeftEdge(const Point& point) const {
Point shiftedPoint;
point_t width = detail::MultiAxisHelper::getWidth(m_axes);
point_t width = detail::MultiAxisHelper::getWidth(m_axes.getAxesTuple());
for (std::size_t i = 0; i < DIM; i++) {
shiftedPoint[i] = point[i] + width[i] / 2;
}
return detail::MultiAxisHelper::getMultiIndexFromPoint(shiftedPoint,
m_axes);
return detail::MultiAxisHelper::getMultiIndexFromPoint(
shiftedPoint, m_axes.getAxesTuple());
}

/// @brief retrieve lower-left bin edge from set of local bin indices
Expand All @@ -337,7 +368,7 @@ class Grid final : public IGrid {
/// @pre @c localBins must only contain valid bin indices (excluding
/// underflow bins).
point_t lowerLeftBinEdge(const index_t& localBins) const {
return detail::MultiAxisHelper::getLowerLeftBinCorner(localBins, m_axes);
return m_axes.getLowerLeftBinCorner(localBins);
}

/// @copydoc Acts::IGrid::lowerLeftBinEdgeAny
Expand All @@ -353,7 +384,7 @@ class Grid final : public IGrid {
/// @pre @c localBins must only contain valid bin indices (excluding
/// overflow bins).
point_t upperRightBinEdge(const index_t& localBins) const {
return detail::MultiAxisHelper::getUpperRightBinCorner(localBins, m_axes);
return m_axes.getUpperRightBinCorner(localBins);
}

/// @copydoc Acts::IGrid::upperRightBinEdgeAny
Expand All @@ -364,16 +395,16 @@ class Grid final : public IGrid {
/// @brief get bin width along each specific axis
///
/// @return array giving the bin width alonf all axes
point_t binWidth() const { return detail::MultiAxisHelper::getWidth(m_axes); }
point_t binWidth() const {
return detail::MultiAxisHelper::getWidth(m_axes.getAxesTuple());
}

/// @brief get number of bins along each specific axis
///
/// @return array giving the number of bins along all axes
///
/// @note Not including under- and overflow bins
index_t numLocalBins() const {
return detail::MultiAxisHelper::getNBins(m_axes);
}
index_t numLocalBins() const { return m_axes.getNBins(); }

/// @copydoc Acts::IGrid::numLocalBinsAny
AnyIndexType numLocalBinsAny() const override {
Expand All @@ -383,16 +414,12 @@ class Grid final : public IGrid {
/// @brief get the minimum value of all axes of one grid
///
/// @return array returning the minima of all given axes
point_t minPosition() const {
return detail::MultiAxisHelper::getMin(m_axes);
}
point_t minPosition() const { return m_axes.getMinPoint(); }

/// @brief get the maximum value of all axes of one grid
///
/// @return array returning the maxima of all given axes
point_t maxPosition() const {
return detail::MultiAxisHelper::getMax(m_axes);
}
point_t maxPosition() const { return m_axes.getMaxPoint(); }

/// @brief set all overflow and underflow bins to a certain value
///
Expand All @@ -401,7 +428,7 @@ class Grid final : public IGrid {
///
void setExteriorBins(const value_type& value) {
for (std::size_t index :
detail::MultiAxisHelper::exteriorBinIndices(m_axes)) {
detail::MultiAxisHelper::exteriorBinIndices(m_axes.getAxesTuple())) {
at(index) = value;
}
}
Expand Down Expand Up @@ -471,7 +498,7 @@ class Grid final : public IGrid {
/// along any axis.
template <class Point>
bool isInside(const Point& position) const {
return detail::MultiAxisHelper::isInside(position, m_axes);
return detail::MultiAxisHelper::isInside(position, m_axes.getAxesTuple());
}

/// @brief get global bin indices for neighborhood
Expand All @@ -492,7 +519,7 @@ class Grid final : public IGrid {
detail::FlatNeighborHoodIndices<DIM> neighborHoodIndices(
const index_t& localBins, std::size_t size = 1u) const {
return detail::MultiAxisHelper::neighborHoodIndices(localBins, size,
m_axes);
m_axes.getAxesTuple());
}

/// @brief get global bin indices for neighborhood
Expand All @@ -515,7 +542,7 @@ class Grid final : public IGrid {
const index_t& localBins,
std::array<std::pair<int, int>, DIM>& sizePerAxis) const {
return detail::MultiAxisHelper::neighborHoodIndices(localBins, sizePerAxis,
m_axes);
m_axes.getAxesTuple());
}

/// @brief total number of bins
Expand All @@ -525,21 +552,7 @@ class Grid final : public IGrid {
///
/// @note This number contains under-and overflow bins along all axes.
std::size_t size(bool fullCounter = true) const {
index_t nBinsArray = numLocalBins();
std::size_t current_size = 1;
// add under-and overflow bins for each axis and multiply all bins
if (fullCounter) {
for (const auto& value : nBinsArray) {
current_size *= value + 2;
}
}
// ignore under-and overflow bins for each axis and multiply all bins
else {
for (const auto& value : nBinsArray) {
current_size *= value;
}
}
return current_size;
return m_axes.getNTotalBins(fullCounter);
}

/// @brief Convenience function to convert the type of the grid
Expand Down Expand Up @@ -579,15 +592,12 @@ class Grid final : public IGrid {

/// @brief get the axes as a tuple
/// @return Reference to the tuple containing all grid axes
const std::tuple<Axes...>& axesTuple() const { return m_axes; }
const std::tuple<Axes...>& axesTuple() const { return m_axes.getAxesTuple(); }

/// @brief get the axes as an array of IAxis pointers
/// @return Vector containing pointers to all grid axes
boost::container::small_vector<const IAxis*, 3> axes() const override {
boost::container::small_vector<const IAxis*, 3> result;
auto axes = detail::MultiAxisHelper::getAxes(m_axes);
std::ranges::copy(axes, std::back_inserter(result));
return result;
return m_axes.getAnyAxesVector();
}

/// begin iterator for global bins
Expand Down Expand Up @@ -622,13 +632,11 @@ class Grid final : public IGrid {
}

protected:
void toStream(std::ostream& os) const override {
printAxes(os, std::make_index_sequence<sizeof...(Axes)>());
}
void toStream(std::ostream& os) const override { os << m_axes; }

private:
/// set of axis defining the multi-dimensional grid
std::tuple<Axes...> m_axes;
/// multi axis for the grid
multi_axis_t m_axes;
/// linear value store for each bin
std::vector<T> m_values;

Expand All @@ -637,19 +645,7 @@ class Grid final : public IGrid {
// doesn't make that much sense from an API design standpoint.
detail::FlatNeighborHoodIndices<DIM> rawClosestPointsIndices(
const index_t& localBins) const {
return detail::MultiAxisHelper::closestPointsIndices(localBins, m_axes);
}

template <std::size_t... Is>
void printAxes(std::ostream& os, std::index_sequence<Is...> /*s*/) const {
auto printOne = [&os, this]<std::size_t index>(
std::integral_constant<std::size_t, index>) {
if constexpr (index > 0) {
os << ", ";
}
os << std::get<index>(m_axes);
};
(printOne(std::integral_constant<std::size_t, Is>()), ...);
return m_axes.getClosestPointsIndices(localBins);
}

static AnyIndexType toAnyIndexType(const index_t& indices) {
Expand Down
Loading
Loading