Import Geant4 7.1.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-09 12:11:21 +02:00
parent 516dbf1a58
commit d93e1e39a9
5384 changed files with 125662 additions and 82444 deletions
@@ -0,0 +1,75 @@
//
// ********************************************************************
// * DISCLAIMER *
// * *
// * The following disclaimer summarizes all the specific disclaimers *
// * of contributors to this software. The specific disclaimers,which *
// * govern, are listed with their locations in: *
// * http://cern.ch/geant4/license *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. *
// * *
// * This code implementation is the intellectual property of the *
// * GEANT4 collaboration. *
// * By copying, distributing or modifying the Program (or any work *
// * based on the Program) you indicate your acceptance of this *
// * statement, and all its terms. *
// ********************************************************************
//
//
// $Id: G4AnalyticalPolSolver.hh,v 1.4 2005/05/19 07:37:10 gcosmo Exp $
// GEANT4 tag $Name: geant4-07-01 $
//
// Class description:
//
// G4AnalyticalPolSolver allows the user to solve analytically a polynomial
// equation up to the 4th order. This is used by CSG solid tracking functions
// like G4Torus.
//
// The algorithm has been adapted from the CACM Algorithm 326:
//
// Roots of low order polynomials
// Author: Terence R.F.Nonweiler
// CACM (Apr 1968) p269
// Translated into C and programmed by M.Dow
// ANUSF, Australian National University, Canberra, Australia
// m.dow@anu.edu.au
//
// Suite of procedures for finding the (complex) roots of the quadratic,
// cubic or quartic polynomials by explicit algebraic methods.
// Each Returns:
//
// x=r[1][k] + i r[2][k] k=1,...,n, where n={2,3,4}
//
// as roots of:
// sum_{k=0:n} p[k] x^(n-k) = 0
// Assumes p[0] != 0. (< or > 0) (overflows otherwise)
// --------------------------- HISTORY --------------------------------------
//
// 13.05.05 V.Grichine ( Vladimir.Grichine@cern.ch )
// First implementation in C++
#ifndef G4AN_POL_SOLVER_HH
#define G4AN_POL_SOLVER_HH
#include "G4Types.hh"
class G4AnalyticalPolSolver
{
public: // with description
G4AnalyticalPolSolver();
~G4AnalyticalPolSolver();
G4int QuadRoots( G4double p[5], G4double r[3][5]);
G4int CubicRoots( G4double p[5], G4double r[3][5]);
G4int BiquadRoots( G4double p[5], G4double r[3][5]);
G4int QuarticRoots( G4double p[5], G4double r[3][5]);
};
#endif
@@ -21,8 +21,8 @@
// ********************************************************************
//
//
// $Id: G4ChebyshevApproximation.hh,v 1.4 2001/07/11 10:00:39 gunter Exp $
// GEANT4 tag $Name: geant4-07-00-cand-01 $
// $Id: G4ChebyshevApproximation.hh,v 1.5 2005/03/15 19:11:35 gcosmo Exp $
// GEANT4 tag $Name: geant4-07-01 $
//
// Class description:
//
@@ -51,8 +51,8 @@
// G4ChebyshevApproximation( function pFunction,
// G4int n,
// G4double a,
// G4double b )
//
// G4double b )
//
// --------------------------------------------------------------------
//
// Constructor for creation of Chebyshev coefficients for m-derivative
@@ -60,21 +60,21 @@
// array of fChebyshevCof will be of (n-m) size. There is a definite dependence
// between the proper selection of n, m, a and b values to get better accuracy
// of the derivative value.
//
//
// G4ChebyshevApproximation( function pFunction,
// G4int n,
// G4int m,
// G4int m,
// G4double a,
// G4double b )
// G4double b )
//
// ------------------------------------------------------
//
// Constructor for creation of Chebyshev coefficients for integral
// from pFunction.
//
//
// G4ChebyshevApproximation( function pFunction,
// G4double a,
// G4double b,
// G4double b,
// G4int n )
//
// ---------------------------------------------------------------
@@ -125,59 +125,55 @@ typedef G4double (*function)(G4double) ;
class G4ChebyshevApproximation
{
public:
G4ChebyshevApproximation( function pFunction,
G4int n,
G4double a,
G4double b ) ;
// Constructor for creation of Chebyshev coefficients for m-derivative
// from pFunction. The value of m ! MUST BE ! < n , because the result
// array of fChebyshevCof will be of (n-m) size.
G4ChebyshevApproximation( function pFunction,
G4int n,
G4int m,
G4double a,
G4double b ) ;
public: // with description
// Constructor for creation of Chebyshev coefficients for integral
// from pFunction.
G4ChebyshevApproximation( function pFunction,
G4double a,
G4double b,
G4int n ) ;
~G4ChebyshevApproximation() ;
// Access functions
G4double GetChebyshevCof(G4int number) const ;
// Methods
G4double ChebyshevEvaluation(G4double x) const ;
void DerivativeChebyshevCof(G4double derCof[]) const ;
void IntegralChebyshevCof(G4double integralCof[]) const ;
private:
G4ChebyshevApproximation( function pFunction,
G4int n,
G4double a,
G4double b ) ;
//
// Constructor for creation of Chebyshev coefficients for m-derivative
// from pFunction. The value of m ! MUST BE ! < n , because the result
// array of fChebyshevCof will be of (n-m) size.
G4ChebyshevApproximation(const G4ChebyshevApproximation&);
G4ChebyshevApproximation& operator=(const G4ChebyshevApproximation&);
G4ChebyshevApproximation( function pFunction,
G4int n,
G4int m,
G4double a,
G4double b ) ;
//
// Constructor for creation of Chebyshev coefficients for integral
// from pFunction.
private:
G4ChebyshevApproximation( function pFunction,
G4double a,
G4double b,
G4int n ) ;
function fFunction ;
G4int fNumber ;
G4double* fChebyshevCof ;
G4double fMean ;
G4double fDiff ;
~G4ChebyshevApproximation() ;
// Access functions
G4double GetChebyshevCof(G4int number) const ;
// Methods
} ;
G4double ChebyshevEvaluation(G4double x) const ;
void DerivativeChebyshevCof(G4double derCof[]) const ;
void IntegralChebyshevCof(G4double integralCof[]) const ;
private:
G4ChebyshevApproximation(const G4ChebyshevApproximation&);
G4ChebyshevApproximation& operator=(const G4ChebyshevApproximation&);
private:
function fFunction ;
G4int fNumber ;
G4double* fChebyshevCof ;
G4double fMean ;
G4double fDiff ;
};
#endif
@@ -22,7 +22,7 @@
//
//
// $Id: G4DataInterpolation.hh,v 1.4 2001/07/11 10:00:39 gunter Exp $
// GEANT4 tag $Name: geant4-07-00-cand-01 $
// GEANT4 tag $Name: geant4-07-01 $
//
// Class description:
//
@@ -22,7 +22,7 @@
//
//
// $Id: G4GaussChebyshevQ.hh,v 1.4 2001/07/11 10:00:39 gunter Exp $
// GEANT4 tag $Name: geant4-07-00-cand-01 $
// GEANT4 tag $Name: geant4-07-01 $
//
// Class description:
//
@@ -22,7 +22,7 @@
//
//
// $Id: G4GaussHermiteQ.hh,v 1.5 2004/11/12 17:38:20 gcosmo Exp $
// GEANT4 tag $Name: geant4-07-00-cand-03 $
// GEANT4 tag $Name: geant4-07-01 $
//
// Class description:
//
@@ -22,7 +22,7 @@
//
//
// $Id: G4GaussJacobiQ.hh,v 1.4 2001/07/11 10:00:39 gunter Exp $
// GEANT4 tag $Name: geant4-07-00-cand-01 $
// GEANT4 tag $Name: geant4-07-01 $
//
// Class description:
//
@@ -22,7 +22,7 @@
//
//
// $Id: G4GaussLaguerreQ.hh,v 1.5 2004/11/12 17:38:29 gcosmo Exp $
// GEANT4 tag $Name: geant4-07-00-cand-03 $
// GEANT4 tag $Name: geant4-07-01 $
//
// Class description:
//
@@ -21,8 +21,8 @@
// ********************************************************************
//
//
// $Id: G4GaussLegendreQ.hh,v 1.4 2001/07/11 10:00:39 gunter Exp $
// GEANT4 tag $Name: geant4-07-00-cand-01 $
// $Id: G4GaussLegendreQ.hh,v 1.5 2005/03/15 19:11:35 gcosmo Exp $
// GEANT4 tag $Name: geant4-07-01 $
//
// Class description:
//
@@ -88,7 +88,7 @@
class G4GaussLegendreQ : public G4VGaussianQuadrature
{
public:
G4GaussLegendreQ( function pFunction ) ;
explicit G4GaussLegendreQ( function pFunction ) ;
G4GaussLegendreQ( function pFunction,
@@ -22,7 +22,7 @@
//
//
// $Id: G4Integrator.hh,v 1.6 2004/11/12 16:25:33 gcosmo Exp $
// GEANT4 tag $Name: geant4-07-00-cand-03 $
// GEANT4 tag $Name: geant4-07-01 $
//
// Class description:
//
@@ -21,8 +21,8 @@
// ********************************************************************
//
//
// $Id: G4Integrator.icc,v 1.11 2004/11/12 17:38:29 gcosmo Exp $
// GEANT4 tag $Name: geant4-07-00-cand-03 $
// $Id: G4Integrator.icc,v 1.12 2005/03/15 19:11:35 gcosmo Exp $
// GEANT4 tag $Name: geant4-07-01 $
//
// Implementation of G4Integrator methods.
//
@@ -188,8 +188,8 @@ void G4Integrator<T,F>::AdaptGauss( T& typeT, F f, G4double xInitial,
if(depth > 100)
{
G4cout<<"G4Integrator<T,F>::AdaptGauss: WARNING !!!"<<G4endl ;
G4cout
<<"Function varies too rapidly to get stated accuracy in 100 steps "<<G4endl ;
G4cout<<"Function varies too rapidly to get stated accuracy in 100 steps "
<<G4endl ;
return ;
}
@@ -251,17 +251,14 @@ void G4Integrator<T,F>::AdaptGauss( G4double (*f)(G4double),
}
}
////////////////////////////////////////////////////////////////////////
//
// Adaptive Gauss integration with accuracy 'e'
// Convenient for using with class object typeT
template<class T, class F> G4double
G4Integrator<T,F>::AdaptiveGauss( T& typeT, F f, G4double xInitial,
G4double xFinal, G4double e )
template<class T, class F>
G4double G4Integrator<T,F>::AdaptiveGauss( T& typeT, F f, G4double xInitial,
G4double xFinal, G4double e )
{
G4int depth = 0 ;
G4double sum = 0.0 ;
@@ -274,9 +271,9 @@ G4Integrator<T,F>::AdaptiveGauss( T& typeT, F f, G4double xInitial,
// Adaptive Gauss integration with accuracy 'e'
// Convenient for using with 'this' pointer
template<class T, class F> G4double
G4Integrator<T,F>::AdaptiveGauss( T* ptrT, F f, G4double xInitial,
G4double xFinal, G4double e )
template<class T, class F>
G4double G4Integrator<T,F>::AdaptiveGauss( T* ptrT, F f, G4double xInitial,
G4double xFinal, G4double e )
{
return AdaptiveGauss(*ptrT,f,xInitial,xFinal,e) ;
}
@@ -286,9 +283,9 @@ G4Integrator<T,F>::AdaptiveGauss( T* ptrT, F f, G4double xInitial,
// Adaptive Gauss integration with accuracy 'e'
// Convenient for using with global scope function f
template <class T, class F> G4double
G4Integrator<T,F>::AdaptiveGauss( G4double (*f)(G4double),
G4double xInitial, G4double xFinal, G4double e )
template <class T, class F>
G4double G4Integrator<T,F>::AdaptiveGauss( G4double (*f)(G4double),
G4double xInitial, G4double xFinal, G4double e )
{
G4int depth = 0 ;
G4double sum = 0.0 ;
@@ -318,8 +315,9 @@ G4Integrator<T,F>::AdaptiveGauss( G4double (*f)(G4double),
// fNumber distinct values of each.
// Convenient for using with some class object dataT
template <class T, class F> G4double
G4Integrator<T,F>::Legendre( T& typeT, F f, G4double a, G4double b, G4int nLegendre)
template <class T, class F>
G4double G4Integrator<T,F>::Legendre( T& typeT, F f, G4double a, G4double b,
G4int nLegendre )
{
G4double newton, newton1, temp1, temp2, temp3, temp ;
G4double xDiff, xMean, dx, integral ;
@@ -330,7 +328,8 @@ G4Integrator<T,F>::Legendre( T& typeT, F f, G4double a, G4double b, G4int nLegen
if(2*fNumber != k)
{
G4Exception("Invalid (odd) n Legendre in G4Integrator<T,F>::Legendre") ;
G4Exception("G4Integrator<T,F>::Legendre(T&,F, ...)", "InvalidCall",
FatalException, "Invalid (odd) nLegendre in constructor.");
}
G4double* fAbscissa = new G4double[fNumber] ;
@@ -359,9 +358,10 @@ G4Integrator<T,F>::Legendre( T& typeT, F f, G4double a, G4double b, G4int nLegen
fAbscissa[fNumber-i] = newton ;
fWeight[fNumber-i] = 2.0/((1.0 - newton*newton)*temp*temp) ;
}
//
// Now we ready to get integral
//
//
// Now we ready to get integral
//
xMean = 0.5*(a + b) ;
xDiff = 0.5*(b - a) ;
@@ -381,8 +381,9 @@ G4Integrator<T,F>::Legendre( T& typeT, F f, G4double a, G4double b, G4int nLegen
//
// Convenient for using with the pointer 'this'
template <class T, class F> G4double
G4Integrator<T,F>::Legendre( T* ptrT, F f, G4double a, G4double b, G4int nLegendre)
template <class T, class F>
G4double G4Integrator<T,F>::Legendre( T* ptrT, F f, G4double a,
G4double b, G4int nLegendre )
{
return Legendre(*ptrT,f,a,b,nLegendre) ;
}
@@ -392,8 +393,8 @@ G4Integrator<T,F>::Legendre( T* ptrT, F f, G4double a, G4double b, G4int nLegend
// Convenient for using with global scope function f
template <class T, class F>
G4double G4Integrator<T,F>::
Legendre( G4double (*f)(G4double), G4double a, G4double b, G4int nLegendre)
G4double G4Integrator<T,F>::Legendre( G4double (*f)(G4double),
G4double a, G4double b, G4int nLegendre)
{
G4double newton, newton1, temp1, temp2, temp3, temp ;
G4double xDiff, xMean, dx, integral ;
@@ -404,7 +405,8 @@ Legendre( G4double (*f)(G4double), G4double a, G4double b, G4int nLegendre)
if(2*fNumber != k)
{
G4Exception("Invalid (odd) n Legendre in G4Integrator<T,F>::Legendre") ;
G4Exception("G4Integrator<T,F>::Legendre(...)", "InvalidCall",
FatalException, "Invalid (odd) nLegendre in constructor.");
}
G4double* fAbscissa = new G4double[fNumber] ;
@@ -433,9 +435,10 @@ Legendre( G4double (*f)(G4double), G4double a, G4double b, G4int nLegendre)
fAbscissa[fNumber-i] = newton ;
fWeight[fNumber-i] = 2.0/((1.0 - newton*newton)*temp*temp) ;
}
//
// Now we ready to get integral
//
//
// Now we ready to get integral
//
xMean = 0.5*(a + b) ;
xDiff = 0.5*(b - a) ;
@@ -460,8 +463,8 @@ Legendre( G4double (*f)(G4double), G4double a, G4double b, G4int nLegendre)
// range of integration, there are actually only five distinct values of each
// Convenient for using with class object typeT
template <class T, class F>
G4double G4Integrator<T,F>::Legendre10( T& typeT, F f,G4double a, G4double b)
template <class T, class F>
G4double G4Integrator<T,F>::Legendre10( T& typeT, F f,G4double a, G4double b)
{
G4int i ;
G4double xDiff, xMean, dx, integral ;
@@ -500,8 +503,9 @@ G4double G4Integrator<T,F>::Legendre10( T* ptrT, F f,G4double a, G4double b)
//
// Convenient for using with global scope functions
template <class T, class F> G4double
G4Integrator<T,F>::Legendre10( G4double (*f)(G4double), G4double a, G4double b)
template <class T, class F>
G4double G4Integrator<T,F>::Legendre10( G4double (*f)(G4double),
G4double a, G4double b )
{
G4int i ;
G4double xDiff, xMean, dx, integral ;
@@ -637,8 +641,9 @@ G4double G4Integrator<T,F>::Legendre96( T* ptrT, F f,G4double a, G4double b)
//
// Convenient for using with global scope function f
template <class T, class F> G4double
G4Integrator<T,F>::Legendre96( G4double (*f)(G4double), G4double a, G4double b)
template <class T, class F>
G4double G4Integrator<T,F>::Legendre96( G4double (*f)(G4double),
G4double a, G4double b )
{
G4int i ;
G4double xDiff, xMean, dx, integral ;
@@ -735,9 +740,9 @@ G4Integrator<T,F>::Legendre96( G4double (*f)(G4double), G4double a, G4double b)
// quadrature method.
// Convenient for using with class object typeT
template <class T, class F> G4double
G4Integrator<T,F>::Chebyshev( T& typeT, F f, G4double a,
G4double b, G4int nChebyshev )
template <class T, class F>
G4double G4Integrator<T,F>::Chebyshev( T& typeT, F f, G4double a,
G4double b, G4int nChebyshev )
{
G4int i ;
G4double xDiff, xMean, dx, integral = 0.0 ;
@@ -751,9 +756,11 @@ G4Integrator<T,F>::Chebyshev( T& typeT, F f, G4double a,
fAbscissa[i] = std::cos(cof*(i + 0.5)) ;
fWeight[i] = cof*std::sqrt(1 - fAbscissa[i]*fAbscissa[i]) ;
}
//
// Now we ready to estimate the integral
//
//
// Now we ready to estimate the integral
//
xMean = 0.5*(a + b) ;
xDiff = 0.5*(b - a) ;
for(i=0;i<fNumber;i++)
@@ -770,8 +777,9 @@ G4Integrator<T,F>::Chebyshev( T& typeT, F f, G4double a,
//
// Convenient for using with 'this' pointer
template <class T, class F> G4double
G4Integrator<T,F>::Chebyshev( T* ptrT, F f, G4double a, G4double b, G4int n)
template <class T, class F>
G4double G4Integrator<T,F>::Chebyshev( T* ptrT, F f, G4double a,
G4double b, G4int n )
{
return Chebyshev(*ptrT,f,a,b,n) ;
}
@@ -780,9 +788,9 @@ G4Integrator<T,F>::Chebyshev( T* ptrT, F f, G4double a, G4double b, G4int n)
//
// For use with global scope functions f
template <class T, class F> G4double
G4Integrator<T,F>::Chebyshev( G4double (*f)(G4double),
G4double a, G4double b, G4int nChebyshev)
template <class T, class F>
G4double G4Integrator<T,F>::Chebyshev( G4double (*f)(G4double),
G4double a, G4double b, G4int nChebyshev )
{
G4int i ;
G4double xDiff, xMean, dx, integral = 0.0 ;
@@ -796,9 +804,11 @@ G4Integrator<T,F>::Chebyshev( G4double (*f)(G4double),
fAbscissa[i] = std::cos(cof*(i + 0.5)) ;
fWeight[i] = cof*std::sqrt(1 - fAbscissa[i]*fAbscissa[i]) ;
}
//
// Now we ready to estimate the integral
//
//
// Now we ready to estimate the integral
//
xMean = 0.5*(a + b) ;
xDiff = 0.5*(b - a) ;
for(i=0;i<fNumber;i++)
@@ -824,8 +834,9 @@ G4Integrator<T,F>::Chebyshev( G4double (*f)(G4double),
// Convenient for using with class object 'typeT' and (typeT.*f) function
// (T::f)
template <class T, class F> G4double
G4Integrator<T,F>::Laguerre( T& typeT, F f, G4double alpha, G4int nLaguerre )
template <class T, class F>
G4double G4Integrator<T,F>::Laguerre( T& typeT, F f, G4double alpha,
G4int nLaguerre )
{
const G4double tolerance = 1.0e-10 ;
const G4int maxNumber = 12 ;
@@ -841,7 +852,8 @@ G4Integrator<T,F>::Laguerre( T& typeT, F f, G4double alpha, G4int nLaguerre )
{
if(i == 1)
{
newton = (1.0 + alpha)*(3.0 + 0.92*alpha)/(1.0 + 2.4*fNumber + 1.8*alpha) ;
newton = (1.0 + alpha)*(3.0 + 0.92*alpha)
/ (1.0 + 2.4*fNumber + 1.8*alpha) ;
}
else if(i == 2)
{
@@ -850,8 +862,9 @@ G4Integrator<T,F>::Laguerre( T& typeT, F f, G4double alpha, G4int nLaguerre )
else
{
cofi = i - 2 ;
newton += ((1.0+2.55*cofi)/(1.9*cofi) + 1.26*cofi*alpha/(1.0+3.5*cofi))*
(newton - fAbscissa[i-3])/(1.0 + 0.3*alpha) ;
newton += ((1.0+2.55*cofi)/(1.9*cofi)
+ 1.26*cofi*alpha/(1.0+3.5*cofi))
* (newton - fAbscissa[i-3])/(1.0 + 0.3*alpha) ;
}
for(k=1;k<=maxNumber;k++)
{
@@ -875,16 +888,19 @@ G4Integrator<T,F>::Laguerre( T& typeT, F f, G4double alpha, G4int nLaguerre )
}
if(k > maxNumber)
{
G4Exception("Too many (>12) iterations in G4Integration::Laguerre") ;
G4Exception("G4Integrator<T,F>::Laguerre(T,F, ...)", "Error",
FatalException, "Too many (>12) iterations.");
}
fAbscissa[i-1] = newton ;
fWeight[i-1] = -std::exp(GammaLogarithm(alpha + fNumber) -
GammaLogarithm((G4double)fNumber))/(temp*fNumber*temp2) ;
}
//
// Integral evaluation
//
//
// Integral evaluation
//
for(i=0;i<fNumber;i++)
{
integral += fWeight[i]*(typeT.*f)(fAbscissa[i]) ;
@@ -912,7 +928,7 @@ G4Integrator<T,F>::Laguerre( T* ptrT, F f, G4double alpha, G4int nLaguerre )
template <class T, class F> G4double
G4Integrator<T,F>::Laguerre( G4double (*f)(G4double),
G4double alpha, G4int nLaguerre)
G4double alpha, G4int nLaguerre )
{
const G4double tolerance = 1.0e-10 ;
const G4int maxNumber = 12 ;
@@ -964,16 +980,19 @@ G4Integrator<T,F>::Laguerre( G4double (*f)(G4double),
}
if(k > maxNumber)
{
G4Exception("Too many (>12) iterations in G4Integration::Laguerre") ;
G4Exception("G4Integrator<T,F>::Laguerre( ...)", "Error",
FatalException, "Too many (>12) iterations.");
}
fAbscissa[i-1] = newton ;
fWeight[i-1] = -std::exp(GammaLogarithm(alpha + fNumber) -
GammaLogarithm((G4double)fNumber))/(temp*fNumber*temp2) ;
}
//
// Integral evaluation
//
//
// Integral evaluation
//
for(i=0;i<fNumber;i++)
{
integral += fWeight[i]*(*f)(fAbscissa[i]) ;
@@ -1023,7 +1042,7 @@ G4double G4Integrator<T,F>::GammaLogarithm(G4double xx)
//
template <class T, class F>
G4double G4Integrator<T,F>::Hermite( T& typeT, F f, G4int nHermite)
G4double G4Integrator<T,F>::Hermite( T& typeT, F f, G4int nHermite )
{
const G4double tolerance = 1.0e-12 ;
const G4int maxNumber = 12 ;
@@ -1084,14 +1103,17 @@ G4double G4Integrator<T,F>::Hermite( T& typeT, F f, G4int nHermite)
}
if(k > maxNumber)
{
G4Exception("Too many (>12) iterations in G4Integrator<T,F>::Hermite") ;
G4Exception("G4Integrator<T,F>::Hermite(T,F, ...)", "Error",
FatalException, "Too many (>12) iterations.");
}
fAbscissa[i-1] = newton ;
fWeight[i-1] = 2.0/(temp*temp) ;
}
//
// Integral calculation
//
//
// Integral calculation
//
for(i=0;i<fNumber;i++)
{
integral += fWeight[i]*( (typeT.*f)(fAbscissa[i]) +
@@ -1108,7 +1130,7 @@ G4double G4Integrator<T,F>::Hermite( T& typeT, F f, G4int nHermite)
// For use with 'this' pointer
template <class T, class F>
G4double G4Integrator<T,F>::Hermite( T* ptrT, F f, G4int n)
G4double G4Integrator<T,F>::Hermite( T* ptrT, F f, G4int n )
{
return Hermite(*ptrT,f,n) ;
}
@@ -1179,14 +1201,17 @@ G4double G4Integrator<T,F>::Hermite( G4double (*f)(G4double), G4int nHermite)
}
if(k > maxNumber)
{
G4Exception("Too many (>12) iterations in G4Integrator<T,F>::Hermite") ;
G4Exception("G4Integrator<T,F>::Hermite(...)", "Error",
FatalException, "Too many (>12) iterations.");
}
fAbscissa[i-1] = newton ;
fWeight[i-1] = 2.0/(temp*temp) ;
}
//
// Integral calculation
//
//
// Integral calculation
//
for(i=0;i<fNumber;i++)
{
integral += fWeight[i]*( (*f)(fAbscissa[i]) + (*f)(-fAbscissa[i]) ) ;
@@ -1208,7 +1233,7 @@ G4double G4Integrator<T,F>::Hermite( G4double (*f)(G4double), G4int nHermite)
template <class T, class F>
G4double G4Integrator<T,F>::Jacobi( T& typeT, F f, G4double alpha,
G4double beta, G4int nJacobi)
G4double beta, G4int nJacobi)
{
const G4double tolerance = 1.0e-12 ;
const G4double maxNumber = 12 ;
@@ -1293,7 +1318,8 @@ G4double G4Integrator<T,F>::Jacobi( T& typeT, F f, G4double alpha,
}
if (k > maxNumber)
{
G4Exception("Too many iterations (>12) in G4Integrator<T,F>::Jacobi") ;
G4Exception("G4Integrator<T,F>::Jacobi(T,F, ...)", "Error",
FatalException, "Too many (>12) iterations.");
}
fAbscissa[i-1] = root ;
fWeight[i-1] = std::exp(GammaLogarithm((G4double)(alpha+nJacobi)) +
@@ -1301,10 +1327,12 @@ G4double G4Integrator<T,F>::Jacobi( T& typeT, F f, G4double alpha,
GammaLogarithm((G4double)(nJacobi+1.0)) -
GammaLogarithm((G4double)(nJacobi + alphaBeta + 1.0)))
*temp*std::pow(2.0,alphaBeta)/(newton*newton2) ;
}
//
// Calculation of the integral
//
}
//
// Calculation of the integral
//
G4double integral = 0.0 ;
for(i=0;i<fNumber;i++)
{
@@ -1333,7 +1361,7 @@ G4double G4Integrator<T,F>::Jacobi( T* ptrT, F f, G4double alpha,
template <class T, class F>
G4double G4Integrator<T,F>::Jacobi( G4double (*f)(G4double), G4double alpha,
G4double beta, G4int nJacobi)
G4double beta, G4int nJacobi)
{
const G4double tolerance = 1.0e-12 ;
const G4double maxNumber = 12 ;
@@ -1418,7 +1446,8 @@ G4double G4Integrator<T,F>::Jacobi( G4double (*f)(G4double), G4double alpha,
}
if (k > maxNumber)
{
G4Exception("Too many iterations (>12) in G4Integrator<T,F>::Jacobi") ;
G4Exception("G4Integrator<T,F>::Jacobi(...)", "Error",
FatalException, "Too many (>12) iterations.");
}
fAbscissa[i-1] = root ;
fWeight[i-1] =
@@ -1427,10 +1456,12 @@ G4double G4Integrator<T,F>::Jacobi( G4double (*f)(G4double), G4double alpha,
GammaLogarithm((G4double)(nJacobi+1.0)) -
GammaLogarithm((G4double)(nJacobi + alphaBeta + 1.0)))
*temp*std::pow(2.0,alphaBeta)/(newton*newton2);
}
//
// Calculation of the integral
//
}
//
// Calculation of the integral
//
G4double integral = 0.0 ;
for(i=0;i<fNumber;i++)
{
@@ -0,0 +1,121 @@
//
// ********************************************************************
// * DISCLAIMER *
// * *
// * The following disclaimer summarizes all the specific disclaimers *
// * of contributors to this software. The specific disclaimers,which *
// * govern, are listed with their locations in: *
// * http://cern.ch/geant4/license *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. *
// * *
// * This code implementation is the intellectual property of the *
// * GEANT4 collaboration. *
// * By copying, distributing or modifying the Program (or any work *
// * based on the Program) you indicate your acceptance of this *
// * statement, and all its terms. *
// ********************************************************************
//
//
// $Id: G4JTPolynomialSolver.hh,v 1.5 2005/03/21 18:27:40 gcosmo Exp $
// GEANT4 tag $Name: geant4-07-01 $
//
// Class description:
//
// G4JTPolynomialSolver implements the Jenkins-Traub algorithm
// for real polynomial root finding.
// The solver returns -1, if the leading coefficient is zero,
// the number of roots found, otherwise.
//
// ----------------------------- INPUT --------------------------------
//
// op - double precision vector of coefficients in order of
// decreasing powers
// degree - integer degree of polynomial
//
// ----------------------------- OUTPUT -------------------------------
//
// zeror,zeroi - double precision vectors of the
// real and imaginary parts of the zeros
//
// ---------------------------- EXAMPLE -------------------------------
//
// G4JTPolynomialSolver trapEq ;
// G4double coef[8] ;
// G4double zr[7] , zi[7] ;
// G4int num = trapEq.FindRoots(coef,7,zr,zi);
// ---------------------------- HISTORY -------------------------------
//
// Translated from original TOMS493 Fortran77 routine (ANSI C, by C.Bond).
// Translated to C++ and adapted to use STL vectors,
// by Oliver Link (Oliver.Link@cern.ch)
//
// --------------------------------------------------------------------
#ifndef G4JTPOLYNOMIALSOLVER_HH
#define G4JTPOLYNOMIALSOLVER_HH
#include <cmath>
#include <vector>
#include "globals.hh"
class G4JTPolynomialSolver
{
public:
G4JTPolynomialSolver();
~G4JTPolynomialSolver();
G4int FindRoots(G4double *op, G4int degree,
G4double *zeror, G4double *zeroi);
private:
std::vector<G4double> p;
std::vector<G4double> qp;
std::vector<G4double> k;
std::vector<G4double> qk;
std::vector<G4double> svk;
G4double sr;
G4double si;
G4double u,v;
G4double a,b,c,d;
G4double a1,a2,a3,a6,a7;
G4double e,f,g,h;
G4double szr,szi;
G4double lzr,lzi;
G4int n,nmi;
/* The following statements set machine constants */
static const G4double base;
static const G4double eta;
static const G4double infin;
static const G4double smalno;
static const G4double are;
static const G4double mre;
static const G4double lo;
void Quadratic(G4double a,G4double b1,G4double c,
G4double *sr,G4double *si, G4double *lr,G4double *li);
void ComputeFixedShiftPolynomial(G4int l2, G4int *nz);
void QuadraticPolynomialIteration(G4double *uu,G4double *vv,G4int *nz);
void RealPolynomialIteration(G4double *sss, G4int *nz, G4int *iflag);
void ComputeScalarFactors(G4int *type);
void ComputeNextPolynomial(G4int *type);
void ComputeNewEstimate(G4int type,G4double *uu,G4double *vv);
void QuadraticSyntheticDivision(G4int n, G4double *u, G4double *v,
std::vector<G4double> &p,
std::vector<G4double> &q,
G4double *a, G4double *b);
};
#endif
@@ -22,7 +22,7 @@
//
//
// $Id: G4PolynomialSolver.hh,v 1.3 2001/07/11 10:00:40 gunter Exp $
// GEANT4 tag $Name: geant4-07-00-cand-01 $
// GEANT4 tag $Name: geant4-07-01 $
//
// class G4PolynomialSolver
//
@@ -22,7 +22,7 @@
//
//
// $Id: G4PolynomialSolver.icc,v 1.7 2004/11/12 17:38:29 gcosmo Exp $
// GEANT4 tag $Name: geant4-07-00-cand-03 $
// GEANT4 tag $Name: geant4-07-01 $
//
// class G4PolynomialSolver
//
@@ -21,34 +21,34 @@
// ********************************************************************
//
//
// $Id: G4SimpleIntegration.hh,v 1.4 2004/11/12 16:25:33 gcosmo Exp $
// GEANT4 tag $Name: geant4-07-00-cand-03 $
// $Id: G4SimpleIntegration.hh,v 1.5 2005/03/15 19:11:35 gcosmo Exp $
// GEANT4 tag $Name: geant4-07-01 $
//
// Class description:
//
// Class for realisation of simple numerical methodes for integration of functions
// with signature: double f(double). The methods based mainly on algorithms given in
// the book : An introduction to NUMERICAL METHODS IN C++, B.H. Flowers, Claredon
// Press, Oxford, 1995
// Class for realisation of simple numerical methodes for integration of
// functions with signature: double f(double). The methods based mainly on
// algorithms given in the book :
// An introduction to NUMERICAL METHODS IN C++,
// B.H. Flowers, Claredon Press, Oxford, 1995.
//
// --------------------------- Member data: -------------------------------------
// --------------------------- Member data ----------------------------
//
// fFunction - pointer to the function to be integrated
// fTolerance - accuracy of integration in Adaptive Gauss method
// fMaxDepth = 100 - constant maximum iteration depth for
// Adaptive Gauss method
// fFunction - pointer to the function to be integrated
// fTolerance - accuracy of integration in Adaptive Gauss method
// fMaxDepth = 100 - constant maximum iteration depth for
// Adaptive Gauss method
//
// --------------------------- Methods: -----------------------------------------
// --------------------------- Methods --------------------------------
//
// Trapezoidal, MidPoint, Gauss,
// and Simpson(double a,double b,int n) - integrate function pointed
// by fFunction from a to b by n iterations, i.e. with Step (b-a)/n
// according to the correspondent method
// Trapezoidal, MidPoint, Gauss and Simpson(double a,double b,int n)
// - integrate function pointed by fFunction from a to b by n iterations,
// i.e. with Step (b-a)/n according to the correspondent method.
//
// AdaptGausIntegration(double a, double b) - integrate function from a to be with
// accuracy <= fTolerance
// AdaptGausIntegration(double a, double b)
// - integrate function from a to be with accuracy <= fTolerance
// ----------------------------- History: ----------------------------------------
// ----------------------------- History ------------------------------
//
// 26.03.97 V.Grichine ( Vladimir.Grichine@cern.ch )
@@ -61,8 +61,9 @@ typedef G4double (*function)(G4double) ;
class G4SimpleIntegration
{
public:
G4SimpleIntegration( function pFunction ) ;
public:
explicit G4SimpleIntegration( function pFunction ) ;
G4SimpleIntegration( function pFunction,
G4double pTolerance ) ;
@@ -73,40 +74,45 @@ public:
G4double Trapezoidal(G4double xInitial,
G4double xFinal,
G4int iterationNumber ) ;
G4int iterationNumber ) ;
G4double MidPoint(G4double xInitial,
G4double xFinal,
G4int iterationNumber ) ;
G4int iterationNumber ) ;
G4double Gauss(G4double xInitial,
G4double xFinal,
G4int iterationNumber ) ;
G4int iterationNumber ) ;
G4double Simpson(G4double xInitial,
G4double xFinal,
G4int iterationNumber ) ;
G4int iterationNumber ) ;
// Adaptive Gauss integration with accuracy ~ fTolerance
G4double AdaptGaussIntegration( G4double xInitial,
G4double xFinal ) ;
protected:
protected:
G4double Gauss( G4double xInitial,
G4double xFinal ) ;
void AdaptGauss( G4double xInitial,
G4double xFinal,
G4double& sum,
G4int& depth ) ;
G4double& sum,
G4int& depth ) ;
private:
private:
G4SimpleIntegration(const G4SimpleIntegration&);
G4SimpleIntegration& operator=(const G4SimpleIntegration&);
// Private copy constructor and assignment operator.
private:
function fFunction ;
G4double fTolerance ;
static G4int fMaxDepth ;
} ;
G4double fTolerance ;
static G4int fMaxDepth ;
};
#endif
@@ -21,8 +21,8 @@
// ********************************************************************
//
//
// $Id: G4VGaussianQuadrature.hh,v 1.5 2004/11/12 17:38:29 gcosmo Exp $
// GEANT4 tag $Name: geant4-07-00-cand-03 $
// $Id: G4VGaussianQuadrature.hh,v 1.6 2005/03/15 19:11:35 gcosmo Exp $
// GEANT4 tag $Name: geant4-07-01 $
//
// Class description:
//
@@ -63,46 +63,34 @@ typedef G4double (*function)(G4double) ;
class G4VGaussianQuadrature
{
public:
// Base constructor
public:
G4VGaussianQuadrature( function pFunction ) ;
// Virtual destructor
virtual ~G4VGaussianQuadrature() ;
// Access functions:
G4double GetAbscissa(G4int index) const ;
explicit G4VGaussianQuadrature( function pFunction ) ;
// Base constructor
G4double GetWeight(G4int index) const ;
G4int GetNumber() const { return fNumber ; }
// Methods:
// virtual G4double DefiniteIntegral( G4double a,
// G4double b ) const = 0 ;
// virtual G4double Integral() const = 0 ;
protected:
G4double GammaLogarithm(G4double xx) ;
virtual ~G4VGaussianQuadrature() ;
// Virtual destructor
// Data members common for GaussianQuadrature family
function fFunction ;
G4double* fAbscissa ;
G4double* fWeight ;
G4int fNumber ;
private:
G4double GetAbscissa(G4int index) const ;
G4double GetWeight(G4int index) const ;
G4int GetNumber() const;
// Access functions
G4VGaussianQuadrature(const G4VGaussianQuadrature&);
G4VGaussianQuadrature& operator=(const G4VGaussianQuadrature&);
protected:
G4double GammaLogarithm(G4double xx) ;
// Data members common for GaussianQuadrature family
//
function fFunction ;
G4double* fAbscissa ;
G4double* fWeight ;
G4int fNumber ;
private:
G4VGaussianQuadrature(const G4VGaussianQuadrature&);
G4VGaussianQuadrature& operator=(const G4VGaussianQuadrature&);
};
#endif