Version: SMASH-3.1
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));
}
QuantumNumbers()
Construct QuantumNumbers collection with all fields 0.

Definition at line 54 of file quantumnumbers.h.

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 std::vector< Particles > &ensembles)
 Construct QuantumNumbers from several sets 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 std::vector< Particles > &ensembles) 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/5]

smash::QuantumNumbers::QuantumNumbers ( )
inline

Construct QuantumNumbers collection with all fields 0.

Definition at line 57 of file quantumnumbers.h.

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

◆ QuantumNumbers() [2/5]

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 76 of file quantumnumbers.h.

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

◆ QuantumNumbers() [3/5]

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 93 of file quantumnumbers.h.

93  : QuantumNumbers() {
94  for (const ParticleData& data : particles) {
95  add_values(data);
96  }
97  }
void add_values(const ParticleData &p)
Add the quantum numbers of a single particle to the collection.

◆ QuantumNumbers() [4/5]

smash::QuantumNumbers::QuantumNumbers ( const std::vector< Particles > &  ensembles)
inlineexplicit

Construct QuantumNumbers from several sets of particles.

Parameters
[in]ensemblesCurrent list of particles in all ensembles
Returns
Constructed object.

Definition at line 104 of file quantumnumbers.h.

105  : QuantumNumbers() {
106  for (const Particles& particles : ensembles) {
107  for (const ParticleData& data : particles) {
108  add_values(data);
109  }
110  }
111  }

◆ QuantumNumbers() [5/5]

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 119 of file quantumnumbers.h.

119  : QuantumNumbers() {
120  for (const auto& p : part) {
121  add_values(p);
122  }
123  }
constexpr int p
Proton.

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 129 of file quantumnumbers.h.

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

◆ momentum()

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

Definition at line 146 of file quantumnumbers.h.

146 { return momentum_; }

◆ 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 155 of file quantumnumbers.h.

155 { return charge_; }

◆ 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 163 of file quantumnumbers.h.

163 { 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 171 of file quantumnumbers.h.

171 { return strangeness_; }

◆ 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 179 of file quantumnumbers.h.

179 { 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 187 of file quantumnumbers.h.

187 { 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 195 of file quantumnumbers.h.

195 { return baryon_number_; }

◆ 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 206 of file quantumnumbers.h.

206  {
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_ &&
230  baryon_number_ == rhs.baryon_number_);
231  // clang-format on
232  }
double sqr() const
calculate the square of the vector (which is a scalar)
Definition: fourvector.h:460
constexpr double small_number
Physical error tolerance.
Definition: constants.h:51

◆ operator!=()

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

Logical complement of QuantumNumbers::operator==.

Definition at line 234 of file quantumnumbers.h.

234 { 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 243 of file quantumnumbers.h.

243  {
244  return {momentum_ - rhs.momentum_, charge_ - rhs.charge_,
245  isospin3_ - rhs.isospin3_, strangeness_ - rhs.strangeness_,
246  charmness_ - rhs.charmness_, bottomness_ - rhs.bottomness_,
247  baryon_number_ - rhs.baryon_number_};
248  }

◆ report_deviations() [1/2]

std::string smash::QuantumNumbers::report_deviations ( const std::vector< Particles > &  ensembles) const
inline

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

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

Definition at line 259 of file quantumnumbers.h.

259  {
260  QuantumNumbers current_values(ensembles);
261  return report_deviations(current_values);
262  }
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.

◆ 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  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 }
const_iterator cbegin() const
Definition: fourvector.h:302
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

Member Data Documentation

◆ momentum_

FourVector smash::QuantumNumbers::momentum_
private

Total momentum four-vector [GeV].

See also
QuantumNumbers::momentum()

Definition at line 290 of file quantumnumbers.h.

◆ charge_

int smash::QuantumNumbers::charge_
private

Total charge.

See also
QuantumNumbers::charge()

Definition at line 297 of file quantumnumbers.h.

◆ isospin3_

int smash::QuantumNumbers::isospin3_
private

Total isospin-3.

See also
QuantumNumbers::isospin3()

Definition at line 303 of file quantumnumbers.h.

◆ strangeness_

int smash::QuantumNumbers::strangeness_
private

Total strangeness.

See also
QuantumNumbers::strangeness()

Definition at line 309 of file quantumnumbers.h.

◆ charmness_

int smash::QuantumNumbers::charmness_
private

Total charm.

See also
QuantumNumbers::charmness()

Definition at line 315 of file quantumnumbers.h.

◆ bottomness_

int smash::QuantumNumbers::bottomness_
private

Total bottom.

See also
QuantumNumbers::bottomness()

Definition at line 321 of file quantumnumbers.h.

◆ baryon_number_

int smash::QuantumNumbers::baryon_number_
private

Total baryon number.

See also
QuantumNumbers::baryon_number()

Definition at line 327 of file quantumnumbers.h.


The documentation for this class was generated from the following files: