Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:22:16

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/EventData/ChargeConcept.hpp"
0014 
0015 #include <cassert>
0016 #include <ostream>
0017 #include <utility>
0018 
0019 namespace Acts {
0020 
0021 /// @brief Particle hypothesis used in reconstruction
0022 ///
0023 /// The reconstruction hypothesis consists of absolute PDG code, mass and
0024 /// absolute charge.
0025 template <ChargeConcept charge_t>
0026 class GenericParticleHypothesis {
0027  public:
0028   /// Type alias for charge type used in particle hypothesis
0029   using ChargeType = charge_t;
0030 
0031   /// Creates a particle hypothesis using absolute PDG, mass and the charge
0032   /// type.
0033   ///
0034   /// @param absPdg the absolute PDG
0035   /// @param mass the particle mass
0036   /// @param chargeType the type of charge
0037   constexpr GenericParticleHypothesis(PdgParticle absPdg, float mass,
0038                                       ChargeType chargeType)
0039       : m_absPdg{absPdg}, m_mass{mass}, m_chargeType{std::move(chargeType)} {
0040     assert(absPdg == makeAbsolutePdgParticle(absPdg) &&
0041            "pdg is expected to be absolute");
0042   }
0043 
0044   /// Creates a particle hypothesis using the absolute PDG.
0045   /// The mass and charge is looked up using @ref findMass and @ref findCharge.
0046   /// If the lookup fails an exception is thrown.
0047   ///
0048   /// @param absPdg the absolute PDG
0049   explicit GenericParticleHypothesis(PdgParticle absPdg)
0050       : m_absPdg{absPdg},
0051         m_mass{findMass(absPdg).value()},
0052         m_chargeType{std::abs(findCharge(absPdg).value())} {
0053     assert(absPdg == makeAbsolutePdgParticle(absPdg) &&
0054            "pdg is expected to be absolute");
0055   }
0056 
0057   /// Copy from another charge hypothesis.
0058   /// @param other The other particle hypothesis to copy from
0059   template <typename other_charge_t>
0060   explicit constexpr GenericParticleHypothesis(
0061       const GenericParticleHypothesis<other_charge_t>& other)
0062       : m_absPdg{other.absolutePdg()},
0063         m_mass{other.mass()},
0064         m_chargeType{other.chargeType()} {}
0065 
0066   /// Get the hypothesized absolute PDG.
0067   /// @return The absolute PDG particle identifier
0068   constexpr PdgParticle absolutePdg() const noexcept { return m_absPdg; }
0069 
0070   /// Get the hypothesized mass.
0071   /// @return The particle mass in natural units
0072   constexpr float mass() const noexcept { return m_mass; }
0073 
0074   /// Get the hypothesized absolute charge.
0075   /// @return The absolute charge magnitude
0076   constexpr float absoluteCharge() const noexcept {
0077     return m_chargeType.absQ();
0078   }
0079 
0080   /// Extracts the signed charge from the `q over p` track parameter using the
0081   /// charge hypothesis.
0082   ///
0083   /// @param qOverP the `q over p` track parameter.
0084   /// @return The extracted signed charge
0085   template <typename T>
0086   constexpr auto extractCharge(T qOverP) const noexcept {
0087     return m_chargeType.extractCharge(qOverP);
0088   }
0089 
0090   /// Extracts the particle momentum from the `q over p` track parameter using
0091   /// the charge hypothesis.
0092   ///
0093   /// @param qOverP the `q over p` track parameter.
0094   /// @return The extracted absolute momentum
0095   template <typename T>
0096   constexpr auto extractMomentum(T qOverP) const noexcept {
0097     return m_chargeType.extractMomentum(qOverP);
0098   }
0099 
0100   /// Calculate the `q over p` track parameter with the given absolute momentum
0101   /// and charge.
0102   ///
0103   /// @param momentum the absolute momentum.
0104   /// @param signedQ the signed charge.
0105   /// @return The calculated charge over momentum ratio
0106   template <typename P, typename Q>
0107   constexpr auto qOverP(P momentum, Q signedQ) const noexcept {
0108     return m_chargeType.qOverP(momentum, signedQ);
0109   }
0110 
0111   /// Get the hypothesized charge type.
0112   /// @return Reference to the charge type object
0113   constexpr const ChargeType& chargeType() const noexcept {
0114     return m_chargeType;
0115   }
0116 
0117   /// Output stream representation of the particle hypothesis
0118   /// @param os Output stream to write to
0119   /// @return Modified output stream for chaining\n
0120   std::ostream& toStream(std::ostream& os) const {
0121     os << "ParticleHypothesis{absPdg=";
0122     if (auto shortString = pdgToShortAbsString(absolutePdg())) {
0123       os << *shortString;
0124     } else {
0125       os << absolutePdg();
0126     }
0127     os << ", mass=" << mass() << ", absCharge=" << absoluteCharge() << "}";
0128     return os;
0129   }
0130 
0131   /// Output stream operator for particle hypothesis
0132   /// @param os Output stream to write to
0133   /// @param particleHypothesis The particle hypothesis to output
0134   /// @return Reference to output stream for chaining
0135   friend std::ostream& operator<<(
0136       std::ostream& os, const GenericParticleHypothesis& particleHypothesis) {
0137     return particleHypothesis.toStream(os);
0138   }
0139 
0140  private:
0141   PdgParticle m_absPdg;
0142   float m_mass;
0143   ChargeType m_chargeType;
0144 
0145   friend bool operator==(const GenericParticleHypothesis<ChargeType>& lhs,
0146                          const GenericParticleHypothesis<ChargeType>& rhs) {
0147     return (lhs.m_absPdg == rhs.m_absPdg) && (lhs.m_mass == rhs.m_mass) &&
0148            (lhs.m_chargeType == rhs.m_chargeType);
0149   }
0150 };
0151 
0152 }  // namespace Acts