File indexing completed on 2025-01-18 09:11:15
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Definitions/ParticleData.hpp"
0010
0011 #include "Acts/Definitions/Units.hpp"
0012
0013 #include <algorithm>
0014 #include <cassert>
0015 #include <cstdint>
0016 #include <iterator>
0017 #include <limits>
0018 #include <optional>
0019 #include <ostream>
0020 #include <type_traits>
0021
0022 #include "ParticleDataTable.hpp"
0023
0024 namespace {
0025
0026
0027
0028
0029 static inline std::optional<std::size_t> findIndexByPdg(std::int32_t pdg) {
0030 auto beg = std::cbegin(kParticlesPdgNumber);
0031 auto end = std::cend(kParticlesPdgNumber);
0032
0033 auto pos = std::find(beg, end, pdg);
0034 if (pos == end) {
0035 return std::nullopt;
0036 }
0037 return std::make_optional(std::distance(beg, pos));
0038 }
0039
0040
0041 template <typename ColumnContainer>
0042 static inline auto findByPdg(std::int32_t pdg, const ColumnContainer& column)
0043 -> std::optional<std::decay_t<decltype(column[0])>> {
0044
0045 assert((std::size(column) == kParticlesCount) && "Inconsistent column size");
0046
0047 auto index = findIndexByPdg(pdg);
0048 if (!index) {
0049 return std::nullopt;
0050 }
0051 return column[*index];
0052 }
0053
0054 static constexpr float extractCharge(float value) {
0055
0056 return (value / 3.0f) * Acts::UnitConstants::e;
0057 }
0058
0059 static constexpr float extractMass(float value) {
0060 return value * Acts::UnitConstants::MeV;
0061 }
0062
0063 }
0064
0065 std::optional<float> Acts::findCharge(Acts::PdgParticle pdg) {
0066 const auto charge =
0067 findByPdg(static_cast<std::int32_t>(pdg), kParticlesThreeCharge);
0068 if (!charge) {
0069 return std::nullopt;
0070 }
0071 return extractCharge(*charge);
0072 }
0073
0074 std::optional<float> Acts::findMass(Acts::PdgParticle pdg) {
0075 const auto mass =
0076 findByPdg(static_cast<std::int32_t>(pdg), kParticlesMassMeV);
0077 if (!mass) {
0078 return std::nullopt;
0079 }
0080 return extractMass(*mass);
0081 }
0082
0083 std::optional<std::string_view> Acts::findName(Acts::PdgParticle pdg) {
0084 return findByPdg(static_cast<std::int32_t>(pdg), kParticlesName);
0085 }
0086
0087 std::optional<Acts::ParticleData> Acts::findParticleData(PdgParticle pdg) {
0088 auto index = findIndexByPdg(pdg);
0089 if (!index) {
0090 return std::nullopt;
0091 }
0092 ParticleData result;
0093 result.charge = extractCharge(kParticlesThreeCharge[*index]);
0094 result.mass = extractMass(kParticlesMassMeV[*index]);
0095 result.name = kParticlesName[*index];
0096 return {};
0097 }
0098
0099 std::ostream& Acts::operator<<(std::ostream& os, Acts::PdgParticle pdg) {
0100 const auto name = Acts::findName(pdg);
0101 if (name) {
0102 os << *name;
0103 } else {
0104 os << static_cast<std::int32_t>(pdg);
0105 }
0106 return os;
0107 }
0108
0109 std::optional<std::string_view> Acts::pdgToShortAbsString(PdgParticle pdg) {
0110 pdg = makeAbsolutePdgParticle(pdg);
0111 if (pdg == eElectron) {
0112 return "e";
0113 }
0114 if (pdg == eMuon) {
0115 return "mu";
0116 }
0117 if (pdg == eTau) {
0118 return "t";
0119 }
0120 if (pdg == eGamma) {
0121 return "g";
0122 }
0123 if (pdg == ePionZero) {
0124 return "pi0";
0125 }
0126 if (pdg == ePionPlus) {
0127 return "pi";
0128 }
0129 if (pdg == eKaonPlus) {
0130 return "K";
0131 }
0132 if (pdg == eNeutron) {
0133 return "n";
0134 }
0135 if (pdg == eProton) {
0136 return "p";
0137 }
0138 if (pdg == eLead) {
0139 return "lead";
0140 }
0141 return std::nullopt;
0142 }