Version: SMASH-1.5
smash::PdgCode Class Reference

#include <pdgcode.h>

PdgCode stores a Particle Data Group Particle Numbering Scheme particle type number.

See also
http://pdg.lbl.gov/2014/reviews/rpp2014-rev-monte-carlo-numbering.pdf

Usage:

#include "include/pdgcode.h"
// initialize with an integer: make sure it is hex-encoded!
PdgCode pi_plus(0x211);
// you can also initialize from a string:
PdgCode pi_minus("-211");
// initialize a PDG Code that knows it is not set yet:
PdgCode other_particle();
// this is true:
if (other_particle == PdgCode::invalid()) {
printf("Invalid particle! Please enter PDG Code: ");
// fill from stringstream:
std::cin >> other_particle;
}
// is this a Kaon?
if (other_particle.code() == 0x311) {
printf("The particle is a K plus\n");
}
// what baryon number does the particle have?
printf("The particle has a baryon number of %d\n",
other_particle.baryon_number());

This class contains a collection of smart accessors to the PDG code so that quantum numbers etc can easily be read off.

Internals

The content is stored in hexadecimal digits, i.e., the number '545' is interpreted as '0x221', i.e., an eta-meson. To check if a given particle is of a given type, make sure that you give the type in hex digits as well (see example above).

