Geant4-11
G4LossTableManager.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// -------------------------------------------------------------------
27//
28// GEANT4 Class file
29//
30//
31// File name: G4LossTableManager
32//
33// Author: Vladimir Ivanchenko
34//
35// Creation date: 03.01.2002
36//
37// Modifications: by V.Ivanchenko
38//
39//
40// Class Description:
41//
42// -------------------------------------------------------------------
43//
44//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
45//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
46
47#include "G4LossTableManager.hh"
48#include "G4SystemOfUnits.hh"
49
51#include "G4VEmProcess.hh"
52
53#include "G4EmParameters.hh"
54#include "G4EmSaturation.hh"
55#include "G4EmConfigurator.hh"
56#include "G4ElectronIonPair.hh"
57#include "G4NIELCalculator.hh"
58#include "G4EmCorrections.hh"
59#include "G4LossTableBuilder.hh"
61#include "G4VSubCutProducer.hh"
62
63#include "G4PhysicsTable.hh"
66#include "G4ProcessManager.hh"
67#include "G4Electron.hh"
68#include "G4Proton.hh"
71#include "G4EmTableType.hh"
72#include "G4Region.hh"
74#include "G4Threading.hh"
75
76#include "G4Gamma.hh"
77#include "G4Positron.hh"
78#include "G4OpticalPhoton.hh"
79#include "G4Neutron.hh"
80#include "G4MuonPlus.hh"
81#include "G4MuonMinus.hh"
82
83//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
84
86
88{
89 if(!instance) {
91 instance = inst.Instance();
92 }
93 return instance;
94}
95
96//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
97
99{
100 for (G4int i=0; i<n_loss; ++i) {
101 delete loss_vector[i];
102 }
103 size_t msc = msc_vector.size();
104 for (size_t j=0; j<msc; ++j) {
105 delete msc_vector[j];
106 }
107 size_t emp = emp_vector.size();
108 for (size_t k=0; k<emp; ++k) {
109 delete emp_vector[k];
110 }
111 emp = p_vector.size();
112 for (size_t k=0; k<emp; ++k) {
113 delete p_vector[k];
114 }
115 size_t mod = mod_vector.size();
116 size_t fmod = fmod_vector.size();
117 //G4cout << " Nmod" << mod << " Nfluc= " << fmod << G4endl;
118 for (size_t a=0; a<mod; ++a) {
119 //G4cout << "Delete model #" << a << " " << mod_vector[a] << G4endl;
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;
124 }
125 }
126 delete mod_vector[a];
127 mod_vector[a] = nullptr;
128 }
129 }
130 for (size_t b=0; b<fmod; ++b) {
131 delete fmod_vector[b];
132 }
133 Clear();
134 delete tableBuilder;
135 delete emCorrections;
136 delete emConfigurator;
137 delete emElectronIonPair;
138 delete nielCalculator;
139 delete atomDeexcitation;
140 delete subcutProducer;
141}
142
143//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
144
146{
148 n_loss = 0;
149 run = -1;
150 startInitialisation = false;
151 all_tables_are_built = false;
152 currentLoss = nullptr;
153 currentParticle = nullptr;
154 firstParticle = nullptr;
155 isMaster = true;
158 theGenericIon= nullptr;
161 isMaster = false;
162 }
165 emConfigurator = nullptr;
166 emElectronIonPair = nullptr;
167 atomDeexcitation = nullptr;
168 subcutProducer = nullptr;
169 nielCalculator = nullptr;
170 gGeneral = nullptr;
171 eGeneral = pGeneral = nullptr;
172}
173
174//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
175
177{
178 all_tables_are_built = false;
179 currentLoss = nullptr;
180 currentParticle = nullptr;
181 if(n_loss) {
182 dedx_vector.clear();
183 range_vector.clear();
184 inv_range_vector.clear();
185 loss_map.clear();
186 loss_vector.clear();
187 part_vector.clear();
188 base_part_vector.clear();
189 tables_are_built.clear();
190 isActive.clear();
191 n_loss = 0;
192 }
193}
194
195//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
196
198{
199 if(!p) { return; }
200 for (G4int i=0; i<n_loss; ++i) {
201 if(loss_vector[i] == p) { return; }
202 }
203 if(verbose > 1) {
204 G4cout << "G4LossTableManager::Register G4VEnergyLossProcess : "
205 << p->GetProcessName() << " idx= " << n_loss << G4endl;
206 }
207 ++n_loss;
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;
217}
218
219//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
220
222{
224 if(!isMaster) {
226 } else {
227 if(verbose > 0) { theParameters->Dump(); }
228 }
231 if(nullptr != emConfigurator) { emConfigurator->SetVerbose(verbose); };
233 if(nullptr != atomDeexcitation) {
236 }
237}
238
239//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
240
242{
243 if(!p) { return; }
244 for (G4int i=0; i<n_loss; ++i) {
245 if(loss_vector[i] == p) {
246 loss_vector[i] = nullptr;
247 break;
248 }
249 }
250}
251
252//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
253
255{
256 if(!p) { return; }
257 G4int n = msc_vector.size();
258 for (G4int i=0; i<n; ++i) {
259 if(msc_vector[i] == p) { return; }
260 }
261 if(verbose > 1) {
262 G4cout << "G4LossTableManager::Register G4VMultipleScattering : "
263 << p->GetProcessName() << " idx= " << msc_vector.size() << G4endl;
264 }
265 msc_vector.push_back(p);
266}
267
268//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
269
271{
272 if(!p) { return; }
273 size_t msc = msc_vector.size();
274 for (size_t i=0; i<msc; ++i) {
275 if(msc_vector[i] == p) {
276 msc_vector[i] = nullptr;
277 break;
278 }
279 }
280}
281
282//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
283
285{
286 if(!p) { return; }
287 G4int n = emp_vector.size();
288 for (G4int i=0; i<n; ++i) {
289 if(emp_vector[i] == p) { return; }
290 }
291 if(verbose > 1) {
292 G4cout << "G4LossTableManager::Register G4VEmProcess : "
293 << p->GetProcessName() << " idx= " << emp_vector.size() << G4endl;
294 }
295 emp_vector.push_back(p);
296}
297
298//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
299
301{
302 if(!p) { return; }
303 size_t emp = emp_vector.size();
304 for (size_t i=0; i<emp; ++i) {
305 if(emp_vector[i] == p) {
306 emp_vector[i] = nullptr;
307 break;
308 }
309 }
310}
311
312//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
313
315{
316 if(!p) { return; }
317 G4int n = p_vector.size();
318 for (G4int i=0; i<n; ++i) {
319 if(p_vector[i] == p) { return; }
320 }
321 if(verbose > 1) {
322 G4cout << "G4LossTableManager::Register G4VProcess : "
323 << p->GetProcessName() << " idx= " << p_vector.size() << G4endl;
324 }
325 p_vector.push_back(p);
326}
327
328//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
329
331{
332 if(!p) { return; }
333 size_t emp = p_vector.size();
334 for (size_t i=0; i<emp; ++i) {
335 if(p_vector[i] == p) {
336 p_vector[i] = nullptr;
337 break;
338 }
339 }
340}
341
342//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
343
345{
346 mod_vector.push_back(p);
347 if(verbose > 1) {
348 G4cout << "G4LossTableManager::Register G4VEmModel : "
349 << p->GetName() << " " << p << " " << mod_vector.size() << G4endl;
350 }
351}
352
353//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
354
356{
357 //G4cout << "G4LossTableManager::DeRegister G4VEmModel : " << p << G4endl;
358 size_t n = mod_vector.size();
359 for (size_t i=0; i<n; ++i) {
360 if(mod_vector[i] == p) {
361 mod_vector[i] = nullptr;
362 break;
363 }
364 }
365}
366
367//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
368
370{
371 fmod_vector.push_back(p);
372 if(verbose > 1) {
373 G4cout << "G4LossTableManager::Register G4VEmFluctuationModel : "
374 << p->GetName() << " " << fmod_vector.size() << G4endl;
375 }
376}
377
378//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
379
381{
382 size_t n = fmod_vector.size();
383 for (size_t i=0; i<n; ++i) {
384 if(fmod_vector[i] == p) { fmod_vector[i] = nullptr; }
385 }
386}
387
388//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
389
391 const G4ParticleDefinition* part,
393{
394 if(!p || !part) { return; }
395 for (G4int i=0; i<n_loss; ++i) {
396 if(loss_vector[i] == p) { return; }
397 }
398 if(verbose > 1) {
399 G4cout << "G4LossTableManager::RegisterExtraParticle "
400 << part->GetParticleName() << " G4VEnergyLossProcess : "
401 << p->GetProcessName() << " idx= " << n_loss << G4endl;
402 }
403 ++n_loss;
404 loss_vector.push_back(p);
405 part_vector.push_back(part);
406 base_part_vector.push_back(p->BaseParticle());
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;
412}
413
414//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
415
418{
419 //G4cout << "G4LossTableManager::GetEnergyLossProcess: "
420 //<< aParticle << " " << currentParticle << " " << currentLoss << G4endl;
421 if(aParticle != currentParticle) {
422 currentParticle = aParticle;
423 std::map<PD,G4VEnergyLossProcess*,std::less<PD> >::const_iterator pos;
424 if ((pos = loss_map.find(aParticle)) != loss_map.end()) {
425 currentLoss = (*pos).second;
426 } else {
427 currentLoss = nullptr;
428 if ((pos = loss_map.find(theGenericIon)) != loss_map.end()) {
429 currentLoss = (*pos).second;
430 }
431 }
432 }
433 return currentLoss;
434}
435
436//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
437
438void
441 G4bool theMaster)
442{
443 if (1 < verbose) {
444 G4cout << "G4LossTableManager::PreparePhysicsTable for "
445 << particle->GetParticleName()
446 << " and " << p->GetProcessName() << " run= " << run
447 << " loss_vector " << loss_vector.size() << G4endl;
448 }
449
450 isMaster = theMaster;
451
452 if(!startInitialisation) {
454 if (1 < verbose) {
455 G4cout << "====== G4LossTableManager::PreparePhysicsTable start ====="
456 << G4endl;
457 }
458 }
459
460 // start initialisation for the first run
461 if( -1 == run ) {
462 if(emConfigurator) { emConfigurator->PrepareModels(particle, p); }
463
464 // initialise particles for given process
465 for (G4int j=0; j<n_loss; ++j) {
466 if (p == loss_vector[j] && !part_vector[j]) {
467 part_vector[j] = particle;
468 if(particle->GetParticleName() == "GenericIon") {
469 theGenericIon = particle;
470 }
471 }
472 }
473 }
474 startInitialisation = true;
475}
476
477//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
478
479void
481 G4VEmProcess* p, G4bool theMaster)
482{
483 if (1 < verbose) {
484 G4cout << "G4LossTableManager::PreparePhysicsTable for "
485 << particle->GetParticleName()
486 << " and " << p->GetProcessName() << G4endl;
487 }
488 isMaster = theMaster;
489
490 if(!startInitialisation) {
492 if (1 < verbose) {
493 G4cout << "====== G4LossTableManager::PreparePhysicsTable start ====="
494 << G4endl;
495 }
496 }
497
498 // start initialisation for the first run
499 if( -1 == run ) {
500 if(emConfigurator) { emConfigurator->PrepareModels(particle, p); }
501 }
502 startInitialisation = true;
503}
504
505//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
506
507void
510 G4bool theMaster)
511{
512 if (1 < verbose) {
513 G4cout << "G4LossTableManager::PreparePhysicsTable for "
514 << particle->GetParticleName()
515 << " and " << p->GetProcessName() << G4endl;
516 }
517
518 isMaster = theMaster;
519
520 if(!startInitialisation) {
522 if (1 < verbose) {
523 G4cout << "====== G4LossTableManager::PreparePhysicsTable start ====="
524 << G4endl;
525 }
526 }
527
528 // start initialisation for the first run
529 if( -1 == run ) {
530 if(emConfigurator) { emConfigurator->PrepareModels(particle, p); }
531 }
532 startInitialisation = true;
533}
534
535//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
536
537void
539{
540 if(-1 == run && startInitialisation) {
542 }
543}
544
545//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
546
548 const G4ParticleDefinition* aParticle,
550{
551 if(1 < verbose) {
552 G4cout << "### G4LossTableManager::LocalPhysicsTable() for "
553 << aParticle->GetParticleName()
554 << " and process " << p->GetProcessName()
555 << G4endl;
556 }
557
558 if(-1 == run && startInitialisation) {
560 firstParticle = aParticle;
561 }
562
564 ++run;
565 if(1 < verbose) {
566 G4cout << "===== G4LossTableManager::LocalPhysicsTable() for run "
567 << run << " =====" << G4endl;
568 }
569 currentParticle = nullptr;
570 startInitialisation = false;
571 for (G4int i=0; i<n_loss; ++i) {
572 if(loss_vector[i]) {
573 tables_are_built[i] = false;
574 } else {
575 tables_are_built[i] = true;
576 part_vector[i] = nullptr;
577 }
578 }
579 }
580
582 for (G4int i=0; i<n_loss; ++i) {
583 if(p == loss_vector[i]) {
584 tables_are_built[i] = true;
585 isActive[i] = true;
586 part_vector[i] = p->Particle();
588 dedx_vector[i] = p->DEDXTable();
591 if(0 == run && p->IsIonisationProcess()) {
592 loss_map[part_vector[i]] = p;
593 //G4cout << "G4LossTableManager::LocalPhysicsTable " << part_vector[i]->GetParticleName()
594 // << " added to map " << p << G4endl;
595 }
596
597 if(1 < verbose) {
598 G4cout << i <<". "<< p->GetProcessName();
599 if(part_vector[i]) {
600 G4cout << " for " << part_vector[i]->GetParticleName();
601 }
602 G4cout << " active= " << isActive[i]
603 << " table= " << tables_are_built[i]
604 << " isIonisation= " << p->IsIonisationProcess()
605 << G4endl;
606 }
607 break;
608 } else if(!tables_are_built[i]) {
609 all_tables_are_built = false;
610 }
611 }
612
613 if(1 < verbose) {
614 G4cout << "### G4LossTableManager::LocalPhysicsTable end"
615 << G4endl;
616 }
618 if(1 < verbose) {
619 G4cout << "%%%%% All dEdx and Range tables for worker are ready for run "
620 << run << " %%%%%" << G4endl;
621 }
622 }
623}
624
625//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
626
628 const G4ParticleDefinition* aParticle,
630{
631 if(1 < verbose) {
632 G4cout << "### G4LossTableManager::BuildPhysicsTable() for "
633 << aParticle->GetParticleName()
634 << " and process " << p->GetProcessName() << G4endl;
635 }
636 // clear configurator
637 if(-1 == run && startInitialisation) {
639 firstParticle = aParticle;
640 }
642 ++run;
643 if(1 < verbose) {
644 G4cout << "===== G4LossTableManager::BuildPhysicsTable() for run "
645 << run << " ===== " << atomDeexcitation << G4endl;
646 }
647 currentParticle = nullptr;
649 }
650
651 // initialisation before any table is built
652 if ( startInitialisation && aParticle == firstParticle ) {
653
654 startInitialisation = false;
655 if(1 < verbose) {
656 G4cout << "### G4LossTableManager start initialisation for first particle "
658 << G4endl;
659 }
660
662
663 for (G4int i=0; i<n_loss; ++i) {
665
666 if(el) {
667 isActive[i] = true;
668 base_part_vector[i] = el->BaseParticle();
669 tables_are_built[i] = false;
671 if(!isActive[i]) {
672 el->SetIonisation(false);
673 tables_are_built[i] = true;
674 }
675
676 if(1 < verbose) {
677 G4cout << i <<". "<< el->GetProcessName();
678 if(el->Particle()) {
679 G4cout << " for " << el->Particle()->GetParticleName();
680 }
681 G4cout << " active= " << isActive[i]
682 << " table= " << tables_are_built[i]
683 << " isIonisation= " << el->IsIonisationProcess();
684 if(base_part_vector[i]) {
685 G4cout << " base particle "
686 << base_part_vector[i]->GetParticleName();
687 }
688 G4cout << G4endl;
689 }
690 } else {
691 tables_are_built[i] = true;
692 part_vector[i] = nullptr;
693 isActive[i] = false;
694 }
695 }
696 }
697
700 return;
701 }
702
703 // Build tables for given particle
705
706 for(G4int i=0; i<n_loss; ++i) {
707 if(p == loss_vector[i] && !tables_are_built[i] && !base_part_vector[i]) {
708 const G4ParticleDefinition* curr_part = part_vector[i];
709 if(1 < verbose) {
710 G4cout << "### Build Table for " << p->GetProcessName()
711 << " and " << curr_part->GetParticleName()
712 << " " << tables_are_built[i] << " " << base_part_vector[i]
713 << G4endl;
714 }
715 G4VEnergyLossProcess* curr_proc = BuildTables(curr_part);
716 if(curr_proc) {
717 CopyTables(curr_part, curr_proc);
718 if(p == curr_proc && 0 == run && p->IsIonisationProcess()) {
719 loss_map[aParticle] = p;
720 //G4cout << "G4LossTableManager::BuildPhysicsTable: "
721 // << aParticle->GetParticleName()
722 // << " added to map " << p << G4endl;
723 }
724 }
725 }
726 if ( !tables_are_built[i] ) { all_tables_are_built = false; }
727 }
728 if(1 < verbose) {
729 G4cout << "### G4LossTableManager::BuildPhysicsTable end: "
730 << "all_tables_are_built= " << all_tables_are_built << " "
731 << aParticle->GetParticleName() << " proc: " << p << G4endl;
732 }
734 if(1 < verbose) {
735 G4cout << "%%%%% All dEdx and Range tables are built for master run= "
736 << run << " %%%%%" << G4endl;
737 }
738 }
739}
740
741//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
742
744 G4VEnergyLossProcess* base_proc)
745{
746 for (G4int j=0; j<n_loss; ++j) {
747
749
750 if (!tables_are_built[j] && part == base_part_vector[j]) {
751 tables_are_built[j] = true;
752 proc->SetDEDXTable(base_proc->IonisationTable(),fRestricted);
753 proc->SetDEDXTable(base_proc->DEDXunRestrictedTable(),fTotal);
754 proc->SetCSDARangeTable(base_proc->CSDARangeTable());
755 proc->SetRangeTableForLoss(base_proc->RangeTableForLoss());
756 proc->SetInverseRangeTable(base_proc->InverseRangeTable());
757 proc->SetLambdaTable(base_proc->LambdaTable());
758 proc->SetIonisation(base_proc->IsIonisationProcess());
759 if(proc->IsIonisationProcess()) {
760 range_vector[j] = base_proc->RangeTableForLoss();
761 inv_range_vector[j] = base_proc->InverseRangeTable();
762 loss_map[part_vector[j]] = proc;
763 //G4cout << "G4LossTableManager::CopyTable "
764 // << part_vector[j]->GetParticleName()
765 // << " added to map " << proc << G4endl;
766 }
767 if (1 < verbose) {
768 G4cout << "For " << proc->GetProcessName()
769 << " for " << part_vector[j]->GetParticleName()
770 << " base_part= " << part->GetParticleName()
771 << " tables are assigned"
772 << G4endl;
773 }
774 }
775
776 if (theElectron == part && theElectron == proc->SecondaryParticle() ) {
777 proc->SetSecondaryRangeTable(base_proc->RangeTableForLoss());
778 }
779 }
780}
781
782//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
783
785 const G4ParticleDefinition* aParticle)
786{
787 if(1 < verbose) {
788 G4cout << "G4LossTableManager::BuildTables() for "
789 << aParticle->GetParticleName() << G4endl;
790 }
791
792 std::vector<G4PhysicsTable*> t_list;
793 std::vector<G4VEnergyLossProcess*> loss_list;
794 std::vector<G4bool> build_flags;
795 G4VEnergyLossProcess* em = nullptr;
796 G4VEnergyLossProcess* p = nullptr;
797 G4int iem = 0;
798 G4PhysicsTable* dedx = nullptr;
799 G4int i;
800
801 G4ProcessVector* pvec =
802 aParticle->GetProcessManager()->GetProcessList();
803 G4int nvec = pvec->size();
804
805 for (i=0; i<n_loss; ++i) {
806 p = loss_vector[i];
807 if (p) {
808 G4bool yes = (aParticle == part_vector[i]);
809
810 // possible case of process sharing between particle/anti-particle
811 if(!yes) {
812 G4VProcess* ptr = static_cast<G4VProcess*>(p);
813 for(G4int j=0; j<nvec; ++j) {
814 //G4cout << "j= " << j << " " << (*pvec)[j] << " " << ptr << G4endl;
815 if(ptr == (*pvec)[j]) {
816 yes = true;
817 break;
818 }
819 }
820 }
821 // process belong to this particle
822 if(yes && isActive[i]) {
823 if (p->IsIonisationProcess() || !em) {
824 em = p;
825 iem= i;
826 }
827 // tables may be shared between particle/anti-particle
828 G4bool val = false;
829 if (!tables_are_built[i]) {
830 val = true;
831 dedx = p->BuildDEDXTable(fRestricted);
832 //G4cout << "Build DEDX table for " << p->GetProcessName()
833 // << " idx= " << i << dedx << " " << dedx->length() << G4endl;
834 p->SetDEDXTable(dedx,fRestricted);
835 tables_are_built[i] = true;
836 } else {
837 dedx = p->DEDXTable();
838 }
839 t_list.push_back(dedx);
840 loss_list.push_back(p);
841 build_flags.push_back(val);
842 }
843 }
844 }
845
846 G4int n_dedx = t_list.size();
847 if (0 == n_dedx || !em) {
848 G4cout << "G4LossTableManager WARNING: no DEDX processes for "
849 << aParticle->GetParticleName() << G4endl;
850 return 0;
851 }
852 G4int nSubRegions = em->NumberOfSubCutoffRegions();
853
854 if (1 < verbose) {
855 G4cout << "G4LossTableManager::BuildTables() start to build range tables"
856 << " and the sum of " << n_dedx << " processes"
857 << " iem= " << iem << " em= " << em->GetProcessName()
858 << " buildCSDARange= " << theParameters->BuildCSDARange()
859 << " nSubRegions= " << nSubRegions;
860 if(subcutProducer) {
861 G4cout << " SubCutProducer " << subcutProducer->GetName();
862 }
863 G4cout << G4endl;
864 }
865 // do not build tables if producer class is defined
866 if(subcutProducer) { nSubRegions = 0; }
867
868 dedx = em->DEDXTable();
869 em->SetIonisation(true);
870 em->SetDEDXTable(dedx, fIsIonisation);
871
872 if (1 < n_dedx) {
873 dedx = 0;
875 tableBuilder->BuildDEDXTable(dedx, t_list);
876 em->SetDEDXTable(dedx, fRestricted);
877 }
878
879 /*
880 if(2==run && "e-" == aParticle->GetParticleName()) {
881 G4cout << "G4LossTableManager::BuildTables for e- " << dedx << G4endl;
882 G4cout << (*dedx) << G4endl;
883 G4cout << "%%%%% Instance ID= " << (*dedx)[0]->GetInstanceID() << G4endl;
884 G4cout << "%%%%% LastValue= " << (*dedx)[0]->GetLastValue() << G4endl;
885 G4cout << "%%%%% 1.2 " << (*(dedx))[0]->Value(1.2) << G4endl;
886 }
887 */
888 dedx_vector[iem] = dedx;
889
890 G4PhysicsTable* range = em->RangeTableForLoss();
891 if(!range) range = G4PhysicsTableHelper::PreparePhysicsTable(range);
892 range_vector[iem] = range;
893
894 G4PhysicsTable* invrange = em->InverseRangeTable();
895 if(!invrange) invrange = G4PhysicsTableHelper::PreparePhysicsTable(invrange);
896 inv_range_vector[iem] = invrange;
897
898 tableBuilder->BuildRangeTable(dedx, range);
899 tableBuilder->BuildInverseRangeTable(range, invrange);
900
901 // if(1<verbose) G4cout << *dedx << G4endl;
902
903 em->SetRangeTableForLoss(range);
904 em->SetInverseRangeTable(invrange);
905
906 // if(1<verbose) G4cout << *range << G4endl;
907
908 std::vector<G4PhysicsTable*> listSub;
909 std::vector<G4PhysicsTable*> listCSDA;
910
911 for (i=0; i<n_dedx; ++i) {
912 p = loss_list[i];
913 if(p != em) { p->SetIonisation(false); }
914 if(build_flags[i]) {
916 }
918 dedx = p->BuildDEDXTable(fTotal);
919 p->SetDEDXTable(dedx,fTotal);
920 listCSDA.push_back(dedx);
921 }
922 }
923
925 G4PhysicsTable* dedxCSDA = em->DEDXunRestrictedTable();
926 if (1 < n_dedx) {
927 dedxCSDA = nullptr;
929 tableBuilder->BuildDEDXTable(dedxCSDA, listCSDA);
930 em->SetDEDXTable(dedxCSDA,fTotal);
931 }
932 G4PhysicsTable* rCSDA = em->CSDARangeTable();
933 if(!rCSDA) { rCSDA = G4PhysicsTableHelper::PreparePhysicsTable(rCSDA); }
934 tableBuilder->BuildRangeTable(dedxCSDA, rCSDA);
935 em->SetCSDARangeTable(rCSDA);
936 }
937
938 if (1 < verbose) {
939 G4cout << "G4LossTableManager::BuildTables: Tables are built for "
940 << aParticle->GetParticleName()
941 << "; ionisation process: " << em->GetProcessName()
942 << " " << em
943 << G4endl;
944 }
945 return em;
946}
947
948//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
949
951 const G4ParticleDefinition* aParticle)
952{
954 ed << "Energy loss process not found for " << aParticle->GetParticleName()
955 << " !";
956 G4Exception("G4LossTableManager::ParticleHaveNoLoss", "em0001",
957 FatalException, ed);
958}
959
960//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
961
963{
964 verbose = val;
965}
966
967//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
968
969const std::vector<G4VEnergyLossProcess*>&
971{
972 return loss_vector;
973}
974
975//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
976
977const std::vector<G4VEmProcess*>& G4LossTableManager::GetEmProcessVector()
978{
979 return emp_vector;
980}
981
982//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
983
984const std::vector<G4VMultipleScattering*>&
986{
987 return msc_vector;
988}
989
990//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
991
993{
995}
996
997//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
998
1000{
1001 if(!emConfigurator) {
1003 }
1004 return emConfigurator;
1005}
1006
1007//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
1008
1010{
1011 if(!emElectronIonPair) {
1013 }
1014 return emElectronIonPair;
1015}
1016
1017//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
1018
1020{
1021 if(ptr && ptr != nielCalculator) {
1022 delete nielCalculator;
1023 nielCalculator = ptr;
1024 }
1025}
1026
1027//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
1028
1030{
1031 if(!nielCalculator) {
1032 nielCalculator = new G4NIELCalculator(nullptr, verbose);
1033 }
1034 return nielCalculator;
1035}
1036
1037//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
1038
1040{
1041 if(atomDeexcitation != p) {
1042 delete atomDeexcitation;
1043 atomDeexcitation = p;
1044 }
1045}
1046
1047//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
1048
1050{
1051 if(subcutProducer != p) {
1052 delete subcutProducer;
1053 subcutProducer = p;
1054 }
1055}
1056
1057//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
1058
1060{
1061 G4String ss = "G4LossTableManager::" + tit;
1063 /*
1064 ed << "Parameter is out of range: " << val
1065 << " it will have no effect!\n" << " ## "
1066 << " nbins= " << nbinsLambda
1067 << " nbinsPerDecade= " << nbinsPerDecade
1068 << " Emin(keV)= " << minKinEnergy/keV
1069 << " Emax(GeV)= " << maxKinEnergy/GeV;
1070 */
1071 G4Exception(ss, "em0044", JustWarning, ed);
1072}
1073
1074//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
1075
1077{
1078 // Automatic generation of html documentation page for physics lists
1079 // List processes and models for the most important
1080 // particles in descending order of importance
1081 // NB. for model names with length > 18 characters the .rst file needs
1082 // to be edited by hand. Or modify G4EmModelManager::DumpModelList
1083
1084 char* dirName = std::getenv("G4PhysListDocDir");
1085 char* physList = std::getenv("G4PhysListName");
1086 if (dirName && physList) {
1087 G4String physListName = G4String(physList);
1088 G4String pathName = G4String(dirName) + "/" + physListName + ".rst";
1089
1090 std::ofstream outFile;
1091 outFile.open(pathName);
1092
1093 outFile << physListName << G4endl;
1094 outFile << std::string(physListName.length(), '=') << G4endl;
1095
1096 std::vector<G4ParticleDefinition*> particles {
1103 };
1104
1105 std::vector<G4VEmProcess*> emproc_vector = GetEmProcessVector();
1106 std::vector<G4VEnergyLossProcess*> enloss_vector =
1108 std::vector<G4VMultipleScattering*> mscat_vector =
1110
1111 for (auto theParticle : particles) {
1112 outFile << G4endl << "**" << theParticle->GetParticleName()
1113 << "**" << G4endl << G4endl << " .. code-block:: none" << G4endl;
1114
1115 G4ProcessManager* pm = theParticle->GetProcessManager();
1116 G4ProcessVector* pv = pm->GetProcessList();
1117 G4int plen = pm->GetProcessListLength();
1118
1119 for (auto emproc : emproc_vector) {
1120 for (G4int i = 0; i < plen; ++i) {
1121 G4VProcess* proc = (*pv)[i];
1122 if (proc == emproc) {
1123 outFile << G4endl;
1124 proc->ProcessDescription(outFile);
1125 break;
1126 }
1127 }
1128 }
1129
1130 for (auto mscproc : mscat_vector) {
1131 for (G4int i = 0; i < plen; ++i) {
1132 G4VProcess* proc = (*pv)[i];
1133 if (proc == mscproc) {
1134 outFile << G4endl;
1135 proc->ProcessDescription(outFile);
1136 break;
1137 }
1138 }
1139 }
1140
1141 for (auto enlossproc : enloss_vector) {
1142 for (G4int i = 0; i < plen; ++i) {
1143 G4VProcess* proc = (*pv)[i];
1144 if (proc == enlossproc) {
1145 outFile << G4endl;
1146 proc->ProcessDescription(outFile);
1147 break;
1148 }
1149 }
1150 }
1151 }
1152 outFile.close();
1153 }
1154}
1155
1156//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
1157
static const G4double pos
@ fTotal
@ fRestricted
@ fIsIonisation
@ JustWarning
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
static G4Electron * Electron()
Definition: G4Electron.cc:93
void SetVerbose(G4int value)
void PrepareModels(const G4ParticleDefinition *aParticle, G4VEnergyLossProcess *p)
void SetVerbose(G4int verb)
static G4EmParameters * Instance()
G4bool BuildCSDARange() const
G4EmSaturation * GetEmSaturation()
G4int Verbose() const
G4int WorkerVerbose() const
void SetIsPrintedFlag(G4bool val)
static G4Gamma * Gamma()
Definition: G4Gamma.cc:85
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)
std::vector< PD > base_part_vector
std::vector< G4PhysicsTable * > range_vector
void SetAtomDeexcitation(G4VAtomDeexcitation *)
std::vector< G4bool > isActive
std::vector< G4PhysicsTable * > dedx_vector
static G4LossTableManager * Instance()
const std::vector< G4VEmProcess * > & GetEmProcessVector()
void CopyTables(const G4ParticleDefinition *aParticle, G4VEnergyLossProcess *)
G4ElectronIonPair * emElectronIonPair
std::vector< G4VEmProcess * > emp_vector
void ParticleHaveNoLoss(const G4ParticleDefinition *aParticle)
G4VSubCutProducer * subcutProducer
G4VEnergyLossProcess * GetEnergyLossProcess(const G4ParticleDefinition *)
std::map< PD, G4VEnergyLossProcess *, std::less< PD > > loss_map
void LocalPhysicsTables(const G4ParticleDefinition *aParticle, G4VEnergyLossProcess *p)
G4VEnergyLossProcess * currentLoss
G4EmParameters * theParameters
std::vector< G4VMultipleScattering * > msc_vector
G4EmConfigurator * emConfigurator
std::vector< G4VEmModel * > mod_vector
static G4ThreadLocal G4LossTableManager * instance
void PreparePhysicsTable(const G4ParticleDefinition *aParticle, G4VEnergyLossProcess *p, G4bool theMaster)
void BuildPhysicsTable(const G4ParticleDefinition *aParticle)
std::vector< G4VEnergyLossProcess * > loss_vector
std::vector< G4VProcess * > p_vector
const std::vector< G4VMultipleScattering * > & GetMultipleScatteringVector()
void SetVerbose(G4int val)
G4LossTableBuilder * tableBuilder
void DeRegister(G4VEnergyLossProcess *p)
G4NIELCalculator * NIELCalculator()
void SetNIELCalculator(G4NIELCalculator *)
G4EmCorrections * emCorrections
G4EmConfigurator * EmConfigurator()
void Register(G4VEnergyLossProcess *p)
G4ElectronIonPair * ElectronIonPair()
std::vector< G4VEmFluctuationModel * > fmod_vector
void PrintEWarning(G4String, G4double)
G4EmSaturation * EmSaturation()
const std::vector< G4VEnergyLossProcess * > & GetEnergyLossProcessVector()
std::vector< G4bool > tables_are_built
std::vector< PD > part_vector
G4NIELCalculator * nielCalculator
G4VEnergyLossProcess * BuildTables(const G4ParticleDefinition *aParticle)
std::vector< G4PhysicsTable * > inv_range_vector
void SetSubCutProducer(G4VSubCutProducer *)
void RegisterExtraParticle(const G4ParticleDefinition *aParticle, G4VEnergyLossProcess *p)
G4VAtomDeexcitation * atomDeexcitation
static G4MuonMinus * MuonMinusDefinition()
Definition: G4MuonMinus.cc:94
static G4MuonPlus * MuonPlusDefinition()
Definition: G4MuonPlus.cc:93
G4ProcessManager * GetProcessManager() const
const G4String & GetParticleName() const
static G4PhysicsTable * PreparePhysicsTable(G4PhysicsTable *physTable)
void push_back(G4PhysicsVector *)
static G4Positron * Positron()
Definition: G4Positron.cc:93
G4int GetProcessListLength() const
G4ProcessVector * GetProcessList() const
std::size_t size() const
static G4Proton * ProtonDefinition()
Definition: G4Proton.cc:87
const G4String & GetName() const
const G4String & GetName() const
Definition: G4VEmModel.hh:837
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)
void SetSecondaryRangeTable(G4PhysicsTable *p)
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
const G4ParticleDefinition * SecondaryParticle() const
virtual void ProcessDescription(std::ostream &outfile) const
Definition: G4VProcess.cc:175
const G4String & GetProcessName() const
Definition: G4VProcess.hh:382
const G4String & GetName() const
G4bool IsWorkerThread()
Definition: G4Threading.cc:123
Definition: run.py:1
#define G4ThreadLocal
Definition: tls.hh:77