|
|
|||
File indexing completed on 2026-10-04 09:07:42
0001 // 0002 // ******************************************************************** 0003 // * License and Disclaimer * 0004 // * * 0005 // * The Geant4 software is copyright of the Copyright Holders of * 0006 // * the Geant4 Collaboration. It is provided under the terms and * 0007 // * conditions of the Geant4 Software License, included in the file * 0008 // * LICENSE and available at http://cern.ch/geant4/license . These * 0009 // * include a list of copyright holders. * 0010 // * * 0011 // * Neither the authors of this software system, nor their employing * 0012 // * institutes,nor the agencies providing financial support for this * 0013 // * work make any representation or warranty, express or implied, * 0014 // * regarding this software system or assume any liability for its * 0015 // * use. Please see the license in the file LICENSE and URL above * 0016 // * for the full disclaimer and the limitation of liability. * 0017 // * * 0018 // * This code implementation is the result of the scientific and * 0019 // * technical work of the GEANT4 collaboration. * 0020 // * By using, copying, modifying or distributing the software (or * 0021 // * any work based on the software) you agree to acknowledge its * 0022 // * use in resulting scientific publications, and indicate your * 0023 // * acceptance of all terms of the Geant4 Software license. * 0024 // ******************************************************************** 0025 // 0026 // G4PhysicsVector 0027 // 0028 // Class description: 0029 // 0030 // A physics vector which has values of energy-loss, cross-section, 0031 // and other physics values of a particle in matter in a given 0032 // range of energy, momentum, etc. 0033 // This class serves as the base class for a vector having various 0034 // energy scale, for example like 'log', 'linear', 'free', etc. 0035 0036 // Authors: 0037 // - 02 Dec. 1995, G.Cosmo: Structure created based on object model 0038 // - 03 Mar. 1996, K.Amako: Implemented the 1st version 0039 // Revisions: 0040 // - 11 Nov. 2000, H.Kurashige: Use STL vector for dataVector and binVector 0041 // -------------------------------------------------------------------- 0042 #ifndef G4PhysicsVector_hh 0043 #define G4PhysicsVector_hh 1 0044 0045 #include <fstream> 0046 #include <iostream> 0047 #include <vector> 0048 0049 #include "G4Log.hh" 0050 #include "G4PhysicsVectorType.hh" 0051 #include "G4ios.hh" 0052 #include "globals.hh" 0053 0054 class G4PhysicsVector 0055 { 0056 public: 0057 // Default constructor - vector will be filled via Retrieve() method 0058 // Free vector may be filled via InsertValue(..) method 0059 explicit G4PhysicsVector(G4bool spline = false); 0060 0061 // Copy constructor and assignment operator 0062 G4PhysicsVector(const G4PhysicsVector&) = default; 0063 G4PhysicsVector& operator=(const G4PhysicsVector&) = default; 0064 0065 // not used operators 0066 G4PhysicsVector(const G4PhysicsVector&&) = delete; 0067 G4PhysicsVector& operator=(const G4PhysicsVector&&) = delete; 0068 G4bool operator==(const G4PhysicsVector& right) const = delete; 0069 G4bool operator!=(const G4PhysicsVector& right) const = delete; 0070 0071 virtual ~G4PhysicsVector() = default; 0072 0073 // Get the cross-section/energy-loss value corresponding to the 0074 // given energy. An appropriate interpolation is used to calculate 0075 // the value. Consumer code gets changed index and may reuse it 0076 // for the next call to save CPU for bin location. 0077 inline G4double Value(const G4double energy, std::size_t& lastidx) const; 0078 0079 // Get the cross-section/energy-loss value corresponding to the 0080 // given energy. An appropriate interpolation is used to calculate 0081 // the value. This method should be used if bin location cannot be 0082 // kept in the user code. 0083 inline G4double Value(const G4double energy) const; 0084 0085 // Obsolete method to get value, 'isOutRange' is not used anymore. 0086 // This method is kept for the compatibility reason 0087 inline G4double GetValue(const G4double energy, G4bool& isOutRange) const; 0088 0089 // Same as the Value() method above but specialised for log-vector type. 0090 // Note, unlike the general Value() method above, this method will work 0091 // properly only for G4PhysicsLogVector. 0092 inline G4double LogVectorValue(const G4double energy, 0093 const G4double theLogEnergy) const; 0094 0095 // Same as the Value() method above but specialised for free vector 0096 // with logarithmic seach of bin number 0097 inline G4double LogFreeVectorValue(const G4double energy, 0098 const G4double theLogEnergy) const; 0099 0100 // Internal method to define bin location 0101 inline G4bool CheckIndex(const G4double energy, std::size_t& lastidx) const; 0102 0103 // Returns the value for the specified index of the dataVector 0104 // The boundary check will not be done 0105 inline G4double operator[](const std::size_t index) const; 0106 inline G4double operator()(const std::size_t index) const; 0107 0108 // Put data into the vector at 'index' position. 0109 // Take note that the 'index' starts from '0'. 0110 // It is assumed that energies are already filled. 0111 inline void PutValue(const std::size_t index, const G4double value); 0112 0113 // Returns the value in the energy specified by 'index' 0114 // of the energy vector. The boundary check will not be done. 0115 // Use this when compute cross-section, dEdx, or other value 0116 // before filling the vector by PutValue(). 0117 inline G4double Energy(const std::size_t index) const; 0118 inline G4double GetLowEdgeEnergy(const std::size_t index) const; 0119 0120 // Returns the energy of the first and the last point of the vector. 0121 inline G4double GetMinEnergy() const; 0122 inline G4double GetMaxEnergy() const; 0123 0124 // Returns the data of the first and the last point of the vector. 0125 // If the vector is empty returns zeros. 0126 inline G4double GetMinValue() const; 0127 inline G4double GetMaxValue() const; 0128 0129 // Get the total length of the vector 0130 inline std::size_t GetVectorLength() const; 0131 0132 // Computes the lower index the energy bin in case of log-vector i.e. 0133 // in case of vectors with equal bin widths on log-scale 0134 // Note, that no check on the boundary is performed 0135 inline std::size_t ComputeLogVectorBin(const G4double logenergy) const; 0136 0137 // Get physics vector type. 0138 inline G4PhysicsVectorType GetType() const; 0139 0140 // True if using spline interpolation. 0141 inline G4bool GetSpline() const; 0142 0143 // Define verbosity level. 0144 inline void SetVerboseLevel(G4int value); 0145 0146 // Find energy using linear interpolation for vector 0147 // filled by cumulative probability function. 0148 // Assuming that vector is already filled. 0149 inline G4double FindLinearEnergy(const G4double rand) const; 0150 0151 // Find low edge index of a bin for given energy. 0152 // Min value 0, max value idxmax. This method is obsolete and will 0153 // be removed with the next major release. 0154 std::size_t FindBin(const G4double energy, std::size_t idx) const; 0155 0156 // Scale all values of the vector by factorV, energies by vectorE. 0157 // AFter this method FillSecondDerivatives(...) should be called. 0158 // This method may be applied for example after retrieving a vector 0159 // from an external file to convert values into Geant4 units. 0160 void ScaleVector(const G4double factorE, const G4double factorV); 0161 0162 // This method should be called when the vector is fully filled 0163 // There are 3 types of second derivative computations: 0164 // fSplineSimple - 2d derivative continues 0165 // fSplineBase - 3d derivative continues (the default) 0166 // fSplineFixedEdges - 3d derivatives continues, 1st and last 0167 // derivatives are fixed 0168 void FillSecondDerivatives(const G4SplineType = G4SplineType::Base, 0169 const G4double dir1 = 0.0, 0170 const G4double dir2 = 0.0); 0171 0172 // This method may be applied only once. 0173 // Force length of data using std::vector::resize() with the 0174 // the default value 0; partial cross section vector is resized 0175 // only if the number of partial x-sections is above zero. 0176 void SetDataLength(G4int dlength); 0177 0178 // This method can be applied if both energy and data values 0179 // grow monotonically, for example, if in this vector a 0180 // cumulative probability density function is stored. 0181 G4double GetEnergy(const G4double value) const; 0182 0183 // To store/retrieve persistent data to/from file streams. 0184 G4bool Store(std::ofstream& fOut, G4bool ascii = false) const; 0185 G4bool Retrieve(std::ifstream& fIn, G4bool ascii = false); 0186 0187 // Print vector 0188 friend std::ostream& operator<<(std::ostream&, const G4PhysicsVector&); 0189 void DumpValues(G4double unitE = 1.0, G4double unitV = 1.0) const; 0190 0191 protected: 0192 0193 // The default implements a free vector initialisation. 0194 virtual void Initialise(); 0195 0196 void PrintPutValueError(std::size_t index, G4double value, 0197 const G4String& text); 0198 0199 private: 0200 0201 // Internal methods for computing of spline coeffitients 0202 void ComputeSecDerivative0(); 0203 void ComputeSecDerivative1(); 0204 void ComputeSecDerivative2(const G4double firstPointDerivative, 0205 const G4double endPointDerivative); 0206 0207 // Linear or spline interpolation. 0208 inline G4double Interpolation(const std::size_t idx, 0209 const G4double energy) const; 0210 0211 // Assuming (edgeMin <= energy <= edgeMax). 0212 inline std::size_t LogBin(const G4double energy, const G4double loge) const; 0213 inline std::size_t BinaryBin(const G4double energy) const; 0214 inline std::size_t GetBin(const G4double energy) const; 0215 0216 protected: 0217 0218 G4double edgeMin = 0.0; // Energy of first point 0219 G4double edgeMax = 0.0; // Energy of the last point 0220 0221 G4double invdBin = 0.0; // 1/Bin width for linear and log vectors 0222 G4double logemin = 0.0; // used only for log vector 0223 0224 G4double iBin1 = 0.0; // 1/Bin width for scale log vector 0225 G4double lmin1 = 0.0; // used for log search of free vector 0226 0227 G4int verboseLevel = 0; 0228 std::size_t idxmax = 0; 0229 std::size_t imax1 = 0; 0230 std::size_t numberOfNodes = 0; 0231 std::size_t nLogNodes = 0; 0232 0233 G4PhysicsVectorType type = T_G4PhysicsFreeVector; 0234 // The type of PhysicsVector (enumerator) 0235 0236 std::vector<G4double> binVector; // energy 0237 std::vector<G4double> dataVector; // crossection/energyloss 0238 std::vector<G4double> secDerivative; // second derivatives 0239 std::vector<std::size_t> scale; // log seach 0240 0241 private: 0242 0243 G4bool useSpline = false; 0244 }; 0245 0246 #include "G4PhysicsVector.icc" 0247 0248 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|