Version: SMASH-3.0
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());
PdgCode()
Standard initializer.
Definition: pdgcode.h:127
static PdgCode invalid()
PdgCode 0x0 is guaranteed not to be valid by the PDG standard, but it passes all tests here,...
Definition: pdgcode.h:757

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 110 of file pdgcode.h.

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...
 
template<typename T >
 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 integer constructors above, since a 10-digits hexadecimal number like 0x1000020030 exceeds the int32_t capacity. 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_proton () const
 
bool is_neutron () 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_omega () const
 
bool is_rho () const
 
bool is_deuteron () const
 
bool is_triton () 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
 
int32_t 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...
 
int nucleus_p () const
 Number of protons in nucleus. More...
 
int nucleus_n () const
 Number of neutrons in nucleus. More...
 
int nucleus_La () const
 Number of Lambdas in nucleus. More...
 
int nucleus_ap () const
 Number of antiprotons in nucleus. More...
 
int nucleus_an () const
 Number of antineutrons in nucleus. More...
 
int nucleus_aLa () const
 Number of anti-Lambdas in nucleus. More...
 
int nucleus_A () const
 Nucleus mass number. 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/5]

smash::PdgCode::PdgCode ( )
inline

Standard initializer.

Definition at line 127 of file pdgcode.h.

127 : dump_(0x0) {}
std::uint32_t dump_
The bitfield dumped into a single integer.
Definition: pdgcode.h:888

◆ PdgCode() [2/5]

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 133 of file pdgcode.h.

133  {
134  set_from_string(codestring);
135  }
void set_from_string(const std::string &codestring)
Set the PDG code from the given string.
Definition: pdgcode.h:979

◆ PdgCode() [3/5]

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 145 of file pdgcode.h.

145  : dump_(0x0) { // NOLINT(runtime/explicit)
146  digits_.antiparticle_ = false;
147  if (codenumber < 0) {
148  digits_.antiparticle_ = true;
149  codenumber = -codenumber;
150  }
151  set_fields(codenumber);
152  }
struct smash::PdgCode::@0::@2 digits_
The single digits collection of the code.
void set_fields(std::uint32_t abscode)
Sets the bitfield from an unsigned integer.
Definition: pdgcode.h:1084

◆ PdgCode() [4/5]

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 157 of file pdgcode.h.

157  : dump_(0x0) {
158  // use the first bit for the antiparticle_ boolean.
159  digits_.antiparticle_ = ((abscode & 0x80000000u) != 0);
160  set_fields(abscode);
161  }

◆ PdgCode() [5/5]

template<typename T >
smash::PdgCode::PdgCode ( codenumber)
inline

The creation of PdgCode instances for nuclei that have a 10-digits code cannot be done using the integer constructors above, since a 10-digits hexadecimal number like 0x1000020030 exceeds the int32_t capacity.

Nuclei instances can in principle either be created with the string constructor or via the PdgCode::from_decimal() static member, but offering a uniform interface for all cases is definitely user-friendly.

Since the string constructor works, we delegate here the construction to it. In order to execute the needed code to built the string in the member initializer list, we use a common lambda idiom (IIFE) that consists in immediately invoking a lambda function. Using std::invoke makes it more explicit than using () after the lambda braces.

Note
One might wonder why a function template has been used instead of e.g. adding a constructor taking a int64_t argument. The reason is to facilitate the class usage. Having a fixed type would have required the users of this class to exactly match the argument type (and for int64_t there is no standard literal suffix), otherwise the call would have been ambiguous and compilation would have failed. Said differently, we would like
PdgCode deuteron(0x1000010020);
constexpr int64_t deuteron
Deuteron.
to work and not oblige the user to write
PdgCode deuteron(INT64_C(0x1000010020));
just because the constructor takes an int64_t number. The idea here is to offer a better matching to the compiler when the constructor is called with an integer type with size larger than 4 bytes. Type-traits are used to limit the template instantiation to reasonable cases, only.
Warning
In C++, it is more common to enable constructors template via a non-type template parameter, i.e.
template <typename T,
template <typename T,
typename std::enable_if_t<
std::is_integral_v<T> && 4 < sizeof(T), bool
> = true>
PdgCode(T codenumber) // ...
but this breaks Doxygen documentation, because apparently multiple "nested" template parameters are not able to be correctly handled (possibly because of the additional less-than symbol). This limitation has been detected using Doxygen 1.9.X and might be solved in future versions.
Parameters
[in]codenumberThe hexadecimal PDG code
Template Parameters
TThe type of the PDG code, irrelevant for the user and deduced by the compiler

