Version: SMASH-3.1
quantumnumbers.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2015-2018,2022
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #include "smash/quantumnumbers.h"
11 
12 #include <sstream>
13 
14 #include "smash/numerics.h"
15 
16 namespace smash {
17 
18 std::string QuantumNumbers::report_deviations(const QuantumNumbers& rhs) const {
19  if (rhs == *this) {
20  return "";
21  }
22  std::stringstream error_msg;
23  if (momentum_ != rhs.momentum_) {
24  error_msg << "Deviation in Four-Momentum:\n" << std::scientific;
25  }
26  /* programmer's note: here, I'd like to simultaneously loop over an
27  * integer (for the output; so that we know which component is
28  * faulty) and both the current and rhs's momentum four-vector. If
29  * there is a better way to do this, feel free to implement.
30  *
31  * I chose mu < 4 as the breaking condition out of the vague feeling
32  * that comparing integers may be faster than accessing the
33  * iterators. */
34  int mu = 0;
35  for (auto here_iter = momentum_.cbegin(), rhs_iter = rhs.momentum_.cbegin();
36  mu < 4; ++here_iter, ++rhs_iter, ++mu) {
37  if (!almost_equal_physics(*here_iter, *rhs_iter)) {
38  error_msg << " P_" << mu << ": " << *here_iter << " vs. " << *rhs_iter
39  << "; Δ = " << (*here_iter - *rhs_iter) << "\n";
40  }
41  }
42  if (charge_ != rhs.charge_) {
43  error_msg << "Deviation in Charge:\n " << charge_ << " vs. " << rhs.charge_
44  << "\n";
45  }
46  if (isospin3_ != rhs.isospin3_) {
47  error_msg << "Deviation in Isospin 3:\n " << isospin3_ << " vs. "
48  << rhs.isospin3_ << "\n";
49  }
50  if (strangeness_ != rhs.strangeness_) {
51  error_msg << "Deviation in Strangeness:\n " << strangeness_ << " vs. "
52  << rhs.strangeness_ << "\n";
53  }
54  if (charmness_ != rhs.charmness_) {
55  error_msg << "Deviation in Charmness:\n " << charmness_ << " vs. "
56  << rhs.charmness_ << "\n";
57  }
58  if (bottomness_ != rhs.bottomness_) {
59  error_msg << "Deviation in Bottomness:\n " << bottomness_ << " vs. "
60  << rhs.bottomness_ << "\n";
61  }
62  if (baryon_number_ != rhs.baryon_number_) {
63  error_msg << "Deviation in Baryon Number:\n " << baryon_number_ << " vs. "
64  << rhs.baryon_number_ << "\n";
65  }
66  return error_msg.str();
67 }
68 
69 } // namespace smash
const_iterator cbegin() const
Definition: fourvector.h:302
A container for storing conserved values.
int bottomness_
Total bottom.
int isospin3_
Total isospin-3.
FourVector momentum_
Total momentum four-vector [GeV].
int charge_
Total charge.
int baryon_number_
Total baryon number.
int charmness_
Total charm.
int strangeness_
Total strangeness.
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.
Definition: action.h:24
bool almost_equal_physics(const N x, const N y)
Same as smash::almost_equal, but for physical checks like energy-momentum conservation small_number i...
Definition: numerics.h:64
Generic numerical functions.