89 if(
nullptr == instance) {
100 for (
auto const & p : loss_vector) {
delete p; }
101 for (
auto const & p : msc_vector) {
delete p; }
102 for (
auto const & p : emp_vector) {
delete p; }
103 for (
auto const & p : p_vector) {
delete p; }
105 std::size_t mod = mod_vector.size();
106 std::size_t fmod = fmod_vector.size();
107 for (std::size_t a=0; a<mod; ++a) {
108 if(
nullptr != mod_vector[a] ) {
109 for (std::size_t b=0; b<fmod; ++b) {
110 if((
G4VEmModel*)(fmod_vector[b]) == mod_vector[a]) {
111 fmod_vector[b] =
nullptr;
114 delete mod_vector[a];
115 mod_vector[a] =
nullptr;
118 for (
auto const & p : fmod_vector) {
delete p; }
122 delete emCorrections;
123 delete emConfigurator;
124 delete emElectronIonPair;
125 delete nielCalculator;
126 delete atomDeexcitation;
127 delete subcutProducer;
132G4LossTableManager::G4LossTableManager()
135 verbose = theParameters->
Verbose();
137 theGenericIon=
nullptr;
146 loss_vector.reserve(n);
147 part_vector.reserve(n);
148 base_part_vector.reserve(n);
149 dedx_vector.reserve(n);
150 range_vector.reserve(n);
151 inv_range_vector.reserve(n);
152 tables_are_built.reserve(n);
154 msc_vector.reserve(10);
155 emp_vector.reserve(16);
156 mod_vector.reserve(150);
157 fmod_vector.reserve(60);
162void G4LossTableManager::Clear()
164 all_tables_are_built =
false;
165 currentLoss =
nullptr;
166 currentParticle =
nullptr;
169 range_vector.clear();
170 inv_range_vector.clear();
174 base_part_vector.clear();
175 tables_are_built.clear();
186 for (
G4int i=0; i<n_loss; ++i) {
187 if(loss_vector[i] == p) {
return; }
190 G4cout <<
"G4LossTableManager::Register G4VEnergyLossProcess : "
194 loss_vector.push_back(p);
195 part_vector.push_back(
nullptr);
196 base_part_vector.push_back(
nullptr);
197 dedx_vector.push_back(
nullptr);
198 range_vector.push_back(
nullptr);
199 inv_range_vector.push_back(
nullptr);
200 tables_are_built.push_back(
false);
201 isActive.push_back(
true);
202 all_tables_are_built =
false;
209 verbose = theParameters->
Verbose();
213 if(verbose > 0) { theParameters->
Dump(); }
217 if(
nullptr != emConfigurator) { emConfigurator->
SetVerbose(verbose); };
218 if(
nullptr != emElectronIonPair) { emElectronIonPair->
SetVerbose(verbose); };
219 if(
nullptr != atomDeexcitation) {
230 for (
G4int i=0; i<n_loss; ++i) {
231 if(loss_vector[i] == p) {
232 loss_vector[i] =
nullptr;
243 std::size_t n = msc_vector.size();
244 for (std::size_t i=0; i<n; ++i) {
245 if(msc_vector[i] == p) {
return; }
248 G4cout <<
"G4LossTableManager::Register G4VMultipleScattering : "
251 msc_vector.push_back(p);
259 std::size_t msc = msc_vector.size();
260 for (std::size_t i=0; i<msc; ++i) {
261 if(msc_vector[i] == p) {
262 msc_vector[i] =
nullptr;
273 std::size_t n = emp_vector.size();
274 for (std::size_t i=0; i<n; ++i) {
275 if(emp_vector[i] == p) {
return; }
278 G4cout <<
"G4LossTableManager::Register G4VEmProcess : "
281 emp_vector.push_back(p);
289 std::size_t emp = emp_vector.size();
290 for (std::size_t i=0; i<emp; ++i) {
291 if(emp_vector[i] == p) {
292 emp_vector[i] =
nullptr;
303 std::size_t n = p_vector.size();
304 for (std::size_t i=0; i<n; ++i) {
305 if(p_vector[i] == p) {
return; }
308 G4cout <<
"G4LossTableManager::Register G4VProcess : "
311 p_vector.push_back(p);
319 std::size_t emp = p_vector.size();
320 for (std::size_t i=0; i<emp; ++i) {
321 if(p_vector[i] == p) {
322 p_vector[i] =
nullptr;
332 mod_vector.push_back(p);
334 G4cout <<
"G4LossTableManager::Register G4VEmModel : "
335 << p->
GetName() <<
" " << p <<
" " << mod_vector.size() <<
G4endl;
344 std::size_t n = mod_vector.size();
345 for (std::size_t i=0; i<n; ++i) {
346 if(mod_vector[i] == p) {
347 mod_vector[i] =
nullptr;
357 fmod_vector.push_back(p);
359 G4cout <<
"G4LossTableManager::Register G4VEmFluctuationModel : "
368 std::size_t n = fmod_vector.size();
369 for (std::size_t i=0; i<n; ++i) {
370 if(fmod_vector[i] == p) { fmod_vector[i] =
nullptr; }
380 if(!p || !part) {
return; }
381 for (
G4int i=0; i<n_loss; ++i) {
382 if(loss_vector[i] == p) {
return; }
385 G4cout <<
"G4LossTableManager::RegisterExtraParticle "
390 loss_vector.push_back(p);
391 part_vector.push_back(part);
393 dedx_vector.push_back(
nullptr);
394 range_vector.push_back(
nullptr);
395 inv_range_vector.push_back(
nullptr);
396 tables_are_built.push_back(
false);
397 all_tables_are_built =
false;
405 if(aParticle != currentParticle) {
406 currentParticle = aParticle;
407 std::map<PD,G4VEnergyLossProcess*,std::less<PD> >::const_iterator pos;
408 if ((pos = loss_map.find(aParticle)) != loss_map.end()) {
409 currentLoss = (*pos).second;
411 currentLoss =
nullptr;
413 (pos = loss_map.find(theGenericIon)) != loss_map.end()) {
414 currentLoss = (*pos).second;
428 G4cout <<
"G4LossTableManager::PreparePhysicsTable for "
431 <<
" loss_vector " << loss_vector.size() <<
G4endl;
434 if(!startInitialisation) {
437 G4cout <<
"====== G4LossTableManager::PreparePhysicsTable start ====="
444 if(emConfigurator) { emConfigurator->
PrepareModels(particle, p); }
447 for (
G4int j=0; j<n_loss; ++j) {
448 if (p == loss_vector[j] && !part_vector[j]) {
449 part_vector[j] = particle;
451 theGenericIon = particle;
456 startInitialisation =
true;
466 G4cout <<
"G4LossTableManager::PreparePhysicsTable for "
471 if(!startInitialisation) {
474 G4cout <<
"====== G4LossTableManager::PreparePhysicsTable start ====="
481 if(emConfigurator) { emConfigurator->
PrepareModels(particle, p); }
483 startInitialisation =
true;
493 G4cout <<
"G4LossTableManager::PreparePhysicsTable for "
498 if(!startInitialisation) {
501 G4cout <<
"====== G4LossTableManager::PreparePhysicsTable start ====="
508 if(emConfigurator) { emConfigurator->
PrepareModels(particle, p); }
510 startInitialisation =
true;
518 if(-1 == run && startInitialisation) {
519 if(emConfigurator) { emConfigurator->
Clear(); }
530 G4cout <<
"### G4LossTableManager::LocalPhysicsTable() for "
536 if(-1 == run && startInitialisation) {
537 if(emConfigurator) { emConfigurator->
Clear(); }
538 firstParticle = aParticle;
541 if(startInitialisation) {
544 G4cout <<
"===== G4LossTableManager::LocalPhysicsTable() for run "
545 << run <<
" =====" <<
G4endl;
547 currentParticle =
nullptr;
548 startInitialisation =
false;
549 for (
G4int i=0; i<n_loss; ++i) {
551 tables_are_built[i] =
false;
553 tables_are_built[i] =
true;
554 part_vector[i] =
nullptr;
559 all_tables_are_built=
true;
560 for (
G4int i=0; i<n_loss; ++i) {
561 if(p == loss_vector[i]) {
562 tables_are_built[i] =
true;
570 loss_map[part_vector[i]] = p;
576 G4cout <<
" for " << part_vector[i]->GetParticleName();
578 G4cout <<
" active= " << isActive[i]
579 <<
" table= " << tables_are_built[i]
584 }
else if(!tables_are_built[i]) {
585 all_tables_are_built =
false;
590 G4cout <<
"### G4LossTableManager::LocalPhysicsTable end"
593 if(all_tables_are_built) {
595 G4cout <<
"%%%%% All dEdx and Range tables for worker are ready for run "
596 << run <<
" %%%%%" <<
G4endl;
608 G4cout <<
"### G4LossTableManager::BuildPhysicsTable() for "
613 if(-1 == run && startInitialisation) {
614 if(emConfigurator) { emConfigurator->
Clear(); }
615 firstParticle = aParticle;
617 if(startInitialisation) {
620 G4cout <<
"===== G4LossTableManager::BuildPhysicsTable() for run "
621 << run <<
" ===== " << atomDeexcitation <<
G4endl;
623 currentParticle =
nullptr;
624 all_tables_are_built=
true;
628 if ( startInitialisation && aParticle == firstParticle ) {
630 startInitialisation =
false;
632 G4cout <<
"### G4LossTableManager start initialisation for first particle "
637 if(nielCalculator) { nielCalculator->
Initialise(); }
639 for (
G4int i=0; i<n_loss; ++i) {
645 tables_are_built[i] =
false;
646 all_tables_are_built=
false;
652 G4cout <<
" active= " << isActive[i]
653 <<
" table= " << tables_are_built[i]
655 if(base_part_vector[i]) {
656 G4cout <<
" base particle "
657 << base_part_vector[i]->GetParticleName();
662 tables_are_built[i] =
true;
663 part_vector[i] =
nullptr;
669 if (all_tables_are_built) {
675 all_tables_are_built =
true;
677 for(
G4int i=0; i<n_loss; ++i) {
678 if(p == loss_vector[i] && !tables_are_built[i] && !base_part_vector[i]) {
683 <<
" " << tables_are_built[i] <<
" " << base_part_vector[i]
688 CopyTables(curr_part, curr_proc);
690 loss_map[aParticle] = p;
697 if ( !tables_are_built[i] ) { all_tables_are_built =
false; }
700 G4cout <<
"### G4LossTableManager::BuildPhysicsTable end: "
701 <<
"all_tables_are_built= " << all_tables_are_built <<
" "
704 if(all_tables_are_built) {
706 G4cout <<
"%%%%% All dEdx and Range tables are built for master run= "
707 << run <<
" %%%%%" <<
G4endl;
717 for (
G4int j=0; j<n_loss; ++j) {
721 if (!tables_are_built[j] && part == base_part_vector[j]) {
722 tables_are_built[j] =
true;
733 loss_map[part_vector[j]] = proc;
740 <<
" for " << part_vector[j]->GetParticleName()
742 <<
" tables are assigned"
755 G4cout <<
"G4LossTableManager::BuildTables() for "
759 std::vector<G4PhysicsTable*> t_list;
760 std::vector<G4VEnergyLossProcess*> loss_list;
761 std::vector<G4bool> build_flags;
772 for (i=0; i<n_loss; ++i) {
775 G4bool yes = (aParticle == part_vector[i]);
780 for(
G4int j=0; j<nvec; ++j) {
782 if(ptr == (*pvec)[j]) {
789 if(yes && isActive[i]) {
796 if (!tables_are_built[i]) {
802 tables_are_built[i] =
true;
806 t_list.push_back(dedx);
807 loss_list.push_back(p);
808 build_flags.push_back(val);
814 if (0 == n_dedx || !em) {
815 G4cout <<
"G4LossTableManager WARNING: no DEDX processes for "
822 G4cout <<
"G4LossTableManager::BuildTables() start to build range tables"
823 <<
" and the sum of " << n_dedx <<
" processes"
826 <<
" nSubRegions= " << nSubRegions;
833 if(subcutProducer) { nSubRegions = 0; }
855 dedx_vector[iem] = dedx;
859 range_vector[iem] = range;
863 inv_range_vector[iem] = invrange;
875 std::vector<G4PhysicsTable*> listCSDA;
877 for (i=0; i<n_dedx; ++i) {
886 listCSDA.push_back(dedx);
904 G4cout <<
"G4LossTableManager::BuildTables: Tables are built for "
915void G4LossTableManager::ParticleHaveNoLoss(
919 ed <<
"Energy loss process not found for " << aParticle->
GetParticleName()
921 G4Exception(
"G4LossTableManager::ParticleHaveNoLoss",
"em0001",
934const std::vector<G4VEnergyLossProcess*>&
949const std::vector<G4VMultipleScattering*>&
966 if(!emConfigurator) {
969 return emConfigurator;
976 if(!emElectronIonPair) {
979 return emElectronIonPair;
986 if(ptr && ptr != nielCalculator) {
987 delete nielCalculator;
988 nielCalculator = ptr;
996 if(!nielCalculator) {
999 return nielCalculator;
1006 if(atomDeexcitation != p) {
1007 delete atomDeexcitation;
1008 atomDeexcitation = p;
1016 if(subcutProducer != p) {
1017 delete subcutProducer;
1026 G4String ss =
"G4LossTableManager::" + tit;
1049 char* dirName = std::getenv(
"G4PhysListDocDir");
1050 char* physList = std::getenv(
"G4PhysListName");
1051 if (dirName && physList) {
1055 std::ofstream outFile;
1056 outFile.open(pathName);
1058 outFile << physListName <<
G4endl;
1059 outFile << std::string(physListName.length(),
'=') <<
G4endl;
1061 std::vector<G4ParticleDefinition*> particles {
1071 std::vector<G4VEnergyLossProcess*> enloss_vector =
1073 std::vector<G4VMultipleScattering*> mscat_vector =
1076 for (
auto theParticle : particles) {
1077 outFile <<
G4endl <<
"**" << theParticle->GetParticleName()
1084 for (
auto emproc : emproc_vector) {
1085 for (
G4int i = 0; i < plen; ++i) {
1087 if (proc == emproc) {
1095 for (
auto mscproc : mscat_vector) {
1096 for (
G4int i = 0; i < plen; ++i) {
1098 if (proc == mscproc) {
1106 for (
auto enlossproc : enloss_vector) {
1107 for (
G4int i = 0; i < plen; ++i) {
1109 if (proc == enlossproc) {
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
G4GLOB_DLL std::ostream G4cout
static G4Electron * Electron()
void SetVerbose(G4int value)
void PrepareModels(const G4ParticleDefinition *aParticle, G4VEnergyLossProcess *p)
void SetVerbose(G4int verb)
static G4EmParameters * Instance()
G4bool BuildCSDARange() const
G4EmSaturation * GetEmSaturation()
G4int WorkerVerbose() const
void SetIsPrintedFlag(G4bool val)
void BuildRangeTable(const G4PhysicsTable *dedxTable, G4PhysicsTable *rangeTable)
void BuildDEDXTable(G4PhysicsTable *dedxTable, const std::vector< G4PhysicsTable * > &)
void BuildInverseRangeTable(const G4PhysicsTable *rangeTable, G4PhysicsTable *invRangeTable)
void SetInitialisationFlag(G4bool flag)
void SetAtomDeexcitation(G4VAtomDeexcitation *)
static G4LossTableManager * Instance()
const std::vector< G4VEmProcess * > & GetEmProcessVector()
G4VEnergyLossProcess * GetEnergyLossProcess(const G4ParticleDefinition *)
void LocalPhysicsTables(const G4ParticleDefinition *aParticle, G4VEnergyLossProcess *p)
void BuildPhysicsTable(const G4ParticleDefinition *aParticle)
const std::vector< G4VMultipleScattering * > & GetMultipleScatteringVector()
void SetVerbose(G4int val)
void DeRegister(G4VEnergyLossProcess *p)
G4NIELCalculator * NIELCalculator()
void SetNIELCalculator(G4NIELCalculator *)
G4EmConfigurator * EmConfigurator()
void Register(G4VEnergyLossProcess *p)
G4ElectronIonPair * ElectronIonPair()
G4EmSaturation * EmSaturation()
const std::vector< G4VEnergyLossProcess * > & GetEnergyLossProcessVector()
void PreparePhysicsTable(const G4ParticleDefinition *aParticle, G4VEnergyLossProcess *p)
void SetSubCutProducer(G4VSubCutProducer *)
void RegisterExtraParticle(const G4ParticleDefinition *aParticle, G4VEnergyLossProcess *p)
static G4MuonMinus * MuonMinusDefinition()
static G4MuonPlus * MuonPlusDefinition()
G4ProcessManager * GetProcessManager() const
G4double GetPDGCharge() const
const G4String & GetParticleName() const
static G4PhysicsTable * PreparePhysicsTable(G4PhysicsTable *physTable)
static G4Positron * Positron()
G4int GetProcessListLength() const
G4ProcessVector * GetProcessList() const
static G4Proton * ProtonDefinition()
void SetVerboseLevel(G4int)
void InitialiseAtomicDeexcitation()
const G4String & GetName() const
const G4String & GetName() const
const G4ParticleDefinition * BaseParticle() const
G4PhysicsTable * RangeTableForLoss() const
G4PhysicsTable * InverseRangeTable() const
G4PhysicsTable * CSDARangeTable() const
void SetRangeTableForLoss(G4PhysicsTable *p)
G4int NumberOfSubCutoffRegions() const
G4PhysicsTable * BuildDEDXTable(G4EmTableType tType=fRestricted)
const G4ParticleDefinition * Particle() const
void SetInverseRangeTable(G4PhysicsTable *p)
G4bool IsIonisationProcess() const
void SetDEDXTable(G4PhysicsTable *p, G4EmTableType tType)
G4PhysicsTable * BuildLambdaTable(G4EmTableType tType=fRestricted)
void SetIonisation(G4bool val)
void SetLambdaTable(G4PhysicsTable *p)
G4PhysicsTable * IonisationTable() const
G4PhysicsTable * LambdaTable() const
void SetCSDARangeTable(G4PhysicsTable *pRange)
G4PhysicsTable * DEDXunRestrictedTable() const
G4PhysicsTable * DEDXTable() const
virtual void ProcessDescription(std::ostream &outfile) const
const G4String & GetProcessName() const
const G4String & GetName() const