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