Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 // $Id: G4Pow.cc 93311 2015-10-16 10:16:37Z gcosmo $
27 //
28 // -------------------------------------------------------------------
29 //
30 // GEANT4 Class file
31 //
32 //
33 // File name: G4Pow
34 //
35 // Author: Vladimir Ivanchenko
36 //
37 // Creation date: 23.05.2009
38 //
39 // Modifications:
40 // 08.01.2011 V.Ivanchenko extended maxZ from 256 to 512
41 // 02.05.2013 V.Ivanchenko added expA and logX methods,
42 // revised A13, logA, powZ, powA to improved accuracy
43 //
44 // -------------------------------------------------------------------
45 
46 #include "G4Pow.hh"
47 #ifdef G4MULTITHREADED
48 #include "G4Threading.hh"
49 #endif
50 
51 G4Pow* G4Pow::fpInstance = 0;
52 
53 // -------------------------------------------------------------------
54 
56 {
57  if (fpInstance == 0)
58  {
59  static G4Pow geant4pow;
60  fpInstance = &geant4pow;
61  }
62  return fpInstance;
63 }
64 
65 // -------------------------------------------------------------------
66 
67 G4Pow::G4Pow()
68  : onethird(1.0/3.0), max2(5)
69 {
70 #ifdef G4MULTITHREADED
72  {
73  G4Exception ("G4Pow::G4Pow()", "InvalidSetup", FatalException,
74  "Attempt to instantiate G4Pow in worker thread!");
75  }
76 #endif
77  const G4int maxZ = 512;
78  const G4int maxZfact = 170;
79 
80  maxA = -0.6 + maxZ;
81  maxA2 = 1.25 + max2*0.2;
82  maxAexp = -0.76+ maxZfact*0.5;
83 
84  ener.resize(max2+1,1.0);
85  logen.resize(max2+1,0.0);
86  lz2.resize(max2+1,0.0);
87  pz13.resize(maxZ,0.0);
88  lz.resize(maxZ,0.0);
89  fexp.resize(maxZfact,0.0);
90  fact.resize(maxZfact,0.0);
91  logfact.resize(maxZ,0.0);
92 
93  G4double f = 1.0;
94  G4double logf = 0.0;
95  fact[0] = 1.0;
96  fexp[0] = 1.0;
97 
98  for(G4int i=1; i<=max2; ++i)
99  {
100  ener[i] = powN(500.,i);
101  logen[i]= G4Log(ener[i]);
102  lz2[i] = G4Log(1.0 + i*0.2);
103  }
104 
105  for(G4int i=1; i<maxZ; ++i)
106  {
107  G4double x = G4double(i);
108  pz13[i] = std::pow(x,onethird);
109  lz[i] = G4Log(x);
110  if(i < maxZfact)
111  {
112  f *= x;
113  fact[i] = f;
114  fexp[i] = G4Exp(0.5*i);
115  }
116  logf += lz[i];
117  logfact[i] = logf;
118  }
119 }
120 
121 // -------------------------------------------------------------------
122 
124 {}
125 
126 // -------------------------------------------------------------------
127 
129 {
130  if(0.0 == x) { return 0.0; }
131  if(std::abs(n) > 8) { return std::pow(x, G4double(n)); }
132  G4double res = 1.0;
133  if(n >= 0) { for(G4int i=0; i<n; ++i) { res *= x; } }
134  else if(n < 0)
135  {
136  G4double y = 1.0/x;
137  G4int nn = -n;
138  for(G4int i=0; i<nn; ++i) { res *= y; }
139  }
140  return res;
141 }
static G4Pow * GetInstance()
Definition: G4Pow.cc:55
~G4Pow()
Definition: G4Pow.cc:123
G4double powN(G4double x, G4int n) const
Definition: G4Pow.cc:128
Definition: G4Pow.hh:56
int G4int
Definition: G4Types.hh:78
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4bool IsWorkerThread()
Definition: G4Threading.cc:145
G4double G4Log(G4double x)
Definition: G4Log.hh:230
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
Definition: G4Exp.hh:183
double G4double
Definition: G4Types.hh:76