Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 74256 2013-10-02 14:24:02Z 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 #include "G4Threading.hh"
48 
49 G4Pow* G4Pow::fpInstance = 0;
50 
51 // -------------------------------------------------------------------
52 
54 {
55  if (fpInstance == 0)
56  {
57  fpInstance = new G4Pow;
58  }
59  return fpInstance;
60 }
61 
62 // -------------------------------------------------------------------
63 
64 G4Pow::G4Pow()
65  : onethird(1.0/3.0), max2(5)
66 {
67  if(G4Threading::IsWorkerThread() == true) {
68  G4Exception ("G4Pow::G4Pow()", "glob090", FatalException,
69  "Attempt to instantiate G4Pow in worker thread");
70  }
71 
72  const G4int maxZ = 512;
73  const G4int maxZfact = 170;
74 
75  maxA = -0.6 + maxZ;
76  maxA2 = 1.25 + max2*0.2;
77  maxAexp = -0.76+ maxZfact*0.5;
78 
79  ener.resize(max2+1,1.0);
80  logen.resize(max2+1,0.0);
81  lz2.resize(max2+1,0.0);
82  pz13.resize(maxZ,0.0);
83  lz.resize(maxZ,0.0);
84  fexp.resize(maxZfact,0.0);
85  fact.resize(maxZfact,0.0);
86  logfact.resize(maxZ,0.0);
87 
88  G4double f = 1.0;
89  G4double logf = 0.0;
90  fact[0] = 1.0;
91  fexp[0] = 1.0;
92 
93  for(G4int i=1; i<=max2; ++i)
94  {
95  ener[i] = powN(500.,i);
96  logen[i]= G4Log(ener[i]);
97  lz2[i] = G4Log(1.0 + i*0.2);
98  }
99 
100  for(G4int i=1; i<maxZ; ++i)
101  {
102  G4double x = G4double(i);
103  pz13[i] = std::pow(x,onethird);
104  lz[i] = G4Log(x);
105  if(i < maxZfact)
106  {
107  f *= x;
108  fact[i] = f;
109  fexp[i] = G4Exp(0.5*i);
110  }
111  logf += lz[i];
112  logfact[i] = logf;
113  }
114 }
115 
116 // -------------------------------------------------------------------
117 
118 G4Pow::~G4Pow()
119 {
120  delete fpInstance; fpInstance = 0;
121 }
122 
123 // -------------------------------------------------------------------
124 
126 {
127  if(std::abs(n) > 8) { return std::pow(x, G4double(n)); }
128  G4double res = 1.0;
129  if(n >= 0) { for(G4int i=0; i<n; ++i) { res *= x; } }
130  else if((n < 0) && (x != 0.0))
131  {
132  G4double y = 1.0/x;
133  G4int nn = -n;
134  for(G4int i=0; i<nn; ++i) { res *= y; }
135  }
136  return res;
137 }
static G4Pow * GetInstance()
Definition: G4Pow.cc:53
G4double powN(G4double x, G4int n) const
Definition: G4Pow.cc:125
Definition: G4Pow.hh:56
int G4int
Definition: G4Types.hh:78
const G4int n
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4bool IsWorkerThread()
Definition: G4Threading.cc:104
G4double G4Log(G4double x)
Definition: G4Log.hh:227
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
Definition: G4Exp.hh:180
double G4double
Definition: G4Types.hh:76