Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4PhysicsVector.hh
Go to the documentation of this file.
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 //
27 // $Id: G4PhysicsVector.hh 98864 2016-08-15 11:53:26Z gcosmo $
28 //
29 //
30 //---------------------------------------------------------------
31 // GEANT 4 class header file
32 //
33 // G4PhysicsVector.hh
34 //
35 // Class description:
36 //
37 // A physics vector which has values of energy-loss, cross-section,
38 // and other physics values of a particle in matter in a given
39 // range of the energy, momentum, etc.
40 // This class serves as the base class for a vector having various
41 // energy scale, for example like 'log', 'linear', 'free', etc.
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
64 
65 #include <iostream>
66 #include <fstream>
67 #include <vector>
68 
69 #include "globals.hh"
70 #include "G4ios.hh"
71 #include "G4PhysicsVectorType.hh"
72 #include "G4Log.hh"
73 
74 typedef std::vector<G4double> G4PVDataVector;
75 
77 {
78  public:// with description
79 
80  explicit G4PhysicsVector(G4bool spline = false);
81  // default constructor - vector will be filled via Retrieve() method
82 
85  // Copy constructor and assignment operator.
86 
87  virtual ~G4PhysicsVector();
88 
89  G4double Value(G4double theEnergy, size_t& lastidx) const;
90  // Get the cross-section/energy-loss value corresponding to the
91  // given energy. An appropriate interpolation is used to calculate
92  // the value. Consumer code got changed index and may reuse it
93  // for the next call to save CPU for bin location.
94 
95  inline G4double Value(G4double theEnergy) const;
96  // Get the cross-section/energy-loss value corresponding to the
97  // given energy. An appropriate interpolation is used to calculate
98  // the value. This method is kept for backward compatibility reason,
99  // it should be used instead of the previous method if bin location
100  // cannot be kept thread safe
101 
102  inline G4double GetValue(G4double theEnergy, G4bool& isOutRange) const;
103  // Obsolete method to get value, isOutRange is not used anymore.
104  // This method is kept for the compatibility reason.
105 
106  G4int operator==(const G4PhysicsVector &right) const ;
107  G4int operator!=(const G4PhysicsVector &right) const ;
108 
109  inline G4double operator[](const size_t index) const ;
110  // Returns the value for the specified index of the dataVector
111  // The boundary check will not be done.
112 
113  inline G4double operator()(const size_t index) const ;
114  // Returns the value for the specified index of the dataVector
115  // The boundary check will not be done.
116 
117  inline void PutValue(size_t index, G4double theValue);
118  // Put 'theValue' into the dataVector specified by 'index'.
119  // Take note that the 'index' starts from '0'.
120  // To fill the vector, you have beforehand to construct a vector
121  // by the constructor with Emin, Emax, Nbin. 'theValue' should
122  // be the crosssection/energyloss value corresponding to the
123  // energy of the index.
124 
125  virtual void ScaleVector(G4double factorE, G4double factorV);
126  // Scale all values of the vector and second derivatives
127  // by factorV, energies by vectorE. This method may be applied
128  // for example after Retrieve a vector from an external file to
129  // convert values into Geant4 units
130 
131  inline G4double Energy(size_t index) const;
132  // Returns the value in the energy specified by 'index'
133  // of the energy vector. The boundary check will not be done.
134  // Use this function when compute cross section or dEdx
135  // before filling the vector by PutValue(..).
136 
137  inline G4double GetMaxEnergy() const;
138  // Returns the energy of the last point of the vector
139 
140  G4double GetLowEdgeEnergy(size_t binNumber) const;
141  // Obsolete method
142  // Get the energy value at the low edge of the specified bin.
143  // Take note that the 'binNumber' starts from '0'.
144  // The boundary check will not be done.
145 
146  inline size_t GetVectorLength() const;
147  // Get the total length of the vector.
148 
149  inline size_t FindBin(G4double energy, size_t idx) const;
150  // find low edge index of a bin for given energy
151  // min value 0, max value VectorLength-1
152  // idx is suggested bin number from user code
153 
154  void FillSecondDerivatives();
155  // Initialise second derivatives for spline keeping
156  // 3d derivative continues - default algorithm
157  // Warning: this method should be called when the vector
158  // is already filled
159 
160  void ComputeSecDerivatives();
161  // Initialise second derivatives for spline using algorithm
162  // which garantee only 1st derivative continues
163  // Warning: this method should be called when the vector
164  // is already filled
165 
166  void ComputeSecondDerivatives(G4double firstPointDerivative,
167  G4double endPointDerivative);
168  // Initialise second derivatives for spline using
169  // user defined 1st derivatives at edge points
170  // Warning: this method should be called when the vector
171  // is already filled
172 
173  G4double FindLinearEnergy(G4double rand) const;
174  // Find energy using linear interpolation for vector
175  // filled by cumulative probability function
176  // value of rand should be between 0 and 1
177 
178  inline G4bool IsFilledVectorExist() const;
179  // Is non-empty physics vector already exist?
180 
181  inline G4PhysicsVectorType GetType() const;
182  // Get physics vector type
183 
184  inline void SetSpline(G4bool);
185  // Activate/deactivate Spline interpolation.
186 
187  G4bool Store(std::ofstream& fOut, G4bool ascii=false) const;
188  virtual G4bool Retrieve(std::ifstream& fIn, G4bool ascii=false);
189  // To store/retrieve persistent data to/from file streams.
190 
191  friend std::ostream& operator<<(std::ostream&, const G4PhysicsVector&);
192  void DumpValues(G4double unitE=1.0, G4double unitV=1.0) const;
193  // print vector
194 
195  inline void SetVerboseLevel(G4int value);
196 
197  protected:
198 
199  void DeleteData();
200  void CopyData(const G4PhysicsVector& vec);
201  // Internal methods for allowing copy of objects
202 
203  void PrintPutValueError(size_t index);
204 
205  protected:
206 
207  G4PhysicsVectorType type; // The type of PhysicsVector (enumerator)
208 
209  G4double edgeMin; // Energy of first point
210  G4double edgeMax; // Energy of the last point
211 
213 
214  G4PVDataVector dataVector; // Vector to keep the crossection/energyloss
215  G4PVDataVector binVector; // Vector to keep energy
216  G4PVDataVector secDerivative; // Vector to keep second derivatives
217 
218  private:
219 
220  G4bool SplinePossible();
221 
222  inline G4double LinearInterpolation(size_t idx, G4double energy) const;
223  // Linear interpolation function
224  inline G4double SplineInterpolation(size_t idx, G4double energy) const;
225  // Spline interpolation function
226 
227  inline G4double Interpolation(size_t idx, G4double energy) const;
228 
229  inline size_t FindBinLocation(G4double theEnergy) const;
230  // find low edge index of a bin for given energy
231  // min value 0, max value VectorLength-1
232 
233  G4bool useSpline;
234 
235  protected:
236 
237  G4double dBin; // Bin width - useful only for fixed binning
238  G4double baseBin; // Set this in constructor for performance
239 
241 };
242 
243 #include "G4PhysicsVector.icc"
244 
245 #endif
void PrintPutValueError(size_t index)
friend std::ostream & operator<<(std::ostream &, const G4PhysicsVector &)
G4PhysicsVectorType GetType() const
G4PVDataVector dataVector
G4double FindLinearEnergy(G4double rand) const
G4double GetValue(G4double theEnergy, G4bool &isOutRange) const
G4double GetMaxEnergy() const
void CopyData(const G4PhysicsVector &vec)
void DumpValues(G4double unitE=1.0, G4double unitV=1.0) const
G4PhysicsVector(G4bool spline=false)
G4PhysicsVectorType
void ComputeSecondDerivatives(G4double firstPointDerivative, G4double endPointDerivative)
size_t GetVectorLength() const
G4double GetLowEdgeEnergy(size_t binNumber) const
int G4int
Definition: G4Types.hh:78
void FillSecondDerivatives()
G4PVDataVector binVector
void SetSpline(G4bool)
G4bool Store(std::ofstream &fOut, G4bool ascii=false) const
G4int operator!=(const G4PhysicsVector &right) const
const XML_Char int const XML_Char * value
Definition: expat.h:331
G4int operator==(const G4PhysicsVector &right) const
bool G4bool
Definition: G4Types.hh:79
void PutValue(size_t index, G4double theValue)
G4PhysicsVectorType type
G4PVDataVector secDerivative
virtual void ScaleVector(G4double factorE, G4double factorV)
size_t FindBin(G4double energy, size_t idx) const
G4double Energy(size_t index) const
G4double Value(G4double theEnergy, size_t &lastidx) const
G4double energy(const ThreeVector &p, const G4double m)
virtual G4bool Retrieve(std::ifstream &fIn, G4bool ascii=false)
void SetVerboseLevel(G4int value)
G4double operator()(const size_t index) const
G4double operator[](const size_t index) const
double G4double
Definition: G4Types.hh:76
G4bool IsFilledVectorExist() const
void ComputeSecDerivatives()
std::vector< G4double > G4PVDataVector
virtual ~G4PhysicsVector()
G4PhysicsVector & operator=(const G4PhysicsVector &)