Version: SMASH-2.0
particletype.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2020
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;
135  ParticleType &operator=(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_Delta() const { return pdgcode_.is_Delta(); }
219 
221  bool is_rho() const { return pdgcode_.is_rho(); }
222 
224  inline bool is_Nstar() const {
225  return is_baryon() && isospin() == 1 && !pdgcode_.is_nucleon() &&
226  pdgcode_.strangeness() == 0 && pdgcode_.charmness() == 0;
227  }
228 
230  bool is_Nstar1535() const { return pdgcode_.is_Nstar1535(); }
231 
233  inline bool is_Deltastar() const {
234  return is_baryon() && isospin() == 3 && !pdgcode_.is_Delta() &&
235  pdgcode_.strangeness() == 0 && pdgcode_.charmness() == 0;
236  }
237 
239  inline bool is_stable() const { return width_ < width_cutoff; }
240 
242  inline bool is_nucleus() const { return pdgcode_.is_nucleus(); }
243 
245  inline bool is_deuteron() const { return pdgcode_.is_deuteron(); }
246 
248  inline bool is_dprime() const {
249  return is_nucleus() && std::abs(pdgcode_.get_decimal()) == 1000010021;
250  }
251 
262  double min_mass_kinematic() const;
263 
279  double min_mass_spectral() const;
280 
289  double partial_width(const double m, const DecayBranch *mode) const;
290 
297  double total_width(const double m) const;
298 
306  bool wanted_decaymode(const DecayType &t, WhichDecaymodes wh) const;
307 
317  DecayBranchList get_partial_widths(const FourVector p, const ThreeVector x,
318  WhichDecaymodes wh) const;
319 
328  double get_partial_width(const double m,
329  const ParticleTypePtrList dlist) const;
330 
342  double get_partial_in_width(const double m, const ParticleData &p_a,
343  const ParticleData &p_b) const;
344 
359  double spectral_function(double m) const;
360 
369  double spectral_function_no_norm(double m) const;
370 
376  double spectral_function_const_width(double m) const;
377 
388  double spectral_function_simple(double m) const;
389 
400  double sample_resonance_mass(const double mass_stable,
401  const double cms_energy, int L = 0) const;
402 
413  std::pair<double, double> sample_resonance_masses(const ParticleType &t2,
414  const double cms_energy,
415  int L = 0) const;
416 
424 
432  static const ParticleTypeList &list_all();
433 
435  static ParticleTypePtrList &list_nucleons();
437  static ParticleTypePtrList &list_anti_nucleons();
442  static ParticleTypePtrList &list_Deltas();
447  static ParticleTypePtrList &list_anti_Deltas();
452  static ParticleTypePtrList &list_baryon_resonances();
457  static ParticleTypePtrList &list_light_nuclei();
458 
473  static const ParticleTypePtr try_find(PdgCode pdgcode);
474 
488  static const ParticleType &find(PdgCode pdgcode);
489 
491  struct PdgNotFoundFailure : public std::runtime_error {
492  using std::runtime_error::runtime_error;
493  };
494 
501  static bool exists(PdgCode pdgcode);
502 
509  static bool exists(const std::string &name);
510 
524  static void create_type_list(const std::string &particles);
525 
530  bool operator==(const ParticleType &rhs) const {
531  return pdgcode() == rhs.pdgcode();
532  }
537  bool operator!=(const ParticleType &rhs) const {
538  return pdgcode() != rhs.pdgcode();
539  }
546  bool operator<(const ParticleType &rhs) const {
547  return pdgcode() < rhs.pdgcode();
548  }
549 
556  static void check_consistency();
557 
599  ParticleTypePtr operator&() const;
600 
602  struct LoadFailure : public std::runtime_error {
603  using std::runtime_error::runtime_error;
604  };
605 
606  private:
608  std::string name_;
610  double mass_;
612  double width_;
623  mutable double min_mass_kinematic_;
630  mutable double min_mass_spectral_;
633  mutable double norm_factor_ = -1.;
635  int32_t charge_;
637  mutable int isospin_;
639  int I3_;
640 
643 
645  mutable double max_factor1_ = 1.;
647  mutable double max_factor2_ = 1.;
648 
655  friend std::ostream &operator<<(std::ostream &out, const ParticleType &type);
656 };
657 
666  public:
668  const ParticleType &operator*() const { return lookup(); }
669 
671  const ParticleType *operator->() const {
672  // this requires std::addressof because &lookup() would call
673  // ParticleType::operator& and return ParticleTypePtr again
674  return std::addressof(lookup());
675  }
676 
678  ParticleTypePtr() = default;
679 
684  bool operator==(const ParticleTypePtr &rhs) const {
685  return index_ == rhs.index_;
686  }
687 
692  bool operator!=(const ParticleTypePtr &rhs) const {
693  return index_ != rhs.index_;
694  }
701  bool operator<(const ParticleTypePtr &rhs) const {
702  return index_ < rhs.index_;
703  }
704 
706  operator bool() const { return index_ != 0xffff; }
707 
708  private:
715 
720  explicit ParticleTypePtr(std::uint16_t i) : index_(i) {}
721 
733  const ParticleType &lookup() const {
734  assert(index_ != 0xffff);
735  return ParticleType::list_all()[index_];
736  }
737 
743  std::uint16_t index_ = 0xffff;
744 };
745 
747  assert(has_antiparticle());
748  return &find(pdgcode_.get_antiparticle());
749 }
750 
751 } // namespace smash
752 
753 #endif // SRC_INCLUDE_SMASH_PARTICLETYPE_H_
smash::operator*=
void operator*=(Parity &x, Parity y)
Definition: particletype.h:75
smash
Definition: action.h:24
smash::ParticleType::exists
static bool exists(PdgCode pdgcode)
Definition: particletype.cc:107
smash::ParticleType::list_nucleons
static ParticleTypePtrList & list_nucleons()
Definition: particletype.cc:69
smash::PdgCode::get_antiparticle
PdgCode get_antiparticle() const
Construct the antiparticle to a given PDG code.
Definition: pdgcode.h:257
smash::ParticleType::spectral_function_no_norm
double spectral_function_no_norm(double m) const
Full spectral function without normalization factor.
Definition: particletype.cc:590
smash::ParticleType::list_anti_nucleons
static ParticleTypePtrList & list_anti_nucleons()
Definition: particletype.cc:71
smash::ParticleTypePtr::operator->
const ParticleType * operator->() const
Definition: particletype.h:671
smash::ParticleType::dump_width_and_spectral_function
void dump_width_and_spectral_function() const
Prints out width and spectral function versus mass to the standard output.
Definition: particletype.cc:723
smash::ParticleType::width_
double width_
width of the particle
Definition: particletype.h:612
smash::ParticleType::is_meson
bool is_meson() const
Definition: particletype.h:206
smash::ParticleType::width_at_pole
double width_at_pole() const
Definition: particletype.h:150
smash::ParticleType::min_mass_spectral
double min_mass_spectral() const
The minimum mass of the resonance, where the spectral function is non-zero.
Definition: particletype.cc:368
smash::DecayType
DecayType is the abstract base class for all decay types.
Definition: decaytype.h:23
smash::ParticleType::wanted_decaymode
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...
Definition: particletype.cc:454
smash::ParticleType::is_Deltastar
bool is_Deltastar() const
Definition: particletype.h:233
smash::ParticleType::iso_multiplet
IsoParticleType * iso_multiplet() const
Definition: particletype.h:185
smash::ParticleType::operator!=
bool operator!=(const ParticleType &rhs) const
Definition: particletype.h:537
smash::ParticleData
Definition: particledata.h:52
smash::PdgCode::baryon_number
int baryon_number() const
Definition: pdgcode.h:305
smash::PdgCode::is_nucleon
bool is_nucleon() const
Definition: pdgcode.h:321
smash::ParticleType::operator=
ParticleType & operator=(const ParticleType &)=delete
assignment is not allowed, see copy constructor above
smash::PdgCode::is_hadron
bool is_hadron() const
Definition: pdgcode.h:294
smash::ParticleType::list_light_nuclei
static ParticleTypePtrList & list_light_nuclei()
Definition: particletype.cc:85
smash::ParticleType::charge_
int32_t charge_
Charge of the particle; filled automatically from pdgcode_.
Definition: particletype.h:635
smash::PdgCode::spin
unsigned int spin() const
Definition: pdgcode.h:518
smash::ParticleType::is_dprime
bool is_dprime() const
Definition: particletype.h:248
smash::PdgCode::spin_degeneracy
unsigned int spin_degeneracy() const
Definition: pdgcode.h:539
smash::PdgCode::is_Delta
bool is_Delta() const
Definition: pdgcode.h:345
smash::WhichDecaymodes::All
All decay mode widths.
smash::ParticleType::operator<<
friend std::ostream & operator<<(std::ostream &out, const ParticleType &type)
Definition: particletype.cc:761
smash::ParticleType::PdgNotFoundFailure
Definition: particletype.h:491
smash::operator-
EnergyMomentumTensor operator-(EnergyMomentumTensor a, const EnergyMomentumTensor &b)
Direct subtraction operator.
Definition: energymomentumtensor.h:176
macros.h
smash::PdgCode::antiparticle_sign
int antiparticle_sign() const
Definition: pdgcode.h:546
smash::PdgCode::is_lepton
bool is_lepton() const
Definition: pdgcode.h:299
smash::ParticleType::mass
double mass() const
Definition: particletype.h:144
smash::PdgCode::is_nucleus
bool is_nucleus() const
Definition: pdgcode.h:288
smash::ParticleType::spectral_function
double spectral_function(double m) const
Full spectral function of the resonance (relativistic Breit-Wigner distribution with mass-dependent ...
Definition: particletype.cc:570
smash::ParticleType::is_lepton
bool is_lepton() const
Definition: particletype.h:200
smash::ParticleType::is_Delta
bool is_Delta() const
Definition: particletype.h:218
smash::ParticleType::isospin_
int isospin_
Isospin of the particle; filled automatically from pdgcode_.
Definition: particletype.h:637
smash::ParticleType::get_partial_in_width
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 ...
Definition: particletype.cc:551
smash::ParticleType::antiparticle_sign
int antiparticle_sign() const
Definition: particletype.h:165
smash::ParticleType::create_type_list
static void create_type_list(const std::string &particles)
Initialize the global ParticleType list (list_all) from the given input data.
Definition: particletype.cc:199
smash::ParticleTypePtr::ParticleTypePtr
ParticleTypePtr()=default
Default construction initializes with an invalid index.
smash::ParticleType::pdgcode
PdgCode pdgcode() const
Definition: particletype.h:156
smash::ParticleType::name_
std::string name_
name of the particle
Definition: particletype.h:608
smash::ParticleType::spin
unsigned int spin() const
Definition: particletype.h:191
smash::PdgCode::is_rho
bool is_rho() const
Definition: pdgcode.h:387
smash::ParticleType::operator&
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
smash::ParticleType::min_mass_kinematic_
double min_mass_kinematic_
minimum kinematically allowed mass of the particle Mutable, because it is initialized at first call o...
Definition: particletype.h:623
smash::ParticleType::list_anti_Deltas
static ParticleTypePtrList & list_anti_Deltas()
Definition: particletype.cc:77
smash::ParticleType::is_baryon
bool is_baryon() const
Definition: particletype.h:203
smash::ParticleType::list_Deltas
static ParticleTypePtrList & list_Deltas()
Definition: particletype.cc:75
smash::ParticleType::total_width
double total_width(const double m) const
Get the mass-dependent total width of a particle with mass m.
Definition: particletype.cc:429
smash::ParticleType::find
static const ParticleType & find(PdgCode pdgcode)
Returns the ParticleType object for the given pdgcode.
Definition: particletype.cc:99
smash::PdgCode::get_decimal
int32_t get_decimal() const
Definition: pdgcode.h:663
smash::ParticleType::has_antiparticle
bool has_antiparticle() const
Definition: particletype.h:159
smash::ParticleType::decay_modes
const DecayModes & decay_modes() const
Definition: particletype.cc:422
smash::DecayBranch
Definition: processbranch.h:329
smash::ParticleType::spin_degeneracy
unsigned int spin_degeneracy() const
Definition: particletype.h:194
forwarddeclarations.h
smash::ParticleTypePtr
Definition: particletype.h:665
smash::ParticleType::norm_factor_
double norm_factor_
This normalization factor ensures that the spectral function is normalized to unity,...
Definition: particletype.h:633
smash::ThreeVector
Definition: threevector.h:31
smash::ParticleType::iso_multiplet_
IsoParticleType * iso_multiplet_
Container for the isospin multiplet information.
Definition: particletype.h:642
smash::ParticleType::get_partial_widths
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.
Definition: particletype.cc:486
smash::ParticleTypePtr::lookup
const ParticleType & lookup() const
Helper function that does the ParticleType lookup from the stored index.
Definition: particletype.h:733
smash::ParticleType::isospin
int isospin() const
Returns twice the isospin vector length .
Definition: particletype.cc:404
smash::ParticleType::I3_
int I3_
Isospin projection of the particle; filled automatically from pdgcode_.
Definition: particletype.h:639
smash::WhichDecaymodes::Hadronic
Ignore dilepton decay modes widths.
smash::ParticleType::is_nucleus
bool is_nucleus() const
Definition: particletype.h:242
smash::ParticleType::is_deuteron
bool is_deuteron() const
Definition: particletype.h:245
smash::IsoParticleType
Definition: isoparticletype.h:28
smash::ParticleType::sample_resonance_masses
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.
Definition: particletype.cc:672
smash::ParticleType::is_hadron
bool is_hadron() const
Definition: particletype.h:197
smash::ParticleType::is_stable
bool is_stable() const
Definition: particletype.h:239
smash::ParticleType::sample_resonance_mass
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 ...
Definition: particletype.cc:615
smash::WhichDecaymodes
WhichDecaymodes
Decide which decay mode widths are returned in get partical widths.
Definition: particletype.h:32
smash::ParticleType::isospin3_rel
double isospin3_rel() const
Definition: particletype.h:179
smash::ParticleTypePtr::ParticleTypePtr
ParticleTypePtr(std::uint16_t i)
Constructs a pointer to the ParticleType object at offset i.
Definition: particletype.h:720
smash::ParticleType
Definition: particletype.h:97
smash::ParticleType::spectral_function_simple
double spectral_function_simple(double m) const
This one is the most simple form of the spectral function, using a Cauchy distribution (non-relativis...
Definition: particletype.cc:610
smash::ParticleType::name
const std::string & name() const
Definition: particletype.h:141
smash::ParticleTypePtr::operator<
bool operator<(const ParticleTypePtr &rhs) const
"Less than" operator
Definition: particletype.h:701
smash::ParticleType::LoadFailure
Definition: particletype.h:602
smash::PdgCode
Definition: pdgcode.h:108
smash::ParticleType::pdgcode_
PdgCode pdgcode_
PDG Code of the particle.
Definition: particletype.h:616
smash::ParticleType::try_find
static const ParticleTypePtr try_find(PdgCode pdgcode)
Returns the ParticleTypePtr for the given pdgcode.
Definition: particletype.cc:89
smash::ParticleType::ParticleType
ParticleType(std::string n, double m, double w, Parity p, PdgCode id)
Creates a fully initialized ParticleType object.
Definition: particletype.cc:122
smash::ParticleType::parity_
Parity parity_
Parity of the particle.
Definition: particletype.h:614
smash::ParticleType::check_consistency
static void check_consistency()
Definition: particletype.cc:445
smash::ParticleType::is_rho
bool is_rho() const
Definition: particletype.h:221
smash::ParticleType::operator<
bool operator<(const ParticleType &rhs) const
"Less than" operator for sorting the ParticleType list (by PDG code)
Definition: particletype.h:546
smash::ParticleType::mass_sqr
double mass_sqr() const
Definition: particletype.h:147
smash::ParticleType::get_antiparticle
ParticleTypePtr get_antiparticle() const
Definition: particletype.h:746
smash::ParticleType::isospin3
int isospin3() const
Definition: particletype.h:176
smash::ParticleTypePtr::index_
std::uint16_t index_
Stores the index of the references ParticleType object in the global vector.
Definition: particletype.h:743
smash::ParticleType::max_factor2_
double max_factor2_
Maximum factor for double-res mass sampling, cf. sample_resonance_masses.
Definition: particletype.h:647
smash::ParticleTypePtr::operator*
const ParticleType & operator*() const
Definition: particletype.h:668
smash::Parity::Pos
Positive parity.
smash::ParticleType::get_partial_width
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...
Definition: particletype.cc:535
smash::PdgCode::charmness
int charmness() const
Definition: pdgcode.h:462
smash::DecayModes
Definition: decaymodes.h:29
smash::ParticleType::is_Nstar1535
bool is_Nstar1535() const
Definition: particletype.h:230
smash::ParticleType::partial_width
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.
Definition: particletype.cc:413
smash::PdgCode::strangeness
int strangeness() const
Definition: pdgcode.h:455
smash::PdgCode::is_deuteron
bool is_deuteron() const
Definition: pdgcode.h:393
smash::ParticleTypePtr::operator!=
bool operator!=(const ParticleTypePtr &rhs) const
Definition: particletype.h:692
pdgcode.h
smash::ParticleType::min_mass_spectral_
double min_mass_spectral_
minimum mass, where the spectral function is non-zero Mutable, because it is initialized at first cal...
Definition: particletype.h:630
smash::ParticleType::strangeness
int strangeness() const
Definition: particletype.h:212
smash::ParticleType::is_Nstar
bool is_Nstar() const
Definition: particletype.h:224
smash::ParticleType::spectral_function_const_width
double spectral_function_const_width(double m) const
Definition: particletype.cc:600
smash::ParticleType::max_factor1_
double max_factor1_
Maximum factor for single-res mass sampling, cf. sample_resonance_mass.
Definition: particletype.h:645
smash::FourVector
Definition: fourvector.h:33
smash::Parity
Parity
Represent the parity of a particle type.
Definition: particletype.h:24
smash::pdg::p
constexpr int p
Proton.
Definition: pdgcode_constants.h:28
smash::PdgCode::is_baryon
bool is_baryon() const
Definition: pdgcode.h:315
smash::PdgCode::has_antiparticle
bool has_antiparticle() const
Definition: pdgcode.h:402
smash::pdg::n
constexpr int n
Neutron.
Definition: pdgcode_constants.h:30
smash::ParticleType::list_baryon_resonances
static ParticleTypePtrList & list_baryon_resonances()
Definition: particletype.cc:81
smash::ParticleType::min_mass_kinematic
double min_mass_kinematic() const
The minimum mass of the resonance that is kinematically allowed.
Definition: particletype.cc:354
smash::ParticleType::mass_
double mass_
pole mass of the particle
Definition: particletype.h:610
smash::ParticleType::operator==
bool operator==(const ParticleType &rhs) const
Definition: particletype.h:530
smash::operator*
EnergyMomentumTensor operator*(EnergyMomentumTensor a, const double b)
Direct multiplication operator.
Definition: energymomentumtensor.h:189
smash::WhichDecaymodes::Dileptons
Only return dilepton decays widths.
smash::Parity::Neg
Negative parity.
smash::PdgCode::is_Nstar1535
bool is_Nstar1535() const
Definition: pdgcode.h:339
smash::ParticleType::width_cutoff
static constexpr double width_cutoff
Decay width cutoff for considering a particle as stable.
Definition: particletype.h:107
smash::ParticleTypePtr::operator==
bool operator==(const ParticleTypePtr &rhs) const
Definition: particletype.h:684
smash::ParticleType::list_all
static const ParticleTypeList & list_all()
Definition: particletype.cc:51
smash::ParticleType::charge
int32_t charge() const
The charge of the particle.
Definition: particletype.h:188
smash::PdgCode::is_meson
bool is_meson() const
Definition: pdgcode.h:318
smash::ParticleType::parity
Parity parity() const
Definition: particletype.h:153
smash::ParticleType::baryon_number
int baryon_number() const
Definition: particletype.h:209
smash::ParticleType::is_nucleon
bool is_nucleon() const
Definition: particletype.h:215