Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4INCL::IFunction1D Class Referenceabstract

#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.
 
IFunction1Dprimitive () const
 Return a pointer to the (numerical) primitive to this function.
 
InverseInterpolationTableinverseCDFTable (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.
 

Detailed Description

1D function interface

Definition at line 59 of file G4INCLIFunction1D.hh.

Constructor & Destructor Documentation

◆ IFunction1D() [1/2]

G4INCL::IFunction1D::IFunction1D ( )
inline

Definition at line 61 of file G4INCLIFunction1D.hh.

61 :
62 xMin(0.),
63 xMax(0.)
64 {};
G4double xMin
Minimum value of the independent variable.
G4double xMax
Maximum value of the independent variable.

◆ IFunction1D() [2/2]

G4INCL::IFunction1D::IFunction1D ( const G4double  x0,
const G4double  x1 
)
inline

Definition at line 65 of file G4INCLIFunction1D.hh.

65 :
66 xMin(x0),
67 xMax(x1)
68 {};

◆ ~IFunction1D()

virtual G4INCL::IFunction1D::~IFunction1D ( )
inlinevirtual

Definition at line 70 of file G4INCLIFunction1D.hh.

70{};

Member Function Documentation

◆ getXMaximum()

virtual G4double G4INCL::IFunction1D::getXMaximum ( ) const
inlinevirtual

Return the maximum allowed value of the independent variable.

Definition at line 76 of file G4INCLIFunction1D.hh.

76{ return xMax; }

Referenced by G4INCL::NuclearDensityFactory::createRPCorrelationTable(), inverseCDFTable(), G4INCL::InverseInterpolationTable::InverseInterpolationTable(), and primitive().

◆ getXMinimum()

virtual G4double G4INCL::IFunction1D::getXMinimum ( ) const
inlinevirtual

Return the minimum allowed value of the independent variable.

Definition at line 73 of file G4INCLIFunction1D.hh.

73{ return xMin; }

Referenced by G4INCL::NuclearDensityFactory::createRPCorrelationTable(), inverseCDFTable(), G4INCL::InverseInterpolationTable::InverseInterpolationTable(), and primitive().

◆ integrate()

G4double G4INCL::IFunction1D::integrate ( const G4double  x0,
const G4double  x1,
const G4double  step = -1. 
) const
virtual

Integrate the function between two values.

Parameters
x0lower integration bound
x1upper integration bound
steplargest integration step size; if <0, 45 steps will be used
Returns
$\int_{x_0}^{x_1} f(x) dx$

Definition at line 67 of file G4INCLIFunction1D.cc.

67 {
68 G4double xi = std::max(x0, xMin);
69 G4double xa = std::min(x1, xMax);
71
72 if(x1 <= x0) {
73 sign = -1.0;
74 std::swap(xi, xa);
75 } else
76 sign = 1.0;
77
78 const G4double interval = xa - xi;
79
80 G4int nIntervals;
81 if(step<0.) {
82 nIntervals = 45;
83 } else {
84 nIntervals = G4int(interval/step);
85
86 // Round up nIntervals to the closest multiple of 9
87 G4int remainder = nIntervals % 9;
88 if (remainder != 0)
89 nIntervals += 9 - remainder;
90
91 nIntervals = std::max(nIntervals, 9);
92 }
93
94 const G4double dx = interval/nIntervals;
95 G4double result = (operator()(xi) + operator()(xa)) * integrationCoefficients[0]/2;
96 for(G4int j = 1; j<nIntervals; ++j) {
97 const G4double x = xi + interval*G4double(j)/G4double(nIntervals);
98 const unsigned index = j%9;
99 result += operator()(x) * integrationCoefficients[index];
100 }
101
102 return result*dx*sign;
103
104 }
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
virtual G4double operator()(const G4double x) const =0
Compute the value of the function.
G4int sign(T t)

Referenced by primitive().

◆ inverseCDFTable()

InverseInterpolationTable * G4INCL::IFunction1D::inverseCDFTable ( const G4int  nNodes = 60) const

Return a pointer to the inverse of the CDF of this function.

Definition at line 124 of file G4INCLIFunction1D.cc.

124 {
125 class InverseCDF : public IFunction1D {
126 public:
127 InverseCDF(IFunction1D const * const f) :
128 IFunction1D(f->getXMinimum(), f->getXMaximum()),
129 theFunction(f),
130 normalisation(1./theFunction->integrate(xMin,xMax))
131 {}
132
133 G4double operator()(const G4double x) const {
134 return std::min(1., normalisation * theFunction->integrate(xMin,x));
135 }
136 private:
137 IFunction1D const * const theFunction;
138 const G4double normalisation;
139 } *theInverseCDF = new InverseCDF(this);
140
141 InverseInterpolationTable *theTable = new InverseInterpolationTable(*theInverseCDF, nNodes);
142 delete theInverseCDF;
143 return theTable;
144 }

Referenced by G4INCL::NuclearDensityFactory::createPCDFTable(), and G4INCL::NuclearDensityFactory::createRCDFTable().

◆ operator()()

◆ primitive()

IFunction1D * G4INCL::IFunction1D::primitive ( ) const

Return a pointer to the (numerical) primitive to this function.

Definition at line 106 of file G4INCLIFunction1D.cc.

106 {
107 class Primitive : public IFunction1D {
108 public:
109 Primitive(IFunction1D const * const f) :
110 IFunction1D(f->getXMinimum(), f->getXMaximum()),
111 theFunction(f)
112 {}
113
114 G4double operator()(const G4double x) const {
115 return theFunction->integrate(xMin,x);
116 }
117 private:
118 IFunction1D const * const theFunction;
119 } *thePrimitive = new Primitive(this);
120
121 return thePrimitive;
122 }

Member Data Documentation

◆ xMax

G4double G4INCL::IFunction1D::xMax
protected

Maximum value of the independent variable.

Definition at line 100 of file G4INCLIFunction1D.hh.

Referenced by getXMaximum(), and integrate().

◆ xMin

G4double G4INCL::IFunction1D::xMin
protected

Minimum value of the independent variable.

Definition at line 98 of file G4INCLIFunction1D.hh.

Referenced by getXMinimum(), and integrate().


The documentation for this class was generated from the following files: