[833] | 1 | // |
---|
| 2 | // ******************************************************************** |
---|
| 3 | // * License and Disclaimer * |
---|
| 4 | // * * |
---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
| 7 | // * conditions of the Geant4 Software License, included in the file * |
---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
| 9 | // * include a list of copyright holders. * |
---|
| 10 | // * * |
---|
| 11 | // * Neither the authors of this software system, nor their employing * |
---|
| 12 | // * institutes,nor the agencies providing financial support for this * |
---|
| 13 | // * work make any representation or warranty, express or implied, * |
---|
| 14 | // * regarding this software system or assume any liability for its * |
---|
| 15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
| 16 | // * for the full disclaimer and the limitation of liability. * |
---|
| 17 | // * * |
---|
| 18 | // * This code implementation is the result of the scientific and * |
---|
| 19 | // * technical work of the GEANT4 collaboration. * |
---|
| 20 | // * By using, copying, modifying or distributing the software (or * |
---|
| 21 | // * any work based on the software) you agree to acknowledge its * |
---|
| 22 | // * use in resulting scientific publications, and indicate your * |
---|
| 23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
| 24 | // ******************************************************************** |
---|
| 25 | // |
---|
| 26 | // |
---|
[1193] | 27 | // $Id: G4PhysicsVector.hh,v 1.25 2009/11/04 11:32:43 vnivanch Exp $ |
---|
[1228] | 28 | // GEANT4 tag $Name: geant4-09-03 $ |
---|
[833] | 29 | // |
---|
| 30 | // |
---|
| 31 | //--------------------------------------------------------------- |
---|
| 32 | // GEANT 4 class header file |
---|
| 33 | // |
---|
| 34 | // G4PhysicsVector.hh |
---|
| 35 | // |
---|
| 36 | // Class description: |
---|
| 37 | // |
---|
| 38 | // A physics vector which has values of energy-loss, cross-section, |
---|
| 39 | // and other physics values of a particle in matter in a given |
---|
| 40 | // range of the energy, momentum, etc. |
---|
| 41 | // This class serves as the base class for a vector having various |
---|
| 42 | // energy scale, for example like 'log', 'linear', 'free', etc. |
---|
| 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 |
---|
[850] | 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() |
---|
[1193] | 53 | // 11 May 2009, V.Ivanchenko : Added ComputeSecondDerivatives |
---|
| 54 | // 19 Jun. 2009, V.Ivanchenko : Removed hidden bin |
---|
[833] | 55 | // |
---|
| 56 | //--------------------------------------------------------------- |
---|
| 57 | |
---|
| 58 | #ifndef G4PhysicsVector_h |
---|
| 59 | #define G4PhysicsVector_h 1 |
---|
| 60 | |
---|
| 61 | #include <vector> |
---|
| 62 | #include "globals.hh" |
---|
| 63 | #include "G4ios.hh" |
---|
| 64 | #include <iostream> |
---|
| 65 | #include <fstream> |
---|
| 66 | |
---|
[850] | 67 | #include "G4PhysicsVectorType.hh" |
---|
[833] | 68 | |
---|
| 69 | class G4PhysicsVector |
---|
| 70 | { |
---|
| 71 | public: |
---|
| 72 | |
---|
[850] | 73 | G4PhysicsVector(G4bool spline = false); |
---|
[833] | 74 | // constructor |
---|
| 75 | // This class is an abstract class with pure virtual method of |
---|
| 76 | // virtual size_t FindBinLocation(G4double theEnergy) const |
---|
| 77 | // So, default constructor is not supposed to be invoked explicitly |
---|
| 78 | |
---|
| 79 | G4PhysicsVector(const G4PhysicsVector&); |
---|
| 80 | G4PhysicsVector& operator=(const G4PhysicsVector&); |
---|
| 81 | // Copy constructor and assignment operator. |
---|
| 82 | |
---|
| 83 | public: // with description |
---|
| 84 | |
---|
| 85 | virtual ~G4PhysicsVector(); |
---|
| 86 | // destructor |
---|
| 87 | |
---|
[1193] | 88 | inline G4double Value(G4double theEnergy); |
---|
[833] | 89 | // Get the cross-section/energy-loss value corresponding to the |
---|
| 90 | // given energy. An appropriate interpolation is used to calculate |
---|
| 91 | // the value. |
---|
| 92 | |
---|
[1193] | 93 | inline G4double GetValue(G4double theEnergy, G4bool& isOutRange); |
---|
| 94 | // Obolete method to get value, isOutRange is not used anymore. |
---|
| 95 | // This method is kept for the compatibility reason. |
---|
| 96 | |
---|
[833] | 97 | G4int operator==(const G4PhysicsVector &right) const ; |
---|
| 98 | G4int operator!=(const G4PhysicsVector &right) const ; |
---|
[1193] | 99 | |
---|
[833] | 100 | inline G4double operator[](const size_t binNumber) const ; |
---|
| 101 | // Returns simply the value in the bin specified by 'binNumber' |
---|
[1193] | 102 | // of the dataVector. The boundary check will not be done. |
---|
| 103 | |
---|
[833] | 104 | inline G4double operator()(const size_t binNumber) const ; |
---|
| 105 | // Returns simply the value in the bin specified by 'binNumber' |
---|
[1193] | 106 | // of the dataVector. The boundary check will not be Done. |
---|
[833] | 107 | |
---|
[1193] | 108 | inline void PutValue(size_t index, G4double theValue); |
---|
[833] | 109 | // Put 'theValue' into the bin specified by 'binNumber'. |
---|
[1193] | 110 | // Take note that the 'index' starts from '0'. |
---|
| 111 | // To fill the vector, you have beforehand to construct a vector |
---|
[833] | 112 | // by the constructor with Emin, Emax, Nbin. 'theValue' should |
---|
[1193] | 113 | // be the crosssection/energyloss value corresponding to the |
---|
| 114 | // energy of the index. You can get this energy by the next method |
---|
| 115 | // or by the old method GetLowEdgeEnergy(). |
---|
| 116 | |
---|
| 117 | void ScaleVector(G4double factorE, G4double factorV); |
---|
| 118 | // Scale all values of the vector and second derivatives |
---|
| 119 | // by factorV, energies by vectorE. This method may be applied |
---|
| 120 | // for example after Retrieve a vector from an external file to |
---|
| 121 | // convert values into Geant4 units |
---|
| 122 | |
---|
| 123 | inline G4double Energy(size_t index) const; |
---|
| 124 | // Returns simply the value in the energy specified by 'index' |
---|
| 125 | // of the energy vector. The boundary check will not be done. |
---|
| 126 | // Use this function when you fill physis vector by PutValue(). |
---|
| 127 | |
---|
[833] | 128 | virtual G4double GetLowEdgeEnergy(size_t binNumber) const; |
---|
[1193] | 129 | // Obsolete method |
---|
[833] | 130 | // Get the energy value at the low edge of the specified bin. |
---|
| 131 | // Take note that the 'binNumber' starts from '0'. |
---|
[1193] | 132 | // This value should be defined before the call. |
---|
| 133 | // The boundary check will not be done. |
---|
| 134 | |
---|
[833] | 135 | inline size_t GetVectorLength() const; |
---|
| 136 | // Get the toal length (bin number) of the vector. |
---|
[1193] | 137 | |
---|
| 138 | void FillSecondDerivatives(); |
---|
| 139 | // Initialise second derivatives for spline keeping |
---|
| 140 | // 3d derivative continues - default algorithm |
---|
| 141 | |
---|
| 142 | void ComputeSecDerivatives(); |
---|
| 143 | // Initialise second derivatives for spline using algorithm |
---|
| 144 | // which garantee only 1st derivative continues |
---|
| 145 | // Warning: this method should be called when the vector |
---|
| 146 | // is already filled |
---|
| 147 | |
---|
| 148 | void ComputeSecondDerivatives(G4double firstPointDerivative, |
---|
| 149 | G4double endPointDerivative); |
---|
| 150 | // Initialise second derivatives for spline using |
---|
| 151 | // user defined 1st derivatives at edge points |
---|
| 152 | // Warning: this method should be called when the vector |
---|
| 153 | // is already filled |
---|
| 154 | |
---|
[833] | 155 | inline G4bool IsFilledVectorExist() const; |
---|
| 156 | // Is non-empty physics vector already exist? |
---|
| 157 | |
---|
| 158 | inline void PutComment(const G4String& theComment); |
---|
| 159 | // Put a comment to the G4PhysicsVector. This may help to check |
---|
| 160 | // whether your are accessing to the one you want. |
---|
[1193] | 161 | |
---|
[833] | 162 | inline const G4String& GetComment() const; |
---|
| 163 | // Retrieve the comment of the G4PhysicsVector. |
---|
| 164 | |
---|
| 165 | inline G4PhysicsVectorType GetType() const; |
---|
| 166 | // Get physics vector type |
---|
[850] | 167 | |
---|
| 168 | inline void SetSpline(G4bool); |
---|
| 169 | // Activate/deactivate Spline interpolation. |
---|
[833] | 170 | |
---|
| 171 | virtual G4bool Store(std::ofstream& fOut, G4bool ascii=false); |
---|
| 172 | virtual G4bool Retrieve(std::ifstream& fIn, G4bool ascii=false); |
---|
| 173 | // To store/retrieve persistent data to/from file streams. |
---|
| 174 | |
---|
| 175 | friend std::ostream& operator<<(std::ostream&, const G4PhysicsVector&); |
---|
| 176 | |
---|
| 177 | protected: |
---|
| 178 | |
---|
| 179 | virtual size_t FindBinLocation(G4double theEnergy) const=0; |
---|
| 180 | // Find the bin# in which theEnergy belongs - pure virtual function |
---|
| 181 | |
---|
[921] | 182 | void DeleteData(); |
---|
| 183 | void CopyData(const G4PhysicsVector& vec); |
---|
| 184 | // Internal methods for allowing copy of objects |
---|
| 185 | |
---|
| 186 | protected: |
---|
| 187 | |
---|
[833] | 188 | typedef std::vector<G4double> G4PVDataVector; |
---|
| 189 | |
---|
| 190 | G4PhysicsVectorType type; // The type of PhysicsVector (enumerator) |
---|
| 191 | |
---|
[1193] | 192 | G4double edgeMin; // Energy of first point |
---|
| 193 | G4double edgeMax; // Energy of the last point |
---|
[833] | 194 | |
---|
[1193] | 195 | size_t numberOfNodes; |
---|
| 196 | |
---|
[833] | 197 | G4double lastEnergy; // Cache the last input value |
---|
| 198 | G4double lastValue; // Cache the last output value |
---|
| 199 | size_t lastBin; // Cache the last bin location |
---|
| 200 | |
---|
| 201 | G4PVDataVector dataVector; // Vector to keep the crossection/energyloss |
---|
[1193] | 202 | G4PVDataVector binVector; // Vector to keep energy |
---|
| 203 | G4PVDataVector secDerivative; // Vector to keep second derivatives |
---|
[833] | 204 | |
---|
| 205 | private: |
---|
| 206 | |
---|
[1193] | 207 | G4bool SplinePossible(); |
---|
| 208 | |
---|
[850] | 209 | inline G4double LinearInterpolation(); |
---|
| 210 | // Linear interpolation function |
---|
| 211 | inline G4double SplineInterpolation(); |
---|
| 212 | // Spline interpolation function |
---|
| 213 | |
---|
| 214 | inline void Interpolation(); |
---|
| 215 | |
---|
| 216 | G4String comment; |
---|
| 217 | G4bool useSpline; |
---|
[833] | 218 | }; |
---|
| 219 | |
---|
| 220 | #include "G4PhysicsVector.icc" |
---|
| 221 | |
---|
| 222 | #endif |
---|