Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4INCL::InverseInterpolationTable Class Reference

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

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

Additional Inherited Members

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

Detailed Description

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

Definition at line 115 of file G4INCLInverseInterpolationTable.hh.

Constructor & Destructor Documentation

◆ InverseInterpolationTable() [1/2]

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

Definition at line 53 of file G4INCLInverseInterpolationTable.cc.

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

◆ InverseInterpolationTable() [2/2]

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

Definition at line 85 of file G4INCLInverseInterpolationTable.cc.

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

◆ ~InverseInterpolationTable()

virtual G4INCL::InverseInterpolationTable::~InverseInterpolationTable ( )
inlinevirtual

Definition at line 119 of file G4INCLInverseInterpolationTable.hh.

119{}

Member Function Documentation

◆ getNodeAbscissae()

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

Definition at line 123 of file G4INCLInverseInterpolationTable.hh.

123 {
124 std::vector<G4double> x(nodes.size());
125 std::transform(nodes.begin(), nodes.end(), x.begin(),
126 std::mem_fun_ref(&InterpolationNode::getX));
127 return x;
128 }

◆ getNodeValues()

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

Definition at line 130 of file G4INCLInverseInterpolationTable.hh.

130 {
131 std::vector<G4double> y(nodes.size());
132 std::transform(nodes.begin(), nodes.end(), y.begin(),
133 std::mem_fun_ref(&InterpolationNode::getY));
134 return y;
135 }

◆ getNumberOfNodes()

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

Definition at line 121 of file G4INCLInverseInterpolationTable.hh.

121{ return nodes.size(); }

◆ operator()()

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

Compute the value of the function.

Implements G4INCL::IFunction1D.

Definition at line 119 of file G4INCLInverseInterpolationTable.cc.

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

◆ print()

std::string G4INCL::InverseInterpolationTable::print ( ) const

Definition at line 135 of file G4INCLInverseInterpolationTable.cc.

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

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


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