Definition at line 219 of file pdgcode.h.

222  : PdgCode{std::invoke([&codenumber]() {
223  std::stringstream stream;
224  char sign = '+';
225  if (codenumber < 0) {
226  sign = '-';
227  codenumber = -codenumber;
228  }
229  stream << sign << std::hex << codenumber;
230  return stream.str();
231  })} {}

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 252 of file pdgcode.h.

252  {
253  int fail = 0;
254  if (digits_.n_ > 9) {
255  fail |= 1 << 6;
256  }
257  if (digits_.n_R_ > 9) {
258  fail |= 1 << 5;
259  }
260  if (digits_.n_L_ > 9) {
261  fail |= 1 << 4;
262  }
263  if (digits_.n_q1_ > 6) {
264  fail |= 1 << 3;
265  }
266  if (digits_.n_q2_ > 6) {
267  fail |= 1 << 2;
268  }
269  if (digits_.n_q3_ > 6) {
270  fail |= 1 << 1;
271  }
272  if (digits_.n_J_ > 15) {
273  fail |= 1;
274  }
275  return fail;
276  }

◆ 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 286 of file pdgcode.h.

286  {
287  // n_J must be odd for mesons and even for baryons (and cannot be zero)
288  if (is_hadron()) {
289  if (baryon_number() == 0) {
290  // mesons: special cases K0_L=0x130 and K0_S=0x310
291  if ((digits_.n_J_ % 2 == 0) && dump() != 0x130 && dump() != 0x310) {
292  throw InvalidPdgCode("Invalid PDG code " + string() +
293  " (meson with even n_J)");
294  }
295  } else {
296  if ((digits_.n_J_ % 2 != 0) || digits_.n_J_ == 0) {
297  throw InvalidPdgCode("Invalid PDG code " + string() +
298  " (baryon with odd n_J)");
299  }
300  }
301  } else {
302  if (digits_.n_J_ == 0 && dump() != 0x0) {
303  throw InvalidPdgCode("Invalid PDG code " + string() + " (n_J==0)");
304  }
305  }
306  /* The antiparticle flag only makes sense for particle types
307  * that have an antiparticle. */
308  if (digits_.antiparticle_ && !has_antiparticle()) {
309  throw InvalidPdgCode("Invalid PDG code " + string() +
310  " (cannot be negative)");
311  }
312  }
int baryon_number() const
Definition: pdgcode.h:380
std::uint32_t dump() const
Dumps the bitfield into an unsigned integer.
Definition: pdgcode.h:315
bool is_hadron() const
Definition: pdgcode.h:369
bool has_antiparticle() const
Definition: pdgcode.h:489

◆ dump()

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

Dumps the bitfield into an unsigned integer.

Definition at line 315 of file pdgcode.h.

315  {
316  // this cuts the three unused bits.
317  return (dump_ & 0x8fffffff);
318  }

◆ code()

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

Definition at line 321 of file pdgcode.h.

321 { return antiparticle_sign() * ucode(); }
int antiparticle_sign() const
Definition: pdgcode.h:650
std::uint32_t ucode() const
Definition: pdgcode.h:933

◆ string()

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

Definition at line 324 of file pdgcode.h.

324  {
325  std::stringstream ss;
326  ss << get_decimal();
327  return ss.str();
328  }
int32_t get_decimal() const
Definition: pdgcode.h:768

◆ get_antiparticle()

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

