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

Last change on this file since 1202 was 1197, checked in by garnier, 15 years ago

nvx fichiers dans CVS

File size: 4.4 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.2 2009/07/03 11:35:07 vnivanch Exp $
27// GEANT4 tag $Name: global-V09-02-10 $
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
38
39// Author: Vladimir Ivanchenko
40//
41// Creation date: 23.05.2009
42// -------------------------------------------------------------------
43
44#ifndef G4Pow_h
45#define G4Pow_h 1
46
47#include "globals.hh"
48#include "G4DataVector.hh"
49
50class G4Pow
51{
52
53  public:
54
55    static G4Pow* GetInstance();
56
57    // Fast computation of Z^1/3
58    //
59    inline G4double Z13(G4int Z);
60    inline G4double A13(G4double A);
61
62    // Fast computation of Z^2/3
63    //
64    inline G4double Z23(G4int Z);
65    inline G4double A23(G4double A);
66
67    // Fast computation of log(Z)
68    //
69    inline G4double logZ(G4int Z);
70    inline G4double logA(G4double A);
71
72    // Fast computation of log10(Z)
73    //
74    inline G4double log10Z(G4int Z);
75    inline G4double log10A(G4double A);
76
77    // Fast computation of pow(Z,X)
78    //
79    inline G4double powZ(G4int Z, G4double y);
80    inline G4double powA(G4double A, G4double y);
81
82    // Fast factorial
83    //
84    inline G4double factorial(G4int Z);
85
86  private:
87
88    G4Pow();
89   ~G4Pow();
90
91  private:
92
93    static G4Pow* fInstance;
94
95    G4double onethird;
96
97    G4DataVector pz13;
98    G4DataVector lz;
99    G4DataVector fact;
100};
101
102// -------------------------------------------------------------------
103
104inline G4double G4Pow::Z13(G4int Z)
105{
106  return pz13[Z];
107}
108
109inline G4double G4Pow::A13(G4double A)
110{
111  const G4int maxZ = 256; 
112
113  G4double res;
114  G4int i = G4int(A + 0.5);
115  if((i >= 1) && (i < maxZ))
116  {
117    G4double x = (1.0 - A/G4double(i))*onethird;
118    res = pz13[i]*(1.0 + x - x*x*(1.0 - 1.66666666*x));
119  }
120  else
121  {
122    res = std::pow(A, onethird); 
123  }
124  return res;
125}
126
127inline G4double G4Pow::Z23(G4int Z)
128{
129  G4double x = Z13(Z);
130  return x*x;
131}
132
133inline G4double G4Pow::A23(G4double A)
134{
135  G4double x = A13(A);
136  return x*x;
137}
138
139inline G4double G4Pow::logZ(G4int Z)
140{
141  return lz[Z];
142}
143
144inline G4double G4Pow::logA(G4double A)
145{
146  const G4int maxZ = 256;
147
148  G4double res;
149  G4int i = G4int(A + 0.5);
150  if((i >= 1) && (i < maxZ))
151  {
152    G4double x = 1.0 - A/G4double(i);
153    res = lz[i] + x*(1.0 - 0.5*x + onethird*x*x);
154  }
155  else
156  {
157    res = std::log(A);
158  }
159  return res;
160}
161
162inline G4double G4Pow::log10Z(G4int Z)
163{
164  return lz[Z]/lz[10];
165}
166
167inline G4double G4Pow::log10A(G4double A)
168{
169  return logA(A)/lz[10];
170}
171
172inline G4double G4Pow::powZ(G4int Z, G4double y)
173{
174  return std::exp(y*lz[Z]);
175}
176
177inline G4double G4Pow::powA(G4double A, G4double y)
178{
179  return std::exp(y*logA(A));
180}
181
182inline G4double G4Pow::factorial(G4int Z)
183{
184  return fact[Z];
185}
186
187// -------------------------------------------------------------------
188
189#endif
190
Note: See TracBrowser for help on using the repository browser.