File indexing completed on 2025-01-18 10:06:26
0001
0002
0003
0004
0005
0006
0007 #ifndef Pythia8_MathTools_H
0008 #define Pythia8_MathTools_H
0009
0010
0011 #include "Pythia8/Basics.h"
0012 #include "Pythia8/PythiaStdlib.h"
0013
0014 namespace Pythia8 {
0015
0016
0017
0018
0019 double gammaReal(double x);
0020
0021
0022 double besselI0(double x);
0023 double besselI1(double x);
0024 double besselK0(double x);
0025 double besselK1(double x);
0026
0027
0028 bool integrateGauss(double& resultOut, function<double(double)> f,
0029 double xLo, double xHi, double tol=1e-6);
0030
0031
0032 bool brent(double& solutionOut, function<double(double)> f,
0033 double target, double xLo, double xHi, double tol=1e-6, int maxIter = 10000);
0034
0035
0036 double gramDet(double s01tilde, double s12tilde, double s02tilde,
0037 double m0, double m1, double m2);
0038 double gramDet(Vec4 p0, Vec4 p1, Vec4 p2);
0039
0040
0041 double Li2 (const double, const double kmax = 100.0, const double xerr = 1e-9);
0042
0043
0044 double factorial(const int);
0045
0046
0047 int binomial (const int,int);
0048
0049
0050 double lambertW (const double x);
0051
0052
0053 double kallenFunction(const double x, const double y, const double z);
0054
0055
0056 vector<double> linSpace(int nPts, double xMin, double xMax);
0057 vector<double> logSpace(int nPts, double xMin, double xMax);
0058
0059
0060
0061
0062
0063
0064
0065 class LinearInterpolator {
0066
0067 public:
0068
0069 LinearInterpolator() = default;
0070
0071
0072 LinearInterpolator(double leftIn, double rightIn, vector<double> ysIn)
0073 : leftSave(leftIn), rightSave(rightIn), ysSave(ysIn) { }
0074
0075
0076 const vector<double>& data() const { return ysSave; }
0077
0078
0079 double left() const { return leftSave; }
0080 double right() const { return rightSave; }
0081 double dx() const { return (rightSave - leftSave) / (ysSave.size() - 1); }
0082 double xi(int i) const { return leftSave + i * dx(); }
0083
0084
0085 double at(double x) const;
0086 double operator()(double x) const { return at(x); }
0087
0088
0089 Hist plot(string title) const;
0090 Hist plot(string title, double xMin, double xMax) const;
0091
0092
0093 double sample(Rndm& rndm) const;
0094
0095 private:
0096
0097
0098 double leftSave, rightSave;
0099 vector<double> ysSave;
0100
0101 };
0102
0103
0104
0105
0106
0107
0108
0109 class LogInterpolator {
0110
0111 public:
0112
0113
0114 LogInterpolator() = default;
0115
0116
0117 LogInterpolator(double leftIn, double rightIn, vector<double> ysIn)
0118 : leftSave(leftIn), rightSave(rightIn), ysSave(ysIn) {
0119 if (ysIn.size() <= 1)
0120 rxSave = numeric_limits<double>::quiet_NaN();
0121 else
0122 rxSave = pow(rightSave / leftSave, 1. / (ysSave.size() - 1));
0123 }
0124
0125
0126 const vector<double>& data() const { return ysSave; }
0127
0128
0129 double left() const { return leftSave; }
0130 double right() const { return rightSave; }
0131 double rx() const { return rxSave; }
0132
0133
0134 double at(double x) const;
0135 double operator()(double x) const { return at(x); }
0136
0137
0138 Hist plot(string title, int nBins, double xMin, double xMax) const;
0139
0140 private:
0141
0142
0143 double leftSave, rightSave, rxSave;
0144 vector<double> ysSave;
0145
0146 };
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187 class HungarianAlgorithm {
0188
0189 public:
0190
0191
0192 double solve(vector <vector<double> >& distMatrix, vector<int>& assignment);
0193
0194 private:
0195
0196
0197
0198 void optimal(vector<int>& assignment, double& cost,
0199 vector<double>& distMatrix, int nOfRows, int nOfColumns);
0200
0201 void vect(vector<int>& assignment, vector<bool>& starMatrix, int nOfRows,
0202 int nOfColumns);
0203
0204 void calcCost(vector<int>& assignment, double& cost,
0205 vector<double>& distMatrix, int nOfRows);
0206
0207 void step2a(vector<int>& assignment, vector<double>& distMatrix,
0208 vector<bool>& starMatrix, vector<bool>& newStarMatrix,
0209 vector<bool>& primeMatrix, vector<bool>& coveredColumns,
0210 vector<bool>& coveredRows, int nOfRows, int nOfColumns, int minDim);
0211
0212 void step2b(vector<int>& assignment, vector<double>& distMatrix,
0213 vector<bool>& starMatrix, vector<bool>& newStarMatrix,
0214 vector<bool>& primeMatrix, vector<bool>& coveredColumns,
0215 vector<bool>& coveredRows, int nOfRows, int nOfColumns, int minDim);
0216
0217 void step3(vector<int>& assignment, vector<double>& distMatrix,
0218 vector<bool>& starMatrix, vector<bool>& newStarMatrix,
0219 vector<bool>& primeMatrix, vector<bool>& coveredColumns,
0220 vector<bool>& coveredRows, int nOfRows, int nOfColumns, int minDim);
0221
0222 void step4(vector<int>& assignment, vector<double>& distMatrix,
0223 vector<bool>& starMatrix, vector<bool>& newStarMatrix,
0224 vector<bool>& primeMatrix, vector<bool>& coveredColumns,
0225 vector<bool>& coveredRows, int nOfRows, int nOfColumns, int minDim,
0226 int row, int col);
0227
0228 void step5(vector<int>& assignment, vector<double>& distMatrix,
0229 vector<bool>& starMatrix, vector<bool>& newStarMatrix,
0230 vector<bool>& primeMatrix, vector<bool>& coveredColumns,
0231 vector<bool>& coveredRows, int nOfRows, int nOfColumns, int minDim);
0232
0233 };
0234
0235
0236
0237 }
0238
0239 #endif