Construct the antiparticle to a given PDG code.

Definition at line 331 of file pdgcode.h.

331  {
332  PdgCode result = *this;
333  result.digits_.antiparticle_ = !digits_.antiparticle_;
334  return result;
335  }

◆ 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 341 of file pdgcode.h.

341  {
342  // Nucleus and special codes with 2J+1 > 9
343  if (std::abs(pdgcode_decimal) > 1E7) {
344  return PdgCode(std::to_string(pdgcode_decimal));
345  }
346  int a = pdgcode_decimal;
347  int hex_pdg = 0, tmp = 1;
348  while (a) {
349  hex_pdg += (a % 10) * tmp;
350  tmp *= 16;
351  a = a / 10;
352  }
353  return PdgCode(hex_pdg);
354  }

◆ is_nucleus()

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

Definition at line 363 of file pdgcode.h.

363  {
364  assert(digits_.is_nucleus_ == nucleus_.is_nucleus_);
365  return nucleus_.is_nucleus_;
366  }
struct smash::PdgCode::@0::@4 nucleus_
Structure for the nuclei.

◆ is_hadron()

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

Definition at line 369 of file pdgcode.h.

369  {
370  return (digits_.n_q3_ != 0 && digits_.n_q2_ != 0 && !is_nucleus());
371  }
bool is_nucleus() const
Definition: pdgcode.h:363

◆ is_lepton()

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

Definition at line 374 of file pdgcode.h.

374  {
375  return (digits_.n_q1_ == 0 && digits_.n_q2_ == 0 && digits_.n_q3_ == 1 &&
376  !is_nucleus());
377  }

◆ baryon_number()

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

Definition at line 380 of file pdgcode.h.

380  {
381  if (is_nucleus()) {
382  return static_cast<int>(nucleus_.A_) * antiparticle_sign();
383  }
384  if (!is_hadron() || digits_.n_q1_ == 0) {
385  return 0;
386  }
387  return antiparticle_sign();
388  }

◆ is_baryon()

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

Definition at line 390 of file pdgcode.h.

390 { return is_hadron() && digits_.n_q1_ != 0; }

◆ is_meson()

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

Definition at line 393 of file pdgcode.h.

393 { return is_hadron() && digits_.n_q1_ == 0; }

◆ is_nucleon()

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

Definition at line 396 of file pdgcode.h.

396  {
397  const auto abs_code = std::abs(code());
398  return (abs_code == pdg::p || abs_code == pdg::n);
399  }
std::int32_t code() const
Definition: pdgcode.h:321
constexpr int p
Proton.
constexpr int n
Neutron.

◆ is_proton()

bool smash::PdgCode::is_proton ( ) const
inline
Returns
whether this is a proton/anti-proton

Definition at line 402 of file pdgcode.h.

402  {
403  const auto abs_code = std::abs(code());
404  return (abs_code == pdg::p);
405  }

◆ is_neutron()

bool smash::PdgCode::is_neutron ( ) const
inline
Returns
whether this is a neutron/anti-neutron

Definition at line 408 of file pdgcode.h.

408  {
409  const auto abs_code = std::abs(code());
410  return (abs_code == pdg::n);
411  }

◆ is_Nstar1535()

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

Definition at line 414 of file pdgcode.h.

414  {
415  const auto abs_code = std::abs(code());
416  return (abs_code == pdg::N1535_p || abs_code == pdg::N1535_z);
417  }
constexpr int N1535_z
N(1535)⁰.
constexpr int N1535_p
N(1535)⁺.

◆ is_Delta()

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

Definition at line 420 of file pdgcode.h.

420  {
421  const auto abs_code = std::abs(code());
422  return (abs_code == pdg::Delta_pp || abs_code == pdg::Delta_p ||
423  abs_code == pdg::Delta_z || abs_code == pdg::Delta_m);
424  }
constexpr int Delta_p
Δ⁺.
constexpr int Delta_pp
Δ⁺⁺.
constexpr int Delta_m
Δ⁻.
constexpr int Delta_z
Δ⁰.

