Version: SMASH-3.3
particletype.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2021,2023-2025
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 <cstdint>
12 #include <string>
13 #include <utility>
14 #include <vector>
15 
16 #include "forwarddeclarations.h"
17 #include "macros.h"
18 #include "pdgcode.h"
19 
20 namespace smash {
21 
25 enum class Parity {
27  Pos,
29  Neg
30 };
31 
33 enum class WhichDecaymodes {
35  All,
37  Hadronic,
39  Dileptons
40 };
41 
47  switch (p) {
48  case Parity::Pos:
49  return Parity::Neg;
50  case Parity::Neg:
51  return Parity::Pos;
52  }
53  // This is unreachable and should be optimized away.
54  // It is required to silence a compiler warning.
55  throw std::runtime_error("unreachable");
56 }
57 
63 inline Parity operator*(Parity x, Parity y) {
64  if (x == y) {
65  return Parity::Pos;
66  } else {
67  return Parity::Neg;
68  }
69 }
70 
76 inline void operator*=(Parity &x, Parity y) {
77  if (x == y) {
78  x = Parity::Pos;
79  } else {
80  x = Parity::Neg;
81  }
82 }
83 
98 class ParticleType {
99  public:
106  // If this is changed, make sure to update the userguide in
107  // `include/configuration.h`.
108  static constexpr double width_cutoff = 1e-5;
109 
123  ParticleType(std::string n, double m, double w, Parity p, PdgCode id);
124 
129  ParticleType(const ParticleType &) = delete;
131  ParticleType &operator=(const ParticleType &) = delete;
132 
134  ParticleType(ParticleType &&) = default;
137 
139  const DecayModes &decay_modes() const;
140 
142  const std::string &name() const { return name_; }
143 
145  double mass() const { return mass_; }
146 
148  double mass_sqr() const { return mass_ * mass_; }
149 
151  double width_at_pole() const { return width_; }
152 
154  Parity parity() const { return parity_; }
155 
157  PdgCode pdgcode() const { return pdgcode_; }
158 
160  bool has_antiparticle() const { return pdgcode_.has_antiparticle(); }
161 
164 
166  int antiparticle_sign() const { return pdgcode_.antiparticle_sign(); }
167 
174  int isospin() const;
175 
177  int isospin3() const { return I3_; }
178 
180  double isospin3_rel() const {
181  unsigned int I = isospin();
182  return (I == 0) ? 0 : static_cast<double>(isospin3()) / I;
183  }
184 
187 
189  int32_t charge() const { return charge_; }
190 
192  unsigned int spin() const { return pdgcode_.spin(); }
193 
195  unsigned int spin_degeneracy() const { return pdgcode_.spin_degeneracy(); }
196 
198  bool is_hadron() const { return pdgcode_.is_hadron(); }
199 
201  bool is_lepton() const { return pdgcode_.is_lepton(); }
202 
204  bool is_baryon() const { return pdgcode_.is_baryon(); }
205 
207  bool is_meson() const { return pdgcode_.is_meson(); }
208 
210  int baryon_number() const { return pdgcode_.baryon_number(); }
211 
213  int strangeness() const { return pdgcode_.strangeness(); }
214 
216  bool is_nucleon() const { return pdgcode_.is_nucleon(); }
217 
219  bool is_pion() const { return pdgcode_.is_pion(); }
220 
222  bool is_kaon() const { return pdgcode_.is_kaon(); }
223 
225  bool is_Delta() const { return pdgcode_.is_Delta(); }
226 
228  bool is_rho() const { return pdgcode_.is_rho(); }
229 
231  inline bool is_Nstar() const {
232  return is_baryon() && isospin() == 1 && !pdgcode_.is_nucleon() &&
233  pdgcode_.strangeness() == 0 && pdgcode_.charmness() == 0;
234  }
235 
237  bool is_Nstar1535() const { return pdgcode_.is_Nstar1535(); }
238 
240  inline bool is_Sigmastar() const { return pdgcode_.is_Sigmastar(); }
241 
243  inline bool is_Deltastar() const {
244  return is_baryon() && isospin() == 3 && !pdgcode_.is_Delta() &&
245  pdgcode_.strangeness() == 0 && pdgcode_.charmness() == 0;
246  }
247 
249  inline bool is_stable() const { return width_ < width_cutoff; }
250 
252  inline bool is_nucleus() const { return pdgcode_.is_nucleus(); }
253 
255  inline bool is_deuteron() const { return pdgcode_.is_deuteron(); }
256 
258  inline bool is_triton() const { return pdgcode_.is_triton(); }
259 
261  inline bool is_dprime() const {
262  return is_nucleus() && std::abs(pdgcode_.get_decimal()) == 1000010021;
263  }
264 
266  inline bool is_charmonia() const { return pdgcode_.is_charmonia(); }
267 
278  double min_mass_kinematic() const;
279 
295  double min_mass_spectral() const;
296 
305  double partial_width(const double m, const DecayBranch *mode) const;
306 
313  double total_width(const double m) const;
314 
322  bool wanted_decaymode(const DecayType &t, WhichDecaymodes wh) const;
323 
333  DecayBranchList get_partial_widths(const FourVector p, const ThreeVector x,
334  WhichDecaymodes wh) const;
335 
344  double get_partial_width(const double m,
345  const ParticleTypePtrList dlist) const;
346 
358  double get_partial_in_width(const double m, const ParticleData &p_a,
359  const ParticleData &p_b) const;
360 
375  double spectral_function(double m) const;
376 
385  double spectral_function_no_norm(double m) const;
386 
392  double spectral_function_const_width(double m) const;
393 
404  double spectral_function_simple(double m) const;
405 
416  double sample_resonance_mass(const double mass_stable,
417  const double cms_energy, int L = 0) const;
418 
429  std::pair<double, double> sample_resonance_masses(const ParticleType &t2,
430  const double cms_energy,
431  int L = 0) const;
432 
440 
448  static const ParticleTypeList &list_all();
449 
451  static ParticleTypePtrList &list_nucleons();
453  static ParticleTypePtrList &list_anti_nucleons();
458  static ParticleTypePtrList &list_Deltas();
463  static ParticleTypePtrList &list_anti_Deltas();
468  static ParticleTypePtrList &list_baryon_resonances();
473  static ParticleTypePtrList &list_light_nuclei();
474 
489  static const ParticleTypePtr try_find(PdgCode pdgcode);
490 
504  static const ParticleType &find(PdgCode pdgcode);
505 
507  struct PdgNotFoundFailure : public std::runtime_error {
508  using std::runtime_error::runtime_error;
509  };
510 
517  static bool exists(PdgCode pdgcode);
518 
525  static bool exists(const std::string &name);
526 
540  static void create_type_list(const std::string &particles);
541 
546  bool operator==(const ParticleType &rhs) const {
547  return pdgcode() == rhs.pdgcode();
548  }
553  bool operator!=(const ParticleType &rhs) const {
554  return pdgcode() != rhs.pdgcode();
555  }
562  bool operator<(const ParticleType &rhs) const {
563  return pdgcode() < rhs.pdgcode();
564  }
565 
573  static void check_consistency();
574 
616  ParticleTypePtr operator&() const;
617 
619  struct LoadFailure : public std::runtime_error {
620  using std::runtime_error::runtime_error;
621  };
622 
623  private:
625  std::string name_;
627  double mass_;
629  double width_;
640  mutable double min_mass_kinematic_;
647  mutable double min_mass_spectral_;
650  mutable double norm_factor_ = -1.;
652  int32_t charge_;
654  mutable int isospin_;
656  int I3_;
657 
660 
662  mutable double max_factor1_ = 1.;
664  mutable double max_factor2_ = 1.;
665 
672  friend std::ostream &operator<<(std::ostream &out, const ParticleType &type);
673 };
674 
683  public:
685  const ParticleType &operator*() const { return lookup(); }
686 
688  const ParticleType *operator->() const {
689  // this requires std::addressof because &lookup() would call
690  // ParticleType::operator& and return ParticleTypePtr again
691  return std::addressof(lookup());
692  }
693 
695  ParticleTypePtr() = default;
696 
701  bool operator==(const ParticleTypePtr &rhs) const {
702  return index_ == rhs.index_;
703  }
704 
709  bool operator!=(const ParticleTypePtr &rhs) const {
710  return index_ != rhs.index_;
711  }
718  bool operator<(const ParticleTypePtr &rhs) const {
719  return index_ < rhs.index_;
720  }
721 
723  operator bool() const { return index_ != 0xffff; }
724 
725  private:
732 
737  explicit ParticleTypePtr(std::uint16_t i) : index_(i) {}
738 
750  const ParticleType &lookup() const {
751  assert(index_ != 0xffff);
752  return ParticleType::list_all()[index_];
753  }
754 
760  std::uint16_t index_ = 0xffff;
761 };
762 
764  assert(has_antiparticle());
765  return &find(pdgcode_.get_antiparticle());
766 }
767 
779 ParticleTypePtrList list_possible_resonances(const ParticleTypePtr type_a,
780  const ParticleTypePtr type_b);
781 
782 } // namespace smash
783 
784 #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:59
A pointer-like interface to global references to ParticleType objects.
Definition: particletype.h:682
bool operator==(const ParticleTypePtr &rhs) const
Definition: particletype.h:701
const ParticleType & operator*() const
Definition: particletype.h:685
bool operator<(const ParticleTypePtr &rhs) const
"Less than" operator
Definition: particletype.h:718
ParticleTypePtr()=default
Default construction initializes with an invalid index.
bool operator!=(const ParticleTypePtr &rhs) const
Definition: particletype.h:709
const ParticleType & lookup() const
Helper function that does the ParticleType lookup from the stored index.
Definition: particletype.h:750
std::uint16_t index_
Stores the index of the references ParticleType object in the global vector.
Definition: particletype.h:760
const ParticleType * operator->() const
Definition: particletype.h:688
ParticleTypePtr(std::uint16_t i)
Constructs a pointer to the ParticleType object at offset i.
Definition: particletype.h:737
Particle type contains the static properties of a particle species.
Definition: particletype.h:98
double min_mass_spectral_
minimum mass, where the spectral function is non-zero Mutable, because it is initialized at first cal...
Definition: particletype.h:647
bool is_pion() const
Definition: particletype.h:219
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:659
int I3_
Isospin projection of the particle; filled automatically from pdgcode_.
Definition: particletype.h:656
bool is_triton() const
Definition: particletype.h:258
bool is_baryon() const
Definition: particletype.h:204
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:631
int isospin3() const
Definition: particletype.h:177
std::string name_
name of the particle
Definition: particletype.h:625
ParticleTypePtr get_antiparticle() const
Definition: particletype.h:763
bool is_Nstar() const
Definition: particletype.h:231
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:213
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:252
double min_mass_kinematic() const
The minimum mass of the resonance that is kinematically allowed.
PdgCode pdgcode() const
Definition: particletype.h:157
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:664
const std::string & name() const
Definition: particletype.h:142
double min_mass_kinematic_
minimum kinematically allowed mass of the particle Mutable, because it is initialized at first call o...
Definition: particletype.h:640
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:189
int antiparticle_sign() const
Definition: particletype.h:166
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:228
ParticleType & operator=(ParticleType &&)=default
move ctors are needed for std::sort
bool is_hadron() const
Definition: particletype.h:198
unsigned int spin_degeneracy() const
Definition: particletype.h:195
static ParticleTypePtrList & list_anti_nucleons()
Definition: particletype.cc:71
bool is_Nstar1535() const
Definition: particletype.h:237
static const ParticleTypeList & list_all()
Definition: particletype.cc:51
bool is_stable() const
Definition: particletype.h:249
int isospin_
Isospin of the particle; filled automatically from pdgcode_.
Definition: particletype.h:654
ParticleType(const ParticleType &)=delete
Copies are not allowed as they break intended use.
bool is_dprime() const
Definition: particletype.h:261
double isospin3_rel() const
Definition: particletype.h:180
double width_
width of the particle
Definition: particletype.h:629
bool operator<(const ParticleType &rhs) const
"Less than" operator for sorting the ParticleType list (by PDG code)
Definition: particletype.h:562
bool is_Delta() const
Definition: particletype.h:225
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:553
double width_at_pole() const
Definition: particletype.h:151
static ParticleTypePtrList & list_anti_Deltas()
Definition: particletype.cc:77
PdgCode pdgcode_
PDG Code of the particle.
Definition: particletype.h:633
bool has_antiparticle() const
Definition: particletype.h:160
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:216
double mass() const
Definition: particletype.h:145
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:108
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.
bool is_Sigmastar() const
Definition: particletype.h:240
static ParticleTypePtrList & list_Deltas()
Definition: particletype.cc:75
bool is_lepton() const
Definition: particletype.h:201
bool is_deuteron() const
Definition: particletype.h:255
bool is_meson() const
Definition: particletype.h:207
int32_t charge_
Charge of the particle; filled automatically from pdgcode_.
Definition: particletype.h:652
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 ...
bool is_kaon() const
Definition: particletype.h:222
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:192
double norm_factor_
This normalization factor ensures that the spectral function is normalized to unity,...
Definition: particletype.h:650
int baryon_number() const
Definition: particletype.h:210
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:546
double max_factor1_
Maximum factor for single-res mass sampling, cf. sample_resonance_mass.
Definition: particletype.h:662
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:243
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:186
double mass_sqr() const
Definition: particletype.h:148
static ParticleTypePtrList & list_light_nuclei()
Definition: particletype.cc:85
bool is_charmonia() const
Definition: particletype.h:266
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:154
double mass_
pole mass of the particle
Definition: particletype.h:627
PdgCode stores a Particle Data Group Particle Numbering Scheme particle type number.
Definition: pdgcode.h:108
bool is_Nstar1535() const
Definition: pdgcode.h:422
bool is_rho() const
Definition: pdgcode.h:483
int antiparticle_sign() const
Definition: pdgcode.h:719
int baryon_number() const
Definition: pdgcode.h:388
bool is_meson() const
Definition: pdgcode.h:401
bool is_charmonia() const
Definition: pdgcode.h:383
unsigned int spin() const
Definition: pdgcode.h:676
bool is_pion() const
Definition: pdgcode.h:471
bool is_kaon() const
Definition: pdgcode.h:465
bool is_Sigmastar() const
Definition: pdgcode.h:458
bool is_lepton() const
Definition: pdgcode.h:372
bool is_nucleus() const
Definition: pdgcode.h:361
bool is_deuteron() const
Definition: pdgcode.h:489
int charmness() const
Definition: pdgcode.h:618
int strangeness() const
Definition: pdgcode.h:611
int32_t get_decimal() const
Definition: pdgcode.h:837
bool is_baryon() const
Definition: pdgcode.h:398
bool is_nucleon() const
Definition: pdgcode.h:404
PdgCode get_antiparticle() const
Construct the antiparticle to a given PDG code.
Definition: pdgcode.h:329
bool is_hadron() const
Definition: pdgcode.h:367
bool is_triton() const
Definition: pdgcode.h:495
bool is_Delta() const
Definition: pdgcode.h:428
bool has_antiparticle() const
Definition: pdgcode.h:504
unsigned int spin_degeneracy() const
Definition: pdgcode.h:712
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
ParticleTypePtrList list_possible_resonances(const ParticleTypePtr type_a, const ParticleTypePtr type_b)
Lists the possible resonances that decay into two particles.
void operator*=(Parity &x, Parity y)
Definition: particletype.h:76
EnergyMomentumTensor operator-(EnergyMomentumTensor a, const EnergyMomentumTensor &b)
Direct subtraction operator.
Parity
Represent the parity of a particle type.
Definition: particletype.h:25
@ 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:33
@ Hadronic
Ignore dilepton decay modes widths.
@ Dileptons
Only return dilepton decays widths.
@ All
All decay mode widths.