Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions
G4INCL::InverseInterpolationTable Class Reference

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

#include <G4INCLInverseInterpolationTable.hh>

Inheritance diagram for G4INCL::InverseInterpolationTable:
G4INCL::IFunction1D

Public Member Functions

 InverseInterpolationTable (IFunction1D const &f, const unsigned int nNodes=30)
 
 InverseInterpolationTable (std::vector< G4double > const &x, std::vector< G4double > const &y)
 
virtual ~InverseInterpolationTable ()
 
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...
 
InverseInterpolationTableinverseCDFTable (const G4int nNodes=60) const
 Return a pointer to the inverse of the CDF of this function. More...
 

Additional Inherited Members

- Protected Attributes inherited from G4INCL::IFunction1D
G4double xMin
 Minimum value of the independent variable. More...
 
G4double xMax
 Maximum value of the independent variable. More...
 

Detailed Description

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

Definition at line 108 of file G4INCLInverseInterpolationTable.hh.

Constructor & Destructor Documentation

G4INCL::InverseInterpolationTable::InverseInterpolationTable ( IFunction1D const &  f,
const unsigned int  nNodes = 30 
)

Definition at line 51 of file G4INCLInverseInterpolationTable.cc.

References G4INCL::IFunction1D::getXMaximum(), and G4INCL::IFunction1D::getXMinimum().

51  {
52 // assert(nNodes>2);
53 
54  const G4double x0 = f.getXMinimum();
55  const G4double x1 = f.getXMaximum();
56 
57  // Build the nodes
58  G4double last = f(x0);
59  InterpolationNode firstNode(last, x0, 0.);
60  nodes.push_back(firstNode);
61  G4int skippedNodes = 0;
62  for(unsigned i = 1; i < nNodes; i++) {
63  const G4double xi = x0 + i*(x1-x0)/((G4double)(nNodes-1));
64  // Make sure that the x vector is sorted (corresponding to a monotonous
65  // function)
66  const G4double value = f(xi);
67  if(value <= last) {
68  ++skippedNodes;
69  continue;
70  }
71  InterpolationNode node(value, xi, 0.);
72  nodes.push_back(node);
73  last = value;
74  }
75 
76 // assert(nNodes==nodes.size()+skippedNodes);
77 
78  // Initialise the "derivative" values
79  initDerivatives();
80  setFunctionDomain();
81  }
int G4int
Definition: G4Types.hh:78
const XML_Char int const XML_Char * value
double G4double
Definition: G4Types.hh:76
G4INCL::InverseInterpolationTable::InverseInterpolationTable ( std::vector< G4double > const &  x,
std::vector< G4double > const &  y 
)

Definition at line 83 of file G4INCLInverseInterpolationTable.cc.

83  {
84 // assert(x.size()==y.size());
85  // Assert that the x vector is sorted (corresponding to a monotonous
86  // function
87 // assert(std::adjacent_find(nodes.begin(), nodes.end(), std::greater<InterpolationNode>()) == nodes.end());
88 
89  for(unsigned i = 0; i < x.size(); ++i)
90  nodes.push_back(InterpolationNode(x.at(i), y.at(i), 0.));
91 
92  initDerivatives();
93  setFunctionDomain();
94  }
virtual G4INCL::InverseInterpolationTable::~InverseInterpolationTable ( )
inlinevirtual

Definition at line 112 of file G4INCLInverseInterpolationTable.hh.

112 {}

Member Function Documentation

std::vector<G4double> G4INCL::InverseInterpolationTable::getNodeAbscissae ( ) const
inline

Definition at line 116 of file G4INCLInverseInterpolationTable.hh.

References G4INCL::InterpolationNode::getX(), and test::x.

116  {
117  std::vector<G4double> x(nodes.size());
118  std::transform(nodes.begin(), nodes.end(), x.begin(),
119  std::mem_fun_ref(&InterpolationNode::getX));
120  return x;
121  }
std::vector<G4double> G4INCL::InverseInterpolationTable::getNodeValues ( ) const
inline

Definition at line 123 of file G4INCLInverseInterpolationTable.hh.

References G4INCL::InterpolationNode::getY().

123  {
124  std::vector<G4double> y(nodes.size());
125  std::transform(nodes.begin(), nodes.end(), y.begin(),
126  std::mem_fun_ref(&InterpolationNode::getY));
127  return y;
128  }
unsigned int G4INCL::InverseInterpolationTable::getNumberOfNodes ( ) const
inline

Definition at line 114 of file G4INCLInverseInterpolationTable.hh.

114 { return nodes.size(); }
G4double G4INCL::InverseInterpolationTable::operator() ( const G4double  x) const
virtual

Compute the value of the function.

Implements G4INCL::IFunction1D.

Definition at line 117 of file G4INCLInverseInterpolationTable.cc.

117  {
118  // Find the relevant interpolation bin
119  InterpolationNode xNode(x,0.,0.);
120  std::vector<InterpolationNode>::const_iterator iter =
121  std::lower_bound(nodes.begin(), nodes.end(), xNode);
122 
123  if(iter==nodes.begin())
124  return nodes.front().getY();
125 
126  if(iter==nodes.end())
127  return nodes.back().getY();
128 
129  std::vector<InterpolationNode>::const_iterator previousIter = iter - 1;
130  const G4double dx = x - previousIter->getX();
131  return previousIter->getY() + previousIter->getYPrime()*dx;
132  }
double G4double
Definition: G4Types.hh:76
std::string G4INCL::InverseInterpolationTable::print ( ) const

Definition at line 134 of file G4INCLInverseInterpolationTable.cc.

References n.

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

134  {
135  std::string message;
136  for(std::vector<InterpolationNode>::const_iterator n=nodes.begin(), e=nodes.end(); n!=e; ++n)
137  message += n->print();
138  return message;
139  }
const G4int n

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