Version: SMASH-1.6
quantumnumbers.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2014-2019
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #ifndef SRC_INCLUDE_QUANTUMNUMBERS_H_
11 #define SRC_INCLUDE_QUANTUMNUMBERS_H_
12 
13 #include <string>
14 
15 #include "particles.h"
16 
17 namespace smash {
18 
54  public:
57  : momentum_(0., 0., 0., 0.),
58  charge_(0),
59  isospin3_(0),
60  strangeness_(0),
61  charmness_(0),
62  bottomness_(0),
63  baryon_number_(0) {}
64 
75  QuantumNumbers(const FourVector& m, const int q, const int i3, const int s,
76  const int c, const int b, const int B)
77  : momentum_(m),
78  charge_(q),
79  isospin3_(i3),
80  strangeness_(s),
81  charmness_(c),
82  bottomness_(b),
83  baryon_number_(B) {}
84 
92  explicit QuantumNumbers(const Particles& particles) : QuantumNumbers() {
93  for (const ParticleData& data : particles) {
94  add_values(data);
95  }
96  }
97 
104  explicit QuantumNumbers(const ParticleList& part) : QuantumNumbers() {
105  for (const auto& p : part) {
106  add_values(p);
107  }
108  }
109 
114  void add_values(const ParticleData& p) {
115  momentum_ += p.momentum();
116  charge_ += p.pdgcode().charge();
117  isospin3_ += p.pdgcode().isospin3();
119  charmness_ += p.pdgcode().charmness();
120  bottomness_ += p.pdgcode().bottomness();
122  }
123 
131  FourVector momentum() const { return momentum_; }
132 
140  int charge() const { return charge_; }
148  int isospin3() const { return isospin3_; }
156  int strangeness() const { return strangeness_; }
164  int charmness() const { return charmness_; }
172  int bottomness() const { return bottomness_; }
180  int baryon_number() const { return baryon_number_; }
181 
191  bool operator==(const QuantumNumbers& rhs) const {
192  // clang-format off
193  // invariant mass of the current momentum
194  const double m0_invariant = std::sqrt(std::fabs(momentum_.sqr()));
195  // invariant mass of the momentum to be compared
196  const double m1_invariant = std::sqrt(std::fabs(rhs.momentum_.sqr()));
197  // average invariant mass
198  const double avg_m_inv = 0.5 * (m0_invariant + m1_invariant);
199  /* precision used to check relative error
200  * 0.1 is multiplied to make the relative error check kicks in
201  * for collision energies beyond 10 GeV. */
202  const double precision_high = 0.1 * small_number;
203  // difference in the four-momentum
204  FourVector momentum_diff = momentum_ - rhs.momentum_;
205  /* Check whether momentum is conserved.
206  * Even if the absolute difference in each component is larger than
207  * small_number, momentum is still considered to be conserved when
208  * the deviation is small enough compared to the given invariant mass. */
209  bool momentum_conserved = momentum_ == rhs.momentum_ ||
210  (std::fabs(momentum_diff.x0()) < precision_high * avg_m_inv &&
211  std::fabs(momentum_diff.x1()) < precision_high * avg_m_inv &&
212  std::fabs(momentum_diff.x2()) < precision_high * avg_m_inv &&
213  std::fabs(momentum_diff.x3()) < precision_high * avg_m_inv);
214  return (momentum_conserved &&
215  charge_ == rhs.charge_ &&
216  isospin3_ == rhs.isospin3_ &&
217  strangeness_ == rhs.strangeness_ &&
218  charmness_ == rhs.charmness_ &&
219  bottomness_ == rhs.bottomness_ &&
221  // clang-format on
222  }
224  bool operator!=(const QuantumNumbers& rhs) const { return !(*this == rhs); }
225 
234  return {momentum_ - rhs.momentum_, charge_ - rhs.charge_,
238  }
239 
248  std::string report_deviations(const Particles& particles) const {
249  QuantumNumbers current_values(particles);
250  return report_deviations(current_values);
251  }
252 
271  std::string report_deviations(const QuantumNumbers& rhs) const;
272 
273  private:
280 
286  int charge_;
317 };
318 
319 } // namespace smash
320 
321 #endif // SRC_INCLUDE_QUANTUMNUMBERS_H_
int charge() const
The charge of the particle.
Definition: pdgcode.h:470
PdgCode pdgcode() const
Get the pdgcode of the particle.
Definition: particledata.h:81
int bottomness() const
Definition: pdgcode.h:460
int charmness_
Total charm.
int bottomness_
Total bottom.
int baryon_number() const
Definition: pdgcode.h:308
int strangeness_
Total strangeness.
int baryon_number() const
QuantumNumbers(const Particles &particles)
Construct QuantumNumbers collection from the conserved quantities found in a set of particles...
int isospin3_
Total isospin-3.
int charge_
Total charge.
QuantumNumbers()
Construct QuantumNumbers collection with all fields 0.
double x0() const
Definition: fourvector.h:290
int charmness() const
Definition: pdgcode.h:453
void add_values(const ParticleData &p)
Add the quantum numbers of a single particle to the collection.
QuantumNumbers(const ParticleList &part)
Construct QuantumNumbers collection from a particle list.
std::string report_deviations(const Particles &particles) const
Checks if the current particle list has still the same values and reports about differences.
int strangeness() const
double x3() const
Definition: fourvector.h:302
bool operator!=(const QuantumNumbers &rhs) const
Logical complement of QuantumNumbers::operator==.
int strangeness() const
Definition: pdgcode.h:446
A container for storing conserved values.
QuantumNumbers(const FourVector &m, const int q, const int i3, const int s, const int c, const int b, const int B)
double sqr() const
calculate the square of the vector (which is a scalar)
Definition: fourvector.h:437
FourVector momentum_
Total momentum four-vector [GeV].
FourVector momentum() const
constexpr int p
Proton.
constexpr double small_number
Physical error tolerance.
Definition: constants.h:45
QuantumNumbers operator-(const QuantumNumbers &rhs) const
double x2() const
Definition: fourvector.h:298
The Particles class abstracts the storage and manipulation of particles.
Definition: particles.h:33
int baryon_number_
Total baryon number.
bool operator==(const QuantumNumbers &rhs) const
The FourVector class holds relevant values in Minkowski spacetime with (+, −, −, −) metric signature.
Definition: fourvector.h:32
double x1() const
Definition: fourvector.h:294
ParticleData contains the dynamic information of a certain particle.
Definition: particledata.h:52
Definition: action.h:24
const FourVector & momentum() const
Get the particle&#39;s 4-momentum.
Definition: particledata.h:139
int isospin3() const
Definition: pdgcode.h:409