Version: SMASH-3.4
pdgcode.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2019,2021-2022,2026
3  * SMASH Team
4  *
5  * GNU General Public License (GPLv3 or later)
6  */
7 
8 #include "smash/pdgcode.h"
9 
10 #include <istream>
11 
12 namespace smash {
13 
14 std::istream& operator>>(std::istream& is, PdgCode& code) {
15  std::string codestring("");
16  is >> codestring;
17  if (!is) {
18  code = PdgCode::invalid();
19  return is;
20  }
21  try {
22  // set the fields from the string:
23  code.set_from_string(codestring);
24  } catch (PdgCode::InvalidPdgCode&) {
25  is.setstate(std::ios::failbit);
26  code = PdgCode::invalid();
27  }
28  return is;
29 }
30 
31 bool PdgCode::contains_quark(int signedQuark) const {
32  if (!is_hadron())
33  return false;
34 
35  const int absQuark = std::abs(signedQuark);
36  if (absQuark < 1 || absQuark > 6)
37  return false;
38 
39  const int pdgId = get_decimal();
40  const int absPdgId = std::abs(pdgId);
41 
42  if (absPdgId == 111 || absPdgId == 113 || absPdgId == 223) {
43  return (absQuark == 1 || absQuark == 2);
44  }
45  if (absPdgId == 221 || absPdgId == 331) {
46  return (absQuark == 1 || absQuark == 2 || absQuark == 3);
47  }
48 
49  const int netFlavor = net_quark_number(absQuark);
50  if (netFlavor != 0) {
51  return signedQuark > 0 ? (netFlavor > 0) : (netFlavor < 0);
52  }
53 
54  if (baryon_number() != 0)
55  return false;
56 
57  const int flavorDigit1 = digits_.n_q2_;
58  const int flavorDigit2 = digits_.n_q3_;
59  return (absQuark == flavorDigit1 || absQuark == flavorDigit2);
60 }
61 
62 int PdgCode::net_quark_number(const int quark) const {
63  // input sanitization: Only quark numbers 1 through 6 are allowed.
64  if (quark < 1 || quark > 6) {
65  throw std::invalid_argument(
66  std::string("PdgCode::net_quark_number(): ") +
67  std::string("Quark number must be in [1..6], received ") +
68  std::to_string(quark));
69  }
70  if (is_nucleus()) {
71  const int Np = nucleus_.Z_;
72  const int Nn = nucleus_.A_ - nucleus_.Z_ - nucleus_.n_Lambda_;
73  const int NL = nucleus_.n_Lambda_;
74  switch (quark) {
75  case 1:
76  return (2 * Nn + Np + NL) * antiparticle_sign();
77  case 2:
78  return (Nn + 2 * Np + NL) * antiparticle_sign();
79  case 3:
80  return NL * antiparticle_sign();
81  // Charmed nuclei may exist, but they are not foreseen by PDG standard
82  default:
83  return 0.0;
84  }
85  }
86  // non-hadrons and those that have none of this quark type: 0.
87  if (!is_hadron() || (digits_.n_q1_ != quark && digits_.n_q2_ != quark &&
88  digits_.n_q3_ != quark)) {
89  return 0;
90  }
91  // baryons: count quarks.
92  if (baryon_number() != 0) {
93  // for anti-baryons, the sign changes:
94  return antiparticle_sign() *
95  ((digits_.n_q1_ == quark) + (digits_.n_q2_ == quark) +
96  (digits_.n_q3_ == quark));
97  }
98 
99  // mesons.
100 
101  // quarkonium state? Not open net_quark_number.
102  if (digits_.n_q3_ == quark && digits_.n_q2_ == quark) {
103  return 0;
104  }
105  /* this has covered all the easy stuff
106  * get the "other" quark. (We know this must exist, since they are
107  * not both the right one and one of them is the right one). */
108  int otherquark = (digits_.n_q2_ == quark) ? digits_.n_q3_ : digits_.n_q2_;
109  /* "our" quark is the heavier one: 1 for u,c,t; -1 for d,s,b (and of
110  * course the antiparticle sign) */
111  if (quark > otherquark) {
112  return ((quark % 2 == 0) ? 1 : -1) * antiparticle_sign();
113  }
114  /* ours is the lighter: If the heavier particle is u,c,t, the lighter
115  * one (ours) is an antiquark. */
116  return ((otherquark % 2 == 0) ? -1 : 1) * antiparticle_sign();
117 }
118 
119 std::ostream& operator<<(std::ostream& s, const PdgCode& code) {
120  return s << code.string();
121 }
122 
124  int valence_quarks_required) const {
125  if (is_meson()) {
126  return valence_quarks_required == 1 || valence_quarks_required == -1;
127  }
128  if (is_baryon()) {
129  if (baryon_number() == 1) {
130  return valence_quarks_required == 1 || valence_quarks_required == 2;
131  }
132  if (baryon_number() == -1) {
133  return valence_quarks_required == -1 || valence_quarks_required == -2;
134  }
135  }
136  throw std::runtime_error("String fragment is neither baryon nor meson");
137 }
138 } // namespace smash
PdgCode stores a Particle Data Group Particle Numbering Scheme particle type number.
Definition: pdgcode.h:108
int antiparticle_sign() const
Definition: pdgcode.h:734
int baryon_number() const
Definition: pdgcode.h:388
bool is_meson() const
Definition: pdgcode.h:401
int net_quark_number(const int quark) const
Returns the net number of quarks with given flavour number For public use, see strangeness(),...
Definition: pdgcode.cc:62
bool is_nucleus() const
Definition: pdgcode.h:361
struct smash::PdgCode::@0::@2 digits_
The single digits collection of the code.
int32_t get_decimal() const
Definition: pdgcode.h:852
bool is_baryon() const
Definition: pdgcode.h:398
std::string string() const
Definition: pdgcode.h:322
bool is_hadron() const
Definition: pdgcode.h:367
static PdgCode invalid()
PdgCode 0x0 is guaranteed not to be valid by the PDG standard, but it passes all tests here,...
Definition: pdgcode.h:841
bool contains_enough_valence_quarks(int valence_quarks_required) const
Definition: pdgcode.cc:123
void set_from_string(const std::string &codestring)
Set the PDG code from the given string.
Definition: pdgcode.h:1085
bool contains_quark(int quark) const
Checks whether this hadron contains a quark (or antiquark) of a given flavour.
Definition: pdgcode.cc:31
struct smash::PdgCode::@0::@4 nucleus_
Structure for the nuclei.
std::ostream & operator<<(std::ostream &out, const ActionPtr &action)
Convenience: dereferences the ActionPtr to Action.
Definition: action.h:546
Definition: action.h:24
std::istream & operator>>(std::istream &is, PdgCode &code)
Sets the PDG code from the textual representation in the input stream.
Definition: pdgcode.cc:14
std::string to_string(ThermodynamicQuantity quantity)
Convert a ThermodynamicQuantity enum value to its corresponding string.
Definition: stringify.cc:26
thrown for invalid inputs
Definition: pdgcode.h:114