8 #include "Pythia8/PythiaStdlib.h"
17 string toLower(
const string& name,
bool trim) {
22 if (name.find_first_not_of(
" \n\t\v\b\r\f\a") == string::npos)
return "";
23 int firstChar = name.find_first_not_of(
" \n\t\v\b\r\f\a");
24 int lastChar = name.find_last_not_of(
" \n\t\v\b\r\f\a");
25 temp = name.substr( firstChar, lastChar + 1 - firstChar);
29 for (
int i = 0; i < int(temp.length()); ++i) temp[i] = tolower(temp[i]);
39 double GammaCoef[9] = {
40 0.99999999999980993, 676.5203681218851, -1259.1392167224028,
41 771.32342877765313, -176.61502916214059, 12.507343278686905,
42 -0.13857109526572012, 9.9843695780195716e-6, 1.5056327351493116e-7};
44 double GammaReal(
double x) {
47 if (x < 0.5)
return M_PI / (sin(M_PI * x) * GammaReal(1 - x));
51 double gamma = GammaCoef[0];
52 for (
int i = 1; i < 9; ++i) gamma += GammaCoef[i] / (z + i);
56 gamma *= sqrt(2. * M_PI) * pow(t, z + 0.5) * exp(-t);
66 double besselI0(
double x){
76 result = 1.0 + 3.5156229 * t2 + 3.0899424 * pow2(t2)
77 + 1.2067492 * pow3(t2) + 0.2659732 * pow4(t2)
78 + 0.0360768 * pow5(t2) * 0.0045813 * pow6(t2);
81 result = exp(x) / sqrt(x) * ( 0.39894228 + 0.01328592 * u
82 + 0.00225319 * pow2(u) - 0.00157565 * pow3(u)
83 + 0.00916281 * pow4(u) - 0.02057706 * pow5(u)
84 + 0.02635537 * pow6(u) - 0.01647633 * pow7(u)
85 + 0.00392377 * pow8(u) );
96 double besselI1(
double x){
106 result = x * ( 0.5 + 0.87890594 * t2 + 0.51498869 * pow2(t2)
107 + 0.15084934 * pow3(t2) + 0.02658733 * pow4(t2)
108 + 0.00301532 * pow5(t2) * 0.00032411 * pow6(t2) );
111 result = exp(x) / sqrt(x) * ( 0.39894228 - 0.03988024 * u
112 - 0.00368018 * pow2(u) + 0.00163801 * pow3(u)
113 - 0.01031555 * pow4(u) + 0.02282967 * pow5(u)
114 - 0.02895312 * pow6(u) + 0.01787654 * pow7(u)
115 - 0.00420059 * pow8(u) );
126 double besselK0(
double x){
133 double x2 = pow2(0.5 * x);
134 result = -log(0.5 * x) * besselI0(x) - 0.57721566
135 + 0.42278420 * x2 + 0.23069756 * pow2(x2)
136 + 0.03488590 * pow3(x2) + 0.00262698 * pow4(x2)
137 + 0.00010750 * pow5(x2) + 0.00000740 * pow6(x2);
140 result = exp(-x) / sqrt(x) * ( 1.25331414 - 0.07832358 * z
141 + 0.02189568 * pow2(z) - 0.01062446 * pow3(z)
142 + 0.00587872 * pow4(z) - 0.00251540 * pow5(z)
143 + 0.00053208 * pow6(z) );
154 double besselK1(
double x){
161 double x2 = pow2(0.5 * x);
162 result = log(0.5 * x) * besselI1(x) + 1./x * ( 1. + 0.15443144 * x2
163 - 0.67278579 * pow2(x2) - 0.18156897 * pow3(x2)
164 - 0.01919402 * pow4(x2) - 0.00110404 * pow5(x2)
165 - 0.00004686 * pow6(x2) );
168 result = exp(-x) / sqrt(x) * ( 1.25331414 + 0.23498619 * z
169 - 0.03655620 * pow2(z) + 0.01504268 * pow3(z)
170 - 0.00780353 * pow4(z) + 0.00325614 * pow5(z)
171 - 0.00068245 * pow6(z) );
190 double FunctionEncapsulator::f(vector<double>) {
201 bool FunctionEncapsulator::integrateGauss(
double& result,
int iArg,
double xLo,
202 double xHi, vector<double> args,
double tol) {
208 if (iArg >=
int(args.size()))
return false;
211 if (xLo >= xHi)
return true;
214 static double x8[4]={ 0.96028985649753623, 0.79666647741362674,
215 0.52553240991632899, 0.18343464249564980};
216 static double w8[4]={ 0.10122853629037626, 0.22238103445337447,
217 0.31370664587788729, 0.36268378337836198};
219 static double x16[8]={ 0.98940093499164993, 0.94457502307323258,
220 0.86563120238783174, 0.75540440835500303, 0.61787624440264375,
221 0.45801677765722739, 0.28160355077925891, 0.09501250983763744};
222 static double w16[8]={ 0.027152459411754095, 0.062253523938647893,
223 0.095158511682492785, 0.12462897125553387, 0.14959598881657673,
224 0.16915651939500254, 0.18260341504492359, 0.18945061045506850};
227 double c = 0.001/abs(xHi-xLo);
234 double zMid = 0.5*(zHi+zLo);
235 double zDel = 0.5*(zHi-zLo);
239 for (
int i=0;i<4;i++) {
240 double dz = zDel * x8[i];
241 args[iArg] = zMid+dz;
243 args[iArg] = zMid-dz;
245 s8 += w8[i]*(f1 + f2);
249 for (
int i=0;i<8;i++) {
250 double dz = zDel * x16[i];
251 args[iArg] = zMid+dz;
253 args[iArg] = zMid-dz;
255 s16 += w16[i]*(f1 + f2);
260 if (abs(s16-s8) < tol*(1+abs(s16))) {
266 if ( zLo == zHi ) nextbin =
false;
270 if (1.0 + c*abs(zDel) == 1.0) {
272 cout <<
"\n FunctionEncapsulator::integrateGauss(): cannot "
273 <<
"reach desired tolerance at double precision." << endl;
291 bool FunctionEncapsulator::brent(
double& solution,
double targetValue,
292 int iArg,
double xLo,
double xHi, vector<double> argsIn,
double tol,
299 if (iArg >=
int(argsIn.size()))
return false;
300 if (xLo > xHi)
return false;
302 vector<double> args(argsIn);
305 double f1 = f(args) - targetValue;
312 double f2 = f(args) - targetValue;
319 if ( f1 * f2 > 0.0)
return false;
324 double x3 = 0.5 * (xLo + xHi);
327 while(++iter < maxIter) {
330 double f3 = f(args) - targetValue;
337 if (f1 * f3 < 0.0) xHi = x3;
340 if ((xHi - xLo) < tol * (abs(xHi) < 1.0 ? xHi : 1.0)) {
341 solution = 0.5 * (xLo + xHi);
346 double den = (f2 - f1) * (f3 - f1) * (f2 - f3);
347 double num = x3 * (f1 - f2) * (f2 - f3 + f1) + f2 * x1 * (f2 - f3)
348 + f1 * x2 * (f3 - f1);
349 double dx = xHi - xLo;
350 if (den != 0.0) dx = f3 * num / den;
356 if ((xHi - x) * (x - xLo) < 0.0) {
357 dx = 0.5 * (xHi - xLo);