Version: SMASH-3.1
quantumnumbers.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2014-2020,2022-2023
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #ifndef SRC_INCLUDE_SMASH_QUANTUMNUMBERS_H_
11 #define SRC_INCLUDE_SMASH_QUANTUMNUMBERS_H_
12 
13 #include <string>
14 #include <vector>
15 
16 #include "particles.h"
17 
18 namespace smash {
19 
55  public:
58  : momentum_(0., 0., 0., 0.),
59  charge_(0),
60  isospin3_(0),
61  strangeness_(0),
62  charmness_(0),
63  bottomness_(0),
64  baryon_number_(0) {}
65 
76  QuantumNumbers(const FourVector& m, const int q, const int i3, const int s,
77  const int c, const int b, const int B)
78  : momentum_(m),
79  charge_(q),
80  isospin3_(i3),
81  strangeness_(s),
82  charmness_(c),
83  bottomness_(b),
84  baryon_number_(B) {}
85 
93  explicit QuantumNumbers(const Particles& particles) : QuantumNumbers() {
94  for (const ParticleData& data : particles) {
95  add_values(data);
96  }
97  }
98 
104  explicit QuantumNumbers(const std::vector<Particles>& ensembles)
105  : QuantumNumbers() {
106  for (const Particles& particles : ensembles) {
107  for (const ParticleData& data : particles) {
108  add_values(data);
109  }
110  }
111  }
112 
119  explicit QuantumNumbers(const ParticleList& part) : QuantumNumbers() {
120  for (const auto& p : part) {
121  add_values(p);
122  }
123  }
124 
129  void add_values(const ParticleData& p) {
130  momentum_ += p.momentum();
131  charge_ += p.pdgcode().charge();
132  isospin3_ += p.pdgcode().isospin3();
133  strangeness_ += p.pdgcode().strangeness();
134  charmness_ += p.pdgcode().charmness();
135  bottomness_ += p.pdgcode().bottomness();
136  baryon_number_ += p.pdgcode().baryon_number();
137  }
138 
146  FourVector momentum() const { return momentum_; }
147 
155  int charge() const { return charge_; }
163  int isospin3() const { return isospin3_; }
171  int strangeness() const { return strangeness_; }
179  int charmness() const { return charmness_; }
187  int bottomness() const { return bottomness_; }
195  int baryon_number() const { return baryon_number_; }
196 
206  bool operator==(const QuantumNumbers& rhs) const {
207  // clang-format off
208  // invariant mass of the current momentum
209  const double m0_invariant = std::sqrt(std::fabs(momentum_.sqr()));
210  // invariant mass of the momentum to be compared
211  const double m1_invariant = std::sqrt(std::fabs(rhs.momentum_.sqr()));
212  // average invariant mass
213  const double avg_m_inv = 0.5 * (m0_invariant + m1_invariant);
214  // difference in the four-momentum
215  FourVector momentum_diff = momentum_ - rhs.momentum_;
216  /* Check whether momentum is conserved.
217  * The momentum is considered to be conserved when the deviation
218  * is small enough compared to the given invariant mass. */
219  bool momentum_conserved =
220  (std::fabs(momentum_diff.x0()) <= small_number * avg_m_inv &&
221  std::fabs(momentum_diff.x1()) <= small_number * avg_m_inv &&
222  std::fabs(momentum_diff.x2()) <= small_number * avg_m_inv &&
223  std::fabs(momentum_diff.x3()) <= small_number * avg_m_inv);
224  return (momentum_conserved &&
225  charge_ == rhs.charge_ &&
226  isospin3_ == rhs.isospin3_ &&
227  strangeness_ == rhs.strangeness_ &&
228  charmness_ == rhs.charmness_ &&
229  bottomness_ == rhs.bottomness_ &&
231  // clang-format on
232  }
234  bool operator!=(const QuantumNumbers& rhs) const { return !(*this == rhs); }
235 
244  return {momentum_ - rhs.momentum_, charge_ - rhs.charge_,
248  }
249 
259  std::string report_deviations(const std::vector<Particles>& ensembles) const {
260  QuantumNumbers current_values(ensembles);
261  return report_deviations(current_values);
262  }
263 
282  std::string report_deviations(const QuantumNumbers& rhs) const;
283 
284  private:
291 
297  int charge_;
328 };
329 
330 } // namespace smash
331 
332 #endif // SRC_INCLUDE_SMASH_QUANTUMNUMBERS_H_
The FourVector class holds relevant values in Minkowski spacetime with (+, −, −, −) metric signature.
Definition: fourvector.h:33
double x3() const
Definition: fourvector.h:325
double x2() const
Definition: fourvector.h:321
double sqr() const
calculate the square of the vector (which is a scalar)
Definition: fourvector.h:460
double x0() const
Definition: fourvector.h:313
double x1() const
Definition: fourvector.h:317
ParticleData contains the dynamic information of a certain particle.
Definition: particledata.h:58
The Particles class abstracts the storage and manipulation of particles.
Definition: particles.h:33
A container for storing conserved values.
void add_values(const ParticleData &p)
Add the quantum numbers of a single particle to the collection.
QuantumNumbers(const Particles &particles)
Construct QuantumNumbers collection from the conserved quantities found in a set of particles.
int bottomness_
Total bottom.
int isospin3_
Total isospin-3.
QuantumNumbers operator-(const QuantumNumbers &rhs) const
bool operator==(const QuantumNumbers &rhs) const
FourVector momentum_
Total momentum four-vector [GeV].
int charge_
Total charge.
FourVector momentum() const
int baryon_number_
Total baryon number.
QuantumNumbers()
Construct QuantumNumbers collection with all fields 0.
QuantumNumbers(const ParticleList &part)
Construct QuantumNumbers collection from a particle list.
int charmness_
Total charm.
int strangeness_
Total strangeness.
bool operator!=(const QuantumNumbers &rhs) const
Logical complement of QuantumNumbers::operator==.
QuantumNumbers(const FourVector &m, const int q, const int i3, const int s, const int c, const int b, const int B)
std::string report_deviations(const std::vector< Particles > &ensembles) const
Checks if the current particle list has still the same values and reports about differences.
QuantumNumbers(const std::vector< Particles > &ensembles)
Construct QuantumNumbers from several sets of particles.
constexpr int p
Proton.
Definition: action.h:24
constexpr double small_number
Physical error tolerance.
Definition: constants.h:51