Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4VUserPhysicsList.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// G4VUserPhysicsList implementation
27//
28// Original author: H.Kurashige (Kobe University), 9 January 1998
29// --------------------------------------------------------------------
30
32#include "G4VUserPhysicsList.hh"
33
34#include "G4Material.hh"
37#include "G4ParticleTable.hh"
38#include "G4ProcessManager.hh"
39#include "G4ProductionCuts.hh"
41#include "G4Region.hh"
42#include "G4RegionStore.hh"
43#include "G4SystemOfUnits.hh"
44#include "G4UImanager.hh"
45#include "G4UnitsTable.hh"
47#include "G4VTrackingManager.hh"
48#include "G4ios.hh"
49#include "globals.hh"
50
51#include <fstream>
52#include <iomanip>
53#include <unordered_set>
54
55// This static member is thread local. For each thread, it holds the array
56// size of G4VUPLData instances.
57//
58#define G4MT_theMessenger \
59 ((this->subInstanceManager.offset[this->g4vuplInstanceID])._theMessenger)
60#define G4MT_thePLHelper \
61 ((this->subInstanceManager.offset[this->g4vuplInstanceID])._thePLHelper)
62#define fIsPhysicsTableBuilt \
63 ((this->subInstanceManager.offset[this->g4vuplInstanceID]) \
64 ._fIsPhysicsTableBuilt)
65#define fDisplayThreshold \
66 ((this->subInstanceManager.offset[this->g4vuplInstanceID])._fDisplayThreshold)
67#define theParticleIterator \
68 ((this->subInstanceManager.offset[this->g4vuplInstanceID]) \
69 ._theParticleIterator)
70
71// This field helps to use the class G4VUPLManager
72//
74
75// --------------------------------------------------------------------
77{
79 _theMessenger = nullptr;
83}
84
85// --------------------------------------------------------------------
87{
89 // default cut value (1.0mm)
90 defaultCutValue = 1.0 * mm;
91
92 // pointer to the particle table
94 // theParticleIterator = theParticleTable->GetIterator();
95
96 // pointer to the cuts table
98
99 // set energy range for SetCut calcuration
100 fCutsTable->SetEnergyRange(0.99 * keV, 100 * TeV);
101
102 // UI Messenger
103 // theMessenger = new G4UserPhysicsListMessenger(this);
105
106 // PhysicsListHelper
107 // thePLHelper = G4PhysicsListHelper::GetPhysicsListHelper();
108 // thePLHelper->SetVerboseLevel(verboseLevel);
109 // G4MT_thePLHelper = G4PhysicsListHelper::GetPhysicsListHelper(); //AND
110 G4MT_thePLHelper->SetVerboseLevel(verboseLevel); // AND
111
112 fIsPhysicsTableBuilt = false;
114}
115
116// --------------------------------------------------------------------
118{
119 // Remember messengers are per-thread, so this needs to be done by each
120 // worker and due to the presence of "this" cannot be done in
121 // G4VUPLData::initialize()
123}
124
125// --------------------------------------------------------------------
127{
130 delete G4MT_theMessenger;
131 G4MT_theMessenger = nullptr;
132}
133
134// --------------------------------------------------------------------
136{
137 delete G4MT_theMessenger;
138 G4MT_theMessenger = nullptr;
139
142
143 // invoke DeleteAllParticle
145}
146
147// --------------------------------------------------------------------
149 : verboseLevel(right.verboseLevel)
150 , defaultCutValue(right.defaultCutValue)
151 , isSetDefaultCutValue(right.isSetDefaultCutValue)
152 , fRetrievePhysicsTable(right.fRetrievePhysicsTable)
153 , fStoredInAscii(right.fStoredInAscii)
154 , fIsCheckedForRetrievePhysicsTable(right.fIsCheckedForRetrievePhysicsTable)
155 , fIsRestoredCutValues(right.fIsRestoredCutValues)
156 , directoryPhysicsTable(right.directoryPhysicsTable)
157 , fDisableCheckParticleList(right.fDisableCheckParticleList)
158{
160 // pointer to the particle table
163 // pointer to the cuts table
165
166 // UI Messenger
168
169 // PhysicsListHelper
171 G4MT_thePLHelper->SetVerboseLevel(verboseLevel);
172
174 .offset[right.GetInstanceID()]
175 ._fIsPhysicsTableBuilt;
177 .offset[right.GetInstanceID()]
178 ._fDisplayThreshold;
179}
180
181// --------------------------------------------------------------------
184{
185 if(this != &right)
186 {
196 .offset[right.GetInstanceID()]
197 ._fIsPhysicsTableBuilt;
199 .offset[right.GetInstanceID()]
200 ._fDisplayThreshold;
202 }
203 return *this;
204}
205
206// --------------------------------------------------------------------
209{
210 if(newParticle == nullptr)
211 return;
212 G4Exception("G4VUserPhysicsList::AddProcessManager", "Run0252",
213 JustWarning, "This method is obsolete");
214}
215
216// --------------------------------------------------------------------
218{
219 // Request lock for particle table access. Some changes are inside
220 // this critical region.
221#ifdef G4MULTITHREADED
222 G4MUTEXLOCK(&G4ParticleTable::particleTableMutex());
223 G4ParticleTable::lockCount()++;
224#endif
227
228 // loop over all particles in G4ParticleTable
229 theParticleIterator->reset();
230 while((*theParticleIterator)())
231 {
232 G4ParticleDefinition* particle = theParticleIterator->value();
233 G4ProcessManager* pmanager = particle->GetProcessManager();
234
235 if(pmanager == nullptr)
236 {
237 // create process manager if the particle does not have its own.
238 pmanager = new G4ProcessManager(particle);
239 particle->SetProcessManager(pmanager);
240 if(particle->GetMasterProcessManager() == nullptr)
241 particle->SetMasterProcessManager(pmanager);
242#ifdef G4VERBOSE
243 if(verboseLevel > 2)
244 {
245 G4cout << "G4VUserPhysicsList::InitializeProcessManager: creating "
246 "ProcessManager to "
247 << particle->GetParticleName() << G4endl;
248 }
249#endif
250 }
251 }
252
253 if(gion != nullptr)
254 {
255 G4ProcessManager* gionPM = gion->GetProcessManager();
256 // loop over all particles once again (this time, with all general ions)
257 theParticleIterator->reset(false);
258 while((*theParticleIterator)())
259 {
260 G4ParticleDefinition* particle = theParticleIterator->value();
261 if(particle->IsGeneralIon())
262 {
263 particle->SetProcessManager(gionPM);
264#ifdef G4VERBOSE
265 if(verboseLevel > 2)
266 {
267 G4cout << "G4VUserPhysicsList::InitializeProcessManager: copying "
268 "ProcessManager to "
269 << particle->GetParticleName() << G4endl;
270 }
271#endif
272 }
273 }
274 }
275
276 // release lock for particle table access
277#ifdef G4MULTITHREADED
278 G4MUTEXUNLOCK(&G4ParticleTable::particleTableMutex());
279#endif
280}
281
282// --------------------------------------------------------------------
284{
285 // Request lock for particle table access. Some changes are inside
286 // this critical region.
287#ifdef G4MULTITHREADED
288 G4MUTEXLOCK(&G4ParticleTable::particleTableMutex());
289 G4ParticleTable::lockCount()++;
290#endif
291
292 // loop over all particles in G4ParticleTable
293 theParticleIterator->reset();
294 while((*theParticleIterator)())
295 {
296 G4ParticleDefinition* particle = theParticleIterator->value();
297 if(particle->GetInstanceID() <
299 {
300 if(particle->GetParticleSubType() != "generic" ||
301 particle->GetParticleName() == "GenericIon")
302 {
303 G4ProcessManager* pmanager = particle->GetProcessManager();
304 if(pmanager != nullptr)
305 delete pmanager;
306#ifdef G4VERBOSE
307 if(verboseLevel > 2)
308 {
309 G4cout << "G4VUserPhysicsList::RemoveProcessManager: ";
310 G4cout << "remove ProcessManager from ";
311 G4cout << particle->GetParticleName() << G4endl;
312 }
313#endif
314 }
315 particle->SetProcessManager(nullptr);
316 }
317 }
318
319 // release lock for particle table access
320#ifdef G4MULTITHREADED
321 G4MUTEXUNLOCK(&G4ParticleTable::particleTableMutex());
322#endif
323}
324
325// --------------------------------------------------------------------
327{
328 // One tracking manager may be registered for multiple particles, make sure
329 // to delete every object only once.
330 std::unordered_set<G4VTrackingManager *> trackingManagers;
331
332 // loop over all particles in G4ParticleTable
333 theParticleIterator->reset();
334 while((*theParticleIterator)())
335 {
336 G4ParticleDefinition* particle = theParticleIterator->value();
337 if (auto *trackingManager = particle->GetTrackingManager())
338 {
339#ifdef G4VERBOSE
340 if(verboseLevel > 2)
341 {
342 G4cout << "G4VUserPhysicsList::RemoveTrackingManager: ";
343 G4cout << "remove TrackingManager from ";
344 G4cout << particle->GetParticleName() << G4endl;
345 }
346#endif
347 trackingManagers.insert(trackingManager);
348 particle->SetTrackingManager(nullptr);
349 }
350 }
351
352 for (G4VTrackingManager *tm : trackingManagers)
353 {
354 delete tm;
355 }
356}
357
358// --------------------------------------------------------------------
360{
362 {
364 }
365
366#ifdef G4VERBOSE
367 if(verboseLevel > 1)
368 {
369 G4cout << "G4VUserPhysicsList::SetCuts: " << G4endl;
370 G4cout << "Cut for gamma: " << GetCutValue("gamma") / mm << "[mm]"
371 << G4endl;
372 G4cout << "Cut for e-: " << GetCutValue("e-") / mm << "[mm]" << G4endl;
373 G4cout << "Cut for e+: " << GetCutValue("e+") / mm << "[mm]" << G4endl;
374 G4cout << "Cut for proton: " << GetCutValue("proton") / mm << "[mm]"
375 << G4endl;
376 }
377#endif
378
379 // dump Cut values if verboseLevel==3
380 if(verboseLevel > 2)
381 {
383 }
384}
385
386// --------------------------------------------------------------------
388{
389 if(value < 0.0)
390 {
391#ifdef G4VERBOSE
392 if(verboseLevel > 0)
393 {
394 G4cout << "G4VUserPhysicsList::SetDefaultCutValue: negative cut values"
395 << " :" << value / mm << "[mm]" << G4endl;
396 }
397#endif
398 return;
399 }
400
401 defaultCutValue = value;
403
404 // set cut values for gamma at first and for e- and e+
408 SetCutValue(defaultCutValue, "proton");
409
410#ifdef G4VERBOSE
411 if(verboseLevel > 1)
412 {
413 G4cout << "G4VUserPhysicsList::SetDefaultCutValue:"
414 << "default cut value is changed to :" << defaultCutValue / mm
415 << "[mm]" << G4endl;
416 }
417#endif
418}
419
420// --------------------------------------------------------------------
422{
423 std::size_t nReg = (G4RegionStore::GetInstance())->size();
424 if(nReg == 0)
425 {
426#ifdef G4VERBOSE
427 if(verboseLevel > 0)
428 {
429 G4cout << "G4VUserPhysicsList::GetCutValue "
430 << " : No Default Region " << G4endl;
431 }
432#endif
433 G4Exception("G4VUserPhysicsList::GetCutValue", "Run0253", FatalException,
434 "No Default Region");
435 return -1. * mm;
436 }
437 G4Region* region =
438 G4RegionStore::GetInstance()->GetRegion("DefaultRegionForTheWorld", false);
439 return region->GetProductionCuts()->GetProductionCut(name);
440}
441
442// --------------------------------------------------------------------
444{
445 SetParticleCuts(aCut, name);
446}
447
448// --------------------------------------------------------------------
450 const G4String& rname)
451{
453 if(region != nullptr)
454 {
455 // set cut value
456 SetParticleCuts(aCut, pname, region);
457 }
458 else
459 {
460#ifdef G4VERBOSE
461 if(verboseLevel > 0)
462 {
463 G4cout << "G4VUserPhysicsList::SetCutValue "
464 << " : No Region of " << rname << G4endl;
465 }
466#endif
467 }
468}
469
470// --------------------------------------------------------------------
472{
475}
476
477// --------------------------------------------------------------------
479{
480 // set cut values for gamma at first and for e- and e+
481 SetCutValue(aCut, "gamma", rname);
482 SetCutValue(aCut, "e-", rname);
483 SetCutValue(aCut, "e+", rname);
484 SetCutValue(aCut, "proton", rname);
485}
486
487// --------------------------------------------------------------------
489 G4ParticleDefinition* particle,
490 G4Region* region)
491{
492 SetParticleCuts(cut, particle->GetParticleName(), region);
493}
494
495// --------------------------------------------------------------------
497 const G4String& particleName,
498 G4Region* region)
499{
500 if(cut < 0.0)
501 {
502#ifdef G4VERBOSE
503 if(verboseLevel > 0)
504 {
505 G4cout << "G4VUserPhysicsList::SetParticleCuts: negative cut values"
506 << " :" << cut / mm << "[mm]"
507 << " for " << particleName << G4endl;
508 }
509#endif
510 return;
511 }
512
513 G4Region* world_region =
514 G4RegionStore::GetInstance()->GetRegion("DefaultRegionForTheWorld", false);
515 if(region == nullptr)
516 {
517 std::size_t nReg = G4RegionStore::GetInstance()->size();
518 if(nReg == 0)
519 {
520#ifdef G4VERBOSE
521 if(verboseLevel > 0)
522 {
523 G4cout << "G4VUserPhysicsList::SetParticleCuts "
524 << " : No Default Region " << G4endl;
525 }
526#endif
527 G4Exception("G4VUserPhysicsList::SetParticleCuts ", "Run0254",
528 FatalException, "No Default Region");
529 return;
530 }
531 region = world_region;
532 }
533
535 {
537 }
538
539 G4ProductionCuts* pcuts = region->GetProductionCuts();
540 if(region != world_region &&
542 ->GetDefaultProductionCuts())
543 { // This region had no unique cuts yet but shares the default cuts.
544 // Need to create a new object before setting the value.
545 pcuts =
547 ->GetDefaultProductionCuts()));
548 region->SetProductionCuts(pcuts);
549 }
550 pcuts->SetProductionCut(cut, particleName);
551#ifdef G4VERBOSE
552 if(verboseLevel > 2)
553 {
554 G4cout << "G4VUserPhysicsList::SetParticleCuts: "
555 << " :" << cut / mm << "[mm]"
556 << " for " << particleName << G4endl;
557 }
558#endif
559}
560
561// --------------------------------------------------------------------
563{
564 // Prepare Physics table for all particles
565 theParticleIterator->reset();
566 while((*theParticleIterator)())
567 {
568 G4ParticleDefinition* particle = theParticleIterator->value();
569 PreparePhysicsTable(particle);
570 }
571
572 // ask processes to prepare physics table
574 {
577 // check if retrieve Cut Table successfully
579 {
580#ifdef G4VERBOSE
581 if(verboseLevel > 0)
582 {
583 G4cout << "G4VUserPhysicsList::BuildPhysicsTable"
584 << " Retrieve Cut Table failed !!" << G4endl;
585 }
586#endif
587 G4Exception("G4VUserPhysicsList::BuildPhysicsTable", "Run0255",
588 RunMustBeAborted, "Fail to retrieve Production Cut Table");
589 }
590 else
591 {
592#ifdef G4VERBOSE
593 if(verboseLevel > 2)
594 {
595 G4cout << "G4VUserPhysicsList::BuildPhysicsTable"
596 << " Retrieve Cut Table successfully " << G4endl;
597 }
598#endif
599 }
600 }
601 else
602 {
603#ifdef G4VERBOSE
604 if(verboseLevel > 2)
605 {
606 G4cout << "G4VUserPhysicsList::BuildPhysicsTable"
607 << " does not retrieve Cut Table but calculate " << G4endl;
608 }
609#endif
610 }
611
612 // Sets a value to particle
613 // set cut values for gamma at first and for e- and e+
614 G4String particleName;
616 if(GammaP)
617 BuildPhysicsTable(GammaP);
619 if(EMinusP)
620 BuildPhysicsTable(EMinusP);
622 if(EPlusP)
623 BuildPhysicsTable(EPlusP);
625 if(ProtonP)
626 BuildPhysicsTable(ProtonP);
627
628 theParticleIterator->reset();
629 while((*theParticleIterator)())
630 {
631 G4ParticleDefinition* particle = theParticleIterator->value();
632 if(particle != GammaP && particle != EMinusP && particle != EPlusP &&
633 particle != ProtonP)
634 {
635 BuildPhysicsTable(particle);
636 }
637 }
638
639 // Set flag
641}
642
643// --------------------------------------------------------------------
645{
646 if (auto *trackingManager = particle->GetTrackingManager())
647 {
648#ifdef G4VERBOSE
649 if(verboseLevel > 2)
650 {
651 G4cout << "G4VUserPhysicsList::BuildPhysicsTable "
652 << "Calculate Physics Table for " << particle->GetParticleName()
653 << " via custom TrackingManager" << G4endl;
654 }
655#endif
656 trackingManager->BuildPhysicsTable(*particle);
657 return;
658 }
659
660 // Change in order to share physics tables for two kind of process.
661
662 if(particle->GetMasterProcessManager() == nullptr)
663 {
664#ifdef G4VERBOSE
665 if(verboseLevel > 0)
666 { G4cout
667 << "#### G4VUserPhysicsList::BuildPhysicsTable() - BuildPhysicsTable("
668 << particle->GetParticleName() << ") skipped..." << G4endl; }
669#endif
670 return;
671 }
673 {
675 {
676 // fail to retrieve cut tables
677#ifdef G4VERBOSE
678 if(verboseLevel > 0)
679 {
680 G4cout << "G4VUserPhysicsList::BuildPhysicsTable "
681 << "Physics table can not be retrieved and will be calculated "
682 << G4endl;
683 }
684#endif
685 fRetrievePhysicsTable = false;
686 }
687 else
688 {
689#ifdef G4VERBOSE
690 if(verboseLevel > 2)
691 {
692 G4cout << "G4VUserPhysicsList::BuildPhysicsTable "
693 << " Retrieve Physics Table for " << particle->GetParticleName()
694 << G4endl;
695 }
696#endif
697 // Retrieve PhysicsTable from files for proccesses
699 }
700 }
701
702#ifdef G4VERBOSE
703 if(verboseLevel > 2)
704 {
705 G4cout << "G4VUserPhysicsList::BuildPhysicsTable "
706 << "Calculate Physics Table for " << particle->GetParticleName()
707 << G4endl;
708 }
709#endif
710 // Rebuild the physics tables for every process for this particle type
711 // if particle is not ShortLived
712 if(!particle->IsShortLived())
713 {
714 G4ProcessManager* pManager = particle->GetProcessManager();
715 if(pManager == nullptr)
716 {
717#ifdef G4VERBOSE
718 if(verboseLevel > 0)
719 {
720 G4cout << "G4VUserPhysicsList::BuildPhysicsTable "
721 << " : No Process Manager for " << particle->GetParticleName()
722 << G4endl;
723 G4cout << particle->GetParticleName()
724 << " should be created in your PhysicsList" << G4endl;
725 }
726#endif
727 G4Exception("G4VUserPhysicsList::BuildPhysicsTable", "Run0271",
728 FatalException, "No process manager");
729 return;
730 }
731
732 // Get processes from master thread;
733 G4ProcessManager* pManagerShadow = particle->GetMasterProcessManager();
734
735 G4ProcessVector* pVector = pManager->GetProcessList();
736 if(pVector == nullptr)
737 {
738#ifdef G4VERBOSE
739 if(verboseLevel > 0)
740 {
741 G4cout << "G4VUserPhysicsList::BuildPhysicsTable "
742 << " : No Process Vector for " << particle->GetParticleName()
743 << G4endl;
744 }
745#endif
746 G4Exception("G4VUserPhysicsList::BuildPhysicsTable", "Run0272",
747 FatalException, "No process Vector");
748 return;
749 }
750#ifdef G4VERBOSE
751 if(verboseLevel > 2)
752 {
753 G4cout << "G4VUserPhysicsList::BuildPhysicsTable %%%%%% "
754 << particle->GetParticleName() << G4endl;
755 G4cout << " ProcessManager : " << pManager
756 << " ProcessManagerShadow : " << pManagerShadow << G4endl;
757 for(G4int iv1 = 0; iv1 < (G4int)pVector->size(); ++iv1)
758 {
759 G4cout << " " << iv1 << " - " << (*pVector)[iv1]->GetProcessName()
760 << G4endl;
761 }
762 G4cout << "--------------------------------------------------------------"
763 << G4endl;
764 G4ProcessVector* pVectorShadow = pManagerShadow->GetProcessList();
765
766 for(G4int iv2 = 0; iv2 < (G4int)pVectorShadow->size(); ++iv2)
767 {
768 G4cout << " " << iv2 << " - "
769 << (*pVectorShadow)[iv2]->GetProcessName() << G4endl;
770 }
771 }
772#endif
773 for(G4int j = 0; j < (G4int)pVector->size(); ++j)
774 {
775 // Andrea July 16th 2013 : migration to new interface...
776 // Infer if we are in a worker thread or master thread
777 // Master thread is the one in which the process manager
778 // and process manager shadow pointers are the same
779 if(pManagerShadow == pManager)
780 {
781 (*pVector)[j]->BuildPhysicsTable(*particle);
782 }
783 else
784 {
785 (*pVector)[j]->BuildWorkerPhysicsTable(*particle);
786 }
787
788 } // End loop on processes vector
789 } // End if short-lived
790}
791
792// --------------------------------------------------------------------
794{
795 if (auto *trackingManager = particle->GetTrackingManager())
796 {
797 trackingManager->PreparePhysicsTable(*particle);
798 return;
799 }
800
801 if(!(particle->GetMasterProcessManager()))
802 {
803 return;
804 }
805 // Prepare the physics tables for every process for this particle type
806 // if particle is not ShortLived
807 if(!particle->IsShortLived())
808 {
809 G4ProcessManager* pManager = particle->GetProcessManager();
810 if(pManager == nullptr)
811 {
812#ifdef G4VERBOSE
813 if(verboseLevel > 0)
814 {
815 G4cout << "G4VUserPhysicsList::PreparePhysicsTable "
816 << ": No Process Manager for " << particle->GetParticleName()
817 << G4endl;
818 G4cout << particle->GetParticleName()
819 << " should be created in your PhysicsList" << G4endl;
820 }
821#endif
822 G4Exception("G4VUserPhysicsList::PreparePhysicsTable", "Run0273",
823 FatalException, "No process manager");
824 return;
825 }
826
827 // Get processes from master thread
828 G4ProcessManager* pManagerShadow = particle->GetMasterProcessManager();
829
830 G4ProcessVector* pVector = pManager->GetProcessList();
831 if(pVector == nullptr)
832 {
833#ifdef G4VERBOSE
834 if(verboseLevel > 0)
835 {
836 G4cout << "G4VUserPhysicsList::PreparePhysicsTable "
837 << ": No Process Vector for " << particle->GetParticleName()
838 << G4endl;
839 }
840#endif
841 G4Exception("G4VUserPhysicsList::PreparePhysicsTable", "Run0274",
842 FatalException, "No process Vector");
843 return;
844 }
845 for(G4int j = 0; j < (G4int)pVector->size(); ++j)
846 {
847 // Andrea July 16th 2013 : migration to new interface...
848 // Infer if we are in a worker thread or master thread
849 // Master thread is the one in which the process manager
850 // and process manager shadow pointers are the same
851 if(pManagerShadow == pManager)
852 {
853 (*pVector)[j]->PreparePhysicsTable(*particle);
854 }
855 else
856 {
857 (*pVector)[j]->PrepareWorkerPhysicsTable(*particle);
858 }
859 } // End loop on processes vector
860 } // End if pn ShortLived
861}
862
863// --------------------------------------------------------------------
865 G4VProcess* process, G4ParticleDefinition* particle)
866{
867 // TODO Should we change this function?
868 //*******************************************************************
869 // Temporary addition to make the integral schema of electromagnetic
870 // processes work.
871
872 if((process->GetProcessName() == "Imsc") ||
873 (process->GetProcessName() == "IeIoni") ||
874 (process->GetProcessName() == "IeBrems") ||
875 (process->GetProcessName() == "Iannihil") ||
876 (process->GetProcessName() == "IhIoni") ||
877 (process->GetProcessName() == "IMuIoni") ||
878 (process->GetProcessName() == "IMuBrems") ||
879 (process->GetProcessName() == "IMuPairProd"))
880 {
881#ifdef G4VERBOSE
882 if(verboseLevel > 2)
883 {
884 G4cout << "G4VUserPhysicsList::BuildIntegralPhysicsTable "
885 << " BuildPhysicsTable is invoked for "
886 << process->GetProcessName() << "(" << particle->GetParticleName()
887 << ")" << G4endl;
888 }
889#endif
890 process->BuildPhysicsTable(*particle);
891 }
892}
893
894// --------------------------------------------------------------------
896{
897 theParticleIterator->reset();
898 G4int idx = 0;
899 while((*theParticleIterator)())
900 {
901 G4ParticleDefinition* particle = theParticleIterator->value();
902 G4cout << particle->GetParticleName();
903 if((idx++ % 4) == 3)
904 {
905 G4cout << G4endl;
906 }
907 else
908 {
909 G4cout << ", ";
910 }
911 }
912 G4cout << G4endl;
913}
914
915// --------------------------------------------------------------------
917{
918 fDisplayThreshold = flag;
919}
920
921// --------------------------------------------------------------------
923{
924 if(fDisplayThreshold == 0)
925 return;
928}
929
930// --------------------------------------------------------------------
932{
933 G4bool ascii = fStoredInAscii;
934 G4String dir = directory;
935 if(dir.empty())
937 else
939
940 // store CutsTable info
941 if(!fCutsTable->StoreCutsTable(dir, ascii))
942 {
943 G4Exception("G4VUserPhysicsList::StorePhysicsTable", "Run0281", JustWarning,
944 "Fail to store Cut Table");
945 return false;
946 }
947#ifdef G4VERBOSE
948 if(verboseLevel > 2)
949 {
950 G4cout << "G4VUserPhysicsList::StorePhysicsTable "
951 << " Store material and cut values successfully" << G4endl;
952 }
953#endif
954
955 G4bool success = true;
956
957 // loop over all particles in G4ParticleTable
958 theParticleIterator->reset();
959 while((*theParticleIterator)())
960 {
961 G4ParticleDefinition* particle = theParticleIterator->value();
962 // Store physics tables for every process for this particle type
963 G4ProcessVector* pVector =
964 (particle->GetProcessManager())->GetProcessList();
965 for(G4int j = 0; j < (G4int)pVector->size(); ++j)
966 {
967 if(!(*pVector)[j]->StorePhysicsTable(particle, dir, ascii))
968 {
969 G4String comment = "Fail to store physics table for ";
970 comment += (*pVector)[j]->GetProcessName();
971 comment += "(" + particle->GetParticleName() + ")";
972 G4Exception("G4VUserPhysicsList::StorePhysicsTable", "Run0282",
973 JustWarning, comment);
974 success = false;
975 }
976 }
977 // end loop over processes
978 }
979 // end loop over particles
980 return success;
981}
982
983// --------------------------------------------------------------------
985{
987 if(!directory.empty())
988 {
989 directoryPhysicsTable = directory;
990 }
992 fIsRestoredCutValues = false;
993}
994
995// --------------------------------------------------------------------
997 const G4String& directory,
998 G4bool ascii)
999{
1000 G4bool success[100];
1001 // Retrieve physics tables for every process for this particle type
1002 G4ProcessVector* pVector = (particle->GetProcessManager())->GetProcessList();
1003 for(G4int j = 0; j < (G4int)pVector->size(); ++j)
1004 {
1005 success[j] =
1006 (*pVector)[j]->RetrievePhysicsTable(particle, directory, ascii);
1007
1008 if(!success[j])
1009 {
1010#ifdef G4VERBOSE
1011 if(verboseLevel > 2)
1012 {
1013 G4cout << "G4VUserPhysicsList::RetrievePhysicsTable "
1014 << " Fail to retrieve Physics Table for "
1015 << (*pVector)[j]->GetProcessName() << G4endl;
1016 G4cout << "Calculate Physics Table for " << particle->GetParticleName()
1017 << G4endl;
1018 }
1019#endif
1020 (*pVector)[j]->BuildPhysicsTable(*particle);
1021 }
1022 }
1023 for(G4int j = 0; j < (G4int)pVector->size(); ++j)
1024 {
1025 // temporary addition to make the integral schema
1026 if(!success[j])
1027 BuildIntegralPhysicsTable((*pVector)[j], particle);
1028 }
1029}
1030
1031// --------------------------------------------------------------------
1033{
1034#ifdef G4VERBOSE
1035 if(verboseLevel > 2)
1036 {
1037 G4cout << "G4VUserPhysicsList::SetApplyCuts for " << name << G4endl;
1038 }
1039#endif
1040 if(name == "all")
1041 {
1046 }
1047 else
1048 {
1050 }
1051}
1052
1053// --------------------------------------------------------------------
1055{
1057}
1058
1059// --------------------------------------------------------------------
1061{
1063 {
1064 G4MT_thePLHelper->CheckParticleList();
1065 }
1066}
1067
1068// --------------------------------------------------------------------
1070{
1071 G4MT_thePLHelper->AddTransportation();
1072}
1073
1074// --------------------------------------------------------------------
1076{
1077 G4MT_thePLHelper->UseCoupledTransportation(vl);
1078}
1079
1080// --------------------------------------------------------------------
1082 G4ParticleDefinition* particle)
1083{
1084 return G4MT_thePLHelper->RegisterProcess(process, particle);
1085}
1086
1087// --------------------------------------------------------------------
1090{
1091 return (subInstanceManager.offset[g4vuplInstanceID])._theParticleIterator;
1092}
1093
1094// --------------------------------------------------------------------
1096{
1097 verboseLevel = value;
1098 // set verboseLevel for G4ProductionCutsTable same as one for
1099 // G4VUserPhysicsList:
1101
1102 G4MT_thePLHelper->SetVerboseLevel(verboseLevel);
1103
1104#ifdef G4VERBOSE
1105 if(verboseLevel > 1)
1106 {
1107 G4cout << "G4VUserPhysicsList::SetVerboseLevel :"
1108 << " Verbose level is set to " << verboseLevel << G4endl;
1109 }
1110#endif
1111}
@ JustWarning
@ FatalException
@ RunMustBeAborted
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
#define G4MUTEXLOCK(mutex)
Definition: G4Threading.hh:251
#define G4MUTEXUNLOCK(mutex)
Definition: G4Threading.hh:254
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define G4MT_theMessenger
#define G4MT_thePLHelper
#define theParticleIterator
#define fIsPhysicsTableBuilt
#define fDisplayThreshold
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
static G4PART_DLL G4int & slavetotalspace()
G4int GetInstanceID() const
G4ProcessManager * GetProcessManager() const
G4VTrackingManager * GetTrackingManager() const
void SetMasterProcessManager(G4ProcessManager *aNewPM)
G4bool IsGeneralIon() const
void SetTrackingManager(G4VTrackingManager *aTrackingManager)
G4ProcessManager * GetMasterProcessManager() const
G4bool GetApplyCutsFlag() const
const G4String & GetParticleName() const
void SetProcessManager(G4ProcessManager *aProcessManager)
const G4String & GetParticleSubType() const
G4PTblDicIterator * GetIterator() const
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
static G4ParticleTable * GetParticleTable()
G4ParticleDefinition * GetGenericIon() const
static G4PhysicsListHelper * GetPhysicsListHelper()
G4ProcessVector * GetProcessList() const
std::size_t size() const
G4bool RetrieveCutsTable(const G4String &directory, G4bool ascii=false)
void SetVerboseLevel(G4int value)
G4bool StoreCutsTable(const G4String &directory, G4bool ascii=false)
void SetEnergyRange(G4double lowedge, G4double highedge)
static G4ProductionCutsTable * GetProductionCutsTable()
void SetProductionCut(G4double cut, G4int index)
G4double GetProductionCut(G4int index) const
static G4RegionStore * GetInstance()
G4Region * GetRegion(const G4String &name, G4bool verbose=true) const
G4ProductionCuts * GetProductionCuts() const
void SetProductionCuts(G4ProductionCuts *cut)
virtual void BuildPhysicsTable(const G4ParticleDefinition &)
Definition: G4VProcess.hh:187
const G4String & GetProcessName() const
Definition: G4VProcess.hh:386
G4int _fDisplayThreshold
G4bool _fIsPhysicsTableBuilt
G4ParticleTable::G4PTblDicIterator * _theParticleIterator
G4PhysicsListHelper * _thePLHelper
G4UserPhysicsListMessenger * _theMessenger
G4RUN_DLL G4ThreadLocalStatic T * offset
G4int CreateSubInstance()
G4double GetCutValue(const G4String &pname) const
void SetDefaultCutValue(G4double newCutValue)
void SetPhysicsTableRetrieved(const G4String &directory="")
G4VUserPhysicsList & operator=(const G4VUserPhysicsList &)
void PreparePhysicsTable(G4ParticleDefinition *)
virtual void TerminateWorker()
void SetCutValue(G4double aCut, const G4String &pname)
G4bool RegisterProcess(G4VProcess *process, G4ParticleDefinition *particle)
void UseCoupledTransportation(G4bool vl=true)
void SetCutsForRegion(G4double aCut, const G4String &rname)
G4ProductionCutsTable * fCutsTable
void AddProcessManager(G4ParticleDefinition *newParticle, G4ProcessManager *newManager=nullptr)
G4bool StorePhysicsTable(const G4String &directory=".")
G4ParticleTable::G4PTblDicIterator * GetParticleIterator() const
G4ParticleTable * theParticleTable
void SetVerboseLevel(G4int value)
void SetApplyCuts(G4bool value, const G4String &name)
virtual void RetrievePhysicsTable(G4ParticleDefinition *, const G4String &directory, G4bool ascii=false)
G4bool fIsCheckedForRetrievePhysicsTable
void SetParticleCuts(G4double cut, G4ParticleDefinition *particle, G4Region *region=nullptr)
void DumpCutValuesTable(G4int flag=1)
G4bool GetApplyCuts(const G4String &name) const
static G4RUN_DLL G4VUPLManager subInstanceManager
void BuildIntegralPhysicsTable(G4VProcess *, G4ParticleDefinition *)
G4int GetInstanceID() const
virtual void InitializeWorker()
static const G4VUPLManager & GetSubInstanceManager()