#include <G4INCLInverseInterpolationTable.hh>
Inheritance diagram for G4INCL::InverseInterpolationTable:
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< G4double > | getNodeAbscissae () const |
std::vector< G4double > | getNodeValues () const |
G4double | operator() (const G4double x) const |
Compute the value of the function. | |
std::string | print () const |
Definition at line 113 of file G4INCLInverseInterpolationTable.hh.
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().
00051 { 00052 // assert(nNodes>2); 00053 00054 const G4double x0 = f.getXMinimum(); 00055 const G4double x1 = f.getXMaximum(); 00056 00057 // Build the nodes 00058 G4double last = f(x0); 00059 InterpolationNode firstNode(last, x0, 0.); 00060 nodes.push_back(firstNode); 00061 G4int skippedNodes = 0; 00062 for(unsigned i = 1; i < nNodes; i++) { 00063 const G4double xi = x0 + i*(x1-x0)/((G4double)(nNodes-1)); 00064 // Make sure that the x vector is sorted (corresponding to a monotonous 00065 // function) 00066 const G4double value = f(xi); 00067 if(value <= last) { 00068 ++skippedNodes; 00069 continue; 00070 } 00071 InterpolationNode node(value, xi, 0.); 00072 nodes.push_back(node); 00073 last = value; 00074 } 00075 00076 // assert(nNodes==nodes.size()+skippedNodes); 00077 00078 // Initialise the "derivative" values 00079 initDerivatives(); 00080 setFunctionDomain(); 00081 }
G4INCL::InverseInterpolationTable::InverseInterpolationTable | ( | std::vector< G4double > const & | x, | |
std::vector< G4double > const & | y | |||
) |
Definition at line 83 of file G4INCLInverseInterpolationTable.cc.
00083 { 00084 // assert(x.size()==y.size()); 00085 // Assert that the x vector is sorted (corresponding to a monotonous 00086 // function 00087 // assert(std::adjacent_find(nodes.begin(), nodes.end(), std::greater<InterpolationNode>()) == nodes.end()); 00088 00089 for(unsigned i = 0; i < x.size(); ++i) 00090 nodes.push_back(InterpolationNode(x.at(i), y.at(i), 0.)); 00091 00092 initDerivatives(); 00093 setFunctionDomain(); 00094 }
virtual G4INCL::InverseInterpolationTable::~InverseInterpolationTable | ( | ) | [inline, virtual] |
std::vector<G4double> G4INCL::InverseInterpolationTable::getNodeAbscissae | ( | ) | const [inline] |
Definition at line 121 of file G4INCLInverseInterpolationTable.hh.
References G4INCL::InterpolationNode::getX().
00121 { 00122 std::vector<G4double> x(nodes.size()); 00123 std::transform(nodes.begin(), nodes.end(), x.begin(), 00124 std::mem_fun_ref(&InterpolationNode::getX)); 00125 return x; 00126 }
std::vector<G4double> G4INCL::InverseInterpolationTable::getNodeValues | ( | ) | const [inline] |
Definition at line 128 of file G4INCLInverseInterpolationTable.hh.
References G4INCL::InterpolationNode::getY().
00128 { 00129 std::vector<G4double> y(nodes.size()); 00130 std::transform(nodes.begin(), nodes.end(), y.begin(), 00131 std::mem_fun_ref(&InterpolationNode::getY)); 00132 return y; 00133 }
unsigned int G4INCL::InverseInterpolationTable::getNumberOfNodes | ( | ) | const [inline] |
Compute the value of the function.
Implements G4INCL::IFunction1D.
Definition at line 117 of file G4INCLInverseInterpolationTable.cc.
00117 { 00118 // Find the relevant interpolation bin 00119 std::vector<InterpolationNode>::const_iterator iter = 00120 std::lower_bound(nodes.begin(), nodes.end(), x); 00121 00122 if(iter==nodes.begin()) 00123 return nodes.front().getY(); 00124 00125 if(iter==nodes.end()) 00126 return nodes.back().getY(); 00127 00128 std::vector<InterpolationNode>::const_iterator previousIter = iter - 1; 00129 const G4double dx = x - previousIter->getX(); 00130 return previousIter->getY() + previousIter->getYPrime()*dx; 00131 }
std::string G4INCL::InverseInterpolationTable::print | ( | ) | const |
Definition at line 133 of file G4INCLInverseInterpolationTable.cc.
References CLHEP::detail::n.
Referenced by G4INCL::NuclearDensityFactory::createPCDFTable(), G4INCL::NuclearDensityFactory::createRCDFTable(), and G4INCL::NuclearDensity::NuclearDensity().
00133 { 00134 std::string message; 00135 for(std::vector<InterpolationNode>::const_iterator n=nodes.begin(); n!=nodes.end(); ++n) 00136 message += n->print(); 00137 return message; 00138 }