Import Geant4 10.7.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2020-06-26 10:23:25 +02:00
parent c02c370437
commit 67ba86d073
1871 changed files with 174422 additions and 131884 deletions
@@ -23,21 +23,26 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// First implementation - 20th August 2004, H.Kurashige
// G4MCCIndexConversionTable class implementation
//
// Author: H.Kurashige, 20 August 2004 - First implementation
//---------------------------------------------------------------------
#include "G4MCCIndexConversionTable.hh"
// --------------------------------------------------------------------
G4MCCIndexConversionTable::G4MCCIndexConversionTable()
{
}
// --------------------------------------------------------------------
G4MCCIndexConversionTable::~G4MCCIndexConversionTable()
{
vecNewIndex.clear();
}
void G4MCCIndexConversionTable::Reset(size_t siz)
// --------------------------------------------------------------------
void G4MCCIndexConversionTable::Reset(std::size_t siz)
{
// reset conversion table
vecNewIndex.clear();
@@ -23,51 +23,45 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// G4MaterialCutsCouple class implementation
//
//
//
// --------------------------------------------------------------
// GEANT 4 class implementation file/ History:
// 18 Sep. 2002, H.Kuirashige : Structure created based on object model
// --------------------------------------------------------------
// Author: H.Kurashige, 17 September 2002 - First implementation
// --------------------------------------------------------------------
#include "G4MaterialCutsCouple.hh"
#include "G4Material.hh"
#include <iomanip>
#include "G4Material.hh"
#include "G4ProductionCuts.hh"
G4MaterialCutsCouple::G4MaterialCutsCouple() :
isMaterialModified(false),
fMaterial(nullptr),
fCuts(nullptr),
indexNumber(-1),
isUsedInGeometry(false)
// --------------------------------------------------------------------
G4MaterialCutsCouple::G4MaterialCutsCouple()
{
}
// --------------------------------------------------------------------
G4MaterialCutsCouple::G4MaterialCutsCouple(const G4Material* material,
G4ProductionCuts* cut) :
isMaterialModified(true),
fMaterial(material),
fCuts(cut),
indexNumber(-1),
isUsedInGeometry(false)
G4ProductionCuts* cut)
: isMaterialModified(true),
fMaterial(material),
fCuts(cut)
{
}
// --------------------------------------------------------------------
G4MaterialCutsCouple::G4MaterialCutsCouple(const G4MaterialCutsCouple& right)
:fMaterial(nullptr), fCuts(nullptr)
: fMaterial(nullptr), fCuts(nullptr)
{
*this = right;
}
// --------------------------------------------------------------------
G4MaterialCutsCouple::~G4MaterialCutsCouple()
{
}
G4MaterialCutsCouple & G4MaterialCutsCouple::operator=(const G4MaterialCutsCouple &right)
// --------------------------------------------------------------------
G4MaterialCutsCouple&
G4MaterialCutsCouple::operator=(const G4MaterialCutsCouple& right)
{
if (&right==this) return *this;
@@ -79,4 +73,3 @@ G4MaterialCutsCouple & G4MaterialCutsCouple::operator=(const G4MaterialCutsCoupl
return *this;
}
@@ -23,93 +23,93 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// G4PhysicsTableHelper class implementation
//
//
// ------------------------------------------------------------
// GEANT 4 class header file
//
// Class Description
//
// G4PhysicsTableHelper is a static utility class
// for helping processes to build their physics table
//
// ------------------------------------------------------------
// First Implementation 20 Aug. 2004 H.Kurashige
//
// ------------------------------------------------------------
// Author: H.Kurashige, 20 August 2004 - First implementation
// --------------------------------------------------------------------
#include "G4PhysicsTableHelper.hh"
#include "G4ProductionCutsTable.hh"
G4ThreadLocal G4int G4PhysicsTableHelper::verboseLevel = 1;
// --------------------------------------------------------------------
G4PhysicsTableHelper::G4PhysicsTableHelper()
{
}
// --------------------------------------------------------------------
G4PhysicsTableHelper::~G4PhysicsTableHelper()
{
}
G4PhysicsTableHelper::G4PhysicsTableHelper(const G4PhysicsTableHelper&)
// --------------------------------------------------------------------
G4PhysicsTable*
G4PhysicsTableHelper::PreparePhysicsTable(G4PhysicsTable* physTable)
{
}
G4ProductionCutsTable* cutTable
= G4ProductionCutsTable::GetProductionCutsTable();
std::size_t numberOfMCC = cutTable->GetTableSize();
G4PhysicsTableHelper& G4PhysicsTableHelper::operator=(const G4PhysicsTableHelper&)
{
return *this;
}
G4PhysicsTable* G4PhysicsTableHelper::PreparePhysicsTable(G4PhysicsTable* physTable)
{
G4ProductionCutsTable* cutTable = G4ProductionCutsTable::GetProductionCutsTable();
size_t numberOfMCC = cutTable->GetTableSize();
if ( physTable != nullptr) {
if ( physTable != nullptr)
{
// compare size of physics table and number of material-cuts-couple
if ( physTable->size() < numberOfMCC) {
// enlarge physcis table
if ( physTable->size() < numberOfMCC)
{
// enlarge physics table
physTable->resize(numberOfMCC, nullptr);
#ifdef G4VERBOSE
if (verboseLevel>2) {
G4cerr << "G4PhysicsTableHelper::PreparePhysicsTable ";
G4cerr << "Physics Table "<< physTable ;
G4cerr << " is resized to " << numberOfMCC << G4endl;
if (verboseLevel>2)
{
G4cerr << "G4PhysicsTableHelper::PreparePhysicsTable ";
G4cerr << "Physics Table "<< physTable ;
G4cerr << " is resized to " << numberOfMCC << G4endl;
}
#endif
} else if ( physTable->size() > numberOfMCC){
}
else if ( physTable->size() > numberOfMCC)
{
// ERROR: this situation should not occur
// size of physics table is shorter than number of material-cuts-couple
// size of physics table is shorter than number of material-cuts-couple
physTable->resize(numberOfMCC);
#ifdef G4VERBOSE
if (verboseLevel>0) {
G4cerr << "G4PhysicsTableHelper::PreparePhysicsTable ";
G4cerr << "Physics Table "<< physTable ;
G4cerr << " is longer than number of material-cuts-couple " << G4endl;
if (verboseLevel>0)
{
G4cerr << "G4PhysicsTableHelper::PreparePhysicsTable ";
G4cerr << "Physics Table "<< physTable ;
G4cerr << " is longer than number of material-cuts-couple " << G4endl;
}
#endif
G4Exception( "G4PhysicsTableHelper::PreparePhysicsTable()",
"ProcCuts001", FatalException,
"Physics Table is inconsistent with material-cuts-couple");
"ProcCuts001", FatalException,
"Physics Table is inconsistent with material-cuts-couple");
}
} else {
}
else
{
// create PhysicsTable is given poitner is null
physTable = new G4PhysicsTable(numberOfMCC);
if (physTable != nullptr) {
if (physTable != nullptr)
{
physTable->resize(numberOfMCC, nullptr);
} else {
}
else
{
G4Exception( "G4PhysicsTableHelper::PreparePhysicsTable()",
"ProcCuts002", FatalException,
"Can't create Physics Table");
"ProcCuts002", FatalException,
"Can't create Physics Table");
}
}
#ifdef G4VERBOSE
if (verboseLevel>2) {
if ( physTable != nullptr) {
if (verboseLevel>2)
{
if ( physTable != nullptr)
{
G4cerr << "Physics Table size "<< physTable->size();
} else {
}
else
{
G4cerr << "Physics Table does not exist ";
}
G4cerr << ": number of material-cuts-couple " << numberOfMCC << G4endl;
@@ -119,9 +119,11 @@ G4PhysicsTable* G4PhysicsTableHelper::PreparePhysicsTable(G4PhysicsTable* physTa
// Reset recal-needed flag for all physics vectors
physTable->ResetFlagArray();
for (size_t idx = 0; idx <numberOfMCC; idx +=1){
for (std::size_t idx = 0; idx <numberOfMCC; ++idx)
{
const G4MaterialCutsCouple* mcc = cutTable->GetMaterialCutsCouple(idx);
//check if re-calculation of the physics vector is needed
// check if re-calculation of the physics vector is needed
// MCC is not used
if ( !mcc->IsUsed() ) physTable->ClearFlag(idx);
@@ -132,37 +134,42 @@ G4PhysicsTable* G4PhysicsTableHelper::PreparePhysicsTable(G4PhysicsTable* physTa
return physTable;
}
// --------------------------------------------------------------------
G4bool G4PhysicsTableHelper::RetrievePhysicsTable(G4PhysicsTable* physTable,
const G4String& fileName,
G4bool ascii )
const G4String& fileName,
G4bool ascii )
{
if (physTable == nullptr ) return false;
// retrieve physics table from the given file
G4PhysicsTable* tempTable = new G4PhysicsTable();
if (! tempTable->RetrievePhysicsTable(fileName,ascii) ){
if (! tempTable->RetrievePhysicsTable(fileName,ascii) )
{
#ifdef G4VERBOSE
if (verboseLevel>1) {
if (verboseLevel>1)
{
G4cerr << "G4PhysicsTableHelper::RetrievePhysicsTable ";
G4cerr << "Fail to retrieve from "<< fileName << G4endl;
}
#endif
G4Exception( "G4ProductionCutsTable::RetrievePhysicsTable()",
"ProcCuts105",
JustWarning, "Can not retrieve physics tables from file");
"ProcCuts105",
JustWarning, "Can not retrieve physics tables from file");
delete tempTable;
return false;
}
G4ProductionCutsTable* cutTable = G4ProductionCutsTable::GetProductionCutsTable();
const G4MCCIndexConversionTable* converter = cutTable->GetMCCIndexConversionTable();
G4ProductionCutsTable* cutTable
= G4ProductionCutsTable::GetProductionCutsTable();
const G4MCCIndexConversionTable* converter
= cutTable->GetMCCIndexConversionTable();
// check physics table size
if ( tempTable->size() != converter->size()){
if ( tempTable->size() != converter->size())
{
#ifdef G4VERBOSE
if (verboseLevel>0) {
if (verboseLevel>0)
{
G4cerr << "G4PhysicsTableHelper::RetrievePhysicsTable ";
G4cerr << "Size of the physics table in "<< fileName;
G4cerr << "( size =" << tempTable->size() << ")";
@@ -171,21 +178,23 @@ G4bool G4PhysicsTableHelper::RetrievePhysicsTable(G4PhysicsTable* physTable,
G4cerr << G4endl;
}
#endif
G4Exception( "G4ProductionCutsTable::RetrievePhysicsTable()",
"ProcCuts106",
JustWarning, "Retrived file is inconsistent with current physics tables ");
G4Exception("G4ProductionCutsTable::RetrievePhysicsTable()",
"ProcCuts106", JustWarning,
"Retrieved file is inconsistent with current physics tables!");
delete tempTable;
return false;
}
// fill the given physics table with retrived physics vectors
for (size_t idx=0; idx<converter->size(); idx++){
if (converter->IsUsed(idx)){
// fill the given physics table with retrieved physics vectors
for (std::size_t idx=0; idx<converter->size(); ++idx)
{
if (converter->IsUsed(idx))
{
if (converter->GetIndex(idx)<0) continue;
size_t i = converter->GetIndex(idx);
std::size_t i = converter->GetIndex(idx);
G4PhysicsVector* vec = (*physTable)[i];
if (vec != nullptr ) delete vec;
(*physTable)[i] = (*tempTable)[idx];
if (vec != nullptr ) delete vec;
(*physTable)[i] = (*tempTable)[idx];
physTable->ClearFlag(i);
}
}
@@ -195,16 +204,18 @@ G4bool G4PhysicsTableHelper::RetrievePhysicsTable(G4PhysicsTable* physTable,
return true;
}
// --------------------------------------------------------------------
void G4PhysicsTableHelper::SetPhysicsVector(G4PhysicsTable* physTable,
size_t idx,
G4PhysicsVector* vec)
std::size_t idx,
G4PhysicsVector* vec)
{
if ( physTable == nullptr) { return; }
if ( physTable->size() <= idx) {
if ( physTable->size() <= idx)
{
#ifdef G4VERBOSE
if (verboseLevel>0) {
if (verboseLevel>0)
{
G4cerr << "G4PhysicsTableHelper::SetPhysicsVector ";
G4cerr << "Given index (" << idx << ") exceeds ";
G4cerr << "size of the physics table ";
@@ -212,9 +223,9 @@ void G4PhysicsTableHelper::SetPhysicsVector(G4PhysicsTable* physTable,
G4cerr << G4endl;
}
#endif
G4Exception( "G4ProductionCutsTable::SetPhysicsVector()",
"ProcCuts107",
JustWarning, "Illegal index ");
G4Exception("G4ProductionCutsTable::SetPhysicsVector()",
"ProcCuts107",
JustWarning, "Illegal index!");
return;
}
@@ -222,20 +233,16 @@ void G4PhysicsTableHelper::SetPhysicsVector(G4PhysicsTable* physTable,
(*physTable)[idx] = vec;
// clear flag
physTable->ClearFlag(idx);
}
// --------------------------------------------------------------------
void G4PhysicsTableHelper::SetVerboseLevel(G4int value)
{
verboseLevel = value;
}
// --------------------------------------------------------------------
G4int G4PhysicsTableHelper::GetVerboseLevel()
{
return verboseLevel;
}
+39 -36
View File
@@ -23,16 +23,14 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// G4ProductionCuts class implementation
//
//
//
// --------------------------------------------------------------
// GEANT 4 class implementation file/ History:
// 18 Sep. 2002, H.Kuirashige : Structure created based on object model
// --------------------------------------------------------------
// Author: H.Kurashige, 17 September 2002 - First implementation
// --------------------------------------------------------------------
#include "G4ProductionCuts.hh"
#include "G4ProductionCutsTable.hh"
#include <iomanip>
G4ThreadLocal G4ParticleDefinition* G4ProductionCuts::gammaDef = nullptr;
@@ -40,18 +38,18 @@ G4ThreadLocal G4ParticleDefinition* G4ProductionCuts::electDef = nullptr;
G4ThreadLocal G4ParticleDefinition* G4ProductionCuts::positDef = nullptr;
G4ThreadLocal G4ParticleDefinition* G4ProductionCuts::protonDef = nullptr;
G4ProductionCuts::G4ProductionCuts() :
isModified(true)
G4ProductionCuts::G4ProductionCuts()
{
for (G4int i=0; i< NumberOfG4CutIndex; i++) {
for (G4int i=0; i< NumberOfG4CutIndex; ++i)
{
fRangeCuts.push_back(0.0);
}
}
G4ProductionCuts::G4ProductionCuts(const G4ProductionCuts& right)
: isModified(true)
{
for (G4int i=0; i< NumberOfG4CutIndex; i++) {
for (G4int i=0; i< NumberOfG4CutIndex; ++i)
{
fRangeCuts.push_back(0.0);
}
*this = right;
@@ -62,32 +60,30 @@ G4ProductionCuts::~G4ProductionCuts()
fRangeCuts.clear();
}
G4ProductionCuts & G4ProductionCuts::operator=(const G4ProductionCuts &right)
G4ProductionCuts& G4ProductionCuts::operator=(const G4ProductionCuts& right)
{
if (&right==this) return *this;
for (G4int i=0; i< NumberOfG4CutIndex; i++) {
for (G4int i=0; i< NumberOfG4CutIndex; ++i)
{
fRangeCuts[i] = right.fRangeCuts[i];
}
isModified = right.isModified;
return *this;
}
G4bool G4ProductionCuts::operator==(const G4ProductionCuts &right) const
G4bool G4ProductionCuts::operator==(const G4ProductionCuts& right) const
{
return (this == &right);
}
G4bool G4ProductionCuts::operator!=(const G4ProductionCuts &right) const
G4bool G4ProductionCuts::operator!=(const G4ProductionCuts& right) const
{
return (this != &right);
return (this != &right);
}
G4int G4ProductionCuts::GetIndex(const G4String& name)
G4int G4ProductionCuts::GetIndex(const G4String& name)
{
static const G4String gamma ("gamma");
static const G4String electron("e-");
@@ -105,44 +101,51 @@ G4int G4ProductionCuts::GetIndex(const G4String& name)
}
G4int G4ProductionCuts::GetIndex(const G4ParticleDefinition* ptcl)
G4int G4ProductionCuts::GetIndex(const G4ParticleDefinition* ptcl)
{
if(!ptcl) return -1;
// In the first call, pointers are set
if(gammaDef==nullptr && ptcl->GetParticleName()=="gamma") { gammaDef = (G4ParticleDefinition*) ptcl; }
if(electDef==nullptr && ptcl->GetParticleName()=="e-") { electDef = (G4ParticleDefinition*) ptcl; }
if(positDef==nullptr && ptcl->GetParticleName()=="e+") { positDef = (G4ParticleDefinition*) ptcl; }
if(protonDef==nullptr && ptcl->GetParticleName()=="proton") { protonDef = (G4ParticleDefinition*) ptcl; }
if(gammaDef==nullptr && ptcl->GetParticleName()=="gamma")
{ gammaDef = (G4ParticleDefinition*) ptcl; }
if(electDef==nullptr && ptcl->GetParticleName()=="e-")
{ electDef = (G4ParticleDefinition*) ptcl; }
if(positDef==nullptr && ptcl->GetParticleName()=="e+")
{ positDef = (G4ParticleDefinition*) ptcl; }
if(protonDef==nullptr && ptcl->GetParticleName()=="proton")
{ protonDef = (G4ParticleDefinition*) ptcl; }
G4int index;
if(ptcl==(const G4ParticleDefinition*) gammaDef) { index = 0; }
else if(ptcl==(const G4ParticleDefinition*) electDef) { index = 1; }
else if(ptcl==(const G4ParticleDefinition*) positDef) { index = 2; }
else if(ptcl==(const G4ParticleDefinition*) protonDef) { index = 3; }
else { index = -1; }
else { index = -1; }
return index;
}
void G4ProductionCuts::SetProductionCuts(std::vector<G4double>& cut)
void G4ProductionCuts::SetProductionCuts(std::vector<G4double>& cut)
{
G4int vSize = cut.size();
if (vSize != NumberOfG4CutIndex) {
if (vSize != NumberOfG4CutIndex)
{
#ifdef G4VERBOSE
if ( G4ProductionCutsTable::GetProductionCutsTable()->GetVerboseLevel()>1) {
if ( G4ProductionCutsTable::GetProductionCutsTable()->GetVerboseLevel()>1)
{
G4cerr << "G4ProductionCuts::SetProductionCuts ";
G4cerr << " The size of given cut value vector [=" << vSize << "] "
<< " is not consitent with number of CutIndex [="
<< NumberOfG4CutIndex << G4endl;
<< " is not consistent with number of CutIndex [="
<< NumberOfG4CutIndex << G4endl;
}
#endif
G4Exception( "G4ProductionCuts::SetProductionCuts ",
"ProcCuts108",
JustWarning, "Given vector size is inconsitent ");
if (NumberOfG4CutIndex<vSize) vSize = NumberOfG4CutIndex;
"ProcCuts108",
JustWarning, "Given vector size is inconsistent ");
if (NumberOfG4CutIndex<vSize) { vSize = NumberOfG4CutIndex; }
}
for(G4int i = 0; (i<vSize ); i++) {
for(G4int i = 0; (i<vSize ); ++i)
{
fRangeCuts[i] = cut[i];
}
isModified = true;
File diff suppressed because it is too large Load Diff
@@ -23,16 +23,10 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// G4ProductionCutsTableMessenger class implementation
//
//
//
//---------------------------------------------------------------
//
// G4ProductionCutsTableMessenger.cc
// ------------------------------------------------------------
// History
// first version 02 Mar. 2008 by H.Kurashige
//
// Author: H.Kurashige, 02 March 2008 - First version
// --------------------------------------------------------------------
#include "G4ProductionCutsTableMessenger.hh"
#include "G4ProductionCutsTable.hh"
@@ -47,10 +41,12 @@
#include <sstream>
G4ProductionCutsTableMessenger::G4ProductionCutsTableMessenger( G4ProductionCutsTable* pTable)
:theCutsTable(pTable)
// --------------------------------------------------------------------
G4ProductionCutsTableMessenger::
G4ProductionCutsTableMessenger(G4ProductionCutsTable* pTable)
: theCutsTable(pTable)
{
// /cuts/ directory
// /cuts/ directory
theDirectory = new G4UIdirectory("/cuts/");
theDirectory->SetGuidance("Commands for G4VUserPhysicsList.");
@@ -92,12 +88,12 @@ G4ProductionCutsTableMessenger::G4ProductionCutsTableMessenger( G4ProductionCu
setMaxEnergyCutCmd->SetDefaultUnit("GeV");
setMaxEnergyCutCmd->AvailableForStates(G4State_PreInit);
// /cuts/dump command
// /cuts/dump command
dumpCmd = new G4UIcmdWithoutParameter("/cuts/dump",this);
dumpCmd->SetGuidance("Dump cuplues in ProductuinCutsTable. ");
dumpCmd->SetGuidance("Dump couples in G4ProductionCutsTable. ");
}
// --------------------------------------------------------------------
G4ProductionCutsTableMessenger::~G4ProductionCutsTableMessenger()
{
delete dumpCmd;
@@ -108,54 +104,61 @@ G4ProductionCutsTableMessenger::~G4ProductionCutsTableMessenger()
delete theDirectory;
}
void G4ProductionCutsTableMessenger::SetNewValue(G4UIcommand * command,
G4String newValue)
// --------------------------------------------------------------------
void G4ProductionCutsTableMessenger::SetNewValue(G4UIcommand* command,
G4String newValue)
{
if( command==verboseCmd ) {
if( command==verboseCmd )
{
theCutsTable->SetVerboseLevel(verboseCmd->GetNewIntValue(newValue));
} else if( command==dumpCmd ){
}
else if( command==dumpCmd )
{
theCutsTable-> DumpCouples();
} else if( command==setLowEdgeCmd ){
}
else if( command==setLowEdgeCmd )
{
G4double lowEdge = setLowEdgeCmd->GetNewDoubleValue(newValue);
G4double highEdge = theCutsTable->GetHighEdgeEnergy();
theCutsTable->SetEnergyRange(lowEdge, highEdge);
} else if( command==setHighEdgeCmd ){
}
else if( command==setHighEdgeCmd )
{
G4double highEdge = setHighEdgeCmd->GetNewDoubleValue(newValue);
G4double lowEdge = theCutsTable->GetLowEdgeEnergy();
theCutsTable->SetEnergyRange(lowEdge, highEdge);
} else if( command==setMaxEnergyCutCmd ){
}
else if( command==setMaxEnergyCutCmd )
{
G4double cut = setHighEdgeCmd->GetNewDoubleValue(newValue);
theCutsTable->SetMaxEnergyCut(cut);
}
}
G4String G4ProductionCutsTableMessenger::GetCurrentValue(G4UIcommand * command)
// --------------------------------------------------------------------
G4String G4ProductionCutsTableMessenger::GetCurrentValue(G4UIcommand* command)
{
G4String cv;
if( command==verboseCmd ){
if( command==verboseCmd )
{
cv = verboseCmd->ConvertToString(theCutsTable->GetVerboseLevel());
} else if( command==setLowEdgeCmd ){
}
else if( command==setLowEdgeCmd )
{
G4double lowEdge = theCutsTable->GetLowEdgeEnergy();
cv = setLowEdgeCmd->ConvertToString( lowEdge, "keV" );
} else if( command==setHighEdgeCmd ){
}
else if( command==setHighEdgeCmd )
{
G4double highEdge = theCutsTable->GetHighEdgeEnergy();
cv = setHighEdgeCmd->ConvertToString( highEdge, "TeV" );
} else if( command==setMaxEnergyCutCmd ){
}
else if( command==setMaxEnergyCutCmd )
{
G4double cut = theCutsTable->GetMaxEnergyCut();
cv = setMaxEnergyCutCmd->ConvertToString( cut, "GeV" );
}
}
return cv;
}
@@ -23,13 +23,10 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// G4RToEConvForElectron class implementation
//
//
//
// --------------------------------------------------------------
// GEANT 4 class implementation file/ History:
// 5 Oct. 2002, H.Kuirashige : Structure created based on object model
// --------------------------------------------------------------
// Author: H.Kurashige, 05 October 2002 - First implementation
// --------------------------------------------------------------------
#include "G4RToEConvForElectron.hh"
#include "G4ParticleDefinition.hh"
@@ -41,67 +38,68 @@
#include "G4PhysicalConstants.hh"
#include "G4SystemOfUnits.hh"
// --------------------------------------------------------------------
G4RToEConvForElectron::G4RToEConvForElectron()
: G4VRangeToEnergyConverter(),
Mass(0.0),
Z(-1.),
taul(0.0),
ionpot(0.0),
ionpotlog(-1.0e-10),
bremfactor(0.1)
: G4VRangeToEnergyConverter()
{
theParticle = G4ParticleTable::GetParticleTable()->FindParticle("e-");
if (theParticle ==0) {
theParticle = G4ParticleTable::GetParticleTable()->FindParticle("e-");
if (theParticle == nullptr )
{
#ifdef G4VERBOSE
if (GetVerboseLevel()>0) {
G4cout << " G4RToEConvForElectron::G4RToEConvForElectron() ";
G4cout << " Electron is not defined !!" << G4endl;
if (GetVerboseLevel()>0)
{
G4cout << "G4RToEConvForElectron::G4RToEConvForElectron() - ";
G4cout << "Electron is not defined !!" << G4endl;
}
#endif
} else {
}
else
{
Mass = theParticle->GetPDGMass();
}
}
// --------------------------------------------------------------------
G4RToEConvForElectron::~G4RToEConvForElectron()
{
}
// **********************************************************************
// ************************* ComputeLoss ********************************
// **********************************************************************
// ***********************************************************************
// ************************** ComputeLoss ********************************
// ***********************************************************************
G4double G4RToEConvForElectron::ComputeLoss(G4double AtomicNumber,
G4double KineticEnergy)
G4double KineticEnergy)
{
const G4double cbr1=0.02, cbr2=-5.7e-5, cbr3=1., cbr4=0.072;
const G4double Tlow=10.*keV, Thigh=1.*GeV;
const G4double cbr1=0.02, cbr2=-5.7e-5, cbr3=1., cbr4=0.072;
const G4double Tlow=10.*keV, Thigh=1.*GeV;
// calculate dE/dx for electrons
if( std::fabs(AtomicNumber-Z)>0.1 ) {
if( std::fabs(AtomicNumber-Z)>0.1 )
{
Z = AtomicNumber;
taul = Tlow/Mass;
ionpot = 1.6e-5*MeV*std::exp(0.9*std::log(Z))/Mass;
ionpotlog = std::log(ionpot);
}
G4double tau = KineticEnergy/Mass;
G4double dEdx;
if(tau<taul) {
if(tau<taul)
{
G4double t1 = taul+1.;
G4double t2 = taul+2.;
G4double tsq = taul*taul;
G4double beta2 = taul*t2/(t1*t1);
G4double f = 1.-beta2+std::log(tsq/2.)
+(0.5+0.25*tsq+(1.+2.*taul)*std::log(0.5))/(t1*t1);
+(0.5+0.25*tsq+(1.+2.*taul)*std::log(0.5))/(t1*t1);
dEdx = (std::log(2.*taul+4.)-2.*ionpotlog+f)/beta2;
dEdx = twopi_mc2_rcl2*Z*dEdx;
G4double clow = dEdx*std::sqrt(taul);
dEdx = clow/std::sqrt(KineticEnergy/Mass);
} else {
}
else
{
G4double t1 = tau+1.;
G4double t2 = tau+2.;
G4double tsq = tau*tau;
+61 -57
View File
@@ -23,13 +23,10 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// G4RToEConvForGamma class implementation
//
//
//
// --------------------------------------------------------------
// GEANT 4 class implementation file/ History:
// 5 Oct. 2002, H.Kuirashige : Structure created based on object model
// --------------------------------------------------------------
// Author: H.Kurashige, 05 October 2002 - First implementation
// --------------------------------------------------------------------
#include "G4RToEConvForGamma.hh"
#include "G4ParticleDefinition.hh"
@@ -40,20 +37,18 @@
#include "G4ios.hh"
#include "G4SystemOfUnits.hh"
// --------------------------------------------------------------------
G4RToEConvForGamma::G4RToEConvForGamma()
: G4VRangeToEnergyConverter(),
Z(-1),
s200keV(0.), s1keV(0.),
tmin(0.), tlow(0.),
smin(0.), slow(0.),
cmin(0.), clow(0.), chigh(0.)
: G4VRangeToEnergyConverter()
{
theParticle = G4ParticleTable::GetParticleTable()->FindParticle("gamma");
if (theParticle ==0) {
theParticle = G4ParticleTable::GetParticleTable()->FindParticle("gamma");
if (theParticle == nullptr)
{
#ifdef G4VERBOSE
if (GetVerboseLevel()>0) {
G4cout << " G4RToEConvForGamma::G4RToEConvForGamma() ";
G4cout << " Gamma is not defined !!" << G4endl;
if (GetVerboseLevel()>0)
{
G4cout << " G4RToEConvForGamma::G4RToEConvForGamma() - ";
G4cout << "Gamma is not defined !!" << G4endl;
}
#endif
}
@@ -63,7 +58,6 @@ G4RToEConvForGamma::~G4RToEConvForGamma()
{
}
// ***********************************************************************
// ******************* BuildAbsorptionLengthVector ***********************
// ***********************************************************************
@@ -72,47 +66,52 @@ void G4RToEConvForGamma::BuildAbsorptionLengthVector(
G4RangeVector* absorptionLengthVector )
{
// fill the absorption length vector for this material
// absorption length is defined here as
// absorption length is defined here as:
// absorption length = 5./ macroscopic absorption cross section
//
// absorption length = 5./ macroscopic absorption cross section
//
const G4CrossSectionTable* aCrossSectionTable = (G4CrossSectionTable*)(theLossTable);
const G4ElementVector* elementVector = aMaterial->GetElementVector();
const G4double* atomicNumDensityVector = aMaterial->GetAtomicNumDensityVector();
const G4CrossSectionTable* aCrossSectionTable
= (G4CrossSectionTable*)(theLossTable);
const G4ElementVector* elementVector
= aMaterial->GetElementVector();
const G4double* atomicNumDensityVector
= aMaterial->GetAtomicNumDensityVector();
// fill absorption length vector
// fill absorption length vector
G4int NumEl = aMaterial->GetNumberOfElements();
G4double absorptionLengthMax = 0.0;
for (size_t ibin=0; ibin<size_t(TotBin); ibin++) {
G4double SIGMA = 0. ;
for (size_t iel=0; iel<size_t(NumEl); iel++) {
for (std::size_t ibin=0; ibin<size_t(TotBin); ++ibin)
{
G4double SIGMA = 0.;
for (std::size_t iel=0; iel<size_t(NumEl); ++iel)
{
G4int IndEl = (*elementVector)[iel]->GetIndex();
SIGMA += atomicNumDensityVector[iel]*
(*((*aCrossSectionTable)[IndEl]))[ibin];
SIGMA += atomicNumDensityVector[iel]
* (*((*aCrossSectionTable)[IndEl]))[ibin];
}
// absorption length=5./SIGMA
absorptionLengthVector->PutValue(ibin, 5./SIGMA);
if (absorptionLengthMax < 5./SIGMA ) absorptionLengthMax = 5./SIGMA;
if (absorptionLengthMax < 5./SIGMA )
absorptionLengthMax = 5./SIGMA;
}
}
// ***********************************************************************
// ********************** ComputeCrossSection ****************************
// ***********************************************************************
G4double G4RToEConvForGamma::ComputeCrossSection(G4double AtomicNumber,
G4double KineticEnergy)
G4double KineticEnergy)
{
// Compute the "absorption" cross section of the photon "absorption"
// cross section means here the sum of the cross sections of the
// pair production, Compton scattering and photoelectric processes
// Compute the "absorption" cross-section of the photon "absorption".
// Cross-section means here the sum of the cross-sections of the
// pair production, Compton scattering and photoelectric processes
const G4double t1keV = 1.*keV;
const G4double t200keV = 200.*keV;
const G4double t100MeV = 100.*MeV;
// compute Z dependent quantities in the case of a new AtomicNumber
if(std::abs(AtomicNumber-Z)>0.1) {
// Compute Z dependent quantities in the case of a new AtomicNumber
if(std::abs(AtomicNumber-Z)>0.1)
{
Z = AtomicNumber;
G4double Zsquare = Z*Z;
G4double Zlog = std::log(Z);
@@ -121,33 +120,38 @@ G4double G4RToEConvForGamma::ComputeCrossSection(G4double AtomicNumber,
s200keV = (0.2651-0.1501*Zlog+0.02283*Zlogsquare)*Zsquare;
tmin = (0.552+218.5/Z+557.17/Zsquare)*MeV;
smin = (0.01239+0.005585*Zlog-0.000923*Zlogsquare)*std::exp(1.5*Zlog);
cmin=std::log(s200keV/smin)/(std::log(tmin/t200keV)*std::log(tmin/t200keV));
cmin = std::log(s200keV/smin)
/(std::log(tmin/t200keV)*std::log(tmin/t200keV));
tlow = 0.2*std::exp(-7.355/std::sqrt(Z))*MeV;
slow = s200keV*std::exp(0.042*Z*std::log(t200keV/tlow)*std::log(t200keV/tlow));
slow = s200keV
* std::exp(0.042*Z*std::log(t200keV/tlow)*std::log(t200keV/tlow));
s1keV = 300.*Zsquare;
clow =std::log(s1keV/slow)/std::log(tlow/t1keV);
chigh=(7.55e-5-0.0542e-5*Z)*Zsquare*Z/std::log(t100MeV/tmin);
clow = std::log(s1keV/slow)/std::log(tlow/t1keV);
chigh = (7.55e-5-0.0542e-5*Z)*Zsquare*Z/std::log(t100MeV/tmin);
}
// calculate the cross section (using an approximate empirical formula)
// Calculate the cross-section (using an approximate empirical formula)
G4double xs;
if ( KineticEnergy<tlow ) {
if ( KineticEnergy<tlow )
{
if(KineticEnergy<t1keV) xs = slow*std::exp(clow*std::log(tlow/t1keV));
else xs = slow*std::exp(clow*std::log(tlow/KineticEnergy));
} else if ( KineticEnergy<t200keV ) {
else xs = slow*std::exp(clow*std::log(tlow/KineticEnergy));
}
else if ( KineticEnergy<t200keV )
{
xs = s200keV
* std::exp(0.042*Z*std::log(t200keV/KineticEnergy)*std::log(t200keV/KineticEnergy));
} else if( KineticEnergy<tmin ){
* std::exp(0.042*Z*std::log(t200keV/KineticEnergy)
*std::log(t200keV/KineticEnergy));
}
else if( KineticEnergy<tmin )
{
xs = smin
* std::exp(cmin*std::log(tmin/KineticEnergy)*std::log(tmin/KineticEnergy));
} else {
* std::exp(cmin*std::log(tmin/KineticEnergy)
*std::log(tmin/KineticEnergy));
}
else
{
xs = smin + chigh*std::log(KineticEnergy/tmin);
}
return xs * barn;
}
@@ -23,13 +23,10 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// G4RToEConvForPositron class implementation
//
//
//
// --------------------------------------------------------------
// GEANT 4 class implementation file/ History:
// 5 Oct. 2002, H.Kuirashige : Structure created based on object model
// --------------------------------------------------------------
// Author: H.Kurashige, 05 October 2002 - First implementation
// --------------------------------------------------------------------
#include "G4RToEConvForPositron.hh"
#include "G4ParticleDefinition.hh"
@@ -41,46 +38,44 @@
#include "G4PhysicalConstants.hh"
#include "G4SystemOfUnits.hh"
// --------------------------------------------------------------------
G4RToEConvForPositron::G4RToEConvForPositron()
: G4VRangeToEnergyConverter(),
Mass(0.0),
Z(-1.),
taul(0.0),
ionpot(0.0),
ionpotlog(-1.0e-10),
bremfactor(0.1)
: G4VRangeToEnergyConverter()
{
theParticle = G4ParticleTable::GetParticleTable()->FindParticle("e+");
if (theParticle ==0) {
theParticle = G4ParticleTable::GetParticleTable()->FindParticle("e+");
if (theParticle == nullptr)
{
#ifdef G4VERBOSE
if (GetVerboseLevel()>0) {
G4cout << " G4RToEConvForPositron::G4RToEConvForPositron() ";
G4cout << " Positron is not defined !!" << G4endl;
if (GetVerboseLevel()>0)
{
G4cout << "G4RToEConvForPositron::G4RToEConvForPositron() - ";
G4cout << "Positron is not defined !!" << G4endl;
}
#endif
} else {
}
else
{
Mass = theParticle->GetPDGMass();
}
}
// --------------------------------------------------------------------
G4RToEConvForPositron::~G4RToEConvForPositron()
{
}
// **********************************************************************
// ************************* ComputeLoss ********************************
// **********************************************************************
G4double G4RToEConvForPositron::ComputeLoss(G4double AtomicNumber,
G4double KineticEnergy)
G4double KineticEnergy)
{
const G4double cbr1=0.02, cbr2=-5.7e-5, cbr3=1., cbr4=0.072;
const G4double Tlow=10.*keV, Thigh=1.*GeV;
const G4double cbr1=0.02, cbr2=-5.7e-5, cbr3=1., cbr4=0.072;
const G4double Tlow=10.*keV, Thigh=1.*GeV;
// calculate dE/dx for electrons
if( std::fabs(AtomicNumber-Z)>0.1 ) {
// calculate dE/dx for electrons
if( std::fabs(AtomicNumber-Z)>0.1 )
{
Z = AtomicNumber;
taul = Tlow/Mass;
ionpot = 1.6e-5*MeV*std::exp(0.9*std::log(Z))/Mass;
@@ -90,39 +85,38 @@ G4double G4RToEConvForPositron::ComputeLoss(G4double AtomicNumber,
G4double tau = KineticEnergy/Mass;
G4double dEdx;
if(tau<taul)
if(tau<taul)
{
G4double t1 = taul+1.;
G4double t2 = taul+2.;
G4double tsq = taul*taul;
G4double beta2 = taul*t2/(t1*t1);
G4double f = 2.*std::log(taul)
-(6.*taul+1.5*tsq-taul*(1.-tsq/3.)/t2-tsq*(0.5-tsq/12.)/
(t2*t2))/(t1*t1);
-(6.*taul+1.5*tsq-taul*(1.-tsq/3.)/t2
-tsq*(0.5-tsq/12.)/(t2*t2))/(t1*t1);
dEdx = (std::log(2.*taul+4.)-2.*ionpotlog+f)/beta2;
dEdx = twopi_mc2_rcl2*Z*dEdx;
G4double clow = dEdx*std::sqrt(taul);
dEdx = clow/std::sqrt(KineticEnergy/Mass);
} else {
G4double t1 = tau+1.;
}
else
{
G4double t1 = tau+1.;
G4double t2 = tau+2.;
G4double tsq = tau*tau;
G4double beta2 = tau*t2/(t1*t1);
G4double f = 2.*std::log(tau)
- (6.*tau+1.5*tsq-tau*(1.-tsq/3.)/t2-tsq*(0.5-tsq/12.)/
(t2*t2))/(t1*t1);
- (6.*tau+1.5*tsq-tau*(1.-tsq/3.)/t2
-tsq*(0.5-tsq/12.)/(t2*t2))/(t1*t1);
dEdx = (std::log(2.*tau+4.)-2.*ionpotlog+f)/beta2;
dEdx = twopi_mc2_rcl2*Z*dEdx;
// loss from bremsstrahlung follows
G4double cbrem = (cbr1+cbr2*Z)
*(cbr3+cbr4*std::log(KineticEnergy/Thigh));
* (cbr3+cbr4*std::log(KineticEnergy/Thigh));
cbrem = Z*(Z+1.)*cbrem*tau/beta2;
cbrem *= bremfactor ;
cbrem *= bremfactor;
dEdx += twopi_mc2_rcl2*cbrem;
}
return dEdx;
}
@@ -23,13 +23,10 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// G4RToEConvForProton class implementation
//
//
//
// --------------------------------------------------------------
// GEANT 4 class implementation file/ History:
// 5 Oct. 2002, H.Kuirashige : Structure created based on object model
// --------------------------------------------------------------
// Author: H.Kurashige, 05 October 2002 - First implementation
// --------------------------------------------------------------------
#include "G4RToEConvForProton.hh"
#include "G4ParticleTable.hh"
@@ -40,50 +37,51 @@
#include "G4PhysicalConstants.hh"
#include "G4SystemOfUnits.hh"
// --------------------------------------------------------------------
G4RToEConvForProton::G4RToEConvForProton()
: G4VRangeToEnergyConverter(),
Mass(0.0),
Z(-1.),
tau0(0.0), taul(0.0), taum(0.0),
ionpot(0.0),
ca(0.0), cba(0.0), cc(0.0)
: G4VRangeToEnergyConverter()
{
theParticle = G4ParticleTable::GetParticleTable()->FindParticle("proton");
if (theParticle ==0) {
theParticle = G4ParticleTable::GetParticleTable()->FindParticle("proton");
if (theParticle == nullptr)
{
#ifdef G4VERBOSE
if (GetVerboseLevel()>0) {
G4cout << " G4RToEConvForProton::G4RToEConvForProton() ";
G4cout << " proton is not defined !!" << G4endl;
if (GetVerboseLevel()>0)
{
G4cout << "G4RToEConvForProton::G4RToEConvForProton() - ";
G4cout << "Proton is not defined !!" << G4endl;
}
#endif
} else {
}
else
{
Mass = theParticle->GetPDGMass();
}
}
// --------------------------------------------------------------------
G4RToEConvForProton::~G4RToEConvForProton()
{
}
// --------------------------------------------------------------------
G4double G4RToEConvForProton::Convert(G4double rangeCut, const G4Material* )
{
// Simple formula
// range = Ekin/(100*keV)*(1*mm);
// Simple formula - range = Ekin/(100*keV)*(1*mm);
return (rangeCut/(1.0*mm)) * (100.0*keV);
}
// **********************************************************************
// ************************* ComputeLoss ********************************
// **********************************************************************
G4double G4RToEConvForProton::ComputeLoss(G4double AtomicNumber,
G4double KineticEnergy)
G4double KineticEnergy)
{
// calculate dE/dx
const G4double z2Particle = 1.0;
const G4double z2Particle = 1.0;
if( std::fabs(AtomicNumber-Z)>0.1 ){
if( std::fabs(AtomicNumber-Z)>0.1 )
{
// recalculate constants
Z = AtomicNumber;
G4double Z13 = std::exp(std::log(Z)/3.);
@@ -91,7 +89,8 @@ G4double G4RToEConvForProton::ComputeLoss(G4double AtomicNumber,
taum = 0.035*Z13*MeV/proton_mass_c2;
taul = 2.*MeV/proton_mass_c2;
ionpot = 1.6e-5*MeV*std::exp(0.9*std::log(Z));
cc = (taul+1.)*(taul+1.)*std::log(2.*electron_mass_c2*taul*(taul+2.)/ionpot)/(taul*(taul+2.))-1.;
cc = (taul+1.)*(taul+1.)*std::log(2.*electron_mass_c2*taul*(taul+2.)/ionpot)
/ (taul*(taul+2.))-1.;
cc = 2.*twopi_mc2_rcl2*Z*cc*std::sqrt(taul);
ca = cc/((1.-0.5*std::sqrt(tau0/taum))*tau0);
cba = -0.5/std::sqrt(taum);
@@ -99,26 +98,33 @@ G4double G4RToEConvForProton::ComputeLoss(G4double AtomicNumber,
G4double tau = KineticEnergy/Mass;
G4double dEdx;
if ( tau <= tau0 ) {
if ( tau <= tau0 )
{
dEdx = ca*(std::sqrt(tau)+cba*tau);
} else {
if( tau <= taul ) {
}
else
{
if( tau <= taul )
{
dEdx = cc/std::sqrt(tau);
} else {
dEdx = (tau+1.)*(tau+1.)*
std::log(2.*electron_mass_c2*tau*(tau+2.)/ionpot)/(tau*(tau+2.))-1.;
}
else
{
dEdx = (tau+1.)*(tau+1.)
* std::log(2.*electron_mass_c2*tau*(tau+2.)/ionpot)
/ (tau*(tau+2.))-1.;
dEdx = 2.*twopi_mc2_rcl2*Z*dEdx;
}
}
return dEdx*z2Particle ;
}
// **********************************************************************
// ************************* Reset ********************************
// **********************************************************************
void G4RToEConvForProton::Reset()
{
// do nothing because loss tables and range vectors are not used
return;
}
@@ -23,13 +23,10 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// G4VRangeToEnergyConverter class implementation
//
//
//
// --------------------------------------------------------------
// GEANT 4 class implementation file/ History:
// 5 Oct. 2002, H.Kuirashige : Structure created based on object model
// --------------------------------------------------------------
// Author: H.Kurashige, 05 October 2002 - First implementation
// --------------------------------------------------------------------
#include "G4VRangeToEnergyConverter.hh"
#include "G4ParticleTable.hh"
@@ -44,32 +41,29 @@ G4double G4VRangeToEnergyConverter::LowestEnergy = 0.99e-3*MeV;
G4double G4VRangeToEnergyConverter::HighestEnergy = 100.0e6*MeV;
G4double G4VRangeToEnergyConverter::MaxEnergyCut = 10.0*GeV;
G4VRangeToEnergyConverter::G4VRangeToEnergyConverter():
theParticle(0), theLossTable(0), NumberOfElements(0), TotBin(300),
verboseLevel(1)
// --------------------------------------------------------------------
G4VRangeToEnergyConverter::G4VRangeToEnergyConverter()
{
fMaxEnergyCut = 0.;
}
G4VRangeToEnergyConverter::G4VRangeToEnergyConverter(const G4VRangeToEnergyConverter& right) : theParticle(right.theParticle), theLossTable(0), TotBin(right.TotBin)
// --------------------------------------------------------------------
G4VRangeToEnergyConverter::
G4VRangeToEnergyConverter(const G4VRangeToEnergyConverter& right)
{
fMaxEnergyCut = 0.;
if (theLossTable) {
theLossTable->clearAndDestroy();
delete theLossTable;
theLossTable=0;
}
*this = right;
}
G4VRangeToEnergyConverter & G4VRangeToEnergyConverter::operator=(const G4VRangeToEnergyConverter &right)
// --------------------------------------------------------------------
G4VRangeToEnergyConverter&
G4VRangeToEnergyConverter::operator=(const G4VRangeToEnergyConverter& right)
{
if (this == &right) return *this;
if (theLossTable) {
if (theLossTable != nullptr)
{
theLossTable->clearAndDestroy();
delete theLossTable;
theLossTable=0;
}
}
fMaxEnergyCut = right.fMaxEnergyCut;
NumberOfElements = right.NumberOfElements;
@@ -80,9 +74,11 @@ G4VRangeToEnergyConverter & G4VRangeToEnergyConverter::operator=(const G4VRangeT
theLossTable = new G4LossTable();
theLossTable->reserve(G4Element::GetNumberOfElements());
// fill the loss table
for (size_t j=0; j<size_t(NumberOfElements); j++){
G4LossVector* aVector = new G4LossVector(LowestEnergy, MaxEnergyCut, TotBin);
for (size_t i=0; i<=size_t(TotBin); i++) {
for (std::size_t j=0; j<std::size_t(NumberOfElements); ++j)
{
G4LossVector* aVector = new G4LossVector(LowestEnergy,MaxEnergyCut,TotBin);
for (std::size_t i=0; i<=std::size_t(TotBin); ++i)
{
G4double Value = (*((*right.theLossTable)[j]))[i];
aVector->PutValue(i,Value);
}
@@ -90,21 +86,25 @@ G4VRangeToEnergyConverter & G4VRangeToEnergyConverter::operator=(const G4VRangeT
}
// clean up range vector store
for (size_t idx=0; idx<fRangeVectorStore.size(); idx++){
for (std::size_t idx=0; idx<fRangeVectorStore.size(); ++idx)
{
delete fRangeVectorStore.at(idx);
}
fRangeVectorStore.clear();
// copy range vector store
for (size_t j=0; j<((right.fRangeVectorStore).size()); j++){
for (std::size_t j=0; j<((right.fRangeVectorStore).size()); ++j)
{
G4RangeVector* vector = (right.fRangeVectorStore).at(j);
G4RangeVector* rangeVector = 0;
if (vector !=0 ) {
G4RangeVector* rangeVector = nullptr;
if (vector != nullptr )
{
rangeVector = new G4RangeVector(LowestEnergy, MaxEnergyCut, TotBin);
fMaxEnergyCut = MaxEnergyCut;
for (size_t i=0; i<=size_t(TotBin); i++) {
G4double Value = (*vector)[i];
rangeVector->PutValue(i,Value);
for (std::size_t i=0; i<=std::size_t(TotBin); ++i)
{
G4double Value = (*vector)[i];
rangeVector->PutValue(i,Value);
}
}
fRangeVectorStore.push_back(rangeVector);
@@ -112,54 +112,47 @@ G4VRangeToEnergyConverter & G4VRangeToEnergyConverter::operator=(const G4VRangeT
return *this;
}
// --------------------------------------------------------------------
G4VRangeToEnergyConverter::~G4VRangeToEnergyConverter()
{
Reset();
// Comment out Reset() for MT application
/////MA // delete loss table without deleteing vectors
/////MA if (theLossTable) {
/////MA delete theLossTable;
/////MA }
/////MA theLossTable=0;
/////MA NumberOfElements=0;
/////MA
/////MA //clear RangeVectorStore without deleteing vectors
/////MA fRangeVectorStore.clear();
}
G4bool G4VRangeToEnergyConverter::operator==(const G4VRangeToEnergyConverter &right) const
// --------------------------------------------------------------------
G4bool
G4VRangeToEnergyConverter::operator==(const G4VRangeToEnergyConverter& r) const
{
return this == &right;
return this == &r;
}
G4bool G4VRangeToEnergyConverter::operator!=(const G4VRangeToEnergyConverter &right) const
// --------------------------------------------------------------------
G4bool
G4VRangeToEnergyConverter::operator!=(const G4VRangeToEnergyConverter &r) const
{
return this != &right;
return this != &r;
}
// **********************************************************************
// ************************* Convert ***********************************
// **********************************************************************
G4double G4VRangeToEnergyConverter::Convert(G4double rangeCut,
const G4Material* material)
const G4Material* material)
{
#ifdef G4VERBOSE
if (GetVerboseLevel()>3) {
G4cout << "G4VRangeToEnergyConverter::Convert() ";
if (GetVerboseLevel()>3)
{
G4cout << "G4VRangeToEnergyConverter::Convert() - ";
G4cout << "Convert for " << material->GetName()
<< " with Range Cut " << rangeCut/mm << "[mm]" << G4endl;
<< " with Range Cut " << rangeCut/mm << "[mm]" << G4endl;
}
#endif
G4double theKineticEnergyCuts = 0.;
if (fMaxEnergyCut != MaxEnergyCut) {
if (fMaxEnergyCut != MaxEnergyCut)
{
fMaxEnergyCut = MaxEnergyCut;
// clear loss table and renge vectors
// clear loss table and range vectors
Reset();
}
@@ -168,30 +161,33 @@ G4double G4VRangeToEnergyConverter::Convert(G4double rangeCut,
// Build range vector for every material, convert cut into energy-cut,
// fill theKineticEnergyCuts and delete the range vector
static const G4double tune = 0.025*mm*g/cm3 ,lowen = 30.*keV ;
static const G4double tune = 0.025*mm*g/cm3, lowen = 30.*keV ;
// check density
G4double density = material->GetDensity() ;
if(density <= 0.) {
if(density <= 0.)
{
#ifdef G4VERBOSE
if (GetVerboseLevel()>0) {
G4cout << "G4VRangeToEnergyConverter::Convert() ";
if (GetVerboseLevel()>0)
{
G4cout << "G4VRangeToEnergyConverter::Convert() - ";
G4cout << material->GetName() << "has zero density "
<< "( " << density << ")" << G4endl;
<< "( " << density << ")" << G4endl;
}
#endif
return 0.;
}
// initialize RangeVectorStore
// initialise RangeVectorStore
const G4MaterialTable* table = G4Material::GetMaterialTable();
G4int ext_size = table->size() - fRangeVectorStore.size();
for (int i=0; i<ext_size; i++) fRangeVectorStore.push_back(0);
for (G4int i=0; i<ext_size; ++i) fRangeVectorStore.push_back(nullptr);
// Build Range Vector
G4int idx = material->GetIndex();
G4RangeVector* rangeVector = fRangeVectorStore.at(idx);
if (rangeVector == 0) {
if (rangeVector == nullptr)
{
rangeVector = new G4RangeVector(LowestEnergy, MaxEnergyCut, TotBin);
BuildRangeVector(material, rangeVector);
fRangeVectorStore.at(idx) = rangeVector;
@@ -200,16 +196,21 @@ G4double G4VRangeToEnergyConverter::Convert(G4double rangeCut,
// Convert Range Cut ro Kinetic Energy Cut
theKineticEnergyCuts = ConvertCutToKineticEnergy(rangeVector, rangeCut, idx);
if( ((theParticle->GetParticleName()=="e-")||(theParticle->GetParticleName()=="e+"))
&& (theKineticEnergyCuts < lowen) ) {
if( ((theParticle->GetParticleName()=="e-")
||(theParticle->GetParticleName()=="e+"))
&&(theKineticEnergyCuts < lowen) )
{
// corr. should be switched on smoothly
theKineticEnergyCuts /= (1.+(1.-theKineticEnergyCuts/lowen)*
tune/(rangeCut*density));
theKineticEnergyCuts /= (1.+(1.-theKineticEnergyCuts/lowen)
* tune/(rangeCut*density));
}
if(theKineticEnergyCuts < LowestEnergy) {
theKineticEnergyCuts = LowestEnergy ;
} else if(theKineticEnergyCuts > MaxEnergyCut) {
if(theKineticEnergyCuts < LowestEnergy)
{
theKineticEnergyCuts = LowestEnergy;
}
else if(theKineticEnergyCuts > MaxEnergyCut)
{
theKineticEnergyCuts = MaxEnergyCut;
}
@@ -220,31 +221,33 @@ G4double G4VRangeToEnergyConverter::Convert(G4double rangeCut,
// ************************ SetEnergyRange *****************************
// **********************************************************************
void G4VRangeToEnergyConverter::SetEnergyRange(G4double lowedge,
G4double highedge)
G4double highedge)
{
// check LowestEnergy/ HighestEnergy
if ( (lowedge<0.0)||(highedge<=lowedge) ){
if ( (lowedge<0.0)||(highedge<=lowedge) )
{
#ifdef G4VERBOSE
G4cerr << "Error in G4VRangeToEnergyConverter::SetEnergyRange";
G4cerr << " : illegal energy range" << "(" << lowedge/GeV;
G4cerr << "Error in G4VRangeToEnergyConverter::SetEnergyRange()";
G4cerr << ": illegal energy range" << "(" << lowedge/GeV;
G4cerr << "," << highedge/GeV << ") [GeV]" << G4endl;
#endif
G4Exception( "G4VRangeToEnergyConverter::SetEnergyRange()",
"ProcCuts101",
JustWarning, "Illegal energy range ");
} else {
"ProcCuts101", JustWarning, "Illegal energy range");
}
else
{
LowestEnergy = lowedge;
HighestEnergy = highedge;
}
}
// --------------------------------------------------------------------
G4double G4VRangeToEnergyConverter::GetLowEdgeEnergy()
{
return LowestEnergy;
}
// --------------------------------------------------------------------
G4double G4VRangeToEnergyConverter::GetHighEdgeEnergy()
{
return HighestEnergy;
@@ -258,6 +261,7 @@ G4double G4VRangeToEnergyConverter::GetMaxEnergyCut()
return MaxEnergyCut;
}
// --------------------------------------------------------------------
void G4VRangeToEnergyConverter::SetMaxEnergyCut(G4double value)
{
MaxEnergyCut = value;
@@ -269,29 +273,31 @@ void G4VRangeToEnergyConverter::SetMaxEnergyCut(G4double value)
void G4VRangeToEnergyConverter::Reset()
{
// delete loss table
if (theLossTable) {
if (theLossTable != nullptr)
{
theLossTable->clearAndDestroy();
delete theLossTable;
}
theLossTable=0;
NumberOfElements=0;
theLossTable = nullptr;
NumberOfElements = 0;
//clear RangeVectorStore
for (size_t idx=0; idx<fRangeVectorStore.size(); idx++){
// clear RangeVectorStore
for (std::size_t idx=0; idx<fRangeVectorStore.size(); ++idx)
{
delete fRangeVectorStore.at(idx);
}
fRangeVectorStore.clear();
}
// **********************************************************************
// ************************ BuildLossTable ******************************
// **********************************************************************
// create Energy Loss Table for charged particles
// (cross section tabel for neutral )
void G4VRangeToEnergyConverter::BuildLossTable()
{
if (size_t(NumberOfElements) == G4Element::GetNumberOfElements()) return;
// Create Energy Loss Table for charged particles
// (cross-section table for neutral)
if (std::size_t(NumberOfElements) == G4Element::GetNumberOfElements()) return;
// clear Loss table and Range vectors
Reset();
@@ -301,23 +307,24 @@ void G4VRangeToEnergyConverter::BuildLossTable()
theLossTable = new G4LossTable();
theLossTable->reserve(G4Element::GetNumberOfElements());
#ifdef G4VERBOSE
if (GetVerboseLevel()>3) {
G4cout << "G4VRangeToEnergyConverter::BuildLossTable() ";
if (GetVerboseLevel()>3)
{
G4cout << "G4VRangeToEnergyConverter::BuildLossTable() - ";
G4cout << "Create theLossTable[" << theLossTable << "]";
G4cout << " NumberOfElements=" << NumberOfElements <<G4endl;
G4cout << " NumberOfElements=" << NumberOfElements << G4endl;
}
#endif
// fill the loss table
for (size_t j=0; j<size_t(NumberOfElements); j++){
for (std::size_t j=0; j<std::size_t(NumberOfElements); ++j)
{
G4double Value;
G4LossVector* aVector= 0;
aVector= new G4LossVector(LowestEnergy, MaxEnergyCut, TotBin);
for (size_t i=0; i<=size_t(TotBin); i++) {
Value = ComputeLoss( (*G4Element::GetElementTable())[j]->GetZ(),
aVector->Energy(i)
);
G4LossVector* aVector = nullptr;
aVector = new G4LossVector(LowestEnergy, MaxEnergyCut, TotBin);
for (std::size_t i=0; i<=std::size_t(TotBin); ++i)
{
Value = ComputeLoss( (*G4Element::GetElementTable())[j]->GetZ(),
aVector->Energy(i) );
aVector->PutValue(i,Value);
}
theLossTable->insert(aVector);
@@ -328,44 +335,54 @@ void G4VRangeToEnergyConverter::BuildLossTable()
// ************************ BuildRangeVector ****************************
// **********************************************************************
void G4VRangeToEnergyConverter::BuildRangeVector(const G4Material* aMaterial,
G4PhysicsLogVector* rangeVector)
G4PhysicsLogVector* rangeVector)
{
// create range vector for a material
const G4ElementVector* elementVector = aMaterial->GetElementVector();
const G4double* atomicNumDensityVector = aMaterial->GetAtomicNumDensityVector();
const G4ElementVector* elementVector
= aMaterial->GetElementVector();
const G4double* atomicNumDensityVector
= aMaterial->GetAtomicNumDensityVector();
G4int NumEl = aMaterial->GetNumberOfElements();
// calculate parameters of the low energy part first
size_t i;
std::size_t i;
std::vector<G4double> lossV;
for ( size_t ib=0; ib<=size_t(TotBin); ib++) {
for ( std::size_t ib=0; ib<=std::size_t(TotBin); ++ib)
{
G4double loss=0.;
for (i=0; i<size_t(NumEl); i++) {
for (i=0; i<std::size_t(NumEl); ++i)
{
G4int IndEl = (*elementVector)[i]->GetIndex();
loss += atomicNumDensityVector[i]*
(*((*theLossTable)[IndEl]))[ib];
(*((*theLossTable)[IndEl]))[ib];
}
lossV.push_back(loss);
}
// Integrate with Simpson formula with logarithmic binning
G4double dltau = 1.0;
if (LowestEnergy>0.) {
G4double ltt =std::log(MaxEnergyCut/LowestEnergy);
dltau = ltt/TotBin;
if (LowestEnergy>0.)
{
G4double ltt =std::log(MaxEnergyCut/LowestEnergy);
dltau = ltt/TotBin;
}
G4double s0 = 0.;
G4double Value;
for ( i=0; i<=size_t(TotBin); i++) {
for ( i=0; i<=std::size_t(TotBin); ++i )
{
G4double t = rangeVector->GetLowEdgeEnergy(i);
G4double q = t/lossV[i];
if (i==0) s0 += 0.5*q;
else s0 += q;
if (i==0) {
Value = (s0 + 0.5*q)*dltau ;
} else {
if (i==0)
{
Value = (s0 + 0.5*q)*dltau ;
}
else
{
Value = (s0 - 0.5*q)*dltau ;
}
rangeVector->PutValue(i,Value);
@@ -376,18 +393,18 @@ void G4VRangeToEnergyConverter::BuildRangeVector(const G4Material* aMaterial,
// ****************** ConvertCutToKineticEnergy *************************
// **********************************************************************
G4double G4VRangeToEnergyConverter::ConvertCutToKineticEnergy(
G4RangeVector* rangeVector,
G4double theCutInLength,
G4RangeVector* rangeVector,
G4double theCutInLength,
#ifdef G4VERBOSE
size_t materialIndex
std::size_t materialIndex
#else
size_t
std::size_t
#endif
) const
) const
{
const G4double epsilon=0.01;
const G4double epsilon = 0.01;
// find max. range and the corresponding energy (rmax,Tmax)
// find max. range and the corresponding energy (rmax,Tmax)
G4double rmax= -1.e10*mm;
G4double T1 = LowestEnergy;
@@ -400,23 +417,29 @@ G4double G4VRangeToEnergyConverter::ConvertCutToKineticEnergy(
// scan range vector to find nearest bin
// ( suppose that r(Ti) > r(Tj) if Ti >Tj )
for (size_t ibin=0; ibin<=size_t(TotBin); ibin++) {
for (std::size_t ibin=0; ibin<=std::size_t(TotBin); ++ibin)
{
G4double T=rangeVector->GetLowEdgeEnergy(ibin);
G4double r=(*rangeVector)[ibin];
if ( r>rmax ) rmax=r;
if (r <theCutInLength ) {
if (r <theCutInLength )
{
T1 = T;
r1 = r;
} else if (r >theCutInLength ) {
}
else if (r >theCutInLength )
{
T2 = T;
break;
}
}
// check cut in length is smaller than range max
if ( theCutInLength >= rmax ) {
if ( theCutInLength >= rmax )
{
#ifdef G4VERBOSE
if (GetVerboseLevel()>2) {
if (GetVerboseLevel()>2)
{
G4cout << "G4VRangeToEnergyConverter::ConvertCutToKineticEnergy ";
G4cout << " for " << theParticle->GetParticleName() << G4endl;
G4cout << "The cut in range [" << theCutInLength/mm << " (mm)] ";
@@ -430,18 +453,20 @@ G4double G4VRangeToEnergyConverter::ConvertCutToKineticEnergy(
// convert range to energy
G4double T3 = std::sqrt(T1*T2);
G4double r3 = rangeVector->Value(T3);
const size_t MAX_LOOP = 1000;
for (size_t loop_count=0; loop_count<MAX_LOOP; ++loop_count){
const std::size_t MAX_LOOP = 1000;
for (std::size_t loop_count=0; loop_count<MAX_LOOP; ++loop_count)
{
if (std::fabs(1.-r3/theCutInLength)<epsilon ) break;
if ( theCutInLength <= r3 ) {
if ( theCutInLength <= r3 )
{
T2 = T3;
} else {
}
else
{
T1 = T3;
}
T3 = std::sqrt(T1*T2);
r3 = rangeVector->Value(T3);
}
return T3;
}