source: trunk/source/global/management/include/G4Pow.hh@ 1330

Last change on this file since 1330 was 1315, checked in by garnier, 15 years ago

update geant4-09-04-beta-cand-01 interfaces-V09-03-09 vis-V09-03-08

File size: 4.7 KB
Line 
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,v 1.5 2010/05/28 08:18:03 vnivanch Exp $
27// GEANT4 tag $Name: geant4-09-04-beta-cand-01 $
28//
29//
30// -------------------------------------------------------------------
31//
32// Class G4Pow
33//
34// Class description:
35//
36// Utility singleton class for the fast computation of log and pow
37// functions. Integer argument should in the interval 0-255, no
38// check is performed inside these methods for performance reasons.
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);
84
85 // Fast factorial
86 //
87 inline G4double factorial(G4int Z);
88
89 private:
90
91 G4Pow();
92 ~G4Pow();
93
94 private:
95
96 static G4Pow* fInstance;
97
98 G4double onethird;
99
100 G4DataVector pz13;
101 G4DataVector lz;
102 G4DataVector fact;
103};
104
105// -------------------------------------------------------------------
106
107inline G4double G4Pow::Z13(G4int Z)
108{
109 return pz13[Z];
110}
111
112inline G4double G4Pow::A13(G4double A)
113{
114 const G4double minA = 0.5000001;
115 const G4double maxA = 255.5;
116
117 G4double res;
118 if((A >= minA) && (A <= maxA))
119 {
120 G4int i = G4int(A + 0.5);
121 G4double x = (1.0 - A/G4double(i))*onethird;
122 res = pz13[i]*(1.0 + x - x*x*(1.0 - 1.66666666*x));
123 }
124 else
125 {
126 res = std::pow(A, onethird);
127 }
128 return res;
129}
130
131inline G4double G4Pow::Z23(G4int Z)
132{
133 G4double x = Z13(Z);
134 return x*x;
135}
136
137inline G4double G4Pow::A23(G4double A)
138{
139 G4double x = A13(A);
140 return x*x;
141}
142
143inline G4double G4Pow::logZ(G4int Z)
144{
145 return lz[Z];
146}
147
148inline G4double G4Pow::logA(G4double A)
149{
150 const G4double minA = 0.5000001;
151 const G4double maxA = 255.5;
152
153 G4double res;
154 if((A >= minA) && (A <= maxA))
155 {
156 G4int i = G4int(A + 0.5);
157 G4double x = 1.0 - A/G4double(i);
158 res = lz[i] + x*(1.0 - 0.5*x + onethird*x*x);
159 }
160 else
161 {
162 res = std::log(A);
163 }
164 return res;
165}
166
167inline G4double G4Pow::log10Z(G4int Z)
168{
169 return lz[Z]/lz[10];
170}
171
172inline G4double G4Pow::log10A(G4double A)
173{
174 return logA(A)/lz[10];
175}
176
177inline G4double G4Pow::powZ(G4int Z, G4double y)
178{
179 return std::exp(y*lz[Z]);
180}
181
182inline G4double G4Pow::powA(G4double A, G4double y)
183{
184 return std::exp(y*logA(A));
185}
186
187inline G4double G4Pow::factorial(G4int Z)
188{
189 return fact[Z];
190}
191
192// -------------------------------------------------------------------
193
194#endif
195
Note: See TracBrowser for help on using the repository browser.