Geant4-11
G4Pow.cc
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// G4Pow class implemenation
27//
28// Author: Vladimir Ivanchenko, 23.05.2009
29// Revisions:
30// - 23.03.2018, M.Novak: increased accuracy of A13 on the most critical
31// [1/4,4] interval by introducing a denser(0.25) grid
32// --------------------------------------------------------------------
33
34#include "G4Pow.hh"
35#include "G4Threading.hh"
36
37G4Pow* G4Pow::fpInstance = nullptr;
38
39// -------------------------------------------------------------------
40
42{
43 if(fpInstance == nullptr)
44 {
45 static G4Pow geant4pow;
46 fpInstance = &geant4pow;
47 }
48 return fpInstance;
49}
50
51// -------------------------------------------------------------------
52
54{
55#ifdef G4MULTITHREADED
57 {
58 G4Exception("G4Pow::G4Pow()", "InvalidSetup", FatalException,
59 "Attempt to instantiate G4Pow in worker thread!");
60 }
61#endif
62 const G4int maxZ = 512;
63 const G4int maxZfact = 170;
64 const G4int numLowA = 17;
65
66 maxA = -0.6 + maxZ;
67 maxLowA = 4.0;
68 maxA2 = 1.25 + max2 * 0.2;
69 maxAexp = -0.76 + maxZfact * 0.5;
70
71 ener.resize(max2 + 1, 1.0);
72 logen.resize(max2 + 1, 0.0);
73 lz2.resize(max2 + 1, 0.0);
74 pz13.resize(maxZ, 0.0);
75 lowa13.resize(numLowA, 0.0);
76 lz.resize(maxZ, 0.0);
77 fexp.resize(maxZfact, 0.0);
78 fact.resize(maxZfact, 0.0);
79 logfact.resize(maxZ, 0.0);
80
81 G4double f = 1.0;
82 G4double logf = 0.0;
83 fact[0] = 1.0;
84 fexp[0] = 1.0;
85
86 for(G4int i = 1; i <= max2; ++i)
87 {
88 ener[i] = powN(500., i);
89 logen[i] = G4Log(ener[i]);
90 lz2[i] = G4Log(1.0 + i * 0.2);
91 }
92
93 for(G4int i = 1; i < maxZ; ++i)
94 {
95 G4double x = G4double(i);
96 pz13[i] = std::pow(x, onethird);
97 lz[i] = G4Log(x);
98 if(i < maxZfact)
99 {
100 f *= x;
101 fact[i] = f;
102 fexp[i] = G4Exp(0.5 * i);
103 }
104 logf += lz[i];
105 logfact[i] = logf;
106 }
107
108 for(G4int i = 4; i < numLowA; ++i)
109 {
110 lowa13[i] = std::pow(0.25 * i, onethird);
111 }
112}
113
114// -------------------------------------------------------------------
115
117
118// -------------------------------------------------------------------
119
121{
122 G4double res = 0.;
123 if(A > 0.)
124 {
125 const bool invert = (A < 1.);
126 const G4double a = invert ? 1. / A : A;
127 res = (a < maxLowA) ? A13Low(a, invert) : A13High(a, invert);
128 }
129 return res;
130}
131
132// -------------------------------------------------------------------
133
134G4double G4Pow::A13High(const G4double a, const bool invert) const
135{
136 G4double res;
137 if(a < maxA)
138 {
139 const G4int i = static_cast<G4int>(a + 0.5);
140 const G4double x = (a / i - 1.) * onethird;
141 res = pz13[i] * (1. + x - x * x * (1. - 1.666667 * x));
142 }
143 else
144 {
145 res = G4Exp(G4Log(a) * onethird);
146 }
147 res = invert ? 1. / res : res;
148 return res;
149}
150
151// -------------------------------------------------------------------
152
153G4double G4Pow::A13Low(const G4double a, const G4bool invert) const
154{
155 G4double res;
156 const G4int i = static_cast<G4int>(4. * (a + 0.125));
157 const G4double y = 0.25 * i;
158 const G4double x = (a / y - 1.) * onethird;
159 res = lowa13[i] * (1. + x - x * x * (1. - 1.666667 * x));
160 res = invert ? 1. / res : res;
161 return res;
162}
163
164// -------------------------------------------------------------------
165
167{
168 if(0.0 == x)
169 {
170 return 0.0;
171 }
172 if(std::abs(n) > 8)
173 {
174 return std::pow(x, G4double(n));
175 }
176 G4double res = 1.0;
177 if(n >= 0)
178 {
179 for(G4int i = 0; i < n; ++i)
180 {
181 res *= x;
182 }
183 }
184 else if(n < 0)
185 {
186 G4double y = 1.0 / x;
187 G4int nn = -n;
188 for(G4int i = 0; i < nn; ++i)
189 {
190 res *= y;
191 }
192 }
193 return res;
194}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
Definition: G4Exp.hh:179
static const G4int maxZ
G4double G4Log(G4double x)
Definition: G4Log.hh:226
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
const G4double A[17]
Definition: G4Pow.hh:49
static G4Pow * GetInstance()
Definition: G4Pow.cc:41
G4DataVector logfact
Definition: G4Pow.hh:116
G4double maxLowA
Definition: G4Pow.hh:104
G4double A13Low(const G4double, const G4bool) const
Definition: G4Pow.cc:153
const G4int max2
Definition: G4Pow.hh:101
G4DataVector ener
Definition: G4Pow.hh:108
G4double A13(G4double A) const
Definition: G4Pow.cc:120
G4double maxAexp
Definition: G4Pow.hh:106
~G4Pow()
Definition: G4Pow.cc:116
G4DataVector logen
Definition: G4Pow.hh:109
G4DataVector fexp
Definition: G4Pow.hh:114
G4DataVector lz2
Definition: G4Pow.hh:113
G4double powN(G4double x, G4int n) const
Definition: G4Pow.cc:166
G4Pow()
Definition: G4Pow.cc:53
G4double A13High(const G4double, const G4bool) const
Definition: G4Pow.cc:134
G4DataVector pz13
Definition: G4Pow.hh:110
G4DataVector fact
Definition: G4Pow.hh:115
G4double maxA
Definition: G4Pow.hh:103
G4DataVector lowa13
Definition: G4Pow.hh:111
const G4double onethird
Definition: G4Pow.hh:100
static G4Pow * fpInstance
Definition: G4Pow.hh:98
G4DataVector lz
Definition: G4Pow.hh:112
G4double maxA2
Definition: G4Pow.hh:105
G4bool IsWorkerThread()
Definition: G4Threading.cc:123