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