Geant4  10.01
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 83009 2014-07-24 14:51:29Z 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 "G4Allocator.hh"
72 #include "G4PhysicsVectorType.hh"
73 #include "G4Log.hh"
74 
75 typedef std::vector<G4double> G4PVDataVector;
76 
78 {
79  public: // with description
80 
81  G4PhysicsVector(G4bool spline = false);
82  // constructor
83  // This class is an abstract class with pure virtual method of
84  // virtual size_t FindBinLocation(G4double theEnergy) const
85  // So, default constructor is not supposed to be invoked explicitly
86 
89  // Copy constructor and assignment operator.
90 
91  virtual ~G4PhysicsVector();
92  // destructor
93 
94  //inline void* operator new(size_t);
95  // inline void operator delete(void*);
96 
97  G4double Value(G4double theEnergy, size_t& lastidx) const;
98  // Get the cross-section/energy-loss value corresponding to the
99  // given energy. An appropriate interpolation is used to calculate
100  // the value. Consumer code got changed index and may reuse it
101  // for the next call to save CPU for bin location.
102 
103  inline G4double Value(G4double theEnergy) const;
104  // Get the cross-section/energy-loss value corresponding to the
105  // given energy. An appropriate interpolation is used to calculate
106  // the value. This method is kept for backward compatibility reason,
107  // it should be used is bin location cannot be kept thread safe
108 
109  inline G4double GetValue(G4double theEnergy, G4bool& isOutRange) const;
110  // Obsolete method to get value, isOutRange is not used anymore.
111  // This method is kept for the compatibility reason.
112 
113  G4int operator==(const G4PhysicsVector &right) const ;
114  G4int operator!=(const G4PhysicsVector &right) const ;
115 
116  inline G4double operator[](const size_t binNumber) const ;
117  // Returns simply the value in the bin specified by 'binNumber'
118  // of the dataVector. The boundary check will not be done.
119 
120  inline G4double operator()(const size_t binNumber) const ;
121  // Returns simply the value in the bin specified by 'binNumber'
122  // of the dataVector. The boundary check will not be Done.
123 
124  inline void PutValue(size_t index, G4double theValue);
125  // Put 'theValue' into the bin specified by 'binNumber'.
126  // Take note that the 'index' starts from '0'.
127  // To fill the vector, you have beforehand to construct a vector
128  // by the constructor with Emin, Emax, Nbin. 'theValue' should
129  // be the crosssection/energyloss value corresponding to the
130  // energy of the index. You can get this energy by the next method
131  // or by the old method GetLowEdgeEnergy().
132 
133  virtual void ScaleVector(G4double factorE, G4double factorV);
134  // Scale all values of the vector and second derivatives
135  // by factorV, energies by vectorE. This method may be applied
136  // for example after Retrieve a vector from an external file to
137  // convert values into Geant4 units
138 
139  inline G4double Energy(size_t index) const;
140  // Returns simply the value in the energy specified by 'index'
141  // of the energy vector. The boundary check will not be done.
142  // Use this function when you fill physis vector by PutValue().
143 
144  inline G4double GetMaxEnergy() const;
145  // Returns the energy of the last point of the vector
146 
147  G4double GetLowEdgeEnergy(size_t binNumber) const;
148  // Obsolete method
149  // Get the energy value at the low edge of the specified bin.
150  // Take note that the 'binNumber' starts from '0'.
151  // This value should be defined before the call.
152  // The boundary check will not be done.
153 
154  inline size_t GetVectorLength() const;
155  // Get the total length of the vector.
156 
157  inline size_t FindBin(G4double energy, size_t idx) const;
158  // find low edge index of a bin for given energy
159  // min value 0, max value VectorLength-1
160  // idx is suggested bin number from user code
161 
162  void FillSecondDerivatives();
163  // Initialise second derivatives for spline keeping
164  // 3d derivative continues - default algorithm
165 
166  void ComputeSecDerivatives();
167  // Initialise second derivatives for spline using algorithm
168  // which garantee only 1st derivative continues
169  // Warning: this method should be called when the vector
170  // is already filled
171 
172  void ComputeSecondDerivatives(G4double firstPointDerivative,
173  G4double endPointDerivative);
174  // Initialise second derivatives for spline using
175  // user defined 1st derivatives at edge points
176  // Warning: this method should be called when the vector
177  // is already filled
178 
179  G4double FindLinearEnergy(G4double rand) const;
180  // Find energy using linear interpolation for vector
181  // filled by cumulative probability function
182  // value of rand should be between 0 and 1
183 
184  inline G4bool IsFilledVectorExist() const;
185  // Is non-empty physics vector already exist?
186 
187  inline G4PhysicsVectorType GetType() const;
188  // Get physics vector type
189 
190  inline void SetSpline(G4bool);
191  // Activate/deactivate Spline interpolation.
192 
193  virtual G4bool Store(std::ofstream& fOut, G4bool ascii=false);
194  virtual G4bool Retrieve(std::ifstream& fIn, G4bool ascii=false);
195  // To store/retrieve persistent data to/from file streams.
196 
197  friend std::ostream& operator<<(std::ostream&, const G4PhysicsVector&);
198 
199  inline void SetVerboseLevel(G4int value);
200  inline G4int GetVerboseLevel(G4int);
201  // Set/Get Verbose level
202 
203  protected:
204 
205  void DeleteData();
206  void CopyData(const G4PhysicsVector& vec);
207  // Internal methods for allowing copy of objects
208 
209  protected:
210 
211  G4PhysicsVectorType type; // The type of PhysicsVector (enumerator)
212 
213  G4double edgeMin; // Energy of first point
214  G4double edgeMax; // Energy of the last point
215 
217 
218  G4PVDataVector dataVector; // Vector to keep the crossection/energyloss
219  G4PVDataVector binVector; // Vector to keep energy
220  G4PVDataVector secDerivative; // Vector to keep second derivatives
221 
222  private:
223 
225 
226  inline G4double LinearInterpolation(size_t idx, G4double energy) const;
227  // Linear interpolation function
228  inline G4double SplineInterpolation(size_t idx, G4double energy) const;
229  // Spline interpolation function
230 
231  inline G4double Interpolation(size_t idx, G4double energy) const;
232 
233  inline size_t FindBinLocation(G4double theEnergy) const;
234  // Find the bin# in which theEnergy belongs
235 
237 
238  protected:
239 
240  G4double dBin; // Bin width - useful only for fixed binning
241  G4double baseBin; // Set this in constructor for performance
242 
244 };
245 
246 #include "G4PhysicsVector.icc"
247 
248 #endif
friend std::ostream & operator<<(std::ostream &, const G4PhysicsVector &)
G4PhysicsVectorType GetType() const
G4PVDataVector dataVector
G4double LinearInterpolation(size_t idx, G4double energy) const
G4double FindLinearEnergy(G4double rand) const
G4double Interpolation(size_t idx, G4double energy) const
G4double GetValue(G4double theEnergy, G4bool &isOutRange) const
G4double GetMaxEnergy() const
void CopyData(const G4PhysicsVector &vec)
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)
G4double operator[](const size_t binNumber) const
G4int operator!=(const G4PhysicsVector &right) const
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
size_t FindBinLocation(G4double theEnergy) const
G4double Value(G4double theEnergy, size_t &lastidx) const
virtual G4bool Store(std::ofstream &fOut, G4bool ascii=false)
G4double SplineInterpolation(size_t idx, G4double energy) const
G4double energy(const ThreeVector &p, const G4double m)
G4int GetVerboseLevel(G4int)
virtual G4bool Retrieve(std::ifstream &fIn, G4bool ascii=false)
void SetVerboseLevel(G4int value)
double G4double
Definition: G4Types.hh:76
G4double operator()(const size_t binNumber) const
G4bool IsFilledVectorExist() const
void ComputeSecDerivatives()
std::vector< G4double > G4PVDataVector
virtual ~G4PhysicsVector()
G4PhysicsVector & operator=(const G4PhysicsVector &)