Version: SMASH-3.2.2
quantumnumbers.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2015-2018,2022,2025
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  << "; Δ_abs = " << (*here_iter - *rhs_iter) << "; Δ_rel = "
40  << (*here_iter - *rhs_iter) /
41  std::max(std::abs(*here_iter), std::abs(*rhs_iter))
42  << "\n";
43  }
44  }
45  if (charge_ != rhs.charge_) {
46  error_msg << "Deviation in Charge:\n " << charge_ << " vs. " << rhs.charge_
47  << "\n";
48  }
49  if (isospin3_ != rhs.isospin3_) {
50  error_msg << "Deviation in Isospin 3:\n " << isospin3_ << " vs. "
51  << rhs.isospin3_ << "\n";
52  }
53  if (strangeness_ != rhs.strangeness_) {
54  error_msg << "Deviation in Strangeness:\n " << strangeness_ << " vs. "
55  << rhs.strangeness_ << "\n";
56  }
57  if (charmness_ != rhs.charmness_) {
58  error_msg << "Deviation in Charmness:\n " << charmness_ << " vs. "
59  << rhs.charmness_ << "\n";
60  }
61  if (bottomness_ != rhs.bottomness_) {
62  error_msg << "Deviation in Bottomness:\n " << bottomness_ << " vs. "
63  << rhs.bottomness_ << "\n";
64  }
65  if (baryon_number_ != rhs.baryon_number_) {
66  error_msg << "Deviation in Baryon Number:\n " << baryon_number_ << " vs. "
67  << rhs.baryon_number_ << "\n";
68  }
69  return error_msg.str();
70 }
71 
72 } // 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)
Like smash::almost_equal, but using a less strict tolerance, smash::small_number.
Definition: numerics.h:100
Generic numerical functions.