ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4PhysicsVector.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4PhysicsVector.hh
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 //
28 //
29 //---------------------------------------------------------------
30 // GEANT 4 class header file
31 //
32 // G4PhysicsVector.hh
33 //
34 // Class description:
35 //
36 // A physics vector which has values of energy-loss, cross-section,
37 // and other physics values of a particle in matter in a given
38 // range of the energy, momentum, etc.
39 // This class serves as the base class for a vector having various
40 // energy scale, for example like 'log', 'linear', 'free', etc.
41 
42 // History:
43 // 02 Dec. 1995, G.Cosmo : Structure created based on object model
44 // 03 Mar. 1996, K.Amako : Implemented the 1st version
45 // 27 Apr. 1996, K.Amako : Cache mechanism added
46 // 01 Jul. 1996, K.Amako : Now GetValue not virtual
47 // 21 Sep. 1996, K.Amako : Added [] and () operators
48 // 11 Nov. 2000, H.Kurashige : Use STL vector for dataVector and binVector
49 // 09 Mar. 2001, H.Kurashige : Added G4PhysicsVectorType & Store/Retrieve()
50 // 02 Apr. 2008, A.Bagulya : Added SplineInterpolation() and SetSpline()
51 // 11 May 2009, V.Ivanchenko : Added ComputeSecondDerivatives
52 // 19 Jun. 2009, V.Ivanchenko : Removed hidden bin
53 // 22 Dec. 2009 H.Kurashige : Use pointers to G4PVDataVector
54 // 04 May. 2010 H.Kurashige : Use G4PhysicsVectorCache
55 // 28 May 2010 H.Kurashige : Stop using pointers to G4PVDataVector
56 // 16 Aug. 2011 H.Kurashige : Add dBin, baseBin and verboseLevel
57 // 02 Oct. 2013 V.Ivanchenko : FindBinLocation method become inlined;
58 // instead of G4Pow G4Log is used
59 // 15 Mar. 2019 M.Novak : added Value method with the known log-energy value
60 // that can avoid the log call in case of log-vectors
61 // 16 July 2019 M.Novak : special LogVectorValue method for log-vectors
62 //---------------------------------------------------------------
63 
64 #ifndef G4PhysicsVector_h
65 #define G4PhysicsVector_h 1
66 
67 #include <iostream>
68 #include <fstream>
69 #include <vector>
70 
71 #include "globals.hh"
72 #include "G4ios.hh"
73 #include "G4PhysicsVectorType.hh"
74 #include "G4Log.hh"
75 
76 typedef std::vector<G4double> G4PVDataVector;
77 
79 {
80  public:// with description
81 
82  explicit G4PhysicsVector(G4bool spline = false);
83  // default constructor - vector will be filled via Retrieve() method
84 
87  // Copy constructor and assignment operator.
88 
89  virtual ~G4PhysicsVector();
90 
91  G4double Value(G4double theEnergy, size_t& lastidx) const;
92  // Get the cross-section/energy-loss value corresponding to the
93  // given energy. An appropriate interpolation is used to calculate
94  // the value. Consumer code got changed index and may reuse it
95  // for the next call to save CPU for bin location.
96 
97  inline G4double LogVectorValue(const G4double theEnergy,
98  const G4double theLogEnergy) const;
99  // Same as the Value method above but specialised for log-vector type.
100  // Note, unlike the general Value method above, this method will work
101  // properly only in case of G4PhysicsLogVector-s.
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 instead of the previous method if bin location
108  // cannot be kept thread safe
109 
110  inline G4double GetValue(G4double theEnergy, G4bool& isOutRange) const;
111  // Obsolete method to get value, isOutRange is not used anymore.
112  // This method is kept for the compatibility reason.
113 
114  G4bool operator==(const G4PhysicsVector &right) const ;
115  G4bool operator!=(const G4PhysicsVector &right) const ;
116 
117  inline G4double operator[](const size_t index) const ;
118  // Returns the value for the specified index of the dataVector
119  // The boundary check will not be done.
120 
121  inline G4double operator()(const size_t index) const ;
122  // Returns the value for the specified index of the dataVector
123  // The boundary check will not be done.
124 
125  inline void PutValue(size_t index, G4double theValue);
126  // Put 'theValue' into the dataVector specified by 'index'.
127  // Take note that the 'index' starts from '0'.
128  // To fill the vector, you have beforehand to construct a vector
129  // by the constructor with Emin, Emax, Nbin. 'theValue' should
130  // be the crosssection/energyloss value corresponding to the
131  // energy of the index.
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 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 compute cross section or dEdx
143  // before filling the vector by PutValue(..).
144 
145  inline G4double GetMaxEnergy() const;
146  // Returns the energy of the last point of the vector
147 
148  G4double GetLowEdgeEnergy(size_t binNumber) const;
149  // Obsolete method
150  // Get the energy value at the low edge of the specified bin.
151  // Take note that the 'binNumber' starts from '0'.
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  inline size_t ComputeLogVectorBin(const G4double logenergy) const;
163  // Computes the lower index the energy bin in case of log-vector i.e.
164  // in case of vectors with equal bin widths on log-scale.
165 
166  void FillSecondDerivatives();
167  // Initialise second derivatives for spline keeping
168  // 3d derivative continues - default algorithm
169  // Warning: this method should be called when the vector
170  // is already filled
171 
172  void ComputeSecDerivatives();
173  // Initialise second derivatives for spline using algorithm
174  // which garantee only 1st derivative continues
175  // Warning: this method should be called when the vector
176  // is already filled
177 
178  void ComputeSecondDerivatives(G4double firstPointDerivative,
179  G4double endPointDerivative);
180  // Initialise second derivatives for spline using
181  // user defined 1st derivatives at edge points
182  // Warning: this method should be called when the vector
183  // is already filled
184 
185  G4double FindLinearEnergy(G4double rand) const;
186  // Find energy using linear interpolation for vector
187  // filled by cumulative probability function
188  // value of rand should be between 0 and 1
189 
190  inline G4bool IsFilledVectorExist() const;
191  // Is non-empty physics vector already exist?
192 
193  inline G4PhysicsVectorType GetType() const;
194  // Get physics vector type
195 
196  inline void SetSpline(G4bool);
197  // Activate/deactivate Spline interpolation.
198 
199  G4bool Store(std::ofstream& fOut, G4bool ascii=false) const;
200  virtual G4bool Retrieve(std::ifstream& fIn, G4bool ascii=false);
201  // To store/retrieve persistent data to/from file streams.
202 
203  friend std::ostream& operator<<(std::ostream&, const G4PhysicsVector&);
204  void DumpValues(G4double unitE=1.0, G4double unitV=1.0) const;
205  // print vector
206 
207  inline void SetVerboseLevel(G4int value);
208 
209  inline G4double Interpolation(size_t idx, G4double energy) const;
210 
211  protected:
212 
213  void DeleteData();
214  void CopyData(const G4PhysicsVector& vec);
215  // Internal methods for allowing copy of objects
216 
217  void PrintPutValueError(size_t index);
218 
219  protected:
220 
221  G4PhysicsVectorType type; // The type of PhysicsVector (enumerator)
222 
223  G4double edgeMin; // Energy of first point
224  G4double edgeMax; // Energy of the last point
225 
227 
228  G4PVDataVector dataVector; // Vector to keep the crossection/energyloss
229  G4PVDataVector binVector; // Vector to keep energy
230  G4PVDataVector secDerivative; // Vector to keep second derivatives
231 
232  private:
233 
235 
236  inline G4double LinearInterpolation(size_t idx, G4double energy) const;
237  // Linear interpolation function
238  inline G4double SplineInterpolation(size_t idx, G4double energy) const;
239  // Spline interpolation function
240 
241  inline size_t FindBinLocation(G4double theEnergy) const;
242  // find low edge index of a bin for given energy
243  // min value 0, max value VectorLength-1
244 
246 
247  protected:
248 
249  G4double invdBin; // 1/Bin width - useful only for fixed binning
250  G4double baseBin; // Set this in constructor for performance
251 
253 };
254 
255 #include "G4PhysicsVector.icc"
256 
257 #endif