[833] | 1 | // |
---|
| 2 | // ******************************************************************** |
---|
| 3 | // * License and Disclaimer * |
---|
| 4 | // * * |
---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
| 7 | // * conditions of the Geant4 Software License, included in the file * |
---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
| 9 | // * include a list of copyright holders. * |
---|
| 10 | // * * |
---|
| 11 | // * Neither the authors of this software system, nor their employing * |
---|
| 12 | // * institutes,nor the agencies providing financial support for this * |
---|
| 13 | // * work make any representation or warranty, express or implied, * |
---|
| 14 | // * regarding this software system or assume any liability for its * |
---|
| 15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
| 16 | // * for the full disclaimer and the limitation of liability. * |
---|
| 17 | // * * |
---|
| 18 | // * This code implementation is the result of the scientific and * |
---|
| 19 | // * technical work of the GEANT4 collaboration. * |
---|
| 20 | // * By using, copying, modifying or distributing the software (or * |
---|
| 21 | // * any work based on the software) you agree to acknowledge its * |
---|
| 22 | // * use in resulting scientific publications, and indicate your * |
---|
| 23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
| 24 | // ******************************************************************** |
---|
| 25 | // |
---|
| 26 | // |
---|
| 27 | // $Id: G4DataInterpolation.hh,v 1.5 2006/06/29 18:59:29 gunter Exp $ |
---|
[1228] | 28 | // GEANT4 tag $Name: geant4-09-03 $ |
---|
[833] | 29 | // |
---|
| 30 | // Class description: |
---|
| 31 | // |
---|
| 32 | // The class consists of some methods for data interpolations and extrapolations. |
---|
| 33 | // The methods based mainly on recommendations given in the book : An introduction to |
---|
| 34 | // NUMERICAL METHODS IN C++, B.H. Flowers, Claredon Press, Oxford, 1995 |
---|
| 35 | // |
---|
| 36 | // ------------------------------ Data members: --------------------------------- |
---|
| 37 | // |
---|
| 38 | // fArgument and fFunction - pointers to data table to be interpolated |
---|
| 39 | // for y[i] and x[i] respectively |
---|
| 40 | // fNumber - the corresponding table size |
---|
| 41 | // ...... |
---|
| 42 | // G4DataInterpolation( G4double pX[], G4double pY[], G4int number ) |
---|
| 43 | // |
---|
| 44 | // Constructor for initializing of fArgument, fFunction and fNumber data members: |
---|
| 45 | // ...... |
---|
| 46 | // G4DataInterpolation( G4double pX[], G4double pY[], G4int number, |
---|
| 47 | // G4double pFirstDerStart, G4double pFirstDerFinish ) |
---|
| 48 | // |
---|
| 49 | // Constructor for cubic spline interpolation. It creates the array |
---|
| 50 | // fSecondDerivative[0,...fNumber-1] which is used in this interpolation by |
---|
| 51 | // the function: |
---|
| 52 | // .... |
---|
| 53 | // ~G4DataInterpolation() |
---|
| 54 | // |
---|
| 55 | // Destructor deletes dynamically created arrays for data members: fArgument, |
---|
| 56 | // fFunction and fSecondDerivative, all have dimension of fNumber |
---|
| 57 | // |
---|
| 58 | // ------------------------------ Methods: ---------------------------------------- |
---|
| 59 | // |
---|
| 60 | // G4double PolynomInterpolation(G4double pX, G4double& deltaY ) const |
---|
| 61 | // |
---|
| 62 | // This function returns the value P(pX), where P(x) is polynom of fNumber-1 degree |
---|
| 63 | // such that P(fArgument[i]) = fFunction[i], for i = 0, ..., fNumber-1 . |
---|
| 64 | // ........ |
---|
| 65 | // void PolIntCoefficient( G4double cof[]) const |
---|
| 66 | // |
---|
| 67 | // Given arrays fArgument[0,..,fNumber-1] and fFunction[0,..,fNumber-1] , this |
---|
| 68 | // function calculates an array of coefficients. The coefficients don't provide |
---|
| 69 | // usually (fNumber>10) better accuracy for polynom interpolation, as compared with |
---|
| 70 | // PolynomInterpolation function. They could be used instead for derivate |
---|
| 71 | // calculations and some other applications. |
---|
| 72 | // ......... |
---|
| 73 | // G4double RationalPolInterpolation(G4double pX, G4double& deltaY ) const |
---|
| 74 | // |
---|
| 75 | // The function returns diagonal rational function (Bulirsch and Stoer algorithm |
---|
| 76 | // of Neville type) Pn(x)/Qm(x) where P and Q are polynoms. |
---|
| 77 | // Tests showed the method is not stable and hasn't advantage if compared with |
---|
| 78 | // polynomial interpolation |
---|
| 79 | // ................ |
---|
| 80 | // G4double CubicSplineInterpolation(G4double pX) const |
---|
| 81 | // |
---|
| 82 | // Cubic spline interpolation in point pX for function given by the table: |
---|
| 83 | // fArgument, fFunction. The constructor, which creates fSecondDerivative, must be |
---|
| 84 | // called before. The function works optimal, if sequential calls are in random |
---|
| 85 | // values of pX. |
---|
| 86 | // .................. |
---|
| 87 | // G4double FastCubicSpline(G4double pX, G4int index) const |
---|
| 88 | // |
---|
| 89 | // Return cubic spline interpolation in the point pX which is located between |
---|
| 90 | // fArgument[index] and fArgument[index+1]. It is usually called in sequence of |
---|
| 91 | // known from external analysis values of index. |
---|
| 92 | // ......... |
---|
| 93 | // G4int LocateArgument(G4double pX) const |
---|
| 94 | // |
---|
| 95 | // Given argument pX, returns index k, so that pX bracketed by fArgument[k] and |
---|
| 96 | // fArgument[k+1] |
---|
| 97 | // ...................... |
---|
| 98 | // void CorrelatedSearch( G4double pX, G4int& index ) const |
---|
| 99 | // |
---|
| 100 | // Given a value pX, returns a value 'index' such that pX is between fArgument[index] |
---|
| 101 | // and fArgument[index+1]. fArgument MUST BE MONOTONIC, either increasing or |
---|
| 102 | // decreasing. If index = -1 or fNumber, this indicates that pX is out of range. |
---|
| 103 | // The value index on input is taken as the initial approximation for index on |
---|
| 104 | // output. |
---|
| 105 | |
---|
| 106 | // --------------------------------- History: -------------------------------------- |
---|
| 107 | // |
---|
| 108 | // 3.4.97 V.Grichine (Vladimir.Grichine@cern.ch) |
---|
| 109 | // |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | #ifndef G4DATAINTERPOLATION_HH |
---|
| 113 | #define G4DATAINTERPOLATION_HH |
---|
| 114 | |
---|
| 115 | #include "globals.hh" |
---|
| 116 | |
---|
| 117 | class G4DataInterpolation |
---|
| 118 | { |
---|
| 119 | public: |
---|
| 120 | G4DataInterpolation( G4double pX[], |
---|
| 121 | G4double pY[], |
---|
| 122 | G4int number ); |
---|
| 123 | |
---|
| 124 | // Constructor for cubic spline interpolation. It creates fSecond Deivative array |
---|
| 125 | // as well as fArgument and fFunction |
---|
| 126 | |
---|
| 127 | G4DataInterpolation( G4double pX[], |
---|
| 128 | G4double pY[], |
---|
| 129 | G4int number, |
---|
| 130 | G4double pFirstDerStart, |
---|
| 131 | G4double pFirstDerFinish ) ; |
---|
| 132 | |
---|
| 133 | ~G4DataInterpolation() ; |
---|
| 134 | |
---|
| 135 | G4double PolynomInterpolation( G4double pX, |
---|
| 136 | G4double& deltaY ) const ; |
---|
| 137 | |
---|
| 138 | void PolIntCoefficient( G4double cof[]) const ; |
---|
| 139 | |
---|
| 140 | G4double RationalPolInterpolation( G4double pX, |
---|
| 141 | G4double& deltaY ) const ; |
---|
| 142 | |
---|
| 143 | G4double CubicSplineInterpolation( G4double pX ) const ; |
---|
| 144 | |
---|
| 145 | G4double FastCubicSpline( G4double pX, |
---|
| 146 | G4int index ) const ; |
---|
| 147 | |
---|
| 148 | G4int LocateArgument( G4double pX ) const ; |
---|
| 149 | |
---|
| 150 | void CorrelatedSearch( G4double pX, |
---|
| 151 | G4int& index ) const ; |
---|
| 152 | |
---|
| 153 | private: |
---|
| 154 | |
---|
| 155 | G4DataInterpolation(const G4DataInterpolation&); |
---|
| 156 | G4DataInterpolation& operator=(const G4DataInterpolation&); |
---|
| 157 | |
---|
| 158 | private: |
---|
| 159 | G4double* fArgument ; |
---|
| 160 | G4double* fFunction ; |
---|
| 161 | G4double* fSecondDerivative ; |
---|
| 162 | G4int fNumber ; |
---|
| 163 | } ; |
---|
| 164 | |
---|
| 165 | #endif |
---|