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 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /global/management/include/G4PhysicsVector.hh (Version 11.3.0) and /global/management/include/G4PhysicsVector.hh (Version 11.2)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // G4PhysicsVector                                 26 // G4PhysicsVector
 27 //                                                 27 //
 28 // Class description:                              28 // Class description:
 29 //                                                 29 //
 30 // A physics vector which has values of energy     30 // A physics vector which has values of energy-loss, cross-section,
 31 // and other physics values of a particle in m     31 // and other physics values of a particle in matter in a given
 32 // range of energy, momentum, etc.                 32 // range of energy, momentum, etc.
 33 // This class serves as the base class for a v     33 // This class serves as the base class for a vector having various
 34 // energy scale, for example like 'log', 'line     34 // energy scale, for example like 'log', 'linear', 'free', etc.
 35                                                    35 
 36 // Authors:                                        36 // Authors:
 37 // - 02 Dec. 1995, G.Cosmo: Structure created      37 // - 02 Dec. 1995, G.Cosmo: Structure created based on object model
 38 // - 03 Mar. 1996, K.Amako: Implemented the 1s     38 // - 03 Mar. 1996, K.Amako: Implemented the 1st version
 39 // Revisions:                                      39 // Revisions:
 40 // - 11 Nov. 2000, H.Kurashige: Use STL vector     40 // - 11 Nov. 2000, H.Kurashige: Use STL vector for dataVector and binVector
 41 // -------------------------------------------     41 // --------------------------------------------------------------------
 42 #ifndef G4PhysicsVector_hh                         42 #ifndef G4PhysicsVector_hh
 43 #define G4PhysicsVector_hh 1                       43 #define G4PhysicsVector_hh 1
 44                                                    44 
 45 #include <fstream>                                 45 #include <fstream>
 46 #include <iostream>                                46 #include <iostream>
 47 #include <vector>                                  47 #include <vector>
 48                                                    48 
 49 #include "G4Log.hh"                                49 #include "G4Log.hh"
 50 #include "G4PhysicsVectorType.hh"                  50 #include "G4PhysicsVectorType.hh"
 51 #include "G4ios.hh"                                51 #include "G4ios.hh"
 52 #include "globals.hh"                              52 #include "globals.hh"
 53                                                    53 
 54 class G4PhysicsVector                              54 class G4PhysicsVector
 55 {                                                  55 {
 56 public:                                            56 public:
 57   // Default constructor - vector will be fill     57   // Default constructor - vector will be filled via Retrieve() method
 58   // Free vector may be filled via InsertValue     58   // Free vector may be filled via InsertValue(..) method
 59   explicit G4PhysicsVector(G4bool spline = fal     59   explicit G4PhysicsVector(G4bool spline = false);
 60                                                    60 
 61   // Copy constructor and assignment operator      61   // Copy constructor and assignment operator
 62   G4PhysicsVector(const G4PhysicsVector&) = de     62   G4PhysicsVector(const G4PhysicsVector&) = default;
 63   G4PhysicsVector& operator=(const G4PhysicsVe     63   G4PhysicsVector& operator=(const G4PhysicsVector&) = default;
 64                                                    64 
 65   // not used operators                            65   // not used operators
 66   G4PhysicsVector(const G4PhysicsVector&&) = d     66   G4PhysicsVector(const G4PhysicsVector&&) = delete;
 67   G4PhysicsVector& operator=(const G4PhysicsVe     67   G4PhysicsVector& operator=(const G4PhysicsVector&&) = delete;
 68   G4bool operator==(const G4PhysicsVector& rig     68   G4bool operator==(const G4PhysicsVector& right) const = delete;
 69   G4bool operator!=(const G4PhysicsVector& rig     69   G4bool operator!=(const G4PhysicsVector& right) const = delete;
 70                                                    70 
 71   virtual ~G4PhysicsVector() = default;            71   virtual ~G4PhysicsVector() = default;
 72                                                    72 
 73   // Get the cross-section/energy-loss value c     73   // Get the cross-section/energy-loss value corresponding to the
 74   // given energy. An appropriate interpolatio     74   // given energy. An appropriate interpolation is used to calculate
 75   // the value. Consumer code gets changed ind     75   // the value. Consumer code gets changed index and may reuse it
 76   // for the next call to save CPU for bin loc     76   // for the next call to save CPU for bin location.
 77   inline G4double Value(const G4double energy,     77   inline G4double Value(const G4double energy, std::size_t& lastidx) const;
 78                                                    78 
 79   // Get the cross-section/energy-loss value c     79   // Get the cross-section/energy-loss value corresponding to the
 80   // given energy. An appropriate interpolatio     80   // given energy. An appropriate interpolation is used to calculate
 81   // the value. This method should be used if      81   // the value. This method should be used if bin location cannot be 
 82   // kept in the user code.                        82   // kept in the user code.
 83   inline G4double Value(const G4double energy)     83   inline G4double Value(const G4double energy) const;
 84                                                    84 
 85   // Obsolete method to get value, 'isOutRange     85   // Obsolete method to get value, 'isOutRange' is not used anymore.
 86   // This method is kept for the compatibility     86   // This method is kept for the compatibility reason
 87   inline G4double GetValue(const G4double ener     87   inline G4double GetValue(const G4double energy, G4bool& isOutRange) const;
 88                                                    88 
 89   // Same as the Value() method above but spec     89   // Same as the Value() method above but specialised for log-vector type.
 90   // Note, unlike the general Value() method a     90   // Note, unlike the general Value() method above, this method will work
 91   // properly only for G4PhysicsLogVector.         91   // properly only for G4PhysicsLogVector.
 92   inline G4double LogVectorValue(const G4doubl     92   inline G4double LogVectorValue(const G4double energy,
 93                                  const G4doubl     93                                  const G4double theLogEnergy) const;
 94                                                    94 
 95   // Same as the Value() method above but spec     95   // Same as the Value() method above but specialised for free vector
 96   // with logarithmic seach of bin number          96   // with logarithmic seach of bin number
 97   inline G4double LogFreeVectorValue(const G4d     97   inline G4double LogFreeVectorValue(const G4double energy,
 98                                      const G4d     98                                      const G4double theLogEnergy) const;
 99                                                    99 
100   // Returns the value for the specified index    100   // Returns the value for the specified index of the dataVector
101   // The boundary check will not be done          101   // The boundary check will not be done
102   inline G4double operator[](const std::size_t    102   inline G4double operator[](const std::size_t index) const;
103   inline G4double operator()(const std::size_t    103   inline G4double operator()(const std::size_t index) const;
104                                                   104 
105   // Put data into the vector at 'index' posit    105   // Put data into the vector at 'index' position.
106   // Take note that the 'index' starts from '0    106   // Take note that the 'index' starts from '0'.
107   // It is assumed that energies are already f    107   // It is assumed that energies are already filled.
108   inline void PutValue(const std::size_t index    108   inline void PutValue(const std::size_t index, const G4double value);
109                                                   109 
110   // Returns the value in the energy specified    110   // Returns the value in the energy specified by 'index'
111   // of the energy vector. The boundary check     111   // of the energy vector. The boundary check will not be done.
112   // Use this when compute cross-section, dEdx    112   // Use this when compute cross-section, dEdx, or other value
113   // before filling the vector by PutValue().     113   // before filling the vector by PutValue().
114   inline G4double Energy(const std::size_t ind    114   inline G4double Energy(const std::size_t index) const;
115   inline G4double GetLowEdgeEnergy(const std::    115   inline G4double GetLowEdgeEnergy(const std::size_t index) const;
116                                                   116 
117   // Returns the energy of the first and the l    117   // Returns the energy of the first and the last point of the vector.
118   inline G4double GetMinEnergy() const;           118   inline G4double GetMinEnergy() const;
119   inline G4double GetMaxEnergy() const;           119   inline G4double GetMaxEnergy() const;
120                                                   120 
121   // Returns the data of the first and the las    121   // Returns the data of the first and the last point of the vector.
122   // If the vector is empty returns zeros.        122   // If the vector is empty returns zeros.
123   inline G4double GetMinValue() const;            123   inline G4double GetMinValue() const;
124   inline G4double GetMaxValue() const;            124   inline G4double GetMaxValue() const;
125                                                   125 
126   // Get the total length of the vector           126   // Get the total length of the vector
127   inline std::size_t GetVectorLength() const;     127   inline std::size_t GetVectorLength() const;
128                                                   128 
129   // Computes the lower index the energy bin i    129   // Computes the lower index the energy bin in case of log-vector i.e.
130   // in case of vectors with equal bin widths     130   // in case of vectors with equal bin widths on log-scale
131   // Note, that no check on the boundary is pe    131   // Note, that no check on the boundary is performed
132   inline std::size_t ComputeLogVectorBin(const    132   inline std::size_t ComputeLogVectorBin(const G4double logenergy) const;
133                                                   133 
134   // Get physics vector type.                     134   // Get physics vector type.
135   inline G4PhysicsVectorType GetType() const;     135   inline G4PhysicsVectorType GetType() const;
136                                                   136 
137   // True if using spline interpolation.          137   // True if using spline interpolation.
138   inline G4bool GetSpline() const;                138   inline G4bool GetSpline() const;
139                                                   139 
140   // Define verbosity level.                      140   // Define verbosity level.
141   inline void SetVerboseLevel(G4int value);       141   inline void SetVerboseLevel(G4int value);
142                                                   142 
143   // Find energy using linear interpolation fo    143   // Find energy using linear interpolation for vector
144   // filled by cumulative probability function    144   // filled by cumulative probability function.
145   // Assuming that vector is already filled.      145   // Assuming that vector is already filled.
146   inline G4double FindLinearEnergy(const G4dou    146   inline G4double FindLinearEnergy(const G4double rand) const;
147                                                   147 
148   // Find low edge index of a bin for given en    148   // Find low edge index of a bin for given energy.
149   // Min value 0, max value idxmax.               149   // Min value 0, max value idxmax.
150   std::size_t FindBin(const G4double energy, s    150   std::size_t FindBin(const G4double energy, std::size_t idx) const;
151                                                   151 
152   // Scale all values of the vector by factorV    152   // Scale all values of the vector by factorV, energies by vectorE.
153   // AFter this method FillSecondDerivatives(.    153   // AFter this method FillSecondDerivatives(...) should be called. 
154   // This method may be applied for example af    154   // This method may be applied for example after retrieving a vector 
155   // from an external file to convert values i    155   // from an external file to convert values into Geant4 units.
156   void ScaleVector(const G4double factorE, con    156   void ScaleVector(const G4double factorE, const G4double factorV);
157                                                   157 
158   // This method should be called when the vec    158   // This method should be called when the vector is fully filled 
159   // There are 3 types of second derivative co    159   // There are 3 types of second derivative computations:
160   //    fSplineSimple -     2d derivative cont    160   //    fSplineSimple -     2d derivative continues
161   //    fSplineBase -       3d derivative cont    161   //    fSplineBase -       3d derivative continues (the default)
162   //    fSplineFixedEdges - 3d derivatives con    162   //    fSplineFixedEdges - 3d derivatives continues, 1st and last 
163   //                        derivatives are fi    163   //                        derivatives are fixed  
164   void FillSecondDerivatives(const G4SplineTyp    164   void FillSecondDerivatives(const G4SplineType = G4SplineType::Base,
165                              const G4double di    165                              const G4double dir1 = 0.0,
166                              const G4double di    166                              const G4double dir2 = 0.0);
167                                                   167 
168   // This method can be applied if both energy    168   // This method can be applied if both energy and data values 
169   // grow monotonically, for example, if in th    169   // grow monotonically, for example, if in this vector a 
170   // cumulative probability density function i    170   // cumulative probability density function is stored. 
171   G4double GetEnergy(const G4double value) con    171   G4double GetEnergy(const G4double value) const;
172                                                   172 
173   // To store/retrieve persistent data to/from    173   // To store/retrieve persistent data to/from file streams.
174   G4bool Store(std::ofstream& fOut, G4bool asc    174   G4bool Store(std::ofstream& fOut, G4bool ascii = false) const;
175   G4bool Retrieve(std::ifstream& fIn, G4bool a    175   G4bool Retrieve(std::ifstream& fIn, G4bool ascii = false);
176                                                   176 
177   // Print vector                                 177   // Print vector
178   friend std::ostream& operator<<(std::ostream    178   friend std::ostream& operator<<(std::ostream&, const G4PhysicsVector&);
179   void DumpValues(G4double unitE = 1.0, G4doub    179   void DumpValues(G4double unitE = 1.0, G4double unitV = 1.0) const;
180                                                   180 
181 protected:                                        181 protected:
182                                                   182 
183   // The default implements a free vector init    183   // The default implements a free vector initialisation.
184   virtual void Initialise();                      184   virtual void Initialise();
185                                                   185 
186   void PrintPutValueError(std::size_t index, G    186   void PrintPutValueError(std::size_t index, G4double value, 
187                           const G4String& text    187                           const G4String& text);
188                                                   188 
189 private:                                          189 private:
190                                                   190 
191   void ComputeSecDerivative0();                   191   void ComputeSecDerivative0();
192   void ComputeSecDerivative1();                   192   void ComputeSecDerivative1();
193   void ComputeSecDerivative2(const G4double fi    193   void ComputeSecDerivative2(const G4double firstPointDerivative,
194                              const G4double en    194                              const G4double endPointDerivative);
195   // Internal methods for computing of spline     195   // Internal methods for computing of spline coeffitients
196                                                   196 
197   // Linear or spline interpolation.              197   // Linear or spline interpolation.
198   inline G4double Interpolation(const std::siz    198   inline G4double Interpolation(const std::size_t idx,
199                                 const G4double    199                                 const G4double energy) const;
200                                                   200 
201   // Assuming (edgeMin <= energy <= edgeMax).     201   // Assuming (edgeMin <= energy <= edgeMax).
202   inline std::size_t LogBin(const G4double ene    202   inline std::size_t LogBin(const G4double energy, const G4double loge) const;
203   inline std::size_t BinaryBin(const G4double     203   inline std::size_t BinaryBin(const G4double energy) const;
204   inline std::size_t GetBin(const G4double ene    204   inline std::size_t GetBin(const G4double energy) const;
205                                                   205 
206 protected:                                        206 protected:
207                                                   207 
208   G4double edgeMin = 0.0;  // Energy of first     208   G4double edgeMin = 0.0;  // Energy of first point
209   G4double edgeMax = 0.0;  // Energy of the la    209   G4double edgeMax = 0.0;  // Energy of the last point
210                                                   210 
211   G4double invdBin = 0.0;  // 1/Bin width for     211   G4double invdBin = 0.0;  // 1/Bin width for linear and log vectors
212   G4double logemin = 0.0;  // used only for lo    212   G4double logemin = 0.0;  // used only for log vector
213                                                   213 
214   G4double iBin1 = 0.0;  // 1/Bin width for sc    214   G4double iBin1 = 0.0;  // 1/Bin width for scale log vector
215   G4double lmin1 = 0.0;  // used for log searc    215   G4double lmin1 = 0.0;  // used for log search of free vector
216                                                   216 
217   G4int verboseLevel = 0;                         217   G4int verboseLevel = 0;
218   std::size_t idxmax = 0;                         218   std::size_t idxmax = 0;
219   std::size_t imax1 = 0;                          219   std::size_t imax1 = 0;
220   std::size_t numberOfNodes = 0;                  220   std::size_t numberOfNodes = 0;
221   std::size_t nLogNodes = 0;                      221   std::size_t nLogNodes = 0;
222                                                   222 
223   G4PhysicsVectorType type = T_G4PhysicsFreeVe    223   G4PhysicsVectorType type = T_G4PhysicsFreeVector;
224   // The type of PhysicsVector (enumerator)       224   // The type of PhysicsVector (enumerator)
225                                                   225 
226   std::vector<G4double> binVector;      // ene    226   std::vector<G4double> binVector;      // energy
227   std::vector<G4double> dataVector;     // cro    227   std::vector<G4double> dataVector;     // crossection/energyloss
228   std::vector<G4double> secDerivative;  // sec    228   std::vector<G4double> secDerivative;  // second derivatives
229   std::vector<std::size_t> scale;       // log    229   std::vector<std::size_t> scale;       // log seach
230                                                   230 
231 private:                                          231 private:
232                                                   232 
233   G4bool useSpline = false;                       233   G4bool useSpline = false;
234 };                                                234 };
235                                                   235 
236 #include "G4PhysicsVector.icc"                    236 #include "G4PhysicsVector.icc"
237                                                   237 
238 #endif                                            238 #endif
239                                                   239