Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4RunManager.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// G4RunManager implementation
27//
28// Original author: M.Asai, 1996
29// --------------------------------------------------------------------
30
31#include "G4RunManager.hh"
32
33#include "G4ApplicationState.hh"
34#include "G4AssemblyStore.hh"
35#include "G4CopyRandomState.hh"
36#include "G4GeometryManager.hh"
37#include "G4HCofThisEvent.hh"
40#include "G4LogicalVolume.hh"
43#include "G4Material.hh"
47#include "G4ParticleTable.hh"
49#include "G4ProcessManager.hh"
50#include "G4ProcessTable.hh"
52#include "G4RegionStore.hh"
53#include "G4Run.hh"
54#include "G4RunManagerKernel.hh"
55#include "G4RunMessenger.hh"
56#include "G4SDManager.hh"
57#include "G4ScoringBox.hh"
58#include "G4ScoringCylinder.hh"
59#include "G4ScoringManager.hh"
60#include "G4SmartVoxelHeader.hh"
61#include "G4SmartVoxelStat.hh"
62#include "G4SolidStore.hh"
63#include "G4StateManager.hh"
64#include "G4Timer.hh"
66#include "G4FieldBuilder.hh"
67#include "G4UImanager.hh"
68#include "G4UnitsTable.hh"
69#include "G4UserRunAction.hh"
72#include "G4VHitsCollection.hh"
74#include "G4VPhysicalVolume.hh"
76#include "G4VScoringMesh.hh"
79#include "G4VUserPhysicsList.hh"
81#include "G4VVisManager.hh"
83#include "G4ios.hh"
84#include "Randomize.hh"
85
86#include <sstream>
87
88using namespace CLHEP;
89
90// The following lines are needed since G4VUserPhysicsList
91// uses a #define theParticleIterator
92#ifdef theParticleIterator
93# undef theParticleIterator
94#endif
95
96G4ThreadLocal G4RunManager* G4RunManager::fRunManager = nullptr;
97
99
100// --------------------------------------------------------------------
105
106// --------------------------------------------------------------------
108{
109 return fRunManager;
110}
111
112// --------------------------------------------------------------------
114{
115 if (fRunManager != nullptr) {
116 G4Exception("G4RunManager::G4RunManager()", "Run0031", FatalException,
117 "G4RunManager constructed twice.");
118 }
119 fRunManager = this;
120
122 eventManager = kernel->GetEventManager();
123
124 timer = new G4Timer();
125 runMessenger = new G4RunMessenger(this);
126 previousEvents = new std::list<G4Event*>;
129 std::ostringstream oss;
130 G4Random::saveFullState(oss);
134 G4UImanager::GetUIpointer()->SetAlias("RunMode sequential");
135}
136
137// --------------------------------------------------------------------
139{
140 // This version of the constructor should never be called in sequential mode!
141#ifndef G4MULTITHREADED
143 msg << "Geant4 code is compiled without multi-threading support "
144 "(-DG4MULTITHREADED is set to off).";
145 msg << " This type of RunManager can only be used in mult-threaded "
146 "applications.";
147 G4Exception("G4RunManager::G4RunManager(G4bool)", "Run0107", FatalException, msg);
148#endif
149
150 if (fRunManager != nullptr) {
151 G4Exception("G4RunManager::G4RunManager()", "Run0031", FatalException,
152 "G4RunManager constructed twice.");
153 return;
154 }
155 fRunManager = this;
156
157 switch (rmType) {
158 case masterRM:
160 break;
161 case workerRM:
163 break;
164 default:
166 msgx << "This type of RunManager can only be used in multi-threaded "
167 "applications.";
168 G4Exception("G4RunManager::G4RunManager(G4bool)", "Run0108", FatalException, msgx);
169 return;
170 }
171 runManagerType = rmType;
172
173 eventManager = kernel->GetEventManager();
174
175 timer = new G4Timer();
176 runMessenger = new G4RunMessenger(this);
177 previousEvents = new std::list<G4Event*>;
181 std::ostringstream oss;
182 G4Random::saveFullState(oss);
185}
186
187// --------------------------------------------------------------------
189{
191 // set the application state to the quite state
192 if (pStateManager->GetCurrentState() != G4State_Quit) {
193 if (verboseLevel > 1) G4cout << "G4 kernel has come to Quit state." << G4endl;
194 pStateManager->SetNewState(G4State_Quit);
195 }
196
198 if (verboseLevel > 1 && currentRun!=nullptr) {
199 G4cout << "Deleting G4Run (id:" << currentRun->GetRunID() << ") ";
200 if(currentRun->GetEventVectorSize()>0) {
201 G4cout << " that has " << currentRun->GetEventVectorSize()
202 << " events kept in eventVector";
203 }
204 G4cout << G4endl;
205 }
206 delete currentRun;
207 delete timer;
208 delete runMessenger;
209 delete previousEvents;
210
211 // The following will work for all RunManager types
212 // if derived class does the correct thing in the derived
213 // destructor that is: set to zero pointers of
214 // user initialization objects for which have no
215 // ownership
217 delete userRunAction;
218 userRunAction = nullptr;
219 if (verboseLevel > 1) G4cout << "UserRunAction deleted." << G4endl;
220
223 if (verboseLevel > 1) G4cout << "UserPrimaryGenerator deleted." << G4endl;
224
225 if (verboseLevel > 1) G4cout << "RunManager is deleting RunManagerKernel." << G4endl;
226
227 delete kernel;
228
229 fRunManager = nullptr;
230
231 if (verboseLevel > 1) G4cout << "RunManager is deleted." << G4endl;
232}
233
234// --------------------------------------------------------------------
236{
237 if (verboseLevel > 1) G4cout << "UserDetectorConstruction deleted " << userDetector << G4endl;
238 delete userDetector;
239 userDetector = nullptr;
240
241 if (verboseLevel > 1) G4cout << "UserPhysicsList deleted " << physicsList << G4endl;
242 delete physicsList;
243 physicsList = nullptr;
244
245 if (verboseLevel > 1) G4cout << "UserActionInitialization deleted " << userActionInitialization << G4endl;
247 userActionInitialization = nullptr;
248
249 if (verboseLevel > 1) G4cout << "UserWorkerInitialization deleted " << userWorkerInitialization << G4endl;
251 userWorkerInitialization = nullptr;
252
253 if (verboseLevel > 1) G4cout << "UserWorkerThreadInitialization deleted " << userWorkerThreadInitialization << G4endl;
256}
257
258// --------------------------------------------------------------------
259void G4RunManager::BeamOn(G4int n_event, const char* macroFile, G4int n_select)
260{
261 fakeRun = n_event <= 0;
263 if (cond) {
268 DoEventLoop(n_event, macroFile, n_select);
270 }
271 fakeRun = false;
272}
273
274// --------------------------------------------------------------------
276{
278
279 G4ApplicationState currentState = stateManager->GetCurrentState();
280 if (currentState != G4State_PreInit && currentState != G4State_Idle) {
281 G4cerr << "Illegal application state - BeamOn() ignored." << G4endl;
282 return false;
283 }
284
286 G4cerr << " Geant4 kernel should be initialized" << G4endl;
287 G4cerr << "before the first BeamOn(). - BeamOn ignored." << G4endl;
288 return false;
289 }
290
292 if (verboseLevel > 0) {
293 G4cout << "Start re-initialization because " << G4endl;
294 if (!geometryInitialized) G4cout << " Geometry" << G4endl;
295 if (!physicsInitialized) G4cout << " Physics processes" << G4endl;
296 G4cout << "has been modified since last Run." << G4endl;
297 }
298 Initialize();
299 }
300 return true;
301}
302
303// --------------------------------------------------------------------
305{
306 if (!(kernel->RunInitialization(fakeRun))) return;
307
308 runAborted = false;
310
312 if (verboseLevel > 2 && currentRun!=nullptr) {
313 G4cout << "Deleting G4Run (id:" << currentRun->GetRunID() << ") ";
314 if(currentRun->GetEventVectorSize()>0) {
315 G4cout << " that has " << currentRun->GetEventVectorSize()
316 << " events kept in eventVector";
317 }
318 G4cout << G4endl;
319 }
320 delete currentRun;
321 currentRun = nullptr;
322
323 if (fakeRun) return;
324
326
327 if (userRunAction != nullptr) currentRun = userRunAction->GenerateRun();
328 if (currentRun == nullptr) currentRun = new G4Run();
329
330 currentRun->SetRunID(runIDCounter);
331 currentRun->SetNumberOfEventToBeProcessed(numberOfEventToBeProcessed);
332
333 currentRun->SetDCtable(DCtable);
335 if (fSDM != nullptr) {
336 currentRun->SetHCtable(fSDM->GetHCtable());
337 }
338
339 if (G4VScoreNtupleWriter::Instance() != nullptr) {
340 auto hce = (fSDM != nullptr) ? fSDM->PrepareNewEvent() : nullptr;
342 delete hce;
343 }
344
345 std::ostringstream oss;
346 G4Random::saveFullState(oss);
348 currentRun->SetRandomNumberStatus(randomNumberStatusForThisRun);
349
350 for (G4int i_prev = 0; i_prev < n_perviousEventsToBeStored; ++i_prev) {
351 previousEvents->push_back(nullptr);
352 }
353
354 if (printModulo >= 0 || verboseLevel > 0) {
355 G4cout << "### Run " << currentRun->GetRunID() << " starts." << G4endl;
356 }
357 if (userRunAction != nullptr) userRunAction->BeginOfRunAction(currentRun);
358
361 }
362
364 G4String fileN = "currentRun";
366 std::ostringstream os;
367 os << "run" << currentRun->GetRunID();
368 fileN = os.str();
369 }
370 StoreRNGStatus(fileN);
371 }
372}
373
374// --------------------------------------------------------------------
375void G4RunManager::DoEventLoop(G4int n_event, const char* macroFile, G4int n_select)
376{
377 InitializeEventLoop(n_event, macroFile, n_select);
378
379 // Event loop
380 for (G4int i_event = 0; i_event < n_event; ++i_event) {
381 ProcessOneEvent(i_event);
383 if (runAborted) break;
384 }
385
386 // For G4MTRunManager, TerminateEventLoop() is invoked after all threads are
387 // finished.
389}
390
391// --------------------------------------------------------------------
392void G4RunManager::InitializeEventLoop(G4int n_event, const char* macroFile, G4int n_select)
393{
394 if (verboseLevel > 0) {
395 timer->Start();
396 }
397
398 n_select_msg = n_select;
399 if (macroFile != nullptr) {
400 if (n_select_msg < 0) n_select_msg = n_event;
401 msgText = "/control/execute ";
402 msgText += macroFile;
403 selectMacro = macroFile;
404 }
405 else {
406 n_select_msg = -1;
407 selectMacro = "";
408 }
409}
410
411// --------------------------------------------------------------------
420
421// --------------------------------------------------------------------
428
429// --------------------------------------------------------------------
431{
432 if (verboseLevel > 0 && !fakeRun) {
433 timer->Stop();
434 G4cout << " Run terminated." << G4endl;
435 G4cout << "Run Summary" << G4endl;
436 if (runAborted) {
437 G4cout << " Run Aborted after " << numberOfEventProcessed << " events processed." << G4endl;
438 }
439 else {
440 G4cout << " Number of events processed : " << numberOfEventProcessed << G4endl;
441 }
442 G4cout << " " << *timer << G4endl;
443 }
445}
446
447// --------------------------------------------------------------------
449{
450 if (userPrimaryGeneratorAction == nullptr) {
451 G4Exception("G4RunManager::GenerateEvent()", "Run0032", FatalException,
452 "G4VUserPrimaryGeneratorAction is not defined!");
453 return nullptr;
454 }
455
456 auto anEvent = new G4Event(i_event);
457
459 std::ostringstream oss;
460 G4Random::saveFullState(oss);
462 anEvent->SetRandomNumberStatus(randomNumberStatusForThisEvent);
463 }
464
466 G4String fileN = "currentEvent";
468 std::ostringstream os;
469 os << "run" << currentRun->GetRunID() << "evt" << anEvent->GetEventID();
470 fileN = os.str();
471 }
472 StoreRNGStatus(fileN);
473 }
474
475 if (printModulo > 0 && anEvent->GetEventID() % printModulo == 0) {
476 G4cout << "--> Event " << anEvent->GetEventID() << " starts." << G4endl;
477 }
478 userPrimaryGeneratorAction->GeneratePrimaries(anEvent);
479 return anEvent;
480}
481
482// --------------------------------------------------------------------
484{
485 G4String fileN = randomNumberStatusDir + fnpref + ".rndm";
486 G4Random::saveEngineStatus(fileN);
487}
488
489// --------------------------------------------------------------------
491{
493 if (fPersM != nullptr) fPersM->Store(anEvent);
494 currentRun->RecordEvent(anEvent);
495}
496
497// --------------------------------------------------------------------
499{
500 if (!fakeRun) {
502// if(G4int(previousEvents->size())>0) {
503// G4ExceptionDescription ed;
504// ed << "Run still has " << previousEvents->size() << " unfinished events!!";
505// G4Exception("G4RunManager::RunTermination()","RM09009",FatalException,ed);
506// }
507 // tasking occasionally will call this function even
508 // if there was not a current run
509 if (currentRun != nullptr) {
510 if (userRunAction != nullptr) userRunAction->EndOfRunAction(currentRun);
512 if (fPersM != nullptr) fPersM->Store(currentRun);
513 // write & close analysis output
516 }
517 }
518 ++runIDCounter;
519 }
520
521 kernel->RunTermination();
522}
523
524// --------------------------------------------------------------------
526{
527 // Delete all events carried over from previous run.
528 // This method is invoked at the beginning of the next run
529 // or from the destructor of G4RunManager at the very end of
530 // the program.
531 // N.B. If ToBeKept() is true, the pointer of this event is
532 // kept in G4Run of the previous run, and deleted along with
533 // the deletion of G4Run.
534
535 auto evItr = previousEvents->cbegin();
536 while (evItr != previousEvents->cend()) {
537 G4Event* evt = *evItr;
538 if (evt != nullptr && !(evt->ToBeKept())) {
540 delete evt;
541 }
542 evItr = previousEvents->erase(evItr);
543 }
544
545}
546
547// --------------------------------------------------------------------
549{
550 // Delete events that are no longer necessary for post
551 // processing such as visualization.
552 // N.B. If ToBeKept() is true, the pointer of this event is
553 // kept in G4Run of the previous run, and deleted along with
554 // the deletion of G4Run.
555
556 auto evItr = previousEvents->cbegin();
557 while (evItr != previousEvents->cend()) {
558 if (G4int(previousEvents->size()) <= keepNEvents) return;
559
560 G4Event* evt = *evItr;
561 if (evt != nullptr) {
562 if (evt->GetNumberOfGrips() == 0) {
563 if (!(evt->ToBeKept())) {
565 delete evt;
566 }
567 evItr = previousEvents->erase(evItr);
568 }
569 else {
570 ++evItr;
571 }
572 }
573 else {
574 evItr = previousEvents->erase(evItr);
575 }
576 }
577}
578
579// --------------------------------------------------------------------
581{
582 if (anEvent->ToBeKept()) currentRun->StoreEvent(anEvent);
583
585 if (anEvent->GetNumberOfGrips() == 0) {
586 if (!(anEvent->ToBeKept())) {
587 ReportEventDeletion(anEvent);
588 delete anEvent;
589 }
590 }
591 else {
592 previousEvents->push_back(anEvent);
593 }
594 }
595 else {
596 previousEvents->push_back(anEvent);
597 }
598
600}
601
602// --------------------------------------------------------------------
604{
605 if(verboseLevel > 3) {
606 G4cout << "deleting G4Event(" << evt << ") eventID = " << evt->GetEventID()
607 << " -- grips = " << evt->GetNumberOfGrips()
608 << " keepFlag = " << evt->KeepTheEventFlag()
609 << " subEvt = " << evt->GetNumberOfRemainingSubEvents();
610 if(evt->GetNumberOfCompletedSubEvent()>0) {
611 G4cout << " -- contains " << evt->GetNumberOfCompletedSubEvent() << " completed sub-events";
612 }
613 G4cout << G4endl;
614 }
615}
616// --------------------------------------------------------------------
618{
620 G4ApplicationState currentState = stateManager->GetCurrentState();
621 if (currentState != G4State_PreInit && currentState != G4State_Idle) {
622 G4cerr << "Illegal application state - "
623 << "G4RunManager::Initialize() ignored." << G4endl;
624 return;
625 }
626
627 stateManager->SetNewState(G4State_Init);
631 if (stateManager->GetCurrentState() != G4State_Idle) {
632 stateManager->SetNewState(G4State_Idle);
633 }
634}
635
636// --------------------------------------------------------------------
638{
639 if (userDetector == nullptr) {
640 G4Exception("G4RunManager::InitializeGeometry", "Run0033", FatalException,
641 "G4VUserDetectorConstruction is not defined!");
642 return;
643 }
644
645 if (verboseLevel > 1) G4cout << "userDetector->Construct() start." << G4endl;
646
648 G4ApplicationState currentState = stateManager->GetCurrentState();
649 if (currentState == G4State_PreInit || currentState == G4State_Idle) {
650 stateManager->SetNewState(G4State_Init);
651 }
653 kernel->DefineWorldVolume(userDetector->Construct(), false);
654 userDetector->ConstructSDandField();
655 nParallelWorlds = userDetector->ConstructParallelGeometries();
656 userDetector->ConstructParallelSD();
657 kernel->SetNumberOfParallelWorld(nParallelWorlds);
658 }
659 // Notify the VisManager as well
662 if (pVVisManager != nullptr) pVVisManager->GeometryHasChanged();
663 }
664
666 geometryInitialized = true;
667 stateManager->SetNewState(currentState);
668}
669
670// --------------------------------------------------------------------
672{
674 G4ApplicationState currentState = stateManager->GetCurrentState();
675 if (currentState == G4State_PreInit || currentState == G4State_Idle) {
676 stateManager->SetNewState(G4State_Init);
677 }
678 if (physicsList != nullptr) {
679 kernel->InitializePhysics();
680 }
681 else {
682 G4Exception("G4RunManager::InitializePhysics()", "Run0034", FatalException,
683 "G4VUserPhysicsList is not defined!");
684 }
685 physicsInitialized = true;
686 stateManager->SetNewState(currentState);
687}
688
689// --------------------------------------------------------------------
691{
692 // This method is valid only for GeomClosed or EventProc state
694 if (currentState == G4State_GeomClosed || currentState == G4State_EventProc) {
695 runAborted = true;
696 if (currentState == G4State_EventProc && !softAbort) {
697 currentEvent->SetEventAborted();
698 eventManager->AbortCurrentEvent();
699 }
700 }
701 else {
702 G4cerr << "Run is not in progress. AbortRun() ignored." << G4endl;
703 }
704}
705
706// --------------------------------------------------------------------
708{
709 // This method is valid only for EventProc state
711 if (currentState == G4State_EventProc) {
712 currentEvent->SetEventAborted();
713 eventManager->AbortCurrentEvent();
714 }
715 else {
716 G4cerr << "Event is not in progress. AbortEevnt() ignored." << G4endl;
717 }
718}
719
720// --------------------------------------------------------------------
722{
723 kernel->DefineWorldVolume(worldVol, topologyIsChanged);
724}
725
726// --------------------------------------------------------------------
728{
729 G4int runNumber = 0;
730 if (currentRun != nullptr) runNumber = currentRun->GetRunID();
732 G4cerr << "Warning from G4RunManager::rndmSaveThisRun():"
733 << " Random number status was not stored prior to this run." << G4endl
734 << "/random/setSavingFlag command must be issued. "
735 << "Command ignored." << G4endl;
736 return;
737 }
738
739 G4fs::path fileIn = randomNumberStatusDir + "currentRun.rndm";
740
741 std::ostringstream os;
742 os << "run" << runNumber << ".rndm" << '\0';
743 G4fs::path fileOut = randomNumberStatusDir + os.str();
744
745 if (G4CopyRandomState(fileIn, fileOut, "G4RunManager::rndmSaveThisRun()") && verboseLevel > 0)
746 {
747 G4cout << fileIn << " is copied to " << fileOut << G4endl;
748 }
749}
750
751// --------------------------------------------------------------------
753{
754 if (currentEvent == nullptr) {
755 G4cerr << "Warning from G4RunManager::rndmSaveThisEvent():"
756 << " there is no currentEvent available." << G4endl << "Command ignored." << G4endl;
757 return;
758 }
759
761 G4cerr << "Warning from G4RunManager::rndmSaveThisEvent():"
762 << " Random number engine status is not available." << G4endl
763 << "/random/setSavingFlag command must be issued "
764 << "prior to the start of the run. Command ignored." << G4endl;
765 return;
766 }
767
768 G4fs::path fileIn = randomNumberStatusDir + "currentEvent.rndm";
769
770 std::ostringstream os;
771 os << "run" << currentRun->GetRunID() << "evt" << currentEvent->GetEventID() << ".rndm" << '\0';
772 G4fs::path fileOut = randomNumberStatusDir + os.str();
773
774 if (G4CopyRandomState(fileIn, fileOut, "G4RunManager::rndmSaveThisEvent()") && verboseLevel > 0)
775 {
776 G4cout << fileIn << " is copied to " << fileOut << G4endl;
777 }
778}
779
780// --------------------------------------------------------------------
782{
783 G4String fileNameWithDirectory;
784 if (fileN.find('/') == std::string::npos) {
785 fileNameWithDirectory = randomNumberStatusDir + fileN;
786 }
787 else {
788 fileNameWithDirectory = fileN;
789 }
790
791 G4Random::restoreEngineStatus(fileNameWithDirectory);
792 if (verboseLevel > 0)
793 G4cout << "RandomNumberEngineStatus restored from file: " << fileNameWithDirectory << G4endl;
794 G4Random::showEngineStatus();
795}
796
797// --------------------------------------------------------------------
798void G4RunManager::DumpRegion(const G4String& rname) const
799{
800 kernel->DumpRegion(rname);
801}
802
803// --------------------------------------------------------------------
805{
806 kernel->DumpRegion(region);
807}
808
809// --------------------------------------------------------------------
811{
812 using MeshShape = G4VScoringMesh::MeshShape;
813
815 if (ScM == nullptr) return;
816
817 auto nPar = (G4int)ScM->GetNumberOfMesh();
818 if (nPar < 1) return;
819
821 for (G4int iw = 0; iw < nPar; ++iw) {
822 G4VScoringMesh* mesh = ScM->GetMesh(iw);
824 G4VPhysicalVolume* pWorld = nullptr;
825 if (mesh->GetShape() != MeshShape::realWorldLogVol) {
826 pWorld =
828 if (pWorld == nullptr) {
830 ScM->GetWorldName(iw));
831 pWorld->SetName(ScM->GetWorldName(iw));
832
833 G4ParallelWorldProcess* theParallelWorldProcess = mesh->GetParallelWorldProcess();
834 if (theParallelWorldProcess != nullptr) {
835 theParallelWorldProcess->SetParallelWorld(ScM->GetWorldName(iw));
836 }
837 else {
838 theParallelWorldProcess = new G4ParallelWorldProcess(ScM->GetWorldName(iw));
839 mesh->SetParallelWorldProcess(theParallelWorldProcess);
840 theParallelWorldProcess->SetParallelWorld(ScM->GetWorldName(iw));
841
842 theParticleIterator->reset();
843 while ((*theParticleIterator)()) {
844 G4ParticleDefinition* particle = theParticleIterator->value();
845 G4ProcessManager* pmanager = particle->GetProcessManager();
846 if (pmanager != nullptr) {
847 pmanager->AddProcess(theParallelWorldProcess);
848 if (theParallelWorldProcess->IsAtRestRequired(particle)) {
849 pmanager->SetProcessOrdering(theParallelWorldProcess, idxAtRest, 9900);
850 }
851 pmanager->SetProcessOrderingToSecond(theParallelWorldProcess, idxAlongStep);
852 pmanager->SetProcessOrdering(theParallelWorldProcess, idxPostStep, 9900);
853 }
854 }
855 }
856 theParallelWorldProcess->SetLayeredMaterialFlag(mesh->LayeredMassFlg());
857 }
858 }
859 mesh->Construct(pWorld);
860 }
862}
863
864// --------------------------------------------------------------------
866{
867 if(evt==nullptr) evt = currentEvent;
868
869//MAMAMAMA need revisiting
870 if(evt->ScoresAlreadyRecorded()) return;
871//MAMAMAMA need revisiting
872
875 }
876
877 if(evt->ScoresAlreadyRecorded()) {
878 G4Exception("G4RunManager::UpdateScoring()","RMSubEvt001",FatalException,
879 "Double-counting!!!");
880 }
881
882 evt->ScoresRecorded();
883
885 if (ScM == nullptr) return;
886 auto nPar = (G4int)ScM->GetNumberOfMesh();
887 if (nPar < 1) return;
888
889 G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
890 if (HCE == nullptr) return;
891 auto nColl = (G4int)HCE->GetCapacity();
892 for (G4int i = 0; i < nColl; ++i) {
893 G4VHitsCollection* HC = HCE->GetHC(i);
894 if (HC != nullptr) ScM->Accumulate(HC);
895 }
896}
897
898// --------------------------------------------------------------------
900{
901 G4LogicalVolume* pMotherL = pPhys->GetMotherLogical();
902 if (pMotherL != nullptr) ReOptimize(pMotherL);
903}
904
905// --------------------------------------------------------------------
907{
908 G4Timer localtimer;
909 if (verboseLevel > 1) {
910 localtimer.Start();
911 }
912 G4SmartVoxelHeader* header = pLog->GetVoxelHeader();
913 delete header;
914 header = new G4SmartVoxelHeader(pLog);
915 pLog->SetVoxelHeader(header);
916 if (verboseLevel > 1) {
917 localtimer.Stop();
918 G4SmartVoxelStat stat(pLog, header, localtimer.GetSystemElapsed(), localtimer.GetUserElapsed());
919 G4cout << G4endl << "Voxelisation of logical volume <" << pLog->GetName() << ">" << G4endl;
920 G4cout << " heads : " << stat.GetNumberHeads() << " - nodes : " << stat.GetNumberNodes()
921 << " - pointers : " << stat.GetNumberPointers() << G4endl;
922 G4cout << " Memory used : " << (stat.GetMemoryUse() + 512) / 1024
923 << "k - total time : " << stat.GetTotalTime() << " - system time : " << stat.GetSysTime()
924 << G4endl;
925 }
926}
927
928// --------------------------------------------------------------------
933
934// --------------------------------------------------------------------
936{
937 physicsList = userInit;
938 kernel->SetPhysics(userInit);
939}
940
941// --------------------------------------------------------------------
943{
944 G4Exception("G4RunManager::SetUserInitialization()", "Run3001", FatalException,
945 "Base-class G4RunManager cannot take G4UserWorkerInitialization. Use "
946 "G4MTRunManager.");
947}
948
949// --------------------------------------------------------------------
951{
952 G4Exception("G4RunManager::SetUserThreadInitialization()", "Run3001", FatalException,
953 "Base-class G4RunManager cannot take G4UserWorkerThreadInitialization. "
954 "Use G4MTRunManager.");
955}
956
957// --------------------------------------------------------------------
963
964// --------------------------------------------------------------------
966{
967 userRunAction = userAction;
968}
969
970// --------------------------------------------------------------------
975
976// --------------------------------------------------------------------
978{
979 eventManager->SetUserAction(userAction);
980 userEventAction = userAction;
981}
982
983// --------------------------------------------------------------------
985{
986 eventManager->SetUserAction(userAction);
987 userStackingAction = userAction;
988}
989
990// --------------------------------------------------------------------
992{
993 eventManager->SetUserAction(userAction);
994 userTrackingAction = userAction;
995}
996
997// --------------------------------------------------------------------
999{
1000 eventManager->SetUserAction(userAction);
1001 userSteppingAction = userAction;
1002}
1003
1004// --------------------------------------------------------------------
1006{
1007 if (prop) {
1008 G4UImanager::GetUIpointer()->ApplyCommand("/run/geometryModified");
1009 }
1010 else {
1011 kernel->GeometryHasBeenModified();
1012 }
1013}
1014
1015// --------------------------------------------------------------------
1017{
1018 if (destroyFirst && G4Threading::IsMasterThread()) {
1019 if (verboseLevel > 0) {
1020 G4cout << "#### Assembly, Volume, Solid, and Surface Stores are being cleaned." << G4endl;
1021 }
1029
1030 // remove all logical volume pointers from regions
1031 // exception: world logical volume pointer must be kept
1033 for (const auto& rItr : *regionStore) {
1034 if (rItr->GetName() == "DefaultRegionForTheWorld") continue;
1035 auto lvItr = rItr->GetRootLogicalVolumeIterator();
1036 for (std::size_t iRLV = 0; iRLV < rItr->GetNumberOfRootVolumes(); ++iRLV) {
1037 rItr->RemoveRootLogicalVolume(*lvItr, false);
1038 ++lvItr;
1039 }
1040 if (verboseLevel > 0) {
1041 G4cout << "#### Region <" << rItr->GetName() << "> is cleared." << G4endl;
1042 }
1043 }
1044
1045 // clear transportation manager
1048 }
1049 if (prop) {
1050 G4UImanager::GetUIpointer()->ApplyCommand("/run/reinitializeGeometry");
1051 }
1052 else {
1053 kernel->GeometryHasBeenModified();
1054 geometryInitialized = false;
1055 // Notify the VisManager as well
1058 if (pVVisManager != nullptr) pVVisManager->GeometryHasChanged();
1059 }
1060 // Reinitialize field builder
1063 }
1064 }
1065}
1066
1067// --------------------------------------------------------------------
G4ApplicationState
@ G4State_EventProc
@ G4State_Init
@ G4State_Idle
@ G4State_Quit
@ G4State_GeomClosed
@ G4State_PreInit
Helper function for copying random state files in G4run.
G4bool G4CopyRandomState(const G4fs::path &source, const G4fs::path &dest, const G4String &callsite)
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
@ idxPostStep
@ idxAtRest
@ idxAlongStep
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
#define theParticleIterator
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
static G4AssemblyStore * GetInstance()
static void Clean()
G4bool ToBeKept() const
Definition G4Event.hh:105
G4int GetNumberOfGrips() const
Definition G4Event.hh:123
G4HCofThisEvent * GetHCofThisEvent() const
Definition G4Event.hh:164
G4int GetNumberOfCompletedSubEvent() const
Definition G4Event.hh:260
G4int GetEventID() const
Definition G4Event.hh:126
G4bool KeepTheEventFlag() const
Definition G4Event.hh:103
G4bool ScoresAlreadyRecorded() const
Definition G4Event.hh:306
void ScoresRecorded() const
Definition G4Event.hh:305
G4int GetNumberOfRemainingSubEvents() const
Definition G4Event.cc:277
static G4bool IsInstance()
static G4FieldBuilder * Instance()
static G4GeometryManager * GetInstance()
void OpenGeometry(G4VPhysicalVolume *vol=nullptr)
std::size_t GetCapacity()
G4VHitsCollection * GetHC(G4int i)
static G4LogicalVolumeStore * GetInstance()
G4LogicalVolume represents a leaf node or unpositioned subtree in the geometry hierarchy....
void SetVoxelHeader(G4SmartVoxelHeader *pVoxel)
const G4String & GetName() const
G4SmartVoxelHeader * GetVoxelHeader() const
static G4ParallelWorldProcessStore * GetInstance()
void SetLayeredMaterialFlag(G4bool flg=true)
void SetParallelWorld(G4String parallelWorldName)
G4bool IsAtRestRequired(G4ParticleDefinition *)
G4ProcessManager * GetProcessManager() const
G4PTblDicIterator * GetIterator() const
static G4ParticleTable * GetParticleTable()
G4UImessenger * CreateMessenger()
static G4PhysicalVolumeStore * GetInstance()
void SetProcessOrdering(G4VProcess *aProcess, G4ProcessVectorDoItIndex idDoIt, G4int ordDoIt=ordDefault)
void SetProcessOrderingToSecond(G4VProcess *aProcess, G4ProcessVectorDoItIndex idDoIt)
G4int AddProcess(G4VProcess *aProcess, G4int ordAtRestDoIt=ordInActive, G4int ordAlongSteptDoIt=ordInActive, G4int ordPostStepDoIt=ordInActive)
static G4ProcessTable * GetProcessTable()
G4RegionStore is a singleton class, acting as container for all geometrical regions,...
static G4RegionStore * GetInstance()
G4Region defines a region or a group of regions in the detector geometry setup, sharing properties as...
Definition G4Region.hh:90
G4bool isScoreNtupleWriter
G4bool geometryInitialized
virtual void CleanUpPreviousEvents()
virtual void CleanUpUnnecessaryEvents(G4int keepNEvents)
G4int storeRandomNumberStatusToG4Event
G4UserWorkerInitialization * userWorkerInitialization
virtual void AbortRun(G4bool softAbort=false)
virtual void Initialize()
G4int nParallelWorlds
virtual void ReportEventDeletion(const G4Event *evt)
std::list< G4Event * > * previousEvents
G4Timer * timer
G4UserWorkerThreadInitialization * userWorkerThreadInitialization
G4bool geometryDirectlyUpdated
G4int numberOfEventProcessed
virtual void RestoreRandomNumberStatus(const G4String &fileN)
virtual void InitializeEventLoop(G4int n_event, const char *macroFile=nullptr, G4int n_select=-1)
G4UserEventAction * userEventAction
void ReinitializeGeometry(G4bool destroyFirst=false, G4bool prop=true)
virtual void rndmSaveThisEvent()
virtual void DeleteUserInitializations()
G4RunManagerKernel * kernel
G4Run * currentRun
virtual G4bool ConfirmBeamOnCondition()
static G4RunManager * GetRunManager()
virtual void AbortEvent()
virtual void rndmSaveThisRun()
virtual void InitializePhysics()
G4DCtable * DCtable
G4String randomNumberStatusForThisRun
G4String msgText
virtual void BeamOn(G4int n_event, const char *macroFile=nullptr, G4int n_select=-1)
static G4bool IfGeometryHasBeenDestroyed()
G4UserRunAction * userRunAction
virtual void DefineWorldVolume(G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
G4bool rngStatusEventsFlag
G4String selectMacro
virtual void InitializeGeometry()
virtual void RunTermination()
G4bool physicsInitialized
G4VUserActionInitialization * userActionInitialization
virtual void StackPreviousEvent(G4Event *anEvent)
static G4RUN_DLL G4bool fGeometryHasBeenDestroyed
void ReOptimize(G4LogicalVolume *)
G4VUserDetectorConstruction * userDetector
G4VUserPrimaryGeneratorAction * userPrimaryGeneratorAction
void UpdateScoring(const G4Event *evt=nullptr)
G4int numberOfEventToBeProcessed
virtual ~G4RunManager()
G4String randomNumberStatusDir
virtual void TerminateEventLoop()
virtual void SetUserAction(G4UserRunAction *userAction)
G4String randomNumberStatusForThisEvent
void GeometryHasBeenModified(G4bool prop=true)
G4UserTrackingAction * userTrackingAction
RMType runManagerType
G4int n_perviousEventsToBeStored
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
void ReOptimizeMotherOf(G4VPhysicalVolume *)
virtual void ProcessOneEvent(G4int i_event)
G4bool storeRandomNumberStatus
virtual G4Event * GenerateEvent(G4int i_event)
G4bool initializedAtLeastOnce
G4EventManager * eventManager
virtual void StoreRNGStatus(const G4String &filenamePrefix)
virtual void DoEventLoop(G4int n_event, const char *macroFile=nullptr, G4int n_select=-1)
virtual void TerminateOneEvent()
virtual void RunInitialization()
void DumpRegion(const G4String &rname) const
G4VUserPhysicsList * physicsList
virtual void AnalyzeEvent(G4Event *anEvent)
G4UserStackingAction * userStackingAction
G4Event * currentEvent
virtual void ConstructScoringWorlds()
G4UserSteppingAction * userSteppingAction
Definition G4Run.hh:48
G4HCofThisEvent * PrepareNewEvent()
static G4SDManager * GetSDMpointerIfExist()
G4HCtable * GetHCtable() const
G4VScoringMesh * GetMesh(G4int i) const
void Accumulate(G4VHitsCollection *map)
const G4String & GetWorldName(G4int i) const
std::size_t GetNumberOfMesh() const
static G4ScoringManager * GetScoringManagerIfExist()
G4SmartVoxelHeader represents a set of voxels, created by a single axis of virtual division....
G4SmartVoxelStat stores the information on the performance of the smart voxel optimisation algorithm ...
G4long GetMemoryUse() const
G4double GetTotalTime() const
G4long GetNumberPointers() const
G4long GetNumberHeads() const
G4double GetSysTime() const
G4long GetNumberNodes() const
static void Clean()
static G4SolidStore * GetInstance()
const G4ApplicationState & GetCurrentState() const
static G4StateManager * GetStateManager()
G4bool SetNewState(const G4ApplicationState &requestedState)
void Stop()
G4double GetSystemElapsed() const
Definition G4Timer.cc:124
G4double GetUserElapsed() const
Definition G4Timer.cc:135
void Start()
G4VPhysicalVolume * GetParallelWorld(const G4String &worldName)
static G4TransportationManager * GetTransportationManager()
G4VPhysicalVolume * IsWorldExisting(const G4String &worldName)
G4int ApplyCommand(const char *aCommand)
void SetAlias(const char *aliasLine)
static G4UImanager * GetUIpointer()
static G4VPersistencyManager * GetPersistencyManager()
virtual G4bool Store(const G4Event *anEvent)=0
G4VPhysicalVolume is an abstract base class for the representation of a positioned volume....
G4LogicalVolume * GetMotherLogical() const
void SetName(const G4String &pName)
virtual void Write()=0
virtual void Fill(G4HCofThisEvent *hce, G4int eventNumber)=0
virtual G4bool Book(G4HCofThisEvent *hce)=0
static G4VScoreNtupleWriter * Instance()
virtual void OpenFile()=0
MeshShape GetShape() const
void GeometryHasBeenDestroyed()
G4ParallelWorldProcess * GetParallelWorldProcess() const
void SetParallelWorldProcess(G4ParallelWorldProcess *proc)
virtual void Construct(G4VPhysicalVolume *fWorldPhys)
G4bool LayeredMassFlg()
static G4VVisManager * GetConcreteInstance()
virtual void GeometryHasChanged()=0
G4bool IsMasterThread()
#define G4ThreadLocal
Definition tls.hh:77