Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
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 // $Id: G4Pow.hh 109086 2018-03-26 08:20:25Z gcosmo $
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.002-511.5 for all functions except exponent, which is computed
41 // for the interval 0-84.4, standard library is used in the opposite case
42 
43 // Author: Vladimir Ivanchenko
44 //
45 // Creation date: 23.05.2009
46 // -------------------------------------------------------------------
47 
48 #ifndef G4Pow_h
49 #define G4Pow_h 1
50 
51 #include "globals.hh"
52 #include "G4Log.hh"
53 #include "G4Exp.hh"
54 #include "G4DataVector.hh"
55 
56 class G4Pow
57 {
58 
59  public:
60 
61  static G4Pow* GetInstance();
62  ~G4Pow();
63 
64  // Fast computation of Z^1/3
65  //
66  inline G4double Z13(G4int Z) const;
67  G4double A13(G4double A) const;
68 
69  // Fast computation of Z^2/3
70  //
71  inline G4double Z23(G4int Z) const;
72  inline G4double A23(G4double A) const;
73 
74  // Fast computation of log(Z)
75  //
76  inline G4double logZ(G4int Z) const;
77  inline G4double logA(G4double A) const;
78  inline G4double logX(G4double x) const;
79 
80  // Fast computation of log10(Z)
81  //
82  inline G4double log10Z(G4int Z) const;
83  inline G4double log10A(G4double A) const;
84 
85  // Fast computation of exp(X)
86  //
87  inline G4double expA(G4double A) const;
88 
89  // Fast computation of pow(Z,X)
90  //
91  inline G4double powZ(G4int Z, G4double y) const;
92  inline G4double powA(G4double A, G4double y) const;
93  G4double powN(G4double x, G4int n) const;
94 
95  // Fast factorial
96  //
97  inline G4double factorial(G4int Z) const;
98  inline G4double logfactorial(G4int Z) const;
99 
100  private:
101 
102  G4Pow();
103 
104  G4double A13Low(const G4double, const bool) const;
105  G4double A13High(const G4double, const bool) const;
106 
107  inline G4double logBase(G4double x) const;
108 
109  static G4Pow* fpInstance;
110 
112  const G4int max2;
113 
118 
128 };
129 
130 // -------------------------------------------------------------------
131 
132 inline G4double G4Pow::Z13(G4int Z) const
133 {
134  return pz13[Z];
135 }
136 
137 inline G4double G4Pow::Z23(G4int Z) const
138 {
139  G4double x = Z13(Z);
140  return x*x;
141 }
142 
144 {
145  G4double x = A13(A);
146  return x*x;
147 }
148 
150 {
151  return lz[Z];
152 }
153 
155 {
156  G4double res;
157  if(a <= maxA2)
158  {
159  G4int i = G4int(max2*(a - 1) + 0.5);
160  if(i > max2) { i = max2; }
161  G4double x = a/(G4double(i)/max2 + 1) - 1;
162  res = lz2[i] + x*(1.0 - (0.5 - onethird*x)*x);
163  }
164  else if(a <= maxA)
165  {
166  G4int i = G4int(a + 0.5);
167  G4double x = a/G4double(i) - 1;
168  res = lz[i] + x*(1.0 - (0.5 - onethird*x)*x);
169  }
170  else
171  {
172  res = G4Log(a);
173  }
174  return res;
175 }
176 
178 {
179  return (1.0 <= A ? logBase(A) : -logBase(1./A));
180 }
181 
183 {
184  G4double res = 0.0;
185  G4double a = (1.0 <= x) ? x : 1.0/x;
186 
187  if(a <= maxA)
188  {
189  res = logBase(a);
190  }
191  else if(a <= ener[2])
192  {
193  res = logen[1] + logBase(a/ener[1]);
194  }
195  else if(a <= ener[3])
196  {
197  res = logen[2] + logBase(a/ener[2]);
198  }
199  else
200  {
201  res = G4Log(a);
202  }
203 
204  if(1.0 > x) { res = -res; }
205  return res;
206 }
207 
209 {
210  return lz[Z]/lz[10];
211 }
212 
214 {
215  return logX(A)/lz[10];
216 }
217 
219 {
220  G4double res;
221  G4double a = (0.0 <= A) ? A : -A;
222 
223  if(a <= maxAexp)
224  {
225  G4int i = G4int(2*a + 0.5);
226  G4double x = a - i*0.5;
227  res = fexp[i]*(1.0 + x*(1.0 + 0.5*(1.0 + onethird*x)*x));
228  }
229  else
230  {
231  res = G4Exp(a);
232  }
233  if(0.0 > A) { res = 1.0/res; }
234  return res;
235 }
236 
238 {
239  return expA(y*lz[Z]);
240 }
241 
243 {
244  return (0.0 == A ? 0.0 : expA(y*logX(A)));
245 }
246 
248 {
249  return fact[Z];
250 }
251 
253 {
254  return logfact[Z];
255 }
256 
257 // -------------------------------------------------------------------
258 
259 #endif
G4DataVector fexp
Definition: G4Pow.hh:125
Float_t x
Definition: compare.C:6
G4DataVector logfact
Definition: G4Pow.hh:127
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
Definition: G4Exp.hh:183
G4double A13High(const G4double, const bool) const
Definition: G4Pow.cc:150
G4DataVector lz2
Definition: G4Pow.hh:124
G4double logZ(G4int Z) const
Definition: G4Pow.hh:149
G4DataVector fact
Definition: G4Pow.hh:126
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
G4double Z13(G4int Z) const
Definition: G4Pow.hh:132
G4double A13(G4double A) const
Definition: G4Pow.cc:138
G4DataVector ener
Definition: G4Pow.hh:119
G4double logA(G4double A) const
Definition: G4Pow.hh:177
G4double factorial(G4int Z) const
Definition: G4Pow.hh:247
static G4Pow * fpInstance
Definition: G4Pow.hh:109
Float_t y
Definition: compare.C:6
G4double A23(G4double A) const
Definition: G4Pow.hh:143
const G4double onethird
Definition: G4Pow.hh:111
~G4Pow()
Definition: G4Pow.cc:133
const G4int max2
Definition: G4Pow.hh:112
G4double maxA
Definition: G4Pow.hh:114
G4double maxLowA
Definition: G4Pow.hh:115
G4DataVector lz
Definition: G4Pow.hh:123
G4double G4Log(G4double x)
Definition: G4Log.hh:230
G4double powN(G4double x, G4int n) const
Definition: G4Pow.cc:177
Float_t Z
G4double powZ(G4int Z, G4double y) const
Definition: G4Pow.hh:237
G4double expA(G4double A) const
Definition: G4Pow.hh:218
double G4double
Definition: G4Types.hh:76
static G4Pow * GetInstance()
Definition: G4Pow.cc:57
G4double powA(G4double A, G4double y) const
Definition: G4Pow.hh:242
G4DataVector pz13
Definition: G4Pow.hh:121
G4DataVector logen
Definition: G4Pow.hh:120
double A(double temperature)
G4double logfactorial(G4int Z) const
Definition: G4Pow.hh:252
G4Pow()
Definition: G4Pow.cc:69
int G4int
Definition: G4Types.hh:78
G4double log10A(G4double A) const
Definition: G4Pow.hh:213
G4double logX(G4double x) const
Definition: G4Pow.hh:182
Definition: G4Pow.hh:56
G4double logBase(G4double x) const
Definition: G4Pow.hh:154
Char_t n[5]
G4double A13Low(const G4double, const bool) const
Definition: G4Pow.cc:165
G4double log10Z(G4int Z) const
Definition: G4Pow.hh:208
G4double maxA2
Definition: G4Pow.hh:116
G4double maxAexp
Definition: G4Pow.hh:117
G4double Z23(G4int Z) const
Definition: G4Pow.hh:137
G4DataVector lowa13
Definition: G4Pow.hh:122