StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
MathTools.h
1 // MathTools.h is a part of the PYTHIA event generator.
2 // Copyright (C) 2020 Torbjorn Sjostrand.
3 // PYTHIA is licenced under the GNU GPL v2 or later, see COPYING for details.
4 // Please respect the MCnet Guidelines, see GUIDELINES for details.
5 
6 // Header file for some mathematics tools, like special functions.
7 #ifndef Pythia8_MathTools_H
8 #define Pythia8_MathTools_H
9 
10 // Header file for the MathTools methods.
11 #include "Pythia8/Basics.h"
12 #include "Pythia8/PythiaStdlib.h"
13 
14 namespace Pythia8 {
15 
16 //==========================================================================
17 
18 // The Gamma function for real argument.
19 double GammaReal(double x);
20 
21 // Modified Bessel functions of the first and second kinds.
22 double besselI0(double x);
23 double besselI1(double x);
24 double besselK0(double x);
25 double besselK1(double x);
26 
27 // Integrate f(x) dx over the specified range
28 bool integrateGauss(double& resultOut, function<double(double)> f,
29  double xLo, double xHi, double tol=1e-6);
30 
31 // Solve f(x) = target for x in the specified range
32 bool brent(double& solutionOut, function<double(double)> f,
33  double target, double xLo, double xHi, double tol=1e-6, int maxIter = 10000);
34 
35 //==========================================================================
36 
37 // LinearInterpolator class.
38 // Used to interpolate between values in linearly spaced data.
39 
41 
42 public:
43 
44  LinearInterpolator() = default;
45 
46  // Constructor.
47  LinearInterpolator(double leftIn, double rightIn, vector<double> ysIn)
48  : leftSave(leftIn), rightSave(rightIn), ysSave(ysIn) { }
49 
50  // Function to get y-values of interpolation data.
51  const vector<double>& data() const { return ysSave; }
52 
53  // x-values are linearly spaced on the interpolation region.
54  double left() const { return leftSave; }
55  double right() const { return rightSave; }
56  double dx() const { return (rightSave - leftSave) / (ysSave.size() - 1); }
57 
58  // Operator to get interpolated value at the specified point.
59  double operator()(double x) const;
60 
61  // Plot the data points of this LinearInterpolator in a histogram.
62  Hist plot(string title) const;
63  Hist plot(string title, double xMin, double xMax) const;
64 
65 private:
66 
67  // Data members
68  double leftSave, rightSave;
69  vector<double> ysSave;
70 
71 };
72 
73 //==========================================================================
74 
75 } // end namespace Pythia8
76 
77 #endif // Pythia8_MathTools_H