Version: SMASH-3.4
quantumnumbers.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2014-2020,2022-2023,2025
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 
20 /**
21  * \ingroup data
22  *
23  * A container for storing conserved values.
24  *
25  * QuantumNumbers can be used to compare all values that should be
26  * conserved during the evolution, in particular for the whole system at
27  * fixed intervals, or for a subset of particles before- and after a
28  * DecayAction / ScatterAction / Action.
29  *
30  * QuantumNumbers can also be used to store, and retrieve, the total
31  * value of the quantum numbers in e.g. a ScatterAction, before
32  * distributing it to the new particles.
33  *
34  * Currently, momentum conservation (including energy conservation),
35  * charge-, isospin3-, (net-) strangeness-, (net-) bottomness-, (net-)
36  * charmness- and (net-) baryon number conservation are checked. (It
37  * should be noted, or repeated, that only the net quantities are
38  * conserved, hence this is what is stored and compared with this
39  * class.)
40  *
41  * <h2> Usage </h2>
42  *
43  * \code
44  * QuantumNumbers before(particlelist);
45  * do_something_with(particlelist);
46  * QuantumNumbers after(particlelist);
47  * printf("%s", before.report_deviations(after).c_str());
48  * if (before != after) {
49  * throw std::runtime_error(before.report_deviations(after));
50  * }
51  * \endcode
52  */
54  public:
55  /// Construct QuantumNumbers collection with all fields 0.
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) {}
64 
65  /**
66  * \return Constructed QuantumNumbers.
67  * \param[in] m Momentum FourVector [GeV]
68  * \param[in] q Charge
69  * \param[in] i3 Isospin
70  * \param[in] s Strangeness
71  * \param[in] c Charmness
72  * \param[in] b Bottomness
73  * \param[in] B Baryon number
74  */
75  QuantumNumbers(const FourVector& m, const int q, const int i3, const int s,
76  const int c, const int b, const int B)
77  : momentum_(m),
78  charge_(q),
79  isospin3_(i3),
80  strangeness_(s),
81  charmness_(c),
82  bottomness_(b),
83  baryon_number_(B) {}
84 
85  /**
86  * Construct QuantumNumbers collection from the conserved quantities
87  * found in a set of particles.
88  * \param[in] particles set of particles for which
89  * quantum numbers are calculated and constructed
90  * \return Constructed object.
91  */
92  explicit QuantumNumbers(const Particles& particles) : QuantumNumbers() {
93  for (const ParticleData& data : particles) {
94  add_values(data);
95  }
96  }
97 
98  /**
99  * Construct QuantumNumbers from several sets of particles.
100  * \param[in] ensembles Current list of particles in all ensembles
101  * \return Constructed object.
102  */
103  explicit QuantumNumbers(const std::vector<Particles>& ensembles)
104  : QuantumNumbers() {
105  for (const Particles& particles : ensembles) {
106  for (const ParticleData& data : particles) {
107  add_values(data);
108  }
109  }
110  }
111 
112  /**
113  * Construct QuantumNumbers collection from a particle list.
114  * \param[in] part list of particles for which
115  * quantum numbers are calculated and constructed
116  * \return Constructed object.
117  */
118  explicit QuantumNumbers(const ParticleList& part) : QuantumNumbers() {
119  for (const auto& p : part) {
120  add_values(p);
121  }
122  }
123 
124  /**
125  * Add the quantum numbers of a single particle to the collection.
126  * \param[in] p particle whose quantum number is added to the collection
127  */
128  void add_values(const ParticleData& p) {
129  momentum_ += p.momentum();
130  charge_ += p.pdgcode().charge();
131  isospin3_ += p.pdgcode().isospin3();
132  strangeness_ += p.pdgcode().strangeness();
133  charmness_ += p.pdgcode().charmness();
134  bottomness_ += p.pdgcode().bottomness();
135  baryon_number_ += p.pdgcode().baryon_number();
136  }
137 
138  /**
139  * \return The total momentum four-vector.
140  * \f$P^\mu = \sum_{i \in \mbox{particles}} (E_i, \mathbf{p}_i)\f$ [GeV]
141  *
142  * \see QuantumNumbers::momentum_
143  * \see ParticleData::momentum()
144  */
145  FourVector momentum() const { return momentum_; }
146 
147  /**
148  * \return The total electric charge.
149  * \f$Q = \sum_{i \in \mbox{particles}} q_i\f$
150  *
151  * \see QuantumNumbers::charge_
152  * \see PdgCode::charge()
153  */
154  int charge() const { return charge_; }
155  /**
156  * \return Twice the total isospin-3 component.
157  * \f$I = \sum_{i \in \mbox{particles}} 2{I_3}_i\f$
158  *
159  * \see QuantumNumbers::isospin3_
160  * \see PdgCode::isospin3()
161  */
162  int isospin3() const { return isospin3_; }
163  /**
164  * \return The total strangeness.
165  * \f$S = \sum_{i \in \mbox{particles}} S_i\f$
166  *
167  * \see QuantumNumbers::strangeness_
168  * \see PdgCode::strangeness()
169  */
170  int strangeness() const { return strangeness_; }
171  /**
172  * \return The total charm.
173  * \f$C = \sum_{i \in \mbox{particles}} C_i\f$
174  *
175  * \see QuantumNumbers::charmness_
176  * \see PdgCode::charmness()
177  */
178  int charmness() const { return charmness_; }
179  /**
180  * \return The total bottom.
181  * \f$b = \sum_{i \in \mbox{particles}} b_i\f$
182  *
183  * \see QuantumNumbers::bottomness_
184  * \see PdgCode::bottomness()
185  */
186  int bottomness() const { return bottomness_; }
187  /**
188  * \return The total baryon number.
189  * \f$B = \sum_{i \in \mbox{particles}} B_i\f$
190  *
191  * \see QuantumNumbers::baryon_number_
192  * \see PdgCode::baryon_number()
193  */
194  int baryon_number() const { return baryon_number_; }
195 
196  /**
197  * \return true if all members compare true.
198  * \param rhs Right-hand side.
199  *
200  * In the comparison of FourVectors, a little leeway is built-in, so
201  * this does not rely on an exact comparison of floating point values.
202  *
203  * \see FourVector::operator==
204  */
205  bool operator==(const QuantumNumbers& rhs) const {
206  return (momentum_ == rhs.momentum_ && charge_ == rhs.charge_ &&
207  isospin3_ == rhs.isospin3_ && strangeness_ == rhs.strangeness_ &&
208  charmness_ == rhs.charmness_ && bottomness_ == rhs.bottomness_ &&
210  }
211  /// Logical complement of QuantumNumbers::operator==.
212  bool operator!=(const QuantumNumbers& rhs) const { return !(*this == rhs); }
213 
214  /**
215  * \return Entry-wise difference of two sets of QuantumNumbers.
216  * \param rhs Right-hand side.
217  *
218  * If everything is conserved, all entries of the result should be
219  * zero.
220  */
222  return {momentum_ - rhs.momentum_, charge_ - rhs.charge_,
226  }
227 
228  /**
229  * Checks if the current particle list has still the same values and
230  * reports about differences.
231  * \param[in] ensembles Current list of particles in all ensembles, whose
232  * quantum number is compared
233  * \return String reporting the deviations.
234  *
235  * \see QuantumNumbers::report_deviations(const QuantumNumbers&) const
236  */
237  std::string report_deviations(const std::vector<Particles>& ensembles) const {
238  QuantumNumbers current_values(ensembles);
239  return report_deviations(current_values);
240  }
241 
242  /**
243  * Reports on deviations between two QuantumNumbers collections.
244  *
245  * \param[in] rhs Other QuantumNumbers collection.
246  * \return A string with information about the differences.
247  *
248  * If there are no differences, the returned string is empty; else, a
249  * descriptive warning message is returned, e.g.
250  *
251  * \code
252  * Conservation law violations detected (old vs. new)
253  * Deviation in Charge:
254  * 164 vs. 163
255  * Deviation in Isospin 3:
256  * -88 vs. -90
257  * \endcode
258  *
259  */
260  std::string report_deviations(const QuantumNumbers& rhs) const;
261 
262  private:
263  /**
264  * Total momentum four-vector [GeV].
265  *
266  * \see QuantumNumbers::momentum()
267  */
269 
270  /**
271  * Total charge.
272  *
273  * \see QuantumNumbers::charge()
274  */
275  int charge_;
276  /**
277  * Total isospin-3.
278  *
279  * \see QuantumNumbers::isospin3()
280  */
282  /**
283  * Total strangeness.
284  *
285  * \see QuantumNumbers::strangeness()
286  */
288  /**
289  * Total charm.
290  *
291  * \see QuantumNumbers::charmness()
292  */
294  /**
295  * Total bottom.
296  *
297  * \see QuantumNumbers::bottomness()
298  */
300  /**
301  * Total baryon number.
302  *
303  * \see QuantumNumbers::baryon_number()
304  */
306 };
307 
308 } // namespace smash
309 
310 #endif // SRC_INCLUDE_SMASH_QUANTUMNUMBERS_H_
The FourVector class holds relevant values in Minkowski spacetime with (+, −, −, −) metric signature.
Definition: fourvector.h:33
ParticleData contains the dynamic information of a certain particle.
Definition: particledata.h:59
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