10 #ifndef SRC_INCLUDE_SMASH_PDGCODE_H_
11 #define SRC_INCLUDE_SMASH_PDGCODE_H_
25 #include <type_traits>
118 using std::invalid_argument::invalid_argument;
134 explicit PdgCode(
const std::string& codestring) {
148 if (codenumber < 0) {
150 codenumber = -codenumber;
160 digits_.antiparticle_ = ((abscode & 0x80000000u) != 0);
219 template <
typename T>
221 typename std::enable_if_t<std::is_integral_v<T> && 4 <
sizeof(T),
223 :
PdgCode{std::invoke([&codenumber]() {
224 std::stringstream stream;
226 if (codenumber < 0) {
228 codenumber = -codenumber;
230 stream << sign << std::hex << codenumber;
255 if (digits_.n_ > 9) {
258 if (digits_.n_R_ > 9) {
261 if (digits_.n_L_ > 9) {
264 if (digits_.n_q1_ > 6) {
267 if (digits_.n_q2_ > 6) {
270 if (digits_.n_q3_ > 6) {
273 if (digits_.n_J_ > 15) {
290 if (baryon_number() == 0) {
292 if ((digits_.n_J_ % 2 == 0) && dump() != 0x130 && dump() != 0x310) {
294 " (meson with even n_J)");
297 if ((digits_.n_J_ % 2 != 0) || digits_.n_J_ == 0) {
299 " (baryon with odd n_J)");
303 if (digits_.n_J_ == 0 && dump() != 0x0) {
304 throw InvalidPdgCode(
"Invalid PDG code " +
string() +
" (n_J==0)");
309 if (digits_.antiparticle_ && !has_antiparticle()) {
311 " (cannot be negative)");
316 inline std::uint32_t
dump()
const {
318 return (dump_ & 0x8fffffff);
322 inline std::int32_t
code()
const {
return antiparticle_sign() * ucode(); }
326 std::stringstream ss;
334 result.
digits_.antiparticle_ = !digits_.antiparticle_;
344 if (std::abs(pdgcode_decimal) > 1E7) {
345 return PdgCode(std::to_string(pdgcode_decimal));
347 int a = pdgcode_decimal;
348 int hex_pdg = 0, tmp = 1;
350 hex_pdg += (a % 10) * tmp;
365 assert(digits_.is_nucleus_ == nucleus_.is_nucleus_);
366 return nucleus_.is_nucleus_;
371 return (digits_.n_q3_ != 0 && digits_.n_q2_ != 0 && !is_nucleus());
376 return (digits_.n_q1_ == 0 && digits_.n_q2_ == 0 && digits_.n_q3_ == 1 &&
383 return static_cast<int>(nucleus_.A_) * antiparticle_sign();
385 if (!is_hadron() || digits_.n_q1_ == 0) {
388 return antiparticle_sign();
391 inline bool is_baryon()
const {
return is_hadron() && digits_.n_q1_ != 0; }
394 inline bool is_meson()
const {
return is_hadron() && digits_.n_q1_ == 0; }
398 const auto abs_code = std::abs(code());
404 const auto abs_code = std::abs(code());
405 return (abs_code ==
pdg::p);
410 const auto abs_code = std::abs(code());
411 return (abs_code ==
pdg::n);
416 const auto abs_code = std::abs(code());
422 const auto abs_code = std::abs(code());
428 inline bool is_hyperon()
const {
return is_hadron() && digits_.n_q1_ == 3; }
432 return is_hyperon() && digits_.n_q2_ == 3 && digits_.n_q3_ == 3;
437 return is_hyperon() && digits_.n_q2_ == 3 && digits_.n_q3_ != 3;
442 return is_hyperon() && digits_.n_q2_ == 1 && digits_.n_q3_ == 2;
447 return is_hyperon() && digits_.n_q2_ != 3 && !is_Lambda();
452 const auto abs_code = std::abs(code());
458 const auto c = code();
464 const auto c = code();
470 const auto c = code();
476 return is_nucleus() && nucleus_.A_ == 2 && nucleus_.Z_ == 1 &&
477 nucleus_.n_Lambda_ == 0 && nucleus_.I_ == 0;
482 return is_nucleus() && nucleus_.A_ == 3 && nucleus_.Z_ == 1 &&
483 nucleus_.n_Lambda_ == 0 && nucleus_.I_ == 0;
495 return (baryon_number() != 0) || (digits_.n_q2_ != digits_.n_q3_);
497 return digits_.n_q3_ == 1;
509 return net_quark_number(2) - net_quark_number(1);
522 if (is_hadron() && digits_.n_q3_ == 3 && digits_.n_q2_ == 3) {
527 return std::abs(strangeness()) / 3.;
528 }
else if (is_meson()) {
529 return std::abs(strangeness()) / 2.;
550 inline int charmness()
const {
return +net_quark_number(4); }
557 inline int bottomness()
const {
return -net_quark_number(5); }
568 if (is_hadron() || is_nucleus()) {
575 for (
int i = 1; i < 7; i++) {
578 Q += (i % 2 == 0 ? 2 : -1) * net_quark_number(i);
585 if (digits_.n_q3_ == 1) {
586 return -1 * (digits_.n_J_ % 2) * antiparticle_sign();
592 if ((dump_ & 0x0000ffff) == 0x24) {
593 return antiparticle_sign();
608 inline unsigned int spin()
const {
613 if (nucleus_.A_ == 2) {
616 }
else if (nucleus_.A_ == 3) {
621 }
else if (nucleus_.A_ == 4) {
625 throw std::runtime_error(
"Unknown spin of nucleus.");
631 if (digits_.n_J_ == 0) {
634 return digits_.n_J_ - 1;
641 return digits_.n_q3_;
645 if (is_hadron() && digits_.n_J_ > 0) {
652 return (digits_.antiparticle_ ? -1 : +1);
656 if (!is_hadron() || is_nucleus()) {
659 return chunks_.quarks_;
672 std::array<int, 3> result = {
static_cast<int>(digits_.n_q1_),
673 static_cast<int>(digits_.n_q2_),
674 static_cast<int>(digits_.n_q3_)};
677 if (digits_.n_q1_ != 0 && digits_.antiparticle_) {
678 for (
size_t i = 0; i < 3; i++) {
679 result[i] = -result[i];
683 if (digits_.n_q1_ == 0) {
685 if (digits_.n_q2_ == digits_.n_q3_) {
686 result[2] = -result[2];
689 if (digits_.antiparticle_) {
690 result[1] = -result[1];
693 result[2] = -result[2];
697 if (digits_.n_q2_ != digits_.n_q3_ && digits_.n_q2_ % 2 == 1) {
698 for (
int i = 1; i <= 2; i++) {
699 result[i] = -result[i];
719 bool contains_enough_valence_quarks(
int valence_quarks_required)
const;
732 return dump_ < rhs.
dump_;
747 return code() == -rhs.
code();
772 return antiparticle_sign() *
773 (nucleus_.I_ + 10 * nucleus_.A_ + 10000 * nucleus_.Z_ +
774 10000000 * nucleus_.n_Lambda_ + 1000000000);
777 int n_J_2 = digits_.n_J_;
782 return antiparticle_sign() *
783 (n_J_2 + digits_.n_q3_ * 10 + digits_.n_q2_ * 100 +
784 digits_.n_q1_ * 1000 + digits_.n_L_ * 10000 +
785 digits_.n_R_ * 100000 + digits_.n_ * 1000000 + n_J_1 * 10000000);
791 chunks_.excitation_ = 0;
807 int net_quark_number(
const int quark)
const;
811 return (is_nucleus() && !nucleus_.antiparticle_) ? nucleus_.Z_ : 0;
815 return (is_nucleus() && !nucleus_.antiparticle_)
816 ? nucleus_.A_ - nucleus_.Z_ - nucleus_.n_Lambda_
821 return (is_nucleus() && !nucleus_.antiparticle_) ? nucleus_.n_Lambda_ : 0;
825 return (is_nucleus() && nucleus_.antiparticle_) ? nucleus_.Z_ : 0;
829 return (is_nucleus() && nucleus_.antiparticle_)
830 ? nucleus_.A_ - nucleus_.Z_ - nucleus_.n_Lambda_
835 return (is_nucleus() && nucleus_.antiparticle_) ? nucleus_.n_Lambda_ : 0;
838 int nucleus_A()
const {
return is_nucleus() ? nucleus_.A_ : 0; }
852 #if defined(LITTLE_ENDIAN_ARCHITECTURE) || defined(DOXYGEN)
866 std::uint32_t
n_ : 4, : 2;
871 #elif defined(BIG_ENDIAN_ARCHITECTURE)
872 bool antiparticle_ : 1;
873 bool is_nucleus_ : 1, : 2;
874 std::uint32_t n_ : 4;
875 std::uint32_t n_R_ : 4;
876 std::uint32_t n_L_ : 4;
877 std::uint32_t n_q1_ : 4;
878 std::uint32_t n_q2_ : 4;
879 std::uint32_t n_q3_ : 4;
880 std::uint32_t n_J_ : 4;
882 #error Endianness macro of the machine not defined.
895 #if defined(LITTLE_ENDIAN_ARCHITECTURE) || defined(DOXYGEN)
901 #elif defined(BIG_ENDIAN_ARCHITECTURE)
902 std::uint32_t : 4, excitation_ : 12;
903 std::uint32_t quarks_ : 12, : 4;
905 #error Endianness macro of the machine not defined.
910 #if defined(LITTLE_ENDIAN_ARCHITECTURE) || defined(DOXYGEN)
912 std::uint32_t
Z_ : 10;
913 std::uint32_t
A_ : 10;
914 std::uint32_t
I_ : 4;
916 bool antiparticle_ : 1;
917 #elif defined(BIG_ENDIAN_ARCHITECTURE)
918 bool antiparticle_ : 1;
919 bool is_nucleus_ : 1;
920 std::uint32_t I_ : 4;
921 std::uint32_t A_ : 10;
922 std::uint32_t Z_ : 10;
923 std::uint32_t n_Lambda_ : 6;
925 #error Endianness macro of the machine not defined.
934 inline std::uint32_t
ucode()
const {
return (dump_ & 0x0fffffff); }
944 if (48 <= inp && inp <= 57) {
948 if (65 <= inp && inp <= 70) {
949 return inp - 65 + 10;
952 if (97 <= inp && inp <= 102) {
953 return inp - 97 + 10;
955 throw InvalidPdgCode(
"PdgCode: Invalid character " + std::string(&inp, 1) +
983 digits_.n_ = digits_.n_R_ = digits_.n_L_ = digits_.n_q1_ = digits_.n_q2_ =
984 digits_.n_q3_ = digits_.n_J_ = digits_.is_nucleus_ = 0;
985 size_t length = codestring.size();
992 if (codestring[c] ==
'-') {
993 digits_.antiparticle_ =
true;
995 }
else if (codestring[c] ==
'+') {
996 digits_.antiparticle_ =
false;
1000 unsigned int sign = c;
1003 if (length == 10 + sign) {
1004 nucleus_.is_nucleus_ =
true;
1005 if (codestring[c] !=
'1' || codestring[c + 1] !=
'0') {
1007 "\" should start with 10\n");
1011 std::array<int, 8> digits;
1012 for (
int i = 0; i < 8; i++) {
1013 digits[i] = get_digit_from_char(codestring[c + i]);
1015 nucleus_.n_Lambda_ = digits[0];
1016 nucleus_.Z_ = 100 * digits[1] + 10 * digits[2] + digits[3];
1017 nucleus_.A_ = 100 * digits[4] + 10 * digits[5] + digits[6];
1018 nucleus_.I_ = digits[7];
1023 if (length > 8 + sign) {
1025 "\" too long for PDG Code\n");
1029 if (length > 7 + sign) {
1030 digits_.n_J_ += get_digit_from_char(codestring[c++]);
1033 if (length > 6 + sign) {
1034 digits_.n_ = get_digit_from_char(codestring[c++]);
1037 if (length > 5 + sign) {
1038 digits_.n_R_ = get_digit_from_char(codestring[c++]);
1041 if (length > 4 + sign) {
1042 digits_.n_L_ = get_digit_from_char(codestring[c++]);
1045 if (length > 3 + sign) {
1046 digits_.n_q1_ = get_digit_from_char(codestring[c++]);
1047 if (digits_.n_q1_ > 6) {
1048 throw InvalidPdgCode(
"Invalid PDG code " + codestring +
" (n_q1>6)");
1052 if (length > 2 + sign) {
1053 digits_.n_q2_ = get_digit_from_char(codestring[c++]);
1054 if (digits_.n_q2_ > 6) {
1055 throw InvalidPdgCode(
"Invalid PDG code " + codestring +
" (n_q2>6)");
1059 if (length > 1 + sign) {
1060 digits_.n_q3_ = get_digit_from_char(codestring[c++]);
1061 if (digits_.n_q3_ > 6) {
1062 throw InvalidPdgCode(
"Invalid PDG code " + codestring +
" (n_q3>6)");
1066 if (length > sign) {
1067 digits_.n_J_ += get_digit_from_char(codestring[c++]);
1070 "String \"" + codestring +
1071 "\" only consists of a sign, that is no valid PDG Code\n");
1088 bool ap = digits_.antiparticle_;
1089 dump_ = abscode & 0x0fffffff;
1090 digits_.antiparticle_ = ap;
1091 int test = test_code();
1094 " in PDG Code " +
string());
1100 static_assert(
sizeof(PdgCode) == 4,
"should fit into 32 bit integer");
1108 std::istream&
operator>>(std::istream& is, PdgCode& code);
1114 std::ostream&
operator<<(std::ostream& is,
const PdgCode& code);
1118 const auto c1 = pdg1.
code();
1119 const auto c2 = pdg2.
code();
1120 const auto min = std::min(c1, c2);
1121 const auto max = std::max(c1, c2);
1122 return (max == 0x11 && min == -0x11) || (max == 0x13 && min == -0x13);
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.
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.
std::uint32_t dump() const
Dumps the bitfield into an unsigned integer.
std::uint32_t n_
first field: "counter"
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.
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
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 N1535_z
N(1535)⁰.
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)
thrown for invalid inputs