#include <G4INCLIFunction1D.hh>
Inheritance diagram for G4INCL::IFunction1D:
Public Member Functions | |
IFunction1D () | |
IFunction1D (const G4double x0, const G4double x1) | |
virtual | ~IFunction1D () |
virtual G4double | getXMinimum () const |
Return the minimum allowed value of the independent variable. | |
virtual G4double | getXMaximum () const |
Return the maximum allowed value of the independent variable. | |
virtual G4double | operator() (const G4double x) const =0 |
Compute the value of the function. | |
virtual G4double | integrate (const G4double x0, const G4double x1, const G4double step=-1.) const |
Integrate the function between two values. | |
IFunction1D * | primitive () const |
Return a pointer to the (numerical) primitive to this function. | |
InverseInterpolationTable * | inverseCDFTable (const G4int nNodes=60) const |
Return a pointer to the inverse of the CDF of this function. | |
Protected Attributes | |
G4double | xMin |
Minimum value of the independent variable. | |
G4double | xMax |
Maximum value of the independent variable. |
Definition at line 57 of file G4INCLIFunction1D.hh.
G4INCL::IFunction1D::IFunction1D | ( | ) | [inline] |
Definition at line 59 of file G4INCLIFunction1D.hh.
Referenced by inverseCDFTable(), and primitive().
00059 : 00060 xMin(0.), 00061 xMax(0.) 00062 {}; IFunction1D(const G4double x0, const G4double x1) :
virtual G4INCL::IFunction1D::~IFunction1D | ( | ) | [inline, virtual] |
virtual G4double G4INCL::IFunction1D::getXMaximum | ( | ) | const [inline, virtual] |
Return the maximum allowed value of the independent variable.
Definition at line 74 of file G4INCLIFunction1D.hh.
References xMax.
Referenced by G4INCL::NuclearDensityFactory::createRPCorrelationTable(), inverseCDFTable(), G4INCL::InverseInterpolationTable::InverseInterpolationTable(), and primitive().
00074 { return xMax; }
virtual G4double G4INCL::IFunction1D::getXMinimum | ( | ) | const [inline, virtual] |
Return the minimum allowed value of the independent variable.
Definition at line 71 of file G4INCLIFunction1D.hh.
References xMin.
Referenced by G4INCL::NuclearDensityFactory::createRPCorrelationTable(), inverseCDFTable(), G4INCL::InverseInterpolationTable::InverseInterpolationTable(), and primitive().
00071 { return xMin; }
G4double G4INCL::IFunction1D::integrate | ( | const G4double | x0, | |
const G4double | x1, | |||
const G4double | step = -1. | |||
) | const [virtual] |
Integrate the function between two values.
x0 | lower integration bound | |
x1 | upper integration bound | |
step | largest integration step size; if <0, 45 steps will be used |
Definition at line 65 of file G4INCLIFunction1D.cc.
References operator()(), G4INCL::Math::sign(), xMax, and xMin.
00065 { 00066 G4double xi = std::max(x0, xMin); 00067 G4double xa = std::min(x1, xMax); 00068 G4double sign; 00069 00070 if(x1 <= x0) { 00071 sign = -1.0; 00072 std::swap(xi, xa); 00073 } else 00074 sign = 1.0; 00075 00076 const G4double interval = xa - xi; 00077 00078 G4int nIntervals; 00079 if(step<0.) { 00080 nIntervals = 45; 00081 } else { 00082 nIntervals = G4int(interval/step); 00083 00084 // Round up nIntervals to the closest multiple of 9 00085 G4int remainder = nIntervals % 9; 00086 if (remainder != 0) 00087 nIntervals += 9 - remainder; 00088 00089 nIntervals = std::max(nIntervals, 9); 00090 } 00091 00092 const G4double dx = interval/nIntervals; 00093 G4double result = (operator()(xi) + operator()(xa)) * integrationCoefficients[0]/2; 00094 for(G4int j = 1; j<nIntervals; ++j) { 00095 const G4double x = xi + interval*G4double(j)/G4double(nIntervals); 00096 const unsigned index = j%9; 00097 result += operator()(x) * integrationCoefficients[index]; 00098 } 00099 00100 return result*dx*sign; 00101 00102 }
InverseInterpolationTable * G4INCL::IFunction1D::inverseCDFTable | ( | const G4int | nNodes = 60 |
) | const |
Return a pointer to the inverse of the CDF of this function.
Definition at line 122 of file G4INCLIFunction1D.cc.
References getXMaximum(), getXMinimum(), IFunction1D(), xMax, and xMin.
00122 { 00123 class InverseCDF : public IFunction1D { 00124 public: 00125 InverseCDF(IFunction1D const * const f) : 00126 IFunction1D(f->getXMinimum(), f->getXMaximum()), 00127 theFunction(f), 00128 normalisation(1./theFunction->integrate(xMin,xMax)) 00129 {} 00130 00131 G4double operator()(const G4double x) const { 00132 return std::min(1., normalisation * theFunction->integrate(xMin,x)); 00133 } 00134 private: 00135 IFunction1D const * const theFunction; 00136 const G4double normalisation; 00137 } *theInverseCDF = new InverseCDF(this); 00138 00139 InverseInterpolationTable *theTable = new InverseInterpolationTable(*theInverseCDF, nNodes); 00140 delete theInverseCDF; 00141 return theTable; 00142 }
Compute the value of the function.
Implemented in G4INCL::NuclearDensityFunctions::GaussianRP, G4INCL::NuclearDensityFunctions::Gaussian, G4INCL::NuclearDensityFunctions::HardSphere, G4INCL::NuclearDensityFunctions::ModifiedHarmonicOscillatorRP, G4INCL::NuclearDensityFunctions::ModifiedHarmonicOscillator, G4INCL::NuclearDensityFunctions::ParisR, G4INCL::NuclearDensityFunctions::ParisP, G4INCL::NuclearDensityFunctions::WoodsSaxonRP, G4INCL::NuclearDensityFunctions::WoodsSaxon, and G4INCL::InverseInterpolationTable.
Referenced by integrate(), and primitive().
IFunction1D * G4INCL::IFunction1D::primitive | ( | ) | const |
Return a pointer to the (numerical) primitive to this function.
Definition at line 104 of file G4INCLIFunction1D.cc.
References getXMaximum(), getXMinimum(), IFunction1D(), operator()(), and xMin.
00104 { 00105 class Primitive : public IFunction1D { 00106 public: 00107 Primitive(IFunction1D const * const f) : 00108 IFunction1D(f->getXMinimum(), f->getXMaximum()), 00109 theFunction(f) 00110 {} 00111 00112 G4double operator()(const G4double x) const { 00113 return theFunction->integrate(xMin,x); 00114 } 00115 private: 00116 IFunction1D const * const theFunction; 00117 } *thePrimitive = new Primitive(this); 00118 00119 return thePrimitive; 00120 }
G4double G4INCL::IFunction1D::xMax [protected] |
Maximum value of the independent variable.
Definition at line 98 of file G4INCLIFunction1D.hh.
Referenced by getXMaximum(), integrate(), and inverseCDFTable().
G4double G4INCL::IFunction1D::xMin [protected] |
Minimum value of the independent variable.
Definition at line 96 of file G4INCLIFunction1D.hh.
Referenced by getXMinimum(), integrate(), inverseCDFTable(), and primitive().