Version: SMASH-3.0
particletype.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2021,2023
3  * SMASH Team
4  *
5  * GNU General Public License (GPLv3 or later)
6  */
7 #ifndef SRC_INCLUDE_SMASH_PARTICLETYPE_H_
8 #define SRC_INCLUDE_SMASH_PARTICLETYPE_H_
9 
10 #include <cassert>
11 #include <string>
12 #include <utility>
13 #include <vector>
14 
15 #include "forwarddeclarations.h"
16 #include "macros.h"
17 #include "pdgcode.h"
18 
19 namespace smash {
20 
24 enum class Parity {
26  Pos,
28  Neg
29 };
30 
32 enum class WhichDecaymodes {
34  All,
36  Hadronic,
38  Dileptons
39 };
40 
46  switch (p) {
47  case Parity::Pos:
48  return Parity::Neg;
49  case Parity::Neg:
50  return Parity::Pos;
51  }
52  // This is unreachable and should be optimized away.
53  // It is required to silence a compiler warning.
54  throw std::runtime_error("unreachable");
55 }
56 
62 inline Parity operator*(Parity x, Parity y) {
63  if (x == y) {
64  return Parity::Pos;
65  } else {
66  return Parity::Neg;
67  }
68 }
69 
75 inline void operator*=(Parity &x, Parity y) {
76  if (x == y) {
77  x = Parity::Pos;
78  } else {
79  x = Parity::Neg;
80  }
81 }
82 
97 class ParticleType {
98  public:
105  // If this is changed, make sure to update the userguide in
106  // `include/configuration.h`.
107  static constexpr double width_cutoff = 1e-5;
108 
122  ParticleType(std::string n, double m, double w, Parity p, PdgCode id);
123 
128  ParticleType(const ParticleType &) = delete;
130  ParticleType &operator=(const ParticleType &) = delete;
131 
133  ParticleType(ParticleType &&) = default;
136 
138  const DecayModes &decay_modes() const;
139 
141  const std::string &name() const { return name_; }
142 
144  double mass() const { return mass_; }
145 
147  double mass_sqr() const { return mass_ * mass_; }
148 
150  double width_at_pole() const { return width_; }
151 
153  Parity parity() const { return parity_; }
154 
156  PdgCode pdgcode() const { return pdgcode_; }
157 
159  bool has_antiparticle() const { return pdgcode_.has_antiparticle(); }
160 
163 
165  int antiparticle_sign() const { return pdgcode_.antiparticle_sign(); }
166 
173  int isospin() const;
174 
176  int isospin3() const { return I3_; }
177 
179  double isospin3_rel() const {
180  unsigned int I = isospin();
181  return (I == 0) ? 0 : static_cast<double>(isospin3()) / I;
182  }
183 
186 
188  int32_t charge() const { return charge_; }
189 
191  unsigned int spin() const { return pdgcode_.spin(); }
192 
194  unsigned int spin_degeneracy() const { return pdgcode_.spin_degeneracy(); }
195 
197  bool is_hadron() const { return pdgcode_.is_hadron(); }
198 
200  bool is_lepton() const { return pdgcode_.is_lepton(); }
201 
203  bool is_baryon() const { return pdgcode_.is_baryon(); }
204 
206  bool is_meson() const { return pdgcode_.is_meson(); }
207 
209  int baryon_number() const { return pdgcode_.baryon_number(); }
210 
212  int strangeness() const { return pdgcode_.strangeness(); }
213 
215  bool is_nucleon() const { return pdgcode_.is_nucleon(); }
216 
218  bool is_pion() const { return pdgcode_.is_pion(); }
219 
221  bool is_Delta() const { return pdgcode_.is_Delta(); }
222 
224  bool is_rho() const { return pdgcode_.is_rho(); }
225 
227  inline bool is_Nstar() const {
228  return is_baryon() && isospin() == 1 && !pdgcode_.is_nucleon() &&
229  pdgcode_.strangeness() == 0 && pdgcode_.charmness() == 0;
230  }
231 
233  bool is_Nstar1535() const { return pdgcode_.is_Nstar1535(); }
234 
236  inline bool is_Deltastar() const {
237  return is_baryon() && isospin() == 3 && !pdgcode_.is_Delta() &&
238  pdgcode_.strangeness() == 0 && pdgcode_.charmness() == 0;
239  }
240 
242  inline bool is_stable() const { return width_ < width_cutoff; }
243 
245  inline bool is_nucleus() const { return pdgcode_.is_nucleus(); }
246 
248  inline bool is_deuteron() const { return pdgcode_.is_deuteron(); }
249 
251  inline bool is_triton() const { return pdgcode_.is_triton(); }
252 
254  inline bool is_dprime() const {
255  return is_nucleus() && std::abs(pdgcode_.get_decimal()) == 1000010021;
256  }
257 
268  double min_mass_kinematic() const;
269 
285  double min_mass_spectral() const;
286 
295  double partial_width(const double m, const DecayBranch *mode) const;
296 
303  double total_width(const double m) const;
304 
312  bool wanted_decaymode(const DecayType &t, WhichDecaymodes wh) const;
313 
323  DecayBranchList get_partial_widths(const FourVector p, const ThreeVector x,
324  WhichDecaymodes wh) const;
325 
334  double get_partial_width(const double m,
335  const ParticleTypePtrList dlist) const;
336 
348  double get_partial_in_width(const double m, const ParticleData &p_a,
349  const ParticleData &p_b) const;
350 
365  double spectral_function(double m) const;
366 
375  double spectral_function_no_norm(double m) const;
376 
382  double spectral_function_const_width(double m) const;
383 
394  double spectral_function_simple(double m) const;
395 
406  double sample_resonance_mass(const double mass_stable,
407  const double cms_energy, int L = 0) const;
408 
419  std::pair<double, double> sample_resonance_masses(const ParticleType &t2,
420  const double cms_energy,
421  int L = 0) const;
422 
430 
438  static const ParticleTypeList &list_all();
439 
441  static ParticleTypePtrList &list_nucleons();
443  static ParticleTypePtrList &list_anti_nucleons();
448  static ParticleTypePtrList &list_Deltas();
453  static ParticleTypePtrList &list_anti_Deltas();
458  static ParticleTypePtrList &list_baryon_resonances();
463  static ParticleTypePtrList &list_light_nuclei();
464 
479  static const ParticleTypePtr try_find(PdgCode pdgcode);
480 
494  static const ParticleType &find(PdgCode pdgcode);
495 
497  struct PdgNotFoundFailure : public std::runtime_error {
498  using std::runtime_error::runtime_error;
499  };
500 
507  static bool exists(PdgCode pdgcode);
508 
515  static bool exists(const std::string &name);
516 
530  static void create_type_list(const std::string &particles);
531 
536  bool operator==(const ParticleType &rhs) const {
537  return pdgcode() == rhs.pdgcode();
538  }
543  bool operator!=(const ParticleType &rhs) const {
544  return pdgcode() != rhs.pdgcode();
545  }
552  bool operator<(const ParticleType &rhs) const {
553  return pdgcode() < rhs.pdgcode();
554  }
555 
563  static void check_consistency();
564 
606  ParticleTypePtr operator&() const;
607 
609  struct LoadFailure : public std::runtime_error {
610  using std::runtime_error::runtime_error;
611  };
612 
613  private:
615  std::string name_;
617  double mass_;
619  double width_;
630  mutable double min_mass_kinematic_;
637  mutable double min_mass_spectral_;
640  mutable double norm_factor_ = -1.;
642  int32_t charge_;
644  mutable int isospin_;
646  int I3_;
647 
650 
652  mutable double max_factor1_ = 1.;
654  mutable double max_factor2_ = 1.;
655 
662  friend std::ostream &operator<<(std::ostream &out, const ParticleType &type);
663 };
664 
673  public:
675  const ParticleType &operator*() const { return lookup(); }
676 
678  const ParticleType *operator->() const {
679  // this requires std::addressof because &lookup() would call
680  // ParticleType::operator& and return ParticleTypePtr again
681  return std::addressof(lookup());
682  }
683 
685  ParticleTypePtr() = default;
686 
691  bool operator==(const ParticleTypePtr &rhs) const {
692  return index_ == rhs.index_;
693  }
694 
699  bool operator!=(const ParticleTypePtr &rhs) const {
700  return index_ != rhs.index_;
701  }
708  bool operator<(const ParticleTypePtr &rhs) const {
709  return index_ < rhs.index_;
710  }
711 
713  operator bool() const { return index_ != 0xffff; }
714 
715  private:
722 
727  explicit ParticleTypePtr(std::uint16_t i) : index_(i) {}
728 
740  const ParticleType &lookup() const {
741  assert(index_ != 0xffff);
742  return ParticleType::list_all()[index_];
743  }
744 
750  std::uint16_t index_ = 0xffff;
751 };
752 
754  assert(has_antiparticle());
755  return &find(pdgcode_.get_antiparticle());
756 }
757 
758 } // namespace smash
759 
760 #endif // SRC_INCLUDE_SMASH_PARTICLETYPE_H_
DecayBranch is a derivative of ProcessBranch, which is used to represent decay channels.
The DecayModes class is used to store and update information about decay branches (i....
Definition: decaymodes.h:29
DecayType is the abstract base class for all decay types.
Definition: decaytype.h:23
The FourVector class holds relevant values in Minkowski spacetime with (+, −, −, −) metric signature.
Definition: fourvector.h:33
IsoParticleType is a class to represent isospin multiplets.
ParticleData contains the dynamic information of a certain particle.
Definition: particledata.h:58
A pointer-like interface to global references to ParticleType objects.
Definition: particletype.h:672
bool operator==(const ParticleTypePtr &rhs) const
Definition: particletype.h:691
const ParticleType & operator*() const
Definition: particletype.h:675
bool operator<(const ParticleTypePtr &rhs) const
"Less than" operator
Definition: particletype.h:708
ParticleTypePtr()=default
Default construction initializes with an invalid index.
bool operator!=(const ParticleTypePtr &rhs) const
Definition: particletype.h:699
const ParticleType & lookup() const
Helper function that does the ParticleType lookup from the stored index.
Definition: particletype.h:740
std::uint16_t index_
Stores the index of the references ParticleType object in the global vector.
Definition: particletype.h:750
const ParticleType * operator->() const
Definition: particletype.h:678
ParticleTypePtr(std::uint16_t i)
Constructs a pointer to the ParticleType object at offset i.
Definition: particletype.h:727
Particle type contains the static properties of a particle species.
Definition: particletype.h:97
double min_mass_spectral_
minimum mass, where the spectral function is non-zero Mutable, because it is initialized at first cal...
Definition: particletype.h:637
bool is_pion() const
Definition: particletype.h:218
double min_mass_spectral() const
The minimum mass of the resonance, where the spectral function is non-zero.
IsoParticleType * iso_multiplet_
Container for the isospin multiplet information.
Definition: particletype.h:649
int I3_
Isospin projection of the particle; filled automatically from pdgcode_.
Definition: particletype.h:646
bool is_triton() const
Definition: particletype.h:251
bool is_baryon() const
Definition: particletype.h:203
const DecayModes & decay_modes() const
double spectral_function(double m) const
Full spectral function of the resonance (relativistic Breit-Wigner distribution with mass-dependent ...
Parity parity_
Parity of the particle.
Definition: particletype.h:621
int isospin3() const
Definition: particletype.h:176
std::string name_
name of the particle
Definition: particletype.h:615
ParticleTypePtr get_antiparticle() const
Definition: particletype.h:753
bool is_Nstar() const
Definition: particletype.h:227
double sample_resonance_mass(const double mass_stable, const double cms_energy, int L=0) const
Resonance mass sampling for 2-particle final state with one resonance (type given by 'this') and one ...
double get_partial_width(const double m, const ParticleTypePtrList dlist) const
Get the mass-dependent partial width of a resonance with mass m, decaying into two given daughter par...
int strangeness() const
Definition: particletype.h:212
static const ParticleTypePtr try_find(PdgCode pdgcode)
Returns the ParticleTypePtr for the given pdgcode.
Definition: particletype.cc:89
void dump_width_and_spectral_function() const
Prints out width and spectral function versus mass to the standard output.
double total_width(const double m) const
Get the mass-dependent total width of a particle with mass m.
bool wanted_decaymode(const DecayType &t, WhichDecaymodes wh) const
Helper Function that containes the if-statement logic that decides if a decay mode is either a hadron...
static const ParticleType & find(PdgCode pdgcode)
Returns the ParticleType object for the given pdgcode.
Definition: particletype.cc:99
bool is_nucleus() const
Definition: particletype.h:245
double min_mass_kinematic() const
The minimum mass of the resonance that is kinematically allowed.
PdgCode pdgcode() const
Definition: particletype.h:156
static bool exists(PdgCode pdgcode)
static void check_consistency()
double max_factor2_
Maximum factor for double-res mass sampling, cf. sample_resonance_masses.
Definition: particletype.h:654
const std::string & name() const
Definition: particletype.h:141
double min_mass_kinematic_
minimum kinematically allowed mass of the particle Mutable, because it is initialized at first call o...
Definition: particletype.h:630
ParticleType & operator=(const ParticleType &)=delete
assignment is not allowed, see copy constructor above
int32_t charge() const
The charge of the particle.
Definition: particletype.h:188
int antiparticle_sign() const
Definition: particletype.h:165
double spectral_function_no_norm(double m) const
Full spectral function without normalization factor.
static ParticleTypePtrList & list_nucleons()
Definition: particletype.cc:69
bool is_rho() const
Definition: particletype.h:224
ParticleType & operator=(ParticleType &&)=default
move ctors are needed for std::sort
bool is_hadron() const
Definition: particletype.h:197
unsigned int spin_degeneracy() const
Definition: particletype.h:194
static ParticleTypePtrList & list_anti_nucleons()
Definition: particletype.cc:71
bool is_Nstar1535() const
Definition: particletype.h:233
static const ParticleTypeList & list_all()
Definition: particletype.cc:51
bool is_stable() const
Definition: particletype.h:242
int isospin_
Isospin of the particle; filled automatically from pdgcode_.
Definition: particletype.h:644
ParticleType(const ParticleType &)=delete
Copies are not allowed as they break intended use.
bool is_dprime() const
Definition: particletype.h:254
double isospin3_rel() const
Definition: particletype.h:179
double width_
width of the particle
Definition: particletype.h:619
bool operator<(const ParticleType &rhs) const
"Less than" operator for sorting the ParticleType list (by PDG code)
Definition: particletype.h:552
bool is_Delta() const
Definition: particletype.h:221
double spectral_function_simple(double m) const
This one is the most simple form of the spectral function, using a Cauchy distribution (non-relativis...
bool operator!=(const ParticleType &rhs) const
Definition: particletype.h:543
double width_at_pole() const
Definition: particletype.h:150
static ParticleTypePtrList & list_anti_Deltas()
Definition: particletype.cc:77
PdgCode pdgcode_
PDG Code of the particle.
Definition: particletype.h:623
bool has_antiparticle() const
Definition: particletype.h:159
ParticleType(std::string n, double m, double w, Parity p, PdgCode id)
Creates a fully initialized ParticleType object.
bool is_nucleon() const
Definition: particletype.h:215
double mass() const
Definition: particletype.h:144
static ParticleTypePtrList & list_baryon_resonances()
Definition: particletype.cc:81
static constexpr double width_cutoff
Decay width cutoff for considering a particle as stable.
Definition: particletype.h:107
DecayBranchList get_partial_widths(const FourVector p, const ThreeVector x, WhichDecaymodes wh) const
Get all the mass-dependent partial decay widths of a particle with mass m.
static ParticleTypePtrList & list_Deltas()
Definition: particletype.cc:75
bool is_lepton() const
Definition: particletype.h:200
bool is_deuteron() const
Definition: particletype.h:248
bool is_meson() const
Definition: particletype.h:206
int32_t charge_
Charge of the particle; filled automatically from pdgcode_.
Definition: particletype.h:642
double get_partial_in_width(const double m, const ParticleData &p_a, const ParticleData &p_b) const
Get the mass-dependent partial in-width of a resonance with mass m, decaying into two given daughter ...
static void create_type_list(const std::string &particles)
Initialize the global ParticleType list (list_all) from the given input data.
int isospin() const
Returns twice the isospin vector length .
unsigned int spin() const
Definition: particletype.h:191
double norm_factor_
This normalization factor ensures that the spectral function is normalized to unity,...
Definition: particletype.h:640
int baryon_number() const
Definition: particletype.h:209
ParticleTypePtr operator&() const
Returns an object that acts like a pointer, except that it requires only 2 bytes and inhibits pointer...
Definition: particletype.cc:57
bool operator==(const ParticleType &rhs) const
Definition: particletype.h:536
double max_factor1_
Maximum factor for single-res mass sampling, cf. sample_resonance_mass.
Definition: particletype.h:652
double spectral_function_const_width(double m) const
ParticleType(ParticleType &&)=default
move ctors are needed for std::sort
bool is_Deltastar() const
Definition: particletype.h:236
std::pair< double, double > sample_resonance_masses(const ParticleType &t2, const double cms_energy, int L=0) const
Resonance mass sampling for 2-particle final state with two resonances.
IsoParticleType * iso_multiplet() const
Definition: particletype.h:185
double mass_sqr() const
Definition: particletype.h:147
static ParticleTypePtrList & list_light_nuclei()
Definition: particletype.cc:85
double partial_width(const double m, const DecayBranch *mode) const
Get the mass-dependent partial decay width of a particle with mass m in a particular decay mode.
Parity parity() const
Definition: particletype.h:153
double mass_
pole mass of the particle
Definition: particletype.h:617
PdgCode stores a Particle Data Group Particle Numbering Scheme particle type number.
Definition: pdgcode.h:110
bool is_Nstar1535() const
Definition: pdgcode.h:414
bool is_rho() const
Definition: pdgcode.h:468
int antiparticle_sign() const
Definition: pdgcode.h:650
int baryon_number() const
Definition: pdgcode.h:380
bool is_meson() const
Definition: pdgcode.h:393
unsigned int spin() const
Definition: pdgcode.h:607
bool is_pion() const
Definition: pdgcode.h:456
bool is_lepton() const
Definition: pdgcode.h:374
bool is_nucleus() const
Definition: pdgcode.h:363
bool is_deuteron() const
Definition: pdgcode.h:474
int charmness() const
Definition: pdgcode.h:549
int strangeness() const
Definition: pdgcode.h:542
int32_t get_decimal() const
Definition: pdgcode.h:768
bool is_baryon() const
Definition: pdgcode.h:390
bool is_nucleon() const
Definition: pdgcode.h:396
PdgCode get_antiparticle() const
Construct the antiparticle to a given PDG code.
Definition: pdgcode.h:331
bool is_hadron() const
Definition: pdgcode.h:369
bool is_triton() const
Definition: pdgcode.h:480
bool is_Delta() const
Definition: pdgcode.h:420
bool has_antiparticle() const
Definition: pdgcode.h:489
unsigned int spin_degeneracy() const
Definition: pdgcode.h:643
The ThreeVector class represents a physical three-vector with the components .
Definition: threevector.h:31
friend std::ostream & operator<<(std::ostream &out, const ParticleType &type)
Writes all information about the particle type to the output stream.
constexpr int p
Proton.
constexpr int n
Neutron.
Definition: action.h:24
void operator*=(Parity &x, Parity y)
Definition: particletype.h:75
EnergyMomentumTensor operator-(EnergyMomentumTensor a, const EnergyMomentumTensor &b)
Direct subtraction operator.
Parity
Represent the parity of a particle type.
Definition: particletype.h:24
@ Neg
Negative parity.
@ Pos
Positive parity.
EnergyMomentumTensor operator*(EnergyMomentumTensor a, const double b)
Direct multiplication operator.
WhichDecaymodes
Decide which decay mode widths are returned in get partical widths.
Definition: particletype.h:32
@ Hadronic
Ignore dilepton decay modes widths.
@ Dileptons
Only return dilepton decays widths.
@ All
All decay mode widths.