[833] | 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 | // |
---|
[850] | 27 | // $Id: G4PhysicsVector.icc,v 1.14 2008/09/05 18:04:45 vnivanch Exp $ |
---|
| 28 | // GEANT4 tag $Name: HEAD $ |
---|
[833] | 29 | // |
---|
| 30 | // |
---|
| 31 | //--------------------------------------------------------------- |
---|
| 32 | // GEANT 4 class source file |
---|
| 33 | // |
---|
| 34 | // G4PhysicsVector.icc |
---|
| 35 | // |
---|
| 36 | // Description: |
---|
| 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 | // |
---|
[850] | 43 | // Modified: |
---|
| 44 | // 05 Sep. 2008, V.Ivanchenko : added protections for zero-length vector |
---|
[833] | 45 | //--------------------------------------------------------------- |
---|
| 46 | |
---|
| 47 | inline |
---|
| 48 | G4double G4PhysicsVector::operator[](const size_t binNumber) const |
---|
| 49 | { |
---|
| 50 | return dataVector[binNumber]; |
---|
| 51 | } |
---|
| 52 | |
---|
[850] | 53 | //--------------------------------------------------------------- |
---|
[833] | 54 | |
---|
| 55 | inline |
---|
| 56 | G4double G4PhysicsVector::operator()(const size_t binNumber) const |
---|
| 57 | { |
---|
| 58 | return dataVector[binNumber]; |
---|
| 59 | } |
---|
| 60 | |
---|
[850] | 61 | //--------------------------------------------------------------- |
---|
[833] | 62 | |
---|
| 63 | inline |
---|
| 64 | size_t G4PhysicsVector::GetVectorLength() const |
---|
| 65 | { |
---|
| 66 | return numberOfBin; |
---|
| 67 | } |
---|
| 68 | |
---|
[850] | 69 | //--------------------------------------------------------------- |
---|
[833] | 70 | |
---|
| 71 | inline |
---|
[850] | 72 | G4double G4PhysicsVector::LinearInterpolation() |
---|
[833] | 73 | { |
---|
| 74 | // Linear interpolation is used to get the value. If the give energy |
---|
| 75 | // is in the highest bin, no interpolation will be Done. Because |
---|
| 76 | // there is an extra bin hidden from a user at locBin=numberOfBin, |
---|
| 77 | // the following interpolation is valid even the current locBin= |
---|
| 78 | // numberOfBin-1. |
---|
| 79 | |
---|
[850] | 80 | G4double intplFactor = (lastEnergy-binVector[lastBin]) |
---|
| 81 | / (binVector[lastBin+1]-binVector[lastBin]); // Interpolation factor |
---|
[833] | 82 | |
---|
[850] | 83 | return dataVector[lastBin] + |
---|
| 84 | ( dataVector[lastBin+1]-dataVector[lastBin] ) * intplFactor; |
---|
[833] | 85 | } |
---|
| 86 | |
---|
[850] | 87 | //--------------------------------------------------------------- |
---|
[833] | 88 | |
---|
| 89 | inline |
---|
[850] | 90 | G4double G4PhysicsVector::SplineInterpolation() |
---|
[833] | 91 | { |
---|
[850] | 92 | // Spline interpolation is used to get the value. If the give energy |
---|
| 93 | // is in the highest bin, no interpolation will be Done. Because |
---|
| 94 | // there is an extra bin hidden from a user at locBin=numberOfBin, |
---|
| 95 | // the following interpolation is valid even the current locBin= |
---|
| 96 | // numberOfBin-1. |
---|
[833] | 97 | |
---|
[850] | 98 | if( !secDerivative ) { FillSecondDerivatives(); } |
---|
| 99 | |
---|
| 100 | // check bin value |
---|
| 101 | G4double delta = binVector[lastBin+1] - binVector[lastBin]; |
---|
| 102 | |
---|
| 103 | G4double a = (binVector[lastBin+1] - lastEnergy)/delta; |
---|
| 104 | G4double b = (lastEnergy - binVector[lastBin])/delta; |
---|
| 105 | |
---|
| 106 | // Final evaluation of cubic spline polynomial for return |
---|
| 107 | G4double y1 = dataVector[lastBin]; |
---|
| 108 | G4double y2 = dataVector[lastBin+1]; |
---|
| 109 | |
---|
| 110 | G4double res = a*y1 + b*y2 + |
---|
| 111 | ((a*a*a - a)*secDerivative[lastBin] + |
---|
| 112 | (b*b*b - b)*secDerivative[lastBin+1])*delta*delta/6.0 ; |
---|
| 113 | |
---|
| 114 | return res; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | //--------------------------------------------------------------- |
---|
| 118 | |
---|
| 119 | inline |
---|
| 120 | G4double G4PhysicsVector::GetValue(G4double theEnergy, G4bool&) |
---|
| 121 | { |
---|
[833] | 122 | // Use cache for speed up - check if the value 'theEnergy' is same as the |
---|
| 123 | // last call. If it is same, then use the last bin location. Also the |
---|
| 124 | // value 'theEnergy' lies between the last energy and low edge of of the |
---|
| 125 | // bin of last call, then the last bin location is used. |
---|
| 126 | |
---|
[850] | 127 | if( theEnergy == lastEnergy ) { |
---|
[833] | 128 | |
---|
[850] | 129 | } else if( theEnergy <= edgeMin ) { |
---|
| 130 | lastBin = 0; |
---|
| 131 | lastEnergy = theEnergy; |
---|
| 132 | lastValue = dataVector[0]; |
---|
[833] | 133 | |
---|
[850] | 134 | } else if(theEnergy < lastEnergy && theEnergy >= binVector[lastBin]) { |
---|
[833] | 135 | lastEnergy = theEnergy; |
---|
[850] | 136 | Interpolation(); |
---|
[833] | 137 | |
---|
[850] | 138 | } else if(theEnergy < lastEnergy && theEnergy >= binVector[lastBin-1]) { |
---|
| 139 | lastBin--; |
---|
[833] | 140 | lastEnergy = theEnergy; |
---|
[850] | 141 | Interpolation(); |
---|
[833] | 142 | |
---|
| 143 | } else if( theEnergy >= edgeMax ){ |
---|
| 144 | lastBin = numberOfBin-1; |
---|
[850] | 145 | lastEnergy = edgeMax; |
---|
| 146 | lastValue = dataVector[lastBin]; |
---|
[833] | 147 | |
---|
[850] | 148 | } else { |
---|
| 149 | lastBin = FindBinLocation(theEnergy); |
---|
[833] | 150 | lastEnergy = theEnergy; |
---|
[850] | 151 | Interpolation(); |
---|
[833] | 152 | } |
---|
[850] | 153 | return lastValue; |
---|
| 154 | } |
---|
[833] | 155 | |
---|
[850] | 156 | //--------------------------------------------------------------- |
---|
| 157 | |
---|
| 158 | inline |
---|
| 159 | void G4PhysicsVector::Interpolation() |
---|
| 160 | { |
---|
| 161 | if(useSpline) { lastValue = SplineInterpolation(); } |
---|
| 162 | else { lastValue = LinearInterpolation(); } |
---|
[833] | 163 | } |
---|
| 164 | |
---|
[850] | 165 | //--------------------------------------------------------------- |
---|
| 166 | |
---|
[833] | 167 | inline |
---|
| 168 | void G4PhysicsVector::PutValue(size_t binNumber, G4double theValue) |
---|
| 169 | { |
---|
[850] | 170 | if(binNumber < numberOfBin) { |
---|
| 171 | dataVector[binNumber] = theValue; |
---|
[833] | 172 | |
---|
[850] | 173 | // Fill the bin which is hidden to user with theValue. This is to |
---|
| 174 | // handle correctly when Energy=theEmax in getValue. |
---|
| 175 | |
---|
| 176 | if(binNumber==numberOfBin-1) { dataVector[binNumber+1] = theValue; } |
---|
| 177 | } |
---|
[833] | 178 | } |
---|
| 179 | |
---|
[850] | 180 | //--------------------------------------------------------------- |
---|
| 181 | |
---|
[833] | 182 | inline |
---|
| 183 | G4bool G4PhysicsVector::IsFilledVectorExist() const |
---|
| 184 | { |
---|
| 185 | G4bool status=false; |
---|
| 186 | |
---|
| 187 | if(numberOfBin > 0) { status=true; } |
---|
| 188 | return status; |
---|
| 189 | } |
---|
| 190 | |
---|
[850] | 191 | //--------------------------------------------------------------- |
---|
[833] | 192 | |
---|
| 193 | inline |
---|
| 194 | void G4PhysicsVector::PutComment(const G4String& theComment) |
---|
| 195 | { |
---|
| 196 | comment = theComment; |
---|
| 197 | } |
---|
| 198 | |
---|
[850] | 199 | //--------------------------------------------------------------- |
---|
| 200 | |
---|
[833] | 201 | inline |
---|
| 202 | const G4String& G4PhysicsVector::GetComment() const |
---|
| 203 | { |
---|
| 204 | return comment; |
---|
| 205 | } |
---|
| 206 | |
---|
[850] | 207 | //--------------------------------------------------------------- |
---|
| 208 | |
---|
[833] | 209 | inline |
---|
| 210 | G4PhysicsVectorType G4PhysicsVector::GetType() const |
---|
| 211 | { |
---|
| 212 | return type; |
---|
| 213 | } |
---|
[850] | 214 | |
---|
| 215 | //--------------------------------------------------------------- |
---|
| 216 | |
---|
| 217 | inline |
---|
| 218 | void G4PhysicsVector::SetSpline(G4bool val) |
---|
| 219 | { |
---|
| 220 | useSpline = val; |
---|
| 221 | } |
---|