Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 // G4Integrator inline methods implementation << 27 // 23 // 28 // Author: V.Grichine, 04.09.1999 - First impl << 24 // $Id: G4Integrator.icc,v 1.7 2001/07/11 10:00:40 gunter Exp $ 29 // G4SimpleIntegration class with H.P. << 25 // GEANT4 tag $Name: geant4-04-00 $ 30 // E.TCherniaev advises << 26 // 31 // ------------------------------------------- << 27 // Implementation of G4Integrator methods. >> 28 // >> 29 // 32 30 33 ////////////////////////////////////////////// 31 ///////////////////////////////////////////////////////////////////// 34 // 32 // 35 // Sympson integration method 33 // Sympson integration method 36 // 34 // 37 ////////////////////////////////////////////// 35 ///////////////////////////////////////////////////////////////////// 38 // 36 // 39 // Integration of class member functions T::f << 37 // Integration of class member functions T::f by Simpson method. 40 << 41 template <class T, class F> << 42 G4double G4Integrator<T, F>::Simpson(T& typeT, << 43 G4double << 44 { << 45 G4int i; << 46 G4double step = (xFinal - xInitial) / itera << 47 G4double x = xInitial; << 48 G4double xPlus = xInitial + 0.5 * step; << 49 G4double mean = ((typeT.*f)(xInitial) + (ty << 50 G4double sum = (typeT.*f)(xPlus); << 51 38 52 for(i = 1; i < iterationNumber; ++i) << 39 template <class T, class F> 53 { << 40 G4double G4Integrator<T,F>::Simpson( T& typeT, 54 x += step; << 41 F f, 55 xPlus += step; << 42 G4double xInitial, 56 mean += (typeT.*f)(x); << 43 G4double xFinal, 57 sum += (typeT.*f)(xPlus); << 44 G4int iterationNumber ) 58 } << 45 { 59 mean += 2.0 * sum; << 46 G4int i ; >> 47 G4double step = (xFinal - xInitial)/iterationNumber ; >> 48 G4double x = xInitial ; >> 49 G4double xPlus = xInitial + 0.5*step ; >> 50 G4double mean = ( (typeT.*f)(xInitial) + (typeT.*f)(xFinal) )*0.5 ; >> 51 G4double sum = (typeT.*f)(xPlus) ; >> 52 >> 53 for(i=1;i<iterationNumber;i++) >> 54 { >> 55 x += step ; >> 56 xPlus += step ; >> 57 mean += (typeT.*f)(x) ; >> 58 sum += (typeT.*f)(xPlus) ; >> 59 } >> 60 mean += 2.0*sum ; 60 61 61 return mean * step / 3.0; << 62 return mean*step/3.0 ; 62 } 63 } 63 64 64 ////////////////////////////////////////////// 65 ///////////////////////////////////////////////////////////////////// 65 // 66 // 66 // Integration of class member functions T::f 67 // Integration of class member functions T::f by Simpson method. 67 // Convenient to use with 'this' pointer 68 // Convenient to use with 'this' pointer 68 69 69 template <class T, class F> << 70 template <class T, class F> 70 G4double G4Integrator<T, F>::Simpson(T* ptrT, << 71 G4double G4Integrator<T,F>::Simpson( T* ptrT, 71 G4double << 72 F f, 72 { << 73 G4double xInitial, 73 G4int i; << 74 G4double xFinal, 74 G4double step = (xFinal - xInitial) / itera << 75 G4int iterationNumber ) 75 G4double x = xInitial; << 76 { 76 G4double xPlus = xInitial + 0.5 * step; << 77 G4int i ; 77 G4double mean = ((ptrT->*f)(xInitial) + (pt << 78 G4double step = (xFinal - xInitial)/iterationNumber ; 78 G4double sum = (ptrT->*f)(xPlus); << 79 G4double x = xInitial ; >> 80 G4double xPlus = xInitial + 0.5*step ; >> 81 G4double mean = ( (ptrT->*f)(xInitial) + (ptrT->*f)(xFinal) )*0.5 ; >> 82 G4double sum = (ptrT->*f)(xPlus) ; >> 83 >> 84 for(i=1;i<iterationNumber;i++) >> 85 { >> 86 x += step ; >> 87 xPlus += step ; >> 88 mean += (ptrT->*f)(x) ; >> 89 sum += (ptrT->*f)(xPlus) ; >> 90 } >> 91 mean += 2.0*sum ; 79 92 80 for(i = 1; i < iterationNumber; ++i) << 93 return mean*step/3.0 ; 81 { << 82 x += step; << 83 xPlus += step; << 84 mean += (ptrT->*f)(x); << 85 sum += (ptrT->*f)(xPlus); << 86 } << 87 mean += 2.0 * sum; << 88 << 89 return mean * step / 3.0; << 90 } 94 } 91 95 92 ////////////////////////////////////////////// 96 ///////////////////////////////////////////////////////////////////// 93 // 97 // 94 // Integration of class member functions T::f 98 // Integration of class member functions T::f by Simpson method. 95 // Convenient to use, when function f is defin 99 // Convenient to use, when function f is defined in global scope, i.e. in main() 96 // program 100 // program 97 101 98 template <class T, class F> << 102 template <class T, class F> 99 G4double G4Integrator<T, F>::Simpson(G4double << 103 G4double G4Integrator<T,F>::Simpson( G4double (*f)(G4double), 100 G4double << 104 G4double xInitial, 101 { << 105 G4double xFinal, 102 G4int i; << 106 G4int iterationNumber ) 103 G4double step = (xFinal - xInitial) / itera << 107 { 104 G4double x = xInitial; << 108 G4int i ; 105 G4double xPlus = xInitial + 0.5 * step; << 109 G4double step = (xFinal - xInitial)/iterationNumber ; 106 G4double mean = ((*f)(xInitial) + (*f)(xFin << 110 G4double x = xInitial ; 107 G4double sum = (*f)(xPlus); << 111 G4double xPlus = xInitial + 0.5*step ; 108 << 112 G4double mean = ( (*f)(xInitial) + (*f)(xFinal) )*0.5 ; 109 for(i = 1; i < iterationNumber; ++i) << 113 G4double sum = (*f)(xPlus) ; 110 { << 114 111 x += step; << 115 for(i=1;i<iterationNumber;i++) 112 xPlus += step; << 116 { 113 mean += (*f)(x); << 117 x += step ; 114 sum += (*f)(xPlus); << 118 xPlus += step ; 115 } << 119 mean += (*f)(x) ; 116 mean += 2.0 * sum; << 120 sum += (*f)(xPlus) ; >> 121 } >> 122 mean += 2.0*sum ; 117 123 118 return mean * step / 3.0; << 124 return mean*step/3.0 ; 119 } 125 } 120 126 121 ////////////////////////////////////////////// 127 ////////////////////////////////////////////////////////////////////////// 122 // 128 // 123 // Adaptive Gauss method 129 // Adaptive Gauss method 124 // 130 // 125 ////////////////////////////////////////////// 131 ////////////////////////////////////////////////////////////////////////// 126 // 132 // 127 // 133 // 128 134 129 template <class T, class F> << 135 template <class T, class F> 130 G4double G4Integrator<T, F>::Gauss(T& typeT, F << 136 G4double G4Integrator<T,F>::Gauss( T& typeT, F f, 131 G4double xF << 137 G4double xInitial, G4double xFinal ) 132 { << 138 { 133 static const G4double root = 1.0 / std::sqrt << 139 static G4double root = 1.0/sqrt(3.0) ; 134 << 140 135 G4double xMean = (xInitial + xFinal) / 2.0; << 141 G4double xMean = (xInitial + xFinal)/2.0 ; 136 G4double Step = (xFinal - xInitial) / 2.0; << 142 G4double Step = (xFinal - xInitial)/2.0 ; 137 G4double delta = Step * root; << 143 G4double delta = Step*root ; 138 G4double sum = ((typeT.*f)(xMean + delta) << 144 G4double sum = ((typeT.*f)(xMean + delta) + 139 << 145 (typeT.*f)(xMean - delta)) ; 140 return sum * Step; << 146 >> 147 return sum*Step ; 141 } 148 } 142 149 143 ////////////////////////////////////////////// 150 ////////////////////////////////////////////////////////////////////// 144 // 151 // 145 // 152 // 146 153 147 template <class T, class F> << 154 template <class T, class F> G4double 148 G4double G4Integrator<T, F>::Gauss(T* ptrT, F << 155 G4Integrator<T,F>::Gauss( T* ptrT, F f, G4double a, G4double b ) 149 { 156 { 150 return Gauss(*ptrT, f, a, b); << 157 return Gauss(*ptrT,f,a,b) ; 151 } 158 } 152 159 153 ////////////////////////////////////////////// 160 /////////////////////////////////////////////////////////////////////// 154 // 161 // 155 // 162 // 156 163 157 template <class T, class F> 164 template <class T, class F> 158 G4double G4Integrator<T, F>::Gauss(G4double (* << 165 G4double G4Integrator<T,F>::Gauss( G4double (*f)(G4double), 159 G4double xF << 166 G4double xInitial, G4double xFinal) 160 { 167 { 161 static const G4double root = 1.0 / std::sqrt << 168 static G4double root = 1.0/sqrt(3.0) ; 162 << 169 163 G4double xMean = (xInitial + xFinal) / 2.0; << 170 G4double xMean = (xInitial + xFinal)/2.0 ; 164 G4double Step = (xFinal - xInitial) / 2.0; << 171 G4double Step = (xFinal - xInitial)/2.0 ; 165 G4double delta = Step * root; << 172 G4double delta = Step*root ; 166 G4double sum = ((*f)(xMean + delta) + (*f) << 173 G4double sum = ( (*f)(xMean + delta) + (*f)(xMean - delta) ) ; 167 << 174 168 return sum * Step; << 175 return sum*Step ; 169 } 176 } 170 177 171 ////////////////////////////////////////////// 178 /////////////////////////////////////////////////////////////////////////// 172 // 179 // 173 // 180 // 174 181 175 template <class T, class F> << 182 template <class T, class F> 176 void G4Integrator<T, F>::AdaptGauss(T& typeT, << 183 void G4Integrator<T,F>::AdaptGauss( T& typeT, F f, G4double xInitial, 177 G4double x << 184 G4double xFinal, G4double fTolerance, 178 G4double& << 185 G4double& sum, >> 186 G4int& depth ) >> 187 { >> 188 if(depth > 100) >> 189 { >> 190 G4cout<<"G4Integrator<T,F>::AdaptGauss: WARNING !!!"<<G4endl ; >> 191 G4cout >> 192 <<"Function varies too rapidly to get stated accuracy in 100 steps "<<G4endl ; >> 193 >> 194 return ; >> 195 } >> 196 G4double xMean = (xInitial + xFinal)/2.0 ; >> 197 G4double leftHalf = Gauss(typeT,f,xInitial,xMean) ; >> 198 G4double rightHalf = Gauss(typeT,f,xMean,xFinal) ; >> 199 G4double full = Gauss(typeT,f,xInitial,xFinal) ; >> 200 if(fabs(leftHalf+rightHalf-full) < fTolerance) >> 201 { >> 202 sum += full ; >> 203 } >> 204 else >> 205 { >> 206 depth++ ; >> 207 AdaptGauss(typeT,f,xInitial,xMean,fTolerance,sum,depth) ; >> 208 AdaptGauss(typeT,f,xMean,xFinal,fTolerance,sum,depth) ; >> 209 } >> 210 } >> 211 >> 212 template <class T, class F> >> 213 void G4Integrator<T,F>::AdaptGauss( T* ptrT, F f, G4double xInitial, >> 214 G4double xFinal, G4double fTolerance, >> 215 G4double& sum, >> 216 G4int& depth ) 179 { 217 { 180 if(depth > 100) << 218 AdaptGauss(*ptrT,f,xInitial,xFinal,fTolerance,sum,depth) ; 181 { << 182 G4cout << "G4Integrator<T,F>::AdaptGauss: << 183 G4cout << "Function varies too rapidly to << 184 << G4endl; << 185 << 186 return; << 187 } << 188 G4double xMean = (xInitial + xFinal) / 2 << 189 G4double leftHalf = Gauss(typeT, f, xInitia << 190 G4double rightHalf = Gauss(typeT, f, xMean, << 191 G4double full = Gauss(typeT, f, xInitia << 192 if(std::fabs(leftHalf + rightHalf - full) < << 193 { << 194 sum += full; << 195 } << 196 else << 197 { << 198 ++depth; << 199 AdaptGauss(typeT, f, xInitial, xMean, fTol << 200 AdaptGauss(typeT, f, xMean, xFinal, fToler << 201 } << 202 } << 203 << 204 template <class T, class F> << 205 void G4Integrator<T, F>::AdaptGauss(T* ptrT, F << 206 G4double x << 207 G4double& << 208 { << 209 AdaptGauss(*ptrT, f, xInitial, xFinal, fTole << 210 } 219 } 211 220 212 ////////////////////////////////////////////// 221 ///////////////////////////////////////////////////////////////////////// 213 // 222 // 214 // 223 // 215 template <class T, class F> 224 template <class T, class F> 216 void G4Integrator<T, F>::AdaptGauss(G4double ( << 225 void G4Integrator<T,F>::AdaptGauss( G4double (*f)(G4double), 217 G4double x << 226 G4double xInitial, G4double xFinal, 218 G4double& << 227 G4double fTolerance, G4double& sum, 219 { << 228 G4int& depth ) 220 if(depth > 100) << 229 { 221 { << 230 if(depth > 100) 222 G4cout << "G4SimpleIntegration::AdaptGauss << 231 { 223 G4cout << "Function varies too rapidly to << 232 G4cout<<"G4SimpleIntegration::AdaptGauss: WARNING !!!"<<G4endl ; 224 << G4endl; << 233 G4cout<<"Function varies too rapidly to get stated accuracy in 100 steps " 225 << 234 <<G4endl ; 226 return; << 235 227 } << 236 return ; 228 G4double xMean = (xInitial + xFinal) / 2 << 237 } 229 G4double leftHalf = Gauss(f, xInitial, xMea << 238 G4double xMean = (xInitial + xFinal)/2.0 ; 230 G4double rightHalf = Gauss(f, xMean, xFinal) << 239 G4double leftHalf = Gauss(f,xInitial,xMean) ; 231 G4double full = Gauss(f, xInitial, xFin << 240 G4double rightHalf = Gauss(f,xMean,xFinal) ; 232 if(std::fabs(leftHalf + rightHalf - full) < << 241 G4double full = Gauss(f,xInitial,xFinal) ; 233 { << 242 if(fabs(leftHalf+rightHalf-full) < fTolerance) 234 sum += full; << 243 { 235 } << 244 sum += full ; 236 else << 245 } 237 { << 246 else 238 ++depth; << 247 { 239 AdaptGauss(f, xInitial, xMean, fTolerance, << 248 depth++ ; 240 AdaptGauss(f, xMean, xFinal, fTolerance, s << 249 AdaptGauss(f,xInitial,xMean,fTolerance,sum,depth) ; 241 } << 250 AdaptGauss(f,xMean,xFinal,fTolerance,sum,depth) ; >> 251 } 242 } 252 } 243 253 >> 254 >> 255 >> 256 244 ////////////////////////////////////////////// 257 //////////////////////////////////////////////////////////////////////// 245 // 258 // 246 // Adaptive Gauss integration with accuracy 'e 259 // Adaptive Gauss integration with accuracy 'e' 247 // Convenient for using with class object type 260 // Convenient for using with class object typeT 248 << 261 249 template <class T, class F> << 262 template<class T, class F> G4double 250 G4double G4Integrator<T, F>::AdaptiveGauss(T& << 263 G4Integrator<T,F>::AdaptiveGauss( T& typeT, F f, G4double xInitial, 251 G4d << 264 G4double xFinal, G4double e ) 252 { << 265 { 253 G4int depth = 0; << 266 G4int depth = 0 ; 254 G4double sum = 0.0; << 267 G4double sum = 0.0 ; 255 AdaptGauss(typeT, f, xInitial, xFinal, e, su << 268 AdaptGauss(typeT,f,xInitial,xFinal,e,sum,depth) ; 256 return sum; << 269 return sum ; 257 } 270 } 258 271 259 ////////////////////////////////////////////// 272 //////////////////////////////////////////////////////////////////////// 260 // 273 // 261 // Adaptive Gauss integration with accuracy 'e 274 // Adaptive Gauss integration with accuracy 'e' 262 // Convenient for using with 'this' pointer 275 // Convenient for using with 'this' pointer 263 << 276 264 template <class T, class F> << 277 template<class T, class F> G4double 265 G4double G4Integrator<T, F>::AdaptiveGauss(T* << 278 G4Integrator<T,F>::AdaptiveGauss( T* ptrT, F f, G4double xInitial, 266 G4d << 279 G4double xFinal, G4double e ) 267 { 280 { 268 return AdaptiveGauss(*ptrT, f, xInitial, xFi << 281 return AdaptiveGauss(*ptrT,f,xInitial,xFinal,e) ; 269 } 282 } 270 283 271 ////////////////////////////////////////////// 284 //////////////////////////////////////////////////////////////////////// 272 // 285 // 273 // Adaptive Gauss integration with accuracy 'e 286 // Adaptive Gauss integration with accuracy 'e' 274 // Convenient for using with global scope func 287 // Convenient for using with global scope function f 275 << 288 276 template <class T, class F> << 289 template <class T, class F> G4double 277 G4double G4Integrator<T, F>::AdaptiveGauss(G4d << 290 G4Integrator<T,F>::AdaptiveGauss( G4double (*f)(G4double), 278 G4d << 291 G4double xInitial, G4double xFinal, G4double e ) 279 G4d << 292 { 280 { << 293 G4int depth = 0 ; 281 G4int depth = 0; << 294 G4double sum = 0.0 ; 282 G4double sum = 0.0; << 295 AdaptGauss(f,xInitial,xFinal,e,sum,depth) ; 283 AdaptGauss(f, xInitial, xFinal, e, sum, dept << 296 return sum ; 284 return sum; << 285 } 297 } 286 298 287 ////////////////////////////////////////////// 299 //////////////////////////////////////////////////////////////////////////// 288 // Gauss integration methods involving ortogon 300 // Gauss integration methods involving ortogonal polynomials 289 ////////////////////////////////////////////// 301 //////////////////////////////////////////////////////////////////////////// 290 // 302 // 291 // Methods involving Legendre polynomials << 303 // Methods involving Legendre polynomials 292 // 304 // 293 ////////////////////////////////////////////// 305 ///////////////////////////////////////////////////////////////////////// 294 // 306 // 295 // The value nLegendre set the accuracy requir 307 // The value nLegendre set the accuracy required, i.e the number of points 296 // where the function pFunction will be evalua 308 // where the function pFunction will be evaluated during integration. 297 // The function creates the arrays for absciss << 309 // The function creates the arrays for abscissas and weights that used 298 // in Gauss-Legendre quadrature method. << 310 // in Gauss-Legendre quadrature method. 299 // The values a and b are the limits of integr 311 // The values a and b are the limits of integration of the function f . 300 // nLegendre MUST BE EVEN !!! 312 // nLegendre MUST BE EVEN !!! 301 // Returns the integral of the function f betw << 313 // Returns the integral of the function f between a and b, by 2*fNumber point 302 // Gauss-Legendre integration: the function is 314 // Gauss-Legendre integration: the function is evaluated exactly 303 // 2*fNumber times at interior points in the r << 315 // 2*fNumber times at interior points in the range of integration. 304 // Since the weights and abscissas are, in thi << 316 // Since the weights and abscissas are, in this case, symmetric around 305 // the midpoint of the range of integration, t << 317 // the midpoint of the range of integration, there are actually only 306 // fNumber distinct values of each. 318 // fNumber distinct values of each. 307 // Convenient for using with some class object 319 // Convenient for using with some class object dataT 308 320 309 template <class T, class F> << 321 template <class T, class F> G4double 310 G4double G4Integrator<T, F>::Legendre(T& typeT << 322 G4Integrator<T,F>::Legendre( T& typeT, F f, G4double a, G4double b, G4int nLegendre) 311 G4int nL << 312 { 323 { 313 G4double nwt, nwt1, temp1, temp2, temp3, tem << 324 G4double newton, newton1, temp1, temp2, temp3, temp ; 314 G4double xDiff, xMean, dx, integral; << 325 G4double xDiff, xMean, dx, integral ; 315 << 316 const G4double tolerance = 1.6e-10; << 317 G4int i, j, k = nLegendre; << 318 G4int fNumber = (nLegendre + 1) / 2; << 319 << 320 if(2 * fNumber != k) << 321 { << 322 G4Exception("G4Integrator<T,F>::Legendre(T << 323 FatalException, "Invalid (odd) << 324 } << 325 << 326 G4double* fAbscissa = new G4double[fNumber]; << 327 G4double* fWeight = new G4double[fNumber]; << 328 << 329 for(i = 1; i <= fNumber; ++i) // Loop over << 330 { << 331 nwt = std::cos(CLHEP::pi * (i - 0.25) / << 332 (k + 0.5)); // Initial roo << 333 326 334 do // loop of Newton's method << 327 const G4double tolerance = 1.6e-10 ; 335 { << 328 G4int i, j, k = nLegendre ; 336 temp1 = 1.0; << 329 G4int fNumber = (nLegendre + 1)/2 ; 337 temp2 = 0.0; << 330 338 for(j = 1; j <= k; ++j) << 331 if(2*fNumber != k) 339 { << 332 { 340 temp3 = temp2; << 333 G4Exception("Invalid (odd) n Legendre in G4Integrator<T,F>::Legendre") ; 341 temp2 = temp1; << 334 } 342 temp1 = ((2.0 * j - 1.0) * nwt * temp2 << 335 343 } << 336 G4double* fAbscissa = new G4double[fNumber] ; 344 temp = k * (nwt * temp1 - temp2) / (nwt << 337 G4double* fWeight = new G4double[fNumber] ; 345 nwt1 = nwt; << 338 346 nwt = nwt1 - temp1 / temp; // Newton's << 339 for(i=1;i<=fNumber;i++) // Loop over the desired roots 347 } while(std::fabs(nwt - nwt1) > tolerance) << 340 { 348 << 341 newton = cos(pi*(i - 0.25)/(k + 0.5)) ; // Initial root approximation 349 fAbscissa[fNumber - i] = nwt; << 342 350 fWeight[fNumber - i] = 2.0 / ((1.0 - nwt << 343 do // loop of Newton's method 351 } << 344 { 352 << 345 temp1 = 1.0 ; 353 // << 346 temp2 = 0.0 ; 354 // Now we ready to get integral << 347 for(j=1;j<=k;j++) 355 // << 348 { 356 << 349 temp3 = temp2 ; 357 xMean = 0.5 * (a + b); << 350 temp2 = temp1 ; 358 xDiff = 0.5 * (b - a); << 351 temp1 = ((2.0*j - 1.0)*newton*temp2 - (j - 1.0)*temp3)/j ; 359 integral = 0.0; << 352 } 360 for(i = 0; i < fNumber; ++i) << 353 temp = k*(newton*temp1 - temp2)/(newton*newton - 1.0) ; 361 { << 354 newton1 = newton ; 362 dx = xDiff * fAbscissa[i]; << 355 newton = newton1 - temp1/temp ; // Newton's method 363 integral += fWeight[i] * ((typeT.*f)(xMean << 356 } 364 } << 357 while(fabs(newton - newton1) > tolerance) ; 365 delete[] fAbscissa; << 358 366 delete[] fWeight; << 359 fAbscissa[fNumber-i] = newton ; 367 return integral *= xDiff; << 360 fWeight[fNumber-i] = 2.0/((1.0 - newton*newton)*temp*temp) ; 368 } << 361 } >> 362 // >> 363 // Now we ready to get integral >> 364 // >> 365 >> 366 xMean = 0.5*(a + b) ; >> 367 xDiff = 0.5*(b - a) ; >> 368 integral = 0.0 ; >> 369 for(i=0;i<fNumber;i++) >> 370 { >> 371 dx = xDiff*fAbscissa[i] ; >> 372 integral += fWeight[i]*( (typeT.*f)(xMean + dx) + >> 373 (typeT.*f)(xMean - dx) ) ; >> 374 } >> 375 return integral *= xDiff ; >> 376 } 369 377 370 ////////////////////////////////////////////// 378 /////////////////////////////////////////////////////////////////////// 371 // 379 // 372 // Convenient for using with the pointer 'this 380 // Convenient for using with the pointer 'this' 373 381 374 template <class T, class F> << 382 template <class T, class F> G4double 375 G4double G4Integrator<T, F>::Legendre(T* ptrT, << 383 G4Integrator<T,F>::Legendre( T* ptrT, F f, G4double a, G4double b, G4int nLegendre) 376 G4int nL << 377 { 384 { 378 return Legendre(*ptrT, f, a, b, nLegendre); << 385 return Legendre(*ptrT,f,a,b,nLegendre) ; 379 } 386 } 380 387 381 ////////////////////////////////////////////// 388 /////////////////////////////////////////////////////////////////////// 382 // 389 // 383 // Convenient for using with global scope func 390 // Convenient for using with global scope function f 384 391 385 template <class T, class F> 392 template <class T, class F> 386 G4double G4Integrator<T, F>::Legendre(G4double << 393 G4double G4Integrator<T,F>:: 387 G4double << 394 Legendre( G4double (*f)(G4double), G4double a, G4double b, G4int nLegendre) 388 { 395 { 389 G4double nwt, nwt1, temp1, temp2, temp3, tem << 396 G4double newton, newton1, temp1, temp2, temp3, temp ; 390 G4double xDiff, xMean, dx, integral; << 397 G4double xDiff, xMean, dx, integral ; 391 << 392 const G4double tolerance = 1.6e-10; << 393 G4int i, j, k = nLegendre; << 394 G4int fNumber = (nLegendre + 1) / 2; << 395 << 396 if(2 * fNumber != k) << 397 { << 398 G4Exception("G4Integrator<T,F>::Legendre(. << 399 FatalException, "Invalid (odd) << 400 } << 401 << 402 G4double* fAbscissa = new G4double[fNumber]; << 403 G4double* fWeight = new G4double[fNumber]; << 404 << 405 for(i = 1; i <= fNumber; i++) // Loop over << 406 { << 407 nwt = std::cos(CLHEP::pi * (i - 0.25) / << 408 (k + 0.5)); // Initial roo << 409 398 410 do // loop of Newton's method << 399 const G4double tolerance = 1.6e-10 ; 411 { << 400 G4int i, j, k = nLegendre ; 412 temp1 = 1.0; << 401 G4int fNumber = (nLegendre + 1)/2 ; 413 temp2 = 0.0; << 402 414 for(j = 1; j <= k; ++j) << 403 if(2*fNumber != k) 415 { << 404 { 416 temp3 = temp2; << 405 G4Exception("Invalid (odd) n Legendre in G4Integrator<T,F>::Legendre") ; 417 temp2 = temp1; << 406 } 418 temp1 = ((2.0 * j - 1.0) * nwt * temp2 << 407 419 } << 408 G4double* fAbscissa = new G4double[fNumber] ; 420 temp = k * (nwt * temp1 - temp2) / (nwt << 409 G4double* fWeight = new G4double[fNumber] ; 421 nwt1 = nwt; << 410 422 nwt = nwt1 - temp1 / temp; // Newton's << 411 for(i=1;i<=fNumber;i++) // Loop over the desired roots 423 } while(std::fabs(nwt - nwt1) > tolerance) << 412 { 424 << 413 newton = cos(pi*(i - 0.25)/(k + 0.5)) ; // Initial root approximation 425 fAbscissa[fNumber - i] = nwt; << 414 426 fWeight[fNumber - i] = 2.0 / ((1.0 - nwt << 415 do // loop of Newton's method 427 } << 416 { 428 << 417 temp1 = 1.0 ; 429 // << 418 temp2 = 0.0 ; 430 // Now we ready to get integral << 419 for(j=1;j<=k;j++) 431 // << 420 { 432 << 421 temp3 = temp2 ; 433 xMean = 0.5 * (a + b); << 422 temp2 = temp1 ; 434 xDiff = 0.5 * (b - a); << 423 temp1 = ((2.0*j - 1.0)*newton*temp2 - (j - 1.0)*temp3)/j ; 435 integral = 0.0; << 424 } 436 for(i = 0; i < fNumber; ++i) << 425 temp = k*(newton*temp1 - temp2)/(newton*newton - 1.0) ; 437 { << 426 newton1 = newton ; 438 dx = xDiff * fAbscissa[i]; << 427 newton = newton1 - temp1/temp ; // Newton's method 439 integral += fWeight[i] * ((*f)(xMean + dx) << 428 } 440 } << 429 while(fabs(newton - newton1) > tolerance) ; 441 delete[] fAbscissa; << 430 442 delete[] fWeight; << 431 fAbscissa[fNumber-i] = newton ; 443 << 432 fWeight[fNumber-i] = 2.0/((1.0 - newton*newton)*temp*temp) ; 444 return integral *= xDiff; << 433 } 445 } << 434 // >> 435 // Now we ready to get integral >> 436 // >> 437 >> 438 xMean = 0.5*(a + b) ; >> 439 xDiff = 0.5*(b - a) ; >> 440 integral = 0.0 ; >> 441 for(i=0;i<fNumber;i++) >> 442 { >> 443 dx = xDiff*fAbscissa[i] ; >> 444 integral += fWeight[i]*( (*f)(xMean + dx) + (*f)(xMean - dx) ) ; >> 445 } >> 446 return integral *= xDiff ; >> 447 } 446 448 447 ////////////////////////////////////////////// 449 //////////////////////////////////////////////////////////////////////////// 448 // 450 // 449 // Returns the integral of the function to be 451 // Returns the integral of the function to be pointed by T::f between a and b, 450 // by ten point Gauss-Legendre integration: th 452 // by ten point Gauss-Legendre integration: the function is evaluated exactly 451 // ten times at interior points in the range o 453 // ten times at interior points in the range of integration. Since the weights 452 // and abscissas are, in this case, symmetric << 454 // and abscissas are, in this case, symmetric around the midpoint of the 453 // range of integration, there are actually on 455 // range of integration, there are actually only five distinct values of each 454 // Convenient for using with class object type 456 // Convenient for using with class object typeT 455 457 456 template <class T, class F> << 458 template <class T, class F> 457 G4double G4Integrator<T, F>::Legendre10(T& typ << 459 G4double G4Integrator<T,F>::Legendre10( T& typeT, F f,G4double a, G4double b) 458 { 460 { 459 G4int i; << 461 G4int i ; 460 G4double xDiff, xMean, dx, integral; << 462 G4double xDiff, xMean, dx, integral ; 461 << 463 462 // From Abramowitz M., Stegan I.A. 1964 , Ha << 464 // From Abramowitz M., Stegan I.A. 1964 , Handbook of Math... , p. 916 463 << 465 464 static const G4double abscissa[] = { 0.14887 << 466 static G4double abscissa[] = { 0.148874338981631, 0.433395394129247, 465 0.67940 << 467 0.679409568299024, 0.865063366688985, 466 0.97390 << 468 0.973906528517172 } ; 467 << 469 468 static const G4double weight[] = { 0.2955242 << 470 static G4double weight[] = { 0.295524224714753, 0.269266719309996, 469 0.2190863 << 471 0.219086362515982, 0.149451349150581, 470 0.0666713 << 472 0.066671344308688 } ; 471 xMean = 0.5 * (a + << 473 xMean = 0.5*(a + b) ; 472 xDiff = 0.5 * (b - << 474 xDiff = 0.5*(b - a) ; 473 integral = 0.0; << 475 integral = 0.0 ; 474 for(i = 0; i < 5; ++i) << 476 for(i=0;i<5;i++) 475 { << 477 { 476 dx = xDiff * abscissa[i]; << 478 dx = xDiff*abscissa[i] ; 477 integral += weight[i] * ((typeT.*f)(xMean << 479 integral += weight[i]*( (typeT.*f)(xMean + dx) + (typeT.*f)(xMean - dx)) ; 478 } << 480 } 479 return integral *= xDiff; << 481 return integral *= xDiff ; 480 } 482 } 481 483 482 ////////////////////////////////////////////// 484 /////////////////////////////////////////////////////////////////////////// 483 // 485 // 484 // Convenient for using with the pointer 'this 486 // Convenient for using with the pointer 'this' 485 487 486 template <class T, class F> << 488 template <class T, class F> 487 G4double G4Integrator<T, F>::Legendre10(T* ptr << 489 G4double G4Integrator<T,F>::Legendre10( T* ptrT, F f,G4double a, G4double b) 488 { 490 { 489 return Legendre10(*ptrT, f, a, b); << 491 return Legendre10(*ptrT,f,a,b) ; 490 } << 492 } 491 493 492 ////////////////////////////////////////////// 494 ////////////////////////////////////////////////////////////////////////// 493 // 495 // 494 // Convenient for using with global scope func 496 // Convenient for using with global scope functions 495 497 496 template <class T, class F> << 498 template <class T, class F> G4double 497 G4double G4Integrator<T, F>::Legendre10(G4doub << 499 G4Integrator<T,F>::Legendre10( G4double (*f)(G4double), G4double a, G4double b) 498 G4doub << 499 { 500 { 500 G4int i; << 501 G4int i ; 501 G4double xDiff, xMean, dx, integral; << 502 G4double xDiff, xMean, dx, integral ; 502 << 503 503 // From Abramowitz M., Stegan I.A. 1964 , Ha << 504 // From Abramowitz M., Stegan I.A. 1964 , Handbook of Math... , p. 916 504 << 505 505 static const G4double abscissa[] = { 0.14887 << 506 static G4double abscissa[] = { 0.148874338981631, 0.433395394129247, 506 0.67940 << 507 0.679409568299024, 0.865063366688985, 507 0.97390 << 508 0.973906528517172 } ; 508 << 509 509 static const G4double weight[] = { 0.2955242 << 510 static G4double weight[] = { 0.295524224714753, 0.269266719309996, 510 0.2190863 << 511 0.219086362515982, 0.149451349150581, 511 0.0666713 << 512 0.066671344308688 } ; 512 xMean = 0.5 * (a + << 513 xMean = 0.5*(a + b) ; 513 xDiff = 0.5 * (b - << 514 xDiff = 0.5*(b - a) ; 514 integral = 0.0; << 515 integral = 0.0 ; 515 for(i = 0; i < 5; ++i) << 516 for(i=0;i<5;i++) 516 { << 517 { 517 dx = xDiff * abscissa[i]; << 518 dx = xDiff*abscissa[i] ; 518 integral += weight[i] * ((*f)(xMean + dx) << 519 integral += weight[i]*( (*f)(xMean + dx) + (*f)(xMean - dx)) ; 519 } << 520 } 520 return integral *= xDiff; << 521 return integral *= xDiff ; 521 } 522 } 522 523 523 ////////////////////////////////////////////// 524 /////////////////////////////////////////////////////////////////////// 524 // 525 // 525 // Returns the integral of the function to be 526 // Returns the integral of the function to be pointed by T::f between a and b, 526 // by 96 point Gauss-Legendre integration: the 527 // by 96 point Gauss-Legendre integration: the function is evaluated exactly 527 // ten Times at interior points in the range o 528 // ten Times at interior points in the range of integration. Since the weights 528 // and abscissas are, in this case, symmetric << 529 // and abscissas are, in this case, symmetric around the midpoint of the 529 // range of integration, there are actually on 530 // range of integration, there are actually only five distinct values of each 530 // Convenient for using with some class object 531 // Convenient for using with some class object typeT 531 532 532 template <class T, class F> << 533 template <class T, class F> 533 G4double G4Integrator<T, F>::Legendre96(T& typ << 534 G4double G4Integrator<T,F>::Legendre96( T& typeT, F f,G4double a, G4double b) 534 { 535 { 535 G4int i; << 536 G4int i ; 536 G4double xDiff, xMean, dx, integral; << 537 G4double xDiff, xMean, dx, integral ; 537 << 538 538 // From Abramowitz M., Stegan I.A. 1964 , Ha << 539 // From Abramowitz M., Stegan I.A. 1964 , Handbook of Math... , p. 919 539 << 540 540 static const G4double abscissa[] = { << 541 static G4double 541 0.016276744849602969579, 0.048812985136049 << 542 abscissa[] = { 542 0.081297495464425558994, 0.113695850110665 << 543 0.016276744849602969579, 0.048812985136049731112, 543 0.145973714654896941989, 0.178096882367618 << 544 0.081297495464425558994, 0.113695850110665920911, 544 << 545 0.145973714654896941989, 0.178096882367618602759, // 6 545 0.210031310460567203603, 0.241743156163840 << 546 546 0.273198812591049141487, 0.304364944354496 << 547 0.210031310460567203603, 0.241743156163840012328, 547 0.335208522892625422616, 0.365696861472313 << 548 0.273198812591049141487, 0.304364944354496353024, 548 << 549 0.335208522892625422616, 0.365696861472313635031, // 12 549 0.395797649828908603285, 0.425478988407300 << 550 550 0.454709422167743008636, 0.483457973920596 << 551 0.395797649828908603285, 0.425478988407300545365, 551 0.511694177154667673586, 0.539388108324357 << 552 0.454709422167743008636, 0.483457973920596359768, 552 << 553 0.511694177154667673586, 0.539388108324357436227, // 18 553 0.566510418561397168404, 0.593032364777572 << 554 554 0.618925840125468570386, 0.644163403784967 << 555 0.566510418561397168404, 0.593032364777572080684, 555 0.668718310043916153953, 0.692564536642171 << 556 0.618925840125468570386, 0.644163403784967106798, 556 << 557 0.668718310043916153953, 0.692564536642171561344, // 24 557 0.715676812348967626225, 0.738030643744400 << 558 558 0.759602341176647498703, 0.780369043867433 << 559 0.715676812348967626225, 0.738030643744400132851, 559 0.800308744139140817229, 0.819400310737931 << 560 0.759602341176647498703, 0.780369043867433217604, 560 << 561 0.800308744139140817229, 0.819400310737931675539, // 30 561 0.837623511228187121494, 0.854959033434601 << 562 562 0.871388505909296502874, 0.886894517402420 << 563 0.837623511228187121494, 0.854959033434601455463, 563 0.901460635315852341319, 0.915071423120898 << 564 0.871388505909296502874, 0.886894517402420416057, 564 << 565 0.901460635315852341319, 0.915071423120898074206, // 36 565 0.927712456722308690965, 0.939370339752755 << 566 566 0.950032717784437635756, 0.959688291448742 << 567 0.927712456722308690965, 0.939370339752755216932, 567 0.968326828463264212174, 0.975939174585136 << 568 0.950032717784437635756, 0.959688291448742539300, 568 << 569 0.968326828463264212174, 0.975939174585136466453, // 42 569 0.982517263563014677447, 0.988054126329623 << 570 570 0.992543900323762624572, 0.995981842987209 << 571 0.982517263563014677447, 0.988054126329623799481, 571 0.998364375863181677724, 0.999689503883230 << 572 0.992543900323762624572, 0.995981842987209290650, 572 }; << 573 0.998364375863181677724, 0.999689503883230766828 // 48 573 << 574 } ; 574 static const G4double weight[] = { << 575 575 0.032550614492363166242, 0.032516118713868 << 576 static G4double 576 0.032447163714064269364, 0.032343822568575 << 577 weight[] = { 577 0.032206204794030250669, 0.032034456231992 << 578 0.032550614492363166242, 0.032516118713868835987, 578 << 579 0.032447163714064269364, 0.032343822568575928429, 579 0.031828758894411006535, 0.031589330770727 << 580 0.032206204794030250669, 0.032034456231992663218, // 6 580 0.031316425596862355813, 0.031010332586313 << 581 581 0.030671376123669149014, 0.030299915420827 << 582 0.031828758894411006535, 0.031589330770727168558, 582 << 583 0.031316425596862355813, 0.031010332586313837423, 583 0.029896344136328385984, 0.029461089958167 << 584 0.030671376123669149014, 0.030299915420827593794, // 12 584 0.028994614150555236543, 0.028497411065085 << 585 585 0.027970007616848334440, 0.027412962726029 << 586 0.029896344136328385984, 0.029461089958167905970, 586 << 587 0.028994614150555236543, 0.028497411065085385646, 587 0.026826866725591762198, 0.026212340735672 << 588 0.027970007616848334440, 0.027412962726029242823, // 18 588 0.025570036005349361499, 0.024900633222483 << 589 589 0.024204841792364691282, 0.023483399085926 << 590 0.026826866725591762198, 0.026212340735672413913, 590 << 591 0.025570036005349361499, 0.024900633222483610288, 591 0.022737069658329374001, 0.021966644438744 << 592 0.024204841792364691282, 0.023483399085926219842, // 24 592 0.021172939892191298988, 0.020356797154333 << 593 593 0.019519081140145022410, 0.018660679627411 << 594 0.022737069658329374001, 0.021966644438744349195, 594 << 595 0.021172939892191298988, 0.020356797154333324595, 595 0.017782502316045260838, 0.016885479864245 << 596 0.019519081140145022410, 0.018660679627411467385, // 30 596 0.015970562902562291381, 0.015038721026994 << 597 597 0.014090941772314860916, 0.013128229566961 << 598 0.017782502316045260838, 0.016885479864245172450, 598 << 599 0.015970562902562291381, 0.015038721026994938006, 599 0.012151604671088319635, 0.011162102099838 << 600 0.014090941772314860916, 0.013128229566961572637, // 36 600 0.010160770535008415758, 0.009148671230783 << 601 601 0.008126876925698759217, 0.007096470791153 << 602 0.012151604671088319635, 0.011162102099838498591, 602 << 603 0.010160770535008415758, 0.009148671230783386633, 603 0.006058545504235961683, 0.005014202742927 << 604 0.008126876925698759217, 0.007096470791153865269, // 42 604 0.003964554338444686674, 0.002910731817934 << 605 605 0.001853960788946921732, 0.000796792065552 << 606 0.006058545504235961683, 0.005014202742927517693, 606 }; << 607 0.003964554338444686674, 0.002910731817934946408, 607 xMean = 0.5 * (a + b); << 608 0.001853960788946921732, 0.000796792065552012429 // 48 608 xDiff = 0.5 * (b - a); << 609 } ; 609 integral = 0.0; << 610 xMean = 0.5*(a + b) ; 610 for(i = 0; i < 48; ++i) << 611 xDiff = 0.5*(b - a) ; 611 { << 612 integral = 0.0 ; 612 dx = xDiff * abscissa[i]; << 613 for(i=0;i<48;i++) 613 integral += weight[i] * ((typeT.*f)(xMean << 614 { 614 } << 615 dx = xDiff*abscissa[i] ; 615 return integral *= xDiff; << 616 integral += weight[i]*((typeT.*f)(xMean + dx) + (typeT.*f)(xMean - dx)) ; >> 617 } >> 618 return integral *= xDiff ; 616 } 619 } 617 620 618 ////////////////////////////////////////////// 621 /////////////////////////////////////////////////////////////////////// 619 // 622 // 620 // Convenient for using with the pointer 'this 623 // Convenient for using with the pointer 'this' 621 624 622 template <class T, class F> << 625 template <class T, class F> 623 G4double G4Integrator<T, F>::Legendre96(T* ptr << 626 G4double G4Integrator<T,F>::Legendre96( T* ptrT, F f,G4double a, G4double b) 624 { 627 { 625 return Legendre96(*ptrT, f, a, b); << 628 return Legendre96(*ptrT,f,a,b) ; 626 } << 629 } 627 630 628 ////////////////////////////////////////////// 631 /////////////////////////////////////////////////////////////////////// 629 // 632 // 630 // Convenient for using with global scope func << 633 // Convenient for using with global scope function f 631 634 632 template <class T, class F> << 635 template <class T, class F> G4double 633 G4double G4Integrator<T, F>::Legendre96(G4doub << 636 G4Integrator<T,F>::Legendre96( G4double (*f)(G4double), G4double a, G4double b) 634 G4doub << 635 { 637 { 636 G4int i; << 638 G4int i ; 637 G4double xDiff, xMean, dx, integral; << 639 G4double xDiff, xMean, dx, integral ; 638 << 640 639 // From Abramowitz M., Stegan I.A. 1964 , Ha << 641 // From Abramowitz M., Stegan I.A. 1964 , Handbook of Math... , p. 919 640 << 642 641 static const G4double abscissa[] = { << 643 static G4double 642 0.016276744849602969579, 0.048812985136049 << 644 abscissa[] = { 643 0.081297495464425558994, 0.113695850110665 << 645 0.016276744849602969579, 0.048812985136049731112, 644 0.145973714654896941989, 0.178096882367618 << 646 0.081297495464425558994, 0.113695850110665920911, 645 << 647 0.145973714654896941989, 0.178096882367618602759, // 6 646 0.210031310460567203603, 0.241743156163840 << 648 647 0.273198812591049141487, 0.304364944354496 << 649 0.210031310460567203603, 0.241743156163840012328, 648 0.335208522892625422616, 0.365696861472313 << 650 0.273198812591049141487, 0.304364944354496353024, 649 << 651 0.335208522892625422616, 0.365696861472313635031, // 12 650 0.395797649828908603285, 0.425478988407300 << 652 651 0.454709422167743008636, 0.483457973920596 << 653 0.395797649828908603285, 0.425478988407300545365, 652 0.511694177154667673586, 0.539388108324357 << 654 0.454709422167743008636, 0.483457973920596359768, 653 << 655 0.511694177154667673586, 0.539388108324357436227, // 18 654 0.566510418561397168404, 0.593032364777572 << 656 655 0.618925840125468570386, 0.644163403784967 << 657 0.566510418561397168404, 0.593032364777572080684, 656 0.668718310043916153953, 0.692564536642171 << 658 0.618925840125468570386, 0.644163403784967106798, 657 << 659 0.668718310043916153953, 0.692564536642171561344, // 24 658 0.715676812348967626225, 0.738030643744400 << 660 659 0.759602341176647498703, 0.780369043867433 << 661 0.715676812348967626225, 0.738030643744400132851, 660 0.800308744139140817229, 0.819400310737931 << 662 0.759602341176647498703, 0.780369043867433217604, 661 << 663 0.800308744139140817229, 0.819400310737931675539, // 30 662 0.837623511228187121494, 0.854959033434601 << 664 663 0.871388505909296502874, 0.886894517402420 << 665 0.837623511228187121494, 0.854959033434601455463, 664 0.901460635315852341319, 0.915071423120898 << 666 0.871388505909296502874, 0.886894517402420416057, 665 << 667 0.901460635315852341319, 0.915071423120898074206, // 36 666 0.927712456722308690965, 0.939370339752755 << 668 667 0.950032717784437635756, 0.959688291448742 << 669 0.927712456722308690965, 0.939370339752755216932, 668 0.968326828463264212174, 0.975939174585136 << 670 0.950032717784437635756, 0.959688291448742539300, 669 << 671 0.968326828463264212174, 0.975939174585136466453, // 42 670 0.982517263563014677447, 0.988054126329623 << 672 671 0.992543900323762624572, 0.995981842987209 << 673 0.982517263563014677447, 0.988054126329623799481, 672 0.998364375863181677724, 0.999689503883230 << 674 0.992543900323762624572, 0.995981842987209290650, 673 }; << 675 0.998364375863181677724, 0.999689503883230766828 // 48 674 << 676 } ; 675 static const G4double weight[] = { << 677 676 0.032550614492363166242, 0.032516118713868 << 678 static G4double 677 0.032447163714064269364, 0.032343822568575 << 679 weight[] = { 678 0.032206204794030250669, 0.032034456231992 << 680 0.032550614492363166242, 0.032516118713868835987, 679 << 681 0.032447163714064269364, 0.032343822568575928429, 680 0.031828758894411006535, 0.031589330770727 << 682 0.032206204794030250669, 0.032034456231992663218, // 6 681 0.031316425596862355813, 0.031010332586313 << 683 682 0.030671376123669149014, 0.030299915420827 << 684 0.031828758894411006535, 0.031589330770727168558, 683 << 685 0.031316425596862355813, 0.031010332586313837423, 684 0.029896344136328385984, 0.029461089958167 << 686 0.030671376123669149014, 0.030299915420827593794, // 12 685 0.028994614150555236543, 0.028497411065085 << 687 686 0.027970007616848334440, 0.027412962726029 << 688 0.029896344136328385984, 0.029461089958167905970, 687 << 689 0.028994614150555236543, 0.028497411065085385646, 688 0.026826866725591762198, 0.026212340735672 << 690 0.027970007616848334440, 0.027412962726029242823, // 18 689 0.025570036005349361499, 0.024900633222483 << 691 690 0.024204841792364691282, 0.023483399085926 << 692 0.026826866725591762198, 0.026212340735672413913, 691 << 693 0.025570036005349361499, 0.024900633222483610288, 692 0.022737069658329374001, 0.021966644438744 << 694 0.024204841792364691282, 0.023483399085926219842, // 24 693 0.021172939892191298988, 0.020356797154333 << 695 694 0.019519081140145022410, 0.018660679627411 << 696 0.022737069658329374001, 0.021966644438744349195, 695 << 697 0.021172939892191298988, 0.020356797154333324595, 696 0.017782502316045260838, 0.016885479864245 << 698 0.019519081140145022410, 0.018660679627411467385, // 30 697 0.015970562902562291381, 0.015038721026994 << 699 698 0.014090941772314860916, 0.013128229566961 << 700 0.017782502316045260838, 0.016885479864245172450, 699 << 701 0.015970562902562291381, 0.015038721026994938006, 700 0.012151604671088319635, 0.011162102099838 << 702 0.014090941772314860916, 0.013128229566961572637, // 36 701 0.010160770535008415758, 0.009148671230783 << 703 702 0.008126876925698759217, 0.007096470791153 << 704 0.012151604671088319635, 0.011162102099838498591, 703 << 705 0.010160770535008415758, 0.009148671230783386633, 704 0.006058545504235961683, 0.005014202742927 << 706 0.008126876925698759217, 0.007096470791153865269, // 42 705 0.003964554338444686674, 0.002910731817934 << 707 706 0.001853960788946921732, 0.000796792065552 << 708 0.006058545504235961683, 0.005014202742927517693, 707 }; << 709 0.003964554338444686674, 0.002910731817934946408, 708 xMean = 0.5 * (a + b); << 710 0.001853960788946921732, 0.000796792065552012429 // 48 709 xDiff = 0.5 * (b - a); << 711 } ; 710 integral = 0.0; << 712 xMean = 0.5*(a + b) ; 711 for(i = 0; i < 48; ++i) << 713 xDiff = 0.5*(b - a) ; 712 { << 714 integral = 0.0 ; 713 dx = xDiff * abscissa[i]; << 715 for(i=0;i<48;i++) 714 integral += weight[i] * ((*f)(xMean + dx) << 716 { 715 } << 717 dx = xDiff*abscissa[i] ; 716 return integral *= xDiff; << 718 integral += weight[i]*((*f)(xMean + dx) + (*f)(xMean - dx)) ; >> 719 } >> 720 return integral *= xDiff ; 717 } 721 } 718 722 719 ////////////////////////////////////////////// 723 ////////////////////////////////////////////////////////////////////////////// 720 // 724 // 721 // Methods involving Chebyshev polynomials << 725 // Methods involving Chebyshev polynomials 722 // 726 // 723 ////////////////////////////////////////////// 727 /////////////////////////////////////////////////////////////////////////// 724 // 728 // 725 // Integrates function pointed by T::f from a << 729 // Integrates function pointed by T::f from a to b by Gauss-Chebyshev 726 // quadrature method. 730 // quadrature method. 727 // Convenient for using with class object type 731 // Convenient for using with class object typeT 728 732 729 template <class T, class F> << 733 template <class T, class F> G4double 730 G4double G4Integrator<T, F>::Chebyshev(T& type << 734 G4Integrator<T,F>::Chebyshev( T& typeT, F f, G4double a, 731 G4int n << 735 G4double b, G4int nChebyshev ) 732 { << 736 { 733 G4int i; << 737 G4int i ; 734 G4double xDiff, xMean, dx, integral = 0.0; << 738 G4double xDiff, xMean, dx, integral = 0.0 ; 735 << 739 736 G4int fNumber = nChebyshev; // Try to << 740 G4int fNumber = nChebyshev ; // Try to reduce fNumber twice ?? 737 G4double cof = CLHEP::pi / fNumber; << 741 G4double cof = pi/fNumber ; 738 G4double* fAbscissa = new G4double[fNumber]; << 742 G4double* fAbscissa = new G4double[fNumber] ; 739 G4double* fWeight = new G4double[fNumber]; << 743 G4double* fWeight = new G4double[fNumber] ; 740 for(i = 0; i < fNumber; ++i) << 744 for(i=0;i<fNumber;i++) 741 { << 745 { 742 fAbscissa[i] = std::cos(cof * (i + 0.5)); << 746 fAbscissa[i] = cos(cof*(i + 0.5)) ; 743 fWeight[i] = cof * std::sqrt(1 - fAbscis << 747 fWeight[i] = cof*sqrt(1 - fAbscissa[i]*fAbscissa[i]) ; 744 } << 748 } 745 << 749 // 746 // << 750 // Now we ready to estimate the integral 747 // Now we ready to estimate the integral << 751 // 748 // << 752 xMean = 0.5*(a + b) ; 749 << 753 xDiff = 0.5*(b - a) ; 750 xMean = 0.5 * (a + b); << 754 for(i=0;i<fNumber;i++) 751 xDiff = 0.5 * (b - a); << 755 { 752 for(i = 0; i < fNumber; ++i) << 756 dx = xDiff*fAbscissa[i] ; 753 { << 757 integral += fWeight[i]*(typeT.*f)(xMean + dx) ; 754 dx = xDiff * fAbscissa[i]; << 758 } 755 integral += fWeight[i] * (typeT.*f)(xMean << 759 return integral *= xDiff ; 756 } << 757 delete[] fAbscissa; << 758 delete[] fWeight; << 759 return integral *= xDiff; << 760 } 760 } 761 761 762 ////////////////////////////////////////////// 762 /////////////////////////////////////////////////////////////////////// 763 // 763 // 764 // Convenient for using with 'this' pointer 764 // Convenient for using with 'this' pointer 765 765 766 template <class T, class F> << 766 template <class T, class F> G4double 767 G4double G4Integrator<T, F>::Chebyshev(T* ptrT << 767 G4Integrator<T,F>::Chebyshev( T* ptrT, F f, G4double a, G4double b, G4int n) 768 G4int n << 769 { 768 { 770 return Chebyshev(*ptrT, f, a, b, n); << 769 return Chebyshev(*ptrT,f,a,b,n) ; 771 } << 770 } 772 771 773 ////////////////////////////////////////////// 772 //////////////////////////////////////////////////////////////////////// 774 // 773 // 775 // For use with global scope functions f << 774 // For use with global scope functions f 776 << 777 template <class T, class F> << 778 G4double G4Integrator<T, F>::Chebyshev(G4doubl << 779 G4doubl << 780 { << 781 G4int i; << 782 G4double xDiff, xMean, dx, integral = 0.0; << 783 775 784 G4int fNumber = nChebyshev; // Try to << 776 template <class T, class F> G4double 785 G4double cof = CLHEP::pi / fNumber; << 777 G4Integrator<T,F>::Chebyshev( G4double (*f)(G4double), 786 G4double* fAbscissa = new G4double[fNumber]; << 778 G4double a, G4double b, G4int nChebyshev) 787 G4double* fWeight = new G4double[fNumber]; << 779 { 788 for(i = 0; i < fNumber; ++i) << 780 G4int i ; 789 { << 781 G4double xDiff, xMean, dx, integral = 0.0 ; 790 fAbscissa[i] = std::cos(cof * (i + 0.5)); << 782 791 fWeight[i] = cof * std::sqrt(1 - fAbscis << 783 G4int fNumber = nChebyshev ; // Try to reduce fNumber twice ?? 792 } << 784 G4double cof = pi/fNumber ; 793 << 785 G4double* fAbscissa = new G4double[fNumber] ; 794 // << 786 G4double* fWeight = new G4double[fNumber] ; 795 // Now we ready to estimate the integral << 787 for(i=0;i<fNumber;i++) 796 // << 788 { 797 << 789 fAbscissa[i] = cos(cof*(i + 0.5)) ; 798 xMean = 0.5 * (a + b); << 790 fWeight[i] = cof*sqrt(1 - fAbscissa[i]*fAbscissa[i]) ; 799 xDiff = 0.5 * (b - a); << 791 } 800 for(i = 0; i < fNumber; ++i) << 792 // 801 { << 793 // Now we ready to estimate the integral 802 dx = xDiff * fAbscissa[i]; << 794 // 803 integral += fWeight[i] * (*f)(xMean + dx); << 795 xMean = 0.5*(a + b) ; 804 } << 796 xDiff = 0.5*(b - a) ; 805 delete[] fAbscissa; << 797 for(i=0;i<fNumber;i++) 806 delete[] fWeight; << 798 { 807 return integral *= xDiff; << 799 dx = xDiff*fAbscissa[i] ; >> 800 integral += fWeight[i]*(*f)(xMean + dx) ; >> 801 } >> 802 return integral *= xDiff ; 808 } 803 } 809 804 810 ////////////////////////////////////////////// 805 ////////////////////////////////////////////////////////////////////// 811 // 806 // 812 // Method involving Laguerre polynomials 807 // Method involving Laguerre polynomials 813 // 808 // 814 ////////////////////////////////////////////// 809 ////////////////////////////////////////////////////////////////////// 815 // 810 // 816 // Integral from zero to infinity of std::pow( << 811 // Integral from zero to infinity of pow(x,alpha)*exp(-x)*f(x). 817 // The value of nLaguerre sets the accuracy. 812 // The value of nLaguerre sets the accuracy. 818 // The function creates arrays fAbscissa[0,.., << 813 // The function creates arrays fAbscissa[0,..,nLaguerre-1] and 819 // fWeight[0,..,nLaguerre-1] . << 814 // fWeight[0,..,nLaguerre-1] . 820 // Convenient for using with class object 'typ 815 // Convenient for using with class object 'typeT' and (typeT.*f) function 821 // (T::f) 816 // (T::f) 822 817 823 template <class T, class F> << 818 template <class T, class F> G4double 824 G4double G4Integrator<T, F>::Laguerre(T& typeT << 819 G4Integrator<T,F>::Laguerre( T& typeT, F f, G4double alpha, G4int nLaguerre ) 825 G4int nL << 826 { 820 { 827 const G4double tolerance = 1.0e-10; << 821 const G4double tolerance = 1.0e-10 ; 828 const G4int maxNumber = 12; << 822 const G4int maxNumber = 12 ; 829 G4int i, j, k; << 823 G4int i, j, k ; 830 G4double nwt = 0., nwt1, temp1, temp2, << 824 G4double newton, newton1, temp1, temp2, temp3, temp, cofi ; 831 G4double integral = 0.0; << 825 G4double integral = 0.0 ; 832 << 826 833 G4int fNumber = nLaguerre; << 827 G4int fNumber = nLaguerre ; 834 G4double* fAbscissa = new G4double[fNumber]; << 828 G4double* fAbscissa = new G4double[fNumber] ; 835 G4double* fWeight = new G4double[fNumber]; << 829 G4double* fWeight = new G4double[fNumber] ; >> 830 >> 831 for(i=1;i<=fNumber;i++) // Loop over the desired roots >> 832 { >> 833 if(i == 1) >> 834 { >> 835 newton = (1.0 + alpha)*(3.0 + 0.92*alpha)/(1.0 + 2.4*fNumber + 1.8*alpha) ; >> 836 } >> 837 else if(i == 2) >> 838 { >> 839 newton += (15.0 + 6.25*alpha)/(1.0 + 0.9*alpha + 2.5*fNumber) ; >> 840 } >> 841 else >> 842 { >> 843 cofi = i - 2 ; >> 844 newton += ((1.0+2.55*cofi)/(1.9*cofi) + 1.26*cofi*alpha/(1.0+3.5*cofi))* >> 845 (newton - fAbscissa[i-3])/(1.0 + 0.3*alpha) ; >> 846 } >> 847 for(k=1;k<=maxNumber;k++) >> 848 { >> 849 temp1 = 1.0 ; >> 850 temp2 = 0.0 ; 836 851 837 for(i = 1; i <= fNumber; ++i) // Loop over << 852 for(j=1;j<=fNumber;j++) 838 { << 853 { 839 if(i == 1) << 854 temp3 = temp2 ; 840 { << 855 temp2 = temp1 ; 841 nwt = (1.0 + alpha) * (3.0 + 0.92 * alph << 856 temp1 = ((2*j - 1 + alpha - newton)*temp2 - (j - 1 + alpha)*temp3)/j ; 842 (1.0 + 2.4 * fNumber + 1.8 * alpha << 857 } 843 } << 858 temp = (fNumber*temp1 - (fNumber +alpha)*temp2)/newton ; 844 else if(i == 2) << 859 newton1 = newton ; 845 { << 860 newton = newton1 - temp1/temp ; 846 nwt += (15.0 + 6.25 * alpha) / (1.0 + 0. << 861 847 } << 862 if(fabs(newton - newton1) <= tolerance) 848 else << 863 { 849 { << 864 break ; 850 cofi = i - 2; << 865 } 851 nwt += ((1.0 + 2.55 * cofi) / (1.9 * cof << 866 } 852 1.26 * cofi * alpha / (1.0 + 3.5 << 867 if(k > maxNumber) 853 (nwt - fAbscissa[i - 3]) / (1.0 + << 868 { 854 } << 869 G4Exception("Too many (>12) iterations in G4Integration::Laguerre") ; 855 for(k = 1; k <= maxNumber; ++k) << 870 } 856 { << 871 857 temp1 = 1.0; << 872 fAbscissa[i-1] = newton ; 858 temp2 = 0.0; << 873 fWeight[i-1] = -exp(GammaLogarithm(alpha + fNumber) - 859 << 874 GammaLogarithm((G4double)fNumber))/(temp*fNumber*temp2) ; 860 for(j = 1; j <= fNumber; ++j) << 875 } 861 { << 876 // 862 temp3 = temp2; << 877 // Integral evaluation 863 temp2 = temp1; << 878 // 864 temp1 = << 879 for(i=0;i<fNumber;i++) 865 ((2 * j - 1 + alpha - nwt) * temp2 - << 880 { 866 } << 881 integral += fWeight[i]*(typeT.*f)(fAbscissa[i]) ; 867 temp = (fNumber * temp1 - (fNumber + alp << 882 } 868 nwt1 = nwt; << 883 return integral ; 869 nwt = nwt1 - temp1 / temp; << 884 } 870 << 871 if(std::fabs(nwt - nwt1) <= tolerance) << 872 { << 873 break; << 874 } << 875 } << 876 if(k > maxNumber) << 877 { << 878 G4Exception("G4Integrator<T,F>::Laguerre << 879 FatalException, "Too many (> << 880 } << 881 << 882 fAbscissa[i - 1] = nwt; << 883 fWeight[i - 1] = -std::exp(GammaLogarith << 884 GammaLogarithm( << 885 (temp * fNumber * temp2); << 886 } << 887 885 888 // << 889 // Integral evaluation << 890 // << 891 886 892 for(i = 0; i < fNumber; ++i) << 893 { << 894 integral += fWeight[i] * (typeT.*f)(fAbsci << 895 } << 896 delete[] fAbscissa; << 897 delete[] fWeight; << 898 return integral; << 899 } << 900 887 901 ////////////////////////////////////////////// 888 ////////////////////////////////////////////////////////////////////// 902 // 889 // 903 // 890 // 904 891 905 template <class T, class F> << 892 template <class T, class F> G4double 906 G4double G4Integrator<T, F>::Laguerre(T* ptrT, << 893 G4Integrator<T,F>::Laguerre( T* ptrT, F f, G4double alpha, G4int nLaguerre ) 907 G4int nL << 908 { 894 { 909 return Laguerre(*ptrT, f, alpha, nLaguerre); << 895 return Laguerre(*ptrT,f,alpha,nLaguerre) ; 910 } 896 } 911 897 912 ////////////////////////////////////////////// 898 //////////////////////////////////////////////////////////////////////// 913 // 899 // 914 // For use with global scope functions f << 900 // For use with global scope functions f 915 901 916 template <class T, class F> << 902 template <class T, class F> G4double 917 G4double G4Integrator<T, F>::Laguerre(G4double << 903 G4Integrator<T,F>::Laguerre( G4double (*f)(G4double), 918 G4int nL << 904 G4double alpha, G4int nLaguerre) 919 { << 905 { 920 const G4double tolerance = 1.0e-10; << 906 const G4double tolerance = 1.0e-10 ; 921 const G4int maxNumber = 12; << 907 const G4int maxNumber = 12 ; 922 G4int i, j, k; << 908 G4int i, j, k ; 923 G4double nwt = 0., nwt1, temp1, temp2, << 909 G4double newton, newton1, temp1, temp2, temp3, temp, cofi ; 924 G4double integral = 0.0; << 910 G4double integral = 0.0 ; 925 << 911 926 G4int fNumber = nLaguerre; << 912 G4int fNumber = nLaguerre ; 927 G4double* fAbscissa = new G4double[fNumber]; << 913 G4double* fAbscissa = new G4double[fNumber] ; 928 G4double* fWeight = new G4double[fNumber]; << 914 G4double* fWeight = new G4double[fNumber] ; 929 << 915 930 for(i = 1; i <= fNumber; ++i) // Loop over << 916 for(i=1;i<=fNumber;i++) // Loop over the desired roots 931 { << 917 { 932 if(i == 1) << 918 if(i == 1) 933 { << 919 { 934 nwt = (1.0 + alpha) * (3.0 + 0.92 * alph << 920 newton = (1.0 + alpha)*(3.0 + 0.92*alpha)/(1.0 + 2.4*fNumber + 1.8*alpha) ; 935 (1.0 + 2.4 * fNumber + 1.8 * alpha << 921 } 936 } << 922 else if(i == 2) 937 else if(i == 2) << 923 { 938 { << 924 newton += (15.0 + 6.25*alpha)/(1.0 + 0.9*alpha + 2.5*fNumber) ; 939 nwt += (15.0 + 6.25 * alpha) / (1.0 + 0. << 925 } 940 } << 926 else 941 else << 927 { 942 { << 928 cofi = i - 2 ; 943 cofi = i - 2; << 929 newton += ((1.0+2.55*cofi)/(1.9*cofi) + 1.26*cofi*alpha/(1.0+3.5*cofi))* 944 nwt += ((1.0 + 2.55 * cofi) / (1.9 * cof << 930 (newton - fAbscissa[i-3])/(1.0 + 0.3*alpha) ; 945 1.26 * cofi * alpha / (1.0 + 3.5 << 931 } 946 (nwt - fAbscissa[i - 3]) / (1.0 + << 932 for(k=1;k<=maxNumber;k++) 947 } << 933 { 948 for(k = 1; k <= maxNumber; ++k) << 934 temp1 = 1.0 ; 949 { << 935 temp2 = 0.0 ; 950 temp1 = 1.0; << 951 temp2 = 0.0; << 952 << 953 for(j = 1; j <= fNumber; ++j) << 954 { << 955 temp3 = temp2; << 956 temp2 = temp1; << 957 temp1 = << 958 ((2 * j - 1 + alpha - nwt) * temp2 - << 959 } << 960 temp = (fNumber * temp1 - (fNumber + alp << 961 nwt1 = nwt; << 962 nwt = nwt1 - temp1 / temp; << 963 << 964 if(std::fabs(nwt - nwt1) <= tolerance) << 965 { << 966 break; << 967 } << 968 } << 969 if(k > maxNumber) << 970 { << 971 G4Exception("G4Integrator<T,F>::Laguerre << 972 "Too many (>12) iterations." << 973 } << 974 << 975 fAbscissa[i - 1] = nwt; << 976 fWeight[i - 1] = -std::exp(GammaLogarith << 977 GammaLogarithm( << 978 (temp * fNumber * temp2); << 979 } << 980 << 981 // << 982 // Integral evaluation << 983 // << 984 936 985 for(i = 0; i < fNumber; i++) << 937 for(j=1;j<=fNumber;j++) 986 { << 938 { 987 integral += fWeight[i] * (*f)(fAbscissa[i] << 939 temp3 = temp2 ; 988 } << 940 temp2 = temp1 ; 989 delete[] fAbscissa; << 941 temp1 = ((2*j - 1 + alpha - newton)*temp2 - (j - 1 + alpha)*temp3)/j ; 990 delete[] fWeight; << 942 } 991 return integral; << 943 temp = (fNumber*temp1 - (fNumber +alpha)*temp2)/newton ; >> 944 newton1 = newton ; >> 945 newton = newton1 - temp1/temp ; >> 946 >> 947 if(fabs(newton - newton1) <= tolerance) >> 948 { >> 949 break ; >> 950 } >> 951 } >> 952 if(k > maxNumber) >> 953 { >> 954 G4Exception("Too many (>12) iterations in G4Integration::Laguerre") ; >> 955 } >> 956 >> 957 fAbscissa[i-1] = newton ; >> 958 fWeight[i-1] = -exp(GammaLogarithm(alpha + fNumber) - >> 959 GammaLogarithm((G4double)fNumber))/(temp*fNumber*temp2) ; >> 960 } >> 961 // >> 962 // Integral evaluation >> 963 // >> 964 for(i=0;i<fNumber;i++) >> 965 { >> 966 integral += fWeight[i]*(*f)(fAbscissa[i]) ; >> 967 } >> 968 return integral ; 992 } 969 } 993 970 994 ////////////////////////////////////////////// 971 /////////////////////////////////////////////////////////////////////// 995 // 972 // 996 // Auxiliary function which returns the value << 973 // Auxiliary function which returns the value of log(gamma-function(x)) 997 // Returns the value ln(Gamma(xx) for xx > 0. << 974 // Returns the value ln(Gamma(xx) for xx > 0. Full accuracy is obtained for 998 // xx > 1. For 0 < xx < 1. the reflection form 975 // xx > 1. For 0 < xx < 1. the reflection formula (6.1.4) can be used first. 999 // (Adapted from Numerical Recipes in C) 976 // (Adapted from Numerical Recipes in C) 1000 // 977 // 1001 978 1002 template <class T, class F> 979 template <class T, class F> 1003 G4double G4Integrator<T, F>::GammaLogarithm(G << 980 G4double G4Integrator<T,F>::GammaLogarithm(G4double xx) 1004 { 981 { 1005 static const G4double cof[6] = { 76.1800917 << 982 static G4double cof[6] = { 76.18009172947146, -86.50532032941677, 1006 24.0140982 << 983 24.01409824083091, -1.231739572450155, 1007 0.12086509 << 984 0.1208650973866179e-2, -0.5395239384953e-5 } ; 1008 G4int j; << 985 register HepInt j; 1009 G4double x = xx - 1.0; << 986 G4double x = xx - 1.0 ; 1010 G4double tmp = x + 5.5; << 987 G4double tmp = x + 5.5 ; 1011 tmp -= (x + 0.5) * std::log(tmp); << 988 tmp -= (x + 0.5) * log(tmp) ; 1012 G4double ser = 1.000000000190015; << 989 G4double ser = 1.000000000190015 ; 1013 990 1014 for(j = 0; j <= 5; ++j) << 991 for ( j = 0; j <= 5; j++ ) 1015 { 992 { 1016 x += 1.0; << 993 x += 1.0 ; 1017 ser += cof[j] / x; << 994 ser += cof[j]/x ; 1018 } 995 } 1019 return -tmp + std::log(2.5066282746310005 * << 996 return -tmp + log(2.5066282746310005*ser) ; 1020 } 997 } 1021 998 1022 ///////////////////////////////////////////// 999 /////////////////////////////////////////////////////////////////////// 1023 // 1000 // 1024 // Method involving Hermite polynomials 1001 // Method involving Hermite polynomials 1025 // 1002 // 1026 ///////////////////////////////////////////// 1003 /////////////////////////////////////////////////////////////////////// 1027 // 1004 // 1028 // 1005 // 1029 // Gauss-Hermite method for integration of st << 1006 // Gauss-Hermite method for integration of exp(-x*x)*f(x) 1030 // from minus infinity to plus infinity . << 1007 // from minus infinity to plus infinity . 1031 // 1008 // 1032 1009 1033 template <class T, class F> << 1010 template <class T, class F> 1034 G4double G4Integrator<T, F>::Hermite(T& typeT << 1011 G4double G4Integrator<T,F>::Hermite( T& typeT, F f, G4int nHermite) 1035 { 1012 { 1036 const G4double tolerance = 1.0e-12; << 1013 const G4double tolerance = 1.0e-12 ; 1037 const G4int maxNumber = 12; << 1014 const G4int maxNumber = 12 ; 1038 << 1015 1039 G4int i, j, k; << 1016 G4int i, j, k ; 1040 G4double integral = 0.0; << 1017 G4double integral = 0.0 ; 1041 G4double nwt = 0., nwt1, temp1, temp2, << 1018 G4double newton, newton1, temp1, temp2, temp3, temp ; 1042 1019 1043 G4double piInMinusQ = << 1020 G4double piInMinusQ = pow(pi,-0.25) ; // 1.0/sqrt(sqrt(pi)) ?? 1044 std::pow(CLHEP::pi, -0.25); // 1.0/std:: << 1045 1021 1046 G4int fNumber = (nHermite + 1) / 2; << 1022 G4int fNumber = (nHermite +1)/2 ; 1047 G4double* fAbscissa = new G4double[fNumber] << 1023 G4double* fAbscissa = new G4double[fNumber] ; 1048 G4double* fWeight = new G4double[fNumber] << 1024 G4double* fWeight = new G4double[fNumber] ; 1049 << 1050 for(i = 1; i <= fNumber; ++i) << 1051 { << 1052 if(i == 1) << 1053 { << 1054 nwt = std::sqrt((G4double)(2 * nHermite << 1055 1.85575001 * std::pow((G4double)( << 1056 } << 1057 else if(i == 2) << 1058 { << 1059 nwt -= 1.14001 * std::pow((G4double) nH << 1060 } << 1061 else if(i == 3) << 1062 { << 1063 nwt = 1.86002 * nwt - 0.86002 * fAbscis << 1064 } << 1065 else if(i == 4) << 1066 { << 1067 nwt = 1.91001 * nwt - 0.91001 * fAbscis << 1068 } << 1069 else << 1070 { << 1071 nwt = 2.0 * nwt - fAbscissa[i - 3]; << 1072 } << 1073 for(k = 1; k <= maxNumber; ++k) << 1074 { << 1075 temp1 = piInMinusQ; << 1076 temp2 = 0.0; << 1077 << 1078 for(j = 1; j <= nHermite; ++j) << 1079 { << 1080 temp3 = temp2; << 1081 temp2 = temp1; << 1082 temp1 = nwt * std::sqrt(2.0 / j) * te << 1083 std::sqrt(((G4double)(j - 1)) << 1084 } << 1085 temp = std::sqrt((G4double) 2 * nHermit << 1086 nwt1 = nwt; << 1087 nwt = nwt1 - temp1 / temp; << 1088 << 1089 if(std::fabs(nwt - nwt1) <= tolerance) << 1090 { << 1091 break; << 1092 } << 1093 } << 1094 if(k > maxNumber) << 1095 { << 1096 G4Exception("G4Integrator<T,F>::Hermite << 1097 FatalException, "Too many ( << 1098 } << 1099 fAbscissa[i - 1] = nwt; << 1100 fWeight[i - 1] = 2.0 / (temp * temp); << 1101 } << 1102 1025 1103 // << 1026 for(i=1;i<=fNumber;i++) 1104 // Integral calculation << 1027 { 1105 // << 1028 if(i == 1) >> 1029 { >> 1030 newton = sqrt((G4double)(2*nHermite + 1)) - >> 1031 1.85575001*pow((G4double)(2*nHermite + 1),-0.16666999) ; >> 1032 } >> 1033 else if(i == 2) >> 1034 { >> 1035 newton -= 1.14001*pow((G4double)nHermite,0.425999)/newton ; >> 1036 } >> 1037 else if(i == 3) >> 1038 { >> 1039 newton = 1.86002*newton - 0.86002*fAbscissa[0] ; >> 1040 } >> 1041 else if(i == 4) >> 1042 { >> 1043 newton = 1.91001*newton - 0.91001*fAbscissa[1] ; >> 1044 } >> 1045 else >> 1046 { >> 1047 newton = 2.0*newton - fAbscissa[i - 3] ; >> 1048 } >> 1049 for(k=1;k<=maxNumber;k++) >> 1050 { >> 1051 temp1 = piInMinusQ ; >> 1052 temp2 = 0.0 ; 1106 1053 1107 for(i = 0; i < fNumber; ++i) << 1054 for(j=1;j<=nHermite;j++) 1108 { << 1055 { 1109 integral += << 1056 temp3 = temp2 ; 1110 fWeight[i] * ((typeT.*f)(fAbscissa[i]) << 1057 temp2 = temp1 ; 1111 } << 1058 temp1 = newton*sqrt(2.0/j)*temp2 - 1112 delete[] fAbscissa; << 1059 sqrt(((G4double)(j - 1))/j)*temp3 ; 1113 delete[] fWeight; << 1060 } 1114 return integral; << 1061 temp = sqrt((G4double)2*nHermite)*temp2 ; >> 1062 newton1 = newton ; >> 1063 newton = newton1 - temp1/temp ; >> 1064 >> 1065 if(fabs(newton - newton1) <= tolerance) >> 1066 { >> 1067 break ; >> 1068 } >> 1069 } >> 1070 if(k > maxNumber) >> 1071 { >> 1072 G4Exception("Too many (>12) iterations in G4Integrator<T,F>::Hermite") ; >> 1073 } >> 1074 fAbscissa[i-1] = newton ; >> 1075 fWeight[i-1] = 2.0/(temp*temp) ; >> 1076 } >> 1077 // >> 1078 // Integral calculation >> 1079 // >> 1080 for(i=0;i<fNumber;i++) >> 1081 { >> 1082 integral += fWeight[i]*( (typeT.*f)(fAbscissa[i]) + >> 1083 (typeT.*f)(-fAbscissa[i]) ) ; >> 1084 } >> 1085 return integral ; 1115 } 1086 } 1116 1087 >> 1088 1117 ///////////////////////////////////////////// 1089 //////////////////////////////////////////////////////////////////////// 1118 // 1090 // 1119 // For use with 'this' pointer 1091 // For use with 'this' pointer 1120 1092 1121 template <class T, class F> << 1093 template <class T, class F> 1122 G4double G4Integrator<T, F>::Hermite(T* ptrT, << 1094 G4double G4Integrator<T,F>::Hermite( T* ptrT, F f, G4int n) 1123 { 1095 { 1124 return Hermite(*ptrT, f, n); << 1096 return Hermite(*ptrT,f,n) ; 1125 } << 1097 } 1126 1098 1127 ///////////////////////////////////////////// 1099 //////////////////////////////////////////////////////////////////////// 1128 // 1100 // 1129 // For use with global scope f 1101 // For use with global scope f 1130 1102 1131 template <class T, class F> 1103 template <class T, class F> 1132 G4double G4Integrator<T, F>::Hermite(G4double << 1104 G4double G4Integrator<T,F>::Hermite( G4double (*f)(G4double), G4int nHermite) 1133 { 1105 { 1134 const G4double tolerance = 1.0e-12; << 1106 const G4double tolerance = 1.0e-12 ; 1135 const G4int maxNumber = 12; << 1107 const G4int maxNumber = 12 ; 1136 << 1108 1137 G4int i, j, k; << 1109 G4int i, j, k ; 1138 G4double integral = 0.0; << 1110 G4double integral = 0.0 ; 1139 G4double nwt = 0., nwt1, temp1, temp2, << 1111 G4double newton, newton1, temp1, temp2, temp3, temp ; 1140 << 1112 1141 G4double piInMinusQ = << 1113 G4double piInMinusQ = pow(pi,-0.25) ; // 1.0/sqrt(sqrt(pi)) ?? 1142 std::pow(CLHEP::pi, -0.25); // 1.0/std:: << 1114 1143 << 1115 G4int fNumber = (nHermite +1)/2 ; 1144 G4int fNumber = (nHermite + 1) / 2; << 1116 G4double* fAbscissa = new G4double[fNumber] ; 1145 G4double* fAbscissa = new G4double[fNumber] << 1117 G4double* fWeight = new G4double[fNumber] ; 1146 G4double* fWeight = new G4double[fNumber] << 1118 1147 << 1119 for(i=1;i<=fNumber;i++) 1148 for(i = 1; i <= fNumber; ++i) << 1120 { 1149 { << 1121 if(i == 1) 1150 if(i == 1) << 1122 { 1151 { << 1123 newton = sqrt((G4double)(2*nHermite + 1)) - 1152 nwt = std::sqrt((G4double)(2 * nHermite << 1124 1.85575001*pow((G4double)(2*nHermite + 1),-0.16666999) ; 1153 1.85575001 * std::pow((G4double)( << 1125 } 1154 } << 1126 else if(i == 2) 1155 else if(i == 2) << 1127 { 1156 { << 1128 newton -= 1.14001*pow((G4double)nHermite,0.425999)/newton ; 1157 nwt -= 1.14001 * std::pow((G4double) nH << 1129 } 1158 } << 1130 else if(i == 3) 1159 else if(i == 3) << 1131 { 1160 { << 1132 newton = 1.86002*newton - 0.86002*fAbscissa[0] ; 1161 nwt = 1.86002 * nwt - 0.86002 * fAbscis << 1133 } 1162 } << 1134 else if(i == 4) 1163 else if(i == 4) << 1135 { 1164 { << 1136 newton = 1.91001*newton - 0.91001*fAbscissa[1] ; 1165 nwt = 1.91001 * nwt - 0.91001 * fAbscis << 1137 } 1166 } << 1138 else 1167 else << 1139 { 1168 { << 1140 newton = 2.0*newton - fAbscissa[i - 3] ; 1169 nwt = 2.0 * nwt - fAbscissa[i - 3]; << 1141 } 1170 } << 1142 for(k=1;k<=maxNumber;k++) 1171 for(k = 1; k <= maxNumber; ++k) << 1143 { 1172 { << 1144 temp1 = piInMinusQ ; 1173 temp1 = piInMinusQ; << 1145 temp2 = 0.0 ; 1174 temp2 = 0.0; << 1175 << 1176 for(j = 1; j <= nHermite; ++j) << 1177 { << 1178 temp3 = temp2; << 1179 temp2 = temp1; << 1180 temp1 = nwt * std::sqrt(2.0 / j) * te << 1181 std::sqrt(((G4double)(j - 1)) << 1182 } << 1183 temp = std::sqrt((G4double) 2 * nHermit << 1184 nwt1 = nwt; << 1185 nwt = nwt1 - temp1 / temp; << 1186 << 1187 if(std::fabs(nwt - nwt1) <= tolerance) << 1188 { << 1189 break; << 1190 } << 1191 } << 1192 if(k > maxNumber) << 1193 { << 1194 G4Exception("G4Integrator<T,F>::Hermite << 1195 "Too many (>12) iterations. << 1196 } << 1197 fAbscissa[i - 1] = nwt; << 1198 fWeight[i - 1] = 2.0 / (temp * temp); << 1199 } << 1200 << 1201 // << 1202 // Integral calculation << 1203 // << 1204 1146 1205 for(i = 0; i < fNumber; ++i) << 1147 for(j=1;j<=nHermite;j++) 1206 { << 1148 { 1207 integral += fWeight[i] * ((*f)(fAbscissa[ << 1149 temp3 = temp2 ; 1208 } << 1150 temp2 = temp1 ; 1209 delete[] fAbscissa; << 1151 temp1 = newton*sqrt(2.0/j)*temp2 - 1210 delete[] fWeight; << 1152 sqrt(((G4double)(j - 1))/j)*temp3 ; 1211 return integral; << 1153 } >> 1154 temp = sqrt((G4double)2*nHermite)*temp2 ; >> 1155 newton1 = newton ; >> 1156 newton = newton1 - temp1/temp ; >> 1157 >> 1158 if(fabs(newton - newton1) <= tolerance) >> 1159 { >> 1160 break ; >> 1161 } >> 1162 } >> 1163 if(k > maxNumber) >> 1164 { >> 1165 G4Exception("Too many (>12) iterations in G4Integrator<T,F>::Hermite") ; >> 1166 } >> 1167 fAbscissa[i-1] = newton ; >> 1168 fWeight[i-1] = 2.0/(temp*temp) ; >> 1169 } >> 1170 // >> 1171 // Integral calculation >> 1172 // >> 1173 for(i=0;i<fNumber;i++) >> 1174 { >> 1175 integral += fWeight[i]*( (*f)(fAbscissa[i]) + (*f)(-fAbscissa[i]) ) ; >> 1176 } >> 1177 return integral ; 1212 } 1178 } 1213 1179 1214 ///////////////////////////////////////////// 1180 //////////////////////////////////////////////////////////////////////////// 1215 // 1181 // 1216 // Method involving Jacobi polynomials 1182 // Method involving Jacobi polynomials 1217 // 1183 // 1218 ///////////////////////////////////////////// 1184 //////////////////////////////////////////////////////////////////////////// 1219 // 1185 // 1220 // Gauss-Jacobi method for integration of ((1 1186 // Gauss-Jacobi method for integration of ((1-x)^alpha)*((1+x)^beta)*f(x) 1221 // from minus unit to plus unit . 1187 // from minus unit to plus unit . 1222 // 1188 // 1223 1189 1224 template <class T, class F> << 1190 template <class T, class F> 1225 G4double G4Integrator<T, F>::Jacobi(T& typeT, << 1191 G4double G4Integrator<T,F>::Jacobi( T& typeT, F f, G4double alpha, 1226 G4double << 1192 G4double beta, G4int nJacobi) 1227 { << 1193 { 1228 const G4double tolerance = 1.0e-12; << 1194 const G4double tolerance = 1.0e-12 ; 1229 const G4double maxNumber = 12; << 1195 const G4double maxNumber = 12 ; 1230 G4int i, k, j; << 1196 G4int i, k, j ; 1231 G4double alphaBeta, alphaReduced, betaReduc << 1197 G4double alphaBeta, alphaReduced, betaReduced, root1, root2, root3 ; 1232 << 1198 G4double a, b, c, newton1, newton2, newton3, newton, temp, root, rootTemp ; 1233 G4double a, b, c, nwt1, nwt2, nwt3, nwt, te << 1199 1234 << 1200 G4int fNumber = nJacobi ; 1235 G4int fNumber = nJacobi; << 1201 G4double* fAbscissa = new G4double[fNumber] ; 1236 G4double* fAbscissa = new G4double[fNumber] << 1202 G4double* fWeight = new G4double[fNumber] ; 1237 G4double* fWeight = new G4double[fNumber] << 1203 1238 << 1204 for (i=1;i<=nJacobi;i++) 1239 for(i = 1; i <= nJacobi; ++i) << 1205 { 1240 { << 1206 if (i == 1) 1241 if(i == 1) << 1207 { 1242 { << 1208 alphaReduced = alpha/nJacobi ; 1243 alphaReduced = alpha / nJacobi; << 1209 betaReduced = beta/nJacobi ; 1244 betaReduced = beta / nJacobi; << 1210 root1 = (1.0+alpha)*(2.78002/(4.0+nJacobi*nJacobi)+ 1245 root1 = (1.0 + alpha) * (2.78002 << 1211 0.767999*alphaReduced/nJacobi) ; 1246 0.767999 * alp << 1212 root2 = 1.0+1.48*alphaReduced+0.96002*betaReduced + 1247 root2 = 1.0 + 1.48 * alphaReduce << 1213 0.451998*alphaReduced*alphaReduced + 1248 0.451998 * alphaReduced * alpha << 1214 0.83001*alphaReduced*betaReduced ; 1249 0.83001 * alphaReduced * betaRe << 1215 root = 1.0-root1/root2 ; 1250 root = 1.0 - root1 / root2; << 1216 } 1251 } << 1217 else if (i == 2) 1252 else if(i == 2) << 1218 { 1253 { << 1219 root1=(4.1002+alpha)/((1.0+alpha)*(1.0+0.155998*alpha)) ; 1254 root1 = (4.1002 + alpha) / ((1.0 + alph << 1220 root2=1.0+0.06*(nJacobi-8.0)*(1.0+0.12*alpha)/nJacobi ; 1255 root2 = 1.0 + 0.06 * (nJacobi - 8.0) * << 1221 root3=1.0+0.012002*beta*(1.0+0.24997*fabs(alpha))/nJacobi ; 1256 root3 = << 1222 root -= (1.0-root)*root1*root2*root3 ; 1257 1.0 + 0.012002 * beta * (1.0 + 0.2499 << 1223 } 1258 root -= (1.0 - root) * root1 * root2 * << 1224 else if (i == 3) 1259 } << 1225 { 1260 else if(i == 3) << 1226 root1=(1.67001+0.27998*alpha)/(1.0+0.37002*alpha) ; 1261 { << 1227 root2=1.0+0.22*(nJacobi-8.0)/nJacobi ; 1262 root1 = (1.67001 + 0.27998 * alpha) / ( << 1228 root3=1.0+8.0*beta/((6.28001+beta)*nJacobi*nJacobi) ; 1263 root2 = 1.0 + 0.22 * (nJacobi - 8.0) / << 1229 root -= (fAbscissa[0]-root)*root1*root2*root3 ; 1264 root3 = 1.0 + 8.0 * beta / ((6.28001 + << 1230 } 1265 root -= (fAbscissa[0] - root) * root1 * << 1231 else if (i == nJacobi-1) 1266 } << 1232 { 1267 else if(i == nJacobi - 1) << 1233 root1=(1.0+0.235002*beta)/(0.766001+0.118998*beta) ; 1268 { << 1234 root2=1.0/(1.0+0.639002*(nJacobi-4.0)/(1.0+0.71001*(nJacobi-4.0))) ; 1269 root1 = (1.0 + 0.235002 * beta) / (0.76 << 1235 root3=1.0/(1.0+20.0*alpha/((7.5+alpha)*nJacobi*nJacobi)) ; 1270 root2 = 1.0 / (1.0 + 0.639002 * (nJacob << 1236 root += (root-fAbscissa[nJacobi-4])*root1*root2*root3 ; 1271 (1.0 + 0.71001 * << 1237 } 1272 root3 = 1.0 / (1.0 + 20.0 * alpha / ((7 << 1238 else if (i == nJacobi) 1273 root += (root - fAbscissa[nJacobi - 4]) << 1239 { 1274 } << 1240 root1 = (1.0+0.37002*beta)/(1.67001+0.27998*beta) ; 1275 else if(i == nJacobi) << 1241 root2 = 1.0/(1.0+0.22*(nJacobi-8.0)/nJacobi) ; 1276 { << 1242 root3 = 1.0/(1.0+8.0*alpha/((6.28002+alpha)*nJacobi*nJacobi)) ; 1277 root1 = (1.0 + 0.37002 * beta) / (1.670 << 1243 root += (root-fAbscissa[nJacobi-3])*root1*root2*root3 ; 1278 root2 = 1.0 / (1.0 + 0.22 * (nJacobi - << 1244 } 1279 root3 = << 1245 else 1280 1.0 / (1.0 + 8.0 * alpha / ((6.28002 << 1246 { 1281 root += (root - fAbscissa[nJacobi - 3]) << 1247 root = 3.0*fAbscissa[i-2]-3.0*fAbscissa[i-3]+fAbscissa[i-4] ; 1282 } << 1248 } 1283 else << 1249 alphaBeta = alpha + beta ; 1284 { << 1250 for (k=1;k<=maxNumber;k++) 1285 root = 3.0 * fAbscissa[i - 2] - 3.0 * f << 1251 { 1286 } << 1252 temp = 2.0 + alphaBeta ; 1287 alphaBeta = alpha + beta; << 1253 newton1 = (alpha-beta+temp*root)/2.0 ; 1288 for(k = 1; k <= maxNumber; ++k) << 1254 newton2 = 1.0 ; 1289 { << 1255 for (j=2;j<=nJacobi;j++) 1290 temp = 2.0 + alphaBeta; << 1256 { 1291 nwt1 = (alpha - beta + temp * root) / 2 << 1257 newton3 = newton2 ; 1292 nwt2 = 1.0; << 1258 newton2 = newton1 ; 1293 for(j = 2; j <= nJacobi; ++j) << 1259 temp = 2*j+alphaBeta ; 1294 { << 1260 a = 2*j*(j+alphaBeta)*(temp-2.0) ; 1295 nwt3 = nwt2; << 1261 b = (temp-1.0)*(alpha*alpha-beta*beta+temp*(temp-2.0)*root) ; 1296 nwt2 = nwt1; << 1262 c = 2.0*(j-1+alpha)*(j-1+beta)*temp ; 1297 temp = 2 * j + alphaBeta; << 1263 newton1 = (b*newton2-c*newton3)/a ; 1298 a = 2 * j * (j + alphaBeta) * (tem << 1264 } 1299 b = (temp - 1.0) * << 1265 newton = (nJacobi*(alpha - beta - temp*root)*newton1 + 1300 (alpha * alpha - beta * beta + te << 1266 2.0*(nJacobi + alpha)*(nJacobi + beta)*newton2)/ 1301 c = 2.0 * (j - 1 + alpha) * (j - 1 << 1267 (temp*(1.0 - root*root)) ; 1302 nwt1 = (b * nwt2 - c * nwt3) / a; << 1268 rootTemp = root ; 1303 } << 1269 root = rootTemp - newton1/newton ; 1304 nwt = (nJacobi * (alpha - beta - temp * << 1270 if (fabs(root-rootTemp) <= tolerance) 1305 2.0 * (nJacobi + alpha) * (nJaco << 1271 { 1306 (temp * (1.0 - root * root)); << 1272 break ; 1307 rootTemp = root; << 1273 } 1308 root = rootTemp - nwt1 / nwt; << 1274 } 1309 if(std::fabs(root - rootTemp) <= tolera << 1275 if (k > maxNumber) 1310 { << 1276 { 1311 break; << 1277 G4Exception("Too many iterations (>12) in G4Integrator<T,F>::Jacobi") ; 1312 } << 1278 } 1313 } << 1279 fAbscissa[i-1] = root ; 1314 if(k > maxNumber) << 1280 fWeight[i-1] = exp(GammaLogarithm((G4double)(alpha+nJacobi)) + 1315 { << 1281 GammaLogarithm((G4double)(beta+nJacobi)) - 1316 G4Exception("G4Integrator<T,F>::Jacobi( << 1282 GammaLogarithm((G4double)(nJacobi+1.0)) - 1317 FatalException, "Too many ( << 1283 GammaLogarithm((G4double)(nJacobi + alphaBeta + 1.0))) 1318 } << 1284 *temp*pow(2.0,alphaBeta)/(newton*newton2) ; 1319 fAbscissa[i - 1] = root; << 1285 } 1320 fWeight[i - 1] = << 1286 // 1321 std::exp(GammaLogarithm((G4double)(alph << 1287 // Calculation of the integral 1322 GammaLogarithm((G4double)(beta << 1288 // 1323 GammaLogarithm((G4double)(nJac << 1289 G4double integral = 0.0 ; 1324 GammaLogarithm((G4double)(nJac << 1290 for(i=0;i<fNumber;i++) 1325 temp * std::pow(2.0, alphaBeta) / (nwt << 1291 { 1326 } << 1292 integral += fWeight[i]*(typeT.*f)(fAbscissa[i]) ; 1327 << 1293 } 1328 // << 1294 return integral ; 1329 // Calculation of the integral << 1330 // << 1331 << 1332 G4double integral = 0.0; << 1333 for(i = 0; i < fNumber; ++i) << 1334 { << 1335 integral += fWeight[i] * (typeT.*f)(fAbsc << 1336 } << 1337 delete[] fAbscissa; << 1338 delete[] fWeight; << 1339 return integral; << 1340 } 1295 } 1341 1296 >> 1297 1342 ///////////////////////////////////////////// 1298 ///////////////////////////////////////////////////////////////////////// 1343 // 1299 // 1344 // For use with 'this' pointer 1300 // For use with 'this' pointer 1345 1301 1346 template <class T, class F> << 1302 template <class T, class F> 1347 G4double G4Integrator<T, F>::Jacobi(T* ptrT, << 1303 G4double G4Integrator<T,F>::Jacobi( T* ptrT, F f, G4double alpha, 1348 G4int n) << 1304 G4double beta, G4int n) 1349 { 1305 { 1350 return Jacobi(*ptrT, f, alpha, beta, n); << 1306 return Jacobi(*ptrT,f,alpha,beta,n) ; 1351 } << 1307 } 1352 1308 1353 ///////////////////////////////////////////// 1309 ///////////////////////////////////////////////////////////////////////// 1354 // 1310 // 1355 // For use with global scope f << 1311 // For use with global scope f 1356 1312 1357 template <class T, class F> 1313 template <class T, class F> 1358 G4double G4Integrator<T, F>::Jacobi(G4double << 1314 G4double G4Integrator<T,F>::Jacobi( G4double (*f)(G4double), G4double alpha, 1359 G4double << 1315 G4double beta, G4int nJacobi) 1360 { 1316 { 1361 const G4double tolerance = 1.0e-12; << 1317 const G4double tolerance = 1.0e-12 ; 1362 const G4double maxNumber = 12; << 1318 const G4double maxNumber = 12 ; 1363 G4int i, k, j; << 1319 G4int i, k, j ; 1364 G4double alphaBeta, alphaReduced, betaReduc << 1320 G4double alphaBeta, alphaReduced, betaReduced, root1, root2, root3 ; 1365 << 1321 G4double a, b, c, newton1, newton2, newton3, newton, temp, root, rootTemp ; 1366 G4double a, b, c, nwt1, nwt2, nwt3, nwt, te << 1322 1367 << 1323 G4int fNumber = nJacobi ; 1368 G4int fNumber = nJacobi; << 1324 G4double* fAbscissa = new G4double[fNumber] ; 1369 G4double* fAbscissa = new G4double[fNumber] << 1325 G4double* fWeight = new G4double[fNumber] ; 1370 G4double* fWeight = new G4double[fNumber] << 1326 1371 << 1327 for (i=1;i<=nJacobi;i++) 1372 for(i = 1; i <= nJacobi; ++i) << 1328 { 1373 { << 1329 if (i == 1) 1374 if(i == 1) << 1330 { 1375 { << 1331 alphaReduced = alpha/nJacobi ; 1376 alphaReduced = alpha / nJacobi; << 1332 betaReduced = beta/nJacobi ; 1377 betaReduced = beta / nJacobi; << 1333 root1 = (1.0+alpha)*(2.78002/(4.0+nJacobi*nJacobi)+ 1378 root1 = (1.0 + alpha) * (2.78002 << 1334 0.767999*alphaReduced/nJacobi) ; 1379 0.767999 * alp << 1335 root2 = 1.0+1.48*alphaReduced+0.96002*betaReduced + 1380 root2 = 1.0 + 1.48 * alphaReduce << 1336 0.451998*alphaReduced*alphaReduced + 1381 0.451998 * alphaReduced * alpha << 1337 0.83001*alphaReduced*betaReduced ; 1382 0.83001 * alphaReduced * betaRe << 1338 root = 1.0-root1/root2 ; 1383 root = 1.0 - root1 / root2; << 1339 } 1384 } << 1340 else if (i == 2) 1385 else if(i == 2) << 1341 { 1386 { << 1342 root1=(4.1002+alpha)/((1.0+alpha)*(1.0+0.155998*alpha)) ; 1387 root1 = (4.1002 + alpha) / ((1.0 + alph << 1343 root2=1.0+0.06*(nJacobi-8.0)*(1.0+0.12*alpha)/nJacobi ; 1388 root2 = 1.0 + 0.06 * (nJacobi - 8.0) * << 1344 root3=1.0+0.012002*beta*(1.0+0.24997*fabs(alpha))/nJacobi ; 1389 root3 = << 1345 root -= (1.0-root)*root1*root2*root3 ; 1390 1.0 + 0.012002 * beta * (1.0 + 0.2499 << 1346 } 1391 root -= (1.0 - root) * root1 * root2 * << 1347 else if (i == 3) 1392 } << 1348 { 1393 else if(i == 3) << 1349 root1=(1.67001+0.27998*alpha)/(1.0+0.37002*alpha) ; 1394 { << 1350 root2=1.0+0.22*(nJacobi-8.0)/nJacobi ; 1395 root1 = (1.67001 + 0.27998 * alpha) / ( << 1351 root3=1.0+8.0*beta/((6.28001+beta)*nJacobi*nJacobi) ; 1396 root2 = 1.0 + 0.22 * (nJacobi - 8.0) / << 1352 root -= (fAbscissa[0]-root)*root1*root2*root3 ; 1397 root3 = 1.0 + 8.0 * beta / ((6.28001 + << 1353 } 1398 root -= (fAbscissa[0] - root) * root1 * << 1354 else if (i == nJacobi-1) 1399 } << 1355 { 1400 else if(i == nJacobi - 1) << 1356 root1=(1.0+0.235002*beta)/(0.766001+0.118998*beta) ; 1401 { << 1357 root2=1.0/(1.0+0.639002*(nJacobi-4.0)/(1.0+0.71001*(nJacobi-4.0))) ; 1402 root1 = (1.0 + 0.235002 * beta) / (0.76 << 1358 root3=1.0/(1.0+20.0*alpha/((7.5+alpha)*nJacobi*nJacobi)) ; 1403 root2 = 1.0 / (1.0 + 0.639002 * (nJacob << 1359 root += (root-fAbscissa[nJacobi-4])*root1*root2*root3 ; 1404 (1.0 + 0.71001 * << 1360 } 1405 root3 = 1.0 / (1.0 + 20.0 * alpha / ((7 << 1361 else if (i == nJacobi) 1406 root += (root - fAbscissa[nJacobi - 4]) << 1362 { 1407 } << 1363 root1 = (1.0+0.37002*beta)/(1.67001+0.27998*beta) ; 1408 else if(i == nJacobi) << 1364 root2 = 1.0/(1.0+0.22*(nJacobi-8.0)/nJacobi) ; 1409 { << 1365 root3 = 1.0/(1.0+8.0*alpha/((6.28002+alpha)*nJacobi*nJacobi)) ; 1410 root1 = (1.0 + 0.37002 * beta) / (1.670 << 1366 root += (root-fAbscissa[nJacobi-3])*root1*root2*root3 ; 1411 root2 = 1.0 / (1.0 + 0.22 * (nJacobi - << 1367 } 1412 root3 = << 1368 else 1413 1.0 / (1.0 + 8.0 * alpha / ((6.28002 << 1369 { 1414 root += (root - fAbscissa[nJacobi - 3]) << 1370 root = 3.0*fAbscissa[i-2]-3.0*fAbscissa[i-3]+fAbscissa[i-4] ; 1415 } << 1371 } 1416 else << 1372 alphaBeta = alpha + beta ; 1417 { << 1373 for (k=1;k<=maxNumber;k++) 1418 root = 3.0 * fAbscissa[i - 2] - 3.0 * f << 1374 { 1419 } << 1375 temp = 2.0 + alphaBeta ; 1420 alphaBeta = alpha + beta; << 1376 newton1 = (alpha-beta+temp*root)/2.0 ; 1421 for(k = 1; k <= maxNumber; ++k) << 1377 newton2 = 1.0 ; 1422 { << 1378 for (j=2;j<=nJacobi;j++) 1423 temp = 2.0 + alphaBeta; << 1379 { 1424 nwt1 = (alpha - beta + temp * root) / 2 << 1380 newton3 = newton2 ; 1425 nwt2 = 1.0; << 1381 newton2 = newton1 ; 1426 for(j = 2; j <= nJacobi; ++j) << 1382 temp = 2*j+alphaBeta ; 1427 { << 1383 a = 2*j*(j+alphaBeta)*(temp-2.0) ; 1428 nwt3 = nwt2; << 1384 b = (temp-1.0)*(alpha*alpha-beta*beta+temp*(temp-2.0)*root) ; 1429 nwt2 = nwt1; << 1385 c = 2.0*(j-1+alpha)*(j-1+beta)*temp ; 1430 temp = 2 * j + alphaBeta; << 1386 newton1 = (b*newton2-c*newton3)/a ; 1431 a = 2 * j * (j + alphaBeta) * (tem << 1387 } 1432 b = (temp - 1.0) * << 1388 newton = (nJacobi*(alpha - beta - temp*root)*newton1 + 1433 (alpha * alpha - beta * beta + te << 1389 2.0*(nJacobi + alpha)*(nJacobi + beta)*newton2)/ 1434 c = 2.0 * (j - 1 + alpha) * (j - 1 << 1390 (temp*(1.0 - root*root)) ; 1435 nwt1 = (b * nwt2 - c * nwt3) / a; << 1391 rootTemp = root ; 1436 } << 1392 root = rootTemp - newton1/newton ; 1437 nwt = (nJacobi * (alpha - beta - temp * << 1393 if (fabs(root-rootTemp) <= tolerance) 1438 2.0 * (nJacobi + alpha) * (nJaco << 1394 { 1439 (temp * (1.0 - root * root)); << 1395 break ; 1440 rootTemp = root; << 1396 } 1441 root = rootTemp - nwt1 / nwt; << 1397 } 1442 if(std::fabs(root - rootTemp) <= tolera << 1398 if (k > maxNumber) 1443 { << 1399 { 1444 break; << 1400 G4Exception("Too many iterations (>12) in G4Integrator<T,F>::Jacobi") ; 1445 } << 1401 } 1446 } << 1402 fAbscissa[i-1] = root ; 1447 if(k > maxNumber) << 1403 fWeight[i-1] = exp(GammaLogarithm((G4double)(alpha+nJacobi)) + 1448 { << 1404 GammaLogarithm((G4double)(beta+nJacobi)) - 1449 G4Exception("G4Integrator<T,F>::Jacobi( << 1405 GammaLogarithm((G4double)(nJacobi+1.0)) - 1450 "Too many (>12) iterations. << 1406 GammaLogarithm((G4double)(nJacobi + alphaBeta + 1.0))) 1451 } << 1407 *temp*pow(2.0,alphaBeta)/(newton*newton2) ; 1452 fAbscissa[i - 1] = root; << 1408 } 1453 fWeight[i - 1] = << 1409 // 1454 std::exp(GammaLogarithm((G4double)(alph << 1410 // Calculation of the integral 1455 GammaLogarithm((G4double)(beta << 1411 // 1456 GammaLogarithm((G4double)(nJac << 1412 G4double integral = 0.0 ; 1457 GammaLogarithm((G4double)(nJac << 1413 for(i=0;i<fNumber;i++) 1458 temp * std::pow(2.0, alphaBeta) / (nwt << 1414 { 1459 } << 1415 integral += fWeight[i]*(*f)(fAbscissa[i]) ; >> 1416 } >> 1417 return integral ; >> 1418 } 1460 1419 1461 // << 1462 // Calculation of the integral << 1463 // << 1464 1420 1465 G4double integral = 0.0; << 1466 for(i = 0; i < fNumber; ++i) << 1467 { << 1468 integral += fWeight[i] * (*f)(fAbscissa[i << 1469 } << 1470 delete[] fAbscissa; << 1471 delete[] fWeight; << 1472 return integral; << 1473 } << 1474 1421 1475 // 1422 // 1476 // 1423 // 1477 ///////////////////////////////////////////// 1424 /////////////////////////////////////////////////////////////////// >> 1425 >> 1426 >> 1427 >> 1428 1478 1429