File indexing completed on 2025-07-06 07:51:51
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012
0013 #include <optional>
0014 #include <type_traits>
0015 #include <variant>
0016
0017 namespace Acts {
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
0050
0051
0052
0053
0054
0055
0056 class BoundaryTolerance {
0057 public:
0058 struct InfiniteParams {};
0059
0060 struct NoneParams {};
0061
0062 struct AbsoluteBoundParams {
0063 double tolerance0{};
0064 double tolerance1{};
0065 };
0066
0067 struct AbsoluteCartesianParams {
0068 double tolerance0{};
0069 double tolerance1{};
0070 };
0071
0072 struct AbsoluteEuclideanParams {
0073 double tolerance{};
0074 };
0075
0076 struct Chi2BoundParams {
0077 double maxChi2{};
0078 std::array<double, 4> weight;
0079
0080 Eigen::Map<SquareMatrix2> weightMatrix() {
0081 return Eigen::Map<SquareMatrix2>(weight.data());
0082 }
0083
0084 Eigen::Map<const SquareMatrix2> weightMatrix() const {
0085 return Eigen::Map<const SquareMatrix2>(weight.data());
0086 }
0087 };
0088
0089 static_assert(std::is_trivially_copyable_v<Chi2BoundParams>);
0090
0091 private:
0092
0093 using Variant = std::variant<InfiniteParams, NoneParams, AbsoluteBoundParams,
0094 AbsoluteCartesianParams, AbsoluteEuclideanParams,
0095 Chi2BoundParams>;
0096 static_assert(std::is_trivially_copyable_v<Variant>);
0097
0098
0099 explicit BoundaryTolerance(Variant variant);
0100
0101 public:
0102
0103 static auto Infinite() noexcept {
0104 return BoundaryTolerance{InfiniteParams{}};
0105 }
0106
0107
0108 static auto None() noexcept { return BoundaryTolerance{NoneParams{}}; }
0109
0110
0111 static auto AbsoluteBound(double tolerance0, double tolerance1) {
0112 if (tolerance0 < 0 || tolerance1 < 0) {
0113 throw std::invalid_argument(
0114 "AbsoluteBound: Tolerance must be non-negative");
0115 }
0116 return BoundaryTolerance{AbsoluteBoundParams{tolerance0, tolerance1}};
0117 }
0118
0119
0120 static auto AbsoluteCartesian(double tolerance0, double tolerance1) {
0121 if (tolerance0 < 0 || tolerance1 < 0) {
0122 throw std::invalid_argument(
0123 "AbsoluteCartesian: Tolerance must be non-negative");
0124 }
0125 if ((tolerance0 == 0) != (tolerance1 == 0)) {
0126 throw std::invalid_argument(
0127 "AbsoluteCartesian: Both tolerances must be zero or non-zero");
0128 }
0129 return BoundaryTolerance{AbsoluteCartesianParams{tolerance0, tolerance1}};
0130 }
0131
0132
0133 static auto AbsoluteEuclidean(double tolerance) noexcept {
0134 return BoundaryTolerance{AbsoluteEuclideanParams{tolerance}};
0135 }
0136
0137
0138 static auto Chi2Bound(const SquareMatrix2& weight, double maxChi2) noexcept {
0139 Chi2BoundParams tolerance{maxChi2, {}};
0140 tolerance.weightMatrix() = weight;
0141 return BoundaryTolerance{tolerance};
0142 }
0143
0144 BoundaryTolerance(const BoundaryTolerance& other) noexcept = default;
0145 BoundaryTolerance& operator=(const BoundaryTolerance& other) noexcept =
0146 default;
0147 BoundaryTolerance(BoundaryTolerance&& other) noexcept = default;
0148 BoundaryTolerance& operator=(BoundaryTolerance&& other) noexcept = default;
0149
0150 enum class ToleranceMode {
0151 Extend,
0152 None,
0153 Shrink
0154 };
0155
0156
0157 bool isInfinite() const;
0158
0159 bool isNone() const;
0160
0161 bool hasAbsoluteBound(bool isCartesian = false) const;
0162
0163 bool hasAbsoluteCartesian() const;
0164
0165 bool hasAbsoluteEuclidean() const;
0166
0167 bool hasChi2Bound() const;
0168
0169
0170 ToleranceMode toleranceMode() const;
0171
0172
0173 AbsoluteBoundParams asAbsoluteBound(bool isCartesian = false) const;
0174
0175 const AbsoluteCartesianParams& asAbsoluteCartesian() const;
0176
0177 const AbsoluteEuclideanParams& asAbsoluteEuclidean() const;
0178
0179 const Chi2BoundParams& asChi2Bound() const;
0180
0181
0182 std::optional<AbsoluteBoundParams> asAbsoluteBoundOpt(
0183 bool isCartesian = false) const;
0184
0185
0186 bool isTolerated(const Vector2& distance,
0187 const std::optional<SquareMatrix2>& jacobianOpt) const;
0188
0189
0190 bool hasMetric(bool hasJacobian) const;
0191
0192
0193 SquareMatrix2 getMetric(const std::optional<SquareMatrix2>& jacobian) const;
0194
0195 private:
0196 Variant m_variant;
0197
0198
0199 template <typename T>
0200 bool holdsVariant() const {
0201 return std::holds_alternative<T>(m_variant);
0202 }
0203
0204
0205 template <typename T>
0206 const T& getVariant() const {
0207 return std::get<T>(m_variant);
0208 }
0209
0210 template <typename T>
0211 const T* getVariantPtr() const {
0212 return holdsVariant<T>() ? &getVariant<T>() : nullptr;
0213 }
0214 };
0215
0216 static_assert(std::is_trivially_copyable_v<BoundaryTolerance>);
0217 static_assert(std::is_trivially_move_constructible_v<BoundaryTolerance>);
0218
0219 }