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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 10.6.p2)


  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                             << 
 27 //                                                 26 //
 28 // Class description:                          << 
 29 //                                                 27 //
 30 // A physics vector which has values of energy <<  28 // 
 31 // and other physics values of a particle in m <<  29 //---------------------------------------------------------------
 32 // range of energy, momentum, etc.             <<  30 //      GEANT 4 class header file
 33 // This class serves as the base class for a v <<  31 //
 34 // energy scale, for example like 'log', 'line <<  32 //  G4PhysicsVector.hh
 35                                                <<  33 //
 36 // Authors:                                    <<  34 //  Class description:
 37 // - 02 Dec. 1995, G.Cosmo: Structure created  <<  35 //
 38 // - 03 Mar. 1996, K.Amako: Implemented the 1s <<  36 //    A physics vector which has values of energy-loss, cross-section, 
 39 // Revisions:                                  <<  37 //    and other physics values of a particle in matter in a given 
 40 // - 11 Nov. 2000, H.Kurashige: Use STL vector <<  38 //    range of the energy, momentum, etc.
 41 // ------------------------------------------- <<  39 //    This class serves as the base class for a vector having various 
 42 #ifndef G4PhysicsVector_hh                     <<  40 //    energy scale, for example like 'log', 'linear', 'free', etc.
 43 #define G4PhysicsVector_hh 1                   <<  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
 44                                                    66 
 45 #include <fstream>                             << 
 46 #include <iostream>                                67 #include <iostream>
                                                   >>  68 #include <fstream>
 47 #include <vector>                                  69 #include <vector>
 48                                                    70 
 49 #include "G4Log.hh"                            << 
 50 #include "G4PhysicsVectorType.hh"              << 
 51 #include "G4ios.hh"                            << 
 52 #include "globals.hh"                              71 #include "globals.hh"
                                                   >>  72 #include "G4ios.hh"
                                                   >>  73 #include "G4PhysicsVectorType.hh"
                                                   >>  74 #include "G4Log.hh"
                                                   >>  75 
                                                   >>  76 typedef std::vector<G4double> G4PVDataVector;
 53                                                    77 
 54 class G4PhysicsVector                          <<  78 class G4PhysicsVector 
 55 {                                                  79 {
 56 public:                                        <<  80   public:// with description
 57   // Default constructor - vector will be fill <<  81 
 58   // Free vector may be filled via InsertValue <<  82     explicit G4PhysicsVector(G4bool spline = false);
 59   explicit G4PhysicsVector(G4bool spline = fal <<  83          // default constructor - vector will be filled via Retrieve() method 
 60                                                <<  84 
 61   // Copy constructor and assignment operator  <<  85     G4PhysicsVector(const G4PhysicsVector&);
 62   G4PhysicsVector(const G4PhysicsVector&) = de <<  86     G4PhysicsVector& operator=(const G4PhysicsVector&);
 63   G4PhysicsVector& operator=(const G4PhysicsVe <<  87          // Copy constructor and assignment operator.
 64                                                <<  88 
 65   // not used operators                        <<  89     virtual ~G4PhysicsVector();
 66   G4PhysicsVector(const G4PhysicsVector&&) = d <<  90 
 67   G4PhysicsVector& operator=(const G4PhysicsVe <<  91     G4double Value(G4double theEnergy, size_t& lastidx) const; 
 68   G4bool operator==(const G4PhysicsVector& rig <<  92          // Get the cross-section/energy-loss value corresponding to the
 69   G4bool operator!=(const G4PhysicsVector& rig <<  93          // given energy. An appropriate interpolation is used to calculate
 70                                                <<  94          // the value. Consumer code got changed index and may reuse it
 71   virtual ~G4PhysicsVector() = default;        <<  95          // for the next call to save CPU for bin location. 
 72                                                <<  96 
 73   // Get the cross-section/energy-loss value c <<  97     inline G4double LogVectorValue(const G4double theEnergy,
 74   // given energy. An appropriate interpolatio <<  98                                    const G4double theLogEnergy) const;
 75   // the value. Consumer code gets changed ind <<  99          // Same as the Value method above but specialised for log-vector type.
 76   // for the next call to save CPU for bin loc << 100          // Note, unlike the general Value method above, this method will work
 77   inline G4double Value(const G4double energy, << 101          // properly only in case of G4PhysicsLogVector-s.
 78                                                << 102 
 79   // Get the cross-section/energy-loss value c << 103     inline G4double Value(G4double theEnergy) const; 
 80   // given energy. An appropriate interpolatio << 104          // Get the cross-section/energy-loss value corresponding to the
 81   // the value. This method should be used if  << 105          // given energy. An appropriate interpolation is used to calculate
 82   // kept in the user code.                    << 106          // the value. This method is kept for backward compatibility reason,
 83   inline G4double Value(const G4double energy) << 107          // it should be used instead of the previous method if bin location 
 84                                                << 108          // cannot be kept thread safe
 85   // Obsolete method to get value, 'isOutRange << 109 
 86   // This method is kept for the compatibility << 110     inline G4double GetValue(G4double theEnergy, G4bool& isOutRange) const;
 87   inline G4double GetValue(const G4double ener << 111          // Obsolete method to get value, isOutRange is not used anymore. 
 88                                                << 112          // This method is kept for the compatibility reason.
 89   // Same as the Value() method above but spec << 113 
 90   // Note, unlike the general Value() method a << 114     G4bool operator==(const G4PhysicsVector &right) const ;
 91   // properly only for G4PhysicsLogVector.     << 115     G4bool operator!=(const G4PhysicsVector &right) const ;
 92   inline G4double LogVectorValue(const G4doubl << 116 
 93                                  const G4doubl << 117     inline G4double operator[](const size_t index) const ;
 94                                                << 118          // Returns the value for the specified index of the dataVector
 95   // Same as the Value() method above but spec << 119          // The boundary check will not be done. 
 96   // with logarithmic seach of bin number      << 120 
 97   inline G4double LogFreeVectorValue(const G4d << 121     inline G4double operator()(const size_t index) const ;
 98                                      const G4d << 122          // Returns the value for the specified index of the dataVector
 99                                                << 123          // The boundary check will not be done. 
100   // Returns the value for the specified index << 124 
101   // The boundary check will not be done       << 125     inline void PutValue(size_t index, G4double theValue);
102   inline G4double operator[](const std::size_t << 126          // Put 'theValue' into the dataVector specified by 'index'.
103   inline G4double operator()(const std::size_t << 127          // Take note that the 'index' starts from '0'.
104                                                << 128          // To fill the vector, you have beforehand to construct a vector
105   // Put data into the vector at 'index' posit << 129          // by the constructor with Emin, Emax, Nbin. 'theValue' should
106   // Take note that the 'index' starts from '0 << 130          // be the crosssection/energyloss value corresponding to the  
107   // It is assumed that energies are already f << 131          // energy of the index. 
108   inline void PutValue(const std::size_t index << 132 
109                                                << 133     virtual void ScaleVector(G4double factorE, G4double factorV);
110   // Returns the value in the energy specified << 134          // Scale all values of the vector and second derivatives
111   // of the energy vector. The boundary check  << 135          // by factorV, energies by vectorE. This method may be applied 
112   // Use this when compute cross-section, dEdx << 136          // for example after Retrieve a vector from an external file to 
113   // before filling the vector by PutValue().  << 137          // convert values into Geant4 units
114   inline G4double Energy(const std::size_t ind << 138 
115   inline G4double GetLowEdgeEnergy(const std:: << 139     inline G4double Energy(size_t index) const;
116                                                << 140          // Returns the value in the energy specified by 'index'
117   // Returns the energy of the first and the l << 141          // of the energy vector. The boundary check will not be done. 
118   inline G4double GetMinEnergy() const;        << 142          // Use this function when compute cross section or dEdx 
119   inline G4double GetMaxEnergy() const;        << 143          // before filling the vector by PutValue(..).
120                                                << 144 
121   // Returns the data of the first and the las << 145     inline G4double GetMaxEnergy() const;
122   // If the vector is empty returns zeros.     << 146          // Returns the energy of the last point of the vector
123   inline G4double GetMinValue() const;         << 147 
124   inline G4double GetMaxValue() const;         << 148     G4double GetLowEdgeEnergy(size_t binNumber) const;
125                                                << 149          // Obsolete method
126   // Get the total length of the vector        << 150          // Get the energy value at the low edge of the specified bin.
127   inline std::size_t GetVectorLength() const;  << 151          // Take note that the 'binNumber' starts from '0'.
128                                                << 152          // The boundary check will not be done.
129   // Computes the lower index the energy bin i << 153 
130   // in case of vectors with equal bin widths  << 154     inline size_t GetVectorLength() const;
131   // Note, that no check on the boundary is pe << 155          // Get the total length of the vector. 
132   inline std::size_t ComputeLogVectorBin(const << 156 
133                                                << 157     inline size_t FindBin(G4double energy, size_t idx) const;
134   // Get physics vector type.                  << 158          // find low edge index of a bin for given energy
135   inline G4PhysicsVectorType GetType() const;  << 159          // min value 0, max value VectorLength-1
136                                                << 160          // idx is suggested bin number from user code
137   // True if using spline interpolation.       << 161 
138   inline G4bool GetSpline() const;             << 162     inline size_t ComputeLogVectorBin(const G4double logenergy) const;
139                                                << 163          // Computes the lower index the energy bin in case of log-vector i.e.
140   // Define verbosity level.                   << 164          // in case of vectors with equal bin widths on log-scale.
141   inline void SetVerboseLevel(G4int value);    << 165 
142                                                << 166     void FillSecondDerivatives();
143   // Find energy using linear interpolation fo << 167          // Initialise second derivatives for spline keeping 
144   // filled by cumulative probability function << 168          // 3d derivative continues - default algorithm
145   // Assuming that vector is already filled.   << 169          // Warning: this method should be called when the vector 
146   inline G4double FindLinearEnergy(const G4dou << 170          // is already filled
147                                                << 171 
148   // Find low edge index of a bin for given en << 172     void ComputeSecDerivatives();
149   // Min value 0, max value idxmax.            << 173          // Initialise second derivatives for spline using algorithm 
150   std::size_t FindBin(const G4double energy, s << 174          // which garantee only 1st derivative continues 
151                                                << 175          // Warning: this method should be called when the vector 
152   // Scale all values of the vector by factorV << 176          // is already filled
153   // AFter this method FillSecondDerivatives(. << 177 
154   // This method may be applied for example af << 178     void ComputeSecondDerivatives(G4double firstPointDerivative, 
155   // from an external file to convert values i << 179                                   G4double endPointDerivative);
156   void ScaleVector(const G4double factorE, con << 180          // Initialise second derivatives for spline using 
157                                                << 181          // user defined 1st derivatives at edge points
158   // This method should be called when the vec << 182          // Warning: this method should be called when the vector 
159   // There are 3 types of second derivative co << 183          // is already filled
160   //    fSplineSimple -     2d derivative cont << 184 
161   //    fSplineBase -       3d derivative cont << 185     G4double FindLinearEnergy(G4double rand) const;
162   //    fSplineFixedEdges - 3d derivatives con << 186          // Find energy using linear interpolation for vector
163   //                        derivatives are fi << 187          // filled by cumulative probability function 
164   void FillSecondDerivatives(const G4SplineTyp << 188          // value of rand should be between 0 and 1
165                              const G4double di << 189 
166                              const G4double di << 190     inline G4bool IsFilledVectorExist() const;
167                                                << 191          // Is non-empty physics vector already exist?
168   // This method can be applied if both energy << 192 
169   // grow monotonically, for example, if in th << 193     inline G4PhysicsVectorType GetType() const;
170   // cumulative probability density function i << 194          // Get physics vector type
171   G4double GetEnergy(const G4double value) con << 195   
172                                                << 196     inline void SetSpline(G4bool);
173   // To store/retrieve persistent data to/from << 197          // Activate/deactivate Spline interpolation.
174   G4bool Store(std::ofstream& fOut, G4bool asc << 198 
175   G4bool Retrieve(std::ifstream& fIn, G4bool a << 199     G4bool Store(std::ofstream& fOut, G4bool ascii=false) const;
176                                                << 200     virtual G4bool Retrieve(std::ifstream& fIn, G4bool ascii=false);
177   // Print vector                              << 201          // To store/retrieve persistent data to/from file streams.
178   friend std::ostream& operator<<(std::ostream << 202 
179   void DumpValues(G4double unitE = 1.0, G4doub << 203     friend std::ostream& operator<<(std::ostream&, const G4PhysicsVector&);
180                                                << 204     void DumpValues(G4double unitE=1.0, G4double unitV=1.0) const;
181 protected:                                     << 205          // print vector
182                                                << 206 
183   // The default implements a free vector init << 207     inline void SetVerboseLevel(G4int value);
184   virtual void Initialise();                   << 208 
185                                                << 209     inline G4double Interpolation(size_t idx, G4double energy) const;
186   void PrintPutValueError(std::size_t index, G << 210 
187                           const G4String& text << 211   protected:
188                                                << 212 
189 private:                                       << 213     void DeleteData();
190                                                << 214     void CopyData(const G4PhysicsVector& vec);
191   void ComputeSecDerivative0();                << 215          // Internal methods for allowing copy of objects
192   void ComputeSecDerivative1();                << 216 
193   void ComputeSecDerivative2(const G4double fi << 217     void PrintPutValueError(size_t index);
194                              const G4double en << 218 
195   // Internal methods for computing of spline  << 219   protected:
196                                                << 220 
197   // Linear or spline interpolation.           << 221     G4PhysicsVectorType type;   // The type of PhysicsVector (enumerator)
198   inline G4double Interpolation(const std::siz << 222 
199                                 const G4double << 223     G4double edgeMin;           // Energy of first point
200                                                << 224     G4double edgeMax;           // Energy of the last point
201   // Assuming (edgeMin <= energy <= edgeMax).  << 225 
202   inline std::size_t LogBin(const G4double ene << 226     size_t numberOfNodes;
203   inline std::size_t BinaryBin(const G4double  << 227 
204   inline std::size_t GetBin(const G4double ene << 228     G4PVDataVector  dataVector;    // Vector to keep the crossection/energyloss
205                                                << 229     G4PVDataVector  binVector;     // Vector to keep energy
206 protected:                                     << 230     G4PVDataVector  secDerivative; // Vector to keep second derivatives 
207                                                << 231 
208   G4double edgeMin = 0.0;  // Energy of first  << 232   private:
209   G4double edgeMax = 0.0;  // Energy of the la << 233 
210                                                << 234     G4bool SplinePossible();
211   G4double invdBin = 0.0;  // 1/Bin width for  << 235 
212   G4double logemin = 0.0;  // used only for lo << 236     inline G4double LinearInterpolation(size_t idx, G4double energy) const;
213                                                << 237          // Linear interpolation function
214   G4double iBin1 = 0.0;  // 1/Bin width for sc << 238     inline G4double SplineInterpolation(size_t idx, G4double energy) const;
215   G4double lmin1 = 0.0;  // used for log searc << 239          // Spline interpolation function
216                                                << 240 
217   G4int verboseLevel = 0;                      << 241     inline size_t FindBinLocation(G4double theEnergy) const;
218   std::size_t idxmax = 0;                      << 242          // find low edge index of a bin for given energy
219   std::size_t imax1 = 0;                       << 243          // min value 0, max value VectorLength-1
220   std::size_t numberOfNodes = 0;               << 244 
221   std::size_t nLogNodes = 0;                   << 245     G4bool     useSpline;
222                                                << 246 
223   G4PhysicsVectorType type = T_G4PhysicsFreeVe << 247   protected:
224   // The type of PhysicsVector (enumerator)    << 
225                                                << 
226   std::vector<G4double> binVector;      // ene << 
227   std::vector<G4double> dataVector;     // cro << 
228   std::vector<G4double> secDerivative;  // sec << 
229   std::vector<std::size_t> scale;       // log << 
230                                                   248 
231 private:                                       << 249     G4double invdBin;       // 1/Bin width - useful only for fixed binning
                                                   >> 250     G4double baseBin;       // Set this in constructor for performance
232                                                   251 
233   G4bool useSpline = false;                    << 252     G4int verboseLevel;
234 };                                                253 };
235                                                   254 
236 #include "G4PhysicsVector.icc"                    255 #include "G4PhysicsVector.icc"
237                                                   256 
238 #endif                                            257 #endif
239                                                   258