Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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$
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
53class 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* fInstance;
99
100 G4double onethird;
101
102 G4DataVector pz13;
103 G4DataVector lz;
104 G4DataVector fact;
105 G4DataVector logfact;
106};
107
108// -------------------------------------------------------------------
109
111{
112 return pz13[Z];
113}
114
116{
117 const G4double minA = 0.5000001;
118 const G4double maxA = 255.5;
119
120 G4double res;
121 if((A >= minA) && (A <= maxA))
122 {
123 G4int i = G4int(A + 0.5);
124 G4double x = (1.0 - A/G4double(i))*onethird;
125 res = pz13[i]*(1.0 + x - x*x*(1.0 - 1.66666666*x));
126 }
127 else
128 {
129 res = std::pow(A, onethird);
130 }
131 return res;
132}
133
135{
136 G4double x = Z13(Z);
137 return x*x;
138}
139
141{
142 G4double x = A13(A);
143 return x*x;
144}
145
147{
148 return lz[Z];
149}
150
152{
153 const G4double minA = 0.5000001;
154 const G4double maxA = 255.5;
155
156 G4double res;
157 if((A >= minA) && (A <= maxA))
158 {
159 G4int i = G4int(A + 0.5);
160 G4double x = 1.0 - A/G4double(i);
161 res = lz[i] + x*(1.0 - 0.5*x + onethird*x*x);
162 }
163 else
164 {
165 res = std::log(A);
166 }
167 return res;
168}
169
171{
172 return lz[Z]/lz[10];
173}
174
176{
177 return logA(A)/lz[10];
178}
179
181{
182 return std::exp(y*lz[Z]);
183}
184
186{
187 return std::exp(y*logA(A));
188}
189
191{
192 return fact[Z];
193}
194
196{
197 return logfact[Z];
198}
199
200// -------------------------------------------------------------------
201
202#endif
203
#define A23
#define A13
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
Definition: G4Pow.hh:54
static G4Pow * GetInstance()
Definition: G4Pow.cc:50
G4double A13(G4double A)
Definition: G4Pow.hh:115
G4double log10A(G4double A)
Definition: G4Pow.hh:175
G4double factorial(G4int Z)
Definition: G4Pow.hh:190
G4double powA(G4double A, G4double y)
Definition: G4Pow.hh:185
G4double Z23(G4int Z)
Definition: G4Pow.hh:134
G4double log10Z(G4int Z)
Definition: G4Pow.hh:170
G4double powN(G4double x, G4int n)
Definition: G4Pow.cc:98
G4double logfactorial(G4int Z)
Definition: G4Pow.hh:195
G4double Z13(G4int Z)
Definition: G4Pow.hh:110
G4double A23(G4double A)
Definition: G4Pow.hh:140
G4double logA(G4double A)
Definition: G4Pow.hh:151
G4double powZ(G4int Z, G4double y)
Definition: G4Pow.hh:180
G4double logZ(G4int Z)
Definition: G4Pow.hh:146