File indexing completed on 2026-11-08 10:11:25
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <cstddef>
0010 #include <functional>
0011
0012 #include "corecel/Assert.hh"
0013
0014 namespace celeritas
0015 {
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 class PDGNumber
0031 {
0032 public:
0033
0034 constexpr PDGNumber() = default;
0035
0036
0037 explicit constexpr PDGNumber(int val) : value_(val) {}
0038
0039
0040 explicit constexpr operator bool() const { return value_ != 0; }
0041
0042
0043 constexpr int unchecked_get() const { return value_; }
0044
0045
0046 inline int get() const;
0047
0048
0049
0050
0051 constexpr friend bool operator==(PDGNumber lhs, PDGNumber rhs)
0052 {
0053 return lhs.unchecked_get() == rhs.unchecked_get();
0054 }
0055
0056
0057 constexpr friend bool operator!=(PDGNumber lhs, PDGNumber rhs)
0058 {
0059 return !(lhs == rhs);
0060 }
0061
0062
0063 constexpr friend bool operator<(PDGNumber lhs, PDGNumber rhs)
0064 {
0065 return lhs.unchecked_get() < rhs.unchecked_get();
0066 }
0067
0068 private:
0069 int value_{0};
0070 };
0071
0072
0073
0074
0075
0076
0077
0078 inline int PDGNumber::get() const
0079 {
0080 CELER_ENSURE(*this);
0081 return value_;
0082 }
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099 namespace pdg
0100 {
0101
0102
0103 #define CELER_DEFINE_PDGNUMBER(NAME, VALUE) \
0104 inline constexpr PDGNumber NAME() \
0105 { \
0106 return PDGNumber{VALUE}; \
0107 }
0108
0109
0110
0111
0112
0113
0114
0115 CELER_DEFINE_PDGNUMBER(electron, 11)
0116 CELER_DEFINE_PDGNUMBER(positron, -11)
0117 CELER_DEFINE_PDGNUMBER(mu_minus, 13)
0118 CELER_DEFINE_PDGNUMBER(mu_plus, -13)
0119 CELER_DEFINE_PDGNUMBER(tau_minus, 15)
0120 CELER_DEFINE_PDGNUMBER(tau_plus, -15)
0121
0122
0123 CELER_DEFINE_PDGNUMBER(gamma, 22)
0124
0125
0126 CELER_DEFINE_PDGNUMBER(ion, 90)
0127
0128
0129 CELER_DEFINE_PDGNUMBER(pi_plus, 211)
0130 CELER_DEFINE_PDGNUMBER(pi_minus, -211)
0131 CELER_DEFINE_PDGNUMBER(kaon_plus, 321)
0132 CELER_DEFINE_PDGNUMBER(kaon_minus, -321)
0133 CELER_DEFINE_PDGNUMBER(neutron, 2112)
0134 CELER_DEFINE_PDGNUMBER(anti_neutron, -2112)
0135 CELER_DEFINE_PDGNUMBER(proton, 2212)
0136 CELER_DEFINE_PDGNUMBER(anti_proton, -2212)
0137
0138
0139 CELER_DEFINE_PDGNUMBER(hydrogen, 1000010010)
0140 CELER_DEFINE_PDGNUMBER(deuteron, 1000010020)
0141 CELER_DEFINE_PDGNUMBER(anti_deuteron, -1000010020)
0142 CELER_DEFINE_PDGNUMBER(triton, 1000010030)
0143 CELER_DEFINE_PDGNUMBER(anti_triton, -1000010030)
0144 CELER_DEFINE_PDGNUMBER(he3, 1000020030)
0145 CELER_DEFINE_PDGNUMBER(anti_he3, -1000020030)
0146 CELER_DEFINE_PDGNUMBER(alpha, 1000020040)
0147 CELER_DEFINE_PDGNUMBER(anti_alpha, -1000020040)
0148
0149
0150 CELER_DEFINE_PDGNUMBER(muonic_hydrogen, 2000010010)
0151 CELER_DEFINE_PDGNUMBER(muonic_deuteron, 2000010020)
0152 CELER_DEFINE_PDGNUMBER(muonic_triton, 2000010030)
0153 CELER_DEFINE_PDGNUMBER(muonic_alpha, 2000020040)
0154 CELER_DEFINE_PDGNUMBER(muonic_he3, 2000020030)
0155
0156
0157
0158 #undef CELER_DEFINE_PDGNUMBER
0159
0160 }
0161 }
0162
0163
0164
0165
0166
0167 namespace std
0168 {
0169
0170 template<>
0171 struct hash<celeritas::PDGNumber>
0172 {
0173 using argument_type = celeritas::PDGNumber;
0174 using result_type = std::size_t;
0175 result_type operator()(argument_type const& pdg) const noexcept
0176 {
0177 return std::hash<int>()(pdg.unchecked_get());
0178 }
0179 };
0180 }
0181