10 #ifndef SRC_INCLUDE_SMASH_PDGCODE_H_
11 #define SRC_INCLUDE_SMASH_PDGCODE_H_
25 #include <type_traits>
115 using std::invalid_argument::invalid_argument;
131 explicit PdgCode(
const std::string& codestring) {
145 if (codenumber < 0) {
147 codenumber = -codenumber;
157 digits_.antiparticle_ = ((abscode & 0x80000000u) != 0);
216 template <
typename T>
218 typename std::enable_if_t<std::is_integral_v<T> && 4 <
sizeof(T),
220 :
PdgCode{std::invoke([&codenumber]() {
221 std::stringstream stream;
223 if (codenumber < 0) {
225 codenumber = -codenumber;
227 stream << sign << std::hex << codenumber;
252 if (digits_.n_ > 9) {
255 if (digits_.n_R_ > 9) {
258 if (digits_.n_L_ > 9) {
261 if (digits_.n_q1_ > 6) {
264 if (digits_.n_q2_ > 6) {
267 if (digits_.n_q3_ > 6) {
270 if (digits_.n_J_ > 15) {
287 if (baryon_number() == 0) {
289 if ((digits_.n_J_ % 2 == 0) && dump() != 0x130 && dump() != 0x310) {
291 " (meson with even n_J)");
294 if ((digits_.n_J_ % 2 != 0) || digits_.n_J_ == 0) {
296 " (baryon with odd n_J)");
300 if (digits_.n_J_ == 0 && dump() != 0x0) {
301 throw InvalidPdgCode(
"Invalid PDG code " +
string() +
" (n_J==0)");
306 if (digits_.antiparticle_ && !has_antiparticle()) {
308 " (cannot be negative)");
313 inline std::uint32_t
dump()
const {
315 return (dump_ & 0x8fffffff);
319 inline std::int32_t
code()
const {
return antiparticle_sign() * ucode(); }
323 std::stringstream ss;
331 result.
digits_.antiparticle_ = !digits_.antiparticle_;
341 if (std::abs(pdgcode_decimal) > 1E7) {
344 int a = pdgcode_decimal;
345 int hex_pdg = 0, tmp = 1;
347 hex_pdg += (a % 10) * tmp;
362 assert(digits_.is_nucleus_ == nucleus_.is_nucleus_);
363 return nucleus_.is_nucleus_;
368 return (digits_.n_q3_ != 0 && digits_.n_q2_ != 0 && !is_nucleus());
373 return (digits_.n_q1_ == 0 && digits_.n_q2_ == 0 && digits_.n_q3_ == 1 &&
379 return (is_lepton() && digits_.n_J_ % 2 == 0);
384 return is_meson() && digits_.n_q2_ == 4 && digits_.n_q3_ == 4;
390 return static_cast<int>(nucleus_.A_) * antiparticle_sign();
392 if (!is_hadron() || digits_.n_q1_ == 0) {
395 return antiparticle_sign();
398 inline bool is_baryon()
const {
return is_hadron() && digits_.n_q1_ != 0; }
401 inline bool is_meson()
const {
return is_hadron() && digits_.n_q1_ == 0; }
405 const auto abs_code = std::abs(code());
411 const auto abs_code = std::abs(code());
412 return (abs_code ==
pdg::p);
417 const auto abs_code = std::abs(code());
418 return (abs_code ==
pdg::n);
423 const auto abs_code = std::abs(code());
429 const auto abs_code = std::abs(code());
435 inline bool is_hyperon()
const {
return is_hadron() && digits_.n_q1_ == 3; }
439 return is_hyperon() && digits_.n_q2_ == 3 && digits_.n_q3_ == 3;
444 return is_hyperon() && digits_.n_q2_ == 3 && digits_.n_q3_ != 3;
449 return is_hyperon() && digits_.n_q2_ == 1 && digits_.n_q3_ == 2;
454 return is_hyperon() && digits_.n_q2_ != 3 && !is_Lambda();
459 const auto abs_code = std::abs(code());
466 const auto abs_code = std::abs(code());
472 const auto c = code();
478 const auto c = code();
484 const auto c = code();
490 return is_nucleus() && nucleus_.A_ == 2 && nucleus_.Z_ == 1 &&
491 nucleus_.n_Lambda_ == 0 && nucleus_.I_ == 0;
496 return is_nucleus() && nucleus_.A_ == 3 && nucleus_.Z_ == 1 &&
497 nucleus_.n_Lambda_ == 0 && nucleus_.I_ == 0;
509 return (baryon_number() != 0) || (digits_.n_q2_ != digits_.n_q3_);
511 return digits_.n_q3_ == 1;
523 return net_quark_number(2) - net_quark_number(1);
535 return std::abs(strangeness()) / 3.;
536 }
else if (is_meson()) {
539 if (digits_.n_q3_ == 3 && digits_.n_q2_ == 3) {
542 return std::abs(strangeness()) / 2.;
560 return std::abs(charmness()) / 3.;
561 }
else if (is_meson()) {
564 if (digits_.n_q3_ == 4 && digits_.n_q2_ == 4) {
567 return std::abs(charmness()) / 2.;
585 return std::abs(bottomness()) / 3.;
586 }
else if (is_meson()) {
589 if (digits_.n_q3_ == 5 && digits_.n_q2_ == 5) {
592 return std::abs(bottomness()) / 2.;
603 return (frac_charm() != 0) || (frac_bottom() != 0);
618 inline int charmness()
const {
return +net_quark_number(4); }
625 inline int bottomness()
const {
return -net_quark_number(5); }
636 if (is_hadron() || is_nucleus()) {
643 for (
int i = 1; i < 7; i++) {
646 Q += (i % 2 == 0 ? 2 : -1) * net_quark_number(i);
653 if (digits_.n_q3_ == 1) {
654 return -1 * (digits_.n_J_ % 2) * antiparticle_sign();
660 if ((dump_ & 0x0000ffff) == 0x24) {
661 return antiparticle_sign();
676 inline unsigned int spin()
const {
681 if (nucleus_.A_ == 2) {
684 }
else if (nucleus_.A_ == 3) {
689 }
else if (nucleus_.A_ == 4) {
693 throw std::runtime_error(
"Unknown spin of nucleus.");
699 if (digits_.n_J_ == 0) {
702 return digits_.n_J_ - 1;
709 return digits_.n_q3_;
713 if (is_hadron() && digits_.n_J_ > 0) {
720 return (digits_.antiparticle_ ? -1 : +1);
724 if (!is_hadron() || is_nucleus()) {
727 return chunks_.quarks_;
740 std::array<int, 3> result = {
static_cast<int>(digits_.n_q1_),
741 static_cast<int>(digits_.n_q2_),
742 static_cast<int>(digits_.n_q3_)};
745 if (digits_.n_q1_ != 0 && digits_.antiparticle_) {
746 for (
size_t i = 0; i < 3; i++) {
747 result[i] = -result[i];
751 if (digits_.n_q1_ == 0) {
753 if (digits_.n_q2_ == digits_.n_q3_) {
754 result[2] = -result[2];
757 if (digits_.antiparticle_) {
758 result[1] = -result[1];
761 result[2] = -result[2];
765 if (digits_.n_q2_ != digits_.n_q3_ && digits_.n_q2_ % 2 == 1) {
766 for (
int i = 1; i <= 2; i++) {
767 result[i] = -result[i];
787 bool contains_enough_valence_quarks(
int valence_quarks_required)
const;
800 return dump_ < rhs.
dump_;
815 return code() == -rhs.
code();
840 return antiparticle_sign() *
841 (nucleus_.I_ + 10 * nucleus_.A_ + 10000 * nucleus_.Z_ +
842 10000000 * nucleus_.n_Lambda_ + 1000000000);
845 int n_J_2 = digits_.n_J_;
850 return antiparticle_sign() *
851 (n_J_2 + digits_.n_q3_ * 10 + digits_.n_q2_ * 100 +
852 digits_.n_q1_ * 1000 + digits_.n_L_ * 10000 +
853 digits_.n_R_ * 100000 + digits_.n_ * 1000000 + n_J_1 * 10000000);
859 chunks_.excitation_ = 0;
875 int net_quark_number(
const int quark)
const;
879 return (is_nucleus() && !nucleus_.antiparticle_) ? nucleus_.Z_ : 0;
883 return (is_nucleus() && !nucleus_.antiparticle_)
884 ? nucleus_.A_ - nucleus_.Z_ - nucleus_.n_Lambda_
889 return (is_nucleus() && !nucleus_.antiparticle_) ? nucleus_.n_Lambda_ : 0;
893 return (is_nucleus() && nucleus_.antiparticle_) ? nucleus_.Z_ : 0;
897 return (is_nucleus() && nucleus_.antiparticle_)
898 ? nucleus_.A_ - nucleus_.Z_ - nucleus_.n_Lambda_
903 return (is_nucleus() && nucleus_.antiparticle_) ? nucleus_.n_Lambda_ : 0;
906 int nucleus_A()
const {
return is_nucleus() ? nucleus_.A_ : 0; }
920 #if defined(LITTLE_ENDIAN_ARCHITECTURE) || defined(DOXYGEN)
934 std::uint32_t
n_ : 4, : 2;
939 #elif defined(BIG_ENDIAN_ARCHITECTURE)
940 bool antiparticle_ : 1;
941 bool is_nucleus_ : 1, : 2;
942 std::uint32_t n_ : 4;
943 std::uint32_t n_R_ : 4;
944 std::uint32_t n_L_ : 4;
945 std::uint32_t n_q1_ : 4;
946 std::uint32_t n_q2_ : 4;
947 std::uint32_t n_q3_ : 4;
948 std::uint32_t n_J_ : 4;
950 #error Endianness macro of the machine not defined.
963 #if defined(LITTLE_ENDIAN_ARCHITECTURE) || defined(DOXYGEN)
969 #elif defined(BIG_ENDIAN_ARCHITECTURE)
970 std::uint32_t : 4, excitation_ : 12;
971 std::uint32_t quarks_ : 12, : 4;
973 #error Endianness macro of the machine not defined.
978 #if defined(LITTLE_ENDIAN_ARCHITECTURE) || defined(DOXYGEN)
980 std::uint32_t
Z_ : 10;
981 std::uint32_t
A_ : 10;
982 std::uint32_t
I_ : 4;
984 bool antiparticle_ : 1;
985 #elif defined(BIG_ENDIAN_ARCHITECTURE)
986 bool antiparticle_ : 1;
987 bool is_nucleus_ : 1;
988 std::uint32_t I_ : 4;
989 std::uint32_t A_ : 10;
990 std::uint32_t Z_ : 10;
991 std::uint32_t n_Lambda_ : 6;
993 #error Endianness macro of the machine not defined.
1002 inline std::uint32_t
ucode()
const {
return (dump_ & 0x0fffffff); }
1012 if (48 <= inp && inp <= 57) {
1016 if (65 <= inp && inp <= 70) {
1017 return inp - 65 + 10;
1020 if (97 <= inp && inp <= 102) {
1021 return inp - 97 + 10;
1023 throw InvalidPdgCode(
"PdgCode: Invalid character " + std::string(&inp, 1) +
1051 digits_.n_ = digits_.n_R_ = digits_.n_L_ = digits_.n_q1_ = digits_.n_q2_ =
1052 digits_.n_q3_ = digits_.n_J_ = digits_.is_nucleus_ = 0;
1053 size_t length = codestring.size();
1055 throw InvalidPdgCode(
"Empty string does not contain PDG Code\n");
1060 if (codestring[c] ==
'-') {
1061 digits_.antiparticle_ =
true;
1063 }
else if (codestring[c] ==
'+') {
1064 digits_.antiparticle_ =
false;
1068 unsigned int sign = c;
1071 if (length == 10 + sign) {
1072 nucleus_.is_nucleus_ =
true;
1073 if (codestring[c] !=
'1' || codestring[c + 1] !=
'0') {
1075 "\" should start with 10\n");
1079 std::array<int, 8> digits;
1080 for (
int i = 0; i < 8; i++) {
1081 digits[i] = get_digit_from_char(codestring[c + i]);
1083 nucleus_.n_Lambda_ = digits[0];
1084 nucleus_.Z_ = 100 * digits[1] + 10 * digits[2] + digits[3];
1085 nucleus_.A_ = 100 * digits[4] + 10 * digits[5] + digits[6];
1086 nucleus_.I_ = digits[7];
1091 if (length > 8 + sign) {
1093 "\" too long for PDG Code\n");
1097 if (length > 7 + sign) {
1098 digits_.n_J_ += get_digit_from_char(codestring[c++]);
1101 if (length > 6 + sign) {
1102 digits_.n_ = get_digit_from_char(codestring[c++]);
1105 if (length > 5 + sign) {
1106 digits_.n_R_ = get_digit_from_char(codestring[c++]);
1109 if (length > 4 + sign) {
1110 digits_.n_L_ = get_digit_from_char(codestring[c++]);
1113 if (length > 3 + sign) {
1114 digits_.n_q1_ = get_digit_from_char(codestring[c++]);
1115 if (digits_.n_q1_ > 6) {
1116 throw InvalidPdgCode(
"Invalid PDG code " + codestring +
" (n_q1>6)");
1120 if (length > 2 + sign) {
1121 digits_.n_q2_ = get_digit_from_char(codestring[c++]);
1122 if (digits_.n_q2_ > 6) {
1123 throw InvalidPdgCode(
"Invalid PDG code " + codestring +
" (n_q2>6)");
1127 if (length > 1 + sign) {
1128 digits_.n_q3_ = get_digit_from_char(codestring[c++]);
1129 if (digits_.n_q3_ > 6) {
1130 throw InvalidPdgCode(
"Invalid PDG code " + codestring +
" (n_q3>6)");
1134 if (length > sign) {
1135 digits_.n_J_ += get_digit_from_char(codestring[c++]);
1138 "String \"" + codestring +
1139 "\" only consists of a sign, that is no valid PDG Code\n");
1156 bool ap = digits_.antiparticle_;
1157 dump_ = abscode & 0x0fffffff;
1158 digits_.antiparticle_ = ap;
1159 int test = test_code();
1162 " in PDG Code " +
string());
1168 static_assert(
sizeof(PdgCode) == 4,
"should fit into 32 bit integer");
1176 std::istream&
operator>>(std::istream& is, PdgCode& code);
1182 std::ostream&
operator<<(std::ostream& is,
const PdgCode& code);
1186 const auto c1 = pdg1.
code();
1187 const auto c2 = pdg2.
code();
1188 const auto min = std::min(c1, c2);
1189 const auto max = std::max(c1, c2);
1190 return (max == 0x11 && min == -0x11) || (max == 0x13 && min == -0x13) ||
1191 (max == 0x12 && min == -0x11) || (max == 0x11 && min == -0x12);
PdgCode stores a Particle Data Group Particle Numbering Scheme particle type number.
std::uint32_t quarks_
The quark digits n_q{1,2,3}_.
bool is_Nstar1535() const
std::int32_t code() const
int antiparticle_sign() const
PdgCode(T codenumber, typename std::enable_if_t< std::is_integral_v< T > &&4< sizeof(T), bool >=true)
The creation of PdgCode instances for nuclei that have a 10-digits code cannot be done using the inte...
bool operator!=(const PdgCode rhs) const
int nucleus_n() const
Number of neutrons in nucleus.
int baryon_number() const
PdgCode(const std::uint32_t abscode)
Receive an unsigned integer and process it into a PDG Code.
std::uint32_t n_q1_
first quark field. 0 for mesons.
bool is_charmonia() const
PdgCode(const std::string &codestring)
Initialize using a string The string is interpreted as a hexadecimal number, i.e.,...
int nucleus_ap() const
Number of antiprotons in nucleus.
int nucleus_an() const
Number of antineutrons in nucleus.
std::array< int, 3 > quark_content() const
The return is always an array of three numbers, which are pdgcodes of quarks: 1 - d,...
std::uint32_t n_q3_
third quark field
unsigned int spin() const
bool antiparticle_
first bit: stores the sign.
bool is_Sigmastar() const
std::uint32_t dump() const
Dumps the bitfield into an unsigned integer.
std::uint32_t n_
first field: "counter"
double frac_charm() const
std::uint32_t n_J_
spin quantum number .
static PdgCode from_decimal(const int pdgcode_decimal)
Construct PDG code from decimal number.
bool is_antiparticle_of(const PdgCode rhs) const
std::uint32_t bool is_nucleus_
1 for nuclei, 0 for the rest
struct smash::PdgCode::@0::@2 digits_
The single digits collection of the code.
int nucleus_p() const
Number of protons in nucleus.
int32_t get_decimal() const
void set_fields(std::uint32_t abscode)
Sets the bitfield from an unsigned integer.
void check() const
Do all sorts of validity checks.
std::string string() const
int test_code() const
Checks the integer for invalid hex digits.
PdgCode get_antiparticle() const
Construct the antiparticle to a given PDG code.
int nucleus_La() const
Number of Lambdas in nucleus.
double frac_bottom() const
bool operator==(const PdgCode rhs) const
PdgCode()
Standard initializer.
int nucleus_A() const
Nucleus mass number.
static PdgCode invalid()
PdgCode 0x0 is guaranteed not to be valid by the PDG standard, but it passes all tests here,...
int nucleus_aLa() const
Number of anti-Lambdas in nucleus.
bool operator<(const PdgCode rhs) const
Sorts PDG Codes according to their numeric value.
PdgCode(std::int32_t codenumber)
Receive a signed integer and process it into a PDG Code.
void deexcite()
Remove all excitation, except spin. Sign and quark content remains.
std::uint32_t n_L_
"angular momentum"
void set_from_string(const std::string &codestring)
Set the PDG code from the given string.
std::uint32_t ucode() const
std::uint32_t n_R_
"radial excitation"
std::uint32_t dump_
The bitfield dumped into a single integer.
double frac_strange() const
bool has_antiparticle() const
std::uint32_t get_digit_from_char(const char inp) const
bool is_heavy_flavor() const
std::int32_t quarks() const
std::uint32_t n_q2_
second quark field
unsigned int spin_degeneracy() const
std::uint32_t excitation_
The excitation digits n_, n_R_, n_L_.
int charge() const
The charge of the particle.
std::ostream & operator<<(std::ostream &is, const PdgCode &code)
Writes the textual representation of the PDG code to the output stream.
constexpr int Delta_pp
Δ⁺⁺.
constexpr int Sigma_star_z
Σ*⁰
constexpr int N1535_z
N(1535)⁰.
constexpr int Sigma_star_p
Σ*⁺
constexpr int Sigma_star_m
Σ*⁻
constexpr int N1535_p
N(1535)⁺.
bool is_dilepton(const PdgCode pdg1, const PdgCode pdg2)
std::istream & operator>>(std::istream &is, PdgCode &code)
Sets the PDG code from the textual representation in the input stream.
bool has_lepton_pair(const PdgCode pdg1, const PdgCode pdg2, const PdgCode pdg3)
std::string to_string(ThermodynamicQuantity quantity)
Convert a ThermodynamicQuantity enum value to its corresponding string.
thrown for invalid inputs