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 // 00027 // $Id$ 00028 // 00029 // 00030 //--------------------------------------------------------------- 00031 // GEANT 4 class header file 00032 // 00033 // G4PhysicsVector.hh 00034 // 00035 // Class description: 00036 // 00037 // A physics vector which has values of energy-loss, cross-section, 00038 // and other physics values of a particle in matter in a given 00039 // range of the energy, momentum, etc. 00040 // This class serves as the base class for a vector having various 00041 // energy scale, for example like 'log', 'linear', 'free', etc. 00042 00043 // History: 00044 // 02 Dec. 1995, G.Cosmo : Structure created based on object model 00045 // 03 Mar. 1996, K.Amako : Implemented the 1st version 00046 // 27 Apr. 1996, K.Amako : Cache mechanism added 00047 // 01 Jul. 1996, K.Amako : Now GetValue not virtual 00048 // 21 Sep. 1996, K.Amako : Added [] and () operators 00049 // 11 Nov. 2000, H.Kurashige : Use STL vector for dataVector and binVector 00050 // 09 Mar. 2001, H.Kurashige : Added G4PhysicsVectorType & Store/Retrieve() 00051 // 02 Apr. 2008, A.Bagulya : Added SplineInterpolation() and SetSpline() 00052 // 11 May 2009, V.Ivanchenko : Added ComputeSecondDerivatives 00053 // 19 Jun. 2009, V.Ivanchenko : Removed hidden bin 00054 // 22 Dec. 2009 H.Kurashige : Use pointers to G4PVDataVector 00055 // 04 May. 2010 H.Kurashige : Use G4PhysicsVectorCache 00056 // 28 May 2010 H.Kurashige : Stop using pointers to G4PVDataVector 00057 // 16 Aug. 2011 H.Kurashige : Add dBin, baseBin and verboseLevel 00058 //--------------------------------------------------------------- 00059 00060 #ifndef G4PhysicsVector_h 00061 #define G4PhysicsVector_h 1 00062 00063 #include "globals.hh" 00064 #include "G4ios.hh" 00065 00066 #include <iostream> 00067 #include <fstream> 00068 #include <vector> 00069 00070 #include "G4Allocator.hh" 00071 #include "G4PhysicsVectorCache.hh" 00072 #include "G4PhysicsVectorType.hh" 00073 00074 typedef std::vector<G4double> G4PVDataVector; 00075 00076 class G4PhysicsVector 00077 { 00078 public: // with description 00079 00080 G4PhysicsVector(G4bool spline = false); 00081 // constructor 00082 // This class is an abstract class with pure virtual method of 00083 // virtual size_t FindBinLocation(G4double theEnergy) const 00084 // So, default constructor is not supposed to be invoked explicitly 00085 00086 G4PhysicsVector(const G4PhysicsVector&); 00087 G4PhysicsVector& operator=(const G4PhysicsVector&); 00088 // Copy constructor and assignment operator. 00089 00090 virtual ~G4PhysicsVector(); 00091 // destructor 00092 00093 inline void* operator new(size_t); 00094 inline void operator delete(void*); 00095 00096 inline G4double Value(G4double theEnergy); 00097 // Get the cross-section/energy-loss value corresponding to the 00098 // given energy. An appropriate interpolation is used to calculate 00099 // the value. 00100 00101 inline G4double GetValue(G4double theEnergy, G4bool& isOutRange); 00102 // Obolete method to get value, isOutRange is not used anymore. 00103 // This method is kept for the compatibility reason. 00104 00105 G4int operator==(const G4PhysicsVector &right) const ; 00106 G4int operator!=(const G4PhysicsVector &right) const ; 00107 00108 inline G4double operator[](const size_t binNumber) const ; 00109 // Returns simply the value in the bin specified by 'binNumber' 00110 // of the dataVector. The boundary check will not be done. 00111 00112 inline G4double operator()(const size_t binNumber) const ; 00113 // Returns simply the value in the bin specified by 'binNumber' 00114 // of the dataVector. The boundary check will not be Done. 00115 00116 inline void PutValue(size_t index, G4double theValue); 00117 // Put 'theValue' into the bin specified by 'binNumber'. 00118 // Take note that the 'index' starts from '0'. 00119 // To fill the vector, you have beforehand to construct a vector 00120 // by the constructor with Emin, Emax, Nbin. 'theValue' should 00121 // be the crosssection/energyloss value corresponding to the 00122 // energy of the index. You can get this energy by the next method 00123 // or by the old method GetLowEdgeEnergy(). 00124 00125 virtual void ScaleVector(G4double factorE, G4double factorV); 00126 // Scale all values of the vector and second derivatives 00127 // by factorV, energies by vectorE. This method may be applied 00128 // for example after Retrieve a vector from an external file to 00129 // convert values into Geant4 units 00130 00131 inline G4double Energy(size_t index) const; 00132 // Returns simply the value in the energy specified by 'index' 00133 // of the energy vector. The boundary check will not be done. 00134 // Use this function when you fill physis vector by PutValue(). 00135 00136 inline G4double GetMaxEnergy() const; 00137 // Returns the energy of last point 00138 00139 virtual G4double GetLowEdgeEnergy(size_t binNumber) const; 00140 // Obsolete method 00141 // Get the energy value at the low edge of the specified bin. 00142 // Take note that the 'binNumber' starts from '0'. 00143 // This value should be defined before the call. 00144 // The boundary check will not be done. 00145 00146 inline size_t GetVectorLength() const; 00147 // Get the toal length (bin number) of the vector. 00148 00149 void FillSecondDerivatives(); 00150 // Initialise second derivatives for spline keeping 00151 // 3d derivative continues - default algorithm 00152 00153 void ComputeSecDerivatives(); 00154 // Initialise second derivatives for spline using algorithm 00155 // which garantee only 1st derivative continues 00156 // Warning: this method should be called when the vector 00157 // is already filled 00158 00159 void ComputeSecondDerivatives(G4double firstPointDerivative, 00160 G4double endPointDerivative); 00161 // Initialise second derivatives for spline using 00162 // user defined 1st derivatives at edge points 00163 // Warning: this method should be called when the vector 00164 // is already filled 00165 00166 inline G4bool IsFilledVectorExist() const; 00167 // Is non-empty physics vector already exist? 00168 00169 inline G4PhysicsVectorType GetType() const; 00170 // Get physics vector type 00171 00172 inline void SetSpline(G4bool); 00173 // Activate/deactivate Spline interpolation. 00174 00175 virtual G4bool Store(std::ofstream& fOut, G4bool ascii=false); 00176 virtual G4bool Retrieve(std::ifstream& fIn, G4bool ascii=false); 00177 // To store/retrieve persistent data to/from file streams. 00178 00179 friend std::ostream& operator<<(std::ostream&, const G4PhysicsVector&); 00180 00181 00182 inline G4double GetLastEnergy() const; 00183 inline G4double GetLastValue() const; 00184 inline size_t GetLastBin() const; 00185 // Get cache values 00186 00187 inline void SetVerboseLevel(G4int value); 00188 inline G4int GetVerboseLevel(G4int); 00189 // Set/Get Verbose level 00190 00191 protected: 00192 00193 virtual size_t FindBinLocation(G4double theEnergy) const=0; 00194 // Find the bin# in which theEnergy belongs - pure virtual function 00195 00196 void DeleteData(); 00197 void CopyData(const G4PhysicsVector& vec); 00198 // Internal methods for allowing copy of objects 00199 00200 protected: 00201 00202 G4PhysicsVectorType type; // The type of PhysicsVector (enumerator) 00203 00204 G4double edgeMin; // Energy of first point 00205 G4double edgeMax; // Energy of the last point 00206 00207 size_t numberOfNodes; 00208 00209 G4PhysicsVectorCache* cache; 00210 00211 G4PVDataVector dataVector; // Vector to keep the crossection/energyloss 00212 G4PVDataVector binVector; // Vector to keep energy 00213 G4PVDataVector secDerivative; // Vector to keep second derivatives 00214 00215 private: 00216 00217 void ComputeValue(G4double theEnergy); 00218 00219 G4bool SplinePossible(); 00220 00221 inline G4double LinearInterpolation(G4int lastBin); 00222 // Linear interpolation function 00223 inline G4double SplineInterpolation(G4int lastBin); 00224 // Spline interpolation function 00225 00226 inline void Interpolation(G4int lastBin); 00227 00228 G4bool useSpline; 00229 00230 protected: 00231 G4double dBin; // Bin width - useful only for fixed binning 00232 G4double baseBin; // Set this in constructor for performance 00233 00234 G4int verboseLevel; 00235 }; 00236 00237 #include "G4PhysicsVector.icc" 00238 00239 #endif