00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #define INCLXX_IN_GEANT4_MODE 1
00034
00035 #include "globals.hh"
00036
00044 #ifndef G4INCLINVERSEINTERPOLATIONTABLE_HH_
00045 #define G4INCLINVERSEINTERPOLATIONTABLE_HH_
00046
00047 #include "G4INCLIFunction1D.hh"
00048 #include <algorithm>
00049 #include <functional>
00050 #include <sstream>
00051
00052 namespace G4INCL {
00053
00054
00055 class InverseInterpolationTable;
00056
00058 class InterpolationNode {
00059 public:
00060 InterpolationNode(const G4double x0, const G4double y0, const G4double yPrime0) :
00061 x(x0),
00062 y(y0),
00063 yPrime(yPrime0)
00064 {}
00065
00066 virtual ~InterpolationNode() {}
00067
00068 G4bool operator<(const InterpolationNode &rhs) const {
00069 return (x < rhs.x);
00070 }
00071
00072 G4bool operator<=(const InterpolationNode &rhs) const {
00073 return (x <= rhs.x);
00074 }
00075
00076 G4bool operator>(const InterpolationNode &rhs) const {
00077 return (x > rhs.x);
00078 }
00079
00080 G4bool operator>=(const InterpolationNode &rhs) const {
00081 return (x >= rhs.x);
00082 }
00083
00085 friend G4bool operator<(const InterpolationNode &lhs, const G4double rhs) {
00086 return lhs.x < rhs;
00087 }
00088
00089 G4double getX() const { return x; }
00090 G4double getY() const { return y; }
00091 G4double getYPrime() const { return yPrime; }
00092
00093 void setX(const G4double x0) { x=x0; }
00094 void setY(const G4double y0) { y=y0; }
00095 void setYPrime(const G4double yPrime0) { yPrime=yPrime0; }
00096
00097 std::string print() const {
00098 std::stringstream message;
00099 message << "x, y, yPrime: " << x << '\t' << y << '\t' << yPrime << std::endl;
00100 return message.str();
00101 }
00102
00103 protected:
00105 G4double x;
00107 G4double y;
00109 G4double yPrime;
00110 };
00111
00113 class InverseInterpolationTable : public IFunction1D {
00114 public:
00115 InverseInterpolationTable(IFunction1D const &f, const unsigned int nNodes=30);
00116 InverseInterpolationTable(std::vector<G4double> const &x, std::vector<G4double> const &y);
00117 virtual ~InverseInterpolationTable() {}
00118
00119 unsigned int getNumberOfNodes() const { return nodes.size(); }
00120
00121 std::vector<G4double> getNodeAbscissae() const {
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 }
00127
00128 std::vector<G4double> getNodeValues() const {
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 }
00134
00135 G4double operator()(const G4double x) const;
00136
00137 std::string print() const;
00138
00139 private:
00141 void initDerivatives();
00142
00144 void setFunctionDomain();
00145
00147 std::vector<InterpolationNode> nodes;
00148
00149 };
00150
00151 }
00152
00153 #endif // G4INCLINVERSEINTERPOLATIONTABLE_HH_