Version: SMASH-3.1
pdgcode.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2019,2021-2022
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 int PdgCode::net_quark_number(const int quark) const {
32  // input sanitization: Only quark numbers 1 through 6 are allowed.
33  if (quark < 1 || quark > 6) {
34  throw std::invalid_argument(
35  std::string("PdgCode::net_quark_number(): ") +
36  std::string("Quark number must be in [1..6], received ") +
37  std::to_string(quark));
38  }
39  if (is_nucleus()) {
40  const int Np = nucleus_.Z_;
41  const int Nn = nucleus_.A_ - nucleus_.Z_ - nucleus_.n_Lambda_;
42  const int NL = nucleus_.n_Lambda_;
43  switch (quark) {
44  case 1:
45  return (2 * Nn + Np + NL) * antiparticle_sign();
46  case 2:
47  return (Nn + 2 * Np + NL) * antiparticle_sign();
48  case 3:
49  return NL * antiparticle_sign();
50  // Charmed nuclei may exist, but they are not foreseen by PDG standard
51  default:
52  return 0.0;
53  }
54  }
55  // non-hadrons and those that have none of this quark type: 0.
56  if (!is_hadron() || (digits_.n_q1_ != quark && digits_.n_q2_ != quark &&
57  digits_.n_q3_ != quark)) {
58  return 0;
59  }
60  // baryons: count quarks.
61  if (baryon_number() != 0) {
62  // for anti-baryons, the sign changes:
63  return antiparticle_sign() *
64  ((digits_.n_q1_ == quark) + (digits_.n_q2_ == quark) +
65  (digits_.n_q3_ == quark));
66  }
67 
68  // mesons.
69 
70  // quarkonium state? Not open net_quark_number.
71  if (digits_.n_q3_ == quark && digits_.n_q2_ == quark) {
72  return 0;
73  }
74  /* this has covered all the easy stuff
75  * get the "other" quark. (We know this must exist, since they are
76  * not both the right one and one of them is the right one). */
77  int otherquark = (digits_.n_q2_ == quark) ? digits_.n_q3_ : digits_.n_q2_;
78  /* "our" quark is the heavier one: 1 for u,c,t; -1 for d,s,b (and of
79  * course the antiparticle sign) */
80  if (quark > otherquark) {
81  return ((quark % 2 == 0) ? 1 : -1) * antiparticle_sign();
82  }
83  /* ours is the lighter: If the heavier particle is u,c,t, the lighter
84  * one (ours) is an antiquark. */
85  return ((otherquark % 2 == 0) ? -1 : 1) * antiparticle_sign();
86 }
87 
88 std::ostream& operator<<(std::ostream& s, const PdgCode& code) {
89  return s << code.string();
90 }
91 
93  int valence_quarks_required) const {
94  if (is_meson()) {
95  return valence_quarks_required == 1 || valence_quarks_required == -1;
96  }
97  if (is_baryon()) {
98  if (baryon_number() == 1) {
99  return valence_quarks_required == 1 || valence_quarks_required == 2;
100  }
101  if (baryon_number() == -1) {
102  return valence_quarks_required == -1 || valence_quarks_required == -2;
103  }
104  }
105  throw std::runtime_error("String fragment is neither baryon nor meson");
106 }
107 } // namespace smash
PdgCode stores a Particle Data Group Particle Numbering Scheme particle type number.
Definition: pdgcode.h:111
int antiparticle_sign() const
Definition: pdgcode.h:651
int baryon_number() const
Definition: pdgcode.h:381
bool is_meson() const
Definition: pdgcode.h:394
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:31
bool is_nucleus() const
Definition: pdgcode.h:364
struct smash::PdgCode::@0::@2 digits_
The single digits collection of the code.
bool is_baryon() const
Definition: pdgcode.h:391
std::string string() const
Definition: pdgcode.h:325
bool is_hadron() const
Definition: pdgcode.h:370
static PdgCode invalid()
PdgCode 0x0 is guaranteed not to be valid by the PDG standard, but it passes all tests here,...
Definition: pdgcode.h:758
bool contains_enough_valence_quarks(int valence_quarks_required) const
Definition: pdgcode.cc:92
void set_from_string(const std::string &codestring)
Set the PDG code from the given string.
Definition: pdgcode.h:980
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:547
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
thrown for invalid inputs
Definition: pdgcode.h:117