Geant4  10.02
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 
52 
53 // -------------------------------------------------------------------
54 
56 {
57  if (fpInstance == 0)
58  {
59  static G4Pow geant4pow;
60  fpInstance = &geant4pow;
61  }
62  return fpInstance;
63 }
64 
65 // -------------------------------------------------------------------
66 
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
G4DataVector fact
Definition: G4Pow.hh:121
G4double maxAexp
Definition: G4Pow.hh:113
~G4Pow()
Definition: G4Pow.cc:123
G4double powN(G4double x, G4int n) const
Definition: G4Pow.cc:128
Definition: G4Pow.hh:56
const G4double onethird
Definition: G4Pow.hh:108
int G4int
Definition: G4Types.hh:78
G4double maxA2
Definition: G4Pow.hh:112
G4DataVector pz13
Definition: G4Pow.hh:117
static G4Pow * fpInstance
Definition: G4Pow.hh:106
G4DataVector logfact
Definition: G4Pow.hh:122
const G4int max2
Definition: G4Pow.hh:109
G4double maxA
Definition: G4Pow.hh:111
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:129
G4double G4Log(G4double x)
Definition: G4Log.hh:230
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
Definition: G4Exp.hh:183
G4DataVector fexp
Definition: G4Pow.hh:120
G4DataVector ener
Definition: G4Pow.hh:115
const G4double x[NPOINTSGL]
G4Pow()
Definition: G4Pow.cc:67
double G4double
Definition: G4Types.hh:76
G4DataVector logen
Definition: G4Pow.hh:116
G4DataVector lz2
Definition: G4Pow.hh:119
G4DataVector lz
Definition: G4Pow.hh:118