◆ is_hyperon()

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

Definition at line 427 of file pdgcode.h.

427 { return is_hadron() && digits_.n_q1_ == 3; }

◆ is_Omega()

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

Definition at line 430 of file pdgcode.h.

430  {
431  return is_hyperon() && digits_.n_q2_ == 3 && digits_.n_q3_ == 3;
432  }
bool is_hyperon() const
Definition: pdgcode.h:427

◆ is_Xi()

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

Definition at line 435 of file pdgcode.h.

435  {
436  return is_hyperon() && digits_.n_q2_ == 3 && digits_.n_q3_ != 3;
437  }

◆ is_Lambda()

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

Definition at line 440 of file pdgcode.h.

440  {
441  return is_hyperon() && digits_.n_q2_ == 1 && digits_.n_q3_ == 2;
442  }

◆ is_Sigma()

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

Definition at line 445 of file pdgcode.h.

445  {
446  return is_hyperon() && digits_.n_q2_ != 3 && !is_Lambda();
447  }
bool is_Lambda() const
Definition: pdgcode.h:440

◆ is_kaon()

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

Definition at line 450 of file pdgcode.h.

450  {
451  const auto abs_code = std::abs(code());
452  return (abs_code == pdg::K_p) || (abs_code == pdg::K_z);
453  }
constexpr int K_p
K⁺.
constexpr int K_z
K⁰.

◆ is_pion()

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

Definition at line 456 of file pdgcode.h.

456  {
457  const auto c = code();
458  return (c == pdg::pi_z) || (c == pdg::pi_p) || (c == pdg::pi_m);
459  }
constexpr int pi_p
π⁺.
constexpr int pi_z
π⁰.
constexpr int pi_m
π⁻.

◆ is_omega()

bool smash::PdgCode::is_omega ( ) const
inline
Returns
whether this is an omega meson

Definition at line 462 of file pdgcode.h.

462  {
463  const auto c = code();
464  return c == pdg::omega;
465  }
constexpr int omega
ω.

◆ is_rho()

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

Definition at line 468 of file pdgcode.h.

468  {
469  const auto c = code();
470  return (c == pdg::rho_z) || (c == pdg::rho_p) || (c == pdg::rho_m);
471  }
constexpr int rho_p
ρ⁺.
constexpr int rho_m
ρ⁻.
constexpr int rho_z
ρ⁰.

◆ is_deuteron()

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

Definition at line 474 of file pdgcode.h.

474  {
475  return is_nucleus() && nucleus_.A_ == 2 && nucleus_.Z_ == 1 &&
476  nucleus_.n_Lambda_ == 0 && nucleus_.I_ == 0;
477  }

◆ is_triton()

bool smash::PdgCode::is_triton ( ) const
inline
Returns
whether this is (anti-)triton

Definition at line 480 of file pdgcode.h.

480  {
481  return is_nucleus() && nucleus_.A_ == 3 && nucleus_.Z_ == 1 &&
482  nucleus_.n_Lambda_ == 0 && nucleus_.I_ == 0;
483  }

◆ 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 489 of file pdgcode.h.

489  {
490  if (is_nucleus()) {
491  return true;
492  }
493  if (is_hadron()) {
494  return (baryon_number() != 0) || (digits_.n_q2_ != digits_.n_q3_);
495  } else {
496  return digits_.n_q3_ == 1; // leptons!
497  }
498  }

◆ 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 505 of file pdgcode.h.

505  {
506  /* net_quark_number(2) is the number of u quarks,
507  * net_quark_number(1) is the number of d quarks. */
508  return net_quark_number(2) - net_quark_number(1);
509  }
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

◆ 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 518 of file pdgcode.h.

