Skip to content

Commit

Permalink
refactor!: BinningValue becomes a strong enum (#3337)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgessinger authored Jul 3, 2024
1 parent dfced32 commit b7a3e59
Show file tree
Hide file tree
Showing 173 changed files with 2,536 additions and 1,926 deletions.
6 changes: 3 additions & 3 deletions Core/include/Acts/Detector/ProtoBinning.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Acts::Experimental {
/// translated into concrete axis types
struct ProtoBinning {
/// The binning value of this
BinningValue binValue = BinningValue::binValues;
BinningValue binValue;
/// The axis type: equidistant or variable
Acts::AxisType axisType = Acts::AxisType::Equidistant;
/// The axis boundary type: Open, Bound or Closed
Expand Down Expand Up @@ -73,7 +73,7 @@ struct ProtoBinning {
: binValue(bValue), boundaryType(bType), expansion(exp) {
if (minE >= maxE) {
std::string msg = "ProtoBinning: Invalid binning for value '";
msg += binningValueNames()[bValue];
msg += binningValueName(bValue);
msg += "', min edge (" + std::to_string(minE) + ") ";
msg += " needs to be smaller than max edge (";
msg += std::to_string(maxE) + ").";
Expand Down Expand Up @@ -116,7 +116,7 @@ struct ProtoBinning {
std::string toString() const {
std::stringstream ss;
ss << "ProtoBinning: " << bins() << " bins in "
<< binningValueNames()[binValue];
<< binningValueName(binValue);
ss << (axisType == Acts::AxisType::Variable ? ", variable "
: ", equidistant ");
if (!autorange) {
Expand Down
4 changes: 2 additions & 2 deletions Core/include/Acts/Detector/ProtoSupport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct ProtoSupport {

/// The volume envelope/clearance parameters: these are chosen such that the
/// support surface does not touch the volume extent
ExtentEnvelope volumeClearance = zeroEnvelopes;
ExtentEnvelope volumeClearance = ExtentEnvelope::Zero();

/// The constrain(s) from the internal surfaces, done by parsing
/// the polyhedron vertices of the internal objects before support building
Expand All @@ -69,7 +69,7 @@ struct ProtoSupport {
unsigned int splits = 1u;

/// Planar placement (only valid for planar support surfaces)
BinningValue pPlacement = binZ;
BinningValue pPlacement = BinningValue::binZ;

/// Indicate if the support surface(s) should always be addressed in
/// navigation
Expand Down
2 changes: 1 addition & 1 deletion Core/include/Acts/Detector/detail/ReferenceGenerators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct CenterReferenceGenerator {
///
/// This generator will provide only one filling point and hence
/// only a single bin in the indexed grid.
template <BinningValue bVAL = BinningValue::binValues>
template <BinningValue bVAL>
struct BinningValueReferenceGenerator {
/// Helper to access a reference position based on binning value
///
Expand Down
3 changes: 2 additions & 1 deletion Core/include/Acts/Geometry/CuboidVolumeBounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ class CuboidVolumeBounds : public VolumeBounds {
///
/// @return vector of canonical binning values
std::vector<Acts::BinningValue> canonicalBinning() const override {
return {Acts::binX, Acts::binY, Acts::binZ};
return {Acts::BinningValue::binX, Acts::BinningValue::binY,
Acts::BinningValue::binZ};
};

/// Binning borders in ActsScalar
Expand Down
3 changes: 2 additions & 1 deletion Core/include/Acts/Geometry/CutoutCylinderVolumeBounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ class CutoutCylinderVolumeBounds : public VolumeBounds {
///
/// @return vector of canonical binning values
std::vector<Acts::BinningValue> canonicalBinning() const override {
return {Acts::binR, Acts::binPhi, Acts::binZ};
return {Acts::BinningValue::binR, Acts::BinningValue::binPhi,
Acts::BinningValue::binZ};
};

/// Write information about this instance to an outstream
Expand Down
3 changes: 2 additions & 1 deletion Core/include/Acts/Geometry/CylinderVolumeBounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ class CylinderVolumeBounds : public VolumeBounds {
///
/// @return vector of canonical binning values
std::vector<Acts::BinningValue> canonicalBinning() const override {
return {Acts::binR, Acts::binPhi, Acts::binZ};
return {Acts::BinningValue::binR, Acts::BinningValue::binPhi,
Acts::BinningValue::binZ};
};

/// Binning offset - overloaded for some R-binning types
Expand Down
141 changes: 109 additions & 32 deletions Core/include/Acts/Geometry/Extent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "Acts/Definitions/Algebra.hpp"
#include "Acts/Utilities/BinningType.hpp"
#include "Acts/Utilities/Enumerate.hpp"
#include "Acts/Utilities/Helpers.hpp"
#include "Acts/Utilities/RangeXD.hpp"

#include <array>
Expand All @@ -24,12 +25,74 @@
namespace Acts {

using Envelope = std::array<ActsScalar, 2>;
using ExtentEnvelope = std::array<Envelope, binValues>;

constexpr Envelope zeroEnvelope = {0, 0};
constexpr ExtentEnvelope zeroEnvelopes = {
zeroEnvelope, zeroEnvelope, zeroEnvelope, zeroEnvelope,
zeroEnvelope, zeroEnvelope, zeroEnvelope, zeroEnvelope};

/// This struct models a multi-dimensional enveloper along the binning values
struct ExtentEnvelope {
/// Access a single envelope configuration
/// @param bValue the binning value
/// @return the envelope
Envelope& operator[](BinningValue bValue) {
return m_values.at(toUnderlying(bValue));
}

/// Access a single envelope configuration
/// @param bValue the binning value
/// @return the envelope
const Envelope& operator[](BinningValue bValue) const {
return m_values.at(toUnderlying(bValue));
}

/// Constructor from a single envelope that is assigned to all values
/// @param envelope the envelope to be assigned
explicit ExtentEnvelope(const Envelope& envelope = zeroEnvelope) {
for (auto& val : m_values) {
val = envelope;
}
}

/// Constructor from an array of envelopes
/// @param values the array of envelopes
constexpr explicit ExtentEnvelope(
const std::array<Envelope, numBinningValues()>& values)
: m_values(values) {}

/// Static factory for a zero envelope
/// @return the zero envelope
constexpr static ExtentEnvelope Zero() {
return ExtentEnvelope{{
zeroEnvelope,
zeroEnvelope,
zeroEnvelope,
zeroEnvelope,
zeroEnvelope,
zeroEnvelope,
zeroEnvelope,
zeroEnvelope,
zeroEnvelope,
}};
}

/// Comparison operator between envelope sets
/// @param lhs the left hand side
/// @param rhs the right hand side
/// @return true if the envelopes are equal
friend bool operator==(const ExtentEnvelope& lhs, const ExtentEnvelope& rhs) {
return lhs.m_values == rhs.m_values;
}

/// Comparison operator between envelope sets
/// @param lhs the left hand side
/// @param rhs the right hand side
/// @return true if the envelopes are not equal
friend bool operator!=(const ExtentEnvelope& lhs, const ExtentEnvelope& rhs) {
return !(lhs.m_values == rhs.m_values);
}

private:
std::array<Envelope, numBinningValues()> m_values{};
};

/// A class representing the geometric extent of an object in its possible
/// dimensions, these can be all dimensions that are described as BinningValues
Expand All @@ -40,7 +103,7 @@ constexpr ExtentEnvelope zeroEnvelopes = {
class Extent {
public:
/// Constructor with (optional) @param envelope
Extent(const ExtentEnvelope& envelope = zeroEnvelopes);
explicit Extent(const ExtentEnvelope& envelope = ExtentEnvelope::Zero());

/// Define a comparison operator
bool operator==(const Extent& e) const;
Expand All @@ -56,7 +119,7 @@ class Extent {
/// @param fillHistograms is a boolean flag to steer whether the values
/// to fill this extent should be stored
void extend(const Vector3& vtx,
const std::vector<BinningValue>& bValues = s_binningValues,
const std::vector<BinningValue>& bValues = allBinningValues(),
bool applyEnv = true, bool fillHistograms = false);

/// Extend with a set of vectors by iterators
Expand All @@ -69,7 +132,7 @@ class Extent {
/// to fill this extent should be stored
template <typename vector_iterator_t>
void extend(const vector_iterator_t& start, const vector_iterator_t& end,
const std::vector<BinningValue>& bValues = s_binningValues,
const std::vector<BinningValue>& bValues = allBinningValues(),
bool applyEnv = true, bool fillHistograms = false) {
for (vector_iterator_t vIt = start; vIt < end; ++vIt) {
extend(*vIt, bValues, applyEnv, fillHistograms);
Expand All @@ -91,7 +154,7 @@ class Extent {
///
/// @note that the histogram values can not be filled in this call
void extend(const Extent& rhs,
const std::vector<BinningValue>& bValues = s_binningValues,
const std::vector<BinningValue>& bValues = allBinningValues(),
bool applyEnv = true);

/// Constrain an extent by another one, this is
Expand All @@ -102,7 +165,7 @@ class Extent {
///
/// @param envelope an envelope applied to the constrained value
void addConstrain(const Extent& rhs,
const ExtentEnvelope& envelope = zeroEnvelopes);
const ExtentEnvelope& envelope = ExtentEnvelope::Zero());

/// Set a range for a dedicated binning value
///
Expand All @@ -126,14 +189,14 @@ class Extent {
/// (re-)Set the envelope
///
/// @param envelope new envelope to be set
void setEnvelope(const ExtentEnvelope& envelope = zeroEnvelopes);
void setEnvelope(const ExtentEnvelope& envelope = ExtentEnvelope::Zero());

/// Return the individual 1-dimensional range
///
/// @param bValue is the binning value to be returned
///
/// @return a one dimensional arrange
auto range(BinningValue bValue) { return m_range[bValue]; }
auto range(BinningValue bValue) { return m_range[toUnderlying(bValue)]; }

/// Return the individual 1-dimensional range
///
Expand All @@ -143,10 +206,13 @@ class Extent {
Range1D<ActsScalar> range(BinningValue bValue) const;

/// Return the N-dimension range
const RangeXD<binValues, ActsScalar>& range() const;
const RangeXD<numBinningValues(), ActsScalar>& range() const;

/// Return an D-dimensional sub range according to the
/// the given @param binValues
/// the given binvalues
/// @tparam kSUBDIM the number of sub dimensions
/// @param binValues the binning values
/// @return the sub range
template <unsigned int kSUBDIM>
RangeXD<kSUBDIM, ActsScalar> range(
const std::array<BinningValue, kSUBDIM>& binValues) const {
Expand All @@ -166,40 +232,47 @@ class Extent {
/// Return the histogram store
///
/// The histogram store can be used for automated binning detection
const std::array<std::vector<ActsScalar>, binValues>& valueHistograms() const;
const std::array<std::vector<ActsScalar>, numBinningValues()>&
valueHistograms() const;

/// Access the minimum parameter
///
/// @param bValue the binning identification
ActsScalar min(BinningValue bValue) const { return m_range[bValue].min(); }
ActsScalar min(BinningValue bValue) const {
return m_range[toUnderlying(bValue)].min();
}

/// Access the maximum parameter
///
/// @param bValue the binning identification
ActsScalar max(BinningValue bValue) const { return m_range[bValue].max(); }
ActsScalar max(BinningValue bValue) const {
return m_range[toUnderlying(bValue)].max();
}

/// Access the midpoint
///
/// @param bValue the binning identification
ActsScalar medium(BinningValue bValue) const {
return 0.5 * (m_range[bValue].min() + m_range[bValue].max());
return 0.5 * (m_range[toUnderlying(bValue)].min() +
m_range[toUnderlying(bValue)].max());
}

/// Access the parameter interval (i.e. the range span)
///
/// @param bValue the binning identification
ActsScalar interval(BinningValue bValue) const {
return m_range[bValue].size();
return m_range[toUnderlying(bValue)].size();
}

/// Contains check
///
/// @param rhs the extent that is check if it is contained
/// @param bValue is the binning value, if set to binValues
/// @param bValue is the binning value, if set to nullopt
/// the check on all is done
///
/// @return true if the rhs is contained
bool contains(const Extent& rhs, BinningValue bValue = binValues) const;
bool contains(const Extent& rhs,
std::optional<BinningValue> bValue = std::nullopt) const;

/// Contains check for a single point
///
Expand All @@ -211,16 +284,20 @@ class Extent {
/// Intersection checks
///
/// @param rhs the extent that is check for intersection
/// @param bValue is the binning value, if set to binValues
/// @param bValue is the binning value, if set to nulloptr
/// the check on all is done
///
/// @return true if the rhs intersects
bool intersects(const Extent& rhs, BinningValue bValue = binValues) const;
bool intersects(const Extent& rhs,
std::optional<BinningValue> bValue = std::nullopt) const;

/// Constraints check
/// Check if this object constrains a given direction
///
/// @param bValue is the binning value, if all the check on all is done
bool constrains(BinningValue bValue = binValues) const;
/// @param bValue is the binning value
bool constrains(BinningValue bValue) const;

/// Check if this object constrains any direction
bool constrains() const;

/// Convert to output stream for screen output
///
Expand All @@ -229,20 +306,20 @@ class Extent {

private:
/// A bitset that remembers the constraint values
std::bitset<binValues> m_constrains{0};
std::bitset<numBinningValues()> m_constrains{0};
/// The actual range store
RangeXD<binValues, ActsScalar> m_range;
RangeXD<numBinningValues(), ActsScalar> m_range;
/// A potential envelope
ExtentEnvelope m_envelope = zeroEnvelopes;
ExtentEnvelope m_envelope = ExtentEnvelope::Zero();
/// (Optional) Value histograms for bin detection
std::array<std::vector<ActsScalar>, binValues> m_valueHistograms;
std::array<std::vector<ActsScalar>, numBinningValues()> m_valueHistograms;
};

inline Range1D<ActsScalar> Acts::Extent::range(BinningValue bValue) const {
return m_range[bValue];
return m_range[toUnderlying(bValue)];
}

inline const RangeXD<binValues, ActsScalar>& Extent::range() const {
inline const RangeXD<numBinningValues(), ActsScalar>& Extent::range() const {
return m_range;
}

Expand All @@ -254,7 +331,7 @@ inline const ExtentEnvelope& Extent::envelope() const {
return m_envelope;
}

inline const std::array<std::vector<ActsScalar>, binValues>&
inline const std::array<std::vector<ActsScalar>, numBinningValues()>&
Extent::valueHistograms() const {
return m_valueHistograms;
}
Expand Down
3 changes: 2 additions & 1 deletion Core/include/Acts/Geometry/GenericCuboidVolumeBounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ class GenericCuboidVolumeBounds : public VolumeBounds {
///
/// @return vector of canonical binning values
std::vector<Acts::BinningValue> canonicalBinning() const override {
return {Acts::binX, Acts::binY, Acts::binZ};
return {Acts::BinningValue::binX, Acts::BinningValue::binY,
Acts::BinningValue::binZ};
};

/// @param sl is the output stream to be written into
Expand Down
Loading

0 comments on commit b7a3e59

Please sign in to comment.