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 // G4GaussHermiteQ class implementation << 27 // 23 // 28 // Author: V.Grichine, 13.05.1997 V.Grichine << 24 // $Id: G4GaussHermiteQ.cc,v 1.4 2001/07/11 10:00:41 gunter Exp $ 29 // ------------------------------------------- << 25 // GEANT4 tag $Name: geant4-05-02-patch-01 $ 30 << 26 // 31 #include "G4GaussHermiteQ.hh" 27 #include "G4GaussHermiteQ.hh" 32 #include "G4PhysicalConstants.hh" << 33 28 34 #include <limits> << 35 29 36 // ------------------------------------------- 30 // ---------------------------------------------------------- 37 // 31 // 38 // Constructor for Gauss-Hermite 32 // Constructor for Gauss-Hermite 39 33 40 G4GaussHermiteQ::G4GaussHermiteQ(function pFun << 34 G4GaussHermiteQ::G4GaussHermiteQ( function pFunction, 41 : G4VGaussianQuadrature(pFunction) << 35 G4int nHermite ) >> 36 : G4VGaussianQuadrature(pFunction) 42 { 37 { 43 const G4double tolerance = 1.0e-12; << 38 const G4double tolerance = 1.0e-12 ; 44 const G4int maxNumber = 12; << 39 const G4int maxNumber = 12 ; 45 << 40 46 G4int i = 1, j = 1, k = 1; << 41 G4int i, j, k ; 47 G4double newton0 = 0.; << 42 G4double newton=0.; 48 G4double newton1 = 0.0, temp1 = 0.0, temp2 = << 43 G4double newton1, temp1, temp2, temp3, temp ; 49 G4double piInMinusQ = std::pow(pi, -0.25); << 44 G4double piInMinusQ = pow(pi,-0.25) ; // 1.0/sqrt(sqrt(pi)) ?? 50 << 45 51 fNumber = (nHermite + 1) / 2; << 46 fNumber = (nHermite +1)/2 ; 52 fAbscissa = new G4double[fNumber]; << 47 fAbscissa = new G4double[fNumber] ; 53 fWeight = new G4double[fNumber]; << 48 fWeight = new G4double[fNumber] ; 54 << 49 55 for(i = 1; i <= fNumber; ++i) << 50 for(i=1;i<=fNumber;i++) 56 { << 51 { 57 if(i == 1) << 52 if(i == 1) 58 { << 53 { 59 newton0 = << 54 newton = sqrt((G4double)(2*nHermite + 1)) - 60 std::sqrt((G4double)(2 * nHermite + 1) << 55 1.85575001*pow((G4double)(2*nHermite + 1),-0.16666999) ; 61 1.85575001 * std::pow((G4double)(2 * n << 56 } 62 } << 57 else if(i == 2) 63 else if(i == 2) << 58 { 64 { << 59 newton -= 1.14001*pow((G4double)nHermite,0.425999)/newton ; 65 newton0 -= 1.14001 * std::pow((G4double) << 60 } 66 } << 61 else if(i == 3) 67 else if(i == 3) << 62 { 68 { << 63 newton = 1.86002*newton - 0.86002*fAbscissa[0] ; 69 newton0 = 1.86002 * newton0 - 0.86002 * << 64 } 70 } << 65 else if(i == 4) 71 else if(i == 4) << 66 { 72 { << 67 newton = 1.91001*newton - 0.91001*fAbscissa[1] ; 73 newton0 = 1.91001 * newton0 - 0.91001 * << 68 } 74 } << 69 else 75 else << 70 { 76 { << 71 newton = 2.0*newton - fAbscissa[i - 3] ; 77 newton0 = 2.0 * newton0 - fAbscissa[i - << 72 } 78 } << 73 for(k=1;k<=maxNumber;k++) 79 for(k = 1; k <= maxNumber; ++k) << 74 { 80 { << 75 temp1 = piInMinusQ ; 81 temp1 = piInMinusQ; << 76 temp2 = 0.0 ; 82 temp2 = 0.0; << 77 for(j=1;j<=nHermite;j++) 83 for(j = 1; j <= nHermite; ++j) << 78 { 84 { << 79 temp3 = temp2 ; 85 temp3 = temp2; << 80 temp2 = temp1 ; 86 temp2 = temp1; << 81 temp1 = newton*sqrt(2.0/j)*temp2 - sqrt(((G4double)(j - 1))/j)*temp3 ; 87 temp1 = newton0 * std::sqrt(2.0 / j) * << 82 } 88 std::sqrt(((G4double)(j - 1)) << 83 temp = sqrt((G4double)2*nHermite)*temp2 ; 89 } << 84 newton1 = newton ; 90 temp = std::sqrt((G4double) 2 * nHerm << 85 newton = newton1 - temp1/temp ; 91 newton1 = newton0; << 86 if(fabs(newton - newton1) <= tolerance) 92 G4double ratio = std::numeric_limits<G4d << 87 { 93 if(temp > 0.0) << 88 break ; 94 { << 89 } 95 ratio = temp1 / temp; << 90 } 96 } << 91 if(k > maxNumber) 97 newton0 = newton1 - ratio; << 92 { 98 if(std::fabs(newton0 - newton1) <= toler << 93 G4Exception("Too many iterations in Gauss-Hermite constructor") ; 99 { << 94 } 100 break; << 95 fAbscissa[i-1] = newton ; 101 } << 96 fWeight[i-1] = 2.0/(temp*temp) ; 102 } << 97 } 103 if(k > maxNumber) << 104 { << 105 G4Exception("G4GaussHermiteQ::G4GaussHer << 106 FatalException, << 107 "Too many iterations in Gaus << 108 } << 109 fAbscissa[i - 1] = newton0; << 110 fWeight[i - 1] = 2.0 / (temp * temp); << 111 } << 112 } 98 } 113 99 >> 100 114 // ------------------------------------------- 101 // ---------------------------------------------------------- 115 // 102 // 116 // Gauss-Hermite method for integration of std << 103 // Gauss-Hermite method for integration of exp(-x*x)*nFunction(x) from minus infinity 117 // from minus infinity to plus infinity . << 104 // to plus infinity . 118 105 119 G4double G4GaussHermiteQ::Integral() const << 106 G4double >> 107 G4GaussHermiteQ::Integral() const 120 { 108 { 121 G4double integral = 0.0; << 109 G4int i ; 122 for(G4int i = 0; i < fNumber; ++i) << 110 G4double integral = 0.0 ; 123 { << 111 for(i=0;i<fNumber;i++) 124 integral += << 112 { 125 fWeight[i] * (fFunction(fAbscissa[i]) + << 113 integral += fWeight[i]*(fFunction(fAbscissa[i]) + fFunction(-fAbscissa[i])) ; 126 } << 114 } 127 return integral; << 115 return integral ; 128 } 116 } 129 117