518  {
519  /* The quarkonium state has 0 net strangeness
520  * but there are actually 2 strange quarks out of 2 total */
521  if (is_hadron() && digits_.n_q3_ == 3 && digits_.n_q2_ == 3) {
522  return 1.;
523  } else {
524  // For all other cases, there isn't both a strange and anti-strange
525  if (is_baryon()) {
526  return std::abs(strangeness()) / 3.;
527  } else if (is_meson()) {
528  return std::abs(strangeness()) / 2.;
529  } else {
530  /* If not baryon or meson, this should be 0, as AQM does not
531  * extend to non-hadrons */
532  return 0.;
533  }
534  }
535  }
bool is_meson() const
Definition: pdgcode.h:393
int strangeness() const
Definition: pdgcode.h:542
bool is_baryon() const
Definition: pdgcode.h:390

◆ 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 542 of file pdgcode.h.

542 { return -net_quark_number(3); }

◆ 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 549 of file pdgcode.h.

549 { return +net_quark_number(4); }

◆ 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 556 of file pdgcode.h.

556 { return -net_quark_number(5); }

◆ 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 566 of file pdgcode.h.

566  {
567  if (is_hadron() || is_nucleus()) {
568  // Q will accumulate 3*charge (please excuse the upper case. I
569  // want to distinguish this from q which might be interpreted as
570  // shorthand for "quark".)
571  int Q = 0;
572  /* This loops over d,u,s,c,b,t quarks (the latter can be safely ignored,
573  * but I don't think this will be a bottle neck. */
574  for (int i = 1; i < 7; i++) {
575  /* u,c,t quarks have charge = 2/3 e, while d,s,b quarks have -1/3 e.
576  * The antiparticle sign is already in net_quark_number. */
577  Q += (i % 2 == 0 ? 2 : -1) * net_quark_number(i);
578  }
579  return Q / 3;
580  }
581  /* non-hadron:
582  * Leptons: 11, 13, 15 are e, μ, τ and have a charge -1, while
583  * 12, 14, 16 are the neutrinos that have no charge. */
584  if (digits_.n_q3_ == 1) {
585  return -1 * (digits_.n_J_ % 2) * antiparticle_sign();
586  }
587  /* Bosons: 24 is the W+, all else is uncharged.
588  * we ignore the first digits so that this also finds strange gauge
589  * boson "resonances" (in particular, \f$\tilde \chi_1^+\f$ with PDG
590  * Code 1000024). */
591  if ((dump_ & 0x0000ffff) == 0x24) {
592  return antiparticle_sign();
593  }
594  // default (this includes all other Bosons) is 0.
595  return 0;
596  }

◆ spin()

unsigned int smash::PdgCode::spin ( ) const
inline
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.

Exceptions
runtime_errorif a spin of a nucleus is not coded in and has to be guessed

Definition at line 607 of file pdgcode.h.

607  {
608  if (is_nucleus()) {
609  // Generally spin of a nucleus cannot be simply guessed, it should be
610  // provided from some table. However, here we only care about a
611  // limited set of light nuclei with A <= 4.
612  if (nucleus_.A_ == 2) {
613  // Deuteron spin is 1
614  return 2;
615  } else if (nucleus_.A_ == 3) {
616  // Tritium and He-3 spin are 1/2
617  // Hypertriton spin is not firmly determined, but decay branching ratios
618  // indicate spin 1/2
619  return 1;
620  } else if (nucleus_.A_ == 4) {
621  // He-4 spin is 0
622  return 0;
623  }
624  throw std::runtime_error("Unknown spin of nucleus.");
625  // Alternative possibility is to guess 1/2 for fermions and 0 for bosons
626  // as 2 * (nucleus_.A_ % 2).
627  }
628 
629  if (is_hadron()) {
630  if (digits_.n_J_ == 0) {
631  return 0; // special cases: K0_L=0x130 & K0_S=0x310
632  } else {
633  return digits_.n_J_ - 1;
634  }
635  }
636  /* this assumes that we only have white particles (no single
637  * quarks): Electroweak fermions have 11-17, so the
638  * second-to-last-digit is the spin. The same for the Bosons: they
639  * have 21-29 and 2spin = 2 (this fails for the Higgs). */
640  return digits_.n_q3_;
641  }

