Import Geant4 11.3.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2024-06-28 13:08:51 +02:00
parent f7b23877ed
commit e58e650b32
5232 changed files with 239416 additions and 244360 deletions
@@ -41,6 +41,7 @@
//
#include "G4EmDataHandler.hh"
#include "G4EmDataRegistry.hh"
#include "G4ParticleDefinition.hh"
#include "G4EmParameters.hh"
#include "G4PhysicsTableHelper.hh"
@@ -49,27 +50,43 @@
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4EmDataHandler::G4EmDataHandler(size_t n) : tLength(n)
G4EmDataHandler::G4EmDataHandler(std::size_t n, const G4String& nam)
: tLength(n), fName(nam)
{
data.resize(n, nullptr);
fMaxXS = new std::vector<G4double>;
fXSpeaks = new std::vector<G4TwoPeaksXS*>;
G4EmDataRegistry::Instance()->Register(this);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4EmDataHandler::~G4EmDataHandler()
{
for(size_t i=0; i<tLength; ++i) {
for(size_t j = i+1; j<tLength; ++j) {
if(data[j] == data[i]) { data[j] = nullptr; }
if (!fUseBaseParticleTable) {
for (std::size_t i=0; i<tLength; ++i) {
CleanTable(i);
}
CleanTable(i);
delete fMaxXS;
delete fXSpeaks;
}
if (!fElemSelectors.empty()) {
for (auto const & ptr : fElemSelectors) {
if (nullptr != ptr) {
for (auto const & p : *ptr) { delete p; }
}
}
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
size_t G4EmDataHandler::SetTable(G4PhysicsTable* ptr)
std::size_t G4EmDataHandler::SetTable(G4PhysicsTable* ptr)
{
for (std::size_t i=0; i<tLength; ++i) {
if (ptr == data[i]) { return i; }
}
data.push_back(ptr);
++tLength;
return tLength-1;
@@ -77,11 +94,12 @@ size_t G4EmDataHandler::SetTable(G4PhysicsTable* ptr)
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void G4EmDataHandler::UpdateTable(G4PhysicsTable* ptr, size_t idx)
void G4EmDataHandler::UpdateTable(G4PhysicsTable* ptr, std::size_t idx)
{
// update table pointer but not delete previous
if(idx < tLength) {
if(ptr != data[idx]) { data[idx] = ptr; }
if (idx < tLength) {
if (ptr != data[idx]) { data[idx] = ptr; }
data[idx] = G4PhysicsTableHelper::PreparePhysicsTable(data[idx]);
} else {
G4cout << "### G4EmDataHandler::UpdateTable fail for idx=" << idx
<< " length=" << tLength << G4endl;
@@ -90,10 +108,19 @@ void G4EmDataHandler::UpdateTable(G4PhysicsTable* ptr, size_t idx)
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4PhysicsTable* G4EmDataHandler::MakeTable(size_t i)
void G4EmDataHandler::SaveTable(G4PhysicsTable* ptr, std::size_t idx)
{
size_t idx = i;
if(idx >= tLength) {
if (idx < tLength) {
data[idx] = ptr;
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4PhysicsTable* G4EmDataHandler::MakeTable(std::size_t i)
{
std::size_t idx = i;
if (idx >= tLength) {
data.push_back(nullptr);
idx = tLength;
++tLength;
@@ -104,13 +131,13 @@ G4PhysicsTable* G4EmDataHandler::MakeTable(size_t i)
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4PhysicsTable* G4EmDataHandler::MakeTable(G4PhysicsTable* ptr, size_t i)
G4PhysicsTable* G4EmDataHandler::MakeTable(G4PhysicsTable* ptr, std::size_t i)
{
size_t idx = i;
std::size_t idx = i;
// create new table only if index corresponds to the
// position in the vector
if(idx < tLength) {
if(ptr != data[idx]) {
if (idx < tLength) {
if (ptr != data[idx]) {
CleanTable(idx);
data[idx] = ptr;
}
@@ -119,24 +146,27 @@ G4PhysicsTable* G4EmDataHandler::MakeTable(G4PhysicsTable* ptr, size_t i)
idx = tLength;
++tLength;
}
data[idx] = G4PhysicsTableHelper::PreparePhysicsTable(ptr);
data[idx] = G4PhysicsTableHelper::PreparePhysicsTable(data[idx]);
return data[idx];
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void G4EmDataHandler::CleanTable(size_t i)
void G4EmDataHandler::CleanTable(std::size_t i)
{
if(i < tLength && nullptr != data[i]) {
data[i]->clearAndDestroy();
delete data[i];
data[i] = nullptr;
if (i < tLength && nullptr != data[i]) {
auto ptr = data[i];
ptr->clearAndDestroy();
delete ptr;
for (std::size_t j=0; j<tLength; ++j) {
if (ptr == data[j]) { data[j] = nullptr; }
}
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4bool G4EmDataHandler::StorePhysicsTable(size_t idx,
G4bool G4EmDataHandler::StorePhysicsTable(std::size_t idx,
const G4ParticleDefinition* part,
const G4String& fname,
G4bool ascii)
@@ -160,7 +190,7 @@ G4bool G4EmDataHandler::StorePhysicsTable(size_t idx,
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4bool G4EmDataHandler::RetrievePhysicsTable(size_t idx,
G4bool G4EmDataHandler::RetrievePhysicsTable(std::size_t idx,
const G4ParticleDefinition* part,
const G4String& fname,
G4bool ascii, G4bool spline)
@@ -192,9 +222,25 @@ void G4EmDataHandler::SetMasterProcess(const G4VEmProcess* ptr)
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
const G4VEmProcess* G4EmDataHandler::GetMasterProcess(size_t idx) const
const G4VEmProcess* G4EmDataHandler::GetMasterProcess(std::size_t idx) const
{
return (idx < masterProcess.size()) ? masterProcess[idx] : nullptr;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void G4EmDataHandler::SetElementSelectors(std::vector<G4EmElementSelector*>* p,
std::size_t i)
{
if (i < eLength) {
if (fElemSelectors[i] != p) {
delete fElemSelectors[i];
}
fElemSelectors[i] = p;
} else {
fElemSelectors.push_back(p);
++eLength;
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,113 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * 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. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//---------------------------------------------------------------------------
//
// GEANT4 Class file
//
// Author: V.Ivanchenko 18.04.2024
//
//----------------------------------------------------------------------------
#include "G4EmDataRegistry.hh"
#include "G4AutoLock.hh"
G4EmDataRegistry* G4EmDataRegistry::instance = nullptr;
namespace
{
G4Mutex theEmData = G4MUTEX_INITIALIZER;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
G4EmDataRegistry* G4EmDataRegistry::Instance()
{
if (instance == nullptr) {
static G4EmDataRegistry manager;
instance = &manager;
}
return instance;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4EmDataRegistry::G4EmDataRegistry()
{
fDataHandlers.reserve(50);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4EmDataRegistry::~G4EmDataRegistry()
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4EmDataHandler*
G4EmDataRegistry::GetHandlerByName(const G4String& nam, std::size_t n)
{
// handler already exist
G4EmDataHandler* ptr = EmDataHandler(nam);
if (nullptr != ptr) { return ptr; }
// create a new handler
G4AutoLock l(&theEmData);
ptr = EmDataHandler(nam);
if (nullptr == ptr) {
ptr = new G4EmDataHandler(n, nam);
}
l.unlock();
return ptr;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void G4EmDataRegistry::Register(G4EmDataHandler* ptr)
{
if (nullptr == ptr) { return; }
for (auto const & p : fDataHandlers) {
if (p == ptr) { return; }
}
fDataHandlers.push_back(ptr);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4EmDataHandler* G4EmDataRegistry::EmDataHandler(const G4String& nam)
{
G4EmDataHandler* ptr = nullptr;
if (fDataHandlers.empty()) { return ptr; }
for (auto const & p : fDataHandlers) {
if (p->GetName() == nam) {
ptr = p;
break;
}
}
return ptr;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -76,6 +76,7 @@ void G4EmLowEParameters::Initialise()
dnaStationary = false;
dnaMsc = false;
dnaElectronSolvation = fMeesungnoen2002eSolvation;
fTimeStepModel = G4ChemTimeStepModel::Unknown;
fFluoDirectory = fluoDefault;
namePIXE = "Empirical";
@@ -195,6 +196,16 @@ G4DNAModelSubType G4EmLowEParameters::DNAeSolvationSubType() const
return dnaElectronSolvation;
}
void G4EmLowEParameters::SetChemTimeStepModel(G4ChemTimeStepModel val)
{
fTimeStepModel = val;
}
G4ChemTimeStepModel G4EmLowEParameters::GetChemTimeStepModel() const
{
return fTimeStepModel;
}
void G4EmLowEParameters::SetPIXECrossSectionModel(const G4String& sss)
{
namePIXE = sss;
@@ -51,7 +51,6 @@
#include "G4UIcmdWith3VectorAndUnit.hh"
#include "G4UImanager.hh"
#include "G4EmLowEParameters.hh"
#include <sstream>
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
@@ -164,6 +163,13 @@ G4EmLowEParametersMessenger::G4EmLowEParametersMessenger(G4EmLowEParameters* ptr
dnaSolCmd->AvailableForStates(G4State_PreInit);
dnaSolCmd->SetToBeBroadcasted(false);
dnaChemModel = new G4UIcmdWithAString("/process/chem/TimeStepModel",this);
dnaChemModel->SetGuidance("The name of DNA chemistry time step model");
dnaChemModel->SetParameterName("TimeStepModel",true);
dnaChemModel->SetCandidates("SBS IRT IRT_syn");
dnaChemModel->AvailableForStates(G4State_PreInit);
dnaChemModel->SetToBeBroadcasted(false);
meCmd = new G4UIcmdWithAString("/process/em/AddMicroElecRegion",this);
meCmd->SetGuidance("Activate MicroElec model in the G4Region");
meCmd->SetParameterName("MicroElec",true);
@@ -225,6 +231,7 @@ G4EmLowEParametersMessenger::~G4EmLowEParametersMessenger()
delete pixeeXsCmd;
delete livCmd;
delete dnaSolCmd;
delete dnaChemModel;
delete direFluoCmd;
delete meCmd;
delete dnaCmd;
@@ -278,6 +285,16 @@ void G4EmLowEParametersMessenger::SetNewValue(G4UIcommand* command,
ttt = fKreipl2009eSolvation;
}
theParameters->SetDNAeSolvationSubType(ttt);
} else if (command == dnaChemModel) {
G4ChemTimeStepModel stepM = G4ChemTimeStepModel::Unknown;
if(newValue == "IRT") {
stepM = G4ChemTimeStepModel::IRT;
} else if(newValue == "SBS") {
stepM = G4ChemTimeStepModel::SBS;
} else if (newValue == "IRT_syn") {
stepM = G4ChemTimeStepModel::IRT_syn;
}
theParameters->SetChemTimeStepModel(stepM);
} else if (command == direFluoCmd) {
G4EmFluoDirectory ttt = fluoDefault;
if(newValue == "Bearden") { ttt = fluoBearden; }
@@ -160,6 +160,7 @@ void G4EmParameters::Initialise()
safetyFactor = 0.6;
lambdaLimit = 1.0*CLHEP::mm;
factorScreen = 1.0;
fOrtoPsFraction = 0.0375; // 0.75 * 0.05
nbinsPerDecade = 7;
verbose = 1;
@@ -174,7 +175,14 @@ void G4EmParameters::Initialise()
fSStype = fWVI;
fFluct = fUniversalFluctuation;
fDirLEDATA = G4String(G4FindDataDir("G4LEDATA"));
const char* data_dir = G4FindDataDir("G4LEDATA");
if (nullptr != data_dir) {
fDirLEDATA = G4String(data_dir);
}
else {
G4Exception("G4EmParameters::Initialise()", "em0003", JustWarning,
"G4LEDATA data directory was not found.");
}
}
void G4EmParameters::SetLossFluctuations(G4bool val)
@@ -582,13 +590,13 @@ G4double G4EmParameters::MinKinEnergy() const
void G4EmParameters::SetMaxEnergy(G4double val)
{
if(IsLocked()) { return; }
if(val > std::max(minKinEnergy,9.99*CLHEP::MeV) && val < 1.e+7*CLHEP::TeV) {
if(val > std::max(minKinEnergy,599.9*CLHEP::MeV) && val < 1.e+7*CLHEP::TeV) {
maxKinEnergy = val;
} else {
G4ExceptionDescription ed;
ed << "Value of MaxKinEnergy is out of range: "
<< val/CLHEP::GeV
<< " GeV is ignored; allowed range 10 MeV - 1.e+7 TeV";
<< " GeV is ignored; allowed range 600 MeV - 1.e+7 TeV";
PrintWarning(ed);
}
}
@@ -1032,6 +1040,29 @@ G4EmFluctuationType G4EmParameters::FluctuationType() const
return fFluct;
}
void G4EmParameters::SetPositronAtRestModelType(G4PositronAtRestModelType val)
{
if(IsLocked()) { return; }
fPositronium = val;
}
G4PositronAtRestModelType G4EmParameters::PositronAtRestModelType() const
{
return fPositronium;
}
void G4EmParameters::SetOrtoPsFraction(G4double val)
{
if(IsLocked()) { return; }
fOrtoPsFraction = val;
}
G4double G4EmParameters::OrtoPsFraction() const
{
return fOrtoPsFraction;
}
void G4EmParameters::SetMscStepLimitType(G4MscStepLimitType val)
{
if(IsLocked()) { return; }
@@ -1453,6 +1484,13 @@ void G4EmParameters::StreamInfo(std::ostream& os) const
<< fCParameters->DNAElectronMsc() << "\n";
os << "Use DNA e- solvation model type "
<< fCParameters->DNAeSolvationSubType() << "\n";
auto chemModel = fCParameters->GetChemTimeStepModel();
if(fCParameters->GetChemTimeStepModel() != G4ChemTimeStepModel::Unknown)
{
std::vector<G4String> ChemModel{"Unknown","SBS","IRT","IRT_syn"};
os << "Use DNA Chemistry model "
<< ChemModel.at((std::size_t)chemModel) << "\n";
}
os << "=======================================================================" << G4endl;
}
os.precision(prec);
@@ -1485,4 +1523,14 @@ G4bool G4EmParameters::IsLocked() const
fStateManager->GetCurrentState() != G4State_Idle));
}
void G4EmParameters::SetTimeStepModel(const G4ChemTimeStepModel& model)
{
fCParameters-> SetChemTimeStepModel(model);
}
G4ChemTimeStepModel G4EmParameters::GetTimeStepModel() const
{
return fCParameters->GetChemTimeStepModel();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
@@ -438,6 +438,20 @@ G4EmParametersMessenger::G4EmParametersMessenger(G4EmParameters* ptr)
fluc1Cmd->AvailableForStates(G4State_PreInit);
fluc1Cmd->SetToBeBroadcasted(false);
posiCmd = new G4UIcmdWithAString("/process/em/setPositronAtRestModel",this);
posiCmd->SetGuidance("Define model of positron annihilation at rest");
posiCmd->SetParameterName("Posi",true);
posiCmd->SetCandidates("Simple Allison");
posiCmd->AvailableForStates(G4State_PreInit);
posiCmd->SetToBeBroadcasted(false);
ortoCmd = new G4UIcmdWithADouble("/process/em/setOrtoPositronFraction",this);
ortoCmd->SetGuidance("Define model of positron annihilation at rest");
ortoCmd->SetParameterName("frac",false);
ortoCmd->SetRange("frac >= 0.0 && frac <= 1.0");
ortoCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
ortoCmd->SetToBeBroadcasted(false);
tripletCmd = new G4UIcmdWithAnInteger("/process/gconv/conversionType",this);
tripletCmd->SetGuidance("gamma conversion triplet/nuclear generation type:");
tripletCmd->SetGuidance("0 - (default) both triplet and nuclear");
@@ -526,6 +540,8 @@ G4EmParametersMessenger::~G4EmParametersMessenger()
delete nffCmd;
delete ssCmd;
delete fluc1Cmd;
delete posiCmd;
delete ortoCmd;
delete dumpCmd;
}
@@ -715,6 +731,12 @@ void G4EmParametersMessenger::SetNewValue(G4UIcommand* command,
if(newValue == "Dummy") { x = fDummyFluctuation; }
else if(newValue == "Urban") { x = fUrbanFluctuation; }
theParameters->SetFluctuationType(x);
} else if (command == posiCmd) {
G4PositronAtRestModelType x = fSimplePositronium;
if(newValue == "Allison") { x = fAllisonPositronium; }
theParameters->SetPositronAtRestModelType(x);
} else if ( command==ortoCmd ) {
theParameters->SetOrtoPsFraction(ortoCmd->GetNewDoubleValue(newValue));
} else if ( command==tripletCmd ) {
theParameters->SetConversionType(tripletCmd->GetNewIntValue(newValue));
} else if ( command==onIsolatedCmd ) {
@@ -66,7 +66,6 @@ G4EmTableUtil::PrepareEmProcess(G4VEmProcess* proc,
G4VEmModel* mod = modelManager->GetModel(i);
if(nullptr == mod) { continue; }
mod->SetPolarAngleLimit(plimit);
mod->SetMasterThread(master);
if(mod->HighEnergyLimit() > maxKinEnergy) {
mod->SetHighEnergyLimit(maxKinEnergy);
}
@@ -248,7 +247,7 @@ void G4EmTableUtil::BuildLambdaTable(G4VEmProcess* proc,
G4PhysicsTableHelper::SetPhysicsVector(theLambdaTable, i, aVector);
}
// build high energy table
if(nullptr != theLambdaTablePrim) {
if(nullptr != theLambdaTablePrim && minKinEnergyPrim < maxKinEnergy) {
delete (*theLambdaTablePrim)[i];
// start not from zero and always use spline
@@ -352,7 +351,7 @@ G4EmTableUtil::CheckIon(G4VEnergyLossProcess* proc,
if(part->GetParticleType() == "nucleus") {
G4String pname = part->GetParticleName();
if(pname != "deuteron" && pname != "triton" &&
pname != "alpha+" && pname != "alpha") {
pname != "He3" && pname != "alpha+" && pname != "alpha") {
const G4ParticleDefinition* theGIon = G4GenericIon::GenericIon();
isIon = true;
@@ -383,7 +382,7 @@ void G4EmTableUtil::UpdateModels(G4VEnergyLossProcess* proc,
const G4int nModels,
G4int& secID, G4int& biasID,
G4int& mainSec, const G4bool baseMat,
const G4bool isMaster, const G4bool useAGen)
const G4bool, const G4bool useAGen)
{
// defined ID of secondary particles
G4int stype = proc->GetProcessSubType();
@@ -398,7 +397,6 @@ void G4EmTableUtil::UpdateModels(G4VEnergyLossProcess* proc,
// initialisation of models
for(G4int i=0; i<nModels; ++i) {
G4VEmModel* mod = modelManager->GetModel(i);
mod->SetMasterThread(isMaster);
mod->SetAngularGeneratorFlag(useAGen);
if(mod->HighEnergyLimit() > maxKinEnergy) {
mod->SetHighEnergyLimit(maxKinEnergy);
@@ -546,7 +544,6 @@ void G4EmTableUtil::PrepareMscProcess(G4VMultipleScattering* proc,
for(G4int i=0; i<numberOfModels; ++i) {
G4VMscModel* msc = proc->GetModelByIndex(i);
msc->SetIonisation(nullptr, &part);
msc->SetMasterThread(master);
msc->SetPolarAngleLimit(param->MscThetaLimit());
G4double emax = std::min(msc->HighEnergyLimit(),param->MaxKinEnergy());
msc->SetHighEnergyLimit(emax);
@@ -566,15 +563,37 @@ void G4EmTableUtil::BuildMscProcess(G4VMultipleScattering* proc,
auto param = G4EmParameters::Instance();
G4int verb = param->Verbose();
if(!master && firstPart == &part) {
// initialisation of models
G4bool baseMat = masterProc->UseBaseMaterial();
for(G4int i=0; i<nModels; ++i) {
G4VMscModel* msc = proc->GetModelByIndex(i);
G4VMscModel* msc0 = masterProc->GetModelByIndex(i);
msc->SetUseBaseMaterials(baseMat);
msc->SetCrossSectionTable(msc0->GetCrossSectionTable(), false);
msc->InitialiseLocal(&part, msc0);
if (firstPart == &part) {
G4LossTableBuilder* bld = G4LossTableManager::Instance()->GetTableBuilder();
G4bool baseMat = bld->GetBaseMaterialFlag();
if (master) {
for (G4int i=0; i<nModels; ++i) {
G4VMscModel* msc = proc->GetModelByIndex(i);
msc->SetUseBaseMaterials(baseMat);
// table is always built for low mass particles
if (part.GetParticleName() != "GenericIon" &&
(part.GetPDGMass() < CLHEP::GeV || msc->ForceBuildTableFlag())) {
G4double emin =
std::max(msc->LowEnergyLimit(), msc->LowEnergyActivationLimit());
G4double emax =
std::min(msc->HighEnergyLimit(), msc->HighEnergyActivationLimit());
emin = std::max(emin, param->MinKinEnergy());
emax = std::min(emax, param->MaxKinEnergy());
if (emin < emax) {
auto table = bld->BuildTableForModel(msc->GetCrossSectionTable(),
msc, &part, emin, emax, true);
msc->SetCrossSectionTable(table, true);
}
}
}
} else {
for (G4int i=0; i<nModels; ++i) {
G4VMscModel* msc = proc->GetModelByIndex(i);
G4VMscModel* msc0 = masterProc->GetModelByIndex(i);
msc->SetUseBaseMaterials(baseMat);
msc->SetCrossSectionTable(msc0->GetCrossSectionTable(), false);
msc->InitialiseLocal(&part, msc0);
}
}
}
if(!param->IsPrintLocked()) {
@@ -671,7 +690,7 @@ G4bool G4EmTableUtil::RetrieveTable(G4VProcess* ptr,
{
G4bool res = true;
if (nullptr == aTable) { return res; }
if (0 < verb) {
if (1 < verb) {
G4cout << tname << " table for " << part->GetParticleName()
<< " will be retrieved " << G4endl;
}
@@ -685,7 +704,7 @@ G4bool G4EmTableUtil::RetrieveTable(G4VProcess* ptr,
}
if (0 < verb) {
G4cout << tname << " table for " << part->GetParticleName()
<< " is Retrieved from <" << name << ">"
<< " is retrieved from <" << name << ">"
<< G4endl;
}
} else {
@@ -66,6 +66,7 @@
#include "G4LossTableManager.hh"
#include "G4EmParameters.hh"
G4bool G4LossTableBuilder::baseMatFlag = false;
std::vector<G4double>* G4LossTableBuilder::theDensityFactor = nullptr;
std::vector<G4int>* G4LossTableBuilder::theDensityIdx = nullptr;
std::vector<G4bool>* G4LossTableBuilder::theFlag = nullptr;
@@ -73,19 +74,13 @@ std::vector<G4bool>* G4LossTableBuilder::theFlag = nullptr;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
G4LossTableBuilder::G4LossTableBuilder(G4bool master)
: isInitializer(master)
{
theParameters = G4EmParameters::Instance();
if (nullptr == theFlag) {
if (!master) {
G4ExceptionDescription ed;
ed << "The table builder is instantiated in a worker thread ";
G4Exception("G4LossTableBuilder::G4LossTableBuilder ", "em0001",
JustWarning, ed);
}
theDensityFactor = new std::vector<G4double>;
theDensityIdx = new std::vector<G4int>;
theFlag = new std::vector<G4bool>;
isInitializer = true;
}
}
@@ -105,14 +100,14 @@ G4LossTableBuilder::~G4LossTableBuilder()
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
const std::vector<G4int>* G4LossTableBuilder::GetCoupleIndexes() const
const std::vector<G4int>* G4LossTableBuilder::GetCoupleIndexes()
{
return theDensityIdx;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
const std::vector<G4double>* G4LossTableBuilder::GetDensityFactors() const
const std::vector<G4double>* G4LossTableBuilder::GetDensityFactors()
{
return theDensityFactor;
}
@@ -121,7 +116,6 @@ const std::vector<G4double>* G4LossTableBuilder::GetDensityFactors() const
G4bool G4LossTableBuilder::GetFlag(std::size_t idx)
{
if (theFlag->empty()) { InitialiseBaseMaterials(); }
return (idx < theFlag->size()) ? (*theFlag)[idx] : false;
}
@@ -129,7 +123,6 @@ G4bool G4LossTableBuilder::GetFlag(std::size_t idx)
G4bool G4LossTableBuilder::GetBaseMaterialFlag()
{
if (theFlag->empty()) { InitialiseBaseMaterials(); }
return baseMatFlag;
}
@@ -150,6 +143,7 @@ G4LossTableBuilder::BuildDEDXTable(G4PhysicsTable* dedxTable,
for (std::size_t i=0; i<nCouples; ++i) {
auto pv0 = static_cast<G4PhysicsLogVector*>((*(list[0]))[i]);
//if (0 == i) G4cout << i << ". pv0=" << pv0 << " t:" << list[0] << G4endl;
if(pv0 == nullptr) { continue; }
std::size_t npoints = pv0->GetVectorLength();
auto pv = new G4PhysicsLogVector(*pv0);
@@ -157,6 +151,7 @@ G4LossTableBuilder::BuildDEDXTable(G4PhysicsTable* dedxTable,
G4double dedx = 0.0;
for (std::size_t k=0; k<n_processes; ++k) {
const G4PhysicsVector* pv1 = (*(list[k]))[i];
//if (0 == i) G4cout << " " << k << ". pv1=" << pv1 << " t:" << list[k] << G4endl;
dedx += (*pv1)[j];
}
pv->PutValue(j, dedx);
@@ -311,64 +306,49 @@ void G4LossTableBuilder::InitialiseBaseMaterials(const G4PhysicsTable* table)
// reserve memory
theFlag->resize(nCouples, true);
if(nullptr == table) { return; }
if(baseMatFlag) {
theDensityFactor->resize(nCouples,1.0);
theDensityIdx->resize(nCouples);
}
theDensityFactor->resize(nCouples,1.0);
theDensityIdx->resize(nCouples, 0);
// define default flag and index of used material cut couple
for(G4int i=0; i<(G4int)nCouples; ++i) {
(*theFlag)[i] = table->GetFlag(i);
if(baseMatFlag) { (*theDensityIdx)[i] = i; }
for (G4int i=0; i<(G4int)nCouples; ++i) {
(*theFlag)[i] = (nullptr == table) ? true : table->GetFlag(i);
(*theDensityIdx)[i] = i;
}
isInitialized = true;
if(baseMatFlag) {
// use base materials
for(G4int i=0; i<(G4int)nCouples; ++i) {
// base material is needed only for a couple which is not
// initialised and for which tables will be computed
auto couple = theCoupleTable->GetMaterialCutsCouple(i);
auto pcuts = couple->GetProductionCuts();
auto mat = couple->GetMaterial();
auto bmat = mat->GetBaseMaterial();
if (!baseMatFlag) { return; }
// base material exists - find it and check if it can be reused
if(nullptr != bmat) {
for(G4int j=0; j<(G4int)nCouples; ++j) {
if(j == i) { continue; }
auto bcouple = theCoupleTable->GetMaterialCutsCouple(j);
// use base materials
for (G4int i=0; i<(G4int)nCouples; ++i) {
// base material is needed only for a couple which is not
// initialised and for which tables will be computed
auto couple = theCoupleTable->GetMaterialCutsCouple(i);
auto pcuts = couple->GetProductionCuts();
auto mat = couple->GetMaterial();
auto bmat = mat->GetBaseMaterial();
if(bcouple->GetMaterial() == bmat &&
bcouple->GetProductionCuts() == pcuts) {
// base material exists - find it and check if it can be reused
if(nullptr != bmat) {
for(G4int j=0; j<(G4int)nCouples; ++j) {
if(j == i) { continue; }
auto bcouple = theCoupleTable->GetMaterialCutsCouple(j);
// based couple exist in the same region
(*theDensityFactor)[i] = mat->GetDensity()/bmat->GetDensity();
(*theDensityIdx)[i] = j;
(*theFlag)[i] = false;
if(bcouple->GetMaterial() == bmat &&
bcouple->GetProductionCuts() == pcuts) {
// ensure that there will no double initialisation
(*theDensityFactor)[j] = 1.0;
(*theDensityIdx)[j] = j;
(*theFlag)[j] = true;
break;
}
// based couple exist in the same region
(*theDensityFactor)[i] = mat->GetDensity()/bmat->GetDensity();
(*theDensityIdx)[i] = j;
(*theFlag)[i] = false;
// ensure that there will no double initialisation
(*theDensityFactor)[j] = 1.0;
(*theDensityIdx)[j] = j;
(*theFlag)[j] = true;
break;
}
}
}
}
/*
G4cout << "### G4LossTableBuilder::InitialiseBaseMaterials: flag="
<< baseMatFlag << G4endl;
for(std::size_t i=0; i<nCouples; ++i) {
G4cout << "CoupleIdx=" << i << " Flag= " << (*theFlag)[i] << " "
<< theCoupleTable->GetMaterialCutsCouple(i)->GetMaterial()->GetName()
<< " TableFlag= " << table->GetFlag(i)
<< " " << (*table)[i]
<< G4endl;
}
*/
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
@@ -382,13 +362,12 @@ G4LossTableBuilder::BuildTableForModel(G4PhysicsTable* aTable,
{
// check input
G4PhysicsTable* table = G4PhysicsTableHelper::PreparePhysicsTable(aTable);
if(nullptr == table) { return table; }
if(emin >= emax) {
table->clearAndDestroy();
delete table;
table = nullptr;
return table;
if (nullptr == table) { return table; }
if (aTable != nullptr && aTable != table) {
aTable->clearAndDestroy();
delete aTable;
}
InitialiseBaseMaterials(table);
G4int nbins = theParameters->NumberOfBinsPerDecade();
@@ -396,21 +375,25 @@ G4LossTableBuilder::BuildTableForModel(G4PhysicsTable* aTable,
const G4ProductionCutsTable* theCoupleTable=
G4ProductionCutsTable::GetProductionCutsTable();
std::size_t numOfCouples = theCoupleTable->GetTableSize();
/*
G4cout << " G4LossTableBuilder::BuildTableForModel Ncouple=" << numOfCouples
<< " isMaster=" << isInitializer << " model:" << model->GetName()
<< " " << part->GetParticleName() << G4endl;
*/
G4PhysicsLogVector* aVector = nullptr;
for(G4int i=0; i<(G4int)numOfCouples; ++i) {
if ((*theFlag)[i]) {
//G4cout << i << ". " << (*theFlag)[i] << " " << table->GetFlag(i) << G4endl;
if (table->GetFlag(i)) {
// create physics vector and fill it
auto couple = theCoupleTable->GetMaterialCutsCouple(i);
delete (*table)[i];
// if start from zero then change the scale
const G4Material* mat = couple->GetMaterial();
G4double tmin = std::max(emin,model->MinPrimaryEnergy(mat,part));
G4double tmin = std::max(emin, model->MinPrimaryEnergy(mat,part));
if(0.0 >= tmin) { tmin = CLHEP::eV; }
G4int n = nbins;
@@ -424,10 +407,12 @@ G4LossTableBuilder::BuildTableForModel(G4PhysicsTable* aTable,
if(nullptr != aVector) {
//G4cout << part->GetParticleName() << " in " << mat->GetName()
// << " tmin= " << tmin << G4endl;
// << " emin= " << tmin << " emax=" << emax << " n=" << n << G4endl;
for(G4int j=0; j<=n; ++j) {
aVector->PutValue(j, model->Value(couple, part,
aVector->Energy(j)));
G4double e = aVector->Energy(j);
G4double y = model->Value(couple, part, e);
//G4cout << " " << j << ") E=" << e << " y=" << y << G4endl;
aVector->PutValue(j, y);
}
if(spline) { aVector->FillSecondDerivatives(); }
}
@@ -71,7 +71,6 @@
#include "G4EmTableType.hh"
#include "G4Region.hh"
#include "G4PhysicalConstants.hh"
#include "G4Threading.hh"
#include "G4Gamma.hh"
#include "G4Positron.hh"
@@ -79,9 +78,11 @@
#include "G4Neutron.hh"
#include "G4MuonPlus.hh"
#include "G4MuonMinus.hh"
#include "G4GenericIon.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
static std::once_flag applyOnce;
G4ThreadLocal G4LossTableManager* G4LossTableManager::instance = nullptr;
G4LossTableManager* G4LossTableManager::Instance()
@@ -132,13 +133,12 @@ G4LossTableManager::~G4LossTableManager()
G4LossTableManager::G4LossTableManager()
{
theParameters = G4EmParameters::Instance();
verbose = theParameters->Verbose();
theElectron = G4Electron::Electron();
theGenericIon= nullptr;
if(G4Threading::IsWorkerThread()) {
verbose = theParameters->WorkerVerbose();
isMaster = false;
}
// only one thread is the master
std::call_once(applyOnce, [this]() { isMaster = true; });
verbose = isMaster ? theParameters->Verbose() : theParameters->WorkerVerbose();
tableBuilder = new G4LossTableBuilder(isMaster);
emCorrections = new G4EmCorrections(verbose);
@@ -182,7 +182,7 @@ void G4LossTableManager::Clear()
void G4LossTableManager::Register(G4VEnergyLossProcess* p)
{
if(!p) { return; }
if (nullptr == p) { return; }
for (G4int i=0; i<n_loss; ++i) {
if(loss_vector[i] == p) { return; }
}
@@ -206,13 +206,20 @@ void G4LossTableManager::Register(G4VEnergyLossProcess* p)
void G4LossTableManager::ResetParameters()
{
// initialisation once per run
if (!resetParam) { return; }
resetParam = false;
startInitialisation = true;
verbose = theParameters->Verbose();
if(!isMaster) {
verbose = theParameters->WorkerVerbose();
} else {
if(verbose > 0) { theParameters->Dump(); }
}
tableBuilder->SetInitialisationFlag(false);
tableBuilder->InitialiseBaseMaterials();
if (nullptr != nielCalculator) { nielCalculator->Initialise(); }
emCorrections->SetVerbose(verbose);
if(nullptr != emConfigurator) { emConfigurator->SetVerbose(verbose); };
if(nullptr != emElectronIonPair) { emElectronIonPair->SetVerbose(verbose); };
@@ -220,13 +227,19 @@ void G4LossTableManager::ResetParameters()
atomDeexcitation->SetVerboseLevel(verbose);
atomDeexcitation->InitialiseAtomicDeexcitation();
}
if (1 < verbose) {
G4cout << "====== G4LossTableManager::ResetParameters "
<< " Nloss=" << loss_vector.size()
<< " run=" << run << " master=" << isMaster
<< G4endl;
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
void G4LossTableManager::DeRegister(G4VEnergyLossProcess* p)
{
if(!p) { return; }
if (nullptr == p) { return; }
for (G4int i=0; i<n_loss; ++i) {
if(loss_vector[i] == p) {
loss_vector[i] = nullptr;
@@ -239,7 +252,7 @@ void G4LossTableManager::DeRegister(G4VEnergyLossProcess* p)
void G4LossTableManager::Register(G4VMultipleScattering* p)
{
if(!p) { return; }
if (nullptr == p) { return; }
std::size_t n = msc_vector.size();
for (std::size_t i=0; i<n; ++i) {
if(msc_vector[i] == p) { return; }
@@ -255,7 +268,7 @@ void G4LossTableManager::Register(G4VMultipleScattering* p)
void G4LossTableManager::DeRegister(G4VMultipleScattering* p)
{
if(!p) { return; }
if (nullptr == p) { return; }
std::size_t msc = msc_vector.size();
for (std::size_t i=0; i<msc; ++i) {
if(msc_vector[i] == p) {
@@ -269,7 +282,7 @@ void G4LossTableManager::DeRegister(G4VMultipleScattering* p)
void G4LossTableManager::Register(G4VEmProcess* p)
{
if(!p) { return; }
if (nullptr == p) { return; }
std::size_t n = emp_vector.size();
for (std::size_t i=0; i<n; ++i) {
if(emp_vector[i] == p) { return; }
@@ -285,7 +298,7 @@ void G4LossTableManager::Register(G4VEmProcess* p)
void G4LossTableManager::DeRegister(G4VEmProcess* p)
{
if(!p) { return; }
if (nullptr == p) { return; }
std::size_t emp = emp_vector.size();
for (std::size_t i=0; i<emp; ++i) {
if(emp_vector[i] == p) {
@@ -299,7 +312,7 @@ void G4LossTableManager::DeRegister(G4VEmProcess* p)
void G4LossTableManager::Register(G4VProcess* p)
{
if(!p) { return; }
if (nullptr == p) { return; }
std::size_t n = p_vector.size();
for (std::size_t i=0; i<n; ++i) {
if(p_vector[i] == p) { return; }
@@ -315,7 +328,7 @@ void G4LossTableManager::Register(G4VProcess* p)
void G4LossTableManager::DeRegister(G4VProcess* p)
{
if(!p) { return; }
if (nullptr == p) { return; }
std::size_t emp = p_vector.size();
for (std::size_t i=0; i<emp; ++i) {
if(p_vector[i] == p) {
@@ -377,7 +390,7 @@ void G4LossTableManager::RegisterExtraParticle(
const G4ParticleDefinition* part,
G4VEnergyLossProcess* p)
{
if(!p || !part) { return; }
if (nullptr == p || nullptr == part) { return; }
for (G4int i=0; i<n_loss; ++i) {
if(loss_vector[i] == p) { return; }
}
@@ -428,32 +441,26 @@ G4LossTableManager::PreparePhysicsTable(const G4ParticleDefinition* particle,
G4cout << "G4LossTableManager::PreparePhysicsTable for "
<< particle->GetParticleName()
<< " and " << p->GetProcessName() << " run= " << run
<< " loss_vector " << loss_vector.size() << G4endl;
}
if(!startInitialisation) {
ResetParameters();
if (1 < verbose) {
G4cout << "====== G4LossTableManager::PreparePhysicsTable start ====="
<< G4endl;
}
<< " loss_vector " << loss_vector.size()
<< " run=" << run << " master=" << isMaster
<< G4endl;
}
// start initialisation for the first run
if( -1 == run ) {
if(emConfigurator) { emConfigurator->PrepareModels(particle, p); }
if (nullptr != emConfigurator) { emConfigurator->PrepareModels(particle, p); }
// initialise particles for given process
for (G4int j=0; j<n_loss; ++j) {
if (p == loss_vector[j] && !part_vector[j]) {
if (p == loss_vector[j] && nullptr == part_vector[j]) {
part_vector[j] = particle;
if(particle->GetParticleName() == "GenericIon") {
if (particle->GetParticleName() == "GenericIon") {
theGenericIon = particle;
}
}
}
}
startInitialisation = true;
ResetParameters();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
@@ -465,22 +472,17 @@ G4LossTableManager::PreparePhysicsTable(const G4ParticleDefinition* particle,
if (1 < verbose) {
G4cout << "G4LossTableManager::PreparePhysicsTable for "
<< particle->GetParticleName()
<< " and " << p->GetProcessName() << G4endl;
}
if(!startInitialisation) {
ResetParameters();
if (1 < verbose) {
G4cout << "====== G4LossTableManager::PreparePhysicsTable start ====="
<< G4endl;
}
<< " and " << p->GetProcessName()
<< " run=" << run << " master=" << isMaster
<< G4endl;
}
// start initialisation for the first run
if( -1 == run ) {
if(emConfigurator) { emConfigurator->PrepareModels(particle, p); }
if (nullptr != emConfigurator) { emConfigurator->PrepareModels(particle, p); }
}
startInitialisation = true;
ResetParameters();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
@@ -492,22 +494,17 @@ G4LossTableManager::PreparePhysicsTable(const G4ParticleDefinition* particle,
if (1 < verbose) {
G4cout << "G4LossTableManager::PreparePhysicsTable for "
<< particle->GetParticleName()
<< " and " << p->GetProcessName() << G4endl;
}
if(!startInitialisation) {
ResetParameters();
if (1 < verbose) {
G4cout << "====== G4LossTableManager::PreparePhysicsTable start ====="
<< G4endl;
}
<< " and " << p->GetProcessName()
<< " run=" << run << " master=" << isMaster
<< G4endl;
}
// start initialisation for the first run
if( -1 == run ) {
if(emConfigurator) { emConfigurator->PrepareModels(particle, p); }
if ( -1 == run ) {
if (nullptr != emConfigurator) { emConfigurator->PrepareModels(particle, p); }
}
startInitialisation = true;
ResetParameters();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
@@ -516,8 +513,9 @@ void
G4LossTableManager::BuildPhysicsTable(const G4ParticleDefinition*)
{
if(-1 == run && startInitialisation) {
if(emConfigurator) { emConfigurator->Clear(); }
if (nullptr != emConfigurator) { emConfigurator->Clear(); }
}
if (startInitialisation) { resetParam = true; }
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
@@ -526,7 +524,7 @@ void G4LossTableManager::LocalPhysicsTables(
const G4ParticleDefinition* aParticle,
G4VEnergyLossProcess* p)
{
if(1 < verbose) {
if (1 < verbose) {
G4cout << "### G4LossTableManager::LocalPhysicsTable() for "
<< aParticle->GetParticleName()
<< " and process " << p->GetProcessName()
@@ -534,20 +532,21 @@ void G4LossTableManager::LocalPhysicsTables(
}
if(-1 == run && startInitialisation) {
if(emConfigurator) { emConfigurator->Clear(); }
if (nullptr != emConfigurator) { emConfigurator->Clear(); }
firstParticle = aParticle;
}
if(startInitialisation) {
if (startInitialisation) {
++run;
if(1 < verbose) {
if (1 < verbose) {
G4cout << "===== G4LossTableManager::LocalPhysicsTable() for run "
<< run << " =====" << G4endl;
}
currentParticle = nullptr;
startInitialisation = false;
resetParam = true;
for (G4int i=0; i<n_loss; ++i) {
if(loss_vector[i]) {
if (nullptr != loss_vector[i]) {
tables_are_built[i] = false;
} else {
tables_are_built[i] = true;
@@ -611,39 +610,28 @@ void G4LossTableManager::BuildPhysicsTable(
}
// clear configurator
if(-1 == run && startInitialisation) {
if(emConfigurator) { emConfigurator->Clear(); }
if( nullptr != emConfigurator) { emConfigurator->Clear(); }
firstParticle = aParticle;
}
if(startInitialisation) {
++run;
resetParam = true;
startInitialisation = false;
if(1 < verbose) {
G4cout << "===== G4LossTableManager::BuildPhysicsTable() for run "
<< run << " ===== " << atomDeexcitation << G4endl;
}
currentParticle = nullptr;
all_tables_are_built= true;
}
// initialisation before any table is built
if ( startInitialisation && aParticle == firstParticle ) {
startInitialisation = false;
if(1 < verbose) {
G4cout << "### G4LossTableManager start initialisation for first particle "
<< firstParticle->GetParticleName()
<< G4endl;
}
if(nielCalculator) { nielCalculator->Initialise(); }
all_tables_are_built = false;
for (G4int i=0; i<n_loss; ++i) {
G4VEnergyLossProcess* el = loss_vector[i];
if(el) {
if(nullptr != el) {
isActive[i] = true;
part_vector[i] = el->Particle();
base_part_vector[i] = el->BaseParticle();
tables_are_built[i] = false;
all_tables_are_built= false;
tables_are_built[i] = false;
if(1 < verbose) {
G4cout << i <<". "<< el->GetProcessName();
if(el->Particle()) {
@@ -675,7 +663,7 @@ void G4LossTableManager::BuildPhysicsTable(
all_tables_are_built = true;
for(G4int i=0; i<n_loss; ++i) {
if(p == loss_vector[i] && !tables_are_built[i] && !base_part_vector[i]) {
if(p == loss_vector[i] && !tables_are_built[i] && nullptr == base_part_vector[i]) {
const G4ParticleDefinition* curr_part = part_vector[i];
if(1 < verbose) {
G4cout << "### Build Table for " << p->GetProcessName()
@@ -701,12 +689,6 @@ void G4LossTableManager::BuildPhysicsTable(
<< "all_tables_are_built= " << all_tables_are_built << " "
<< aParticle->GetParticleName() << " proc: " << p << G4endl;
}
if(all_tables_are_built) {
if(1 < verbose) {
G4cout << "%%%%% All dEdx and Range tables are built for master run= "
<< run << " %%%%%" << G4endl;
}
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
@@ -720,13 +702,13 @@ void G4LossTableManager::CopyTables(const G4ParticleDefinition* part,
if (!tables_are_built[j] && part == base_part_vector[j]) {
tables_are_built[j] = true;
// for base particle approach only ionisation table should be used
proc->SetDEDXTable(base_proc->IonisationTable(),fRestricted);
proc->SetDEDXTable(base_proc->DEDXunRestrictedTable(),fTotal);
proc->SetCSDARangeTable(base_proc->CSDARangeTable());
proc->SetRangeTableForLoss(base_proc->RangeTableForLoss());
proc->SetInverseRangeTable(base_proc->InverseRangeTable());
proc->SetLambdaTable(base_proc->LambdaTable());
proc->SetIonisation(base_proc->IsIonisationProcess());
if(proc->IsIonisationProcess()) {
range_vector[j] = base_proc->RangeTableForLoss();
inv_range_vector[j] = base_proc->InverseRangeTable();
@@ -736,7 +718,7 @@ void G4LossTableManager::CopyTables(const G4ParticleDefinition* part,
// << " added to map " << proc << G4endl;
}
if (1 < verbose) {
G4cout << "For " << proc->GetProcessName()
G4cout << " CopyTables for " << proc->GetProcessName()
<< " for " << part_vector[j]->GetParticleName()
<< " base_part= " << part->GetParticleName()
<< " tables are assigned"
@@ -752,7 +734,7 @@ G4VEnergyLossProcess* G4LossTableManager::BuildTables(
const G4ParticleDefinition* aParticle)
{
if(1 < verbose) {
G4cout << "G4LossTableManager::BuildTables() for "
G4cout << " G4LossTableManager::BuildTables(part) for "
<< aParticle->GetParticleName() << G4endl;
}
@@ -771,7 +753,7 @@ G4VEnergyLossProcess* G4LossTableManager::BuildTables(
for (i=0; i<n_loss; ++i) {
p = loss_vector[i];
if (p) {
if (nullptr != p) {
G4bool yes = (aParticle == part_vector[i]);
// possible case of process sharing between particle/anti-particle
@@ -819,8 +801,7 @@ G4VEnergyLossProcess* G4LossTableManager::BuildTables(
G4int nSubRegions = em->NumberOfSubCutoffRegions();
if (1 < verbose) {
G4cout << "G4LossTableManager::BuildTables() start to build range tables"
<< " and the sum of " << n_dedx << " processes"
G4cout << " Start to build the sum of " << n_dedx << " processes"
<< " iem= " << iem << " em= " << em->GetProcessName()
<< " buildCSDARange= " << theParameters->BuildCSDARange()
<< " nSubRegions= " << nSubRegions;
@@ -832,8 +813,7 @@ G4VEnergyLossProcess* G4LossTableManager::BuildTables(
// do not build tables if producer class is defined
if(subcutProducer) { nSubRegions = 0; }
dedx = em->DEDXTable();
em->SetIonisation(true);
dedx = em->DEDXTable();
em->SetDEDXTable(dedx, fIsIonisation);
if (1 < n_dedx) {
@@ -843,15 +823,6 @@ G4VEnergyLossProcess* G4LossTableManager::BuildTables(
em->SetDEDXTable(dedx, fRestricted);
}
/*
if(2==run && "e-" == aParticle->GetParticleName()) {
G4cout << "G4LossTableManager::BuildTables for e- " << dedx << G4endl;
G4cout << (*dedx) << G4endl;
G4cout << "%%%%% Instance ID= " << (*dedx)[0]->GetInstanceID() << G4endl;
G4cout << "%%%%% LastValue= " << (*dedx)[0]->GetLastValue() << G4endl;
G4cout << "%%%%% 1.2 " << (*(dedx))[0]->Value(1.2) << G4endl;
}
*/
dedx_vector[iem] = dedx;
G4PhysicsTable* range = em->RangeTableForLoss();
@@ -865,18 +836,13 @@ G4VEnergyLossProcess* G4LossTableManager::BuildTables(
tableBuilder->BuildRangeTable(dedx, range);
tableBuilder->BuildInverseRangeTable(range, invrange);
// if(1<verbose) G4cout << *dedx << G4endl;
em->SetRangeTableForLoss(range);
em->SetInverseRangeTable(invrange);
// if(1<verbose) G4cout << *range << G4endl;
std::vector<G4PhysicsTable*> listCSDA;
for (i=0; i<n_dedx; ++i) {
p = loss_list[i];
if(p != em) { p->SetIonisation(false); }
if(build_flags[i]) {
p->SetLambdaTable(p->BuildLambdaTable(fRestricted));
}
@@ -983,7 +949,7 @@ G4ElectronIonPair* G4LossTableManager::ElectronIonPair()
void G4LossTableManager::SetNIELCalculator(G4NIELCalculator* ptr)
{
if(ptr && ptr != nielCalculator) {
if(nullptr != ptr && ptr != nielCalculator) {
delete nielCalculator;
nielCalculator = ptr;
}
@@ -159,7 +159,6 @@ void G4TransportationWithMsc::PreparePhysicsTable(const G4ParticleDefinition& pa
if (fType == ScatteringType::MultipleScattering) {
for (G4int i = 0; i < numberOfModels; ++i) {
auto msc = static_cast<G4VMscModel*>(fModelManager->GetModel(i));
msc->SetMasterThread(master);
msc->SetPolarAngleLimit(theParameters->MscThetaLimit());
G4double emax = std::min(msc->HighEnergyLimit(), theParameters->MaxKinEnergy());
msc->SetHighEnergyLimit(emax);
@@ -74,7 +74,8 @@ G4VEmModel::G4VEmModel(const G4String& nam):
xsec.resize(nsec);
fEmManager = G4LossTableManager::Instance();
fEmManager->Register(this);
isMaster = fEmManager->IsMaster();
G4LossTableBuilder* bld = fEmManager->GetTableBuilder();
theDensityFactor = bld->GetDensityFactors();
theDensityIdx = bld->GetCoupleIndexes();
@@ -396,13 +397,7 @@ G4VEmModel::SetParticleChange(G4VParticleChange* p, G4VEmFluctuationModel* f)
void G4VEmModel::SetCrossSectionTable(G4PhysicsTable* p, G4bool isLocal)
{
if(p != xSectionTable) {
if(xSectionTable != nullptr && localTable) {
xSectionTable->clearAndDestroy();
delete xSectionTable;
}
xSectionTable = p;
}
xSectionTable = p;
localTable = isLocal;
}
@@ -419,6 +414,11 @@ void G4VEmModel::SetLPMFlag(G4bool)
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void G4VEmModel::SetMasterThread(G4bool)
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void G4VEmModel::ModelDescription(std::ostream& outFile) const
@@ -153,7 +153,7 @@ void G4VEmProcess::PreparePhysicsTable(const G4ParticleDefinition& part)
G4String pname = part.GetParticleName();
if(pname != "deuteron" && pname != "triton" &&
pname != "alpha" && pname != "alpha+" &&
pname != "He3" && pname != "alpha" && pname != "alpha+" &&
pname != "helium" && pname != "hydrogen") {
particle = G4GenericIon::GenericIon();
@@ -272,8 +272,14 @@ void G4VEmProcess::StreamInfo(std::ostream& out,
}
if(fXSType != fEmNoIntegral) { out << " XStype:" << fXSType; }
if(applyCuts) { out << " applyCuts:1 "; }
out << " SubType=" << GetProcessSubType();
if(biasFactor != 1.0) { out << " BiasingFactor= " << biasFactor; }
G4int subtype = GetProcessSubType();
out << " SubType=" << subtype;
if (subtype == fAnnihilation) {
G4int mod = theParameters->PositronAtRestModelType();
const G4String namp[2] = {"Simple", "Allison"};
out << " AtRestModel:" << namp[mod];
}
if(biasFactor != 1.0) { out << " BiasingFactor=" << biasFactor; }
out << " BuildTable=" << buildLambdaTable << G4endl;
if(buildLambdaTable) {
if(particle == &part) {
@@ -554,7 +560,7 @@ G4VParticleChange* G4VEmProcess::PostStepDoIt(const G4Track& track,
G4double time = track.GetGlobalTime();
G4int n1(0), n2(0);
if(num > mainSecondaries) {
if(num0 > mainSecondaries) {
currentModel->FillNumberOfSecondaries(n1, n2);
}
@@ -608,7 +614,7 @@ G4VParticleChange* G4VEmProcess::PostStepDoIt(const G4Track& track,
t->SetCreatorModelID(augerID);
}
} else {
t->SetCreatorModelID(secID);
t->SetCreatorModelID(biasID);
}
}
/*
@@ -218,6 +218,7 @@ G4VEnergyLossProcess::PreparePhysicsTable(const G4ParticleDefinition& part)
}
tablesAreBuilt = false;
if (GetProcessSubType() == fIonisation) { SetIonisation(true); }
G4LossTableBuilder* bld = lManager->GetTableBuilder();
lManager->PreparePhysicsTable(&part, this);
@@ -962,7 +963,18 @@ void G4VEnergyLossProcess::FillSecondariesAlongStep(G4double wt)
if(nullptr != t) {
t->SetWeight(weight);
pParticleChange->AddSecondary(t);
if(i >= n0) { t->SetCreatorModelID(biasID); }
G4int pdg = t->GetDefinition()->GetPDGEncoding();
if (i < n0) {
if (pdg == 22) {
t->SetCreatorModelID(gpixeID);
} else if (pdg == 11) {
t->SetCreatorModelID(epixeID);
} else {
t->SetCreatorModelID(biasID);
}
} else {
t->SetCreatorModelID(biasID);
}
}
}
scTracks.clear();
@@ -1110,17 +1122,19 @@ G4bool G4VEnergyLossProcess::StorePhysicsTable(
{
if (!isMaster || nullptr != baseParticle || part != particle ) return true;
for(std::size_t i=0; i<7; ++i) {
if(nullptr != theData->Table(i)) {
if(1 < verboseLevel) {
G4cout << "G4VEnergyLossProcess::StorePhysicsTable i=" << i
<< " " << particle->GetParticleName()
<< " " << GetProcessName()
<< " " << tnames[i] << " " << theData->Table(i) << G4endl;
}
if(!G4EmTableUtil::StoreTable(this, part, theData->Table(i),
dir, tnames[i], verboseLevel, ascii)) {
return false;
}
// ionisation table only for ionisation process
if (nullptr == theData->Table(i) || (!isIonisation && 1 == i)) {
continue;
}
if (-1 < verboseLevel) {
G4cout << "G4VEnergyLossProcess::StorePhysicsTable i=" << i
<< " " << particle->GetParticleName()
<< " " << GetProcessName()
<< " " << tnames[i] << " " << theData->Table(i) << G4endl;
}
if (!G4EmTableUtil::StoreTable(this, part, theData->Table(i),
dir, tnames[i], verboseLevel, ascii)) {
return false;
}
}
return true;
@@ -1134,6 +1148,8 @@ G4VEnergyLossProcess::RetrievePhysicsTable(const G4ParticleDefinition* part,
{
if (!isMaster || nullptr != baseParticle || part != particle ) return true;
for(std::size_t i=0; i<7; ++i) {
// ionisation table only for ionisation process
if (!isIonisation && 1 == i) { continue; }
if(!G4EmTableUtil::RetrieveTable(this, part, theData->Table(i), dir, tnames[i],
verboseLevel, ascii, spline)) {
return false;
@@ -74,7 +74,7 @@ G4VMscModel::~G4VMscModel() = default;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4ParticleChangeForMSC*
G4VMscModel::GetParticleChangeForMSC(const G4ParticleDefinition* p)
G4VMscModel::GetParticleChangeForMSC(const G4ParticleDefinition*)
{
// recomputed for each new run
if(nullptr == safetyHelper) {
@@ -88,25 +88,6 @@ G4VMscModel::GetParticleChangeForMSC(const G4ParticleDefinition* p)
} else {
change = new G4ParticleChangeForMSC();
}
if(IsMaster() && nullptr != p) {
// table is always built for low mass particles
if(p->GetParticleName() != "GenericIon" &&
(p->GetPDGMass() < CLHEP::GeV || ForceBuildTableFlag()) ) {
G4EmParameters* param = G4EmParameters::Instance();
G4LossTableBuilder* builder =
G4LossTableManager::Instance()->GetTableBuilder();
G4double emin = std::max(LowEnergyLimit(), LowEnergyActivationLimit());
G4double emax = std::min(HighEnergyLimit(), HighEnergyActivationLimit());
emin = std::max(emin, param->MinKinEnergy());
emax = std::min(emax, param->MaxKinEnergy());
if(emin < emax) {
xSectionTable = builder->BuildTableForModel(xSectionTable, this, p,
emin, emax, useSpline);
}
}
}
return change;
}
@@ -141,25 +141,24 @@ void
G4VMultipleScattering::PreparePhysicsTable(const G4ParticleDefinition& part)
{
G4bool master = emManager->IsMaster();
if(nullptr == firstParticle) { firstParticle = &part; }
if (nullptr == firstParticle) { firstParticle = &part; }
emManager->PreparePhysicsTable(&part, this);
currParticle = nullptr;
if(firstParticle == &part) {
baseMat = emManager->GetTableBuilder()->GetBaseMaterialFlag();
G4EmTableUtil::PrepareMscProcess(this, part, modelManager,
stepLimit, facrange,
latDisplacement, master,
isIon, baseMat);
stepLimit, facrange,
latDisplacement, master,
isIon, baseMat);
numberOfModels = modelManager->NumberOfModels();
currentModel = GetModelByIndex(0);
if(nullptr == safetyHelper) {
if (nullptr == safetyHelper) {
safetyHelper = G4TransportationManager::GetTransportationManager()
->GetSafetyHelper();
->GetSafetyHelper();
safetyHelper->InitialiseHelper();
}
}
@@ -171,8 +170,8 @@ void G4VMultipleScattering::BuildPhysicsTable(const G4ParticleDefinition& part)
{
G4bool master = emManager->IsMaster();
if(firstParticle == &part) {
emManager->BuildPhysicsTable(firstParticle);
if(firstParticle == &part) {
emManager->BuildPhysicsTable(&part);
}
const G4VMultipleScattering* ptr = this;
if(!master) {