10 #ifndef SRC_INCLUDE_SMASH_PDGCODE_H_
11 #define SRC_INCLUDE_SMASH_PDGCODE_H_
24 #include <type_traits>
117 using std::invalid_argument::invalid_argument;
133 explicit PdgCode(
const std::string& codestring) {
147 if (codenumber < 0) {
149 codenumber = -codenumber;
159 digits_.antiparticle_ = ((abscode & 0x80000000u) != 0);
218 template <
typename T>
220 typename std::enable_if_t<std::is_integral_v<T> && 4 <
sizeof(T),
222 :
PdgCode{std::invoke([&codenumber]() {
223 std::stringstream stream;
225 if (codenumber < 0) {
227 codenumber = -codenumber;
229 stream << sign << std::hex << codenumber;
254 if (digits_.n_ > 9) {
257 if (digits_.n_R_ > 9) {
260 if (digits_.n_L_ > 9) {
263 if (digits_.n_q1_ > 6) {
266 if (digits_.n_q2_ > 6) {
269 if (digits_.n_q3_ > 6) {
272 if (digits_.n_J_ > 15) {
289 if (baryon_number() == 0) {
291 if ((digits_.n_J_ % 2 == 0) && dump() != 0x130 && dump() != 0x310) {
293 " (meson with even n_J)");
296 if ((digits_.n_J_ % 2 != 0) || digits_.n_J_ == 0) {
298 " (baryon with odd n_J)");
302 if (digits_.n_J_ == 0 && dump() != 0x0) {
303 throw InvalidPdgCode(
"Invalid PDG code " +
string() +
" (n_J==0)");
308 if (digits_.antiparticle_ && !has_antiparticle()) {
310 " (cannot be negative)");
315 inline std::uint32_t
dump()
const {
317 return (dump_ & 0x8fffffff);
321 inline std::int32_t
code()
const {
return antiparticle_sign() * ucode(); }
325 std::stringstream ss;
333 result.
digits_.antiparticle_ = !digits_.antiparticle_;
343 if (std::abs(pdgcode_decimal) > 1E7) {
344 return PdgCode(std::to_string(pdgcode_decimal));
346 int a = pdgcode_decimal;
347 int hex_pdg = 0, tmp = 1;
349 hex_pdg += (a % 10) * tmp;
364 assert(digits_.is_nucleus_ == nucleus_.is_nucleus_);
365 return nucleus_.is_nucleus_;
370 return (digits_.n_q3_ != 0 && digits_.n_q2_ != 0 && !is_nucleus());
375 return (digits_.n_q1_ == 0 && digits_.n_q2_ == 0 && digits_.n_q3_ == 1 &&
382 return static_cast<int>(nucleus_.A_) * antiparticle_sign();
384 if (!is_hadron() || digits_.n_q1_ == 0) {
387 return antiparticle_sign();
390 inline bool is_baryon()
const {
return is_hadron() && digits_.n_q1_ != 0; }
393 inline bool is_meson()
const {
return is_hadron() && digits_.n_q1_ == 0; }
397 const auto abs_code = std::abs(code());
403 const auto abs_code = std::abs(code());
404 return (abs_code ==
pdg::p);
409 const auto abs_code = std::abs(code());
410 return (abs_code ==
pdg::n);
415 const auto abs_code = std::abs(code());
421 const auto abs_code = std::abs(code());
427 inline bool is_hyperon()
const {
return is_hadron() && digits_.n_q1_ == 3; }
431 return is_hyperon() && digits_.n_q2_ == 3 && digits_.n_q3_ == 3;
436 return is_hyperon() && digits_.n_q2_ == 3 && digits_.n_q3_ != 3;
441 return is_hyperon() && digits_.n_q2_ == 1 && digits_.n_q3_ == 2;
446 return is_hyperon() && digits_.n_q2_ != 3 && !is_Lambda();
451 const auto abs_code = std::abs(code());
457 const auto c = code();
463 const auto c = code();
469 const auto c = code();
475 return is_nucleus() && nucleus_.A_ == 2 && nucleus_.Z_ == 1 &&
476 nucleus_.n_Lambda_ == 0 && nucleus_.I_ == 0;
481 return is_nucleus() && nucleus_.A_ == 3 && nucleus_.Z_ == 1 &&
482 nucleus_.n_Lambda_ == 0 && nucleus_.I_ == 0;
494 return (baryon_number() != 0) || (digits_.n_q2_ != digits_.n_q3_);
496 return digits_.n_q3_ == 1;
508 return net_quark_number(2) - net_quark_number(1);
521 if (is_hadron() && digits_.n_q3_ == 3 && digits_.n_q2_ == 3) {
526 return std::abs(strangeness()) / 3.;
527 }
else if (is_meson()) {
528 return std::abs(strangeness()) / 2.;
549 inline int charmness()
const {
return +net_quark_number(4); }
556 inline int bottomness()
const {
return -net_quark_number(5); }
567 if (is_hadron() || is_nucleus()) {
574 for (
int i = 1; i < 7; i++) {
577 Q += (i % 2 == 0 ? 2 : -1) * net_quark_number(i);
584 if (digits_.n_q3_ == 1) {
585 return -1 * (digits_.n_J_ % 2) * antiparticle_sign();
591 if ((dump_ & 0x0000ffff) == 0x24) {
592 return antiparticle_sign();
607 inline unsigned int spin()
const {
612 if (nucleus_.A_ == 2) {
615 }
else if (nucleus_.A_ == 3) {
620 }
else if (nucleus_.A_ == 4) {
624 throw std::runtime_error(
"Unknown spin of nucleus.");
630 if (digits_.n_J_ == 0) {
633 return digits_.n_J_ - 1;
640 return digits_.n_q3_;
644 if (is_hadron() && digits_.n_J_ > 0) {
651 return (digits_.antiparticle_ ? -1 : +1);
655 if (!is_hadron() || is_nucleus()) {
658 return chunks_.quarks_;
671 std::array<int, 3> result = {
static_cast<int>(digits_.n_q1_),
672 static_cast<int>(digits_.n_q2_),
673 static_cast<int>(digits_.n_q3_)};
676 if (digits_.n_q1_ != 0 && digits_.antiparticle_) {
677 for (
size_t i = 0; i < 3; i++) {
678 result[i] = -result[i];
682 if (digits_.n_q1_ == 0) {
684 if (digits_.n_q2_ == digits_.n_q3_) {
685 result[2] = -result[2];
688 if (digits_.antiparticle_) {
689 result[1] = -result[1];
692 result[2] = -result[2];
696 if (digits_.n_q2_ != digits_.n_q3_ && digits_.n_q2_ % 2 == 1) {
697 for (
int i = 1; i <= 2; i++) {
698 result[i] = -result[i];
718 bool contains_enough_valence_quarks(
int valence_quarks_required)
const;
731 return dump_ < rhs.
dump_;
746 return code() == -rhs.
code();
771 return antiparticle_sign() *
772 (nucleus_.I_ + 10 * nucleus_.A_ + 10000 * nucleus_.Z_ +
773 10000000 * nucleus_.n_Lambda_ + 1000000000);
776 int n_J_2 = digits_.n_J_;
781 return antiparticle_sign() *
782 (n_J_2 + digits_.n_q3_ * 10 + digits_.n_q2_ * 100 +
783 digits_.n_q1_ * 1000 + digits_.n_L_ * 10000 +
784 digits_.n_R_ * 100000 + digits_.n_ * 1000000 + n_J_1 * 10000000);
790 chunks_.excitation_ = 0;
806 int net_quark_number(
const int quark)
const;
810 return (is_nucleus() && !nucleus_.antiparticle_) ? nucleus_.Z_ : 0;
814 return (is_nucleus() && !nucleus_.antiparticle_)
815 ? nucleus_.A_ - nucleus_.Z_ - nucleus_.n_Lambda_
820 return (is_nucleus() && !nucleus_.antiparticle_) ? nucleus_.n_Lambda_ : 0;
824 return (is_nucleus() && nucleus_.antiparticle_) ? nucleus_.Z_ : 0;
828 return (is_nucleus() && nucleus_.antiparticle_)
829 ? nucleus_.A_ - nucleus_.Z_ - nucleus_.n_Lambda_
834 return (is_nucleus() && nucleus_.antiparticle_) ? nucleus_.n_Lambda_ : 0;
837 int nucleus_A()
const {
return is_nucleus() ? nucleus_.A_ : 0; }
851 #if defined(LITTLE_ENDIAN_ARCHITECTURE) || defined(DOXYGEN)
865 std::uint32_t
n_ : 4, : 2;
870 #elif defined(BIG_ENDIAN_ARCHITECTURE)
871 bool antiparticle_ : 1;
872 bool is_nucleus_ : 1, : 2;
873 std::uint32_t n_ : 4;
874 std::uint32_t n_R_ : 4;
875 std::uint32_t n_L_ : 4;
876 std::uint32_t n_q1_ : 4;
877 std::uint32_t n_q2_ : 4;
878 std::uint32_t n_q3_ : 4;
879 std::uint32_t n_J_ : 4;
881 #error Endianness macro of the machine not defined.
894 #if defined(LITTLE_ENDIAN_ARCHITECTURE) || defined(DOXYGEN)
900 #elif defined(BIG_ENDIAN_ARCHITECTURE)
901 std::uint32_t : 4, excitation_ : 12;
902 std::uint32_t quarks_ : 12, : 4;
904 #error Endianness macro of the machine not defined.
909 #if defined(LITTLE_ENDIAN_ARCHITECTURE) || defined(DOXYGEN)
911 std::uint32_t
Z_ : 10;
912 std::uint32_t
A_ : 10;
913 std::uint32_t
I_ : 4;
915 bool antiparticle_ : 1;
916 #elif defined(BIG_ENDIAN_ARCHITECTURE)
917 bool antiparticle_ : 1;
918 bool is_nucleus_ : 1;
919 std::uint32_t I_ : 4;
920 std::uint32_t A_ : 10;
921 std::uint32_t Z_ : 10;
922 std::uint32_t n_Lambda_ : 6;
924 #error Endianness macro of the machine not defined.
933 inline std::uint32_t
ucode()
const {
return (dump_ & 0x0fffffff); }
943 if (48 <= inp && inp <= 57) {
947 if (65 <= inp && inp <= 70) {
948 return inp - 65 + 10;
951 if (97 <= inp && inp <= 102) {
952 return inp - 97 + 10;
954 throw InvalidPdgCode(
"PdgCode: Invalid character " + std::string(&inp, 1) +
982 digits_.n_ = digits_.n_R_ = digits_.n_L_ = digits_.n_q1_ = digits_.n_q2_ =
983 digits_.n_q3_ = digits_.n_J_ = digits_.is_nucleus_ = 0;
984 size_t length = codestring.size();
991 if (codestring[c] ==
'-') {
992 digits_.antiparticle_ =
true;
994 }
else if (codestring[c] ==
'+') {
995 digits_.antiparticle_ =
false;
999 unsigned int sign = c;
1002 if (length == 10 + sign) {
1003 nucleus_.is_nucleus_ =
true;
1004 if (codestring[c] !=
'1' || codestring[c + 1] !=
'0') {
1006 "\" should start with 10\n");
1010 std::array<int, 8> digits;
1011 for (
int i = 0; i < 8; i++) {
1012 digits[i] = get_digit_from_char(codestring[c + i]);
1014 nucleus_.n_Lambda_ = digits[0];
1015 nucleus_.Z_ = 100 * digits[1] + 10 * digits[2] + digits[3];
1016 nucleus_.A_ = 100 * digits[4] + 10 * digits[5] + digits[6];
1017 nucleus_.I_ = digits[7];
1022 if (length > 8 + sign) {
1024 "\" too long for PDG Code\n");
1028 if (length > 7 + sign) {
1029 digits_.n_J_ += get_digit_from_char(codestring[c++]);
1032 if (length > 6 + sign) {
1033 digits_.n_ = get_digit_from_char(codestring[c++]);
1036 if (length > 5 + sign) {
1037 digits_.n_R_ = get_digit_from_char(codestring[c++]);
1040 if (length > 4 + sign) {
1041 digits_.n_L_ = get_digit_from_char(codestring[c++]);
1044 if (length > 3 + sign) {
1045 digits_.n_q1_ = get_digit_from_char(codestring[c++]);
1046 if (digits_.n_q1_ > 6) {
1047 throw InvalidPdgCode(
"Invalid PDG code " + codestring +
" (n_q1>6)");
1051 if (length > 2 + sign) {
1052 digits_.n_q2_ = get_digit_from_char(codestring[c++]);
1053 if (digits_.n_q2_ > 6) {
1054 throw InvalidPdgCode(
"Invalid PDG code " + codestring +
" (n_q2>6)");
1058 if (length > 1 + sign) {
1059 digits_.n_q3_ = get_digit_from_char(codestring[c++]);
1060 if (digits_.n_q3_ > 6) {
1061 throw InvalidPdgCode(
"Invalid PDG code " + codestring +
" (n_q3>6)");
1065 if (length > sign) {
1066 digits_.n_J_ += get_digit_from_char(codestring[c++]);
1069 "String \"" + codestring +
1070 "\" only consists of a sign, that is no valid PDG Code\n");
1087 bool ap = digits_.antiparticle_;
1088 dump_ = abscode & 0x0fffffff;
1089 digits_.antiparticle_ = ap;
1090 int test = test_code();
1093 " in PDG Code " +
string());
1099 static_assert(
sizeof(PdgCode) == 4,
"should fit into 32 bit integer");
1107 std::istream&
operator>>(std::istream& is, PdgCode& code);
1113 std::ostream&
operator<<(std::ostream& is,
const PdgCode& code);
1117 const auto c1 = pdg1.
code();
1118 const auto c2 = pdg2.
code();
1119 const auto min = std::min(c1, c2);
1120 const auto max = std::max(c1, c2);
1121 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