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 // G4Physics2DVector << 27 // 26 // 28 // Class description: << 27 // $Id:$ >> 28 // GEANT4 tag $Name: not supported by cvs2svn $ 29 // 29 // 30 // A 2-dimentional vector with linear interpol << 30 // >> 31 //--------------------------------------------------------------- >> 32 // GEANT 4 class header file >> 33 // >> 34 // G4Physics2DVector.hh >> 35 // >> 36 // Class description: >> 37 // >> 38 // A 2-dimentional vector with linear interpolation. 31 39 32 // Author: Vladimir Ivanchenko, 25.09.2011 << 40 // Author: Vladimir Ivanchenko 33 // ------------------------------------------- << 41 // 34 #ifndef G4Physics2DVector_hh << 42 // Creation date: 25.09.2011 35 #define G4Physics2DVector_hh 1 << 43 //--------------------------------------------------------------- >> 44 >> 45 #ifndef G4Physics2DVector_h >> 46 #define G4Physics2DVector_h 1 >> 47 >> 48 #include "globals.hh" >> 49 #include "G4ios.hh" 36 50 37 #include <fstream> << 38 #include <iostream> 51 #include <iostream> >> 52 #include <fstream> 39 #include <vector> 53 #include <vector> 40 54 >> 55 #include "G4Physics2DVectorCache.hh" 41 #include "G4PhysicsVectorType.hh" 56 #include "G4PhysicsVectorType.hh" 42 #include "G4ios.hh" << 43 #include "globals.hh" << 44 57 45 using G4PV2DDataVector = std::vector<G4double> << 58 typedef std::vector<G4double> G4PV2DDataVector; 46 59 47 class G4Physics2DVector << 60 class G4Physics2DVector 48 { 61 { 49 public: << 62 public: // with description 50 G4Physics2DVector(); << 51 // Vector will be filled via Retrieve method << 52 63 53 explicit G4Physics2DVector(std::size_t nx, s << 64 G4Physics2DVector(); 54 // Vector will be filled via Put methods << 65 G4Physics2DVector(size_t nx, size_t ny); >> 66 // constructors 55 67 56 G4Physics2DVector(const G4Physics2DVector&); 68 G4Physics2DVector(const G4Physics2DVector&); 57 G4Physics2DVector& operator=(const G4Physics 69 G4Physics2DVector& operator=(const G4Physics2DVector&); 58 // Copy constructor and assignment operator << 70 // Copy constructor and assignment operator. 59 << 60 G4bool operator==(const G4Physics2DVector& r << 61 G4bool operator!=(const G4Physics2DVector& r << 62 71 63 ~G4Physics2DVector(); 72 ~G4Physics2DVector(); 64 // Destructor << 73 // destructor 65 74 66 G4double Value(G4double x, G4double y, std:: << 75 inline G4double Value(G4double x, G4double y); 67 std::size_t& lastidy) const; << 68 G4double Value(G4double x, G4double y) const << 69 // Main method to interpolate 2D vector 76 // Main method to interpolate 2D vector 70 // Consumer class should provide initial val << 71 77 72 inline void PutX(std::size_t idx, G4double v << 78 inline void PutX(size_t idx, G4double value); 73 inline void PutY(std::size_t idy, G4double v << 79 inline void PutY(size_t idy, G4double value); 74 inline void PutValue(std::size_t idx, std::s << 80 inline void PutValue(size_t idx, size_t idy, G4double value); 75 void PutVectors(const std::vector<G4double>& 81 void PutVectors(const std::vector<G4double>& vecX, 76 const std::vector<G4double>& << 82 const std::vector<G4double>& vecY); 77 // Methods to fill vector << 83 // Methods to fill vector 78 // Take note that the 'index' starts from '0 << 84 // Take note that the 'index' starts from '0'. 79 85 80 void ScaleVector(G4double factor); 86 void ScaleVector(G4double factor); 81 // Scale all values of the vector by factor. << 87 // Scale all values of the vector by factor, 82 // This method may be applied for example af << 88 // This method may be applied 83 // from an external file to convert values i << 89 // for example after Retrieve a vector from an external file to 84 << 90 // convert values into Geant4 units 85 G4double FindLinearX(G4double rand, G4double << 91 86 inline G4double FindLinearX(G4double rand, G << 92 inline G4double GetX(size_t index) const; 87 // Find Y using linear interpolation for Y-v << 93 inline G4double GetY(size_t index) const; 88 // probability function value of rand should << 94 inline G4double GetValue(size_t idx, size_t idy) const; 89 << 90 inline G4double GetX(std::size_t index) cons << 91 inline G4double GetY(std::size_t index) cons << 92 inline G4double GetValue(std::size_t idx, st << 93 // Returns simply the values of the vector b 95 // Returns simply the values of the vector by index 94 // of the energy vector. The boundary check << 96 // of the energy vector. The boundary check will not be done. 95 97 96 inline std::size_t FindBinLocationX(const G4 << 98 inline size_t GetLengthX() const; 97 const st << 99 inline size_t GetLengthY() const; 98 inline std::size_t FindBinLocationY(const G4 << 100 // Get the lengths of the vector. 99 const st << 100 // Find the bin# in which theEnergy belongs. << 101 << 102 inline std::size_t GetLengthX() const; << 103 inline std::size_t GetLengthY() const; << 104 // Get the lengths of the vector << 105 101 106 inline G4PhysicsVectorType GetType() const; 102 inline G4PhysicsVectorType GetType() const; 107 // Get physics vector type 103 // Get physics vector type 108 << 104 109 inline void SetBicubicInterpolation(G4bool); << 105 void Store(std::ofstream& fOut); 110 // Activate/deactivate bicubic interpolation << 111 << 112 void Store(std::ofstream& fOut) const; << 113 G4bool Retrieve(std::ifstream& fIn); 106 G4bool Retrieve(std::ifstream& fIn); 114 // To store/retrieve persistent data to/from << 107 // To store/retrieve persistent data to/from file streams. >> 108 >> 109 inline G4double GetLastX() const; >> 110 inline G4double GetLastY() const; >> 111 inline G4double GetLastValue() const; >> 112 inline size_t GetLastBinX() const; >> 113 inline size_t GetLastBinY() const; >> 114 // Get cache values 115 115 116 inline void SetVerboseLevel(G4int value); 116 inline void SetVerboseLevel(G4int value); >> 117 inline G4int GetVerboseLevel(G4int); >> 118 // Set/Get Verbose level >> 119 >> 120 protected: 117 121 118 protected: << 119 void PrepareVectors(); 122 void PrepareVectors(); 120 123 121 void ClearVectors(); 124 void ClearVectors(); 122 125 123 void CopyData(const G4Physics2DVector& vec); 126 void CopyData(const G4Physics2DVector& vec); 124 127 125 G4double BicubicInterpolation(const G4double << 128 void ComputeValue(G4double x, G4double y); 126 const std::siz << 129 // Main method to interpolate 2D vector 127 const std::siz << 130 128 // Bicubic interpolation of 2D vector << 131 size_t FindBinLocation(G4double z, const G4PV2DDataVector&); 129 << 132 // Main method to local bin 130 inline std::size_t FindBin(const G4double z, << 133 131 const std::size_t << 134 inline void FindBin(G4double z, const G4PV2DDataVector&, 132 const std::size_t << 135 size_t& lastidx); 133 << 136 inline void FindBinLocationX(G4double x); 134 private: << 137 inline void FindBinLocationY(G4double y); 135 G4double InterpolateLinearX(G4PV2DDataVector << 138 // Find the bin# in which theEnergy belongs 136 << 139 // Starting from 0 137 inline G4double DerivativeX(std::size_t idx, << 140 138 G4double fac) co << 141 private: 139 inline G4double DerivativeY(std::size_t idx, << 142 140 G4double fac) co << 143 G4int operator==(const G4Physics2DVector &right) const ; 141 inline G4double DerivativeXY(std::size_t idx << 144 G4int operator!=(const G4Physics2DVector &right) const ; 142 G4double fac) c << 145 143 // computation of derivatives << 146 G4PhysicsVectorType type; // The type of PhysicsVector (enumerator) 144 147 145 G4PhysicsVectorType type = T_G4PhysicsFreeVe << 148 size_t numberOfXNodes; 146 // The type of PhysicsVector (enumerator) << 149 size_t numberOfYNodes; 147 150 148 std::size_t numberOfXNodes = 0; << 151 G4Physics2DVectorCache* cache; 149 std::size_t numberOfYNodes = 0; << 150 152 151 G4PV2DDataVector xVector; << 153 G4PV2DDataVector xVector; 152 G4PV2DDataVector yVector; << 154 G4PV2DDataVector yVector; 153 std::vector<G4PV2DDataVector*> value; 155 std::vector<G4PV2DDataVector*> value; 154 156 155 G4int verboseLevel = 0; << 157 G4int verboseLevel; 156 G4bool useBicubic = false; << 157 }; 158 }; 158 159 159 #include "G4Physics2DVector.icc" 160 #include "G4Physics2DVector.icc" 160 161 161 #endif 162 #endif 162 163