Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:01:27

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2023 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 http://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/Utilities/Concepts.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 <ACTS_CONCEPT(ChargeConcept) charge_t>
0026 class GenericParticleHypothesis {
0027  public:
0028   using ChargeType = charge_t;
0029 
0030   /// Creates a particle hypothesis using absolute PDG, mass and the charge
0031   /// type.
0032   ///
0033   /// @param absPdg the absolute PDG
0034   /// @param mass the particle mass
0035   /// @param chargeType the type of charge
0036   constexpr GenericParticleHypothesis(PdgParticle absPdg, float mass,
0037                                       ChargeType chargeType)
0038       : m_absPdg{absPdg}, m_mass{mass}, m_chargeType{std::move(chargeType)} {
0039     assert(absPdg == makeAbsolutePdgParticle(absPdg) &&
0040            "pdg is expected to be absolute");
0041   }
0042 
0043   /// Creates a particle hypothesis using the absolute PDG.
0044   /// The mass and charge is looked up using @ref findMass and @ref findCharge.
0045   /// If the lookup fails an exception is thrown.
0046   ///
0047   /// @param absPdg the absolute PDG
0048   GenericParticleHypothesis(PdgParticle absPdg)
0049       : m_absPdg{absPdg},
0050         m_mass{findMass(absPdg).value()},
0051         m_chargeType{std::abs(findCharge(absPdg).value())} {
0052     assert(absPdg == makeAbsolutePdgParticle(absPdg) &&
0053            "pdg is expected to be absolute");
0054   }
0055 
0056   /// Copy from another charge hypothesis.
0057   ///
0058   /// @note This enables implicit conversion.
0059   template <typename other_charge_t>
0060   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   constexpr PdgParticle absolutePdg() const noexcept { return m_absPdg; }
0068 
0069   /// Get the hypothesized mass.
0070   constexpr float mass() const noexcept { return m_mass; }
0071 
0072   /// Get the hypothesized absolute charge.
0073   constexpr float absoluteCharge() const noexcept {
0074     return m_chargeType.absQ();
0075   }
0076 
0077   /// Extracts the signed charge from the `q over p` track parameter using the
0078   /// charge hypothesis.
0079   ///
0080   /// @param qOverP the `q over p` track parameter.
0081   template <typename T>
0082   constexpr auto extractCharge(T qOverP) const noexcept {
0083     return m_chargeType.extractCharge(qOverP);
0084   }
0085 
0086   /// Extracts the particle momentum from the `q over p` track parameter using
0087   /// the charge hypothesis.
0088   ///
0089   /// @param qOverP the `q over p` track parameter.
0090   template <typename T>
0091   constexpr auto extractMomentum(T qOverP) const noexcept {
0092     return m_chargeType.extractMomentum(qOverP);
0093   }
0094 
0095   /// Calculate the `q over p` track parameter with the given absolute momentum
0096   /// and charge.
0097   ///
0098   /// @param momentum the absolute momentum.
0099   /// @param signedQ the signed charge.
0100   template <typename P, typename Q>
0101   constexpr auto qOverP(P momentum, Q signedQ) const noexcept {
0102     return m_chargeType.qOverP(momentum, signedQ);
0103   }
0104 
0105   /// Get the hypothesized charge type.
0106   constexpr const ChargeType& chargeType() const noexcept {
0107     return m_chargeType;
0108   }
0109 
0110   std::ostream& toStream(std::ostream& os) const {
0111     os << "ParticleHypothesis{absPdg=";
0112     if (auto shortString = pdgToShortAbsString(absolutePdg())) {
0113       os << *shortString;
0114     } else {
0115       os << absolutePdg();
0116     }
0117     os << ", mass=" << mass() << ", absCharge=" << absoluteCharge() << "}";
0118     return os;
0119   }
0120 
0121   friend std::ostream& operator<<(
0122       std::ostream& os, const GenericParticleHypothesis& particleHypothesis) {
0123     return particleHypothesis.toStream(os);
0124   }
0125 
0126  private:
0127   PdgParticle m_absPdg;
0128   float m_mass;
0129   ChargeType m_chargeType;
0130 
0131   friend bool operator==(const GenericParticleHypothesis<ChargeType>& lhs,
0132                          const GenericParticleHypothesis<ChargeType>& rhs) {
0133     return (lhs.m_absPdg == rhs.m_absPdg) && (lhs.m_mass == rhs.m_mass) &&
0134            (lhs.m_chargeType == rhs.m_chargeType);
0135   }
0136   friend bool operator!=(const GenericParticleHypothesis<ChargeType>& lhs,
0137                          const GenericParticleHypothesis<ChargeType>& rhs) {
0138     return (lhs.m_absPdg != rhs.m_absPdg) || (lhs.m_mass != rhs.m_mass) ||
0139            (lhs.m_chargeType != rhs.m_chargeType);
0140   }
0141 };
0142 
0143 }  // namespace Acts