Warning, file /acts/Core/include/Acts/EventData/ParticleHypothesis.hpp was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/ParticleData.hpp"
0012 #include "Acts/Definitions/PdgParticle.hpp"
0013 #include "Acts/Definitions/Units.hpp"
0014 #include "Acts/EventData/ChargeHypothesis.hpp"
0015
0016 #include <cassert>
0017 #include <iostream>
0018
0019 namespace Acts {
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 class ParticleHypothesis final {
0034 public:
0035
0036
0037 [[nodiscard]] static ParticleHypothesis muon() {
0038 static const ParticleHypothesis cache(PdgParticle::eMuon);
0039 return cache;
0040 }
0041
0042
0043 [[nodiscard]] static ParticleHypothesis pion() {
0044 static const ParticleHypothesis cache(PdgParticle::ePionPlus);
0045 return cache;
0046 }
0047
0048
0049 [[nodiscard]] static ParticleHypothesis electron() {
0050 static const ParticleHypothesis cache(PdgParticle::eElectron);
0051 return cache;
0052 }
0053
0054
0055 [[nodiscard]] static ParticleHypothesis kaon() {
0056 static const ParticleHypothesis cache(PdgParticle::eKaonPlus);
0057 return cache;
0058 }
0059
0060
0061 [[nodiscard]] static ParticleHypothesis proton() {
0062 static const ParticleHypothesis cache(PdgParticle::eProton);
0063 return cache;
0064 }
0065
0066
0067
0068 [[nodiscard]] static ParticleHypothesis photon() {
0069 static const ParticleHypothesis cache(PdgParticle::eGamma);
0070 return cache;
0071 }
0072
0073
0074 [[nodiscard]] static ParticleHypothesis pion0() {
0075 static const ParticleHypothesis cache(PdgParticle::ePionZero);
0076 return cache;
0077 }
0078
0079
0080
0081
0082 [[nodiscard]] static ParticleHypothesis pionLike(float absoluteCharge) {
0083 return pion().withAlteredAbsoluteCharge(absoluteCharge);
0084 }
0085
0086
0087
0088 [[nodiscard]] static ParticleHypothesis geantino() {
0089 static const ParticleHypothesis cache(PdgParticle::eInvalid, 0,
0090 ChargeHypothesis{0});
0091 return cache;
0092 }
0093
0094
0095 [[nodiscard]] static ParticleHypothesis chargedGeantino() {
0096 return geantino().withAlteredAbsoluteCharge(1 * UnitConstants::e);
0097 }
0098
0099
0100
0101 [[nodiscard]] static ParticleHypothesis chargedGeantino(
0102 float absoluteCharge) {
0103 return geantino().withAlteredAbsoluteCharge(absoluteCharge);
0104 }
0105
0106
0107
0108
0109
0110
0111
0112
0113 constexpr ParticleHypothesis(PdgParticle absPdg, float mass, float absCharge,
0114 std::optional<double> momentum = std::nullopt)
0115 : m_absPdg{absPdg},
0116 m_mass{mass},
0117 m_charge{absCharge},
0118 m_momentum{momentum} {
0119 assert(absPdg == makeAbsolutePdgParticle(absPdg) &&
0120 "pdg is expected to be absolute");
0121 }
0122
0123
0124
0125
0126
0127
0128
0129
0130 constexpr ParticleHypothesis(PdgParticle absPdg, float mass,
0131 ChargeHypothesis charge,
0132 std::optional<double> momentum = std::nullopt)
0133 : m_absPdg{absPdg}, m_mass{mass}, m_charge{charge}, m_momentum{momentum} {
0134 assert(absPdg == makeAbsolutePdgParticle(absPdg) &&
0135 "pdg is expected to be absolute");
0136 }
0137
0138
0139
0140
0141
0142
0143
0144 explicit ParticleHypothesis(PdgParticle absPdg,
0145 std::optional<double> momentum = std::nullopt)
0146 : m_absPdg{absPdg},
0147 m_mass{findMass(absPdg).value()},
0148 m_charge{std::abs(findCharge(absPdg).value())},
0149 m_momentum{momentum} {
0150 assert(absPdg == makeAbsolutePdgParticle(absPdg) &&
0151 "pdg is expected to be absolute");
0152 }
0153
0154
0155
0156
0157
0158 [[nodiscard]] ParticleHypothesis withAlteredPdg(PdgParticle absPdg) const {
0159 return ParticleHypothesis(absPdg, mass(), absoluteCharge(), m_momentum);
0160 }
0161
0162
0163
0164
0165
0166 [[nodiscard]] ParticleHypothesis withAlteredMass(float mass) const {
0167 return ParticleHypothesis(absolutePdg(), mass, absoluteCharge(),
0168 m_momentum);
0169 }
0170
0171
0172
0173
0174
0175 [[nodiscard]] ParticleHypothesis withAlteredAbsoluteCharge(
0176 float absoluteCharge) const {
0177 return ParticleHypothesis(absolutePdg(), mass(), absoluteCharge,
0178 m_momentum);
0179 }
0180
0181
0182
0183
0184
0185 [[nodiscard]] ParticleHypothesis withMomentumHypothesis(
0186 double momentum) const {
0187 return ParticleHypothesis(absolutePdg(), mass(), absoluteCharge(),
0188 momentum);
0189 }
0190
0191
0192
0193
0194
0195 [[nodiscard]] ParticleHypothesis withMomentumHypothesis(
0196 std::optional<double> momentum) const {
0197 return ParticleHypothesis(absolutePdg(), mass(), absoluteCharge(),
0198 momentum);
0199 }
0200
0201
0202
0203
0204 [[nodiscard]] ParticleHypothesis withoutMomentumHypothesis() const {
0205 return ParticleHypothesis(absolutePdg(), mass(), absoluteCharge(),
0206 std::nullopt);
0207 }
0208
0209
0210
0211 [[nodiscard]] constexpr PdgParticle absolutePdg() const noexcept {
0212 return m_absPdg;
0213 }
0214
0215
0216
0217 [[nodiscard]] constexpr float mass() const noexcept { return m_mass; }
0218
0219
0220
0221 [[nodiscard]] float absoluteCharge() const noexcept {
0222 return m_charge.absoluteCharge();
0223 }
0224
0225
0226
0227 [[nodiscard]] bool hasMomentumHypothesis() const noexcept {
0228 return m_momentum.has_value();
0229 }
0230
0231
0232
0233 [[nodiscard]] double momentumHypothesis() const { return m_momentum.value(); }
0234
0235
0236
0237
0238
0239
0240 [[nodiscard]] constexpr float extractCharge(double qOverP) const noexcept {
0241 return m_charge.extractCharge(qOverP);
0242 }
0243
0244
0245
0246
0247
0248
0249 [[nodiscard]] constexpr double extractMomentum(double qOverP) const noexcept {
0250 if (m_momentum.has_value()) {
0251 return *m_momentum;
0252 }
0253 return m_charge.extractMomentum(qOverP);
0254 }
0255
0256
0257
0258
0259
0260
0261
0262 [[nodiscard]] constexpr double qOverP(double momentum,
0263 float signedQ) const noexcept {
0264 return m_charge.qOverP(momentum, signedQ);
0265 }
0266
0267
0268
0269 [[nodiscard]] constexpr const ChargeHypothesis& charge() const noexcept {
0270 return m_charge;
0271 }
0272
0273
0274
0275
0276 std::ostream& toStream(std::ostream& os) const {
0277 os << "ParticleHypothesis{absPdg=";
0278 if (auto shortString = pdgToShortAbsString(absolutePdg())) {
0279 os << *shortString;
0280 } else {
0281 os << absolutePdg();
0282 }
0283 os << ", mass=" << mass() << ", absCharge=" << absoluteCharge();
0284 if (hasMomentumHypothesis()) {
0285 os << ", momentum=" << momentumHypothesis();
0286 }
0287 os << "}";
0288 return os;
0289 }
0290
0291
0292
0293
0294
0295 friend std::ostream& operator<<(
0296 std::ostream& os, const ParticleHypothesis& particleHypothesis) {
0297 return particleHypothesis.toStream(os);
0298 }
0299
0300 private:
0301 PdgParticle m_absPdg{PdgParticle::eInvalid};
0302 float m_mass{0};
0303 ChargeHypothesis m_charge;
0304 std::optional<double> m_momentum;
0305
0306 friend bool operator==(const ParticleHypothesis& lhs,
0307 const ParticleHypothesis& rhs) = default;
0308 };
0309
0310
0311
0312 }