| 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.9 2006/06/29 19:02:40 gunter Exp $
|
|---|
| 28 | // GEANT4 tag $Name: geant4-09-01-patch-02 $
|
|---|
| 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 |
|
|---|
| 46 | inline
|
|---|
| 47 | G4double G4PhysicsVector::operator[](const size_t binNumber) const
|
|---|
| 48 | {
|
|---|
| 49 | return dataVector[binNumber];
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 | inline
|
|---|
| 54 | G4double G4PhysicsVector::operator()(const size_t binNumber) const
|
|---|
| 55 | {
|
|---|
| 56 | return dataVector[binNumber];
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 | inline
|
|---|
| 61 | size_t G4PhysicsVector::GetVectorLength() const
|
|---|
| 62 | {
|
|---|
| 63 | return numberOfBin;
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 | inline
|
|---|
| 69 | G4double G4PhysicsVector::LinearInterpolation(G4double theEnergy,
|
|---|
| 70 | size_t theLocBin)
|
|---|
| 71 | {
|
|---|
| 72 |
|
|---|
| 73 | // Linear interpolation is used to get the value. If the give energy
|
|---|
| 74 | // is in the highest bin, no interpolation will be Done. Because
|
|---|
| 75 | // there is an extra bin hidden from a user at locBin=numberOfBin,
|
|---|
| 76 | // the following interpolation is valid even the current locBin=
|
|---|
| 77 | // numberOfBin-1.
|
|---|
| 78 |
|
|---|
| 79 | G4double intplFactor = (theEnergy-binVector[theLocBin])
|
|---|
| 80 | / (binVector[theLocBin+1]-binVector[theLocBin]); // Interpolation factor
|
|---|
| 81 |
|
|---|
| 82 | return dataVector[theLocBin] +
|
|---|
| 83 | ( dataVector[theLocBin+1]-dataVector[theLocBin] ) * intplFactor;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 | inline
|
|---|
| 88 | G4double G4PhysicsVector::GetValue(G4double theEnergy,
|
|---|
| 89 | G4bool& isOutRange)
|
|---|
| 90 | {
|
|---|
| 91 |
|
|---|
| 92 | // Use cache for speed up - check if the value 'theEnergy' is same as the
|
|---|
| 93 | // last call. If it is same, then use the last bin location. Also the
|
|---|
| 94 | // value 'theEnergy' lies between the last energy and low edge of of the
|
|---|
| 95 | // bin of last call, then the last bin location is used.
|
|---|
| 96 |
|
|---|
| 97 | isOutRange = false; // No range check.
|
|---|
| 98 |
|
|---|
| 99 | size_t locBin = 0;
|
|---|
| 100 |
|
|---|
| 101 | if( !(theEnergy != lastEnergy) ) {
|
|---|
| 102 | return lastValue;
|
|---|
| 103 |
|
|---|
| 104 | } else if( (theEnergy < lastEnergy)
|
|---|
| 105 | && (theEnergy >= binVector[lastBin]) ) {
|
|---|
| 106 | locBin = lastBin;
|
|---|
| 107 |
|
|---|
| 108 | lastEnergy = theEnergy;
|
|---|
| 109 | lastValue = LinearInterpolation(theEnergy, locBin);
|
|---|
| 110 | return lastValue;
|
|---|
| 111 |
|
|---|
| 112 | } else if( theEnergy < edgeMin ){
|
|---|
| 113 | lastBin = 0;
|
|---|
| 114 | lastEnergy = theEnergy;
|
|---|
| 115 | lastValue = dataVector[0];
|
|---|
| 116 | return lastValue;
|
|---|
| 117 |
|
|---|
| 118 | } else if( theEnergy >= edgeMax ){
|
|---|
| 119 | lastBin = numberOfBin-1;
|
|---|
| 120 | lastEnergy = theEnergy;
|
|---|
| 121 | lastValue = dataVector[ numberOfBin-1 ];
|
|---|
| 122 | return lastValue;
|
|---|
| 123 |
|
|---|
| 124 | } else {
|
|---|
| 125 | locBin = FindBinLocation(theEnergy);
|
|---|
| 126 |
|
|---|
| 127 | lastBin = locBin;
|
|---|
| 128 | lastEnergy = theEnergy;
|
|---|
| 129 | lastValue = LinearInterpolation(theEnergy, locBin);
|
|---|
| 130 | return lastValue;
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | inline
|
|---|
| 136 | void G4PhysicsVector::PutValue(size_t binNumber, G4double theValue)
|
|---|
| 137 | {
|
|---|
| 138 | dataVector[binNumber] = theValue;
|
|---|
| 139 |
|
|---|
| 140 | // Fill the bin which is hidden to user with theValue. This is to
|
|---|
| 141 | // handle correctly when Energy=theEmax in getValue.
|
|---|
| 142 | if(binNumber==numberOfBin-1) {
|
|---|
| 143 | dataVector[binNumber+1] = theValue;
|
|---|
| 144 | }
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 | inline
|
|---|
| 148 | G4bool G4PhysicsVector::IsFilledVectorExist() const
|
|---|
| 149 | {
|
|---|
| 150 | G4bool status=false;
|
|---|
| 151 |
|
|---|
| 152 | if(numberOfBin > 0) { status=true; }
|
|---|
| 153 | return status;
|
|---|
| 154 | }
|
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 | inline
|
|---|
| 158 | void G4PhysicsVector::PutComment(const G4String& theComment)
|
|---|
| 159 | {
|
|---|
| 160 | comment = theComment;
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 | inline
|
|---|
| 164 | const G4String& G4PhysicsVector::GetComment() const
|
|---|
| 165 | {
|
|---|
| 166 | return comment;
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | inline
|
|---|
| 170 | G4PhysicsVectorType G4PhysicsVector::GetType() const
|
|---|
| 171 | {
|
|---|
| 172 | return type;
|
|---|
| 173 | }
|
|---|