Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Protected Attributes
G4INCL::IFunction1D Class Referenceabstract

#include <G4INCLIFunction1D.hh>

Inheritance diagram for G4INCL::IFunction1D:
G4INCL::InverseInterpolationTable G4INCL::NuclearDensityFunctions::Gaussian G4INCL::NuclearDensityFunctions::GaussianRP G4INCL::NuclearDensityFunctions::HardSphere G4INCL::NuclearDensityFunctions::ModifiedHarmonicOscillator G4INCL::NuclearDensityFunctions::ModifiedHarmonicOscillatorRP G4INCL::NuclearDensityFunctions::ParisP G4INCL::NuclearDensityFunctions::ParisR G4INCL::NuclearDensityFunctions::WoodsSaxon G4INCL::NuclearDensityFunctions::WoodsSaxonRP G4INCL::RootFunctor

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. More...
 
virtual G4double getXMaximum () const
 Return the maximum allowed value of the independent variable. More...
 
virtual G4double operator() (const G4double x) const =0
 Compute the value of the function. More...
 
virtual G4double integrate (const G4double x0, const G4double x1, const G4double step=-1.) const
 Integrate the function between two values. More...
 
IFunction1Dprimitive () const
 Return a pointer to the (numerical) primitive to this function. More...
 
InverseInterpolationTableinverseCDFTable (const G4int nNodes=60) const
 Return a pointer to the inverse of the CDF of this function. More...
 

Protected Attributes

G4double xMin
 Minimum value of the independent variable. More...
 
G4double xMax
 Maximum value of the independent variable. More...
 

Detailed Description

1D function interface

Definition at line 57 of file G4INCLIFunction1D.hh.

Constructor & Destructor Documentation

G4INCL::IFunction1D::IFunction1D ( )
inline

Definition at line 59 of file G4INCLIFunction1D.hh.

Referenced by inverseCDFTable(), and primitive().

59  :
60  xMin(0.),
61  xMax(0.)
62  {};
G4double xMin
Minimum value of the independent variable.
G4double xMax
Maximum value of the independent variable.
G4INCL::IFunction1D::IFunction1D ( const G4double  x0,
const G4double  x1 
)
inline

Definition at line 63 of file G4INCLIFunction1D.hh.

63  :
64  xMin(x0),
65  xMax(x1)
66  {};
G4double xMin
Minimum value of the independent variable.
G4double xMax
Maximum value of the independent variable.
virtual G4INCL::IFunction1D::~IFunction1D ( )
inlinevirtual

Definition at line 68 of file G4INCLIFunction1D.hh.

68 {};

Member Function Documentation

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

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().

74 { return xMax; }
G4double xMax
Maximum value of the independent variable.
virtual G4double G4INCL::IFunction1D::getXMinimum ( ) const
inlinevirtual

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().

71 { return xMin; }
G4double xMin
Minimum value of the independent variable.
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 65 of file G4INCLIFunction1D.cc.

References G4INCL::Math::max(), G4INCL::Math::min(), operator()(), G4INCL::Math::sign(), CLHEP::swap(), test::x, xMax, and xMin.

65  {
66  G4double xi = std::max(x0, xMin);
67  G4double xa = std::min(x1, xMax);
68  G4double sign;
69 
70  if(x1 <= x0) {
71  sign = -1.0;
72  std::swap(xi, xa);
73  } else
74  sign = 1.0;
75 
76  const G4double interval = xa - xi;
77 
78  G4int nIntervals;
79  if(step<0.) {
80  nIntervals = 45;
81  } else {
82  nIntervals = G4int(interval/step);
83 
84  // Round up nIntervals to the closest multiple of 9
85  G4int remainder = nIntervals % 9;
86  if (remainder != 0)
87  nIntervals += 9 - remainder;
88 
89  nIntervals = std::max(nIntervals, 9);
90  }
91 
92  const G4double dx = interval/nIntervals;
93  G4double result = (operator()(xi) + operator()(xa)) * integrationCoefficients[0]/2;
94  for(G4int j = 1; j<nIntervals; ++j) {
95  const G4double x = xi + interval*G4double(j)/G4double(nIntervals);
96  const unsigned index = j%9;
97  result += operator()(x) * integrationCoefficients[index];
98  }
99 
100  return result*dx*sign;
101 
102  }
G4double xMin
Minimum value of the independent variable.
int G4int
Definition: G4Types.hh:78
virtual G4double operator()(const G4double x) const =0
Compute the value of the function.
G4double xMax
Maximum value of the independent variable.
void swap(shared_ptr< P > &, shared_ptr< P > &)
Definition: memory.h:1247
T max(const T t1, const T t2)
brief Return the largest of the two arguments
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
double G4double
Definition: G4Types.hh:76
G4int sign(const T t)
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(), G4INCL::Math::min(), operator()(), test::x, xMax, and xMin.

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

122  {
123  class InverseCDF : public IFunction1D {
124  public:
125  InverseCDF(IFunction1D const * const f) :
126  IFunction1D(f->getXMinimum(), f->getXMaximum()),
127  theFunction(f),
128  normalisation(1./theFunction->integrate(xMin,xMax))
129  {}
130 
131  G4double operator()(const G4double x) const {
132  return std::min(1., normalisation * theFunction->integrate(xMin,x));
133  }
134  private:
135  IFunction1D const * const theFunction;
136  const G4double normalisation;
137  } *theInverseCDF = new InverseCDF(this);
138 
139  InverseInterpolationTable *theTable = new InverseInterpolationTable(*theInverseCDF, nNodes);
140  delete theInverseCDF;
141  return theTable;
142  }
G4double xMin
Minimum value of the independent variable.
virtual G4double operator()(const G4double x) const =0
Compute the value of the 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.
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
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.
double G4double
Definition: G4Types.hh:76
virtual G4double G4INCL::IFunction1D::operator() ( const G4double  x) const
pure virtual
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()(), test::x, and xMin.

104  {
105  class Primitive : public IFunction1D {
106  public:
107  Primitive(IFunction1D const * const f) :
108  IFunction1D(f->getXMinimum(), f->getXMaximum()),
109  theFunction(f)
110  {}
111 
112  G4double operator()(const G4double x) const {
113  return theFunction->integrate(xMin,x);
114  }
115  private:
116  IFunction1D const * const theFunction;
117  } *thePrimitive = new Primitive(this);
118 
119  return thePrimitive;
120  }
G4double xMin
Minimum value of the independent variable.
virtual G4double operator()(const G4double x) const =0
Compute the value of the function.
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.
double G4double
Definition: G4Types.hh:76

Field Documentation

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().


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