Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4Pow.hh
Go to the documentation of this file.
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 // $Id: G4Pow.hh 69386 2013-05-02 10:35:42Z vnivanch $
27 //
28 //
29 // -------------------------------------------------------------------
30 //
31 // Class G4Pow
32 //
33 // Class description:
34 //
35 // Utility singleton class for the fast computation of log and pow
36 // functions. Integer argument should in the interval 0-512, no
37 // check is performed inside these methods for performance reasons.
38 // For factorial integer argument should be in the interval 0-170
39 // Computations with double arguments are fast for the interval
40 // 0.5-255.5, 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 "G4DataVector.hh"
52 
53 class G4Pow
54 {
55 
56  public:
57 
58  static G4Pow* GetInstance();
59 
60  // Fast computation of Z^1/3
61  //
62  inline G4double Z13(G4int Z);
63  inline G4double A13(G4double A);
64 
65  // Fast computation of Z^2/3
66  //
67  inline G4double Z23(G4int Z);
68  inline G4double A23(G4double A);
69 
70  // Fast computation of log(Z)
71  //
72  inline G4double logZ(G4int Z);
73  inline G4double logA(G4double A);
74 
75  // Fast computation of log10(Z)
76  //
77  inline G4double log10Z(G4int Z);
78  inline G4double log10A(G4double A);
79 
80  // Fast computation of pow(Z,X)
81  //
82  inline G4double powZ(G4int Z, G4double y);
83  inline G4double powA(G4double A, G4double y);
85 
86  // Fast factorial
87  //
88  inline G4double factorial(G4int Z);
89  inline G4double logfactorial(G4int Z);
90 
91  private:
92 
93  G4Pow();
94  ~G4Pow();
95 
96  private:
97 
98  static G4Pow* fpInstance;
99 
100  const G4double onethird;
101  const G4double minA;
102  const G4double maxA;
103 
104  G4DataVector pz13;
105  G4DataVector lz;
106  G4DataVector fact;
107  G4DataVector logfact;
108 };
109 
110 // -------------------------------------------------------------------
111 
113 {
114  return pz13[Z];
115 }
116 
118 {
119  G4double res;
120  G4double a = A;
121  if(1.0 > A) { a = 1.0/A; }
122  if(a <= maxA)
123  {
124  G4int i = G4int(a + 0.5);
125  G4double x = (a/G4double(i) - 1.0)*onethird;
126  res = pz13[i]*(1.0 + x - x*x*(1.0 - 1.66666666*x));
127  if(1.0 > A) { res = 1.0/res; }
128  }
129  else
130  {
131  res = std::pow(A, onethird);
132  }
133  return res;
134 }
135 
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  G4double a = A;
157  if(1.0 > A) { a = 1.0/A; }
158  if(a <= maxA)
159  {
160  G4int i = G4int(a + 0.5);
161  G4double x = a/G4double(i) - 1;
162  res = lz[i] + x*(1.0 - (0.5 - onethird*x)*x);
163  if(1.0 > A) { res = -res; }
164  }
165  else
166  {
167  res = std::log(A);
168  }
169  return res;
170 }
171 
173 {
174  return lz[Z]/lz[10];
175 }
176 
178 {
179  return logA(A)/lz[10];
180 }
181 
183 {
184  return std::exp(y*lz[Z]);
185 }
186 
188 {
189  return std::exp(y*logA(A));
190 }
191 
193 {
194  return fact[Z];
195 }
196 
198 {
199  return logfact[Z];
200 }
201 
202 // -------------------------------------------------------------------
203 
204 #endif
205