Version: SMASH-3.1
particletype.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2021,2023-2024
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_Deltastar() const {
241  return is_baryon() && isospin() == 3 && !pdgcode_.is_Delta() &&
242  pdgcode_.strangeness() == 0 && pdgcode_.charmness() == 0;
243  }
244 
246  inline bool is_stable() const { return width_ < width_cutoff; }
247 
249  inline bool is_nucleus() const { return pdgcode_.is_nucleus(); }
250 
252  inline bool is_deuteron() const { return pdgcode_.is_deuteron(); }
253 
255  inline bool is_triton() const { return pdgcode_.is_triton(); }
256 
258  inline bool is_dprime() const {
259  return is_nucleus() && std::abs(pdgcode_.get_decimal()) == 1000010021;
260  }
261 
272  double min_mass_kinematic() const;
273 
289  double min_mass_spectral() const;
290 
299  double partial_width(const double m, const DecayBranch *mode) const;
300 
307  double total_width(const double m) const;
308 
316  bool wanted_decaymode(const DecayType &t, WhichDecaymodes wh) const;
317 
327  DecayBranchList get_partial_widths(const FourVector p, const ThreeVector x,
328  WhichDecaymodes wh) const;
329 
338  double get_partial_width(const double m,
339  const ParticleTypePtrList dlist) const;
340 
352  double get_partial_in_width(const double m, const ParticleData &p_a,
353  const ParticleData &p_b) const;
354 
369  double spectral_function(double m) const;
370 
379  double spectral_function_no_norm(double m) const;
380 
386  double spectral_function_const_width(double m) const;
387 
398  double spectral_function_simple(double m) const;
399 
410  double sample_resonance_mass(const double mass_stable,
411  const double cms_energy, int L = 0) const;
412 
423  std::pair<double, double> sample_resonance_masses(const ParticleType &t2,
424  const double cms_energy,
425  int L = 0) const;
426 
434 
442  static const ParticleTypeList &list_all();
443 
445  static ParticleTypePtrList &list_nucleons();
447  static ParticleTypePtrList &list_anti_nucleons();
452  static ParticleTypePtrList &list_Deltas();
457  static ParticleTypePtrList &list_anti_Deltas();
462  static ParticleTypePtrList &list_baryon_resonances();
467  static ParticleTypePtrList &list_light_nuclei();
468 
483  static const ParticleTypePtr try_find(PdgCode pdgcode);
484 
498  static const ParticleType &find(PdgCode pdgcode);
499 
501  struct PdgNotFoundFailure : public std::runtime_error {
502  using std::runtime_error::runtime_error;
503  };
504 
511  static bool exists(PdgCode pdgcode);
512 
519  static bool exists(const std::string &name);
520 
534  static void create_type_list(const std::string &particles);
535 
540  bool operator==(const ParticleType &rhs) const {
541  return pdgcode() == rhs.pdgcode();
542  }
547  bool operator!=(const ParticleType &rhs) const {
548  return pdgcode() != rhs.pdgcode();
549  }
556  bool operator<(const ParticleType &rhs) const {
557  return pdgcode() < rhs.pdgcode();
558  }
559 
567  static void check_consistency();
568 
610  ParticleTypePtr operator&() const;
611 
613  struct LoadFailure : public std::runtime_error {
614  using std::runtime_error::runtime_error;
615  };
616 
617  private:
619  std::string name_;
621  double mass_;
623  double width_;
634  mutable double min_mass_kinematic_;
641  mutable double min_mass_spectral_;
644  mutable double norm_factor_ = -1.;
646  int32_t charge_;
648  mutable int isospin_;
650  int I3_;
651 
654 
656  mutable double max_factor1_ = 1.;
658  mutable double max_factor2_ = 1.;
659 
666  friend std::ostream &operator<<(std::ostream &out, const ParticleType &type);
667 };
668 
677  public:
679  const ParticleType &operator*() const { return lookup(); }
680 
682  const ParticleType *operator->() const {
683  // this requires std::addressof because &lookup() would call
684  // ParticleType::operator& and return ParticleTypePtr again
685  return std::addressof(lookup());
686  }
687 
689  ParticleTypePtr() = default;
690 
695  bool operator==(const ParticleTypePtr &rhs) const {
696  return index_ == rhs.index_;
697  }
698 
703  bool operator!=(const ParticleTypePtr &rhs) const {
704  return index_ != rhs.index_;
705  }
712  bool operator<(const ParticleTypePtr &rhs) const {
713  return index_ < rhs.index_;
714  }
715 
717  operator bool() const { return index_ != 0xffff; }
718 
719  private:
726 
731  explicit ParticleTypePtr(std::uint16_t i) : index_(i) {}
732 
744  const ParticleType &lookup() const {
745  assert(index_ != 0xffff);
746  return ParticleType::list_all()[index_];
747  }
748 
754  std::uint16_t index_ = 0xffff;
755 };
756 
758  assert(has_antiparticle());
759  return &find(pdgcode_.get_antiparticle());
760 }
761 
773 ParticleTypePtrList list_possible_resonances(const ParticleTypePtr type_a,
774  const ParticleTypePtr type_b);
775 
776 } // namespace smash
777 
778 #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:676
bool operator==(const ParticleTypePtr &rhs) const
Definition: particletype.h:695
const ParticleType & operator*() const
Definition: particletype.h:679
bool operator<(const ParticleTypePtr &rhs) const
"Less than" operator
Definition: particletype.h:712
ParticleTypePtr()=default
Default construction initializes with an invalid index.
bool operator!=(const ParticleTypePtr &rhs) const
Definition: particletype.h:703
const ParticleType & lookup() const
Helper function that does the ParticleType lookup from the stored index.
Definition: particletype.h:744
std::uint16_t index_
Stores the index of the references ParticleType object in the global vector.
Definition: particletype.h:754
const ParticleType * operator->() const
Definition: particletype.h:682
ParticleTypePtr(std::uint16_t i)
Constructs a pointer to the ParticleType object at offset i.
Definition: particletype.h:731
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:641
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:653
int I3_
Isospin projection of the particle; filled automatically from pdgcode_.
Definition: particletype.h:650
bool is_triton() const
Definition: particletype.h:255
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:625
int isospin3() const
Definition: particletype.h:177
std::string name_
name of the particle
Definition: particletype.h:619
ParticleTypePtr get_antiparticle() const
Definition: particletype.h:757
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:249
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:658
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:634
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:246
int isospin_
Isospin of the particle; filled automatically from pdgcode_.
Definition: particletype.h:648
ParticleType(const ParticleType &)=delete
Copies are not allowed as they break intended use.
bool is_dprime() const
Definition: particletype.h:258
double isospin3_rel() const
Definition: particletype.h:180
double width_
width of the particle
Definition: particletype.h:623
bool operator<(const ParticleType &rhs) const
"Less than" operator for sorting the ParticleType list (by PDG code)
Definition: particletype.h:556
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:547
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:627
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.
static ParticleTypePtrList & list_Deltas()
Definition: particletype.cc:75
bool is_lepton() const
Definition: particletype.h:201
bool is_deuteron() const
Definition: particletype.h:252
bool is_meson() const
Definition: particletype.h:207
int32_t charge_
Charge of the particle; filled automatically from pdgcode_.
Definition: particletype.h:646
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:644
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:540
double max_factor1_
Maximum factor for single-res mass sampling, cf. sample_resonance_mass.
Definition: particletype.h:656
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:240
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
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:621
PdgCode stores a Particle Data Group Particle Numbering Scheme particle type number.
Definition: pdgcode.h:111
bool is_Nstar1535() const
Definition: pdgcode.h:415
bool is_rho() const
Definition: pdgcode.h:469
int antiparticle_sign() const
Definition: pdgcode.h:651
int baryon_number() const
Definition: pdgcode.h:381
bool is_meson() const
Definition: pdgcode.h:394
unsigned int spin() const
Definition: pdgcode.h:608
bool is_pion() const
Definition: pdgcode.h:457
bool is_kaon() const
Definition: pdgcode.h:451
bool is_lepton() const
Definition: pdgcode.h:375
bool is_nucleus() const
Definition: pdgcode.h:364
bool is_deuteron() const
Definition: pdgcode.h:475
int charmness() const
Definition: pdgcode.h:550
int strangeness() const
Definition: pdgcode.h:543
int32_t get_decimal() const
Definition: pdgcode.h:769
bool is_baryon() const
Definition: pdgcode.h:391
bool is_nucleon() const
Definition: pdgcode.h:397
PdgCode get_antiparticle() const
Construct the antiparticle to a given PDG code.
Definition: pdgcode.h:332
bool is_hadron() const
Definition: pdgcode.h:370
bool is_triton() const
Definition: pdgcode.h:481
bool is_Delta() const
Definition: pdgcode.h:421
bool has_antiparticle() const
Definition: pdgcode.h:490
unsigned int spin_degeneracy() const
Definition: pdgcode.h:644
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.