◆ spin_degeneracy()

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

Definition at line 643 of file pdgcode.h.

643  {
644  if (is_hadron() && digits_.n_J_ > 0) {
645  return digits_.n_J_;
646  }
647  return spin() + 1;
648  }
unsigned int spin() const
Definition: pdgcode.h:607

◆ antiparticle_sign()

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

Definition at line 650 of file pdgcode.h.

650  {
651  return (digits_.antiparticle_ ? -1 : +1);
652  }

◆ quarks()

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

Definition at line 654 of file pdgcode.h.

654  {
655  if (!is_hadron() || is_nucleus()) {
656  return 0;
657  }
658  return chunks_.quarks_;
659  }
struct smash::PdgCode::@0::@3 chunks_
Chunk collection: here, the chunks with and are directly accessible.

◆ 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 670 of file pdgcode.h.

670  {
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_)};
674  if (is_hadron()) {
675  // Antibaryons
676  if (digits_.n_q1_ != 0 && digits_.antiparticle_) {
677  for (size_t i = 0; i < 3; i++) {
678  result[i] = -result[i];
679  }
680  }
681  // Mesons
682  if (digits_.n_q1_ == 0) {
683  // Own antiparticle
684  if (digits_.n_q2_ == digits_.n_q3_) {
685  result[2] = -result[2];
686  } else {
687  // Like pi-
688  if (digits_.antiparticle_) {
689  result[1] = -result[1];
690  // Like pi+
691  } else {
692  result[2] = -result[2];
693  }
694  }
695  // add extra minus sign according to the pdg convention
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];
699  }
700  }
701  }
702  } else {
703  result = {0, 0, 0};
704  }
705  return result;
706  }

◆ 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 }

◆ 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 730 of file pdgcode.h.

730  {
731  return dump_ < rhs.dump_;
732  /* the complex thing to do here is to calculate:
733  * code() < rhs.code()
734  * but for getting a total order that's overkill. The uint32_t value in
735  * dump_ works just fine. */
736  }

◆ operator==()

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

Definition at line 739 of file pdgcode.h.

739 { return dump_ == rhs.dump_; }

◆ operator!=()

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

Definition at line 742 of file pdgcode.h.

742 { 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 745 of file pdgcode.h.

745  {
746  return code() == -rhs.code();
747  }

◆ 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 757 of file pdgcode.h.

757 { return PdgCode(0x0); }

◆ get_decimal()

int32_t 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 768 of file pdgcode.h.

768  {
769  if (is_nucleus()) {
770  // ±10LZZZAAAI
771  return antiparticle_sign() *
772  (nucleus_.I_ + 10 * nucleus_.A_ + 10000 * nucleus_.Z_ +
773  10000000 * nucleus_.n_Lambda_ + 1000000000);
774  }
775  int n_J_1 = 0;
776  int n_J_2 = digits_.n_J_;
777  if (n_J_2 > 9) {
778  n_J_1 = n_J_2 - 9;
779  n_J_2 = 9;
780  }
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);
785  }

◆ deexcite()

void smash::PdgCode::deexcite ( )
inline

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

Definition at line 788 of file pdgcode.h.

788  {
789  if (!is_nucleus()) {
790  chunks_.excitation_ = 0;
791  } else {
792  nucleus_.I_ = 0;
793  }
794  }

◆ 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_ - 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 }

◆ nucleus_p()

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

Number of protons in nucleus.

Definition at line 809 of file pdgcode.h.

809  {
810  return (is_nucleus() && !nucleus_.antiparticle_) ? nucleus_.Z_ : 0;
811  }

◆ nucleus_n()

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

Number of neutrons in nucleus.

Definition at line 813 of file pdgcode.h.

813  {
814  return (is_nucleus() && !nucleus_.antiparticle_)
815  ? nucleus_.A_ - nucleus_.Z_ - nucleus_.n_Lambda_
816  : 0;
817  }

◆ nucleus_La()

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

