171 lines
5.0 KiB
Plaintext
171 lines
5.0 KiB
Plaintext
//
|
|
// ********************************************************************
|
|
// * DISCLAIMER *
|
|
// * *
|
|
// * The following disclaimer summarizes all the specific disclaimers *
|
|
// * of contributors to this software. The specific disclaimers,which *
|
|
// * govern, are listed with their locations in: *
|
|
// * http://cern.ch/geant4/license *
|
|
// * *
|
|
// * Neither the authors of this software system, nor their employing *
|
|
// * institutes,nor the agencies providing financial support for this *
|
|
// * work make any representation or warranty, express or implied, *
|
|
// * regarding this software system or assume any liability for its *
|
|
// * use. *
|
|
// * *
|
|
// * This code implementation is the intellectual property of the *
|
|
// * GEANT4 collaboration. *
|
|
// * By copying, distributing or modifying the Program (or any work *
|
|
// * based on the Program) you indicate your acceptance of this *
|
|
// * statement, and all its terms. *
|
|
// ********************************************************************
|
|
//
|
|
//
|
|
// $Id: G4PhysicsVector.icc,v 1.7 2001/07/11 10:00:51 gunter Exp $
|
|
// GEANT4 tag $Name: geant4-05-02-patch-01 $
|
|
//
|
|
//
|
|
//---------------------------------------------------------------
|
|
// GEANT 4 class source file
|
|
//
|
|
// G4PhysicsVector.icc
|
|
//
|
|
// Description:
|
|
// A physics vector which has values of energy-loss, cross-section,
|
|
// and other physics values of a particle in matter in a given
|
|
// range of the energy, momentum, etc.
|
|
// This class serves as the base class for a vector having various
|
|
// energy scale, for example like 'log', 'linear', 'free', etc.
|
|
//
|
|
//---------------------------------------------------------------
|
|
|
|
|
|
inline
|
|
G4double G4PhysicsVector::operator[](const size_t binNumber) const
|
|
{
|
|
return dataVector[binNumber];
|
|
}
|
|
|
|
|
|
inline
|
|
G4double G4PhysicsVector::operator()(const size_t binNumber) const
|
|
{
|
|
return dataVector[binNumber];
|
|
}
|
|
|
|
|
|
inline
|
|
size_t G4PhysicsVector::GetVectorLength() const
|
|
{
|
|
return numberOfBin;
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
G4double G4PhysicsVector::LinearInterpolation(G4double theEnergy,
|
|
size_t theLocBin)
|
|
{
|
|
|
|
// Linear interpolation is used to get the value. If the give energy
|
|
// is in the highest bin, no interpolation will be Done. Because
|
|
// there is an extra bin hidden from a user at locBin=numberOfBin,
|
|
// the following interpolation is valid even the current locBin=
|
|
// numberOfBin-1.
|
|
|
|
G4double intplFactor = (theEnergy-binVector[theLocBin])
|
|
/ (binVector[theLocBin+1]-binVector[theLocBin]); // Interpolation factor
|
|
|
|
return dataVector[theLocBin] +
|
|
( dataVector[theLocBin+1]-dataVector[theLocBin] ) * intplFactor;
|
|
}
|
|
|
|
|
|
inline
|
|
G4double G4PhysicsVector::GetValue(G4double theEnergy,
|
|
G4bool& isOutRange)
|
|
{
|
|
|
|
// Use cache for speed up - check if the value 'theEnergy' is same as the
|
|
// last call. If it is same, then use the last bin location. Also the
|
|
// value 'theEnergy' lies between the last energy and low edge of of the
|
|
// bin of last call, then the last bin location is used.
|
|
|
|
isOutRange = false; // No range check.
|
|
|
|
size_t locBin;
|
|
|
|
if( theEnergy == lastEnergy ) {
|
|
return lastValue;
|
|
|
|
} else if( (theEnergy < lastEnergy) &&
|
|
(theEnergy >= binVector[lastBin]) ) {
|
|
locBin = lastBin;
|
|
|
|
lastEnergy = theEnergy;
|
|
lastValue = LinearInterpolation(theEnergy, locBin);
|
|
return lastValue;
|
|
|
|
} else if( theEnergy < edgeMin ){
|
|
lastBin = 0;
|
|
lastEnergy = theEnergy;
|
|
lastValue = dataVector[0];
|
|
return lastValue;
|
|
|
|
} else if( theEnergy >= edgeMax ){
|
|
lastBin = numberOfBin-1;
|
|
lastEnergy = theEnergy;
|
|
lastValue = dataVector[ numberOfBin-1 ];
|
|
return lastValue;
|
|
|
|
} else {
|
|
locBin = FindBinLocation(theEnergy);
|
|
|
|
lastBin = locBin;
|
|
lastEnergy = theEnergy;
|
|
lastValue = LinearInterpolation(theEnergy, locBin);
|
|
return lastValue;
|
|
}
|
|
|
|
}
|
|
|
|
inline
|
|
void G4PhysicsVector::PutValue(size_t binNumber, G4double theValue)
|
|
{
|
|
dataVector[binNumber] = theValue;
|
|
|
|
// Fill the bin which is hidden to user with theValue. This is to
|
|
// handle correctly when Energy=theEmax in getValue.
|
|
if(binNumber==numberOfBin-1) {
|
|
dataVector[binNumber+1] = theValue;
|
|
}
|
|
}
|
|
|
|
inline
|
|
G4bool G4PhysicsVector::IsFilledVectorExist() const
|
|
{
|
|
G4bool status=false;
|
|
|
|
if(numberOfBin > 0) status=true;
|
|
return status;
|
|
}
|
|
|
|
|
|
inline
|
|
void G4PhysicsVector::PutComment(const G4String& theComment)
|
|
{
|
|
comment = theComment;
|
|
}
|
|
|
|
inline
|
|
const G4String& G4PhysicsVector::GetComment() const
|
|
{
|
|
return comment;
|
|
}
|
|
|
|
inline
|
|
G4PhysicsVectorType G4PhysicsVector::GetType() const
|
|
{
|
|
return type;
|
|
}
|