Version: SMASH-3.1
tabulation.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2020
3  * SMASH Team
4  *
5  * GNU General Public License (GPLv3 or later)
6  */
7 
8 #ifndef SRC_INCLUDE_SMASH_TABULATION_H_
9 #define SRC_INCLUDE_SMASH_TABULATION_H_
10 
11 #include <fstream>
12 #include <functional>
13 #include <map>
14 #include <memory>
15 #include <vector>
16 
17 #include "forwarddeclarations.h"
18 #include "integrate.h"
19 #include "kinematics.h"
20 #include "particletype.h"
21 #include "sha256.h"
22 
23 namespace smash {
24 
26 enum class Extrapolation {
27  Zero = 0,
28  Const = 1,
29  Linear = 2,
30 };
31 
35 class Tabulation {
36  public:
40  Tabulation() : values_({}), x_min_(0.0), x_max_(0.0), inv_dx_(0.0) {}
41 
53  Tabulation(double x_min, double range, size_t num,
54  std::function<double(double)> f);
55 
59  bool is_empty() const { return values_.empty(); }
60 
69  static Tabulation from_file(std::ifstream& stream, sha256::Hash hash);
70 
80  double get_value_step(double x) const;
81 
96  double get_value_linear(
97  double x, Extrapolation extrapolation = Extrapolation::Linear) const;
98 
106  void write(std::ofstream& stream, sha256::Hash hash) const;
107 
108  protected:
110  std::vector<double> values_;
111 
113  double x_min_;
114 
116  double x_max_;
117 
119  double inv_dx_;
120 };
121 
136 inline double spec_func_integrand_1res(double resonance_mass, double sqrts,
137  double stable_mass,
138  const ParticleType& type) {
139  if (sqrts <= stable_mass + resonance_mass) {
140  return 0.;
141  }
142 
143  /* Integrand is the spectral function weighted by the CM momentum of the
144  * final state. */
145  return type.spectral_function(resonance_mass) *
146  pCM(sqrts, stable_mass, resonance_mass);
147 }
148 
165 inline double spec_func_integrand_2res(double sqrts, double res_mass_1,
166  double res_mass_2,
167  const ParticleType& t1,
168  const ParticleType& t2) {
169  if (sqrts <= res_mass_1 + res_mass_2) {
170  return 0.;
171  }
172 
173  /* Integrand is the product of the spectral function weighted by the
174  * CM momentum of the final state. */
175  return t1.spectral_function(res_mass_1) * t2.spectral_function(res_mass_2) *
176  pCM(sqrts, res_mass_1, res_mass_2);
177 }
178 
190  const ParticleType& resonance,
191  const ParticleType& stable,
192  double range) {
193  const double m_min = resonance.min_mass_kinematic();
194  const double m_stable = stable.mass();
195  return Tabulation(m_min + m_stable, range, 100, [&](double srts) {
196  return integrate(m_min, srts - m_stable, [&](double m) {
197  return spec_func_integrand_1res(m, srts, m_stable, resonance);
198  });
199  });
200 }
201 
212  const ParticleType& res1,
213  const ParticleType& res2,
214  double range) {
215  const double m1_min = res1.min_mass_kinematic();
216  const double m2_min = res2.min_mass_kinematic();
217  return Tabulation(m1_min + m2_min, range, 125, [&](double srts) {
218  const double m1_max = srts - m2_min;
219  const double m2_max = srts - m1_min;
220  return integrate2d(
221  m1_min, m1_max, m2_min, m2_max, [&](double m1, double m2) {
222  return spec_func_integrand_2res(srts, m1, m2, res1, res2);
223  });
224  });
225 }
226 
227 } // namespace smash
228 
229 #endif // SRC_INCLUDE_SMASH_TABULATION_H_
A C++ interface for numerical integration in two dimensions with the Cuba Cuhre integration function.
Definition: integrate.h:219
A C++ interface for numerical integration in one dimension with the GSL CQUAD integration functions.
Definition: integrate.h:106
Particle type contains the static properties of a particle species.
Definition: particletype.h:98
double spectral_function(double m) const
Full spectral function of the resonance (relativistic Breit-Wigner distribution with mass-dependent ...
double min_mass_kinematic() const
The minimum mass of the resonance that is kinematically allowed.
double mass() const
Definition: particletype.h:145
A class for storing a one-dimensional lookup table of floating-point values.
Definition: tabulation.h:35
double x_min_
lower bound for tabulation
Definition: tabulation.h:113
double inv_dx_
inverse step size 1/dx
Definition: tabulation.h:119
double x_max_
upper bound for tabulation
Definition: tabulation.h:116
std::vector< double > values_
vector for storing tabulated values
Definition: tabulation.h:110
static Tabulation from_file(std::ifstream &stream, sha256::Hash hash)
Construct a tabulation object by reading binary data from a stream.
Definition: tabulation.cc:167
Tabulation()
Construct an empty tabulation object.
Definition: tabulation.h:40
void write(std::ofstream &stream, sha256::Hash hash) const
Write a binary representation of the tabulation to a stream.
Definition: tabulation.cc:159
double get_value_step(double x) const
Look up a value from the tabulation (without any interpolation, simply using the closest tabulated va...
Definition: tabulation.cc:25
bool is_empty() const
Definition: tabulation.h:59
double get_value_linear(double x, Extrapolation extrapolation=Extrapolation::Linear) const
Look up a value from the tabulation using linear interpolation.
Definition: tabulation.cc:38
std::array< uint8_t, HASH_SIZE > Hash
A SHA256 hash.
Definition: sha256.h:25
Definition: action.h:24
T pCM(const T sqrts, const T mass_a, const T mass_b) noexcept
Definition: kinematics.h:79
static Integrator integrate
Definition: decaytype.cc:143
Tabulation spectral_integral_semistable(Integrator &integrate, const ParticleType &resonance, const ParticleType &stable, double range)
Create a table for the spectral integral of a resonance and a stable particle.
Definition: tabulation.h:189
static Integrator2d integrate2d(1E7)
double spec_func_integrand_2res(double sqrts, double res_mass_1, double res_mass_2, const ParticleType &t1, const ParticleType &t2)
Spectral function integrand for GSL integration, with two resonances in the final state.
Definition: tabulation.h:165
Extrapolation
The kind of extrapolation used by the tabulation.
Definition: tabulation.h:26
Tabulation spectral_integral_unstable(Integrator2d &integrate2d, const ParticleType &res1, const ParticleType &res2, double range)
Create a table for the spectral integral of two resonances.
Definition: tabulation.h:211
double spec_func_integrand_1res(double resonance_mass, double sqrts, double stable_mass, const ParticleType &type)
Spectral function integrand for GSL integration, with one resonance in the final state (the second pa...
Definition: tabulation.h:136