100 for (
G4int i=0; i<n_loss; ++i) {
101 delete loss_vector[i];
103 size_t msc = msc_vector.size();
104 for (
size_t j=0; j<msc; ++j) {
105 delete msc_vector[j];
107 size_t emp = emp_vector.size();
108 for (
size_t k=0; k<emp; ++k) {
109 delete emp_vector[k];
111 emp = p_vector.size();
112 for (
size_t k=0; k<emp; ++k) {
115 size_t mod = mod_vector.size();
116 size_t fmod = fmod_vector.size();
118 for (
size_t a=0; a<mod; ++a) {
120 if(
nullptr != mod_vector[a] ) {
121 for (
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 (
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();
230 if(emConfigurator) { emConfigurator->
SetVerbose(verbose); };
231 if(emElectronIonPair) { emElectronIonPair->
SetVerbose(verbose); };
232 if(atomDeexcitation) {
243 for (
G4int i=0; i<n_loss; ++i) {
244 if(loss_vector[i] == p) {
245 loss_vector[i] =
nullptr;
256 G4int n = msc_vector.size();
257 for (
G4int i=0; i<n; ++i) {
258 if(msc_vector[i] == p) {
return; }
261 G4cout <<
"G4LossTableManager::Register G4VMultipleScattering : "
264 msc_vector.push_back(p);
272 size_t msc = msc_vector.size();
273 for (
size_t i=0; i<msc; ++i) {
274 if(msc_vector[i] == p) {
275 msc_vector[i] =
nullptr;
286 G4int n = emp_vector.size();
287 for (
G4int i=0; i<n; ++i) {
288 if(emp_vector[i] == p) {
return; }
291 G4cout <<
"G4LossTableManager::Register G4VEmProcess : "
294 emp_vector.push_back(p);
302 size_t emp = emp_vector.size();
303 for (
size_t i=0; i<emp; ++i) {
304 if(emp_vector[i] == p) {
305 emp_vector[i] =
nullptr;
316 G4int n = p_vector.size();
317 for (
G4int i=0; i<n; ++i) {
318 if(p_vector[i] == p) {
return; }
321 G4cout <<
"G4LossTableManager::Register G4VProcess : "
324 p_vector.push_back(p);
332 size_t emp = p_vector.size();
333 for (
size_t i=0; i<emp; ++i) {
334 if(p_vector[i] == p) {
335 p_vector[i] =
nullptr;
345 mod_vector.push_back(p);
347 G4cout <<
"G4LossTableManager::Register G4VEmModel : "
348 << p->
GetName() <<
" " << p <<
" " << mod_vector.size() <<
G4endl;
357 size_t n = mod_vector.size();
358 for (
size_t i=0; i<n; ++i) {
359 if(mod_vector[i] == p) {
360 mod_vector[i] =
nullptr;
370 fmod_vector.push_back(p);
372 G4cout <<
"G4LossTableManager::Register G4VEmFluctuationModel : "
381 size_t n = fmod_vector.size();
382 for (
size_t i=0; i<n; ++i) {
383 if(fmod_vector[i] == p) { fmod_vector[i] =
nullptr; }
393 if(!p || !part) {
return; }
394 for (
G4int i=0; i<n_loss; ++i) {
395 if(loss_vector[i] == p) {
return; }
398 G4cout <<
"G4LossTableManager::RegisterExtraParticle "
403 loss_vector.push_back(p);
404 part_vector.push_back(part);
406 dedx_vector.push_back(
nullptr);
407 range_vector.push_back(
nullptr);
408 inv_range_vector.push_back(
nullptr);
409 tables_are_built.push_back(
false);
410 all_tables_are_built =
false;
420 if(aParticle != currentParticle) {
421 currentParticle = aParticle;
422 std::map<PD,G4VEnergyLossProcess*,std::less<PD> >::const_iterator pos;
423 if ((pos = loss_map.find(aParticle)) != loss_map.end()) {
424 currentLoss = (*pos).second;
426 currentLoss =
nullptr;
427 if ((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) {
return; }
700 all_tables_are_built =
true;
702 for(
G4int i=0; i<n_loss; ++i) {
703 if(p == loss_vector[i] && !tables_are_built[i] && !base_part_vector[i]) {
708 <<
" " << tables_are_built[i] <<
" " << base_part_vector[i]
713 CopyTables(curr_part, curr_proc);
715 loss_map[aParticle] = p;
722 if ( !tables_are_built[i] ) { all_tables_are_built =
false; }
725 G4cout <<
"### G4LossTableManager::BuildPhysicsTable end: "
726 <<
"all_tables_are_built= " << all_tables_are_built <<
" "
729 if(all_tables_are_built) {
731 G4cout <<
"%%%%% All dEdx and Range tables are built for master run= "
732 << run <<
" %%%%%" <<
G4endl;
742 for (
G4int j=0; j<n_loss; ++j) {
746 if (!tables_are_built[j] && part == base_part_vector[j]) {
747 tables_are_built[j] =
true;
760 loss_map[part_vector[j]] = proc;
767 <<
" for " << part_vector[j]->GetParticleName()
769 <<
" tables are assigned"
786 G4cout <<
"G4LossTableManager::BuildTables() for "
790 std::vector<G4PhysicsTable*> t_list;
791 std::vector<G4VEnergyLossProcess*> loss_list;
792 std::vector<G4bool> build_flags;
803 for (i=0; i<n_loss; ++i) {
806 G4bool yes = (aParticle == part_vector[i]);
811 for(
G4int j=0; j<nvec; ++j) {
813 if(ptr == (*pvec)[j]) {
820 if(yes && isActive[i]) {
827 if (!tables_are_built[i]) {
833 tables_are_built[i] =
true;
838 loss_list.push_back(p);
839 build_flags.push_back(val);
844 G4int n_dedx = t_list.size();
845 if (0 == n_dedx || !em) {
846 G4cout <<
"G4LossTableManager WARNING: no DEDX processes for "
853 G4cout <<
"G4LossTableManager::BuildTables() start to build range tables"
854 <<
" and the sum of " << n_dedx <<
" processes"
857 <<
" nSubRegions= " << nSubRegions;
864 if(subcutProducer) { nSubRegions = 0; }
886 dedx_vector[iem] = dedx;
890 range_vector[iem] = range;
894 inv_range_vector[iem] = invrange;
906 std::vector<G4PhysicsTable*> listSub;
907 std::vector<G4PhysicsTable*> listCSDA;
909 for (i=0; i<n_dedx; ++i) {
915 if (0 < nSubRegions) {
918 listSub.push_back(dedx);
927 listCSDA.push_back(dedx);
931 if (0 < nSubRegions) {
933 if (1 < listSub.size()) {
956 G4cout <<
"G4LossTableManager::BuildTables: Tables are built for "
967void G4LossTableManager::ParticleHaveNoLoss(
971 ed <<
"Energy loss process not found for " << aParticle->
GetParticleName()
973 G4Exception(
"G4LossTableManager::ParticleHaveNoLoss",
"em0001",
986const std::vector<G4VEnergyLossProcess*>&
1001const std::vector<G4VMultipleScattering*>&
1018 if(!emConfigurator) {
1021 return emConfigurator;
1028 if(!emElectronIonPair) {
1031 return emElectronIonPair;
1038 if(ptr && ptr != nielCalculator) {
1039 delete nielCalculator;
1040 nielCalculator = ptr;
1048 if(!nielCalculator) {
1051 return nielCalculator;
1058 if(atomDeexcitation != p) {
1059 delete atomDeexcitation;
1060 atomDeexcitation = p;
1068 if(subcutProducer != p) {
1069 delete subcutProducer;
1078 G4String ss =
"G4LossTableManager::" + tit;
1101 char* dirName = std::getenv(
"G4PhysListDocDir");
1102 char* physList = std::getenv(
"G4PhysListName");
1103 if (dirName && physList) {
1107 std::ofstream outFile;
1108 outFile.open(pathName);
1110 outFile << physListName <<
G4endl;
1111 outFile << std::string(physListName.length(),
'=') <<
G4endl;
1113 std::vector<G4ParticleDefinition*> particles {
1123 std::vector<G4VEnergyLossProcess*> enloss_vector =
1125 std::vector<G4VMultipleScattering*> mscat_vector =
1128 for (
auto theParticle : particles) {
1129 outFile <<
G4endl <<
"**" << theParticle->GetParticleName()
1136 for (
auto emproc : emproc_vector) {
1137 for (
G4int i = 0; i < plen; ++i) {
1139 if (proc == emproc) {
1147 for (
auto mscproc : mscat_vector) {
1148 for (
G4int i = 0; i < plen; ++i) {
1150 if (proc == mscproc) {
1158 for (
auto enlossproc : enloss_vector) {
1159 for (
G4int i = 0; i < plen; ++i) {
1161 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 BuildInverseRangeTable(const G4PhysicsTable *rangeTable, G4PhysicsTable *invRangeTable, G4bool useBM=false)
void BuildRangeTable(const G4PhysicsTable *dedxTable, G4PhysicsTable *rangeTable, G4bool useBM=false)
void BuildDEDXTable(G4PhysicsTable *dedxTable, const std::vector< G4PhysicsTable * > &)
void SetSplineFlag(G4bool flag)
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
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)
void AddCollaborativeProcess(G4VEnergyLossProcess *)
G4PhysicsTable * DEDXTableForSubsec() const
G4PhysicsTable * IonisationTableForSubsec() const
const G4ParticleDefinition * Particle() const
void SetInverseRangeTable(G4PhysicsTable *p)
G4PhysicsTable * SubLambdaTable() const
G4bool IsIonisationProcess() const
void SetDEDXTable(G4PhysicsTable *p, G4EmTableType tType)
void SetSecondaryRangeTable(G4PhysicsTable *p)
G4PhysicsTable * BuildLambdaTable(G4EmTableType tType=fRestricted)
void SetIonisation(G4bool val)
void SetSubLambdaTable(G4PhysicsTable *p)
void SetLambdaTable(G4PhysicsTable *p)
G4PhysicsTable * IonisationTable() const
G4PhysicsTable * LambdaTable() const
void SetCSDARangeTable(G4PhysicsTable *pRange)
G4PhysicsTable * DEDXunRestrictedTable() const
G4PhysicsTable * DEDXTable() const
const G4ParticleDefinition * SecondaryParticle() const
virtual void ProcessDescription(std::ostream &outfile) const
const G4String & GetProcessName() const
const G4String & GetName() const