| 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 | //
|
|---|
| 27 | // $Id: G4PhysicsVector.icc,v 1.28 2010/05/28 05:13:43 kurasige Exp $
|
|---|
| 28 | // GEANT4 tag $Name: geant4-09-04-beta-01 $
|
|---|
| 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::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
|
|---|
| 64 | G4double G4PhysicsVector::operator[](const size_t binNumber) const
|
|---|
| 65 | {
|
|---|
| 66 | return dataVector[binNumber];
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | //---------------------------------------------------------------
|
|---|
| 70 |
|
|---|
| 71 | inline
|
|---|
| 72 | G4double G4PhysicsVector::operator()(const size_t binNumber) const
|
|---|
| 73 | {
|
|---|
| 74 | return dataVector[binNumber];
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | //---------------------------------------------------------------
|
|---|
| 78 |
|
|---|
| 79 | inline
|
|---|
| 80 | G4double G4PhysicsVector::Energy(const size_t binNumber) const
|
|---|
| 81 | {
|
|---|
| 82 | return binVector[binNumber];
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | //---------------------------------------------------------------
|
|---|
| 86 |
|
|---|
| 87 | inline
|
|---|
| 88 | size_t G4PhysicsVector::GetVectorLength() const
|
|---|
| 89 | {
|
|---|
| 90 | return numberOfNodes;
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | //---------------------------------------------------------------
|
|---|
| 94 |
|
|---|
| 95 | inline
|
|---|
| 96 | G4double G4PhysicsVector::GetValue(G4double theEnergy, G4bool&)
|
|---|
| 97 | {
|
|---|
| 98 | return Value(theEnergy);
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | //------------------------------------------------
|
|---|
| 102 |
|
|---|
| 103 | inline
|
|---|
| 104 | G4double G4PhysicsVector::LinearInterpolation(G4int lastBin)
|
|---|
| 105 | {
|
|---|
| 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 |
|
|---|
| 112 | G4double intplFactor = (cache->lastEnergy-binVector[lastBin])
|
|---|
| 113 | / (binVector[lastBin + 1]-binVector[lastBin]); // Interpol. factor
|
|---|
| 114 |
|
|---|
| 115 | return dataVector[lastBin] +
|
|---|
| 116 | ( dataVector[lastBin + 1]-dataVector[lastBin] ) * intplFactor;
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | //---------------------------------------------------------------
|
|---|
| 120 |
|
|---|
| 121 | inline
|
|---|
| 122 | G4double G4PhysicsVector::SplineInterpolation(G4int lastBin)
|
|---|
| 123 | {
|
|---|
| 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.
|
|---|
| 129 |
|
|---|
| 130 | if(0 == secDerivative.size() ) { FillSecondDerivatives(); }
|
|---|
| 131 |
|
|---|
| 132 | // check bin value
|
|---|
| 133 | G4double x1 = binVector[lastBin];
|
|---|
| 134 | G4double x2 = binVector[lastBin + 1];
|
|---|
| 135 | G4double delta = x2 - x1;
|
|---|
| 136 |
|
|---|
| 137 | G4double a = (x2 - cache->lastEnergy)/delta;
|
|---|
| 138 | G4double b = (cache->lastEnergy - x1)/delta;
|
|---|
| 139 |
|
|---|
| 140 | // Final evaluation of cubic spline polynomial for return
|
|---|
| 141 | G4double y1 = dataVector[lastBin];
|
|---|
| 142 | G4double y2 = dataVector[lastBin + 1];
|
|---|
| 143 |
|
|---|
| 144 | G4double res = a*y1 + b*y2 +
|
|---|
| 145 | ( (a*a*a - a)*secDerivative[lastBin] +
|
|---|
| 146 | (b*b*b - b)*secDerivative[lastBin + 1] )*delta*delta/6.0;
|
|---|
| 147 |
|
|---|
| 148 | return res;
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | //---------------------------------------------------------------
|
|---|
| 152 |
|
|---|
| 153 | inline
|
|---|
| 154 | void G4PhysicsVector::Interpolation(G4int lastBin)
|
|---|
| 155 | {
|
|---|
| 156 | if(useSpline) { cache->lastValue = SplineInterpolation(lastBin); }
|
|---|
| 157 | else { cache->lastValue = LinearInterpolation(lastBin); }
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | //---------------------------------------------------------------
|
|---|
| 161 |
|
|---|
| 162 | inline
|
|---|
| 163 | void G4PhysicsVector::PutValue(size_t binNumber, G4double theValue)
|
|---|
| 164 | {
|
|---|
| 165 | dataVector[binNumber] = theValue;
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 | //---------------------------------------------------------------
|
|---|
| 169 |
|
|---|
| 170 | inline
|
|---|
| 171 | G4bool G4PhysicsVector::IsFilledVectorExist() const
|
|---|
| 172 | {
|
|---|
| 173 | G4bool status=false;
|
|---|
| 174 |
|
|---|
| 175 | if(numberOfNodes > 0) { status=true; }
|
|---|
| 176 | return status;
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | //---------------------------------------------------------------
|
|---|
| 180 |
|
|---|
| 181 | inline
|
|---|
| 182 | void G4PhysicsVector::PutComment(const G4String& theComment)
|
|---|
| 183 | {
|
|---|
| 184 | comment = theComment;
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | //---------------------------------------------------------------
|
|---|
| 188 |
|
|---|
| 189 | inline
|
|---|
| 190 | const G4String& G4PhysicsVector::GetComment() const
|
|---|
| 191 | {
|
|---|
| 192 | return comment;
|
|---|
| 193 | }
|
|---|
| 194 |
|
|---|
| 195 | //---------------------------------------------------------------
|
|---|
| 196 |
|
|---|
| 197 | inline
|
|---|
| 198 | G4PhysicsVectorType G4PhysicsVector::GetType() const
|
|---|
| 199 | {
|
|---|
| 200 | return type;
|
|---|
| 201 | }
|
|---|
| 202 |
|
|---|
| 203 | //---------------------------------------------------------------
|
|---|
| 204 |
|
|---|
| 205 | inline
|
|---|
| 206 | void G4PhysicsVector::SetSpline(G4bool val)
|
|---|
| 207 | {
|
|---|
| 208 | useSpline = val;
|
|---|
| 209 | }
|
|---|