File indexing completed on 2025-01-18 09:10:47
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/TrackParametrization.hpp"
0012
0013 #include <algorithm>
0014 #include <cmath>
0015 #include <cstddef>
0016 #include <numbers>
0017
0018 namespace Acts::detail {
0019
0020
0021 struct UnrestrictedParameterTraits {
0022
0023 static constexpr bool may_modify_value = false;
0024
0025
0026 template <typename value_t>
0027 static constexpr const value_t& getValue(const value_t& value) {
0028 return value;
0029 }
0030
0031 template <typename value_t>
0032 static constexpr value_t getDifference(const value_t& lhs,
0033 const value_t& rhs) {
0034 return lhs - rhs;
0035 }
0036 };
0037
0038
0039
0040
0041
0042
0043
0044 template <typename limits_t>
0045 struct RestrictedParameterTraits {
0046
0047 static constexpr bool may_modify_value = true;
0048
0049 static constexpr double min = limits_t::lowest();
0050
0051 static constexpr double max = limits_t::max();
0052
0053
0054 template <typename value_t>
0055 static constexpr value_t getValue(const value_t& value) {
0056 return std::clamp(value, static_cast<value_t>(min),
0057 static_cast<value_t>(max));
0058 }
0059
0060 template <typename value_t>
0061 static constexpr value_t getDifference(const value_t& lhs,
0062 const value_t& rhs) {
0063 return getValue(lhs) - getValue(rhs);
0064 }
0065 };
0066
0067
0068
0069
0070
0071
0072 template <typename limits_t>
0073 struct CyclicParameterTraits {
0074
0075 static constexpr bool may_modify_value = true;
0076
0077 static constexpr double min = limits_t::lowest();
0078
0079 static constexpr double max = limits_t::max();
0080
0081
0082 template <typename value_t>
0083 static constexpr value_t getValue(const value_t& value) {
0084 if ((min <= value) && (value < max)) {
0085 return value;
0086 } else {
0087 return value - (max - min) * std::floor((value - min) / (max - min));
0088 }
0089 }
0090
0091 template <typename value_t>
0092 static constexpr value_t getDifference(const value_t& lhs,
0093 const value_t& rhs) {
0094 constexpr value_t range = (max - min);
0095 value_t delta = getValue(lhs) - getValue(rhs);
0096 if ((2 * delta) < -range) {
0097 return delta + range;
0098 } else if (range < (2 * delta)) {
0099 return delta - range;
0100 } else {
0101 return delta;
0102 }
0103 }
0104 };
0105
0106
0107
0108
0109 struct PhiBoundParameterLimits {
0110 static constexpr double lowest() { return -std::numbers::pi; }
0111 static constexpr double max() { return std::numbers::pi; }
0112 };
0113 struct ThetaBoundParameterLimits {
0114 static constexpr double lowest() { return 0; }
0115 static constexpr double max() { return std::numbers::pi; }
0116 };
0117
0118
0119
0120
0121
0122 template <typename index_t, index_t kIndex>
0123 struct ParameterTraitsImpl;
0124 template <>
0125 struct ParameterTraitsImpl<BoundIndices, BoundIndices::eBoundPhi> {
0126 using Type = CyclicParameterTraits<PhiBoundParameterLimits>;
0127 };
0128 template <>
0129 struct ParameterTraitsImpl<BoundIndices, BoundIndices::eBoundTheta> {
0130 using Type = RestrictedParameterTraits<ThetaBoundParameterLimits>;
0131 };
0132 template <BoundIndices kIndex>
0133 struct ParameterTraitsImpl<BoundIndices, kIndex> {
0134
0135 using Type = UnrestrictedParameterTraits;
0136 };
0137 template <FreeIndices kIndex>
0138 struct ParameterTraitsImpl<FreeIndices, kIndex> {
0139
0140 using Type = UnrestrictedParameterTraits;
0141 };
0142
0143
0144
0145
0146
0147
0148
0149
0150 template <typename index_t, index_t kIndex>
0151 using ParameterTraits = typename ParameterTraitsImpl<index_t, kIndex>::Type;
0152
0153
0154
0155
0156
0157
0158 template <typename indices_t>
0159 struct ParametersTraitsImpl;
0160 template <>
0161 struct ParametersTraitsImpl<BoundIndices> {
0162 static constexpr std::size_t kSize =
0163 static_cast<std::size_t>(BoundIndices::eBoundSize);
0164 };
0165 template <>
0166 struct ParametersTraitsImpl<FreeIndices> {
0167 static constexpr std::size_t kSize =
0168 static_cast<std::size_t>(FreeIndices::eFreeSize);
0169 };
0170
0171
0172 template <typename indices_t>
0173 constexpr std::size_t kParametersSize = ParametersTraitsImpl<indices_t>::kSize;
0174
0175 }