62 , fSecondDerivative(new
G4double[number])
66 G4double p = 0.0, qn = 0.0, sig = 0.0, un = 0.0;
67 const G4double maxDerivative = 0.99e30;
70 for(i = 0; i < fNumber; ++i)
75 if(pFirstDerStart > maxDerivative)
77 fSecondDerivative[0] = 0.0;
82 fSecondDerivative[0] = -0.5;
83 u[0] = (3.0 / (fArgument[1] - fArgument[0])) *
84 ((fFunction[1] - fFunction[0]) / (fArgument[1] - fArgument[0]) -
91 for(i = 1; i < fNumber - 1; ++i)
94 (fArgument[i] - fArgument[i - 1]) / (fArgument[i + 1] - fArgument[i - 1]);
95 p = sig * fSecondDerivative[i - 1] + 2.0;
96 fSecondDerivative[i] = (sig - 1.0) / p;
98 (fFunction[i + 1] - fFunction[i]) / (fArgument[i + 1] - fArgument[i]) -
99 (fFunction[i] - fFunction[i - 1]) / (fArgument[i] - fArgument[i - 1]);
101 (6.0 * u[i] / (fArgument[i + 1] - fArgument[i - 1]) - sig * u[i - 1]) / p;
103 if(pFirstDerFinish > maxDerivative)
112 (3.0 / (fArgument[fNumber - 1] - fArgument[fNumber - 2])) *
113 (pFirstDerFinish - (fFunction[fNumber - 1] - fFunction[fNumber - 2]) /
114 (fArgument[fNumber - 1] - fArgument[fNumber - 2]));
116 fSecondDerivative[fNumber - 1] =
117 (un - qn * u[fNumber - 2]) / (qn * fSecondDerivative[fNumber - 2] + 1.0);
122 for(
G4int k = fNumber - 2; k >= 0; --k)
124 fSecondDerivative[k] =
125 fSecondDerivative[k] * fSecondDerivative[k + 1] + u[k];
152 G4int i = 0, j = 1, k = 0;
153 G4double mult = 0.0, difi = 0.0, deltaLow = 0.0, deltaUp = 0.0, cd = 0.0,
157 G4double diff = std::fabs(pX - fArgument[0]);
158 for(i = 0; i < fNumber; ++i)
160 difi = std::fabs(pX - fArgument[i]);
170 for(j = 1; j < fNumber; ++j)
172 for(i = 0; i < fNumber - j; ++i)
174 deltaLow = fArgument[i] - pX;
175 deltaUp = fArgument[i + j] - pX;
176 cd = c[i + 1] - d[i];
177 mult = deltaLow - deltaUp;
180 G4Exception(
"G4DataInterpolation::PolynomInterpolation()",
"Error",
184 d[i] = deltaUp * mult;
185 c[i] = deltaLow * mult;
187 y += (deltaY = (2 * k < (fNumber - j - 1) ? c[k + 1] : d[k--]));
207 G4double reducedY = 0.0, mult = 1.0;
210 for(i = 0; i < fNumber; ++i)
212 tempArgument[i] = cof[i] = 0.0;
214 tempArgument[fNumber - 1] = -fArgument[0];
216 for(i = 1; i < fNumber; ++i)
218 for(j = fNumber - 1 - i; j < fNumber - 1; ++j)
220 tempArgument[j] -= fArgument[i] * tempArgument[j + 1];
222 tempArgument[fNumber - 1] -= fArgument[i];
224 for(i = 0; i < fNumber; ++i)
227 for(j = fNumber - 1; j >= 1; --j)
229 factor = j * tempArgument[j] + factor * fArgument[i];
231 reducedY = fFunction[i] / factor;
233 for(j = fNumber - 1; j >= 0; --j)
235 cof[j] += mult * reducedY;
236 mult = tempArgument[j] + mult * fArgument[i];
239 delete[] tempArgument;
252 G4int i = 0, j = 1, k = 0;
254 G4double mult = 0.0, difi = 0.0, cd = 0.0, y = 0.0, cof = 0.0;
257 G4double diff = std::fabs(pX - fArgument[0]);
258 for(i = 0; i < fNumber; ++i)
260 difi = std::fabs(pX - fArgument[i]);
275 d[i] = fFunction[i] + tolerance;
278 for(j = 1; j < fNumber; ++j)
280 for(i = 0; i < fNumber - j; ++i)
282 cd = c[i + 1] - d[i];
283 difi = fArgument[i + j] - pX;
284 cof = (fArgument[i] - pX) * d[i] / difi;
285 mult = cof - c[i + 1];
288 G4Exception(
"G4DataInterpolation::RationalPolInterpolation()",
"Error",
292 d[i] = c[i + 1] * mult;
295 y += (deltaY = (2 * k < (fNumber - j - 1) ? c[k + 1] : d[k--]));
312 G4int kLow = 0, kHigh = fNumber - 1, k = 0;
317 while((kHigh - kLow) > 1)
319 k = (kHigh + kLow) >> 1;
320 if(fArgument[k] > pX)
329 G4double deltaHL = fArgument[kHigh] - fArgument[kLow];
330 if(!(deltaHL != 0.0))
332 G4Exception(
"G4DataInterpolation::CubicSplineInterpolation()",
"Error",
335 G4double a = (fArgument[kHigh] - pX) / deltaHL;
336 G4double b = (pX - fArgument[kLow]) / deltaHL;
340 return a * fFunction[kLow] + b * fFunction[kHigh] +
341 ((a * a * a - a) * fSecondDerivative[kLow] +
342 (b * b * b - b) * fSecondDerivative[kHigh]) *
343 deltaHL * deltaHL / 6.0;
354 G4double delta = fArgument[index + 1] - fArgument[index];
357 G4Exception(
"G4DataInterpolation::FastCubicSpline()",
"Error",
360 G4double a = (fArgument[index + 1] - pX) / delta;
361 G4double b = (pX - fArgument[index]) / delta;
365 return a * fFunction[index] + b * fFunction[index + 1] +
366 ((a * a * a - a) * fSecondDerivative[index] +
367 (b * b * b - b) * fSecondDerivative[index + 1]) *
415 G4int kHigh = 0, k = 0, Increment = 0;
417 G4bool ascend = (fArgument[fNumber - 1] >= fArgument[0]);
418 if(index < 0 || index > fNumber - 1)
426 if((pX >= fArgument[index]) == ascend)
428 if(index == fNumber - 1)
434 while((pX >= fArgument[kHigh]) == ascend)
437 Increment += Increment;
438 kHigh = index + Increment;
439 if(kHigh > (fNumber - 1))
454 while((pX < fArgument[index]) == ascend)
458 if(Increment >= kHigh)
464 index = kHigh - Increment;
471 while((kHigh - index) != 1)
473 k = (kHigh + index) >> 1;
474 if((pX >= fArgument[k]) == ascend)
483 if(!(pX != fArgument[fNumber - 1]))
487 if(!(pX != fArgument[0]))