The reason for that is that the concept of PdgCodes, especially for Hadrons, is not one of wholesale numbers, but one of concatenated digits. Using hexadecimally interpreted digits makes it numerically very easy to access the separate digits (there's no arithmetic involved with successive divisions by 10 and taking the remainder etc.).

Representing nuclei

Following PDG standard, nuclei are represented by codes ±10LZZZAAAI, where L is number of Lambdas inside the nucleus, ZZZ is charge, AAA is mass number and I is used for excitations. Internally nuclei are represented in a different way from hadrons, but all accessors (charge, baryon number, etc) work in the same way.

Normally nuclei in SMASH are simulated as a collection of protons and neutrons, so there is no need in their PDG codes. However, it is interesting to study light nuclei production, considering them as single pointlike hadrons. This justifies introduction of nuclear PDG codes here.

Limitations:

The code is tuned to non-colored objects at the moment. That means that colored objects (Diquarks and Quarks) are not easily useable with this class; the behaviour of functions baryon_number, charge, is_hadron etc. is undefined. (This is mostly because these things are not well-defined, and/or because the charge and baryon number is not an integer anymore.)

Also, tetra- and pentaquarks cannot be represented; that, though, is a problem of the PDG Numbering Scheme rather than of this class.

Definition at line 108 of file pdgcode.h.

Collaboration diagram for smash::PdgCode:
[legend]

Classes

struct  InvalidPdgCode
 thrown for invalid inputs More...
 

Public Member Functions

 PdgCode ()
 Standard initializer. More...
 
 PdgCode (const std::string &codestring)
 Initialize using a string The string is interpreted as a hexadecimal number, i.e., 211 is interpreted as 0x211 = \(529_{10}\). More...
 
 PdgCode (std::int32_t codenumber)
 Receive a signed integer and process it into a PDG Code. More...
 
 PdgCode (const std::uint32_t abscode)
 receive an unsigned integer and process it into a PDG Code. More...
 
int test_code () const
 Checks the integer for invalid hex digits. More...
 
void check () const
 Do all sorts of validity checks. More...
 
std::uint32_t dump () const
 Dumps the bitfield into an unsigned integer. More...
 
std::int32_t code () const
 
std::string string () const
 
PdgCode get_antiparticle () const
 Construct the antiparticle to a given PDG code. More...
 
bool is_nucleus () const
 
bool is_hadron () const
 
bool is_lepton () const
 
int baryon_number () const
 
bool is_baryon () const
 
bool is_meson () const
 
bool is_nucleon () const
 
bool is_Nstar1535 () const
 
bool is_Delta () const
 
bool is_hyperon () const
 
bool is_Omega () const
 
bool is_Xi () const
 
bool is_Lambda () const
 
bool is_Sigma () const
 
bool is_kaon () const
 
bool is_pion () const
 
bool is_rho () const
 
bool is_deuteron () const
 
bool has_antiparticle () const
 
int isospin3 () const
 
double frac_strange () const
 
int strangeness () const
 
int charmness () const
 
int bottomness () const
 
int charge () const
 The charge of the particle. More...
 
unsigned int spin () const
 
unsigned int spin_degeneracy () const
 
int antiparticle_sign () const
 
std::int32_t quarks () const
 
std::array< int, 3 > quark_content () const
 The return is always an array of three numbers, which are pdgcodes of quarks: 1 - d, 2 - u, 3 - s, 4 - c, 5 - b. More...
 
bool contains_enough_valence_quarks (int valence_quarks_required) const
 
bool operator< (const PdgCode rhs) const
 Sorts PDG Codes according to their numeric value. More...
 
bool operator== (const PdgCode rhs) const
 
bool operator!= (const PdgCode rhs) const
 
bool is_antiparticle_of (const PdgCode rhs) const
 
int get_decimal () const
 
void deexcite ()
 Remove all excitation, except spin. Sign and quark content remains. More...
 
int net_quark_number (const int quark) const
 Returns the net number of quarks with given flavour number For public use, see strangeness(), charmness(), bottomness() and isospin3(). More...
 

Static Public Member Functions

static PdgCode from_decimal (const int pdgcode_decimal)
 Construct PDG code from decimal number. More...
 
static PdgCode invalid ()
 PdgCode 0x0 is guaranteed not to be valid by the PDG standard, but it passes all tests here, so we can use it to show some code is not yet set. More...
 

Private Member Functions

std::uint32_t ucode () const
 
std::uint32_t get_digit_from_char (const char inp) const
 
void set_from_string (const std::string &codestring)
 Set the PDG code from the given string. More...
 
void set_fields (std::uint32_t abscode)
 Sets the bitfield from an unsigned integer. More...
 

Private Attributes

union {
   struct {
      std::uint32_t   n_J_: 4
 spin quantum number \(n_J = 2 J + 1\). More...
 
      std::uint32_t   n_q3_: 4
 third quark field More...
 
      std::uint32_t   n_q2_: 4
 second quark field More...
 
      std::uint32_t   n_q1_: 4
 first quark field. 0 for mesons. More...
 
      std::uint32_t   n_L_: 4
 "angular momentum" More...
 
      std::uint32_t   n_R_: 4
 "radial excitation" More...
 
      std::uint32_t   n_: 4
 first field: "counter" More...
 
      std::uint32_t bool   is_nucleus_: 2: 1
 1 for nuclei, 0 for the rest More...
 
      bool   antiparticle_: 1
 first bit: stores the sign. More...
 
   }   digits_
 The single digits collection of the code. More...
 
   std::uint32_t   dump_
 The bitfield dumped into a single integer. More...
 
   struct {
      std::uint32_t   __pad0__: 4
 
      std::uint32_t   quarks_: 12
 The quark digits n_q{1,2,3}_. More...
 
      std::uint32_t   excitation_: 12
 The excitation digits n_, n_R_, n_L_. More...
 
   }   chunks_
 Chunk collection: here, the chunks with \(nn_Rn_L\) and \(n_{q_1}n_{q_2}n_{q_3}\) are directly accessible. More...
 
   struct {
      std::uint32_t   n_Lambda_: 6
 
      std::uint32_t   Z_: 10
 
      std::uint32_t   A_: 10
 
      std::uint32_t   I_: 4
 
      bool   is_nucleus_: 1
 
      bool   antiparticle_: 1
 
   }   nucleus_
 Structure for the nuclei. More...
 
}; 
 The union holds the data; either as a single integer dump_, as a single-digit bitfield digits_ or as a multiple-digits bitfield chunks_. More...
 

Friends

std::istream & operator>> (std::istream &is, PdgCode &code)
 istream >> PdgCode assigns the PDG Code from an istream. More...
 

Constructor & Destructor Documentation

◆ PdgCode() [1/4]

smash::PdgCode::PdgCode ( )
inline

Standard initializer.

Definition at line 125 of file pdgcode.h.

125 : dump_(0x0) {}
std::uint32_t dump_
The bitfield dumped into a single integer.
Definition: pdgcode.h:756
Here is the caller graph for this function:

◆ PdgCode() [2/4]

smash::PdgCode::PdgCode ( const std::string &  codestring)
inlineexplicit

Initialize using a string The string is interpreted as a hexadecimal number, i.e., 211 is interpreted as 0x211 = \(529_{10}\).

Definition at line 131 of file pdgcode.h.

131  {
132  set_from_string(codestring);
133  }
void set_from_string(const std::string &codestring)
Set the PDG code from the given string.
Definition: pdgcode.h:843
Here is the call graph for this function:

◆ PdgCode() [3/4]

smash::PdgCode::PdgCode ( std::int32_t  codenumber)
inline

Receive a signed integer and process it into a PDG Code.

The sign is taken as antiparticle boolean, while the absolute value of the integer is used as hexdigits.

Parameters
[in]codenumbera signed integer which represent the PDG code The number 0x221 is interpreted as an η meson, -0x211 is a "charged pi antiparticle", i.e., a \(\pi^-\).

Definition at line 143 of file pdgcode.h.

143  : dump_(0x0) { // NOLINT(runtime/explicit)
144  digits_.antiparticle_ = false;
145  if (codenumber < 0) {
146  digits_.antiparticle_ = true;
147  codenumber = -codenumber;
148  }
149  set_fields(codenumber);
150  }
void set_fields(std::uint32_t abscode)
Sets the bitfield from an unsigned integer.
Definition: pdgcode.h:948
struct smash::PdgCode::@0::@2 digits_
The single digits collection of the code.
std::uint32_t dump_
The bitfield dumped into a single integer.
Definition: pdgcode.h:756
Here is the call graph for this function:

◆ PdgCode() [4/4]

smash::PdgCode::PdgCode ( const std::uint32_t  abscode)
inlineexplicit

receive an unsigned integer and process it into a PDG Code.

The first bit is taken and used as antiparticle boolean.

Definition at line 155 of file pdgcode.h.

155  : dump_(0x0) {
156  // use the first bit for the antiparticle_ boolean.
157  digits_.antiparticle_ = ((abscode & 0x80000000u) != 0);
158  set_fields(abscode);
159  }
void set_fields(std::uint32_t abscode)
Sets the bitfield from an unsigned integer.
Definition: pdgcode.h:948
struct smash::PdgCode::@0::@2 digits_
The single digits collection of the code.
std::uint32_t dump_
The bitfield dumped into a single integer.
Definition: pdgcode.h:756
Here is the call graph for this function:

Member Function Documentation

◆ test_code()

int smash::PdgCode::test_code ( ) const
inline

Checks the integer for invalid hex digits.

Usually all digits are at least <= 9. The n_q digits are even <= 6 (because there are only six quarks). The only exception is n_J, where we allow f = 15, which is the largest hexadecimal digit. If one of the hex digits is not also a valid decimal digit, something possibly went wrong - maybe some user of this class forgot to prefix the input with '0x' and thus passed 221 instead of 0x221.

Returns
a bitmask indicating the offending digits. In the above example, 221 = 0xd3, the second-to-last-digit is the offending one, to the return value is 0b10 = 0x2 = 2.

Definition at line 180 of file pdgcode.h.

180  {
181  int fail = 0;
182  if (digits_.n_ > 9) {
183  fail |= 1 << 6;
184  }
185  if (digits_.n_R_ > 9) {
186  fail |= 1 << 5;
187  }
188  if (digits_.n_L_ > 9) {
189  fail |= 1 << 4;
190  }
191  if (digits_.n_q1_ > 6) {
192  fail |= 1 << 3;
193  }
194  if (digits_.n_q2_ > 6) {
195  fail |= 1 << 2;
196  }
197  if (digits_.n_q3_ > 6) {
198  fail |= 1 << 1;
199  }
200  if (digits_.n_J_ > 15) {
201  fail |= 1;
202  }
203  return fail;
204  }
struct smash::PdgCode::@0::@2 digits_
The single digits collection of the code.
Here is the caller graph for this function:

◆ check()

void smash::PdgCode::check ( ) const
inline

Do all sorts of validity checks.

Exceptions
InvalidPdgCodeif meson has even n_J_ (fermionic spin)
InvalidPdgCodeif baryon has odd n_J_ (bosonic spin)
InvalidPdgCodeif n_J_ is 0 (spin is not defined.)
InvalidPdgCodeif particle does not have antiparticle when it is supposed to do.

Definition at line 214 of file pdgcode.h.

214  {
215  // n_J must be odd for mesons and even for baryons (and cannot be zero)
216  if (is_hadron()) {
217  if (baryon_number() == 0) {
218  // mesons: special cases K0_L=0x130 and K0_S=0x310
219  if ((digits_.n_J_ % 2 == 0) && dump() != 0x130 && dump() != 0x310) {
220  throw InvalidPdgCode("Invalid PDG code " + string() +
221  " (meson with even n_J)");
222  }
223  } else {
224  if ((digits_.n_J_ % 2 != 0) || digits_.n_J_ == 0) {
225  throw InvalidPdgCode("Invalid PDG code " + string() +
226  " (baryon with odd n_J)");
227  }
228  }
229  } else {
230  if (digits_.n_J_ == 0 && dump() != 0x0) {
231  throw InvalidPdgCode("Invalid PDG code " + string() + " (n_J==0)");
232  }
233  }
234  /* The antiparticle flag only makes sense for particle types
235  * that have an antiparticle. */
236  if (digits_.antiparticle_ && !has_antiparticle()) {
237  throw InvalidPdgCode("Invalid PDG code " + string() +
238  " (cannot be negative)");
239  }
240  }
std::uint32_t dump() const
Dumps the bitfield into an unsigned integer.
Definition: pdgcode.h:243
struct smash::PdgCode::@0::@2 digits_
The single digits collection of the code.
bool has_antiparticle() const
Definition: pdgcode.h:393
int baryon_number() const
Definition: pdgcode.h:308
bool is_hadron() const
Definition: pdgcode.h:297
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dump()

std::uint32_t smash::PdgCode::dump ( ) const
inline

Dumps the bitfield into an unsigned integer.

Definition at line 243 of file pdgcode.h.

243  {
244  // this cuts the three unused bits.
245  return (dump_ & 0x8fffffff);
246  }
std::uint32_t dump_
The bitfield dumped into a single integer.
Definition: pdgcode.h:756
Here is the caller graph for this function:

◆ code()

std::int32_t smash::PdgCode::code ( ) const
inline
Returns
a signed integer with the PDG code in hexadecimal.

Definition at line 249 of file pdgcode.h.

249 { return antiparticle_sign() * ucode(); }
int antiparticle_sign() const
Definition: pdgcode.h:537
std::uint32_t ucode() const
Definition: pdgcode.h:797
Here is the call graph for this function:
Here is the caller graph for this function:

◆ string()

std::string smash::PdgCode::string ( ) const
inline
Returns
the PDG Code as a decimal string.

Definition at line 252 of file pdgcode.h.

252  {
253  std::stringstream ss;
254  ss << get_decimal();
255  return ss.str();
256  }
int get_decimal() const
Definition: pdgcode.h:655
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_antiparticle()

PdgCode smash::PdgCode::get_antiparticle ( ) const
inline

Construct the antiparticle to a given PDG code.

Definition at line 259 of file pdgcode.h.

259  {
260  PdgCode result = *this;
261  result.digits_.antiparticle_ = !digits_.antiparticle_;
262  return result;
263  }
struct smash::PdgCode::@0::@2 digits_
The single digits collection of the code.
PdgCode()
Standard initializer.
Definition: pdgcode.h:125
Here is the caller graph for this function:

◆ from_decimal()

static PdgCode smash::PdgCode::from_decimal ( const int  pdgcode_decimal)
inlinestatic

Construct PDG code from decimal number.

Parameters
[in]pdgcode_decimaldecimal integer representing the PDG code

Definition at line 269 of file pdgcode.h.

269  {
270  // Nucleus and special codes with 2J+1 > 9
271  if (std::abs(pdgcode_decimal) > 1E7) {
272  return PdgCode(std::to_string(pdgcode_decimal));
273  }
274  int a = pdgcode_decimal;
275  int hex_pdg = 0, tmp = 1;
276  while (a) {
277  hex_pdg += (a % 10) * tmp;
278  tmp *= 16;
279  a = a / 10;
280  }
281  return PdgCode(hex_pdg);
282  }
PdgCode()
Standard initializer.
Definition: pdgcode.h:125
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_nucleus()

bool smash::PdgCode::is_nucleus ( ) const
inline
Returns
true if this is a nucleus, false otherwise

Definition at line 291 of file pdgcode.h.

291  {
292  assert(digits_.is_nucleus_ == nucleus_.is_nucleus_);
293  return nucleus_.is_nucleus_;
294  }
struct smash::PdgCode::@0::@4 nucleus_
Structure for the nuclei.
struct smash::PdgCode::@0::@2 digits_
The single digits collection of the code.
Here is the caller graph for this function:

◆ is_hadron()

bool smash::PdgCode::is_hadron ( ) const
inline
Returns
true if this is a baryon, antibaryon or meson.

Definition at line 297 of file pdgcode.h.

297  {
298  return (digits_.n_q3_ != 0 && digits_.n_q2_ != 0 && !is_nucleus());
299  }
bool is_nucleus() const
Definition: pdgcode.h:291
struct smash::PdgCode::@0::@2 digits_
The single digits collection of the code.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_lepton()

bool smash::PdgCode::is_lepton ( ) const
inline
Returns
true if this is a lepton.

Definition at line 302 of file pdgcode.h.

302  {
303  return (digits_.n_q1_ == 0 && digits_.n_q2_ == 0 && digits_.n_q3_ == 1 &&
304  !is_nucleus());
305  }
bool is_nucleus() const
Definition: pdgcode.h:291
struct smash::PdgCode::@0::@2 digits_
The single digits collection of the code.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ baryon_number()

int smash::PdgCode::baryon_number ( ) const
inline
Returns
the baryon number of the particle.

Definition at line 308 of file pdgcode.h.

308  {
309  if (is_nucleus()) {
310  return static_cast<int>(nucleus_.A_) * antiparticle_sign();
311  }
312  if (!is_hadron() || digits_.n_q1_ == 0) {
313  return 0;
314  }
315  return antiparticle_sign();
316  }
int antiparticle_sign() const
Definition: pdgcode.h:537
struct smash::PdgCode::@0::@4 nucleus_
Structure for the nuclei.
bool is_nucleus() const
Definition: pdgcode.h:291
struct smash::PdgCode::@0::@2 digits_
The single digits collection of the code.
bool is_hadron() const
Definition: pdgcode.h:297
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_baryon()

bool smash::PdgCode::is_baryon ( ) const
inline
Returns
whether this PDG code identifies a baryon.

Definition at line 318 of file pdgcode.h.

318 { return is_hadron() && digits_.n_q1_ != 0; }
struct smash::PdgCode::@0::@2 digits_
The single digits collection of the code.
bool is_hadron() const
Definition: pdgcode.h:297
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_meson()

bool smash::PdgCode::is_meson ( ) const
inline
Returns
whether this PDG code identifies a meson.

Definition at line 321 of file pdgcode.h.

321 { return is_hadron() && digits_.n_q1_ == 0; }
struct smash::PdgCode::@0::@2 digits_
The single digits collection of the code.
bool is_hadron() const
Definition: pdgcode.h:297
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_nucleon()

bool smash::PdgCode::is_nucleon ( ) const
inline
Returns
whether this is a nucleon/anti-nucleon (p, n, -p, -n)

Definition at line 324 of file pdgcode.h.

324  {
325  const auto abs_code = std::abs(code());
326  return (abs_code == pdg::p || abs_code == pdg::n);
327  }
constexpr int p
Proton.
constexpr int n
Neutron.
std::int32_t code() const
Definition: pdgcode.h:249
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_Nstar1535()

bool smash::PdgCode::is_Nstar1535 ( ) const
inline
Returns
whether this is a N*(1535) (+/0)

Definition at line 330 of file pdgcode.h.

330  {
331  const auto abs_code = std::abs(code());
332  return (abs_code == pdg::N1535_p || abs_code == pdg::N1535_z);
333  }
constexpr int N1535_p
N(1535)⁺.
constexpr int N1535_z
N(1535)⁰.
std::int32_t code() const
Definition: pdgcode.h:249
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_Delta()

bool smash::PdgCode::is_Delta ( ) const
inline
Returns
whether this is a Delta(1232) (with anti-delta)

Definition at line 336 of file pdgcode.h.

336  {
337  const auto abs_code = std::abs(code());
338  return (abs_code == pdg::Delta_pp || abs_code == pdg::Delta_p ||
339  abs_code == pdg::Delta_z || abs_code == pdg::Delta_m);
340  }
constexpr int Delta_m
Δ⁻.
constexpr int Delta_z
Δ⁰.
constexpr int Delta_p
Δ⁺.
constexpr int Delta_pp
Δ⁺⁺.
std::int32_t code() const
Definition: pdgcode.h:249
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_hyperon()

bool smash::PdgCode::is_hyperon ( ) const
inline
Returns
whether this is a hyperon (Lambda, Sigma, Xi, Omega)

Definition at line 343 of file pdgcode.h.

343 { return is_hadron() && digits_.n_q1_ == 3; }
struct smash::PdgCode::@0::@2 digits_
The single digits collection of the code.
bool is_hadron() const
Definition: pdgcode.h:297
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_Omega()

bool smash::PdgCode::is_Omega ( ) const
inline
Returns
whether this is a Omega baryon

Definition at line 346 of file pdgcode.h.

346  {
347  return is_hyperon() && digits_.n_q2_ == 3 && digits_.n_q3_ == 3;
348  }
bool is_hyperon() const
Definition: pdgcode.h:343
struct smash::PdgCode::@0::@2 digits_
The single digits collection of the code.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_Xi()

bool smash::PdgCode::is_Xi ( ) const
inline
Returns
whether this is a Xi baryon

Definition at line 351 of file pdgcode.h.

351  {
352  return is_hyperon() && digits_.n_q2_ == 3 && digits_.n_q3_ != 3;
353  }
bool is_hyperon() const
Definition: pdgcode.h:343
struct smash::PdgCode::@0::@2 digits_
The single digits collection of the code.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_Lambda()

bool smash::PdgCode::is_Lambda ( ) const
inline
Returns
whether this is a Lambda baryon

Definition at line 356 of file pdgcode.h.

356  {
357  return is_hyperon() && digits_.n_q2_ == 1 && digits_.n_q3_ == 2;
358  }
bool is_hyperon() const
Definition: pdgcode.h:343
struct smash::PdgCode::@0::@2 digits_
The single digits collection of the code.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_Sigma()

bool smash::PdgCode::is_Sigma ( ) const
inline
Returns
whether this is a Sigma baryon

Definition at line 361 of file pdgcode.h.

361  {
362  return is_hyperon() && digits_.n_q2_ != 3 && !is_Lambda();
363  }
bool is_hyperon() const
Definition: pdgcode.h:343
struct smash::PdgCode::@0::@2 digits_
The single digits collection of the code.
bool is_Lambda() const
Definition: pdgcode.h:356
Here is the call graph for this function:

◆ is_kaon()

bool smash::PdgCode::is_kaon ( ) const
inline
Returns
whether this is a kaon (K+, K-, K0, Kbar0)

Definition at line 366 of file pdgcode.h.

366  {
367  const auto abs_code = std::abs(code());
368  return (abs_code == pdg::K_p) || (abs_code == pdg::K_z);
369  }
constexpr int K_p
K⁺.
constexpr int K_z
K⁰.
std::int32_t code() const
Definition: pdgcode.h:249
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_pion()

bool smash::PdgCode::is_pion ( ) const
inline
Returns
whether this is a pion (pi+/pi0/pi-)

Definition at line 372 of file pdgcode.h.

372  {
373  const auto c = code();
374  return (c == pdg::pi_z) || (c == pdg::pi_p) || (c == pdg::pi_m);
375  }
constexpr int pi_z
π⁰.
constexpr int pi_p
π⁺.
constexpr int pi_m
π⁻.
std::int32_t code() const
Definition: pdgcode.h:249
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_rho()

bool smash::PdgCode::is_rho ( ) const
inline
Returns
whether this is a rho meson (rho+/rho0/rho-)

Definition at line 378 of file pdgcode.h.

378  {
379  const auto c = code();
380  return (c == pdg::rho_z) || (c == pdg::rho_p) || (c == pdg::rho_m);
381  }
constexpr int rho_z
ρ⁰.
constexpr int rho_p
ρ⁺.
constexpr int rho_m
ρ⁻.
std::int32_t code() const
Definition: pdgcode.h:249
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_deuteron()

bool smash::PdgCode::is_deuteron ( ) const
inline
Returns
whether this is (anti-)deuteron

Definition at line 384 of file pdgcode.h.

384  {
385  const int dec = get_decimal();
386  return is_nucleus() && (dec == pdg::decimal_d || dec == pdg::decimal_antid);
387  }
int get_decimal() const
Definition: pdgcode.h:655
bool is_nucleus() const
Definition: pdgcode.h:291
constexpr int decimal_d
Deuteron in decimal digits.
constexpr int decimal_antid
Anti-deuteron in decimal digits.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ has_antiparticle()

bool smash::PdgCode::has_antiparticle ( ) const
inline
Returns
whether a particle has a distinct antiparticle (or whether it is its own antiparticle).

Definition at line 393 of file pdgcode.h.

393  {
394  if (is_nucleus()) {
395  return true;
396  }
397  if (is_hadron()) {
398  return (baryon_number() != 0) || (digits_.n_q2_ != digits_.n_q3_);
399  } else {
400  return digits_.n_q3_ == 1; // leptons!
401  }
402  }
bool is_nucleus() const
Definition: pdgcode.h:291
struct smash::PdgCode::@0::@2 digits_
The single digits collection of the code.
int baryon_number() const
Definition: pdgcode.h:308
bool is_hadron() const
Definition: pdgcode.h:297
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isospin3()

int smash::PdgCode::isospin3 ( ) const
inline
Returns
twice the isospin-3 component \(I_3\).

This is calculated from the sum of net_quark_number of up and down.

Definition at line 409 of file pdgcode.h.

409  {
410  /* net_quark_number(2) is the number of u quarks,
411  * net_quark_number(1) is the number of d quarks. */
412  return net_quark_number(2) - net_quark_number(1);
413  }
int net_quark_number(const int quark) const
Returns the net number of quarks with given flavour number For public use, see strangeness(), charmness(), bottomness() and isospin3().
Definition: pdgcode.cc:31
Here is the call graph for this function:

◆ frac_strange()

double smash::PdgCode::frac_strange ( ) const
inline
Returns
the fraction number of strange quarks (strange + anti-strange) / total

This is useful for the AQM cross-section scaling, and needs to be positive definite.

Definition at line 422 of file pdgcode.h.

422  {
423  /* The quarkonium state has 0 net strangeness
424  * but there are actually 2 strange quarks out of 2 total */
425  if (is_hadron() && digits_.n_q3_ == 3 && digits_.n_q2_ == 3) {
426  return 1.;
427  } else {
428  // For all other cases, there isn't both a strange and anti-strange
429  if (is_baryon()) {
430  return abs(strangeness()) / 3.;
431  } else if (is_meson()) {
432  return abs(strangeness()) / 2.;
433  } else {
434  /* If not baryon or meson, this should be 0, as AQM does not
435  * extend to non-hadrons */
436  return 0.;
437  }
438  }
439  }
struct smash::PdgCode::@0::@2 digits_
The single digits collection of the code.
int strangeness() const
Definition: pdgcode.h:446
bool is_baryon() const
Definition: pdgcode.h:318
bool is_meson() const
Definition: pdgcode.h:321
bool is_hadron() const
Definition: pdgcode.h:297
Here is the call graph for this function:
Here is the caller graph for this function:

◆ strangeness()

int smash::PdgCode::strangeness ( ) const
inline
Returns
the net number of \(\bar s\) quarks.

For particles with one strange quark, -1 is returned.

Definition at line 446 of file pdgcode.h.

446 { return -net_quark_number(3); }
int net_quark_number(const int quark) const
Returns the net number of quarks with given flavour number For public use, see strangeness(), charmness(), bottomness() and isospin3().
Definition: pdgcode.cc:31
Here is the call graph for this function:
Here is the caller graph for this function:

◆ charmness()

int smash::PdgCode::charmness ( ) const
inline
Returns
the net number of \(c\) quarks

For particles with one charm quark, +1 is returned.

Definition at line 453 of file pdgcode.h.

453 { return +net_quark_number(4); }
int net_quark_number(const int quark) const
Returns the net number of quarks with given flavour number For public use, see strangeness(), charmness(), bottomness() and isospin3().
Definition: pdgcode.cc:31
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bottomness()

int smash::PdgCode::bottomness ( ) const
inline
Returns
the net number of \(\bar b\) quarks

For particles with one bottom quark, -1 is returned.

Definition at line 460 of file pdgcode.h.

460 { return -net_quark_number(5); }
int net_quark_number(const int quark) const
Returns the net number of quarks with given flavour number For public use, see strangeness(), charmness(), bottomness() and isospin3().
Definition: pdgcode.cc:31
Here is the call graph for this function:

◆ charge()

int smash::PdgCode::charge ( ) const
inline

The charge of the particle.

The charge is calculated from the quark content (for hadrons) or basically tabulated; currently leptons, neutrinos and the standard model gauge bosons are known; unknown particles return a charge of 0.

Returns
charge of the particle

Definition at line 470 of file pdgcode.h.

470  {
471  if (is_hadron() || is_nucleus()) {
472  // Q will accumulate 3*charge (please excuse the upper case. I
473  // want to distinguish this from q which might be interpreted as
474  // shorthand for "quark".)
475  int Q = 0;
476  /* This loops over d,u,s,c,b,t quarks (the latter can be safely ignored,
477  * but I don't think this will be a bottle neck. */
478  for (int i = 1; i < 7; i++) {
479  /* u,c,t quarks have charge = 2/3 e, while d,s,b quarks have -1/3 e.
480  * The antiparticle sign is already in net_quark_number. */
481  Q += (i % 2 == 0 ? 2 : -1) * net_quark_number(i);
482  }
483  return Q / 3;
484  }
485  /* non-hadron:
486  * Leptons: 11, 13, 15 are e, μ, τ and have a charge -1, while
487  * 12, 14, 16 are the neutrinos that have no charge. */
488  if (digits_.n_q3_ == 1) {
489  return -1 * (digits_.n_J_ % 2) * antiparticle_sign();
490  }
491  /* Bosons: 24 is the W+, all else is uncharged.
492  * we ignore the first digits so that this also finds strange gauge
493  * boson "resonances" (in particular, \f$\tilde \chi_1^+\f$ with PDG
494  * Code 1000024). */
495  if ((dump_ & 0x0000ffff) == 0x24) {
496  return antiparticle_sign();
497  }
498  // default (this includes all other Bosons) is 0.
499  return 0;
500  }
int net_quark_number(const int quark) const
Returns the net number of quarks with given flavour number For public use, see strangeness(), charmness(), bottomness() and isospin3().
Definition: pdgcode.cc:31
int antiparticle_sign() const
Definition: pdgcode.h:537
bool is_nucleus() const
Definition: pdgcode.h:291
struct smash::PdgCode::@0::@2 digits_
The single digits collection of the code.
std::uint32_t dump_
The bitfield dumped into a single integer.
Definition: pdgcode.h:756
bool is_hadron() const
Definition: pdgcode.h:297
Here is the call graph for this function:
Here is the caller graph for this function:

◆ spin()

unsigned int smash::PdgCode::spin ( ) const
inline
Todo:
(oliiny): take care of spin for nuclei
Returns
twice the spin of a particle.

The code is good for hadrons, leptons and spin-1-bosons. It returns 2 (meaning spin=1) for the Higgs, though.

Definition at line 509 of file pdgcode.h.

509  {
510  if (is_nucleus()) {
511  /* Currently the only nucleus I care about is deutron,
512  * which has spin one. */
513  return 2;
514  }
515 
516  if (is_hadron()) {
517  if (digits_.n_J_ == 0) {
518  return 0; // special cases: K0_L=0x130 & K0_S=0x310
519  } else {
520  return digits_.n_J_ - 1;
521  }
522  }
523  /* this assumes that we only have white particles (no single
524  * quarks): Electroweak fermions have 11-17, so the
525  * second-to-last-digit is the spin. The same for the Bosons: they
526  * have 21-29 and 2spin = 2 (this fails for the Higgs). */
527  return digits_.n_q3_;
528  }
bool is_nucleus() const
Definition: pdgcode.h:291
struct smash::PdgCode::@0::@2 digits_
The single digits collection of the code.
bool is_hadron() const
Definition: pdgcode.h:297
Here is the call graph for this function:
Here is the caller graph for this function:

◆ spin_degeneracy()

unsigned int smash::PdgCode::spin_degeneracy ( ) const
inline
Returns
the spin degeneracy \(2s + 1\) of a particle.

Definition at line 530 of file pdgcode.h.

530  {
531  if (is_hadron() && digits_.n_J_ > 0) {
532  return digits_.n_J_;
533  }
534  return spin() + 1;
535  }
unsigned int spin() const
Definition: pdgcode.h:509
struct smash::PdgCode::@0::@2 digits_
The single digits collection of the code.
bool is_hadron() const
Definition: pdgcode.h:297
Here is the call graph for this function:

◆ antiparticle_sign()

int smash::PdgCode::antiparticle_sign ( ) const
inline
Returns
-1 for antiparticles and +1 for particles.

Definition at line 537 of file pdgcode.h.

537  {
538  return (digits_.antiparticle_ ? -1 : +1);
539  }
struct smash::PdgCode::@0::@2 digits_
The single digits collection of the code.
Here is the caller graph for this function:

◆ quarks()

std::int32_t smash::PdgCode::quarks ( ) const
inline
Returns
an integer with only the quark numbers set.

Definition at line 541 of file pdgcode.h.

541  {
542  if (!is_hadron() || is_nucleus()) {
543  return 0;
544  }
545  return chunks_.quarks_;
546  }
bool is_nucleus() const
Definition: pdgcode.h:291
struct smash::PdgCode::@0::@3 chunks_
Chunk collection: here, the chunks with and are directly accessible.
bool is_hadron() const
Definition: pdgcode.h:297
Here is the call graph for this function:

◆ quark_content()

std::array<int, 3> smash::PdgCode::quark_content ( ) const
inline

The return is always an array of three numbers, which are pdgcodes of quarks: 1 - d, 2 - u, 3 - s, 4 - c, 5 - b.

Antiquarks get a negative sign. For mesons the first number in array is always 0. There is a difficulty with mesons that are a superposition, for example \( \pi^0 = \frac{1}{\sqrt{2}}(u \bar{u} + d \bar{d}) \). Currently for \( \pi^0 \) just {0, 1, -1} is returned.

Returns
quark content as an array.

Definition at line 557 of file pdgcode.h.

557  {
558  std::array<int, 3> result = {static_cast<int>(digits_.n_q1_),
559  static_cast<int>(digits_.n_q2_),
560  static_cast<int>(digits_.n_q3_)};
561  if (is_hadron()) {
562  // Antibaryons
563  if (digits_.n_q1_ != 0 && digits_.antiparticle_) {
564  for (size_t i = 0; i < 3; i++) {
565  result[i] = -result[i];
566  }
567  }
568  // Mesons
569  if (digits_.n_q1_ == 0) {
570  // Own antiparticle
571  if (digits_.n_q2_ == digits_.n_q3_) {
572  result[2] = -result[2];
573  } else {
574  // Like pi-
575  if (digits_.antiparticle_) {
576  result[1] = -result[1];
577  // Like pi+
578  } else {
579  result[2] = -result[2];
580  }
581  }
582  // add extra minus sign according to the pdg convention
583  if (digits_.n_q2_ != digits_.n_q3_ && digits_.n_q2_ % 2 == 1) {
584  for (int i = 1; i <= 2; i++) {
585  result[i] = -result[i];
586  }
587  }
588  }
589  } else {
590  result = {0, 0, 0};
591  }
592  return result;
593  }
struct smash::PdgCode::@0::@2 digits_
The single digits collection of the code.
bool is_hadron() const
Definition: pdgcode.h:297
Here is the call graph for this function:
Here is the caller graph for this function:

◆ contains_enough_valence_quarks()

bool smash::PdgCode::contains_enough_valence_quarks ( int  valence_quarks_required) const
Returns
whether a particle contains at least the given number of valence quarks.
Parameters
[in]valence_quarks_requirednumber of valence quarks that particle is supposed to contain.
Exceptions
std::runtime_errorif it is not a hadron

This is necessary for string fragmentation.

Definition at line 92 of file pdgcode.cc.

93  {
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 }
bool is_baryon() const
Definition: pdgcode.h:318
bool is_meson() const
Definition: pdgcode.h:321
int baryon_number() const
Definition: pdgcode.h:308
Here is the call graph for this function:

◆ operator<()

bool smash::PdgCode::operator< ( const PdgCode  rhs) const
inline

Sorts PDG Codes according to their numeric value.

This is used by std::map

Definition at line 617 of file pdgcode.h.

617  {
618  return dump_ < rhs.dump_;
619  /* the complex thing to do here is to calculate:
620  * code() < rhs.code()
621  * but for getting a total order that's overkill. The uint32_t value in
622  * dump_ works just fine. */
623  }
std::uint32_t dump_
The bitfield dumped into a single integer.
Definition: pdgcode.h:756

◆ operator==()

bool smash::PdgCode::operator== ( const PdgCode  rhs) const
inline
Returns
if the codes are equal

Definition at line 626 of file pdgcode.h.

626 { return dump_ == rhs.dump_; }
std::uint32_t dump_
The bitfield dumped into a single integer.
Definition: pdgcode.h:756

◆ operator!=()

bool smash::PdgCode::operator!= ( const PdgCode  rhs) const
inline
Returns
if the codes are not equal.

Definition at line 629 of file pdgcode.h.

629 { return !(*this == rhs); }

◆ is_antiparticle_of()

bool smash::PdgCode::is_antiparticle_of ( const PdgCode  rhs) const
inline
Returns
if the code of rhs is the inverse of this one.

Definition at line 632 of file pdgcode.h.

632  {
633  return code() == -rhs.code();
634  }
std::int32_t code() const
Definition: pdgcode.h:249
Here is the call graph for this function:
Here is the caller graph for this function:

◆ invalid()

static PdgCode smash::PdgCode::invalid ( )
inlinestatic

PdgCode 0x0 is guaranteed not to be valid by the PDG standard, but it passes all tests here, so we can use it to show some code is not yet set.

Definition at line 644 of file pdgcode.h.

644 { return PdgCode(0x0); }
PdgCode()
Standard initializer.
Definition: pdgcode.h:125
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_decimal()

int smash::PdgCode::get_decimal ( ) const
inline
Returns
an integer with decimal representation of the code. If the spin is too large for the last digit, an additional digit at the beginning will be used, so that the sum of the first and the last digit is the spin. This is used for binary and ROOT output.
Exceptions
InvalidPdgCodeif the spin degeneracy is larger than 9

Definition at line 655 of file pdgcode.h.

655  {
656  if (is_nucleus()) {
657  // ±10LZZZAAAI
658  return antiparticle_sign() *
659  (nucleus_.I_ + 10 * nucleus_.A_ + 10000 * nucleus_.Z_ +
660  10000000 * nucleus_.n_Lambda_ + 1000000000);
661  }
662  int n_J_1 = 0;
663  int n_J_2 = digits_.n_J_;
664  if (n_J_2 > 9) {
665  n_J_1 = n_J_2 - 9;
666  n_J_2 = 9;
667  }
668  return antiparticle_sign() *
669  (n_J_2 + digits_.n_q3_ * 10 + digits_.n_q2_ * 100 +
670  digits_.n_q1_ * 1000 + digits_.n_L_ * 10000 +
671  digits_.n_R_ * 100000 + digits_.n_ * 1000000 + n_J_1 * 10000000);
672  }
int antiparticle_sign() const
Definition: pdgcode.h:537
struct smash::PdgCode::@0::@4 nucleus_
Structure for the nuclei.
bool is_nucleus() const
Definition: pdgcode.h:291
struct smash::PdgCode::@0::@2 digits_
The single digits collection of the code.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ deexcite()

void smash::PdgCode::deexcite ( )
inline

Remove all excitation, except spin. Sign and quark content remains.

Definition at line 675 of file pdgcode.h.

675  {
676  if (!is_nucleus()) {
677  chunks_.excitation_ = 0;
678  } else {
679  nucleus_.I_ = 0;
680  }
681  }
struct smash::PdgCode::@0::@4 nucleus_
Structure for the nuclei.
bool is_nucleus() const
Definition: pdgcode.h:291
struct smash::PdgCode::@0::@3 chunks_
Chunk collection: here, the chunks with and are directly accessible.
Here is the call graph for this function:

◆ net_quark_number()

int smash::PdgCode::net_quark_number ( const int  quark) const

Returns the net number of quarks with given flavour number For public use, see strangeness(), charmness(), bottomness() and isospin3().

Parameters
[in]quarkPDG Code of quark: (1..6) = (d,u,s,c,b,t)
Returns
for the net number of quarks (#quarks - #antiquarks)
Exceptions
std::invalid_argumentif quark is not any of d, u, s, c, b and t quarks

Definition at line 31 of file pdgcode.cc.

31  {
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_;
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 }
int antiparticle_sign() const
Definition: pdgcode.h:537
struct smash::PdgCode::@0::@4 nucleus_
Structure for the nuclei.
bool is_nucleus() const
Definition: pdgcode.h:291
struct smash::PdgCode::@0::@2 digits_
The single digits collection of the code.
int baryon_number() const
Definition: pdgcode.h:308
bool is_hadron() const
Definition: pdgcode.h:297
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ucode()

std::uint32_t smash::PdgCode::ucode ( ) const
inlineprivate
Returns
an unsigned integer with the PDG code in hexadecimal (disregarding the antiparticle flag).

Definition at line 797 of file pdgcode.h.

797 { return (dump_ & 0x0fffffff); }
std::uint32_t dump_
The bitfield dumped into a single integer.
Definition: pdgcode.h:756
Here is the caller graph for this function:

◆ get_digit_from_char()

std::uint32_t smash::PdgCode::get_digit_from_char ( const char  inp) const
inlineprivate
Returns
digits from a hexadecimal character.
Parameters
[in]inpcharacter which is translated into digit
Exceptions
InvalidPdgCodeif character does not correspond to digit

Definition at line 805 of file pdgcode.h.

805  {
806  // Decimal digit
807  if (48 <= inp && inp <= 57) {
808  return inp - 48;
809  }
810  // Hexdecimal digit, uppercase
811  if (65 <= inp && inp <= 70) {
812  return inp - 65 + 10;
813  }
814  // Hexdecimal digit, lowercase
815  if (97 <= inp && inp <= 102) {
816  return inp - 97 + 10;
817  }
818  throw InvalidPdgCode("PdgCode: Invalid character " + std::string(&inp, 1) +
819  " found.\n");
820  }
Here is the caller graph for this function:

◆ set_from_string()

void smash::PdgCode::set_from_string ( const std::string &  codestring)
inlineprivate

Set the PDG code from the given string.

This supports hexdecimal digits. If the last digit is not enough to represent the spin, a digit can be added at the beginning which will be added to the total spin.

Parameters
[in]codestringstring which is translated into PdgCode
Exceptions
InvalidPdgCodeif the input string is empty
InvalidPdgCodeif it is a nucleus whose PDG code does not begin with 10
InvalidPdgCodeif it is not a nucleus while number of digits is more than 8
InvalidPdgCodeif the 1st quark field is not any of d, u, s, c, b and t quarks
InvalidPdgCodeif the 2nd quark field is not any of d, u, s, c, b and t quarks
InvalidPdgCodeif the 3rd quark field is not any of d, u, s, c, b and t quarks
InvalidPdgCodeif there is nothing else but sign

Definition at line 843 of file pdgcode.h.

843  {
844  dump_ = 0;
845  // Implicit with the above: digits_.antiparticle_ = false;
846  digits_.n_ = digits_.n_R_ = digits_.n_L_ = digits_.n_q1_ = digits_.n_q2_ =
847  digits_.n_q3_ = digits_.n_J_ = digits_.is_nucleus_ = 0;
848  size_t length = codestring.size();
849  if (length < 1) {
850  throw InvalidPdgCode("Empty string does not contain PDG Code\n");
851  }
852  int c = 0;
853  /* Look at current character; if it is a + or minus sign, read it
854  * and advance to next char. */
855  if (codestring[c] == '-') {
856  digits_.antiparticle_ = true;
857  ++c;
858  } else if (codestring[c] == '+') {
859  digits_.antiparticle_ = false;
860  ++c;
861  }
862  // Save if the first character was a sign:
863  unsigned int sign = c;
864 
865  // Nucleus
866  if (length == 10 + sign) {
867  nucleus_.is_nucleus_ = true;
868  if (codestring[c] != '1' || codestring[c + 1] != '0') {
869  throw InvalidPdgCode("Pdg code of nucleus \"" + codestring +
870  "\" should start with 10\n");
871  }
872  c += 2;
873  // ±10LZZZAAAI is the standard for nuclei
874  std::array<int, 8> digits;
875  for (int i = 0; i < 8; i++) {
876  digits[i] = get_digit_from_char(codestring[c + i]);
877  }
878  nucleus_.n_Lambda_ = digits[0];
879  nucleus_.Z_ = 100 * digits[1] + 10 * digits[2] + digits[3];
880  nucleus_.A_ = 100 * digits[4] + 10 * digits[5] + digits[6];
881  nucleus_.I_ = digits[7];
882  return;
883  }
884 
885  // Codestring shouldn't be longer than 8 + sign, except for nuclei
886  if (length > 8 + sign) {
887  throw InvalidPdgCode("String \"" + codestring +
888  "\" too long for PDG Code\n");
889  }
890  /* Please note that in what follows, we actually need c++, not ++c.
891  * first digit is used for n_J if the last digit is not enough. */
892  if (length > 7 + sign) {
893  digits_.n_J_ += get_digit_from_char(codestring[c++]);
894  }
895  // Codestring has 7 digits? 7th from last goes in n_.
896  if (length > 6 + sign) {
897  digits_.n_ = get_digit_from_char(codestring[c++]);
898  }
899  // It has 6 or 7 digits? 6th from last is n_R_.
900  if (length > 5 + sign) {
901  digits_.n_R_ = get_digit_from_char(codestring[c++]);
902  }
903  // 5th from last is n_L_.
904  if (length > 4 + sign) {
905  digits_.n_L_ = get_digit_from_char(codestring[c++]);
906  }
907  // 4th from last is n_q1_.
908  if (length > 3 + sign) {
909  digits_.n_q1_ = get_digit_from_char(codestring[c++]);
910  if (digits_.n_q1_ > 6) {
911  throw InvalidPdgCode("Invalid PDG code " + codestring + " (n_q1>6)");
912  }
913  }
914  // 3rd from last is n_q2_.
915  if (length > 2 + sign) {
916  digits_.n_q2_ = get_digit_from_char(codestring[c++]);
917  if (digits_.n_q2_ > 6) {
918  throw InvalidPdgCode("Invalid PDG code " + codestring + " (n_q2>6)");
919  }
920  }
921  // Next to last is n_q3_.
922  if (length > 1 + sign) {
923  digits_.n_q3_ = get_digit_from_char(codestring[c++]);
924  if (digits_.n_q3_ > 6) {
925  throw InvalidPdgCode("Invalid PDG code " + codestring + " (n_q3>6)");
926  }
927  }
928  // Last digit is the spin degeneracy.
929  if (length > sign) {
930  digits_.n_J_ += get_digit_from_char(codestring[c++]);
931  } else {
932  throw InvalidPdgCode(
933  "String \"" + codestring +
934  "\" only consists of a sign, that is no valid PDG Code\n");
935  }
936  check();
937  }
struct smash::PdgCode::@0::@4 nucleus_
Structure for the nuclei.
struct smash::PdgCode::@0::@2 digits_
The single digits collection of the code.
std::uint32_t get_digit_from_char(const char inp) const
Definition: pdgcode.h:805
std::uint32_t dump_
The bitfield dumped into a single integer.
Definition: pdgcode.h:756
void check() const
Do all sorts of validity checks.
Definition: pdgcode.h:214
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_fields()

void smash::PdgCode::set_fields ( std::uint32_t  abscode)
inlineprivate

Sets the bitfield from an unsigned integer.

Usually called from the constructors.

Parameters
[in]abscodeinteger which replace PDG code except sign
Exceptions
InvalidPdgCodeif input is not a valid PDG code
See also
PdgCode::test_code

Definition at line 948 of file pdgcode.h.

948  {
949  /* "dump_ =" overwrites antiparticle_, but this needs to have been set
950  * already, so we carry it around the assignment. */
951  bool ap = digits_.antiparticle_;
952  dump_ = abscode & 0x0fffffff;
953  digits_.antiparticle_ = ap;
954  int test = test_code();
955  if (test > 0) {
956  throw InvalidPdgCode("Invalid digits " + std::to_string(test) +
957  " in PDG Code " + string());
958  }
959  check();
960  }
struct smash::PdgCode::@0::@2 digits_
The single digits collection of the code.
int test_code() const
Checks the integer for invalid hex digits.
Definition: pdgcode.h:180
std::uint32_t dump_
The bitfield dumped into a single integer.
Definition: pdgcode.h:756
void check() const
Do all sorts of validity checks.
Definition: pdgcode.h:214
Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator>>

std::istream& operator>> ( std::istream &  is,
PdgCode code 
)
friend

istream >> PdgCode assigns the PDG Code from an istream.

Parameters
[in]isinput string
[out]codePdgCode to be set

Definition at line 14 of file pdgcode.cc.

14  {
15  std::string codestring("");
16  is >> codestring;
17  if (!is) {
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);
27  }
28  return is;
29 }
static PdgCode invalid()
PdgCode 0x0 is guaranteed not to be valid by the PDG standard, but it passes all tests here...
Definition: pdgcode.h:644
std::int32_t code() const
Definition: pdgcode.h:249

Member Data Documentation

◆ n_J_

std::uint32_t smash::PdgCode::n_J_

spin quantum number \(n_J = 2 J + 1\).

Definition at line 723 of file pdgcode.h.

◆ n_q3_

std::uint32_t smash::PdgCode::n_q3_

third quark field

Definition at line 725 of file pdgcode.h.

◆ n_q2_

std::uint32_t smash::PdgCode::n_q2_

second quark field

Definition at line 727 of file pdgcode.h.

◆ n_q1_

std::uint32_t smash::PdgCode::n_q1_

first quark field. 0 for mesons.

Definition at line 729 of file pdgcode.h.

◆ n_L_

std::uint32_t smash::PdgCode::n_L_

"angular momentum"

Definition at line 731 of file pdgcode.h.

◆ n_R_

std::uint32_t smash::PdgCode::n_R_

"radial excitation"

Definition at line 733 of file pdgcode.h.

◆ n_

std::uint32_t smash::PdgCode::n_

first field: "counter"

Definition at line 735 of file pdgcode.h.

◆ is_nucleus_ [1/2]

std::uint32_t bool smash::PdgCode::is_nucleus_

1 for nuclei, 0 for the rest

Definition at line 735 of file pdgcode.h.

◆ antiparticle_

bool smash::PdgCode::antiparticle_

first bit: stores the sign.

Definition at line 739 of file pdgcode.h.

◆ digits_

struct { ... } smash::PdgCode::digits_

The single digits collection of the code.

Here, every PDG code digits is directly accessible.

◆ dump_

std::uint32_t smash::PdgCode::dump_

The bitfield dumped into a single integer.

Please note that the 2nd, 3rd and 4th highest bits are possibly undefined.

Definition at line 756 of file pdgcode.h.

◆ __pad0__

std::uint32_t smash::PdgCode::__pad0__

Definition at line 763 of file pdgcode.h.

◆ quarks_

std::uint32_t smash::PdgCode::quarks_

The quark digits n_q{1,2,3}_.

Definition at line 765 of file pdgcode.h.

◆ excitation_

std::uint32_t smash::PdgCode::excitation_

The excitation digits n_, n_R_, n_L_.

Definition at line 767 of file pdgcode.h.

◆ chunks_

struct { ... } smash::PdgCode::chunks_

Chunk collection: here, the chunks with \(nn_Rn_L\) and \(n_{q_1}n_{q_2}n_{q_3}\) are directly accessible.

◆ n_Lambda_

std::uint32_t smash::PdgCode::n_Lambda_

Definition at line 776 of file pdgcode.h.

◆ Z_

std::uint32_t smash::PdgCode::Z_

Definition at line 777 of file pdgcode.h.

◆ A_

std::uint32_t smash::PdgCode::A_

Definition at line 778 of file pdgcode.h.

◆ I_

std::uint32_t smash::PdgCode::I_

Definition at line 779 of file pdgcode.h.

◆ is_nucleus_ [2/2]

bool smash::PdgCode::is_nucleus_

Definition at line 780 of file pdgcode.h.

◆ nucleus_

struct { ... } smash::PdgCode::nucleus_

Structure for the nuclei.

◆ @1

union { ... }

The union holds the data; either as a single integer dump_, as a single-digit bitfield digits_ or as a multiple-digits bitfield chunks_.


The documentation for this class was generated from the following files: