Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4INCL::IFunction1D Class Referenceabstract

#include <G4INCLIFunction1D.hh>

Inheritance diagram for G4INCL::IFunction1D:

Public Types

typedef G4double(*const ManipulatorFunc )(const G4double)
 Typedef to simplify the syntax of inverseCDFTable. More...
 

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...
 
InterpolationTableinverseCDFTable (ManipulatorFunc fWrap=0, 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 58 of file G4INCLIFunction1D.hh.

Member Typedef Documentation

typedef G4double(* const G4INCL::IFunction1D::ManipulatorFunc)(const G4double)

Typedef to simplify the syntax of inverseCDFTable.

Definition at line 93 of file G4INCLIFunction1D.hh.

Constructor & Destructor Documentation

G4INCL::IFunction1D::IFunction1D ( )
inline

Definition at line 60 of file G4INCLIFunction1D.hh.

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

Here is the caller graph for this function:

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

Definition at line 64 of file G4INCLIFunction1D.hh.

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

Definition at line 69 of file G4INCLIFunction1D.hh.

69 {};

Member Function Documentation

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

Return the maximum allowed value of the independent variable.

Definition at line 75 of file G4INCLIFunction1D.hh.

75 { return xMax; }
G4double xMax
Maximum value of the independent variable.

Here is the caller graph for this function:

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

Return the minimum allowed value of the independent variable.

Definition at line 72 of file G4INCLIFunction1D.hh.

72 { return xMin; }
G4double xMin
Minimum value of the independent variable.

Here is the caller graph for this function:

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 66 of file G4INCLIFunction1D.cc.

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

Here is the call graph for this function:

InterpolationTable * G4INCL::IFunction1D::inverseCDFTable ( IFunction1D::ManipulatorFunc  fWrap = 0,
const G4int  nNodes = 60 
) const

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

The function parameter fWrap is wrapped around the return value of operator(). If fWrap=NULL (default), fWrap=identity.

Definition at line 123 of file G4INCLIFunction1D.cc.

123  {
124  class InverseCDF : public IFunction1D {
125  public:
126  InverseCDF(IFunction1D const * const f, ManipulatorFunc fw) :
127  IFunction1D(f->getXMinimum(), f->getXMaximum()),
128  theFunction(f),
129  normalisation(1./theFunction->integrate(xMin,xMax)),
130  fWrap(fw)
131  {}
132 
133  G4double operator()(const G4double x) const {
134  if(fWrap)
135  return fWrap(std::min(1., normalisation * theFunction->integrate(xMin,x)));
136  else
137  return std::min(1., normalisation * theFunction->integrate(xMin,x));
138  }
139  private:
140  IFunction1D const * const theFunction;
141  const G4double normalisation;
142  ManipulatorFunc fWrap;
143  } *theInverseCDF = new InverseCDF(this, fWrap);
144 
145  InterpolationTable *theTable = new InvFInterpolationTable(*theInverseCDF, nNodes);
146  delete theInverseCDF;
147  return theTable;
148  }
G4double(*const ManipulatorFunc)(const G4double)
Typedef to simplify the syntax of inverseCDFTable.
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

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

Definition at line 105 of file G4INCLIFunction1D.cc.

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

Here is the call graph for this function:

Member Data Documentation

G4double G4INCL::IFunction1D::xMax
protected

Maximum value of the independent variable.

Definition at line 106 of file G4INCLIFunction1D.hh.

G4double G4INCL::IFunction1D::xMin
protected

Minimum value of the independent variable.

Definition at line 104 of file G4INCLIFunction1D.hh.


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