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