Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GenericParticleHypothesis.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file GenericParticleHypothesis.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2023 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
16 
17 #include <iosfwd>
18 #include <utility>
19 
20 namespace Acts {
21 
26 template <ACTS_CONCEPT(ChargeConcept) charge_t>
28  public:
29  using ChargeType = charge_t;
30 
37  constexpr GenericParticleHypothesis(PdgParticle absPdg, float mass,
38  ChargeType chargeType)
39  : m_absPdg{absPdg}, m_mass{mass}, m_chargeType{std::move(chargeType)} {
40  assert(absPdg == makeAbsolutePdgParticle(absPdg) &&
41  "pdg is expected to be absolute");
42  }
43 
50  : m_absPdg{absPdg},
51  m_mass{findMass(absPdg).value()},
52  m_chargeType{std::abs(findCharge(absPdg).value())} {
53  assert(absPdg == makeAbsolutePdgParticle(absPdg) &&
54  "pdg is expected to be absolute");
55  }
56 
60  template <typename other_charge_t>
61  constexpr GenericParticleHypothesis(
62  const GenericParticleHypothesis<other_charge_t>& other)
63  : m_absPdg{other.absolutePdg()},
64  m_mass{other.mass()},
65  m_chargeType{other.chargeType()} {}
66 
68  constexpr PdgParticle absolutePdg() const noexcept { return m_absPdg; }
69 
71  constexpr float mass() const noexcept { return m_mass; }
72 
74  constexpr float absoluteCharge() const noexcept {
75  return m_chargeType.absQ();
76  }
77 
82  template <typename T>
83  constexpr auto extractCharge(T qOverP) const noexcept {
84  return m_chargeType.extractCharge(qOverP);
85  }
86 
91  template <typename T>
92  constexpr auto extractMomentum(T qOverP) const noexcept {
93  return m_chargeType.extractMomentum(qOverP);
94  }
95 
101  template <typename P, typename Q>
102  constexpr auto qOverP(P momentum, Q signedQ) const noexcept {
103  return m_chargeType.qOverP(momentum, signedQ);
104  }
105 
107  constexpr const ChargeType& chargeType() const noexcept {
108  return m_chargeType;
109  }
110 
111  std::ostream& toStream(std::ostream& os) const {
112  os << "ParticleHypothesis{absPdg=";
113  if (auto shortString = pdgToShortAbsString(absolutePdg())) {
114  os << *shortString;
115  } else {
116  os << absolutePdg();
117  }
118  os << ", mass=" << mass() << ", absCharge=" << absoluteCharge() << "}";
119  return os;
120  }
121 
122  friend std::ostream& operator<<(
123  std::ostream& os, const GenericParticleHypothesis& particleHypothesis) {
124  return particleHypothesis.toStream(os);
125  }
126 
127  private:
128  PdgParticle m_absPdg;
129  float m_mass;
131 
134  return (lhs.m_absPdg == rhs.m_absPdg) && (lhs.m_mass == rhs.m_mass) &&
135  (lhs.m_chargeType == rhs.m_chargeType);
136  }
139  return (lhs.m_absPdg != rhs.m_absPdg) || (lhs.m_mass != rhs.m_mass) ||
140  (lhs.m_chargeType != rhs.m_chargeType);
141  }
142 };
143 
144 } // namespace Acts