Thermal-FIST  1.3
Package for hadron resonance gas model applications
RandomGenerators.h
Go to the documentation of this file.
1 /*
2  * Thermal-FIST package
3  *
4  * Copyright (c) 2015-2019 Volodymyr Vovchenko
5  *
6  * GNU General Public License (GPLv3 or later)
7  */
8 #ifndef RANDOMGENERATORS_H
9 #define RANDOMGENERATORS_H
10 
11 #include <cmath>
12 
13 #include "MersenneTwister.h"
16 
17 namespace thermalfist {
18 
21  namespace RandomGenerators {
22 
24  extern MTRand randgenMT;
25 
27  void SetSeed(const unsigned int seed);
28 
32  int RandomPoisson(double mean);
33 
38  int RandomPoisson(double mean, MTRand &rangen);
39 
42  double SkellamProbability(int k, double mu1, double mu2);
43 
44 
50  {
51  static double pn(int n, double a, int nu);
52 
53  //static double R(double x, int nu) { return xMath::BesselI(nu + 1, x) / xMath::BesselI(nu, x); }
54  static double R(double x, int nu);
55 
56  static double mu(double a, int nu) { return a * R(a, nu) / 2; }
57 
58  static double chi2(double a, int nu);
59 
60  static int m(double a, int nu) { return static_cast<int>((sqrt(a*a+static_cast<double>(nu)*nu) - nu)/2.); }
61 
62  static double sig2(double a, int nu);
63 
64  static double Q2(double a, int nu);
65 
66  static int RandomBesselPoisson(double a, int nu, MTRand &rangen);
67 
68  static int RandomBesselPoisson(double a, int nu) { return RandomBesselPoisson(a, nu, randgenMT); }
69 
70  static double pmXmOverpm(int X, int tm, double a, int nu);
71 
72  static int RandomBesselDevroye1(double a, int nu, MTRand &rangen);
73 
74  static int RandomBesselDevroye1(double a, int nu) { return RandomBesselDevroye1(a, nu, randgenMT); }
75 
76  static int RandomBesselDevroye2(double a, int nu, MTRand &rangen);
77 
78  static int RandomBesselDevroye2(double a, int nu) { return RandomBesselDevroye2(a, nu, randgenMT); }
79 
80  static int RandomBesselDevroye3(double a, int nu, MTRand &rangen);
81 
82  static int RandomBesselDevroye3(double a, int nu) { return RandomBesselDevroye3(a, nu, randgenMT); }
83 
84  static int RandomBesselNormal(double a, int nu, MTRand &rangen);
85 
86  static int RandomBesselNormal(double a, int nu) { return RandomBesselNormal(a, nu, randgenMT); }
87 
88  static int RandomBesselCombined(double a, int nu, MTRand &rangen);
89 
90  static int RandomBesselCombined(double a, int nu) { return RandomBesselCombined(a, nu, randgenMT); }
91  };
92 
93 
96  {
97  public:
100 
103 
108  virtual std::vector<double> GetMomentum(double mass = -1.) const = 0;
109  };
110 
111 
112 
121  {
122  public:
131  ThermalMomentumGenerator(double mass = 0.938, int statistics = 0, double T = 0.100, double mu = 0.) :
132  m_Mass(mass), m_T(T), m_Mu(mu), m_Statistics(statistics)
133  {
134  //FixParameters();
135  m_Max = ComputeMaximum(m_Mass);
136  }
137 
144  double GetP(double mass = -1.) const;
145 
146  private:
148  double g(double x, double mass = -1.) const;
149 
150  double ComputeMaximum(double mass) const;
151 
152  void FixParameters();
153 
154  double m_Mass, m_T, m_Mu;
155  int m_Statistics;
156 
157  double m_Max;
158  };
159 
160 
161 
171  {
172  public:
173 
175 
183  SiemensRasmussenMomentumGenerator(double T, double beta, double mass) :m_T(T), m_Beta(beta), m_Mass(mass) {
184  m_Gamma = 1. / sqrt(1. - m_Beta * m_Beta);
185  FixParameters();
186  }
187 
189 
197  void SetParameters(double T, double beta, double mass) {
198  m_T = T;
199  m_Beta = beta;
200  m_Mass = mass;
201  m_Gamma = 1. / sqrt(1. - m_Beta * m_Beta);
202  FixParameters();
203  }
204 
205  double GetBeta() const { return m_Beta; }
206  double GetMass() const { return m_Mass; }
207 
208  // Override functions begin
209 
210  virtual std::vector<double> GetMomentum(double mass = -1.) const;
211 
212  // Override functions end
213 
214 
215  private:
216  double w(double p) const {
217  return sqrt(p*p + m_Mass * m_Mass);
218  }
219 
220  double alpha(double p) const {
221  return m_Gamma * m_Beta * p / m_T;
222  }
223 
226  double g(double x, double mass = -1.) const;
227  double g2(double x, double tp, double mass = -1.) const;
228 
230  void FixParameters();
231 
235  double GetRandom(double mass = -1.) const;
236 
237  double m_T;
238  double m_Beta;
239  double m_Mass;
240  double m_Gamma;
241  double m_Norm;
242  double m_Max;
243  };
244 
245 
256  {
257  public:
259 
269  SiemensRasmussenMomentumGeneratorGeneralized(double T, double beta, double mass, int statistics = 0, double mu = 0) :
270  SiemensRasmussenMomentumGenerator(T, beta, mass),
271  m_Generator(mass, statistics, T, mu)
272  {
273 
274  }
275 
276  // Override functions begin
277 
278  virtual std::vector<double> GetMomentum(double mass = -1.) const;
279 
280  // Override functions end
281 
282  private:
283  ThermalMomentumGenerator m_Generator;
284  };
285 
286 
287 
296  {
297  public:
309  double Tkin = 0.100, double etamax = 3.0, double mass = 0.938, int statistics = 0, double mu = 0);
310 
317 
318  double EtaMax() const { return m_EtaMax; }
319  double Mass() const { return m_Mass; }
320 
321  // Override functions begin
322 
323  virtual std::vector<double> GetMomentum(double mass = -1.) const;
324 
325  // Override functions end
326 
327  protected:
334  virtual double GetRandomZeta(MTRand& rangen = RandomGenerators::randgenMT) const;
335 
336  private:
337  BoostInvariantFreezeoutParametrization* m_FreezeoutModel;
338  ThermalMomentumGenerator m_Generator;
339  double m_Tkin;
340  double m_EtaMax;
341  double m_Mass;
342  };
343 
344 
348  {
349  public:
350 
352 
362  BreitWignerGenerator(double M, double gamma, double mthr) : m_M(M), m_Gamma(gamma), m_Mthr(mthr) { FixParameters(); }
363 
365 
373  void SetParameters(double M, double gamma, double mthr);
374 
375  // Generates random resonance mass m from relativistic Breit-Wigner distribution
383  double GetRandom() const;
384 
385  private:
387  double f(double x) const;
388 
390  void FixParameters();
391 
392  double m_M;
393  double m_Gamma;
394  double m_Mthr;
395  double m_Norm;
396  double m_Max;
397  };
398 
399 
412  {
413  public:
415 
424  ThermalBreitWignerGenerator(ThermalParticle *part, double T, double Mu) : m_part(part), m_T(T), m_Mu(Mu) { FixParameters(); }
425 
427 
436  void SetParameters(ThermalParticle *part, double T, double Mu);
437 
443  double GetRandom() const;
444 
445  protected:
447  virtual void FixParameters();
448 
450  virtual double f(double M) const;
451 
453  double m_T, m_Mu;
454  double m_Xmin, m_Xmax;
455  double m_Max;
456  };
457 
458  // Class for generating mass of resonance in accordance with its fixed Breit-Wigner distribution multiplied by the Boltzmann factor
472  {
473  public:
474 
476 
483  ThermalBreitWignerGenerator(part, T, Mu) {
484  FixParameters();
485  }
486 
488 
489  protected:
490  virtual void FixParameters();
491 
492  virtual double f(double M) const;
493  };
494  }
495 
496 } // namespace thermalfist
497 
498 
504 namespace thermalfist {
505 
508  namespace RandomGenerators {
509 
510  // Class for generating momentum of particle with mass m in accordance with Schnedermann-Sollfrank-Heinz formula with temperature T, transverse flow beta, and longitudinal flow etamax
521  {
522  public:
524 
533  SSHMomentumGenerator(double T, double betas, double etamax, double npow, double mass) :m_T(T), m_BetaS(betas), m_EtaMax(etamax), m_n(npow), m_Mass(mass) {
534  m_distr = SSHDistribution(0, m_Mass, m_T, m_BetaS, m_EtaMax, m_n, false);
535  m_dPt = 0.02;
536  m_dy = 0.05;
537  FixParameters2();
538 
539  }
540 
542 
552  void SetParameters(double T, double betas, double etamax, double npow, double mass) {
553  m_T = T;
554  m_BetaS = betas;
555  m_EtaMax = etamax;
556  m_Mass = mass;
557  m_n = npow;
558  m_distr = SSHDistribution(0, m_Mass, m_T, m_BetaS, m_EtaMax, m_n);
559  m_dPt = 0.02;
560  m_dy = 0.05;
561  FixParameters2();
562  }
563 
571  void SetMeanBetaT(double betaT) {
572  m_BetaS = (2. + m_n) / 2. * betaT;
573  m_distr = SSHDistribution(0, m_Mass, m_T, m_BetaS, m_EtaMax, m_n);
574  m_dPt = 0.02;
575  m_dy = 0.05;
576  FixParameters2();
577  }
578 
579  double GetTkin() const { return m_T; }
580  double GetBetaSurface() const { return m_BetaS; }
581  double GetMass() const { return m_Mass; }
582  double GetNPow() const { return m_n; }
583  double GetEtaMax() const { return m_EtaMax; }
584 
585  // Override functions begin
586 
587  std::vector<double> GetMomentum(double mass = -1.) const;
588 
589  // Override functions end
590 
591  private:
592  double w(double p) const {
593  return sqrt(p * p + m_Mass * m_Mass);
594  }
595 
596  double g(double x) const {
597  return m_distr.dndpt(-log(x)) / x;
598  }
599 
600  double g2(double x) const {
601  return m_dndpt.f(x);
602  }
603 
604  void FixParameters();
605 
606  void FixParameters2();
607 
608  // Finds the maximum of g(x) using the ternary search
609  void FindMaximumPt();
610 
611  void FindMaximumY(double pt);
612 
613  void FindMaximumY2(double pt);
614 
615  // Generates random pt and y
616  std::pair<double, double> GetRandom(double mass = -1.);
617 
618  std::pair<double, double> GetRandom2(double mass = -1.) const;
619 
620  double m_T, m_BetaS, m_EtaMax, m_n, m_Mass;
621  double m_MaxY, m_MaxPt;
622  SSHDistribution m_distr;
623  SplineFunction m_dndpt;
624  std::vector<SplineFunction> m_dndy;
625  std::vector<double> m_MaxYs;
626  double m_dPt;
627  double m_dy;
628  };
629 
630  }
631 
632 } // namespace thermalfist
633 
636 #endif
Class for generating mass of resonance in accordance with the constant width Breit-Wigner distributio...
int RandomPoisson(double mean)
Generates random integer distributed by Poisson with specified mean Uses randgenMT.
Class for generating the momentum of a particle in accordance with the longitudinally symmetric blast...
Base class for Monte Carlo sampling of particle momenta.
Class for generating the absolute values of the momentum of a particle in its local rest frame...
void SetParameters(double T, double betas, double etamax, double npow, double mass)
Sets the parameters of the distribution.
SiemensRasmussenMomentumGeneratorGeneralized(double T, double beta, double mass, int statistics=0, double mu=0)
Construct a new SiemensRasmussenMomentumGeneratorGeneralized object.
void SetMeanBetaT(double betaT)
Set the mean transverse flow velocity.
static int RandomBesselCombined(double a, int nu, MTRand &rangen)
SSHMomentumGenerator(double T, double betas, double etamax, double npow, double mass)
Construct a new SSHGenerator object.
Class implementing a simple linear spline.
static int RandomBesselDevroye2(double a, int nu, MTRand &rangen)
Class for generating mass of resonance in accordance with the relativistic Breit-Wigner distribution...
static int RandomBesselDevroye1(double a, int nu, MTRand &rangen)
void SetParameters(double T, double beta, double mass)
Sets the parameters of the Siemens-Rasmussen distribution.
void SetSeed(const unsigned int seed)
Set the seed of the random number generator randgenMT.
MTRand randgenMT
The Mersenne Twister random number generator.
Class containing all information about a particle specie.
static int RandomBesselNormal(double a, int nu, MTRand &rangen)
Generator of a random number from the Bessel distribution (a, nu), nu is integer Uses methods from ht...
double SkellamProbability(int k, double mu1, double mu2)
Probability of a Skellam distributed random variable with Poisson means mu1 and mu2 to have the value...
Class for generating the momentum of a particle in accordance with the Siemens-Rasmussen formula...
ThermalEnergyBreitWignerGenerator(ThermalParticle *part, double T, double Mu)
Construct a new ThermalEnergyBreitWignerGenerator object.
BreitWignerGenerator(double M, double gamma, double mthr)
Construct a new BreitWignerGenerator object.
Base class implementing a longitudinally boost-invariant azimuthally symmetric freeze-out parametriza...
ThermalMomentumGenerator(double mass=0.938, int statistics=0, double T=0.100, double mu=0.)
Construct a new ThermalMomentumGenerator object.
ThermalBreitWignerGenerator(ThermalParticle *part, double T, double Mu)
Construct a new ThermalBreitWignerGenerator object.
Class for generating momentum of a particle in accordance with a longitudinally boost invariant and a...
A generalized class for generating the momentum of a particle in accordance with the Siemens-Rasmusse...
Class for generating mass of resonance in accordance with the energy-dependent Breit-Wigner distribut...
static double pmXmOverpm(int X, int tm, double a, int nu)
static int RandomBesselPoisson(double a, int nu, MTRand &rangen)
SiemensRasmussenMomentumGenerator(double T, double beta, double mass)
Construct a new SiemensRasmussenMomentumGenerator object.
The main namespace where all classes and functions of the Thermal-FIST library reside.
Class implementing the momentum distribution in the longitudinally symmetric Blast-Wave model...
static int RandomBesselDevroye3(double a, int nu, MTRand &rangen)