00001 // 00002 // ******************************************************************** 00003 // * License and Disclaimer * 00004 // * * 00005 // * The Geant4 software is copyright of the Copyright Holders of * 00006 // * the Geant4 Collaboration. It is provided under the terms and * 00007 // * conditions of the Geant4 Software License, included in the file * 00008 // * LICENSE and available at http://cern.ch/geant4/license . These * 00009 // * include a list of copyright holders. * 00010 // * * 00011 // * Neither the authors of this software system, nor their employing * 00012 // * institutes,nor the agencies providing financial support for this * 00013 // * work make any representation or warranty, express or implied, * 00014 // * regarding this software system or assume any liability for its * 00015 // * use. Please see the license in the file LICENSE and URL above * 00016 // * for the full disclaimer and the limitation of liability. * 00017 // * * 00018 // * This code implementation is the result of the scientific and * 00019 // * technical work of the GEANT4 collaboration. * 00020 // * By using, copying, modifying or distributing the software (or * 00021 // * any work based on the software) you agree to acknowledge its * 00022 // * use in resulting scientific publications, and indicate your * 00023 // * acceptance of all terms of the Geant4 Software license. * 00024 // ******************************************************************** 00025 // 00026 // 00027 // $Id$ 00028 // 00029 // Class description: 00030 // 00031 // Class creating the Chebyshev approximation for a function pointed by fFunction 00032 // data member. The Chebyshev polinom approximation provides an efficient evaluation 00033 // of minimax polynomial, which (among all polynomials of the same degree) has the 00034 // smallest maximum deviation from the true function. 00035 // The methods based mainly on recommendations given in the book : An introduction to 00036 // NUMERICAL METHODS IN C++, B.H. Flowers, Claredon Press, Oxford, 1995 00037 // 00038 // ------------------------- MEMBER DATA ------------------------------------ 00039 // 00040 // function fFunction - pointer to a function considered 00041 // G4int fNumber - number of Chebyshev coefficients 00042 // G4double* fChebyshevCof - array of Chebyshev coefficients 00043 // G4double fMean = (a+b)/2 - mean point of interval 00044 // G4double fDiff = (b-a)/2 - half of the interval value 00045 // 00046 // ------------------------ CONSTRUCTORS ---------------------------------- 00047 // 00048 // Constructor for initialisation of the class data members. It creates the array 00049 // fChebyshevCof[0,...,fNumber-1], fNumber = n ; which consists of Chebyshev 00050 // coefficients describing the function pointed by pFunction. The values a and b 00051 // fixe the interval of validity of Chebyshev approximation. 00052 // 00053 // G4ChebyshevApproximation( function pFunction, 00054 // G4int n, 00055 // G4double a, 00056 // G4double b ) 00057 // 00058 // -------------------------------------------------------------------- 00059 // 00060 // Constructor for creation of Chebyshev coefficients for m-derivative 00061 // from pFunction. The value of m ! MUST BE ! < n , because the result 00062 // array of fChebyshevCof will be of (n-m) size. There is a definite dependence 00063 // between the proper selection of n, m, a and b values to get better accuracy 00064 // of the derivative value. 00065 // 00066 // G4ChebyshevApproximation( function pFunction, 00067 // G4int n, 00068 // G4int m, 00069 // G4double a, 00070 // G4double b ) 00071 // 00072 // ------------------------------------------------------ 00073 // 00074 // Constructor for creation of Chebyshev coefficients for integral 00075 // from pFunction. 00076 // 00077 // G4ChebyshevApproximation( function pFunction, 00078 // G4double a, 00079 // G4double b, 00080 // G4int n ) 00081 // 00082 // --------------------------------------------------------------- 00083 // 00084 // Destructor deletes the array of Chebyshev coefficients 00085 // 00086 // ~G4ChebyshevApproximation() 00087 // 00088 // ----------------------------- METHODS ---------------------------------- 00089 // 00090 // Access function for Chebyshev coefficients 00091 // 00092 // G4double GetChebyshevCof(G4int number) const 00093 // 00094 // -------------------------------------------------------------- 00095 // 00096 // Evaluate the value of fFunction at the point x via the Chebyshev coefficients 00097 // fChebyshevCof[0,...,fNumber-1] 00098 // 00099 // G4double ChebyshevEvaluation(G4double x) const 00100 // 00101 // ------------------------------------------------------------------ 00102 // 00103 // Returns the array derCof[0,...,fNumber-2], the Chebyshev coefficients of the 00104 // derivative of the function whose coefficients are fChebyshevCof 00105 // 00106 // void DerivativeChebyshevCof(G4double derCof[]) const 00107 // 00108 // ------------------------------------------------------------------------ 00109 // 00110 // This function produces the array integralCof[0,...,fNumber-1] , the Chebyshev 00111 // coefficients of the integral of the function whose coefficients are 00112 // fChebyshevCof. The constant of integration is set so that the integral vanishes 00113 // at the point (fMean - fDiff) 00114 // 00115 // void IntegralChebyshevCof(G4double integralCof[]) const 00116 00117 // --------------------------- HISTORY -------------------------------------- 00118 // 00119 // 24.04.97 V.Grichine ( Vladimir.Grichine@cern.ch ) 00120 00121 #ifndef G4CHEBYSHEVAPPROXIMATION_HH 00122 #define G4CHEBYSHEVAPPROXIMATION_HH 00123 00124 #include "globals.hh" 00125 00126 typedef G4double (*function)(G4double) ; 00127 00128 class G4ChebyshevApproximation 00129 { 00130 public: // with description 00131 00132 G4ChebyshevApproximation( function pFunction, 00133 G4int n, 00134 G4double a, 00135 G4double b ) ; 00136 // 00137 // Constructor for creation of Chebyshev coefficients for m-derivative 00138 // from pFunction. The value of m ! MUST BE ! < n , because the result 00139 // array of fChebyshevCof will be of (n-m) size. 00140 00141 G4ChebyshevApproximation( function pFunction, 00142 G4int n, 00143 G4int m, 00144 G4double a, 00145 G4double b ) ; 00146 // 00147 // Constructor for creation of Chebyshev coefficients for integral 00148 // from pFunction. 00149 00150 G4ChebyshevApproximation( function pFunction, 00151 G4double a, 00152 G4double b, 00153 G4int n ) ; 00154 00155 ~G4ChebyshevApproximation() ; 00156 00157 // Access functions 00158 00159 G4double GetChebyshevCof(G4int number) const ; 00160 00161 // Methods 00162 00163 G4double ChebyshevEvaluation(G4double x) const ; 00164 void DerivativeChebyshevCof(G4double derCof[]) const ; 00165 void IntegralChebyshevCof(G4double integralCof[]) const ; 00166 00167 private: 00168 00169 G4ChebyshevApproximation(const G4ChebyshevApproximation&); 00170 G4ChebyshevApproximation& operator=(const G4ChebyshevApproximation&); 00171 00172 private: 00173 00174 function fFunction ; 00175 G4int fNumber ; 00176 G4double* fChebyshevCof ; 00177 G4double fMean ; 00178 G4double fDiff ; 00179 }; 00180 00181 #endif