Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4INCL::InterpolationTable Class Reference

Class for interpolating the of a 1-dimensional function. More...

#include <G4INCLInterpolationTable.hh>

Inheritance diagram for G4INCL::InterpolationTable:
Collaboration diagram for G4INCL::InterpolationTable:

Public Member Functions

 InterpolationTable (std::vector< G4double > const &x, std::vector< G4double > const &y)
 
virtual ~InterpolationTable ()
 
unsigned int getNumberOfNodes () const
 
std::vector< G4doublegetNodeAbscissae () const
 
std::vector< G4doublegetNodeValues () const
 
G4double operator() (const G4double x) const
 Compute the value of the function. More...
 
std::string print () const
 
- Public Member Functions inherited from G4INCL::IFunction1D
 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 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 Member Functions

 InterpolationTable ()
 
void initDerivatives ()
 Initialise the values of the node derivatives. More...
 

Protected Attributes

std::vector< InterpolationNodenodes
 Interpolating nodes. More...
 
- Protected Attributes inherited from G4INCL::IFunction1D
G4double xMin
 Minimum value of the independent variable. More...
 
G4double xMax
 Maximum value of the independent variable. More...
 

Additional Inherited Members

- Public Types inherited from G4INCL::IFunction1D
typedef G4double(*const ManipulatorFunc )(const G4double)
 Typedef to simplify the syntax of inverseCDFTable. More...
 

Detailed Description

Class for interpolating the of a 1-dimensional function.

Definition at line 106 of file G4INCLInterpolationTable.hh.

Constructor & Destructor Documentation

G4INCL::InterpolationTable::InterpolationTable ( std::vector< G4double > const &  x,
std::vector< G4double > const &  y 
)

Definition at line 54 of file G4INCLInterpolationTable.cc.

55  : IFunction1D(x.front(), x.back())
56  {
57 // assert(x.size()==y.size());
58  // Assert that the x vector is sorted
59 // assert(std::adjacent_find(nodes.begin(), nodes.end(), std::greater<InterpolationNode>()) == nodes.end());
60 
61  for(unsigned i = 0; i < x.size(); ++i)
62  nodes.push_back(InterpolationNode(x.at(i), y.at(i), 0.));
63 
65  }
void initDerivatives()
Initialise the values of the node derivatives.
tuple x
Definition: test.py:50
std::vector< InterpolationNode > nodes
Interpolating nodes.

Here is the call graph for this function:

virtual G4INCL::InterpolationTable::~InterpolationTable ( )
inlinevirtual

Definition at line 109 of file G4INCLInterpolationTable.hh.

109 {}
G4INCL::InterpolationTable::InterpolationTable ( )
protected

Definition at line 52 of file G4INCLInterpolationTable.cc.

Member Function Documentation

std::vector< G4double > G4INCL::InterpolationTable::getNodeAbscissae ( ) const

Definition at line 67 of file G4INCLInterpolationTable.cc.

67  {
68  std::vector<G4double> x(nodes.size());
69  std::transform(nodes.begin(), nodes.end(), x.begin(),
70  std::mem_fun_ref(&InterpolationNode::getX));
71  return x;
72  }
tuple x
Definition: test.py:50
std::vector< InterpolationNode > nodes
Interpolating nodes.

Here is the call graph for this function:

std::vector< G4double > G4INCL::InterpolationTable::getNodeValues ( ) const

Definition at line 74 of file G4INCLInterpolationTable.cc.

74  {
75  std::vector<G4double> y(nodes.size());
76  std::transform(nodes.begin(), nodes.end(), y.begin(),
77  std::mem_fun_ref(&InterpolationNode::getY));
78  return y;
79  }
std::vector< InterpolationNode > nodes
Interpolating nodes.

Here is the call graph for this function:

unsigned int G4INCL::InterpolationTable::getNumberOfNodes ( ) const
inline

Definition at line 111 of file G4INCLInterpolationTable.hh.

111 { return nodes.size(); }
std::vector< InterpolationNode > nodes
Interpolating nodes.
void G4INCL::InterpolationTable::initDerivatives ( )
protected

Initialise the values of the node derivatives.

Definition at line 81 of file G4INCLInterpolationTable.cc.

81  {
82  for(unsigned i = 0; i < nodes.size()-1; i++) {
83  if((nodes.at(i+1).getX() - nodes.at(i).getX()) == 0.0) // Safeguard against division by zero
84  nodes[i].setYPrime(0.0);
85  else
86  nodes[i].setYPrime((nodes.at(i+1).getY() - nodes.at(i).getY())/(nodes.at(i+1).getX() - nodes.at(i).getX()));
87  }
88  nodes.back().setYPrime(nodes.at(nodes.size()-2).getYPrime()); // Duplicate the last value
89  }
std::vector< InterpolationNode > nodes
Interpolating nodes.

Here is the caller graph for this function:

G4double G4INCL::InterpolationTable::operator() ( const G4double  x) const
virtual

Compute the value of the function.

Implements G4INCL::IFunction1D.

Definition at line 91 of file G4INCLInterpolationTable.cc.

91  {
92  // Find the relevant interpolation bin
93  InterpolationNode xNode(x,0.,0.);
94  std::vector<InterpolationNode>::const_iterator iter =
95  std::lower_bound(nodes.begin(), nodes.end(), xNode);
96 
97  if(iter==nodes.begin())
98  return nodes.front().getY();
99 
100  if(iter==nodes.end())
101  return nodes.back().getY();
102 
103  std::vector<InterpolationNode>::const_iterator previousIter = iter - 1;
104  const G4double dx = x - previousIter->getX();
105  return previousIter->getY() + previousIter->getYPrime()*dx;
106  }
tuple x
Definition: test.py:50
double G4double
Definition: G4Types.hh:76
std::vector< InterpolationNode > nodes
Interpolating nodes.
std::string G4INCL::InterpolationTable::print ( ) const

Definition at line 108 of file G4INCLInterpolationTable.cc.

108  {
109  std::string message;
110  for(std::vector<InterpolationNode>::const_iterator n=nodes.begin(), e=nodes.end(); n!=e; ++n)
111  message += n->print();
112  return message;
113  }
const G4int n
std::vector< InterpolationNode > nodes
Interpolating nodes.

Here is the caller graph for this function:

Member Data Documentation

std::vector<InterpolationNode> G4INCL::InterpolationTable::nodes
protected

Interpolating nodes.

Definition at line 128 of file G4INCLInterpolationTable.hh.


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