G4Pow.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // $Id: G4Pow.cc 69381 2013-05-02 09:58:14Z gcosmo $
00027 //
00028 // -------------------------------------------------------------------
00029 //
00030 // GEANT4 Class file
00031 //
00032 //
00033 // File name:     G4Pow
00034 //
00035 // Author:        Vladimir Ivanchenko
00036 //
00037 // Creation date: 23.05.2009
00038 //
00039 // Modifications:
00040 // 08.01.2011 V.Ivanchenko extended maxZ from 256 to 512
00041 //
00042 // -------------------------------------------------------------------
00043 
00044 #include "G4Pow.hh"
00045 
00046 G4Pow* G4Pow::fpInstance = 0;
00047 
00048 // -------------------------------------------------------------------
00049 
00050 G4Pow* G4Pow::GetInstance()
00051 {
00052   if (fpInstance == 0)
00053   {
00054     fpInstance = new G4Pow;
00055   }
00056   return fpInstance;
00057 }
00058 
00059 // -------------------------------------------------------------------
00060 
00061 G4Pow::G4Pow()
00062   : onethird(1.0/3.0), minA(0.5000001), maxA(255.5)
00063 {
00064   const G4int maxZ = 512; 
00065   const G4int maxZfact = 170; 
00066 
00067   pz13.resize(maxZ,0.0);
00068   lz.resize(maxZ,0.0);
00069   fact.resize(maxZfact,0.0);
00070   logfact.resize(maxZ,0.0);
00071 
00072   G4double f = 1.0;
00073   G4double logf = 0.0;
00074   fact[0] = 1.0;
00075 
00076   for(G4int i=1; i<maxZ; ++i)
00077   {
00078     G4double x  = G4double(i);
00079     pz13[i] = std::pow(x,onethird);
00080     lz[i]   = std::log(x);
00081     if(i < maxZfact)
00082     { 
00083       f *= x; 
00084       fact[i] = f;
00085     }
00086     logf += lz[i];
00087     logfact[i] = logf;
00088   }
00089 }
00090 
00091 // -------------------------------------------------------------------
00092 
00093 G4Pow::~G4Pow()
00094 {
00095   delete fpInstance; fpInstance = 0;
00096 }
00097 
00098 // -------------------------------------------------------------------
00099 
00100 G4double G4Pow::powN(G4double x, G4int n)
00101 {
00102   if(std::abs(n) > 8) { return std::pow(x, G4double(n)); }
00103   G4double res = 1.0;
00104   if(n >= 0) { for(G4int i=0; i<n; ++i) { res *= x; } }
00105   else if((n < 0) && (x != 0.0))
00106   {
00107     G4double y = 1.0/x;
00108     G4int nn = -n;
00109     for(G4int i=0; i<nn; ++i) { res *= y; }
00110   }
00111   return res;
00112 }

Generated on Mon May 27 17:49:24 2013 for Geant4 by  doxygen 1.4.7