ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4GaussJacobiQ.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4GaussJacobiQ.cc
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 //
28 #include "G4GaussJacobiQ.hh"
29 
30 
31 // -------------------------------------------------------------
32 //
33 // Constructor for Gauss-Jacobi integration method.
34 //
35 
36 G4GaussJacobiQ::G4GaussJacobiQ( function pFunction,
38  G4double beta,
39  G4int nJacobi )
40  : G4VGaussianQuadrature(pFunction)
41 
42 {
43  const G4double tolerance = 1.0e-12 ;
44  const G4double maxNumber = 12 ;
45  G4int i=1, k=1 ;
46  G4double root=0.;
47  G4double alphaBeta=0.0, alphaReduced=0.0, betaReduced=0.0,
48  root1=0.0, root2=0.0, root3=0.0 ;
49  G4double a=0.0, b=0.0, c=0.0,
50  newton1=0.0, newton2=0.0, newton3=0.0, newton0=0.0,
51  temp=0.0, rootTemp=0.0 ;
52 
53  fNumber = nJacobi ;
54  fAbscissa = new G4double[fNumber] ;
55  fWeight = new G4double[fNumber] ;
56 
57  for (i=1;i<=nJacobi;i++)
58  {
59  if (i == 1)
60  {
61  alphaReduced = alpha/nJacobi ;
62  betaReduced = beta/nJacobi ;
63  root1 = (1.0+alpha)*(2.78002/(4.0+nJacobi*nJacobi)+
64  0.767999*alphaReduced/nJacobi) ;
65  root2 = 1.0+1.48*alphaReduced+0.96002*betaReduced
66  + 0.451998*alphaReduced*alphaReduced
67  + 0.83001*alphaReduced*betaReduced ;
68  root = 1.0-root1/root2 ;
69  }
70  else if (i == 2)
71  {
72  root1=(4.1002+alpha)/((1.0+alpha)*(1.0+0.155998*alpha)) ;
73  root2=1.0+0.06*(nJacobi-8.0)*(1.0+0.12*alpha)/nJacobi ;
74  root3=1.0+0.012002*beta*(1.0+0.24997*std::fabs(alpha))/nJacobi ;
75  root -= (1.0-root)*root1*root2*root3 ;
76  }
77  else if (i == 3)
78  {
79  root1=(1.67001+0.27998*alpha)/(1.0+0.37002*alpha) ;
80  root2=1.0+0.22*(nJacobi-8.0)/nJacobi ;
81  root3=1.0+8.0*beta/((6.28001+beta)*nJacobi*nJacobi) ;
82  root -= (fAbscissa[0]-root)*root1*root2*root3 ;
83  }
84  else if (i == nJacobi-1)
85  {
86  root1=(1.0+0.235002*beta)/(0.766001+0.118998*beta) ;
87  root2=1.0/(1.0+0.639002*(nJacobi-4.0)/(1.0+0.71001*(nJacobi-4.0))) ;
88  root3=1.0/(1.0+20.0*alpha/((7.5+alpha)*nJacobi*nJacobi)) ;
89  root += (root-fAbscissa[nJacobi-4])*root1*root2*root3 ;
90  }
91  else if (i == nJacobi)
92  {
93  root1 = (1.0+0.37002*beta)/(1.67001+0.27998*beta) ;
94  root2 = 1.0/(1.0+0.22*(nJacobi-8.0)/nJacobi) ;
95  root3 = 1.0/(1.0+8.0*alpha/((6.28002+alpha)*nJacobi*nJacobi)) ;
96  root += (root-fAbscissa[nJacobi-3])*root1*root2*root3 ;
97  }
98  else
99  {
100  root = 3.0*fAbscissa[i-2]-3.0*fAbscissa[i-3]+fAbscissa[i-4] ;
101  }
102  alphaBeta = alpha + beta ;
103  for (k=1;k<=maxNumber;k++)
104  {
105  temp = 2.0 + alphaBeta ;
106  newton1 = (alpha-beta+temp*root)/2.0 ;
107  newton2 = 1.0 ;
108  for (G4int j=2;j<=nJacobi;j++)
109  {
110  newton3 = newton2 ;
111  newton2 = newton1 ;
112  temp = 2*j+alphaBeta ;
113  a = 2*j*(j+alphaBeta)*(temp-2.0) ;
114  b = (temp-1.0)*(alpha*alpha-beta*beta+temp*(temp-2.0)*root) ;
115  c = 2.0*(j-1+alpha)*(j-1+beta)*temp ;
116  newton1 = (b*newton2-c*newton3)/a ;
117  }
118  newton0 = (nJacobi*(alpha - beta - temp*root)*newton1 +
119  2.0*(nJacobi + alpha)*(nJacobi + beta)*newton2)/
120  (temp*(1.0 - root*root)) ;
121  rootTemp = root ;
122  root = rootTemp - newton1/newton0 ;
123  if (std::fabs(root-rootTemp) <= tolerance)
124  {
125  break ;
126  }
127  }
128  if (k > maxNumber)
129  {
130  G4Exception("G4GaussJacobiQ::G4GaussJacobiQ()", "OutOfRange",
131  FatalException, "Too many iterations in constructor.") ;
132  }
133  fAbscissa[i-1] = root ;
134  fWeight[i-1] = std::exp(GammaLogarithm((G4double)(alpha+nJacobi)) +
135  GammaLogarithm((G4double)(beta+nJacobi)) -
136  GammaLogarithm((G4double)(nJacobi+1.0)) -
137  GammaLogarithm((G4double)(nJacobi + alphaBeta + 1.0)))
138  *temp*std::pow(2.0,alphaBeta)/(newton0*newton2) ;
139  }
140 }
141 
142 
143 // ----------------------------------------------------------
144 //
145 // Gauss-Jacobi method for integration of
146 // ((1-x)^alpha)*((1+x)^beta)*pFunction(x)
147 // from minus unit to plus unit .
148 
149 
150 G4double
152 {
153  G4double integral = 0.0 ;
154  for(G4int i=0;i<fNumber;i++)
155  {
156  integral += fWeight[i]*fFunction(fAbscissa[i]) ;
157  }
158  return integral ;
159 }
160