Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-23 07:34:14

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
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 // TODO In principle the factory methods could provide a reference to a static
0022 // instance which would avoid copying the particle hypothesis and potentially
0023 // save some memory. But constexpr+static seems to require C++2b extension.
0024 
0025 /// @ingroup eventdata
0026 /// @defgroup eventdata-particlehypothesis Particle hypothesis for track reconstruction
0027 /// @{
0028 
0029 /// @brief Particle hypothesis used in reconstruction
0030 ///
0031 /// The reconstruction hypothesis consists of absolute PDG code, mass and
0032 /// absolute charge.
0033 class ParticleHypothesis final {
0034  public:
0035   /// Create a muon particle hypothesis
0036   /// @return Muon particle hypothesis with any charge type
0037   static ParticleHypothesis muon() {
0038     static const ParticleHypothesis cache(PdgParticle::eMuon);
0039     return cache;
0040   }
0041   /// Create a charged pion particle hypothesis
0042   /// @return Charged pion particle hypothesis with any charge type
0043   static ParticleHypothesis pion() {
0044     static const ParticleHypothesis cache(PdgParticle::ePionPlus);
0045     return cache;
0046   }
0047   /// Create an electron particle hypothesis
0048   /// @return Electron particle hypothesis with any charge type
0049   static ParticleHypothesis electron() {
0050     static const ParticleHypothesis cache(PdgParticle::eElectron);
0051     return cache;
0052   }
0053   /// Create a charged kaon particle hypothesis
0054   /// @return Charged kaon particle hypothesis with any charge type
0055   static ParticleHypothesis kaon() {
0056     static const ParticleHypothesis cache(PdgParticle::eKaonPlus);
0057     return cache;
0058   }
0059   /// Create a proton particle hypothesis
0060   /// @return Proton particle hypothesis with any charge type
0061   static ParticleHypothesis proton() {
0062     static const ParticleHypothesis cache(PdgParticle::eProton);
0063     return cache;
0064   }
0065 
0066   /// Create a photon particle hypothesis
0067   /// @return Photon particle hypothesis with any charge type
0068   static ParticleHypothesis photon() {
0069     static const ParticleHypothesis cache(PdgParticle::eGamma);
0070     return cache;
0071   }
0072   /// Create a neutral pion particle hypothesis
0073   /// @return Neutral pion particle hypothesis with any charge type
0074   static ParticleHypothesis pion0() {
0075     static const ParticleHypothesis cache(PdgParticle::ePionZero);
0076     return cache;
0077   }
0078 
0079   /// Create a pion-like particle hypothesis with custom charge
0080   /// @param absoluteCharge The absolute charge value
0081   /// @return Pion-like particle hypothesis with any charge type
0082   static ParticleHypothesis pionLike(float absoluteCharge) {
0083     return ParticleHypothesis(pion().absolutePdg(), pion().mass(),
0084                               ChargeHypothesis{absoluteCharge});
0085   }
0086 
0087   /// Create a neutral geantino particle hypothesis (massless neutral particle)
0088   /// @return Neutral geantino particle hypothesis with any charge type
0089   static ParticleHypothesis geantino() {
0090     ParticleHypothesis cache(PdgParticle::eInvalid, 0, ChargeHypothesis{0});
0091     return cache;
0092   }
0093   /// Create a charged geantino particle hypothesis with unit charge
0094   /// @return Charged geantino particle hypothesis with any charge type
0095   static ParticleHypothesis chargedGeantino() {
0096     static const auto cache = chargedGeantino(Acts::UnitConstants::e);
0097     return cache;
0098   }
0099   /// Create a charged geantino particle hypothesis with custom charge
0100   /// @param absoluteCharge The absolute charge value
0101   /// @return Charged geantino particle hypothesis with any charge type
0102   static ParticleHypothesis chargedGeantino(float absoluteCharge) {
0103     return ParticleHypothesis(PdgParticle::eInvalid, 0,
0104                               ChargeHypothesis{absoluteCharge});
0105   }
0106 
0107   /// Creates a particle hypothesis using absolute PDG, mass and the charge
0108   /// type.
0109   ///
0110   /// @param absPdg the absolute PDG
0111   /// @param mass the particle mass
0112   /// @param absCharge the absolute charge
0113   constexpr ParticleHypothesis(PdgParticle absPdg, float mass, float absCharge)
0114       : m_absPdg{absPdg}, m_mass{mass}, m_charge{absCharge} {
0115     assert(absPdg == makeAbsolutePdgParticle(absPdg) &&
0116            "pdg is expected to be absolute");
0117   }
0118 
0119   /// Creates a particle hypothesis using absolute PDG, mass and the charge
0120   /// type.
0121   ///
0122   /// @param absPdg the absolute PDG
0123   /// @param mass the particle mass
0124   /// @param charge the charge type
0125   constexpr ParticleHypothesis(PdgParticle absPdg, float mass,
0126                                ChargeHypothesis charge)
0127       : m_absPdg{absPdg}, m_mass{mass}, m_charge{charge} {
0128     assert(absPdg == makeAbsolutePdgParticle(absPdg) &&
0129            "pdg is expected to be absolute");
0130   }
0131 
0132   /// Creates a particle hypothesis using the absolute PDG.
0133   /// The mass and charge is looked up using @ref findMass and @ref findCharge.
0134   /// If the lookup fails an exception is thrown.
0135   ///
0136   /// @param absPdg the absolute PDG
0137   explicit ParticleHypothesis(PdgParticle absPdg)
0138       : m_absPdg{absPdg},
0139         m_mass{findMass(absPdg).value()},
0140         m_charge{std::abs(findCharge(absPdg).value())} {
0141     assert(absPdg == makeAbsolutePdgParticle(absPdg) &&
0142            "pdg is expected to be absolute");
0143   }
0144 
0145   /// Get the hypothesized absolute PDG.
0146   /// @return The absolute PDG particle identifier
0147   constexpr PdgParticle absolutePdg() const noexcept { return m_absPdg; }
0148 
0149   /// Get the hypothesized mass.
0150   /// @return The particle mass in natural units
0151   constexpr float mass() const noexcept { return m_mass; }
0152 
0153   /// Get the hypothesized absolute charge.
0154   /// @return The absolute charge magnitude
0155   float absoluteCharge() const noexcept { return m_charge.absoluteCharge(); }
0156 
0157   /// Extracts the signed charge from the `q over p` track parameter using the
0158   /// charge hypothesis.
0159   ///
0160   /// @param qOverP the `q over p` track parameter.
0161   /// @return The extracted signed charge
0162   constexpr float extractCharge(double qOverP) const noexcept {
0163     return m_charge.extractCharge(qOverP);
0164   }
0165 
0166   /// Extracts the particle momentum from the `q over p` track parameter using
0167   /// the charge hypothesis.
0168   ///
0169   /// @param qOverP the `q over p` track parameter.
0170   /// @return The extracted absolute momentum
0171   constexpr double extractMomentum(double qOverP) const noexcept {
0172     return m_charge.extractMomentum(qOverP);
0173   }
0174 
0175   /// Calculate the `q over p` track parameter with the given absolute momentum
0176   /// and charge.
0177   ///
0178   /// @param momentum the absolute momentum.
0179   /// @param signedQ the signed charge.
0180   /// @return The calculated charge over momentum ratio
0181   constexpr double qOverP(double momentum, float signedQ) const noexcept {
0182     return m_charge.qOverP(momentum, signedQ);
0183   }
0184 
0185   /// Get the hypothesized charge.
0186   /// @return Reference to the charge type object
0187   constexpr const ChargeHypothesis& charge() const noexcept { return m_charge; }
0188 
0189   /// Output stream representation of the particle hypothesis
0190   /// @param os Output stream to write to
0191   /// @return Modified output stream for chaining\n
0192   std::ostream& toStream(std::ostream& os) const {
0193     os << "ParticleHypothesis{absPdg=";
0194     if (auto shortString = pdgToShortAbsString(absolutePdg())) {
0195       os << *shortString;
0196     } else {
0197       os << absolutePdg();
0198     }
0199     os << ", mass=" << mass() << ", absCharge=" << absoluteCharge() << "}";
0200     return os;
0201   }
0202 
0203   /// Output stream operator for particle hypothesis
0204   /// @param os Output stream to write to
0205   /// @param particleHypothesis The particle hypothesis to output
0206   /// @return Reference to output stream for chaining
0207   friend std::ostream& operator<<(
0208       std::ostream& os, const ParticleHypothesis& particleHypothesis) {
0209     return particleHypothesis.toStream(os);
0210   }
0211 
0212  private:
0213   PdgParticle m_absPdg{PdgParticle::eInvalid};
0214   float m_mass{0};
0215   ChargeHypothesis m_charge;
0216 
0217   friend bool operator==(const ParticleHypothesis& lhs,
0218                          const ParticleHypothesis& rhs) = default;
0219 };
0220 
0221 /// @}
0222 
0223 }  // namespace Acts