ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4Pow.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4Pow.hh
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 //
28 // -------------------------------------------------------------------
29 //
30 // Class G4Pow
31 //
32 // Class description:
33 //
34 // Utility singleton class for the fast computation of log and pow
35 // functions. Integer argument should in the interval 0-512, no
36 // check is performed inside these methods for performance reasons.
37 // For factorial integer argument should be in the interval 0-170
38 // Computations with double arguments are fast for the interval
39 // 0.002-511.5 for all functions except exponent, which is computed
40 // for the interval 0-84.4, standard library is used in the opposite case
41 
42 // Author: Vladimir Ivanchenko
43 //
44 // Creation date: 23.05.2009
45 // -------------------------------------------------------------------
46 
47 #ifndef G4Pow_h
48 #define G4Pow_h 1
49 
50 #include "globals.hh"
51 #include "G4Log.hh"
52 #include "G4Exp.hh"
53 #include "G4DataVector.hh"
54 
55 class G4Pow
56 {
57 
58  public:
59 
60  static G4Pow* GetInstance();
61  ~G4Pow();
62 
63  // Fast computation of Z^1/3
64  //
65  inline G4double Z13(G4int Z) const;
66  G4double A13(G4double A) const;
67 
68  // Fast computation of Z^2/3
69  //
70  inline G4double Z23(G4int Z) const;
71  inline G4double A23(G4double A) const;
72 
73  // Fast computation of log(Z)
74  //
75  inline G4double logZ(G4int Z) const;
76  inline G4double logA(G4double A) const;
77  inline G4double logX(G4double x) const;
78 
79  // Fast computation of log10(Z)
80  //
81  inline G4double log10Z(G4int Z) const;
82  inline G4double log10A(G4double A) const;
83 
84  // Fast computation of exp(X)
85  //
86  inline G4double expA(G4double A) const;
87 
88  // Fast computation of pow(Z,X)
89  //
90  inline G4double powZ(G4int Z, G4double y) const;
91  inline G4double powA(G4double A, G4double y) const;
92  G4double powN(G4double x, G4int n) const;
93 
94  // Fast factorial
95  //
96  inline G4double factorial(G4int Z) const;
97  inline G4double logfactorial(G4int Z) const;
98 
99  private:
100 
101  G4Pow();
102 
103  G4double A13Low(const G4double, const bool) const;
104  G4double A13High(const G4double, const bool) const;
105 
106  inline G4double logBase(G4double x) const;
107 
108  static G4Pow* fpInstance;
109 
111  const G4int max2;
112 
117 
127 };
128 
129 // -------------------------------------------------------------------
130 
131 inline G4double G4Pow::Z13(G4int Z) const
132 {
133  return pz13[Z];
134 }
135 
136 inline G4double G4Pow::Z23(G4int Z) const
137 {
138  G4double x = Z13(Z);
139  return x*x;
140 }
141 
143 {
144  G4double x = A13(A);
145  return x*x;
146 }
147 
149 {
150  return lz[Z];
151 }
152 
154 {
155  G4double res;
156  if(a <= maxA2)
157  {
158  G4int i = G4int(max2*(a - 1) + 0.5);
159  if(i > max2) { i = max2; }
160  G4double x = a/(G4double(i)/max2 + 1) - 1;
161  res = lz2[i] + x*(1.0 - (0.5 - onethird*x)*x);
162  }
163  else if(a <= maxA)
164  {
165  G4int i = G4int(a + 0.5);
166  G4double x = a/G4double(i) - 1;
167  res = lz[i] + x*(1.0 - (0.5 - onethird*x)*x);
168  }
169  else
170  {
171  res = G4Log(a);
172  }
173  return res;
174 }
175 
177 {
178  return (1.0 <= A ? logBase(A) : -logBase(1./A));
179 }
180 
182 {
183  G4double res = 0.0;
184  G4double a = (1.0 <= x) ? x : 1.0/x;
185 
186  if(a <= maxA)
187  {
188  res = logBase(a);
189  }
190  else if(a <= ener[2])
191  {
192  res = logen[1] + logBase(a/ener[1]);
193  }
194  else if(a <= ener[3])
195  {
196  res = logen[2] + logBase(a/ener[2]);
197  }
198  else
199  {
200  res = G4Log(a);
201  }
202 
203  if(1.0 > x) { res = -res; }
204  return res;
205 }
206 
208 {
209  return lz[Z]/lz[10];
210 }
211 
213 {
214  return logX(A)/lz[10];
215 }
216 
218 {
219  G4double res;
220  G4double a = (0.0 <= A) ? A : -A;
221 
222  if(a <= maxAexp)
223  {
224  G4int i = G4int(2*a + 0.5);
225  G4double x = a - i*0.5;
226  res = fexp[i]*(1.0 + x*(1.0 + 0.5*(1.0 + onethird*x)*x));
227  }
228  else
229  {
230  res = G4Exp(a);
231  }
232  if(0.0 > A) { res = 1.0/res; }
233  return res;
234 }
235 
237 {
238  return expA(y*lz[Z]);
239 }
240 
242 {
243  return (0.0 == A ? 0.0 : expA(y*logX(A)));
244 }
245 
247 {
248  return fact[Z];
249 }
250 
252 {
253  return logfact[Z];
254 }
255 
256 // -------------------------------------------------------------------
257 
258 #endif