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