File indexing completed on 2025-09-14 08:12:05
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012
0013 #include <type_traits>
0014 #include <variant>
0015
0016 namespace Acts {
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049 class BoundaryTolerance {
0050 public:
0051 struct InfiniteParams {};
0052
0053 struct NoneParams {};
0054
0055 struct AbsoluteEuclideanParams {
0056 double tolerance{};
0057 };
0058
0059 struct Chi2BoundParams {
0060 double maxChi2{};
0061 std::array<double, 4> weight{};
0062
0063 Eigen::Map<SquareMatrix2> weightMatrix() {
0064 return Eigen::Map<SquareMatrix2>(weight.data());
0065 }
0066
0067 Eigen::Map<const SquareMatrix2> weightMatrix() const {
0068 return Eigen::Map<const SquareMatrix2>(weight.data());
0069 }
0070 };
0071
0072 struct Chi2CartesianParams {
0073 double maxChi2{};
0074 std::array<double, 4> weight{};
0075
0076 Eigen::Map<SquareMatrix2> weightMatrix() {
0077 return Eigen::Map<SquareMatrix2>(weight.data());
0078 }
0079
0080 Eigen::Map<const SquareMatrix2> weightMatrix() const {
0081 return Eigen::Map<const SquareMatrix2>(weight.data());
0082 }
0083 };
0084
0085 static_assert(std::is_trivially_copyable_v<Chi2BoundParams>);
0086
0087 private:
0088
0089 using Variant =
0090 std::variant<InfiniteParams, NoneParams, AbsoluteEuclideanParams,
0091 Chi2BoundParams, Chi2CartesianParams>;
0092 static_assert(std::is_trivially_copyable_v<Variant>);
0093
0094
0095 constexpr explicit BoundaryTolerance(Variant variant) : m_variant{variant} {}
0096
0097 public:
0098
0099 constexpr static auto Infinite() noexcept {
0100 return BoundaryTolerance{InfiniteParams{}};
0101 }
0102
0103
0104 constexpr static auto None() noexcept {
0105 return BoundaryTolerance{NoneParams{}};
0106 }
0107
0108
0109 constexpr static auto AbsoluteEuclidean(double tolerance) noexcept {
0110 return BoundaryTolerance{AbsoluteEuclideanParams{tolerance}};
0111 }
0112
0113
0114 static auto Chi2Bound(const SquareMatrix2& weight, double maxChi2) noexcept {
0115 Chi2BoundParams tolerance{maxChi2, {}};
0116 tolerance.weightMatrix() = weight;
0117 return BoundaryTolerance{tolerance};
0118 }
0119
0120
0121 static auto Chi2Cartesian(const SquareMatrix2& weight,
0122 double maxChi2) noexcept {
0123 Chi2CartesianParams tolerance{maxChi2, {}};
0124 tolerance.weightMatrix() = weight;
0125 return BoundaryTolerance{tolerance};
0126 }
0127
0128 BoundaryTolerance(const BoundaryTolerance& other) noexcept = default;
0129 BoundaryTolerance& operator=(const BoundaryTolerance& other) noexcept =
0130 default;
0131 BoundaryTolerance(BoundaryTolerance&& other) noexcept = default;
0132 BoundaryTolerance& operator=(BoundaryTolerance&& other) noexcept = default;
0133
0134 enum class ToleranceMode {
0135 Extend,
0136 None,
0137 Shrink
0138 };
0139
0140
0141 constexpr bool isInfinite() const { return holdsVariant<InfiniteParams>(); }
0142
0143 constexpr bool isNone() const { return holdsVariant<NoneParams>(); }
0144
0145 constexpr bool hasAbsoluteEuclidean() const {
0146 return holdsVariant<AbsoluteEuclideanParams>();
0147 }
0148
0149 constexpr bool hasChi2Bound() const {
0150 return holdsVariant<Chi2BoundParams>();
0151 }
0152
0153 constexpr bool hasChi2Cartesian() const {
0154 return holdsVariant<Chi2CartesianParams>();
0155 }
0156
0157
0158 ToleranceMode toleranceMode() const;
0159
0160
0161 constexpr const AbsoluteEuclideanParams& asAbsoluteEuclidean() const {
0162 return getVariant<AbsoluteEuclideanParams>();
0163 }
0164
0165 constexpr const Chi2BoundParams& asChi2Bound() const {
0166 return getVariant<Chi2BoundParams>();
0167 }
0168
0169 constexpr const Chi2CartesianParams& asChi2Cartesian() const {
0170 return getVariant<Chi2CartesianParams>();
0171 }
0172
0173
0174 bool isTolerated(const Vector2& boundDelta,
0175 const SquareMatrix2& boundToCartesian) const;
0176
0177 private:
0178 Variant m_variant;
0179
0180
0181 template <typename T>
0182 constexpr bool holdsVariant() const {
0183 return std::holds_alternative<T>(m_variant);
0184 }
0185
0186
0187 template <typename T>
0188 constexpr const T& getVariant() const {
0189 return std::get<T>(m_variant);
0190 }
0191
0192 template <typename T>
0193 constexpr const T* getVariantPtr() const {
0194 return holdsVariant<T>() ? &getVariant<T>() : nullptr;
0195 }
0196 };
0197
0198 static_assert(std::is_trivially_copyable_v<BoundaryTolerance>);
0199 static_assert(std::is_trivially_move_constructible_v<BoundaryTolerance>);
0200
0201 }