Import Geant4 10.7.0 source tree
This commit is contained in:
@@ -23,20 +23,10 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4VelocityTable class implementation
|
||||
//
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------------------
|
||||
//
|
||||
// G4VelocityTable.cc
|
||||
//
|
||||
// class description:
|
||||
// This class keeps a table of velocity as a function of
|
||||
// the ratio kinetic erngy and mass
|
||||
//
|
||||
//---------------------------------------------------------------
|
||||
// created 17.Aug. 2011 H.Kurashige
|
||||
//
|
||||
// Author: Hisaya Kurashige, 17 August 2011
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
#include "G4VelocityTable.hh"
|
||||
#include "G4PhysicalConstants.hh"
|
||||
@@ -45,40 +35,32 @@
|
||||
#include "G4Log.hh"
|
||||
#include "G4Exp.hh"
|
||||
|
||||
#include "G4ios.hh"
|
||||
#include "G4ios.hh"
|
||||
|
||||
G4ThreadLocal G4VelocityTable* G4VelocityTable::theInstance = nullptr;
|
||||
|
||||
////////////////
|
||||
// --------------------------------------------------------------------
|
||||
G4VelocityTable::G4VelocityTable()
|
||||
////////////////
|
||||
: edgeMin(0.), edgeMax(0.), numberOfNodes(0),
|
||||
dBin(0.), baseBin(0.),
|
||||
lastEnergy(-DBL_MAX), lastValue(0.), lastBin(0),
|
||||
maxT( 1000.0 ), minT( 0.0001 ), NbinT( 500 )
|
||||
{
|
||||
PrepareVelocityTable();
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////
|
||||
// --------------------------------------------------------------------
|
||||
G4VelocityTable::~G4VelocityTable()
|
||||
/////////////////
|
||||
{
|
||||
dataVector.clear();
|
||||
binVector.clear();
|
||||
}
|
||||
|
||||
|
||||
///////////////////
|
||||
// --------------------------------------------------------------------
|
||||
void G4VelocityTable::PrepareVelocityTable()
|
||||
///////////////////
|
||||
{
|
||||
//const G4double g4log10 = std::log(10.);
|
||||
|
||||
// const G4double g4log10 = std::log(10.);
|
||||
|
||||
dataVector.clear();
|
||||
binVector.clear();
|
||||
dBin = G4Log(maxT/minT)/NbinT;
|
||||
baseBin = G4Log(minT)/dBin;
|
||||
dBin = G4Log(maxT / minT) / NbinT;
|
||||
baseBin = G4Log(minT) / dBin;
|
||||
|
||||
numberOfNodes = NbinT + 1;
|
||||
dataVector.reserve(numberOfNodes);
|
||||
@@ -87,130 +69,140 @@ void G4VelocityTable::PrepareVelocityTable()
|
||||
binVector.push_back(minT);
|
||||
dataVector.push_back(0.0);
|
||||
|
||||
for (size_t i=1; i<numberOfNodes-1; i++){
|
||||
binVector.push_back(G4Exp((baseBin+i)*dBin));
|
||||
for(std::size_t i = 1; i < numberOfNodes - 1; ++i)
|
||||
{
|
||||
binVector.push_back(G4Exp((baseBin + i) * dBin));
|
||||
dataVector.push_back(0.0);
|
||||
}
|
||||
binVector.push_back(maxT);
|
||||
dataVector.push_back(0.0);
|
||||
|
||||
edgeMin = binVector[0];
|
||||
edgeMax = binVector[numberOfNodes-1];
|
||||
|
||||
for (G4int i=0; i<=NbinT; i++){
|
||||
G4double T = binVector[i];
|
||||
dataVector[i]= c_light*std::sqrt(T*(T+2.))/(T+1.0);
|
||||
edgeMin = binVector[0];
|
||||
edgeMax = binVector[numberOfNodes - 1];
|
||||
|
||||
for(G4int i = 0; i <= NbinT; ++i)
|
||||
{
|
||||
G4double T = binVector[i];
|
||||
dataVector[i] = c_light * std::sqrt(T * (T + 2.)) / (T + 1.0);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
size_t G4VelocityTable::FindBinLocation(G4double theEnergy) const
|
||||
// --------------------------------------------------------------------
|
||||
std::size_t G4VelocityTable::FindBinLocation(G4double theEnergy) const
|
||||
{
|
||||
// For G4PhysicsLogVector, FindBinLocation is implemented using
|
||||
// a simple arithmetic calculation.
|
||||
//
|
||||
// Because this is a virtual function, it is accessed through a
|
||||
// pointer to the G4PhyiscsVector object for most usages. In this
|
||||
// case, 'inline' will not be invoked. However, there is a possibility
|
||||
// that the user access to the G4PhysicsLogVector object directly and
|
||||
// pointer to the G4PhysicsVector object for most usages. In this
|
||||
// case, 'inline' will not be invoked. However, there is a possibility
|
||||
// that the user access to the G4PhysicsLogVector object directly and
|
||||
// not through pointers or references. In this case, the 'inline' will
|
||||
// be invoked. (See R.B.Murray, "C++ Strategies and Tactics", Chap.6.6)
|
||||
|
||||
//const G4double g4log10 = G4Log(10.);
|
||||
return size_t( G4Log(theEnergy)/dBin - baseBin );
|
||||
// const G4double g4log10 = G4Log(10.);
|
||||
return std::size_t(G4Log(theEnergy) / dBin - baseBin);
|
||||
}
|
||||
|
||||
G4double G4VelocityTable::Value(G4double theEnergy)
|
||||
// --------------------------------------------------------------------
|
||||
G4double G4VelocityTable::Value(G4double theEnergy)
|
||||
{
|
||||
// Use cache for speed up - check if the value 'theEnergy' is same as the
|
||||
// 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.
|
||||
// value 'theEnergy' lies between the last energy and low edge of of the
|
||||
// bin of last call, then the last bin location is used
|
||||
|
||||
if( theEnergy == lastEnergy ) {
|
||||
|
||||
} else if( theEnergy < lastEnergy
|
||||
&& theEnergy >= binVector[lastBin]) {
|
||||
lastEnergy = theEnergy;
|
||||
lastValue = Interpolation();
|
||||
|
||||
} else if( theEnergy <= edgeMin ) {
|
||||
lastBin = 0;
|
||||
lastEnergy = edgeMin;
|
||||
lastValue = dataVector[0];
|
||||
|
||||
} else if( theEnergy >= edgeMax ){
|
||||
lastBin = numberOfNodes-1;
|
||||
lastEnergy = edgeMax;
|
||||
lastValue = dataVector[lastBin];
|
||||
|
||||
} else {
|
||||
lastBin = (size_t)( G4Log(theEnergy)/dBin - baseBin );
|
||||
if(lastBin == numberOfNodes) { --lastBin; } // VI: fix possible precision lost
|
||||
lastEnergy = theEnergy;
|
||||
lastValue = Interpolation();
|
||||
|
||||
if(theEnergy == lastEnergy)
|
||||
{
|
||||
}
|
||||
return lastValue;
|
||||
else if(theEnergy < lastEnergy && theEnergy >= binVector[lastBin])
|
||||
{
|
||||
lastEnergy = theEnergy;
|
||||
lastValue = Interpolation();
|
||||
}
|
||||
else if(theEnergy <= edgeMin)
|
||||
{
|
||||
lastBin = 0;
|
||||
lastEnergy = edgeMin;
|
||||
lastValue = dataVector[0];
|
||||
}
|
||||
else if(theEnergy >= edgeMax)
|
||||
{
|
||||
lastBin = numberOfNodes - 1;
|
||||
lastEnergy = edgeMax;
|
||||
lastValue = dataVector[lastBin];
|
||||
}
|
||||
else
|
||||
{
|
||||
lastBin = (std::size_t)(G4Log(theEnergy) / dBin - baseBin);
|
||||
if(lastBin == numberOfNodes)
|
||||
{
|
||||
--lastBin;
|
||||
} // VI: fix possible precision lost
|
||||
lastEnergy = theEnergy;
|
||||
lastValue = Interpolation();
|
||||
}
|
||||
return lastValue;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
// Static methods
|
||||
|
||||
///////////////////
|
||||
// --------------------------------------------------------------------
|
||||
G4VelocityTable* G4VelocityTable::GetVelocityTable()
|
||||
///////////////////
|
||||
{
|
||||
if (!theInstance) {
|
||||
if(theInstance == nullptr)
|
||||
{
|
||||
static G4ThreadLocalSingleton<G4VelocityTable> inst;
|
||||
theInstance = inst.Instance();
|
||||
}
|
||||
return theInstance;
|
||||
}
|
||||
|
||||
///////////////////
|
||||
void G4VelocityTable::SetVelocityTableProperties(G4double t_max, G4double t_min, G4int nbin)
|
||||
///////////////////
|
||||
// --------------------------------------------------------------------
|
||||
void G4VelocityTable::
|
||||
SetVelocityTableProperties(G4double t_max, G4double t_min, G4int nbin)
|
||||
{
|
||||
if (theInstance == nullptr) { GetVelocityTable(); }
|
||||
if(theInstance == nullptr)
|
||||
{
|
||||
GetVelocityTable();
|
||||
}
|
||||
|
||||
G4StateManager* stateManager = G4StateManager::GetStateManager();
|
||||
G4StateManager* stateManager = G4StateManager::GetStateManager();
|
||||
G4ApplicationState currentState = stateManager->GetCurrentState();
|
||||
|
||||
|
||||
// check if state is outside event loop
|
||||
if(!(currentState==G4State_Idle||currentState==G4State_PreInit)){
|
||||
G4Exception("G4VelocityTable::SetVelocityTableProperties",
|
||||
"Track101", JustWarning,
|
||||
if(!(currentState == G4State_Idle || currentState == G4State_PreInit))
|
||||
{
|
||||
G4Exception("G4VelocityTable::SetVelocityTableProperties()", "Track101",
|
||||
JustWarning,
|
||||
"Can modify only in PreInit or Idle state : Method ignored.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (nbin > 100 ) theInstance->NbinT = nbin;
|
||||
if ((t_min < t_max)&&(t_min>0.)) {
|
||||
theInstance->minT = t_min;
|
||||
if(nbin > 100)
|
||||
theInstance->NbinT = nbin;
|
||||
if((t_min < t_max) && (t_min > 0.))
|
||||
{
|
||||
theInstance->minT = t_min;
|
||||
theInstance->maxT = t_max;
|
||||
}
|
||||
}
|
||||
theInstance->PrepareVelocityTable();
|
||||
}
|
||||
|
||||
///////////////////
|
||||
// --------------------------------------------------------------------
|
||||
G4double G4VelocityTable::GetMaxTOfVelocityTable()
|
||||
///////////////////
|
||||
{
|
||||
return GetVelocityTable()->maxT;
|
||||
return GetVelocityTable()->maxT;
|
||||
}
|
||||
|
||||
///////////////////
|
||||
G4double G4VelocityTable::GetMinTOfVelocityTable()
|
||||
///////////////////
|
||||
// --------------------------------------------------------------------
|
||||
G4double G4VelocityTable::GetMinTOfVelocityTable()
|
||||
{
|
||||
return GetVelocityTable()->minT;
|
||||
return GetVelocityTable()->minT;
|
||||
}
|
||||
|
||||
///////////////////
|
||||
G4int G4VelocityTable::GetNbinOfVelocityTable()
|
||||
///////////////////
|
||||
// --------------------------------------------------------------------
|
||||
G4int G4VelocityTable::GetNbinOfVelocityTable()
|
||||
{
|
||||
return GetVelocityTable()->NbinT;
|
||||
return GetVelocityTable()->NbinT;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user