100 for (
G4int i=0; i<n_loss; ++i) {
101 delete loss_vector[i];
103 std::size_t msc = msc_vector.size();
104 for (std::size_t j=0; j<msc; ++j) {
105 delete msc_vector[j];
107 std::size_t emp = emp_vector.size();
108 for (std::size_t k=0; k<emp; ++k) {
109 delete emp_vector[k];
111 emp = p_vector.size();
112 for (std::size_t k=0; k<emp; ++k) {
115 std::size_t mod = mod_vector.size();
116 std::size_t fmod = fmod_vector.size();
118 for (std::size_t a=0; a<mod; ++a) {
120 if(
nullptr != mod_vector[a] ) {
121 for (std::size_t b=0; b<fmod; ++b) {
122 if((
G4VEmModel*)(fmod_vector[b]) == mod_vector[a]) {
123 fmod_vector[b] =
nullptr;
126 delete mod_vector[a];
127 mod_vector[a] =
nullptr;
130 for (std::size_t b=0; b<fmod; ++b) {
131 delete fmod_vector[b];
135 delete emCorrections;
136 delete emConfigurator;
137 delete emElectronIonPair;
138 delete nielCalculator;
139 delete atomDeexcitation;
140 delete subcutProducer;
145G4LossTableManager::G4LossTableManager()
150 startInitialisation =
false;
151 all_tables_are_built =
false;
152 currentLoss =
nullptr;
153 currentParticle =
nullptr;
154 firstParticle =
nullptr;
156 verbose = theParameters->
Verbose();
158 theGenericIon=
nullptr;
165 emConfigurator =
nullptr;
166 emElectronIonPair =
nullptr;
167 atomDeexcitation =
nullptr;
168 subcutProducer =
nullptr;
169 nielCalculator =
nullptr;
171 eGeneral = pGeneral =
nullptr;
176void G4LossTableManager::Clear()
178 all_tables_are_built =
false;
179 currentLoss =
nullptr;
180 currentParticle =
nullptr;
183 range_vector.clear();
184 inv_range_vector.clear();
188 base_part_vector.clear();
189 tables_are_built.clear();
200 for (
G4int i=0; i<n_loss; ++i) {
201 if(loss_vector[i] == p) {
return; }
204 G4cout <<
"G4LossTableManager::Register G4VEnergyLossProcess : "
208 loss_vector.push_back(p);
209 part_vector.push_back(
nullptr);
210 base_part_vector.push_back(
nullptr);
211 dedx_vector.push_back(
nullptr);
212 range_vector.push_back(
nullptr);
213 inv_range_vector.push_back(
nullptr);
214 tables_are_built.push_back(
false);
215 isActive.push_back(
true);
216 all_tables_are_built =
false;
223 verbose = theParameters->
Verbose();
227 if(verbose > 0) { theParameters->
Dump(); }
231 if(
nullptr != emConfigurator) { emConfigurator->
SetVerbose(verbose); };
232 if(
nullptr != emElectronIonPair) { emElectronIonPair->
SetVerbose(verbose); };
233 if(
nullptr != atomDeexcitation) {
244 for (
G4int i=0; i<n_loss; ++i) {
245 if(loss_vector[i] == p) {
246 loss_vector[i] =
nullptr;
257 std::size_t n = msc_vector.size();
258 for (std::size_t i=0; i<n; ++i) {
259 if(msc_vector[i] == p) {
return; }
262 G4cout <<
"G4LossTableManager::Register G4VMultipleScattering : "
265 msc_vector.push_back(p);
273 std::size_t msc = msc_vector.size();
274 for (std::size_t i=0; i<msc; ++i) {
275 if(msc_vector[i] == p) {
276 msc_vector[i] =
nullptr;
287 std::size_t n = emp_vector.size();
288 for (std::size_t i=0; i<n; ++i) {
289 if(emp_vector[i] == p) {
return; }
292 G4cout <<
"G4LossTableManager::Register G4VEmProcess : "
295 emp_vector.push_back(p);
303 std::size_t emp = emp_vector.size();
304 for (std::size_t i=0; i<emp; ++i) {
305 if(emp_vector[i] == p) {
306 emp_vector[i] =
nullptr;
317 std::size_t n = p_vector.size();
318 for (std::size_t i=0; i<n; ++i) {
319 if(p_vector[i] == p) {
return; }
322 G4cout <<
"G4LossTableManager::Register G4VProcess : "
325 p_vector.push_back(p);
333 std::size_t emp = p_vector.size();
334 for (std::size_t i=0; i<emp; ++i) {
335 if(p_vector[i] == p) {
336 p_vector[i] =
nullptr;
346 mod_vector.push_back(p);
348 G4cout <<
"G4LossTableManager::Register G4VEmModel : "
349 << p->
GetName() <<
" " << p <<
" " << mod_vector.size() <<
G4endl;
358 std::size_t n = mod_vector.size();
359 for (std::size_t i=0; i<n; ++i) {
360 if(mod_vector[i] == p) {
361 mod_vector[i] =
nullptr;
371 fmod_vector.push_back(p);
373 G4cout <<
"G4LossTableManager::Register G4VEmFluctuationModel : "
382 std::size_t n = fmod_vector.size();
383 for (std::size_t i=0; i<n; ++i) {
384 if(fmod_vector[i] == p) { fmod_vector[i] =
nullptr; }
394 if(!p || !part) {
return; }
395 for (
G4int i=0; i<n_loss; ++i) {
396 if(loss_vector[i] == p) {
return; }
399 G4cout <<
"G4LossTableManager::RegisterExtraParticle "
404 loss_vector.push_back(p);
405 part_vector.push_back(part);
407 dedx_vector.push_back(
nullptr);
408 range_vector.push_back(
nullptr);
409 inv_range_vector.push_back(
nullptr);
410 tables_are_built.push_back(
false);
411 all_tables_are_built =
false;
419 if(aParticle != currentParticle) {
420 currentParticle = aParticle;
421 std::map<PD,G4VEnergyLossProcess*,std::less<PD> >::const_iterator pos;
422 if ((pos = loss_map.find(aParticle)) != loss_map.end()) {
423 currentLoss = (*pos).second;
425 currentLoss =
nullptr;
427 (pos = loss_map.find(theGenericIon)) != loss_map.end()) {
428 currentLoss = (*pos).second;
443 G4cout <<
"G4LossTableManager::PreparePhysicsTable for "
446 <<
" loss_vector " << loss_vector.size() <<
G4endl;
449 isMaster = theMaster;
451 if(!startInitialisation) {
454 G4cout <<
"====== G4LossTableManager::PreparePhysicsTable start ====="
461 if(emConfigurator) { emConfigurator->
PrepareModels(particle, p); }
464 for (
G4int j=0; j<n_loss; ++j) {
465 if (p == loss_vector[j] && !part_vector[j]) {
466 part_vector[j] = particle;
468 theGenericIon = particle;
473 startInitialisation =
true;
483 G4cout <<
"G4LossTableManager::PreparePhysicsTable for "
487 isMaster = theMaster;
489 if(!startInitialisation) {
492 G4cout <<
"====== G4LossTableManager::PreparePhysicsTable start ====="
499 if(emConfigurator) { emConfigurator->
PrepareModels(particle, p); }
501 startInitialisation =
true;
512 G4cout <<
"G4LossTableManager::PreparePhysicsTable for "
517 isMaster = theMaster;
519 if(!startInitialisation) {
522 G4cout <<
"====== G4LossTableManager::PreparePhysicsTable start ====="
529 if(emConfigurator) { emConfigurator->
PrepareModels(particle, p); }
531 startInitialisation =
true;
539 if(-1 == run && startInitialisation) {
540 if(emConfigurator) { emConfigurator->
Clear(); }
551 G4cout <<
"### G4LossTableManager::LocalPhysicsTable() for "
557 if(-1 == run && startInitialisation) {
558 if(emConfigurator) { emConfigurator->
Clear(); }
559 firstParticle = aParticle;
562 if(startInitialisation) {
565 G4cout <<
"===== G4LossTableManager::LocalPhysicsTable() for run "
566 << run <<
" =====" <<
G4endl;
568 currentParticle =
nullptr;
569 startInitialisation =
false;
570 for (
G4int i=0; i<n_loss; ++i) {
572 tables_are_built[i] =
false;
574 tables_are_built[i] =
true;
575 part_vector[i] =
nullptr;
580 all_tables_are_built=
true;
581 for (
G4int i=0; i<n_loss; ++i) {
582 if(p == loss_vector[i]) {
583 tables_are_built[i] =
true;
591 loss_map[part_vector[i]] = p;
599 G4cout <<
" for " << part_vector[i]->GetParticleName();
601 G4cout <<
" active= " << isActive[i]
602 <<
" table= " << tables_are_built[i]
607 }
else if(!tables_are_built[i]) {
608 all_tables_are_built =
false;
613 G4cout <<
"### G4LossTableManager::LocalPhysicsTable end"
616 if(all_tables_are_built) {
618 G4cout <<
"%%%%% All dEdx and Range tables for worker are ready for run "
619 << run <<
" %%%%%" <<
G4endl;
631 G4cout <<
"### G4LossTableManager::BuildPhysicsTable() for "
636 if(-1 == run && startInitialisation) {
637 if(emConfigurator) { emConfigurator->
Clear(); }
638 firstParticle = aParticle;
640 if(startInitialisation) {
643 G4cout <<
"===== G4LossTableManager::BuildPhysicsTable() for run "
644 << run <<
" ===== " << atomDeexcitation <<
G4endl;
646 currentParticle =
nullptr;
647 all_tables_are_built=
true;
651 if ( startInitialisation && aParticle == firstParticle ) {
653 startInitialisation =
false;
655 G4cout <<
"### G4LossTableManager start initialisation for first particle "
660 if(nielCalculator) { nielCalculator->
Initialise(); }
662 for (
G4int i=0; i<n_loss; ++i) {
668 tables_are_built[i] =
false;
669 all_tables_are_built=
false;
672 tables_are_built[i] =
true;
680 G4cout <<
" active= " << isActive[i]
681 <<
" table= " << tables_are_built[i]
683 if(base_part_vector[i]) {
684 G4cout <<
" base particle "
685 << base_part_vector[i]->GetParticleName();
690 tables_are_built[i] =
true;
691 part_vector[i] =
nullptr;
697 if (all_tables_are_built) {
703 all_tables_are_built =
true;
705 for(
G4int i=0; i<n_loss; ++i) {
706 if(p == loss_vector[i] && !tables_are_built[i] && !base_part_vector[i]) {
711 <<
" " << tables_are_built[i] <<
" " << base_part_vector[i]
716 CopyTables(curr_part, curr_proc);
718 loss_map[aParticle] = p;
725 if ( !tables_are_built[i] ) { all_tables_are_built =
false; }
728 G4cout <<
"### G4LossTableManager::BuildPhysicsTable end: "
729 <<
"all_tables_are_built= " << all_tables_are_built <<
" "
732 if(all_tables_are_built) {
734 G4cout <<
"%%%%% All dEdx and Range tables are built for master run= "
735 << run <<
" %%%%%" <<
G4endl;
745 for (
G4int j=0; j<n_loss; ++j) {
749 if (!tables_are_built[j] && part == base_part_vector[j]) {
750 tables_are_built[j] =
true;
761 loss_map[part_vector[j]] = proc;
768 <<
" for " << part_vector[j]->GetParticleName()
770 <<
" tables are assigned"
783 G4cout <<
"G4LossTableManager::BuildTables() for "
787 std::vector<G4PhysicsTable*> t_list;
788 std::vector<G4VEnergyLossProcess*> loss_list;
789 std::vector<G4bool> build_flags;
800 for (i=0; i<n_loss; ++i) {
803 G4bool yes = (aParticle == part_vector[i]);
808 for(
G4int j=0; j<nvec; ++j) {
810 if(ptr == (*pvec)[j]) {
817 if(yes && isActive[i]) {
824 if (!tables_are_built[i]) {
830 tables_are_built[i] =
true;
835 loss_list.push_back(p);
836 build_flags.push_back(val);
842 if (0 == n_dedx || !em) {
843 G4cout <<
"G4LossTableManager WARNING: no DEDX processes for "
850 G4cout <<
"G4LossTableManager::BuildTables() start to build range tables"
851 <<
" and the sum of " << n_dedx <<
" processes"
854 <<
" nSubRegions= " << nSubRegions;
861 if(subcutProducer) { nSubRegions = 0; }
883 dedx_vector[iem] = dedx;
887 range_vector[iem] = range;
891 inv_range_vector[iem] = invrange;
903 std::vector<G4PhysicsTable*> listSub;
904 std::vector<G4PhysicsTable*> listCSDA;
906 for (i=0; i<n_dedx; ++i) {
915 listCSDA.push_back(dedx);
934 G4cout <<
"G4LossTableManager::BuildTables: Tables are built for "
945void G4LossTableManager::ParticleHaveNoLoss(
949 ed <<
"Energy loss process not found for " << aParticle->
GetParticleName()
951 G4Exception(
"G4LossTableManager::ParticleHaveNoLoss",
"em0001",
964const std::vector<G4VEnergyLossProcess*>&
979const std::vector<G4VMultipleScattering*>&
996 if(!emConfigurator) {
999 return emConfigurator;
1006 if(!emElectronIonPair) {
1009 return emElectronIonPair;
1016 if(ptr && ptr != nielCalculator) {
1017 delete nielCalculator;
1018 nielCalculator = ptr;
1026 if(!nielCalculator) {
1029 return nielCalculator;
1036 if(atomDeexcitation != p) {
1037 delete atomDeexcitation;
1038 atomDeexcitation = p;
1046 if(subcutProducer != p) {
1047 delete subcutProducer;
1056 G4String ss =
"G4LossTableManager::" + tit;
1079 char* dirName = std::getenv(
"G4PhysListDocDir");
1080 char* physList = std::getenv(
"G4PhysListName");
1081 if (dirName && physList) {
1085 std::ofstream outFile;
1086 outFile.open(pathName);
1088 outFile << physListName <<
G4endl;
1089 outFile << std::string(physListName.length(),
'=') <<
G4endl;
1091 std::vector<G4ParticleDefinition*> particles {
1101 std::vector<G4VEnergyLossProcess*> enloss_vector =
1103 std::vector<G4VMultipleScattering*> mscat_vector =
1106 for (
auto theParticle : particles) {
1107 outFile <<
G4endl <<
"**" << theParticle->GetParticleName()
1114 for (
auto emproc : emproc_vector) {
1115 for (
G4int i = 0; i < plen; ++i) {
1117 if (proc == emproc) {
1125 for (
auto mscproc : mscat_vector) {
1126 for (
G4int i = 0; i < plen; ++i) {
1128 if (proc == mscproc) {
1136 for (
auto enlossproc : enloss_vector) {
1137 for (
G4int i = 0; i < plen; ++i) {
1139 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 PreparePhysicsTable(const G4ParticleDefinition *aParticle, G4VEnergyLossProcess *p, G4bool theMaster)
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 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)
void push_back(G4PhysicsVector *)
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