34#define INCLXX_IN_GEANT4_MODE 1
54 const G4double IFunction1D::integrationCoefficients[] = {
83 nIntervals =
G4int(interval/step);
86 G4int remainder = nIntervals % 9;
88 nIntervals += 9 - remainder;
90 nIntervals = std::max(nIntervals, 9);
93 const G4double dx = interval/nIntervals;
95 for(
G4int j = 1; j<nIntervals; ++j) {
97 const unsigned index = j%9;
98 result +=
operator()(x) * integrationCoefficients[index];
101 return result*dx*sign;
126 InverseCDF(
IFunction1D const *
const f, ManipulatorFunc fw) :
129 normalisation(1./theFunction->integrate(xMin,xMax)),
135 return fWrap(std::min(1., normalisation * theFunction->integrate(xMin,x)));
137 return std::min(1., normalisation * theFunction->integrate(xMin,x));
142 ManipulatorFunc fWrap;
143 } *theInverseCDF =
new InverseCDF(
this, fWrap);
146 delete theInverseCDF;
Functor for 1-dimensional mathematical functions.
Simple interpolation table for the inverse of a IFunction1D functor.
virtual G4double operator()(const G4double x) const =0
Compute the value of the function.
virtual G4double getXMaximum() const
Return the maximum allowed value of the independent variable.
G4double xMin
Minimum value of the independent variable.
IFunction1D * primitive() const
Return a pointer to the (numerical) primitive to this function.
G4double xMax
Maximum value of the independent variable.
virtual G4double integrate(const G4double x0, const G4double x1, const G4double step=-1.) const
Integrate the function between two values.
G4double(*const) ManipulatorFunc(const G4double)
Typedef to simplify the syntax of inverseCDFTable.
InterpolationTable * inverseCDFTable(ManipulatorFunc fWrap=0, const G4int nNodes=60) const
Return a pointer to the inverse of the CDF of this function.
virtual G4double getXMinimum() const
Return the minimum allowed value of the independent variable.
Class for interpolating the of a 1-dimensional function.
Class for interpolating the inverse of a 1-dimensional function.