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/Algebra.hpp"
0012 #include "Acts/Definitions/Units.hpp"
0013 #include "Acts/EventData/ChargeConcept.hpp"
0014
0015 #include <cassert>
0016 #include <cmath>
0017
0018 namespace Acts {
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 struct Neutral {
0056 constexpr Neutral() = default;
0057
0058
0059
0060
0061
0062
0063 constexpr Neutral(float absQ) noexcept {
0064 assert((absQ == 0) && "Input charge must be zero");
0065 (void)absQ;
0066 }
0067
0068 constexpr float absQ() const noexcept { return 0; }
0069
0070 constexpr float extractCharge(double ) const noexcept {
0071 return 0.0f;
0072 }
0073
0074 constexpr double extractMomentum(double qOverP) const noexcept {
0075 assert(qOverP >= 0 && "qOverP cannot be negative");
0076 return 1.0f / qOverP;
0077 }
0078
0079 constexpr double qOverP(double momentum, float signedQ) const noexcept {
0080 assert((signedQ != 0) && "charge must be 0");
0081 (void)signedQ;
0082 return 1.0f / momentum;
0083 }
0084
0085
0086
0087
0088
0089 friend constexpr bool operator==(Neutral , Neutral ) noexcept {
0090 return true;
0091 }
0092 };
0093
0094 static_assert(ChargeConcept<Neutral>, "Neutral does not fulfill ChargeConcept");
0095
0096
0097 struct SinglyCharged {
0098 constexpr SinglyCharged() = default;
0099
0100
0101
0102
0103
0104
0105 constexpr SinglyCharged(float absQ) noexcept {
0106 assert((absQ == UnitConstants::e) && "Input charge magnitude must be e");
0107 (void)absQ;
0108 }
0109
0110 constexpr float absQ() const noexcept { return UnitConstants::e; }
0111
0112 constexpr float extractCharge(double qOverP) const noexcept {
0113 return std::copysign(UnitConstants::e, qOverP);
0114 }
0115
0116 constexpr double extractMomentum(double qOverP) const noexcept {
0117 return extractCharge(qOverP) / qOverP;
0118 }
0119
0120 constexpr double qOverP(double momentum, float signedQ) const noexcept {
0121 assert((std::abs(signedQ) == UnitConstants::e) &&
0122 "absolute charge must be e");
0123 return signedQ / momentum;
0124 }
0125
0126
0127
0128
0129
0130 friend constexpr bool operator==(SinglyCharged ,
0131 SinglyCharged ) noexcept {
0132 return true;
0133 }
0134 };
0135
0136 static_assert(ChargeConcept<SinglyCharged>,
0137 "SinglyCharged does not fulfill ChargeConcept");
0138
0139
0140
0141 class NonNeutralCharge {
0142 public:
0143
0144 constexpr NonNeutralCharge(float absQ) noexcept : m_absQ{absQ} {
0145 assert((0 < absQ) && "Input charge magnitude must be positive");
0146 }
0147 constexpr NonNeutralCharge(SinglyCharged ) noexcept
0148 : m_absQ{UnitConstants::e} {}
0149
0150 constexpr float absQ() const noexcept { return m_absQ; }
0151
0152 constexpr float extractCharge(double qOverP) const noexcept {
0153 return std::copysign(m_absQ, qOverP);
0154 }
0155 constexpr double extractMomentum(double qOverP) const noexcept {
0156 return extractCharge(qOverP) / qOverP;
0157 }
0158
0159 constexpr double qOverP(double momentum, float signedQ) const noexcept {
0160 assert(std::abs(signedQ) == m_absQ && "inconsistent charge");
0161 return signedQ / momentum;
0162 }
0163
0164
0165 friend constexpr bool operator==(NonNeutralCharge lhs,
0166 NonNeutralCharge rhs) noexcept {
0167 return lhs.m_absQ == rhs.m_absQ;
0168 }
0169
0170 private:
0171 float m_absQ{};
0172 };
0173
0174 static_assert(ChargeConcept<NonNeutralCharge>,
0175 "NonNeutralCharge does not fulfill ChargeConcept");
0176
0177
0178
0179
0180
0181
0182 class AnyCharge {
0183 public:
0184
0185 constexpr AnyCharge(float absQ) noexcept : m_absQ{absQ} {
0186 assert((0 <= absQ) && "Input charge magnitude must be zero or positive");
0187 }
0188 constexpr AnyCharge(SinglyCharged ) noexcept
0189 : m_absQ{UnitConstants::e} {}
0190 constexpr AnyCharge(Neutral ) noexcept {}
0191
0192 constexpr float absQ() const noexcept { return m_absQ; }
0193
0194 constexpr float extractCharge(double qOverP) const noexcept {
0195 return std::copysign(m_absQ, qOverP);
0196 }
0197 constexpr double extractMomentum(double qOverP) const noexcept {
0198 return (m_absQ != 0.0f) ? extractCharge(qOverP) / qOverP : 1.0f / qOverP;
0199 }
0200
0201 constexpr double qOverP(double momentum, float signedQ) const noexcept {
0202 assert(std::abs(signedQ) == m_absQ && "inconsistent charge");
0203 return (m_absQ != 0.0f) ? signedQ / momentum : 1.0f / momentum;
0204 }
0205
0206
0207 friend constexpr bool operator==(AnyCharge lhs, AnyCharge rhs) noexcept {
0208 return lhs.m_absQ == rhs.m_absQ;
0209 }
0210
0211 private:
0212 float m_absQ{};
0213 };
0214
0215 static_assert(ChargeConcept<AnyCharge>,
0216 "AnyCharge does not fulfill ChargeConcept");
0217
0218
0219
0220 }