Number of Lambdas in nucleus.

Definition at line 819 of file pdgcode.h.

819  {
820  return (is_nucleus() && !nucleus_.antiparticle_) ? nucleus_.n_Lambda_ : 0;
821  }

◆ nucleus_ap()

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

Number of antiprotons in nucleus.

Definition at line 823 of file pdgcode.h.

823  {
824  return (is_nucleus() && nucleus_.antiparticle_) ? nucleus_.Z_ : 0;
825  }

◆ nucleus_an()

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

Number of antineutrons in nucleus.

Definition at line 827 of file pdgcode.h.

827  {
828  return (is_nucleus() && nucleus_.antiparticle_)
829  ? nucleus_.A_ - nucleus_.Z_ - nucleus_.n_Lambda_
830  : 0;
831  }

◆ nucleus_aLa()

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

Number of anti-Lambdas in nucleus.

Definition at line 833 of file pdgcode.h.

833  {
834  return (is_nucleus() && nucleus_.antiparticle_) ? nucleus_.n_Lambda_ : 0;
835  }

◆ nucleus_A()

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

Nucleus mass number.

Definition at line 837 of file pdgcode.h.

837 { return is_nucleus() ? nucleus_.A_ : 0; }

◆ 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 933 of file pdgcode.h.

933 { return (dump_ & 0x0fffffff); }

◆ 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 941 of file pdgcode.h.

941  {
942  // Decimal digit
943  if (48 <= inp && inp <= 57) {
944  return inp - 48;
945  }
946  // Hexdecimal digit, uppercase
947  if (65 <= inp && inp <= 70) {
948  return inp - 65 + 10;
949  }
950  // Hexdecimal digit, lowercase
951  if (97 <= inp && inp <= 102) {
952  return inp - 97 + 10;
953  }
954  throw InvalidPdgCode("PdgCode: Invalid character " + std::string(&inp, 1) +
955  " found.\n");
956  }

◆ 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 979 of file pdgcode.h.

979  {
980  dump_ = 0;
981  // Implicit with the above: digits_.antiparticle_ = false;
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();
985  if (length < 1) {
986  throw InvalidPdgCode("Empty string does not contain PDG Code\n");
987  }
988  int c = 0;
989  /* Look at current character; if it is a + or minus sign, read it
990  * and advance to next char. */
991  if (codestring[c] == '-') {
992  digits_.antiparticle_ = true;
993  ++c;
994  } else if (codestring[c] == '+') {
995  digits_.antiparticle_ = false;
996  ++c;
997  }
998  // Save if the first character was a sign:
999  unsigned int sign = c;
1000 
1001  // Nucleus
1002  if (length == 10 + sign) {
1003  nucleus_.is_nucleus_ = true;
1004  if (codestring[c] != '1' || codestring[c + 1] != '0') {
1005  throw InvalidPdgCode("Pdg code of nucleus \"" + codestring +
1006  "\" should start with 10\n");
1007  }
1008  c += 2;
1009  // ±10LZZZAAAI is the standard for nuclei
1010  std::array<int, 8> digits;
1011  for (int i = 0; i < 8; i++) {
1012  digits[i] = get_digit_from_char(codestring[c + i]);
1013  }
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];
1018  return;
1019  }
1020 
1021  // Codestring shouldn't be longer than 8 + sign, except for nuclei
1022  if (length > 8 + sign) {
1023  throw InvalidPdgCode("String \"" + codestring +
1024  "\" too long for PDG Code\n");
1025  }
1026  /* Please note that in what follows, we actually need c++, not ++c.
1027  * first digit is used for n_J if the last digit is not enough. */
1028  if (length > 7 + sign) {
1029  digits_.n_J_ += get_digit_from_char(codestring[c++]);
1030  }
1031  // Codestring has 7 digits? 7th from last goes in n_.
1032  if (length > 6 + sign) {
1033  digits_.n_ = get_digit_from_char(codestring[c++]);
1034  }
1035  // It has 6 or 7 digits? 6th from last is n_R_.
1036  if (length > 5 + sign) {
1037  digits_.n_R_ = get_digit_from_char(codestring[c++]);
1038  }
1039  // 5th from last is n_L_.
1040  if (length > 4 + sign) {
1041  digits_.n_L_ = get_digit_from_char(codestring[c++]);
1042  }
1043  // 4th from last is n_q1_.
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)");
1048  }
1049  }
1050  // 3rd from last is n_q2_.
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)");
1055  }
1056  }
1057  // Next to last is n_q3_.
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)");
1062  }
1063  }
1064  // Last digit is the spin degeneracy.
1065  if (length > sign) {
1066  digits_.n_J_ += get_digit_from_char(codestring[c++]);
1067  } else {
1068  throw InvalidPdgCode(
1069  "String \"" + codestring +
1070  "\" only consists of a sign, that is no valid PDG Code\n");
1071  }
1072  check();
1073  }
void check() const
Do all sorts of validity checks.
Definition: pdgcode.h:286
std::uint32_t get_digit_from_char(const char inp) const
Definition: pdgcode.h:941

