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

Last change on this file since 1340 was 1340, checked in by garnier, 14 years ago

update ti head

File size: 4.9 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.7 2010/08/24 08:12:08 gcosmo Exp $
27// GEANT4 tag $Name: global-V09-03-22 $
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           G4double powN(G4double x, G4int n);
85
86    // Fast factorial
87    //
88    inline G4double factorial(G4int Z);
89    inline G4double logfactorial(G4int Z);
90
91  private:
92
93    G4Pow();
94   ~G4Pow();
95
96  private:
97
98    static G4Pow* fInstance;
99
100    G4double onethird;
101
102    G4DataVector pz13;
103    G4DataVector lz;
104    G4DataVector fact;
105    G4DataVector logfact;
106};
107
108// -------------------------------------------------------------------
109
110inline G4double G4Pow::Z13(G4int Z)
111{
112  return pz13[Z];
113}
114
115inline G4double G4Pow::A13(G4double A)
116{
117  const G4double minA = 0.5000001; 
118  const G4double maxA = 255.5; 
119
120  G4double res;
121  if((A >= minA) && (A <= maxA))
122  {
123    G4int i = G4int(A + 0.5);
124    G4double x = (1.0 - A/G4double(i))*onethird;
125    res = pz13[i]*(1.0 + x - x*x*(1.0 - 1.66666666*x));
126  }
127  else
128  {
129    res = std::pow(A, onethird); 
130  }
131  return res;
132}
133
134inline G4double G4Pow::Z23(G4int Z)
135{
136  G4double x = Z13(Z);
137  return x*x;
138}
139
140inline G4double G4Pow::A23(G4double A)
141{
142  G4double x = A13(A);
143  return x*x;
144}
145
146inline G4double G4Pow::logZ(G4int Z)
147{
148  return lz[Z];
149}
150
151inline G4double G4Pow::logA(G4double A)
152{
153  const G4double minA = 0.5000001; 
154  const G4double maxA = 255.5; 
155
156  G4double res;
157  if((A >= minA) && (A <= maxA))
158  {
159    G4int i = G4int(A + 0.5);
160    G4double x = 1.0 - A/G4double(i);
161    res = lz[i] + x*(1.0 - 0.5*x + onethird*x*x);
162  }
163  else
164  {
165    res = std::log(A);
166  }
167  return res;
168}
169
170inline G4double G4Pow::log10Z(G4int Z)
171{
172  return lz[Z]/lz[10];
173}
174
175inline G4double G4Pow::log10A(G4double A)
176{
177  return logA(A)/lz[10];
178}
179
180inline G4double G4Pow::powZ(G4int Z, G4double y)
181{
182  return std::exp(y*lz[Z]);
183}
184
185inline G4double G4Pow::powA(G4double A, G4double y)
186{
187  return std::exp(y*logA(A));
188}
189
190inline G4double G4Pow::factorial(G4int Z)
191{
192  return fact[Z];
193}
194
195inline G4double G4Pow::logfactorial(G4int Z)
196{
197  return logfact[Z];
198}
199
200// -------------------------------------------------------------------
201
202#endif
203
Note: See TracBrowser for help on using the repository browser.