Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/global/HEPNumerics/include/G4Integrator.icc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /global/HEPNumerics/include/G4Integrator.icc (Version 11.3.0) and /global/HEPNumerics/include/G4Integrator.icc (Version 2.0)


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