[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 | // |
---|
[1340] | 27 | // $Id: G4PhysicsVector.icc,v 1.30 2010/09/20 16:22:56 gcosmo Exp $ |
---|
| 28 | // GEANT4 tag $Name: global-V09-03-22 $ |
---|
[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 | // |
---|
| 43 | //--------------------------------------------------------------- |
---|
| 44 | |
---|
| 45 | inline |
---|
[1315] | 46 | G4double G4PhysicsVector::GetLastEnergy() const |
---|
| 47 | { |
---|
| 48 | return cache->lastEnergy; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | inline |
---|
| 52 | G4double G4PhysicsVector::GetLastValue() const |
---|
| 53 | { |
---|
| 54 | return cache->lastValue; |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | inline |
---|
| 58 | size_t G4PhysicsVector::GetLastBin() const |
---|
| 59 | { |
---|
| 60 | return cache->lastBin; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | inline |
---|
[833] | 64 | G4double G4PhysicsVector::operator[](const size_t binNumber) const |
---|
| 65 | { |
---|
[1315] | 66 | return dataVector[binNumber]; |
---|
[833] | 67 | } |
---|
| 68 | |
---|
[850] | 69 | //--------------------------------------------------------------- |
---|
[833] | 70 | |
---|
| 71 | inline |
---|
| 72 | G4double G4PhysicsVector::operator()(const size_t binNumber) const |
---|
| 73 | { |
---|
| 74 | return dataVector[binNumber]; |
---|
| 75 | } |
---|
| 76 | |
---|
[850] | 77 | //--------------------------------------------------------------- |
---|
[833] | 78 | |
---|
[1193] | 79 | inline |
---|
| 80 | G4double G4PhysicsVector::Energy(const size_t binNumber) const |
---|
| 81 | { |
---|
| 82 | return binVector[binNumber]; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | //--------------------------------------------------------------- |
---|
| 86 | |
---|
[833] | 87 | inline |
---|
| 88 | size_t G4PhysicsVector::GetVectorLength() const |
---|
| 89 | { |
---|
[1193] | 90 | return numberOfNodes; |
---|
[833] | 91 | } |
---|
| 92 | |
---|
[850] | 93 | //--------------------------------------------------------------- |
---|
[833] | 94 | |
---|
| 95 | inline |
---|
[1315] | 96 | G4double G4PhysicsVector::GetValue(G4double theEnergy, G4bool&) |
---|
[833] | 97 | { |
---|
[1315] | 98 | return Value(theEnergy); |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | //------------------------------------------------ |
---|
| 102 | |
---|
| 103 | inline |
---|
| 104 | G4double G4PhysicsVector::LinearInterpolation(G4int lastBin) |
---|
| 105 | { |
---|
[833] | 106 | // Linear interpolation is used to get the value. If the give energy |
---|
| 107 | // is in the highest bin, no interpolation will be Done. Because |
---|
| 108 | // there is an extra bin hidden from a user at locBin=numberOfBin, |
---|
| 109 | // the following interpolation is valid even the current locBin= |
---|
| 110 | // numberOfBin-1. |
---|
| 111 | |
---|
[1315] | 112 | G4double intplFactor = (cache->lastEnergy-binVector[lastBin]) |
---|
| 113 | / (binVector[lastBin + 1]-binVector[lastBin]); // Interpol. factor |
---|
[833] | 114 | |
---|
[850] | 115 | return dataVector[lastBin] + |
---|
[1315] | 116 | ( dataVector[lastBin + 1]-dataVector[lastBin] ) * intplFactor; |
---|
[833] | 117 | } |
---|
| 118 | |
---|
[850] | 119 | //--------------------------------------------------------------- |
---|
[833] | 120 | |
---|
| 121 | inline |
---|
[1315] | 122 | G4double G4PhysicsVector::SplineInterpolation(G4int lastBin) |
---|
[833] | 123 | { |
---|
[850] | 124 | // Spline interpolation is used to get the value. If the give energy |
---|
| 125 | // is in the highest bin, no interpolation will be Done. Because |
---|
| 126 | // there is an extra bin hidden from a user at locBin=numberOfBin, |
---|
| 127 | // the following interpolation is valid even the current locBin= |
---|
| 128 | // numberOfBin-1. |
---|
[833] | 129 | |
---|
[1193] | 130 | if(0 == secDerivative.size() ) { FillSecondDerivatives(); } |
---|
[850] | 131 | |
---|
| 132 | // check bin value |
---|
[1193] | 133 | G4double x1 = binVector[lastBin]; |
---|
[1315] | 134 | G4double x2 = binVector[lastBin + 1]; |
---|
[1193] | 135 | G4double delta = x2 - x1; |
---|
[850] | 136 | |
---|
[1315] | 137 | G4double a = (x2 - cache->lastEnergy)/delta; |
---|
| 138 | G4double b = (cache->lastEnergy - x1)/delta; |
---|
[850] | 139 | |
---|
| 140 | // Final evaluation of cubic spline polynomial for return |
---|
| 141 | G4double y1 = dataVector[lastBin]; |
---|
[1315] | 142 | G4double y2 = dataVector[lastBin + 1]; |
---|
[850] | 143 | |
---|
| 144 | G4double res = a*y1 + b*y2 + |
---|
[1193] | 145 | ( (a*a*a - a)*secDerivative[lastBin] + |
---|
[1315] | 146 | (b*b*b - b)*secDerivative[lastBin + 1] )*delta*delta/6.0; |
---|
[850] | 147 | |
---|
| 148 | return res; |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | //--------------------------------------------------------------- |
---|
| 152 | |
---|
| 153 | inline |
---|
[1315] | 154 | void G4PhysicsVector::Interpolation(G4int lastBin) |
---|
[850] | 155 | { |
---|
[1315] | 156 | if(useSpline) { cache->lastValue = SplineInterpolation(lastBin); } |
---|
| 157 | else { cache->lastValue = LinearInterpolation(lastBin); } |
---|
[833] | 158 | } |
---|
| 159 | |
---|
[850] | 160 | //--------------------------------------------------------------- |
---|
| 161 | |
---|
[833] | 162 | inline |
---|
| 163 | void G4PhysicsVector::PutValue(size_t binNumber, G4double theValue) |
---|
| 164 | { |
---|
[921] | 165 | dataVector[binNumber] = theValue; |
---|
[833] | 166 | } |
---|
| 167 | |
---|
[850] | 168 | //--------------------------------------------------------------- |
---|
| 169 | |
---|
[833] | 170 | inline |
---|
| 171 | G4bool G4PhysicsVector::IsFilledVectorExist() const |
---|
| 172 | { |
---|
| 173 | G4bool status=false; |
---|
| 174 | |
---|
[1193] | 175 | if(numberOfNodes > 0) { status=true; } |
---|
[833] | 176 | return status; |
---|
| 177 | } |
---|
| 178 | |
---|
[850] | 179 | //--------------------------------------------------------------- |
---|
[833] | 180 | |
---|
| 181 | inline |
---|
| 182 | void G4PhysicsVector::PutComment(const G4String& theComment) |
---|
| 183 | { |
---|
| 184 | comment = theComment; |
---|
| 185 | } |
---|
| 186 | |
---|
[850] | 187 | //--------------------------------------------------------------- |
---|
| 188 | |
---|
[833] | 189 | inline |
---|
| 190 | const G4String& G4PhysicsVector::GetComment() const |
---|
| 191 | { |
---|
| 192 | return comment; |
---|
| 193 | } |
---|
| 194 | |
---|
[850] | 195 | //--------------------------------------------------------------- |
---|
| 196 | |
---|
[833] | 197 | inline |
---|
| 198 | G4PhysicsVectorType G4PhysicsVector::GetType() const |
---|
| 199 | { |
---|
| 200 | return type; |
---|
| 201 | } |
---|
[850] | 202 | |
---|
| 203 | //--------------------------------------------------------------- |
---|
| 204 | |
---|
| 205 | inline |
---|
| 206 | void G4PhysicsVector::SetSpline(G4bool val) |
---|
| 207 | { |
---|
| 208 | useSpline = val; |
---|
| 209 | } |
---|