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$ 29 // 28 // 30 // A physics vector which has values of energy << 29 // 31 // and other physics values of a particle in m << 30 //--------------------------------------------------------------- 32 // range of energy, momentum, etc. << 31 // GEANT 4 class header file 33 // This class serves as the base class for a v << 32 // 34 // energy scale, for example like 'log', 'line << 33 // G4PhysicsVector.hh 35 << 34 // 36 // Authors: << 35 // Class description: 37 // - 02 Dec. 1995, G.Cosmo: Structure created << 36 // 38 // - 03 Mar. 1996, K.Amako: Implemented the 1s << 37 // A physics vector which has values of energy-loss, cross-section, 39 // Revisions: << 38 // and other physics values of a particle in matter in a given 40 // - 11 Nov. 2000, H.Kurashige: Use STL vector << 39 // range of the energy, momentum, etc. 41 // ------------------------------------------- << 40 // This class serves as the base class for a vector having various 42 #ifndef G4PhysicsVector_hh << 41 // energy scale, for example like 'log', 'linear', 'free', etc. 43 #define G4PhysicsVector_hh 1 << 42 >> 43 // History: >> 44 // 02 Dec. 1995, G.Cosmo : Structure created based on object model >> 45 // 03 Mar. 1996, K.Amako : Implemented the 1st version >> 46 // 27 Apr. 1996, K.Amako : Cache mechanism added >> 47 // 01 Jul. 1996, K.Amako : Now GetValue not virtual >> 48 // 21 Sep. 1996, K.Amako : Added [] and () operators >> 49 // 11 Nov. 2000, H.Kurashige : Use STL vector for dataVector and binVector >> 50 // 09 Mar. 2001, H.Kurashige : Added G4PhysicsVectorType & Store/Retrieve() >> 51 // 02 Apr. 2008, A.Bagulya : Added SplineInterpolation() and SetSpline() >> 52 // 11 May 2009, V.Ivanchenko : Added ComputeSecondDerivatives >> 53 // 19 Jun. 2009, V.Ivanchenko : Removed hidden bin >> 54 // 22 Dec. 2009 H.Kurashige : Use pointers to G4PVDataVector >> 55 // 04 May. 2010 H.Kurashige : Use G4PhysicsVectorCache >> 56 // 28 May 2010 H.Kurashige : Stop using pointers to G4PVDataVector >> 57 // 16 Aug. 2011 H.Kurashige : Add dBin, baseBin and verboseLevel >> 58 // 02 Oct. 2013 V.Ivanchenko : FindBinLocation method become inlined; >> 59 // instead of G4Pow G4Log is used >> 60 //--------------------------------------------------------------- >> 61 >> 62 #ifndef G4PhysicsVector_h >> 63 #define G4PhysicsVector_h 1 44 64 45 #include <fstream> << 46 #include <iostream> 65 #include <iostream> >> 66 #include <fstream> 47 #include <vector> 67 #include <vector> 48 68 49 #include "G4Log.hh" << 50 #include "G4PhysicsVectorType.hh" << 51 #include "G4ios.hh" << 52 #include "globals.hh" 69 #include "globals.hh" >> 70 #include "G4ios.hh" >> 71 #include "G4PhysicsVectorType.hh" >> 72 #include "G4Log.hh" >> 73 >> 74 typedef std::vector<G4double> G4PVDataVector; 53 75 54 class G4PhysicsVector << 76 class G4PhysicsVector 55 { 77 { 56 public: << 78 public:// with description 57 // Default constructor - vector will be fill << 79 58 // Free vector may be filled via InsertValue << 80 explicit G4PhysicsVector(G4bool spline = false); 59 explicit G4PhysicsVector(G4bool spline = fal << 81 // default constructor - vector will be filled via Retrieve() method 60 << 82 61 // Copy constructor and assignment operator << 83 G4PhysicsVector(const G4PhysicsVector&); 62 G4PhysicsVector(const G4PhysicsVector&) = de << 84 G4PhysicsVector& operator=(const G4PhysicsVector&); 63 G4PhysicsVector& operator=(const G4PhysicsVe << 85 // Copy constructor and assignment operator. 64 << 86 65 // not used operators << 87 virtual ~G4PhysicsVector(); 66 G4PhysicsVector(const G4PhysicsVector&&) = d << 88 67 G4PhysicsVector& operator=(const G4PhysicsVe << 89 G4double Value(G4double theEnergy, size_t& lastidx) const; 68 G4bool operator==(const G4PhysicsVector& rig << 90 // Get the cross-section/energy-loss value corresponding to the 69 G4bool operator!=(const G4PhysicsVector& rig << 91 // given energy. An appropriate interpolation is used to calculate 70 << 92 // the value. Consumer code got changed index and may reuse it 71 virtual ~G4PhysicsVector() = default; << 93 // for the next call to save CPU for bin location. 72 << 94 73 // Get the cross-section/energy-loss value c << 95 inline G4double Value(G4double theEnergy) const; 74 // given energy. An appropriate interpolatio << 96 // Get the cross-section/energy-loss value corresponding to the 75 // the value. Consumer code gets changed ind << 97 // given energy. An appropriate interpolation is used to calculate 76 // for the next call to save CPU for bin loc << 98 // the value. This method is kept for backward compatibility reason, 77 inline G4double Value(const G4double energy, << 99 // it should be used instead of the previous method if bin location 78 << 100 // cannot be kept thread safe 79 // Get the cross-section/energy-loss value c << 101 80 // given energy. An appropriate interpolatio << 102 inline G4double GetValue(G4double theEnergy, G4bool& isOutRange) const; 81 // the value. This method should be used if << 103 // Obsolete method to get value, isOutRange is not used anymore. 82 // kept in the user code. << 104 // This method is kept for the compatibility reason. 83 inline G4double Value(const G4double energy) << 105 84 << 106 G4int operator==(const G4PhysicsVector &right) const ; 85 // Obsolete method to get value, 'isOutRange << 107 G4int operator!=(const G4PhysicsVector &right) const ; 86 // This method is kept for the compatibility << 108 87 inline G4double GetValue(const G4double ener << 109 inline G4double operator[](const size_t index) const ; 88 << 110 // Returns the value for the specified index of the dataVector 89 // Same as the Value() method above but spec << 111 // The boundary check will not be done. 90 // Note, unlike the general Value() method a << 112 91 // properly only for G4PhysicsLogVector. << 113 inline G4double operator()(const size_t index) const ; 92 inline G4double LogVectorValue(const G4doubl << 114 // Returns the value for the specified index of the dataVector 93 const G4doubl << 115 // The boundary check will not be done. 94 << 116 95 // Same as the Value() method above but spec << 117 inline void PutValue(size_t index, G4double theValue); 96 // with logarithmic seach of bin number << 118 // Put 'theValue' into the dataVector specified by 'index'. 97 inline G4double LogFreeVectorValue(const G4d << 119 // Take note that the 'index' starts from '0'. 98 const G4d << 120 // To fill the vector, you have beforehand to construct a vector 99 << 121 // by the constructor with Emin, Emax, Nbin. 'theValue' should 100 // Returns the value for the specified index << 122 // be the crosssection/energyloss value corresponding to the 101 // The boundary check will not be done << 123 // energy of the index. 102 inline G4double operator[](const std::size_t << 124 103 inline G4double operator()(const std::size_t << 125 virtual void ScaleVector(G4double factorE, G4double factorV); 104 << 126 // Scale all values of the vector and second derivatives 105 // Put data into the vector at 'index' posit << 127 // by factorV, energies by vectorE. This method may be applied 106 // Take note that the 'index' starts from '0 << 128 // for example after Retrieve a vector from an external file to 107 // It is assumed that energies are already f << 129 // convert values into Geant4 units 108 inline void PutValue(const std::size_t index << 130 109 << 131 inline G4double Energy(size_t index) const; 110 // Returns the value in the energy specified << 132 // Returns the value in the energy specified by 'index' 111 // of the energy vector. The boundary check << 133 // of the energy vector. The boundary check will not be done. 112 // Use this when compute cross-section, dEdx << 134 // Use this function when compute cross section or dEdx 113 // before filling the vector by PutValue(). << 135 // before filling the vector by PutValue(..). 114 inline G4double Energy(const std::size_t ind << 136 115 inline G4double GetLowEdgeEnergy(const std:: << 137 inline G4double GetMaxEnergy() const; 116 << 138 // Returns the energy of the last point of the vector 117 // Returns the energy of the first and the l << 139 118 inline G4double GetMinEnergy() const; << 140 G4double GetLowEdgeEnergy(size_t binNumber) const; 119 inline G4double GetMaxEnergy() const; << 141 // Obsolete method 120 << 142 // Get the energy value at the low edge of the specified bin. 121 // Returns the data of the first and the las << 143 // Take note that the 'binNumber' starts from '0'. 122 // If the vector is empty returns zeros. << 144 // The boundary check will not be done. 123 inline G4double GetMinValue() const; << 145 124 inline G4double GetMaxValue() const; << 146 inline size_t GetVectorLength() const; 125 << 147 // Get the total length of the vector. 126 // Get the total length of the vector << 148 127 inline std::size_t GetVectorLength() const; << 149 inline size_t FindBin(G4double energy, size_t idx) const; 128 << 150 // find low edge index of a bin for given energy 129 // Computes the lower index the energy bin i << 151 // min value 0, max value VectorLength-1 130 // in case of vectors with equal bin widths << 152 // idx is suggested bin number from user code 131 // Note, that no check on the boundary is pe << 153 132 inline std::size_t ComputeLogVectorBin(const << 154 void FillSecondDerivatives(); 133 << 155 // Initialise second derivatives for spline keeping 134 // Get physics vector type. << 156 // 3d derivative continues - default algorithm 135 inline G4PhysicsVectorType GetType() const; << 157 // Warning: this method should be called when the vector 136 << 158 // is already filled 137 // True if using spline interpolation. << 159 138 inline G4bool GetSpline() const; << 160 void ComputeSecDerivatives(); 139 << 161 // Initialise second derivatives for spline using algorithm 140 // Define verbosity level. << 162 // which garantee only 1st derivative continues 141 inline void SetVerboseLevel(G4int value); << 163 // Warning: this method should be called when the vector 142 << 164 // is already filled 143 // Find energy using linear interpolation fo << 165 144 // filled by cumulative probability function << 166 void ComputeSecondDerivatives(G4double firstPointDerivative, 145 // Assuming that vector is already filled. << 167 G4double endPointDerivative); 146 inline G4double FindLinearEnergy(const G4dou << 168 // Initialise second derivatives for spline using 147 << 169 // user defined 1st derivatives at edge points 148 // Find low edge index of a bin for given en << 170 // Warning: this method should be called when the vector 149 // Min value 0, max value idxmax. << 171 // is already filled 150 std::size_t FindBin(const G4double energy, s << 172 151 << 173 G4double FindLinearEnergy(G4double rand) const; 152 // Scale all values of the vector by factorV << 174 // Find energy using linear interpolation for vector 153 // AFter this method FillSecondDerivatives(. << 175 // filled by cumulative probability function 154 // This method may be applied for example af << 176 // value of rand should be between 0 and 1 155 // from an external file to convert values i << 177 156 void ScaleVector(const G4double factorE, con << 178 inline G4bool IsFilledVectorExist() const; 157 << 179 // Is non-empty physics vector already exist? 158 // This method should be called when the vec << 180 159 // There are 3 types of second derivative co << 181 inline G4PhysicsVectorType GetType() const; 160 // fSplineSimple - 2d derivative cont << 182 // Get physics vector type 161 // fSplineBase - 3d derivative cont << 183 162 // fSplineFixedEdges - 3d derivatives con << 184 inline void SetSpline(G4bool); 163 // derivatives are fi << 185 // Activate/deactivate Spline interpolation. 164 void FillSecondDerivatives(const G4SplineTyp << 186 165 const G4double di << 187 G4bool Store(std::ofstream& fOut, G4bool ascii=false) const; 166 const G4double di << 188 virtual G4bool Retrieve(std::ifstream& fIn, G4bool ascii=false); 167 << 189 // To store/retrieve persistent data to/from file streams. 168 // This method can be applied if both energy << 190 169 // grow monotonically, for example, if in th << 191 friend std::ostream& operator<<(std::ostream&, const G4PhysicsVector&); 170 // cumulative probability density function i << 192 void DumpValues(G4double unitE=1.0, G4double unitV=1.0) const; 171 G4double GetEnergy(const G4double value) con << 193 // print vector 172 << 194 173 // To store/retrieve persistent data to/from << 195 inline void SetVerboseLevel(G4int value); 174 G4bool Store(std::ofstream& fOut, G4bool asc << 196 175 G4bool Retrieve(std::ifstream& fIn, G4bool a << 197 protected: 176 << 198 177 // Print vector << 199 void DeleteData(); 178 friend std::ostream& operator<<(std::ostream << 200 void CopyData(const G4PhysicsVector& vec); 179 void DumpValues(G4double unitE = 1.0, G4doub << 201 // Internal methods for allowing copy of objects 180 << 202 181 protected: << 203 void PrintPutValueError(size_t index); 182 << 204 183 // The default implements a free vector init << 205 protected: 184 virtual void Initialise(); << 206 185 << 207 G4PhysicsVectorType type; // The type of PhysicsVector (enumerator) 186 void PrintPutValueError(std::size_t index, G << 208 187 const G4String& text << 209 G4double edgeMin; // Energy of first point 188 << 210 G4double edgeMax; // Energy of the last point 189 private: << 211 190 << 212 size_t numberOfNodes; 191 void ComputeSecDerivative0(); << 213 192 void ComputeSecDerivative1(); << 214 G4PVDataVector dataVector; // Vector to keep the crossection/energyloss 193 void ComputeSecDerivative2(const G4double fi << 215 G4PVDataVector binVector; // Vector to keep energy 194 const G4double en << 216 G4PVDataVector secDerivative; // Vector to keep second derivatives 195 // Internal methods for computing of spline << 217 196 << 218 private: 197 // Linear or spline interpolation. << 219 198 inline G4double Interpolation(const std::siz << 220 G4bool SplinePossible(); 199 const G4double << 221 200 << 222 inline G4double LinearInterpolation(size_t idx, G4double energy) const; 201 // Assuming (edgeMin <= energy <= edgeMax). << 223 // Linear interpolation function 202 inline std::size_t LogBin(const G4double ene << 224 inline G4double SplineInterpolation(size_t idx, G4double energy) const; 203 inline std::size_t BinaryBin(const G4double << 225 // Spline interpolation function 204 inline std::size_t GetBin(const G4double ene << 226 205 << 227 inline G4double Interpolation(size_t idx, G4double energy) const; 206 protected: << 228 207 << 229 inline size_t FindBinLocation(G4double theEnergy) const; 208 G4double edgeMin = 0.0; // Energy of first << 230 // find low edge index of a bin for given energy 209 G4double edgeMax = 0.0; // Energy of the la << 231 // min value 0, max value VectorLength-1 210 << 232 211 G4double invdBin = 0.0; // 1/Bin width for << 233 G4bool useSpline; 212 G4double logemin = 0.0; // used only for lo << 234 213 << 235 protected: 214 G4double iBin1 = 0.0; // 1/Bin width for sc << 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 236 231 private: << 237 G4double dBin; // Bin width - useful only for fixed binning >> 238 G4double baseBin; // Set this in constructor for performance 232 239 233 G4bool useSpline = false; << 240 G4int verboseLevel; 234 }; 241 }; 235 242 236 #include "G4PhysicsVector.icc" 243 #include "G4PhysicsVector.icc" 237 244 238 #endif 245 #endif 239 246