◆ 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 1084 of file pdgcode.h.

1084  {
1085  /* "dump_ =" overwrites antiparticle_, but this needs to have been set
1086  * already, so we carry it around the assignment. */
1087  bool ap = digits_.antiparticle_;
1088  dump_ = abscode & 0x0fffffff;
1089  digits_.antiparticle_ = ap;
1090  int test = test_code();
1091  if (test > 0) {
1092  throw InvalidPdgCode("Invalid digits " + std::to_string(test) +
1093  " in PDG Code " + string());
1094  }
1095  check();
1096  }
int test_code() const
Checks the integer for invalid hex digits.
Definition: pdgcode.h:252

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 }

Member Data Documentation

◆ n_J_

std::uint32_t smash::PdgCode::n_J_

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

Definition at line 853 of file pdgcode.h.

◆ n_q3_

std::uint32_t smash::PdgCode::n_q3_

third quark field

Definition at line 855 of file pdgcode.h.

◆ n_q2_

std::uint32_t smash::PdgCode::n_q2_

second quark field

Definition at line 857 of file pdgcode.h.

◆ n_q1_

std::uint32_t smash::PdgCode::n_q1_

first quark field. 0 for mesons.

Definition at line 859 of file pdgcode.h.

◆ n_L_

std::uint32_t smash::PdgCode::n_L_

"angular momentum"

Definition at line 861 of file pdgcode.h.

◆ n_R_

std::uint32_t smash::PdgCode::n_R_

"radial excitation"

Definition at line 863 of file pdgcode.h.

◆ n_

std::uint32_t smash::PdgCode::n_

first field: "counter"

Definition at line 865 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 867 of file pdgcode.h.

◆ antiparticle_

bool smash::PdgCode::antiparticle_

first bit: stores the sign.

Definition at line 869 of file pdgcode.h.

◆ 

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 888 of file pdgcode.h.

◆ __pad0__

std::uint32_t smash::PdgCode::__pad0__

Definition at line 895 of file pdgcode.h.

◆ quarks_

std::uint32_t smash::PdgCode::quarks_

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

Definition at line 897 of file pdgcode.h.

◆ excitation_

std::uint32_t smash::PdgCode::excitation_

The excitation digits n_, n_R_, n_L_.

Definition at line 899 of file pdgcode.h.

◆ 

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 910 of file pdgcode.h.

◆ Z_

std::uint32_t smash::PdgCode::Z_

Definition at line 911 of file pdgcode.h.

◆ A_

std::uint32_t smash::PdgCode::A_

Definition at line 912 of file pdgcode.h.

◆ I_

std::uint32_t smash::PdgCode::I_

Definition at line 913 of file pdgcode.h.

◆ is_nucleus_ [2/2]

bool smash::PdgCode::is_nucleus_

Definition at line 914 of file pdgcode.h.

◆ 

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

Structure for the nuclei.

◆ 

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: