Version: SMASH-2.0
smash::QuantumNumbers Class Reference

#include <quantumnumbers.h>

A container for storing conserved values.

QuantumNumbers can be used to compare all values that should be conserved during the evolution, in particular for the whole system at fixed intervals, or for a subset of particles before- and after a DecayAction / ScatterAction / Action.

QuantumNumbers can also be used to store, and retrieve, the total value of the quantum numbers in e.g. a ScatterAction, before distributing it to the new particles.

Currently, momentum conservation (including energy conservation), charge-, isospin3-, (net-) strangeness-, (net-) bottomness-, (net-) charmness- and (net-) baryon number conservation are checked. (It should be noted, or repeated, that only the net quantities are conserved, hence this is what is stored and compared with this class.)

Usage

QuantumNumbers before(particlelist);
do_something_with(particlelist);
QuantumNumbers after(particlelist);
printf("%s", before.report_deviations(after).c_str());
if (before != after) {
throw std::runtime_error(before.report_deviations(after));
}

Definition at line 53 of file quantumnumbers.h.

Collaboration diagram for smash::QuantumNumbers:
[legend]

Public Member Functions

 QuantumNumbers ()
 Construct QuantumNumbers collection with all fields 0. More...
 
 QuantumNumbers (const FourVector &m, const int q, const int i3, const int s, const int c, const int b, const int B)
 
 QuantumNumbers (const Particles &particles)
 Construct QuantumNumbers collection from the conserved quantities found in a set of particles. More...
 
 QuantumNumbers (const ParticleList &part)
 Construct QuantumNumbers collection from a particle list. More...
 
void add_values (const ParticleData &p)
 Add the quantum numbers of a single particle to the collection. More...
 
FourVector momentum () const
 
int charge () const
 
int isospin3 () const
 
int strangeness () const
 
int charmness () const
 
int bottomness () const
 
int baryon_number () const
 
bool operator== (const QuantumNumbers &rhs) const
 
bool operator!= (const QuantumNumbers &rhs) const
 Logical complement of QuantumNumbers::operator==. More...
 
QuantumNumbers operator- (const QuantumNumbers &rhs) const
 
std::string report_deviations (const Particles &particles) const
 Checks if the current particle list has still the same values and reports about differences. More...
 
std::string report_deviations (const QuantumNumbers &rhs) const
 Reports on deviations between two QuantumNumbers collections. More...
 

Private Attributes

FourVector momentum_
 Total momentum four-vector [GeV]. More...
 
int charge_
 Total charge. More...
 
int isospin3_
 Total isospin-3. More...
 
int strangeness_
 Total strangeness. More...
 
int charmness_
 Total charm. More...
 
int bottomness_
 Total bottom. More...
 
int baryon_number_
 Total baryon number. More...
 

Constructor & Destructor Documentation

◆ QuantumNumbers() [1/4]

smash::QuantumNumbers::QuantumNumbers ( )
inline

Construct QuantumNumbers collection with all fields 0.

Definition at line 56 of file quantumnumbers.h.

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) {}

◆ QuantumNumbers() [2/4]

smash::QuantumNumbers::QuantumNumbers ( const FourVector m,
const int  q,
const int  i3,
const int  s,
const int  c,
const int  b,
const int  B 
)
inline
Returns
Constructed QuantumNumbers.
Parameters
[in]mMomentum FourVector [GeV]
[in]qCharge
[in]i3Isospin
[in]sStrangeness
[in]cCharmness
[in]bBottomness
[in]BBaryon number

Definition at line 75 of file quantumnumbers.h.

77  : momentum_(m),
78  charge_(q),
79  isospin3_(i3),
80  strangeness_(s),
81  charmness_(c),
82  bottomness_(b),
83  baryon_number_(B) {}

◆ QuantumNumbers() [3/4]

smash::QuantumNumbers::QuantumNumbers ( const Particles particles)
inlineexplicit

Construct QuantumNumbers collection from the conserved quantities found in a set of particles.

Parameters
[in]particlesset of particles for which quantum numbers are calculated and constructed
Returns
Constructed object.

Definition at line 92 of file quantumnumbers.h.

92  : QuantumNumbers() {
93  for (const ParticleData& data : particles) {
94  add_values(data);
95  }
96  }
Here is the call graph for this function:

◆ QuantumNumbers() [4/4]

smash::QuantumNumbers::QuantumNumbers ( const ParticleList &  part)
inlineexplicit

Construct QuantumNumbers collection from a particle list.

Parameters
[in]partlist of particles for which quantum numbers are calculated and constructed
Returns
Constructed object.

Definition at line 104 of file quantumnumbers.h.

104  : QuantumNumbers() {
105  for (const auto& p : part) {
106  add_values(p);
107  }
108  }
Here is the call graph for this function:

Member Function Documentation

◆ add_values()

void smash::QuantumNumbers::add_values ( const ParticleData p)
inline

Add the quantum numbers of a single particle to the collection.

Parameters
[in]pparticle whose quantum number is added to the collection

Definition at line 114 of file quantumnumbers.h.

114  {
115  momentum_ += p.momentum();
116  charge_ += p.pdgcode().charge();
117  isospin3_ += p.pdgcode().isospin3();
118  strangeness_ += p.pdgcode().strangeness();
119  charmness_ += p.pdgcode().charmness();
120  bottomness_ += p.pdgcode().bottomness();
121  baryon_number_ += p.pdgcode().baryon_number();
122  }
Here is the caller graph for this function:

◆ momentum()

FourVector smash::QuantumNumbers::momentum ( ) const
inline
Returns
The total momentum four-vector. \(P^\mu = \sum_{i \in \mbox{particles}} (E_i, \vec p_i)\) [GeV]
See also
QuantumNumbers::momentum_
ParticleData::momentum()

Definition at line 131 of file quantumnumbers.h.

131 { return momentum_; }
Here is the caller graph for this function:

◆ charge()

int smash::QuantumNumbers::charge ( ) const
inline
Returns
The total electric charge. \(Q = \sum_{i \in \mbox{particles}} q_i\)
See also
QuantumNumbers::charge_
PdgCode::charge()

Definition at line 140 of file quantumnumbers.h.

140 { return charge_; }
Here is the caller graph for this function:

◆ isospin3()

int smash::QuantumNumbers::isospin3 ( ) const
inline
Returns
Twice the total isospin-3 component. \(I = \sum_{i \in \mbox{particles}} 2{I_3}_i\)
See also
QuantumNumbers::isospin3_
PdgCode::isospin3()

Definition at line 148 of file quantumnumbers.h.

148 { return isospin3_; }

◆ strangeness()

int smash::QuantumNumbers::strangeness ( ) const
inline
Returns
The total strangeness. \(S = \sum_{i \in \mbox{particles}} S_i\)
See also
QuantumNumbers::strangeness_
PdgCode::strangeness()

Definition at line 156 of file quantumnumbers.h.

156 { return strangeness_; }
Here is the caller graph for this function:

◆ charmness()

int smash::QuantumNumbers::charmness ( ) const
inline
Returns
The total charm. \(C = \sum_{i \in \mbox{particles}} C_i\)
See also
QuantumNumbers::charmness_
PdgCode::charmness()

Definition at line 164 of file quantumnumbers.h.

164 { return charmness_; }

◆ bottomness()

int smash::QuantumNumbers::bottomness ( ) const
inline
Returns
The total bottom. \(b = \sum_{i \in \mbox{particles}} b_i\)
See also
QuantumNumbers::bottomness_
PdgCode::bottomness()

Definition at line 172 of file quantumnumbers.h.

172 { return bottomness_; }

◆ baryon_number()

int smash::QuantumNumbers::baryon_number ( ) const
inline
Returns
The total baryon number. \(B = \sum_{i \in \mbox{particles}} B_i\)
See also
QuantumNumbers::baryon_number_
PdgCode::baryon_number()

Definition at line 180 of file quantumnumbers.h.

180 { return baryon_number_; }
Here is the caller graph for this function:

◆ operator==()

bool smash::QuantumNumbers::operator== ( const QuantumNumbers rhs) const
inline
Returns
true if all members compare true.
Parameters
rhsRight-hand side.

In the comparison of FourVectors, a little leeway is built-in, so this does not rely on an exact comparison of floating point values.

See also
FourVector::operator==

Definition at line 191 of file quantumnumbers.h.

191  {
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_ &&
220  baryon_number_ == rhs.baryon_number_);
221  // clang-format on
222  }
Here is the call graph for this function:

◆ operator!=()

bool smash::QuantumNumbers::operator!= ( const QuantumNumbers rhs) const
inline

Logical complement of QuantumNumbers::operator==.

Definition at line 224 of file quantumnumbers.h.

224 { return !(*this == rhs); }

◆ operator-()

QuantumNumbers smash::QuantumNumbers::operator- ( const QuantumNumbers rhs) const
inline
Returns
Entry-wise difference of two sets of QuantumNumbers.
Parameters
rhsRight-hand side.

If everything is conserved, all entries of the result should be zero.

Definition at line 233 of file quantumnumbers.h.

233  {
234  return {momentum_ - rhs.momentum_, charge_ - rhs.charge_,
235  isospin3_ - rhs.isospin3_, strangeness_ - rhs.strangeness_,
236  charmness_ - rhs.charmness_, bottomness_ - rhs.bottomness_,
237  baryon_number_ - rhs.baryon_number_};
238  }

◆ report_deviations() [1/2]

std::string smash::QuantumNumbers::report_deviations ( const Particles particles) const
inline

Checks if the current particle list has still the same values and reports about differences.

Parameters
[in]particlesSet of particles whose quantum number is compared
Returns
String reporting the deviations.
See also
QuantumNumbers::report_deviations(const QuantumNumbers&) const

Definition at line 248 of file quantumnumbers.h.

248  {
249  QuantumNumbers current_values(particles);
250  return report_deviations(current_values);
251  }
Here is the caller graph for this function:

◆ report_deviations() [2/2]

std::string smash::QuantumNumbers::report_deviations ( const QuantumNumbers rhs) const

Reports on deviations between two QuantumNumbers collections.

Parameters
[in]rhsOther QuantumNumbers collection.
Returns
A string with information about the differences.

If there are no differences, the returned string is empty; else, a descriptive warning message is returned, e.g.

Conservation law violations detected (old vs. new)
Deviation in Charge:
164 vs. 163
Deviation in Isospin 3:
-88 vs. -90

Definition at line 18 of file quantumnumbers.cc.

18  {
19  if (rhs == *this) {
20  return "";
21  }
22  std::stringstream error_msg;
23  error_msg << "Conservation law violations detected (old vs. new)\n";
24  if (momentum_ != rhs.momentum_) {
25  error_msg << "Deviation in Four-Momentum:\n" << std::scientific;
26  }
27  /* programmer's note: here, I'd like to simultaneously loop over an
28  * integer (for the output; so that we know which component is
29  * faulty) and both the current and rhs's momentum four-vector. If
30  * there is a better way to do this, feel free to implement.
31  *
32  * I chose mu < 4 as the breaking condition out of the vague feeling
33  * that comparing integers may be faster than accessing the
34  * iterators. */
35  int mu = 0;
36  for (auto here_iter = momentum_.cbegin(), rhs_iter = rhs.momentum_.cbegin();
37  mu < 4; ++here_iter, ++rhs_iter, ++mu) {
38  if (!almost_equal_physics(*here_iter, *rhs_iter)) {
39  error_msg << " P_" << mu << ": " << *here_iter << " vs. " << *rhs_iter
40  << "; Δ = " << (*here_iter - *rhs_iter) << "\n";
41  }
42  }
43  if (charge_ != rhs.charge_) {
44  error_msg << "Deviation in Charge:\n " << charge_ << " vs. " << rhs.charge_
45  << "\n";
46  }
47  if (isospin3_ != rhs.isospin3_) {
48  error_msg << "Deviation in Isospin 3:\n " << isospin3_ << " vs. "
49  << rhs.isospin3_ << "\n";
50  }
51  if (strangeness_ != rhs.strangeness_) {
52  error_msg << "Deviation in Strangeness:\n " << strangeness_ << " vs. "
53  << rhs.strangeness_ << "\n";
54  }
55  if (charmness_ != rhs.charmness_) {
56  error_msg << "Deviation in Charmness:\n " << charmness_ << " vs. "
57  << rhs.charmness_ << "\n";
58  }
59  if (bottomness_ != rhs.bottomness_) {
60  error_msg << "Deviation in Bottomness:\n " << bottomness_ << " vs. "
61  << rhs.bottomness_ << "\n";
62  }
63  if (baryon_number_ != rhs.baryon_number_) {
64  error_msg << "Deviation in Baryon Number:\n " << baryon_number_ << " vs. "
65  << rhs.baryon_number_ << "\n";
66  }
67  return error_msg.str();
68 }
Here is the call graph for this function:

Member Data Documentation

◆ momentum_

FourVector smash::QuantumNumbers::momentum_
private

Total momentum four-vector [GeV].

See also
QuantumNumbers::momentum()

Definition at line 279 of file quantumnumbers.h.

◆ charge_

int smash::QuantumNumbers::charge_
private

Total charge.

See also
QuantumNumbers::charge()

Definition at line 286 of file quantumnumbers.h.

◆ isospin3_

int smash::QuantumNumbers::isospin3_
private

Total isospin-3.

See also
QuantumNumbers::isospin3()

Definition at line 292 of file quantumnumbers.h.

◆ strangeness_

int smash::QuantumNumbers::strangeness_
private

Total strangeness.

See also
QuantumNumbers::strangeness()

Definition at line 298 of file quantumnumbers.h.

◆ charmness_

int smash::QuantumNumbers::charmness_
private

Total charm.

See also
QuantumNumbers::charmness()

Definition at line 304 of file quantumnumbers.h.

◆ bottomness_

int smash::QuantumNumbers::bottomness_
private

Total bottom.

See also
QuantumNumbers::bottomness()

Definition at line 310 of file quantumnumbers.h.

◆ baryon_number_

int smash::QuantumNumbers::baryon_number_
private

Total baryon number.

See also
QuantumNumbers::baryon_number()

Definition at line 316 of file quantumnumbers.h.


The documentation for this class was generated from the following files:
smash::QuantumNumbers::charmness_
int charmness_
Total charm.
Definition: quantumnumbers.h:304
smash::FourVector::sqr
double sqr() const
calculate the square of the vector (which is a scalar)
Definition: fourvector.h:450
smash::QuantumNumbers::add_values
void add_values(const ParticleData &p)
Add the quantum numbers of a single particle to the collection.
Definition: quantumnumbers.h:114
smash::small_number
constexpr double small_number
Physical error tolerance.
Definition: constants.h:48
smash::QuantumNumbers::bottomness_
int bottomness_
Total bottom.
Definition: quantumnumbers.h:310
smash::QuantumNumbers::isospin3_
int isospin3_
Total isospin-3.
Definition: quantumnumbers.h:292
smash::QuantumNumbers::strangeness_
int strangeness_
Total strangeness.
Definition: quantumnumbers.h:298
smash::QuantumNumbers::QuantumNumbers
QuantumNumbers()
Construct QuantumNumbers collection with all fields 0.
Definition: quantumnumbers.h:56
smash::DensityType::Charge
smash::QuantumNumbers::charge_
int charge_
Total charge.
Definition: quantumnumbers.h:286
smash::QuantumNumbers::report_deviations
std::string report_deviations(const Particles &particles) const
Checks if the current particle list has still the same values and reports about differences.
Definition: quantumnumbers.h:248
smash::almost_equal_physics
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:62
smash::QuantumNumbers::baryon_number_
int baryon_number_
Total baryon number.
Definition: quantumnumbers.h:316
smash::FourVector::cbegin
const_iterator cbegin() const
Definition: fourvector.h:292
smash::pdg::p
constexpr int p
Proton.
Definition: pdgcode_constants.h:28
smash::QuantumNumbers::momentum_
FourVector momentum_
Total momentum four-vector [GeV].
Definition: quantumnumbers.h:279