Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4PhysicsVector << 27 // 26 // 28 // Class description: << 27 // $Id: G4PhysicsVector.hh,v 1.31 2010-05-28 05:13:43 kurasige Exp $ >> 28 // GEANT4 tag $Name: not supported by cvs2svn $ 29 // 29 // 30 // A physics vector which has values of energy << 30 // 31 // and other physics values of a particle in m << 31 //--------------------------------------------------------------- 32 // range of energy, momentum, etc. << 32 // GEANT 4 class header file 33 // This class serves as the base class for a v << 33 // 34 // energy scale, for example like 'log', 'line << 34 // G4PhysicsVector.hh 35 << 35 // 36 // Authors: << 36 // Class description: 37 // - 02 Dec. 1995, G.Cosmo: Structure created << 37 // 38 // - 03 Mar. 1996, K.Amako: Implemented the 1s << 38 // A physics vector which has values of energy-loss, cross-section, 39 // Revisions: << 39 // and other physics values of a particle in matter in a given 40 // - 11 Nov. 2000, H.Kurashige: Use STL vector << 40 // range of the energy, momentum, etc. 41 // ------------------------------------------- << 41 // This class serves as the base class for a vector having various 42 #ifndef G4PhysicsVector_hh << 42 // energy scale, for example like 'log', 'linear', 'free', etc. 43 #define G4PhysicsVector_hh 1 << 43 >> 44 // History: >> 45 // 02 Dec. 1995, G.Cosmo : Structure created based on object model >> 46 // 03 Mar. 1996, K.Amako : Implemented the 1st version >> 47 // 27 Apr. 1996, K.Amako : Cache mechanism added >> 48 // 01 Jul. 1996, K.Amako : Now GetValue not virtual >> 49 // 21 Sep. 1996, K.Amako : Added [] and () operators >> 50 // 11 Nov. 2000, H.Kurashige : Use STL vector for dataVector and binVector >> 51 // 09 Mar. 2001, H.Kurashige : Added G4PhysicsVectorType & Store/Retrieve() >> 52 // 02 Apr. 2008, A.Bagulya : Added SplineInterpolation() and SetSpline() >> 53 // 11 May 2009, V.Ivanchenko : Added ComputeSecondDerivatives >> 54 // 19 Jun. 2009, V.Ivanchenko : Removed hidden bin >> 55 // 22 Dec. 2009 H.Kurashige : Use pointers to G4PVDataVector >> 56 // 04 May. 2010 H.Kurashige : Use G4PhysicsVectorCache >> 57 // 28 May 2010 H.Kurashige : Stop using pointers to G4PVDataVector >> 58 // 16 Aug. 2011 H.Kurashige : Add dBin, baseBin and verboseLevel >> 59 //--------------------------------------------------------------- >> 60 >> 61 #ifndef G4PhysicsVector_h >> 62 #define G4PhysicsVector_h 1 >> 63 >> 64 #include "globals.hh" >> 65 #include "G4ios.hh" 44 66 45 #include <fstream> << 46 #include <iostream> 67 #include <iostream> >> 68 #include <fstream> 47 #include <vector> 69 #include <vector> 48 70 49 #include "G4Log.hh" << 71 #include "G4Allocator.hh" >> 72 #include "G4PhysicsVectorCache.hh" 50 #include "G4PhysicsVectorType.hh" 73 #include "G4PhysicsVectorType.hh" 51 #include "G4ios.hh" << 52 #include "globals.hh" << 53 74 54 class G4PhysicsVector << 75 typedef std::vector<G4double> G4PVDataVector; >> 76 >> 77 class G4PhysicsVector 55 { 78 { 56 public: << 79 public: // with description 57 // Default constructor - vector will be fill << 80 58 // Free vector may be filled via InsertValue << 81 G4PhysicsVector(G4bool spline = false); 59 explicit G4PhysicsVector(G4bool spline = fal << 82 // constructor 60 << 83 // This class is an abstract class with pure virtual method of 61 // Copy constructor and assignment operator << 84 // virtual size_t FindBinLocation(G4double theEnergy) const 62 G4PhysicsVector(const G4PhysicsVector&) = de << 85 // So, default constructor is not supposed to be invoked explicitly 63 G4PhysicsVector& operator=(const G4PhysicsVe << 86 64 << 87 G4PhysicsVector(const G4PhysicsVector&); 65 // not used operators << 88 G4PhysicsVector& operator=(const G4PhysicsVector&); 66 G4PhysicsVector(const G4PhysicsVector&&) = d << 89 // Copy constructor and assignment operator. 67 G4PhysicsVector& operator=(const G4PhysicsVe << 90 68 G4bool operator==(const G4PhysicsVector& rig << 91 virtual ~G4PhysicsVector(); 69 G4bool operator!=(const G4PhysicsVector& rig << 92 // destructor 70 << 93 71 virtual ~G4PhysicsVector() = default; << 94 inline void* operator new(size_t); 72 << 95 inline void operator delete(void*); 73 // Get the cross-section/energy-loss value c << 96 74 // given energy. An appropriate interpolatio << 97 inline G4double Value(G4double theEnergy); 75 // the value. Consumer code gets changed ind << 98 // Get the cross-section/energy-loss value corresponding to the 76 // for the next call to save CPU for bin loc << 99 // given energy. An appropriate interpolation is used to calculate 77 inline G4double Value(const G4double energy, << 100 // the value. 78 << 101 79 // Get the cross-section/energy-loss value c << 102 inline G4double GetValue(G4double theEnergy, G4bool& isOutRange); 80 // given energy. An appropriate interpolatio << 103 // Obolete method to get value, isOutRange is not used anymore. 81 // the value. This method should be used if << 104 // This method is kept for the compatibility reason. 82 // kept in the user code. << 105 83 inline G4double Value(const G4double energy) << 106 G4int operator==(const G4PhysicsVector &right) const ; 84 << 107 G4int operator!=(const G4PhysicsVector &right) const ; 85 // Obsolete method to get value, 'isOutRange << 108 86 // This method is kept for the compatibility << 109 inline G4double operator[](const size_t binNumber) const ; 87 inline G4double GetValue(const G4double ener << 110 // Returns simply the value in the bin specified by 'binNumber' 88 << 111 // of the dataVector. The boundary check will not be done. 89 // Same as the Value() method above but spec << 112 90 // Note, unlike the general Value() method a << 113 inline G4double operator()(const size_t binNumber) const ; 91 // properly only for G4PhysicsLogVector. << 114 // Returns simply the value in the bin specified by 'binNumber' 92 inline G4double LogVectorValue(const G4doubl << 115 // of the dataVector. The boundary check will not be Done. 93 const G4doubl << 116 94 << 117 inline void PutValue(size_t index, G4double theValue); 95 // Same as the Value() method above but spec << 118 // Put 'theValue' into the bin specified by 'binNumber'. 96 // with logarithmic seach of bin number << 119 // Take note that the 'index' starts from '0'. 97 inline G4double LogFreeVectorValue(const G4d << 120 // To fill the vector, you have beforehand to construct a vector 98 const G4d << 121 // by the constructor with Emin, Emax, Nbin. 'theValue' should 99 << 122 // be the crosssection/energyloss value corresponding to the 100 // Returns the value for the specified index << 123 // energy of the index. You can get this energy by the next method 101 // The boundary check will not be done << 124 // or by the old method GetLowEdgeEnergy(). 102 inline G4double operator[](const std::size_t << 125 103 inline G4double operator()(const std::size_t << 126 virtual void ScaleVector(G4double factorE, G4double factorV); 104 << 127 // Scale all values of the vector and second derivatives 105 // Put data into the vector at 'index' posit << 128 // by factorV, energies by vectorE. This method may be applied 106 // Take note that the 'index' starts from '0 << 129 // for example after Retrieve a vector from an external file to 107 // It is assumed that energies are already f << 130 // convert values into Geant4 units 108 inline void PutValue(const std::size_t index << 131 109 << 132 inline G4double Energy(size_t index) const; 110 // Returns the value in the energy specified << 133 // Returns simply the value in the energy specified by 'index' 111 // of the energy vector. The boundary check << 134 // of the energy vector. The boundary check will not be done. 112 // Use this when compute cross-section, dEdx << 135 // Use this function when you fill physis vector by PutValue(). 113 // before filling the vector by PutValue(). << 136 114 inline G4double Energy(const std::size_t ind << 137 inline G4double GetMaxEnergy() const; 115 inline G4double GetLowEdgeEnergy(const std:: << 138 // Returns the energy of last point 116 << 139 117 // Returns the energy of the first and the l << 140 virtual G4double GetLowEdgeEnergy(size_t binNumber) const; 118 inline G4double GetMinEnergy() const; << 141 // Obsolete method 119 inline G4double GetMaxEnergy() const; << 142 // Get the energy value at the low edge of the specified bin. 120 << 143 // Take note that the 'binNumber' starts from '0'. 121 // Returns the data of the first and the las << 144 // This value should be defined before the call. 122 // If the vector is empty returns zeros. << 145 // The boundary check will not be done. 123 inline G4double GetMinValue() const; << 146 124 inline G4double GetMaxValue() const; << 147 inline size_t GetVectorLength() const; 125 << 148 // Get the toal length (bin number) of the vector. 126 // Get the total length of the vector << 149 127 inline std::size_t GetVectorLength() const; << 150 void FillSecondDerivatives(); 128 << 151 // Initialise second derivatives for spline keeping 129 // Computes the lower index the energy bin i << 152 // 3d derivative continues - default algorithm 130 // in case of vectors with equal bin widths << 153 131 // Note, that no check on the boundary is pe << 154 void ComputeSecDerivatives(); 132 inline std::size_t ComputeLogVectorBin(const << 155 // Initialise second derivatives for spline using algorithm 133 << 156 // which garantee only 1st derivative continues 134 // Get physics vector type. << 157 // Warning: this method should be called when the vector 135 inline G4PhysicsVectorType GetType() const; << 158 // is already filled 136 << 159 137 // True if using spline interpolation. << 160 void ComputeSecondDerivatives(G4double firstPointDerivative, 138 inline G4bool GetSpline() const; << 161 G4double endPointDerivative); 139 << 162 // Initialise second derivatives for spline using 140 // Define verbosity level. << 163 // user defined 1st derivatives at edge points 141 inline void SetVerboseLevel(G4int value); << 164 // Warning: this method should be called when the vector 142 << 165 // is already filled 143 // Find energy using linear interpolation fo << 166 144 // filled by cumulative probability function << 167 inline G4bool IsFilledVectorExist() const; 145 // Assuming that vector is already filled. << 168 // Is non-empty physics vector already exist? 146 inline G4double FindLinearEnergy(const G4dou << 169 147 << 170 inline void PutComment(const G4String& theComment); 148 // Find low edge index of a bin for given en << 171 // Put a comment to the G4PhysicsVector. This may help to check 149 // Min value 0, max value idxmax. << 172 // whether your are accessing to the one you want. 150 std::size_t FindBin(const G4double energy, s << 173 151 << 174 inline const G4String& GetComment() const; 152 // Scale all values of the vector by factorV << 175 // Retrieve the comment of the G4PhysicsVector. 153 // AFter this method FillSecondDerivatives(. << 176 154 // This method may be applied for example af << 177 inline G4PhysicsVectorType GetType() const; 155 // from an external file to convert values i << 178 // Get physics vector type 156 void ScaleVector(const G4double factorE, con << 179 157 << 180 inline void SetSpline(G4bool); 158 // This method should be called when the vec << 181 // Activate/deactivate Spline interpolation. 159 // There are 3 types of second derivative co << 182 160 // fSplineSimple - 2d derivative cont << 183 virtual G4bool Store(std::ofstream& fOut, G4bool ascii=false); 161 // fSplineBase - 3d derivative cont << 184 virtual G4bool Retrieve(std::ifstream& fIn, G4bool ascii=false); 162 // fSplineFixedEdges - 3d derivatives con << 185 // To store/retrieve persistent data to/from file streams. 163 // derivatives are fi << 186 164 void FillSecondDerivatives(const G4SplineTyp << 187 friend std::ostream& operator<<(std::ostream&, const G4PhysicsVector&); 165 const G4double di << 188 166 const G4double di << 189 167 << 190 inline G4double GetLastEnergy() const; 168 // This method can be applied if both energy << 191 inline G4double GetLastValue() const; 169 // grow monotonically, for example, if in th << 192 inline size_t GetLastBin() const; 170 // cumulative probability density function i << 193 // Get cache values 171 G4double GetEnergy(const G4double value) con << 194 172 << 195 inline void SetVerboseLevel(G4int value); 173 // To store/retrieve persistent data to/from << 196 inline G4int GetVerboseLevel(G4int); 174 G4bool Store(std::ofstream& fOut, G4bool asc << 197 // Set/Get Verbose level 175 G4bool Retrieve(std::ifstream& fIn, G4bool a << 198 176 << 199 protected: 177 // Print vector << 200 178 friend std::ostream& operator<<(std::ostream << 201 virtual size_t FindBinLocation(G4double theEnergy) const=0; 179 void DumpValues(G4double unitE = 1.0, G4doub << 202 // Find the bin# in which theEnergy belongs - pure virtual function 180 << 203 181 protected: << 204 void DeleteData(); 182 << 205 void CopyData(const G4PhysicsVector& vec); 183 // The default implements a free vector init << 206 // Internal methods for allowing copy of objects 184 virtual void Initialise(); << 207 185 << 208 protected: 186 void PrintPutValueError(std::size_t index, G << 209 187 const G4String& text << 210 G4PhysicsVectorType type; // The type of PhysicsVector (enumerator) 188 << 211 189 private: << 212 G4double edgeMin; // Energy of first point 190 << 213 G4double edgeMax; // Energy of the last point 191 void ComputeSecDerivative0(); << 214 192 void ComputeSecDerivative1(); << 215 size_t numberOfNodes; 193 void ComputeSecDerivative2(const G4double fi << 216 194 const G4double en << 217 G4PhysicsVectorCache* cache; 195 // Internal methods for computing of spline << 218 196 << 219 G4PVDataVector dataVector; // Vector to keep the crossection/energyloss 197 // Linear or spline interpolation. << 220 G4PVDataVector binVector; // Vector to keep energy 198 inline G4double Interpolation(const std::siz << 221 G4PVDataVector secDerivative; // Vector to keep second derivatives 199 const G4double << 222 200 << 223 private: 201 // Assuming (edgeMin <= energy <= edgeMax). << 224 202 inline std::size_t LogBin(const G4double ene << 225 void ComputeValue(G4double theEnergy); 203 inline std::size_t BinaryBin(const G4double << 226 204 inline std::size_t GetBin(const G4double ene << 227 G4bool SplinePossible(); 205 << 228 206 protected: << 229 inline G4double LinearInterpolation(G4int lastBin); 207 << 230 // Linear interpolation function 208 G4double edgeMin = 0.0; // Energy of first << 231 inline G4double SplineInterpolation(G4int lastBin); 209 G4double edgeMax = 0.0; // Energy of the la << 232 // Spline interpolation function 210 << 233 211 G4double invdBin = 0.0; // 1/Bin width for << 234 inline void Interpolation(G4int lastBin); 212 G4double logemin = 0.0; // used only for lo << 235 213 << 236 G4String comment; 214 G4double iBin1 = 0.0; // 1/Bin width for sc << 237 G4bool useSpline; 215 G4double lmin1 = 0.0; // used for log searc << 216 << 217 G4int verboseLevel = 0; << 218 std::size_t idxmax = 0; << 219 std::size_t imax1 = 0; << 220 std::size_t numberOfNodes = 0; << 221 std::size_t nLogNodes = 0; << 222 << 223 G4PhysicsVectorType type = T_G4PhysicsFreeVe << 224 // The type of PhysicsVector (enumerator) << 225 << 226 std::vector<G4double> binVector; // ene << 227 std::vector<G4double> dataVector; // cro << 228 std::vector<G4double> secDerivative; // sec << 229 std::vector<std::size_t> scale; // log << 230 238 231 private: << 239 protected: >> 240 G4double dBin; // Bin width - useful only for fixed binning >> 241 G4double baseBin; // Set this in constructor for performance 232 242 233 G4bool useSpline = false; << 243 G4int verboseLevel; 234 }; 244 }; 235 245 236 #include "G4PhysicsVector.icc" 246 #include "G4PhysicsVector.icc" 237 247 238 #endif 248 #endif 239 249