Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/global/HEPNumerics/src/G4AnalyticalPolSolver.cc

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/src/G4AnalyticalPolSolver.cc (Version 11.3.0) and /global/HEPNumerics/src/G4AnalyticalPolSolver.cc (Version 10.5)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // G4AnalyticalPolSolver class implementation  << 
 27 //                                                 26 //
 28 // Author: V.Grichine, 24.04.97                <<  27 //
 29 // ------------------------------------------- << 
 30                                                    28 
 31 #include "globals.hh"                          <<  29 #include  "globals.hh"
 32 #include <complex>                             <<  30 #include  <complex>
 33                                                    31 
 34 #include "G4AnalyticalPolSolver.hh"                32 #include "G4AnalyticalPolSolver.hh"
 35                                                    33 
 36 //////////////////////////////////////////////     34 //////////////////////////////////////////////////////////////////////////////
 37                                                    35 
 38 G4AnalyticalPolSolver::G4AnalyticalPolSolver() <<  36 G4AnalyticalPolSolver::G4AnalyticalPolSolver() {;}
 39                                                    37 
 40 //////////////////////////////////////////////     38 //////////////////////////////////////////////////////////////////////////////
 41                                                    39 
 42 G4AnalyticalPolSolver::~G4AnalyticalPolSolver( <<  40 G4AnalyticalPolSolver::~G4AnalyticalPolSolver() {;}
 43                                                    41 
 44 //////////////////////////////////////////////     42 //////////////////////////////////////////////////////////////////////////////
 45 //                                                 43 //
 46 // Array r[3][5]  p[5]                             44 // Array r[3][5]  p[5]
 47 // Roots of poly p[0] x^2 + p[1] x+p[2]=0          45 // Roots of poly p[0] x^2 + p[1] x+p[2]=0
 48 //                                                 46 //
 49 // x = r[1][k] + i r[2][k];  k = 1, 2              47 // x = r[1][k] + i r[2][k];  k = 1, 2
 50                                                    48 
 51 G4int G4AnalyticalPolSolver::QuadRoots(G4doubl <<  49 G4int G4AnalyticalPolSolver::QuadRoots( G4double p[5], G4double r[3][5] )
 52 {                                                  50 {
 53   G4double b, c, d2, d;                            51   G4double b, c, d2, d;
 54                                                    52 
 55   b  = -p[1] / p[0] / 2.;                      <<  53   b  = -p[1]/p[0]/2.;
 56   c  = p[2] / p[0];                            <<  54   c  =  p[2]/p[0];
 57   d2 = b * b - c;                              <<  55   d2 =  b*b - c;
 58                                                <<  56   
 59   if(d2 >= 0.)                                 <<  57   if( d2 >= 0. )
 60   {                                                58   {
 61     d       = std::sqrt(d2);                       59     d       = std::sqrt(d2);
 62     r[1][1] = b - d;                           <<  60     r[1][1] = b - d;   
 63     r[1][2] = b + d;                           <<  61     r[1][2] = b + d;   
 64     r[2][1] = 0.;                              <<  62     r[2][1] = 0.; 
 65     r[2][2] = 0.;                                  63     r[2][2] = 0.;
 66   }                                                64   }
 67   else                                             65   else
 68   {                                                66   {
 69     d       = std::sqrt(-d2);                      67     d       = std::sqrt(-d2);
 70     r[2][1] = d;                               <<  68     r[2][1] =  d; 
 71     r[2][2] = -d;                                  69     r[2][2] = -d;
 72     r[1][1] = b;                               <<  70     r[1][1] =  b; 
 73     r[1][2] = b;                               <<  71     r[1][2] =  b;
 74   }                                                72   }
 75                                                    73 
 76   return 2;                                        74   return 2;
 77 }                                                  75 }
 78                                                    76 
 79 //////////////////////////////////////////////     77 //////////////////////////////////////////////////////////////////////////////
 80 //                                                 78 //
 81 // Array r[3][5]  p[5]                             79 // Array r[3][5]  p[5]
 82 // Roots of poly p[0] x^3 + p[1] x^2...+p[3]=0     80 // Roots of poly p[0] x^3 + p[1] x^2...+p[3]=0
 83 // x=r[1][k] + i r[2][k]  k=1,...,3                81 // x=r[1][k] + i r[2][k]  k=1,...,3
 84 // Assumes 0<arctan(x)<pi/2 for x>0                82 // Assumes 0<arctan(x)<pi/2 for x>0
 85                                                    83 
 86 G4int G4AnalyticalPolSolver::CubicRoots(G4doub <<  84 G4int G4AnalyticalPolSolver::CubicRoots( G4double p[5], G4double r[3][5] )
 87 {                                                  85 {
 88   G4double x, t, b, c, d;                      <<  86   G4double x,t,b,c,d;
 89   G4int k;                                         87   G4int k;
 90                                                    88 
 91   if(p[0] != 1.)                               <<  89   if( p[0] != 1. )
 92   {                                                90   {
 93     for(k = 1; k < 4; k++)                     <<  91     for(k = 1; k < 4; k++ ) { p[k] = p[k]/p[0]; }
 94     {                                          << 
 95       p[k] = p[k] / p[0];                      << 
 96     }                                          << 
 97     p[0] = 1.;                                     92     p[0] = 1.;
 98   }                                                93   }
 99   x = p[1] / 3.0;                              <<  94   x = p[1]/3.0; 
100   t = x * p[1];                                <<  95   t = x*p[1];
101   b = 0.5 * (x * (t / 1.5 - p[2]) + p[3]);     <<  96   b = 0.5*( x*( t/1.5 - p[2] ) + p[3] ); 
102   t = (t - p[2]) / 3.0;                        <<  97   t = ( t - p[2] )/3.0;
103   c = t * t * t;                               <<  98   c = t*t*t; 
104   d = b * b - c;                               <<  99   d = b*b - c;
105                                                   100 
106   if(d >= 0.)                                  << 101   if( d >= 0. )
107   {                                               102   {
108     d = std::pow((std::sqrt(d) + std::fabs(b)) << 103     d = std::pow( (std::sqrt(d) + std::fabs(b) ), 1.0/3.0 );
109                                                << 104     
110     if(d != 0.)                                << 105     if( d != 0. )
111     {                                             106     {
112       if(b > 0.)                               << 107        if( b > 0. ) { b = -d; }
113       {                                        << 108        else         { b =  d; }
114         b = -d;                                << 109        c =  t/b;
115       }                                        << 
116       else                                     << 
117       {                                        << 
118         b = d;                                 << 
119       }                                        << 
120       c = t / b;                               << 
121     }                                             110     }
122     d       = std::sqrt(0.75) * (b - c);       << 111     d       =  std::sqrt(0.75)*(b - c); 
123     r[2][2] = d;                               << 112     r[2][2] =  d; 
124     b       = b + c;                           << 113     b       =  b + c;
125     c       = -0.5 * b - x;                    << 114     c       = -0.5*b-x;
126     r[1][2] = c;                               << 115     r[1][2] =  c;
127                                                << 116 
128     if((b > 0. && x <= 0.) || (b < 0. && x > 0 << 117     if( ( b > 0. &&  x <= 0. ) || ( b < 0. && x > 0. ) )
129     {                                          << 118     {
130       r[1][1] = c;                             << 119        r[1][1] =  c; 
131       r[2][1] = -d;                            << 120        r[2][1] = -d; 
132       r[1][3] = b - x;                         << 121        r[1][3] =  b - x;
133       r[2][3] = 0;                             << 122        r[2][3] =  0;
134     }                                             123     }
135     else                                          124     else
136     {                                             125     {
137       r[1][1] = b - x;                         << 126        r[1][1] =  b - x; 
138       r[2][1] = 0.;                            << 127        r[2][1] =  0.; 
139       r[1][3] = c;                             << 128        r[1][3] =  c;
140       r[2][3] = -d;                            << 129        r[2][3] = -d;
141     }                                             130     }
142   }  // end of 2 equal or complex roots        << 131   }              // end of 2 equal or complex roots 
143   else                                            132   else
144   {                                               133   {
145     if(b == 0.)                                << 134     if( b == 0. ) { d =  std::atan(1.0)/1.5; }
146     {                                          << 135     else          { d =  std::atan( std::sqrt(-d)/std::fabs(b) )/3.0; }
147       d = std::atan(1.0) / 1.5;                << 
148     }                                          << 
149     else                                       << 
150     {                                          << 
151       d = std::atan(std::sqrt(-d) / std::fabs( << 
152     }                                          << 
153                                                   136 
154     if(b < 0.)                                 << 137     if( b < 0. )  { b =  std::sqrt(t)*2.0; }
155     {                                          << 138     else          { b = -2.0*std::sqrt(t); }
156       b = std::sqrt(t) * 2.0;                  << 
157     }                                          << 
158     else                                       << 
159     {                                          << 
160       b = -2.0 * std::sqrt(t);                 << 
161     }                                          << 
162                                                   139 
163     c = std::cos(d) * b;                       << 140     c =  std::cos(d)*b; 
164     t = -std::sqrt(0.75) * std::sin(d) * b - 0 << 141     t = -std::sqrt(0.75)*std::sin(d)*b - 0.5*c;
165     d = -t - c - x;                            << 142     d = -t - c - x; 
166     c = c - x;                                 << 143     c =  c - x; 
167     t = t - x;                                 << 144     t =  t - x;
168                                                   145 
169     if(std::fabs(c) > std::fabs(t))            << 146     if( std::fabs(c) > std::fabs(t) ) { r[1][3] = c; }
170     {                                          << 
171       r[1][3] = c;                             << 
172     }                                          << 
173     else                                          147     else
174     {                                             148     {
175       r[1][3] = t;                             << 149       r[1][3] = t; 
176       t       = c;                                150       t       = c;
177     }                                             151     }
178     if(std::fabs(d) > std::fabs(t))            << 152     if( std::fabs(d) > std::fabs(t) ) { r[1][2] = d; }
179     {                                          << 
180       r[1][2] = d;                             << 
181     }                                          << 
182     else                                          153     else
183     {                                             154     {
184       r[1][2] = t;                             << 155       r[1][2] = t; 
185       t       = d;                                156       t       = d;
186     }                                             157     }
187     r[1][1] = t;                                  158     r[1][1] = t;
188                                                   159 
189     for(k = 1; k < 4; k++)                     << 160     for(k = 1; k < 4; k++ ) { r[2][k] = 0.; }
190     {                                          << 
191       r[2][k] = 0.;                            << 
192     }                                          << 
193   }                                               161   }
194   return 0;                                       162   return 0;
195 }                                                 163 }
196                                                   164 
197 //////////////////////////////////////////////    165 //////////////////////////////////////////////////////////////////////////////
198 //                                                166 //
199 // Array r[3][5]  p[5]                            167 // Array r[3][5]  p[5]
200 // Roots of poly p[0] x^4 + p[1] x^3...+p[4]=0    168 // Roots of poly p[0] x^4 + p[1] x^3...+p[4]=0
201 // x=r[1][k] + i r[2][k]  k=1,...,4               169 // x=r[1][k] + i r[2][k]  k=1,...,4
202                                                   170 
203 G4int G4AnalyticalPolSolver::BiquadRoots(G4dou << 171 G4int G4AnalyticalPolSolver::BiquadRoots( G4double p[5], G4double r[3][5] )
204 {                                                 172 {
205   G4double a, b, c, d, e;                         173   G4double a, b, c, d, e;
206   G4int i, k, j;                                  174   G4int i, k, j;
207                                                   175 
208   if(p[0] != 1.0)                                 176   if(p[0] != 1.0)
209   {                                               177   {
210     for(k = 1; k < 5; k++)                     << 178     for( k = 1; k < 5; k++) { p[k] = p[k]/p[0]; }
211     {                                          << 
212       p[k] = p[k] / p[0];                      << 
213     }                                          << 
214     p[0] = 1.;                                    179     p[0] = 1.;
215   }                                               180   }
216   e = 0.25 * p[1];                             << 181   e = 0.25*p[1];
217   b = 2 * e;                                   << 182   b = 2*e;
218   c = b * b;                                   << 183   c = b*b;
219   d = 0.75 * c;                                << 184   d = 0.75*c;
220   b = p[3] + b * (c - p[2]);                   << 185   b = p[3] + b*( c - p[2] );
221   a = p[2] - d;                                   186   a = p[2] - d;
222   c = p[4] + e * (e * a - p[3]);               << 187   c = p[4] + e*( e*a - p[3] );
223   a = a - d;                                      188   a = a - d;
224                                                   189 
225   p[1] = 0.5 * a;                              << 190   p[1] = 0.5*a;
226   p[2] = (p[1] * p[1] - c) * 0.25;             << 191   p[2] = (p[1]*p[1]-c)*0.25;
227   p[3] = b * b / (-64.0);                      << 192   p[3] = b*b/(-64.0);
228                                                   193 
229   if(p[3] < 0.)                                << 194   if( p[3] < 0. )
230   {                                               195   {
231     CubicRoots(p, r);                          << 196     CubicRoots(p,r);
232                                                   197 
233     for(k = 1; k < 4; k++)                     << 198     for( k = 1; k < 4; k++ )
234     {                                             199     {
235       if(r[2][k] == 0. && r[1][k] > 0)         << 200       if( r[2][k] == 0. && r[1][k] > 0 )
236       {                                           201       {
237         d = r[1][k] * 4;                       << 202         d = r[1][k]*4; 
238         a = a + d;                                203         a = a + d;
239                                                   204 
240         if(a >= 0. && b >= 0.)                 << 205         if     ( a >= 0. && b >= 0.) { p[1] =  std::sqrt(d); }
241         {                                      << 206         else if( a <= 0. && b <= 0.) { p[1] =  std::sqrt(d); }
242           p[1] = std::sqrt(d);                 << 207         else                         { p[1] = -std::sqrt(d); }
243         }                                      << 
244         else if(a <= 0. && b <= 0.)            << 
245         {                                      << 
246           p[1] = std::sqrt(d);                 << 
247         }                                      << 
248         else                                   << 
249         {                                      << 
250           p[1] = -std::sqrt(d);                << 
251         }                                      << 
252                                                   208 
253         b = 0.5 * (a + b / p[1]);              << 209         b = 0.5*( a + b/p[1] );
254                                                   210 
255         p[2] = c / b;                          << 211         p[2]    = c/b; 
256         QuadRoots(p, r);                       << 212         QuadRoots(p,r);
257                                                   213 
258         for(i = 1; i < 3; i++)                 << 214         for( i = 1; i < 3; i++ )
259         {                                         215         {
260           for(j = 1; j < 3; j++)               << 216           for( j = 1; j < 3; j++ ) { r[j][i+2] = r[j][i]; }
261           {                                    << 
262             r[j][i + 2] = r[j][i];             << 
263           }                                    << 
264         }                                         217         }
265         p[1] = -p[1];                          << 218         p[1]    = -p[1]; 
266         p[2] = b;                              << 219         p[2]    =  b; 
267         QuadRoots(p, r);                       << 220         QuadRoots(p,r);
268                                                   221 
269         for(i = 1; i < 5; i++)                 << 222         for( i = 1; i < 5; i++ ) { r[1][i] = r[1][i] - e; }
270         {                                      << 
271           r[1][i] = r[1][i] - e;               << 
272         }                                      << 
273                                                   223 
274         return 4;                                 224         return 4;
275       }                                           225       }
276     }                                             226     }
277   }                                               227   }
278   if(p[2] < 0.)                                << 228   if( p[2] < 0. )
279   {                                               229   {
280     b    = std::sqrt(c);                       << 230     b    = std::sqrt(c); 
281     d    = b + b - a;                             231     d    = b + b - a;
282     p[1] = 0.;                                 << 232     p[1] = 0.; 
283                                                << 233     
284     if(d > 0.)                                 << 234     if( d > 0. ) { p[1] = std::sqrt(d); }
285     {                                          << 
286       p[1] = std::sqrt(d);                     << 
287     }                                          << 
288   }                                               235   }
289   else                                            236   else
290   {                                               237   {
291     if(p[1] > 0.)                              << 238     if( p[1] > 0.) { b =  std::sqrt(p[2])*2.0 + p[1]; }
292     {                                          << 239     else           { b = -std::sqrt(p[2])*2.0 + p[1]; }
293       b = std::sqrt(p[2]) * 2.0 + p[1];        << 
294     }                                          << 
295     else                                       << 
296     {                                          << 
297       b = -std::sqrt(p[2]) * 2.0 + p[1];       << 
298     }                                          << 
299                                                   240 
300     if(b != 0.)                                << 241     if( b != 0.) { p[1] = 0; }
301     {                                          << 
302       p[1] = 0;                                << 
303     }                                          << 
304     else                                          242     else
305     {                                             243     {
306       for(k = 1; k < 5; k++)                   << 244       for(k = 1; k < 5; k++ )
307       {                                           245       {
308         r[1][k] = -e;                          << 246           r[1][k] = -e;
309         r[2][k] = 0;                           << 247           r[2][k] =  0;
310       }                                           248       }
311       return 0;                                   249       return 0;
312     }                                             250     }
313   }                                               251   }
314                                                   252 
315   p[2] = c / b;                                << 253   p[2]    = c/b; 
316   QuadRoots(p, r);                             << 254   QuadRoots(p,r);
317                                                   255 
318   for(k = 1; k < 3; k++)                       << 256   for( k = 1; k < 3; k++ )
319   {                                               257   {
320     for(j = 1; j < 3; j++)                     << 258     for( j = 1; j < 3; j++ ) { r[j][k+2] = r[j][k]; }
321     {                                          << 
322       r[j][k + 2] = r[j][k];                   << 
323     }                                          << 
324   }                                               259   }
325   p[1] = -p[1];                                << 260   p[1]    = -p[1]; 
326   p[2] = b;                                    << 261   p[2]    =  b; 
327   QuadRoots(p, r);                             << 262   QuadRoots(p,r);
328                                                   263 
329   for(k = 1; k < 5; k++)                       << 264   for( k = 1; k < 5; k++ ) { r[1][k] = r[1][k] - e; }
330   {                                            << 
331     r[1][k] = r[1][k] - e;                     << 
332   }                                            << 
333                                                   265 
334   return 4;                                       266   return 4;
335 }                                                 267 }
336                                                   268 
337 //////////////////////////////////////////////    269 //////////////////////////////////////////////////////////////////////////////
338                                                   270 
339 G4int G4AnalyticalPolSolver::QuarticRoots(G4do << 271 G4int G4AnalyticalPolSolver::QuarticRoots( G4double p[5], G4double r[3][5])
340 {                                                 272 {
341   G4double a0, a1, a2, a3, y1;                    273   G4double a0, a1, a2, a3, y1;
342   G4double R2, D2, E2, D, E, R = 0.;              274   G4double R2, D2, E2, D, E, R = 0.;
343   G4double a, b, c, d, ds;                        275   G4double a, b, c, d, ds;
344                                                   276 
345   G4double reRoot[4];                             277   G4double reRoot[4];
346   G4int k;                                     << 278   G4int k, noReRoots = 0;
                                                   >> 279   
                                                   >> 280   for( k = 0; k < 4; k++ ) { reRoot[k] = DBL_MAX; }
347                                                   281 
348   for(k = 0; k < 4; k++)                       << 282   if( p[0] != 1.0 )
349   {                                            << 
350     reRoot[k] = DBL_MAX;                       << 
351   }                                            << 
352                                                << 
353   if(p[0] != 1.0)                              << 
354   {                                               283   {
355     for(k = 1; k < 5; k++)                     << 284     for( k = 1; k < 5; k++) { p[k] = p[k]/p[0]; }
356     {                                          << 
357       p[k] = p[k] / p[0];                      << 
358     }                                          << 
359     p[0] = 1.;                                    285     p[0] = 1.;
360   }                                               286   }
361   a3 = p[1];                                      287   a3 = p[1];
362   a2 = p[2];                                      288   a2 = p[2];
363   a1 = p[3];                                      289   a1 = p[3];
364   a0 = p[4];                                      290   a0 = p[4];
365                                                   291 
366   // resolvent cubic equation cofs:               292   // resolvent cubic equation cofs:
367                                                   293 
368   p[1] = -a2;                                     294   p[1] = -a2;
369   p[2] = a1 * a3 - 4 * a0;                     << 295   p[2] = a1*a3 - 4*a0;
370   p[3] = 4 * a2 * a0 - a1 * a1 - a3 * a3 * a0; << 296   p[3] = 4*a2*a0 - a1*a1 - a3*a3*a0;
371                                                   297 
372   CubicRoots(p, r);                            << 298   CubicRoots(p,r);
373                                                   299 
374   for(k = 1; k < 4; k++)                       << 300   for( k = 1; k < 4; k++ )
375   {                                               301   {
376     if(r[2][k] == 0.)  // find a real root     << 302     if( r[2][k] == 0. ) // find a real root
377     {                                             303     {
                                                   >> 304       noReRoots++;
378       reRoot[k] = r[1][k];                        305       reRoot[k] = r[1][k];
379     }                                             306     }
380     else                                       << 307     else reRoot[k] = DBL_MAX; // kInfinity;
381     {                                          << 
382       reRoot[k] = DBL_MAX;  // kInfinity;      << 
383     }                                          << 
384   }                                               308   }
385   y1 = DBL_MAX;  // kInfinity;                 << 309   y1 = DBL_MAX; // kInfinity;  
386   for(k = 1; k < 4; k++)                       << 310   for( k = 1; k < 4; k++ )
387   {                                               311   {
388     if(reRoot[k] < y1)                         << 312     if ( reRoot[k] < y1 ) { y1 = reRoot[k]; }
389     {                                          << 
390       y1 = reRoot[k];                          << 
391     }                                          << 
392   }                                               313   }
393                                                   314 
394   R2 = 0.25 * a3 * a3 - a2 + y1;               << 315   R2 = 0.25*a3*a3 - a2 + y1;
395   b  = 0.25 * (4 * a3 * a2 - 8 * a1 - a3 * a3  << 316   b  = 0.25*(4*a3*a2 - 8*a1 - a3*a3*a3);
396   c  = 0.75 * a3 * a3 - 2 * a2;                << 317   c  = 0.75*a3*a3 - 2*a2;
397   a  = c - R2;                                    318   a  = c - R2;
398   d  = 4 * y1 * y1 - 16 * a0;                  << 319   d  = 4*y1*y1 - 16*a0;
399                                                   320 
400   if(R2 > 0.)                                  << 321   if( R2 > 0.)
401   {                                               322   {
402     R  = std::sqrt(R2);                        << 323     R = std::sqrt(R2);
403     D2 = a + b / R;                            << 324     D2 = a + b/R;
404     E2 = a - b / R;                            << 325     E2 = a - b/R;
405                                                   326 
406     if(D2 >= 0.)                               << 327     if( D2 >= 0. )
407     {                                             328     {
408       D       = std::sqrt(D2);                    329       D       = std::sqrt(D2);
409       r[1][1] = -0.25 * a3 + 0.5 * R + 0.5 * D << 330       r[1][1] = -0.25*a3 + 0.5*R + 0.5*D;
410       r[1][2] = -0.25 * a3 + 0.5 * R - 0.5 * D << 331       r[1][2] = -0.25*a3 + 0.5*R - 0.5*D;
411       r[2][1] = 0.;                               332       r[2][1] = 0.;
412       r[2][2] = 0.;                               333       r[2][2] = 0.;
413     }                                             334     }
414     else                                          335     else
415     {                                             336     {
416       D       = std::sqrt(-D2);                   337       D       = std::sqrt(-D2);
417       r[1][1] = -0.25 * a3 + 0.5 * R;          << 338       r[1][1] = -0.25*a3 + 0.5*R;
418       r[1][2] = -0.25 * a3 + 0.5 * R;          << 339       r[1][2] = -0.25*a3 + 0.5*R;
419       r[2][1] = 0.5 * D;                       << 340       r[2][1] =  0.5*D;
420       r[2][2] = -0.5 * D;                      << 341       r[2][2] = -0.5*D;
421     }                                             342     }
422     if(E2 >= 0.)                               << 343     if( E2 >= 0. )
423     {                                             344     {
424       E       = std::sqrt(E2);                    345       E       = std::sqrt(E2);
425       r[1][3] = -0.25 * a3 - 0.5 * R + 0.5 * E << 346       r[1][3] = -0.25*a3 - 0.5*R + 0.5*E;
426       r[1][4] = -0.25 * a3 - 0.5 * R - 0.5 * E << 347       r[1][4] = -0.25*a3 - 0.5*R - 0.5*E;
427       r[2][3] = 0.;                               348       r[2][3] = 0.;
428       r[2][4] = 0.;                               349       r[2][4] = 0.;
429     }                                             350     }
430     else                                          351     else
431     {                                             352     {
432       E       = std::sqrt(-E2);                   353       E       = std::sqrt(-E2);
433       r[1][3] = -0.25 * a3 - 0.5 * R;          << 354       r[1][3] = -0.25*a3 - 0.5*R;
434       r[1][4] = -0.25 * a3 - 0.5 * R;          << 355       r[1][4] = -0.25*a3 - 0.5*R;
435       r[2][3] = 0.5 * E;                       << 356       r[2][3] =  0.5*E;
436       r[2][4] = -0.5 * E;                      << 357       r[2][4] = -0.5*E;
437     }                                             358     }
438   }                                               359   }
439   else if(R2 < 0.)                             << 360   else if( R2 < 0.)
440   {                                               361   {
441     R = std::sqrt(-R2);                           362     R = std::sqrt(-R2);
442     G4complex CD2(a, -b / R);                  << 363     G4complex CD2(a,-b/R);
443     G4complex CD = std::sqrt(CD2);                364     G4complex CD = std::sqrt(CD2);
444                                                   365 
445     r[1][1] = -0.25 * a3 + 0.5 * real(CD);     << 366     r[1][1] = -0.25*a3 + 0.5*real(CD);
446     r[1][2] = -0.25 * a3 - 0.5 * real(CD);     << 367     r[1][2] = -0.25*a3 - 0.5*real(CD);
447     r[2][1] = 0.5 * R + 0.5 * imag(CD);        << 368     r[2][1] =  0.5*R + 0.5*imag(CD);
448     r[2][2] = 0.5 * R - 0.5 * imag(CD);        << 369     r[2][2] =  0.5*R - 0.5*imag(CD);
449     G4complex CE2(a, b / R);                   << 370     G4complex CE2(a,b/R);
450     G4complex CE = std::sqrt(CE2);                371     G4complex CE = std::sqrt(CE2);
451                                                   372 
452     r[1][3] = -0.25 * a3 + 0.5 * real(CE);     << 373     r[1][3] = -0.25*a3 + 0.5*real(CE);
453     r[1][4] = -0.25 * a3 - 0.5 * real(CE);     << 374     r[1][4] = -0.25*a3 - 0.5*real(CE);
454     r[2][3] = -0.5 * R + 0.5 * imag(CE);       << 375     r[2][3] =  -0.5*R + 0.5*imag(CE);
455     r[2][4] = -0.5 * R - 0.5 * imag(CE);       << 376     r[2][4] =  -0.5*R - 0.5*imag(CE);
456   }                                               377   }
457   else  // R2=0 case                           << 378   else // R2=0 case
458   {                                               379   {
459     if(d >= 0.)                                   380     if(d >= 0.)
460     {                                             381     {
461       D2 = c + std::sqrt(d);                      382       D2 = c + std::sqrt(d);
462       E2 = c - std::sqrt(d);                      383       E2 = c - std::sqrt(d);
463                                                   384 
464       if(D2 >= 0.)                             << 385       if( D2 >= 0. )
465       {                                           386       {
466         D       = std::sqrt(D2);                  387         D       = std::sqrt(D2);
467         r[1][1] = -0.25 * a3 + 0.5 * R + 0.5 * << 388         r[1][1] = -0.25*a3 + 0.5*R + 0.5*D;
468         r[1][2] = -0.25 * a3 + 0.5 * R - 0.5 * << 389         r[1][2] = -0.25*a3 + 0.5*R - 0.5*D;
469         r[2][1] = 0.;                             390         r[2][1] = 0.;
470         r[2][2] = 0.;                             391         r[2][2] = 0.;
471       }                                           392       }
472       else                                        393       else
473       {                                           394       {
474         D       = std::sqrt(-D2);                 395         D       = std::sqrt(-D2);
475         r[1][1] = -0.25 * a3 + 0.5 * R;        << 396         r[1][1] = -0.25*a3 + 0.5*R;
476         r[1][2] = -0.25 * a3 + 0.5 * R;        << 397         r[1][2] = -0.25*a3 + 0.5*R;
477         r[2][1] = 0.5 * D;                     << 398         r[2][1] =  0.5*D;
478         r[2][2] = -0.5 * D;                    << 399         r[2][2] = -0.5*D;
479       }                                           400       }
480       if(E2 >= 0.)                             << 401       if( E2 >= 0. )
481       {                                           402       {
482         E       = std::sqrt(E2);                  403         E       = std::sqrt(E2);
483         r[1][3] = -0.25 * a3 - 0.5 * R + 0.5 * << 404         r[1][3] = -0.25*a3 - 0.5*R + 0.5*E;
484         r[1][4] = -0.25 * a3 - 0.5 * R - 0.5 * << 405         r[1][4] = -0.25*a3 - 0.5*R - 0.5*E;
485         r[2][3] = 0.;                             406         r[2][3] = 0.;
486         r[2][4] = 0.;                             407         r[2][4] = 0.;
487       }                                           408       }
488       else                                        409       else
489       {                                           410       {
490         E       = std::sqrt(-E2);                 411         E       = std::sqrt(-E2);
491         r[1][3] = -0.25 * a3 - 0.5 * R;        << 412         r[1][3] = -0.25*a3 - 0.5*R;
492         r[1][4] = -0.25 * a3 - 0.5 * R;        << 413         r[1][4] = -0.25*a3 - 0.5*R;
493         r[2][3] = 0.5 * E;                     << 414         r[2][3] =  0.5*E;
494         r[2][4] = -0.5 * E;                    << 415         r[2][4] = -0.5*E;
495       }                                           416       }
496     }                                             417     }
497     else                                          418     else
498     {                                             419     {
499       ds = std::sqrt(-d);                         420       ds = std::sqrt(-d);
500       G4complex CD2(c, ds);                    << 421       G4complex CD2(c,ds);
501       G4complex CD = std::sqrt(CD2);              422       G4complex CD = std::sqrt(CD2);
502                                                   423 
503       r[1][1] = -0.25 * a3 + 0.5 * real(CD);   << 424       r[1][1] = -0.25*a3 + 0.5*real(CD);
504       r[1][2] = -0.25 * a3 - 0.5 * real(CD);   << 425       r[1][2] = -0.25*a3 - 0.5*real(CD);
505       r[2][1] = 0.5 * R + 0.5 * imag(CD);      << 426       r[2][1] =  0.5*R + 0.5*imag(CD);
506       r[2][2] = 0.5 * R - 0.5 * imag(CD);      << 427       r[2][2] =  0.5*R - 0.5*imag(CD);
507                                                   428 
508       G4complex CE2(c, -ds);                   << 429       G4complex CE2(c,-ds);
509       G4complex CE = std::sqrt(CE2);              430       G4complex CE = std::sqrt(CE2);
510                                                   431 
511       r[1][3] = -0.25 * a3 + 0.5 * real(CE);   << 432       r[1][3] = -0.25*a3 + 0.5*real(CE);
512       r[1][4] = -0.25 * a3 - 0.5 * real(CE);   << 433       r[1][4] = -0.25*a3 - 0.5*real(CE);
513       r[2][3] = -0.5 * R + 0.5 * imag(CE);     << 434       r[2][3] =  -0.5*R + 0.5*imag(CE);
514       r[2][4] = -0.5 * R - 0.5 * imag(CE);     << 435       r[2][4] =  -0.5*R - 0.5*imag(CE);
515     }                                          << 436     }  
516   }                                               437   }
517   return 4;                                       438   return 4;
518 }                                                 439 }
519                                                   440 
520 //                                                441 //
521 //                                                442 //
522 //////////////////////////////////////////////    443 //////////////////////////////////////////////////////////////////////////////
523                                                   444