Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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// G4PhysicsVector
27//
28// Class description:
29//
30// A physics vector which has values of energy-loss, cross-section,
31// and other physics values of a particle in matter in a given
32// range of energy, momentum, etc.
33// This class serves as the base class for a vector having various
34// energy scale, for example like 'log', 'linear', 'free', etc.
35
36// Authors:
37// - 02 Dec. 1995, G.Cosmo: Structure created based on object model
38// - 03 Mar. 1996, K.Amako: Implemented the 1st version
39// Revisions:
40// - 11 Nov. 2000, H.Kurashige: Use STL vector for dataVector and binVector
41// - 02 Apr. 2008, A.Bagulya: Added SplineInterpolation() and SetSpline()
42// - 19 Jun. 2009, V.Ivanchenko: Removed hidden bin
43// - 15 Mar. 2019 M.Novak: added Value method with the known log-energy value
44// that can avoid the log call in case of log-vectors
45// --------------------------------------------------------------------
46#ifndef G4PhysicsVector_hh
47#define G4PhysicsVector_hh 1
48
49#include <fstream>
50#include <iostream>
51#include <vector>
52
53#include "G4Log.hh"
55#include "G4ios.hh"
56#include "globals.hh"
57
58using G4PVDataVector = std::vector<G4double>;
59
61{
62 public:
63 explicit G4PhysicsVector(G4bool spline = false);
64 // Default constructor - vector will be filled via Retrieve() method
65
68 // Copy constructor and assignment operator
69
70 G4bool operator==(const G4PhysicsVector& right) const;
71 G4bool operator!=(const G4PhysicsVector& right) const;
72 // Equality operators
73
74 virtual ~G4PhysicsVector();
75
76 G4double Value(G4double theEnergy, std::size_t& lastidx) const;
77 // Get the cross-section/energy-loss value corresponding to the
78 // given energy. An appropriate interpolation is used to calculate
79 // the value. Consumer code gets changed index and may reuse it
80 // for the next call to save CPU for bin location.
81
82 inline G4double LogVectorValue(const G4double theEnergy,
83 const G4double theLogEnergy) const;
84 // Same as the Value() method above but specialised for log-vector type.
85 // Note, unlike the general Value() method above, this method will work
86 // properly only in case of G4PhysicsLogVector-s.
87
88 inline G4double Value(G4double theEnergy) const;
89 // Get the cross-section/energy-loss value corresponding to the
90 // given energy. An appropriate interpolation is used to calculate
91 // the value. This method is kept for backward compatibility reason,
92 // it should be used instead of the previous method if bin location
93 // cannot be kept thread safe
94
95 inline G4double GetValue(G4double theEnergy, G4bool& isOutRange) const;
96 // Obsolete method to get value, 'isOutRange' is not used anymore.
97 // This method is kept for the compatibility reason
98
99 inline G4double operator[](const std::size_t index) const;
100 // Returns the value for the specified index of the dataVector
101 // The boundary check will not be done
102
103 inline G4double operator()(const std::size_t index) const;
104 // Returns the value for the specified index of the dataVector
105 // The boundary check will not be done
106
107 inline void PutValue(std::size_t index, G4double theValue);
108 // Put 'theValue' into the dataVector specified by 'index'.
109 // Take note that the 'index' starts from '0'.
110 // To fill the vector, need to beforehand construct a vector
111 // by the constructor with Emin, Emax, Nbin. 'theValue' should
112 // be the cross-section/energy-loss value corresponding to the
113 // energy of the index
114
115 virtual void ScaleVector(G4double factorE, G4double factorV);
116 // Scale all values of the vector and second derivatives
117 // by factorV, energies by vectorE. This method may be applied
118 // for example after retrieving a vector from an external file to
119 // convert values into Geant4 units
120
121 inline G4double Energy(std::size_t index) const;
122 // Returns the value in the energy specified by 'index'
123 // of the energy vector. The boundary check will not be done.
124 // Use this function when compute cross-section or dEdx
125 // before filling the vector by PutValue()
126
127 inline G4double GetMaxEnergy() const;
128 // Returns the energy of the last point of the vector
129
130 G4double GetLowEdgeEnergy(std::size_t binNumber) const;
131 // Obsolete method
132 // Get the energy value at the low edge of the specified bin.
133 // Take note that the 'binNumber' starts from '0'.
134 // The boundary check will not be done
135
136 inline std::size_t GetVectorLength() const;
137 // Get the total length of the vector
138
139 inline std::size_t FindBin(const G4double energy,
140 const std::size_t idx) const;
141 // Find low edge index of a bin for given energy.
142 // Min value 0, max value VectorLength-1.
143 // idx is suggested bin number from user code
144
145 inline std::size_t ComputeLogVectorBin(const G4double logenergy) const;
146 // Computes the lower index the energy bin in case of log-vector i.e.
147 // in case of vectors with equal bin widths on log-scale
148
150 // Initialise second derivatives for Spline keeping
151 // 3rd derivative continues - default algorithm.
152 // Warning: this method should be called when the vector
153 // is already filled
154
156 // Initialise second derivatives for Spline using algorithm
157 // which garantee only 1st derivative continues.
158 // Warning: this method should be called when the vector
159 // is already filled
160
161 void ComputeSecondDerivatives(G4double firstPointDerivative,
162 G4double endPointDerivative);
163 // Initialise second derivatives for Spline using
164 // user defined 1st derivatives at edge points.
165 // Warning: this method should be called when the vector
166 // is already filled
167
169 // Find energy using linear interpolation for vector
170 // filled by cumulative probability function
171 // value of rand should be between 0 and 1
172
174 // Is non-empty physics vector already exist?
175
177 // Get physics vector type
178
179 inline void SetSpline(G4bool);
180 // Activate/deactivate Spline interpolation
181
182 G4bool Store(std::ofstream& fOut, G4bool ascii = false) const;
183 virtual G4bool Retrieve(std::ifstream& fIn, G4bool ascii = false);
184 // To store/retrieve persistent data to/from file streams.
185
186 friend std::ostream& operator<<(std::ostream&, const G4PhysicsVector&);
187 void DumpValues(G4double unitE = 1.0, G4double unitV = 1.0) const;
188 // Print vector
189
190 inline void SetVerboseLevel(G4int value);
191
192 protected:
193 void DeleteData();
194 void CopyData(const G4PhysicsVector& vec);
195 // Internal methods for allowing copy of objects
196
197 void PrintPutValueError(std::size_t index);
198
200 // The type of PhysicsVector (enumerator)
201
202 G4double edgeMin = 0.0; // Energy of first point
203 G4double edgeMax = 0.0; // Energy of the last point
204
205 G4double invdBin = 0.0; // 1/Bin width - useful only for fixed binning
206 G4double baseBin = 0.0; // Set this in constructor for performance
207
209 std::size_t numberOfNodes = 0;
210
211 G4PVDataVector dataVector; // Vector to keep the crossection/energyloss
212 G4PVDataVector binVector; // Vector to keep energy
213 G4PVDataVector secDerivative; // Vector to keep second derivatives
214
215 private:
216 G4bool SplinePossible();
217
218 inline std::size_t FindBinLocation(const G4double theEnergy) const;
219 // Find low edge index of a bin for given energy.
220 // Min value 0, max value VectorLength-1
221
222 inline G4double Interpolation(const std::size_t idx,
223 const G4double energy) const;
224
225 G4bool useSpline = false;
226};
227
228#include "G4PhysicsVector.icc"
229
230#endif
G4PhysicsVectorType
@ T_G4PhysicsVector
std::vector< G4double > G4PVDataVector
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
void SetVerboseLevel(G4int value)
G4PVDataVector binVector
G4bool operator!=(const G4PhysicsVector &right) const
void ComputeSecondDerivatives(G4double firstPointDerivative, G4double endPointDerivative)
G4double Value(G4double theEnergy) const
G4PhysicsVectorType type
G4double Energy(std::size_t index) const
G4double Value(G4double theEnergy, std::size_t &lastidx) const
G4double GetMaxEnergy() const
G4double operator[](const std::size_t index) const
std::size_t FindBin(const G4double energy, const std::size_t idx) const
std::size_t ComputeLogVectorBin(const G4double logenergy) const
virtual void ScaleVector(G4double factorE, G4double factorV)
G4double GetLowEdgeEnergy(std::size_t binNumber) const
G4bool Store(std::ofstream &fOut, G4bool ascii=false) const
G4bool IsFilledVectorExist() const
G4double FindLinearEnergy(G4double rand) const
G4bool operator==(const G4PhysicsVector &right) const
G4PVDataVector secDerivative
std::size_t numberOfNodes
virtual ~G4PhysicsVector()
void PutValue(std::size_t index, G4double theValue)
G4PhysicsVectorType GetType() const
void ComputeSecDerivatives()
G4double operator()(const std::size_t index) const
void FillSecondDerivatives()
virtual G4bool Retrieve(std::ifstream &fIn, G4bool ascii=false)
void SetSpline(G4bool)
G4PVDataVector dataVector
void CopyData(const G4PhysicsVector &vec)
std::size_t GetVectorLength() const
G4double LogVectorValue(const G4double theEnergy, const G4double theLogEnergy) const
void PrintPutValueError(std::size_t index)
friend std::ostream & operator<<(std::ostream &, const G4PhysicsVector &)
G4PhysicsVector & operator=(const G4PhysicsVector &)
G4double GetValue(G4double theEnergy, G4bool &isOutRange) const
void DumpValues(G4double unitE=1.0, G4double unitV=1.0) const