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