Geant4 11.3.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"
38#include "G4LogicalVolume.hh"
41#include "G4Material.hh"
45#include "G4ParticleTable.hh"
47#include "G4ProcessManager.hh"
48#include "G4ProcessTable.hh"
50#include "G4RegionStore.hh"
51#include "G4Run.hh"
52#include "G4RunManagerKernel.hh"
53#include "G4RunMessenger.hh"
54#include "G4SDManager.hh"
55#include "G4ScoringBox.hh"
56#include "G4ScoringCylinder.hh"
57#include "G4ScoringManager.hh"
58#include "G4SmartVoxelHeader.hh"
59#include "G4SmartVoxelStat.hh"
60#include "G4SolidStore.hh"
61#include "G4StateManager.hh"
62#include "G4Timer.hh"
64#include "G4FieldBuilder.hh"
65#include "G4UImanager.hh"
66#include "G4UnitsTable.hh"
67#include "G4UserRunAction.hh"
70#include "G4VHitsCollection.hh"
72#include "G4VPhysicalVolume.hh"
74#include "G4VScoringMesh.hh"
77#include "G4VUserPhysicsList.hh"
79#include "G4VVisManager.hh"
81#include "G4ios.hh"
82#include "Randomize.hh"
83
84#include <sstream>
85
86using namespace CLHEP;
87
88// The following lines are needed since G4VUserPhysicsList
89// uses a #define theParticleIterator
90#ifdef theParticleIterator
91# undef theParticleIterator
92#endif
93
94G4ThreadLocal G4RunManager* G4RunManager::fRunManager = nullptr;
95
97
98// --------------------------------------------------------------------
103
104// --------------------------------------------------------------------
106{
107 return fRunManager;
108}
109
110// --------------------------------------------------------------------
112{
113 if (fRunManager != nullptr) {
114 G4Exception("G4RunManager::G4RunManager()", "Run0031", FatalException,
115 "G4RunManager constructed twice.");
116 }
117 fRunManager = this;
118
120 eventManager = kernel->GetEventManager();
121
122 timer = new G4Timer();
123 runMessenger = new G4RunMessenger(this);
124 previousEvents = new std::list<G4Event*>;
127 std::ostringstream oss;
128 G4Random::saveFullState(oss);
132 G4UImanager::GetUIpointer()->SetAlias("RunMode sequential");
133}
134
135// --------------------------------------------------------------------
137{
138 // This version of the constructor should never be called in sequential mode!
139#ifndef G4MULTITHREADED
141 msg << "Geant4 code is compiled without multi-threading support "
142 "(-DG4MULTITHREADED is set to off).";
143 msg << " This type of RunManager can only be used in mult-threaded "
144 "applications.";
145 G4Exception("G4RunManager::G4RunManager(G4bool)", "Run0107", FatalException, msg);
146#endif
147
148 if (fRunManager != nullptr) {
149 G4Exception("G4RunManager::G4RunManager()", "Run0031", FatalException,
150 "G4RunManager constructed twice.");
151 return;
152 }
153 fRunManager = this;
154
155 switch (rmType) {
156 case masterRM:
158 break;
159 case workerRM:
161 break;
162 default:
164 msgx << "This type of RunManager can only be used in multi-threaded "
165 "applications.";
166 G4Exception("G4RunManager::G4RunManager(G4bool)", "Run0108", FatalException, msgx);
167 return;
168 }
169 runManagerType = rmType;
170
171 eventManager = kernel->GetEventManager();
172
173 timer = new G4Timer();
174 runMessenger = new G4RunMessenger(this);
175 previousEvents = new std::list<G4Event*>;
179 std::ostringstream oss;
180 G4Random::saveFullState(oss);
183}
184
185// --------------------------------------------------------------------
187{
189 // set the application state to the quite state
190 if (pStateManager->GetCurrentState() != G4State_Quit) {
191 if (verboseLevel > 1) G4cout << "G4 kernel has come to Quit state." << G4endl;
192 pStateManager->SetNewState(G4State_Quit);
193 }
194
196 if (verboseLevel > 1 && currentRun!=nullptr) {
197 G4cout << "Deleting G4Run (id:" << currentRun->GetRunID() << ") ";
198 if(currentRun->GetEventVectorSize()>0) {
199 G4cout << " that has " << currentRun->GetEventVectorSize()
200 << " events kept in eventVector";
201 }
202 G4cout << G4endl;
203 }
204 delete currentRun;
205 delete timer;
206 delete runMessenger;
207 delete previousEvents;
208
209 // The following will work for all RunManager types
210 // if derived class does the correct thing in the derived
211 // destructor that is: set to zero pointers of
212 // user initialization objects for which have no
213 // ownership
215 delete userRunAction;
216 userRunAction = nullptr;
217 if (verboseLevel > 1) G4cout << "UserRunAction deleted." << G4endl;
218
221 if (verboseLevel > 1) G4cout << "UserPrimaryGenerator deleted." << G4endl;
222
223 if (verboseLevel > 1) G4cout << "RunManager is deleting RunManagerKernel." << G4endl;
224
225 delete kernel;
226
227 fRunManager = nullptr;
228
229 if (verboseLevel > 1) G4cout << "RunManager is deleted." << G4endl;
230}
231
232// --------------------------------------------------------------------
234{
235 if (verboseLevel > 1) G4cout << "UserDetectorConstruction deleted " << userDetector << G4endl;
236 delete userDetector;
237 userDetector = nullptr;
238
239 if (verboseLevel > 1) G4cout << "UserPhysicsList deleted " << physicsList << G4endl;
240 delete physicsList;
241 physicsList = nullptr;
242
243 if (verboseLevel > 1) G4cout << "UserActionInitialization deleted " << userActionInitialization << G4endl;
245 userActionInitialization = nullptr;
246
247 if (verboseLevel > 1) G4cout << "UserWorkerInitialization deleted " << userWorkerInitialization << G4endl;
249 userWorkerInitialization = nullptr;
250
251 if (verboseLevel > 1) G4cout << "UserWorkerThreadInitialization deleted " << userWorkerThreadInitialization << G4endl;
254}
255
256// --------------------------------------------------------------------
257void G4RunManager::BeamOn(G4int n_event, const char* macroFile, G4int n_select)
258{
259 fakeRun = n_event <= 0;
261 if (cond) {
266 DoEventLoop(n_event, macroFile, n_select);
268 }
269 fakeRun = false;
270}
271
272// --------------------------------------------------------------------
274{
276
277 G4ApplicationState currentState = stateManager->GetCurrentState();
278 if (currentState != G4State_PreInit && currentState != G4State_Idle) {
279 G4cerr << "Illegal application state - BeamOn() ignored." << G4endl;
280 return false;
281 }
282
284 G4cerr << " Geant4 kernel should be initialized" << G4endl;
285 G4cerr << "before the first BeamOn(). - BeamOn ignored." << G4endl;
286 return false;
287 }
288
290 if (verboseLevel > 0) {
291 G4cout << "Start re-initialization because " << G4endl;
292 if (!geometryInitialized) G4cout << " Geometry" << G4endl;
293 if (!physicsInitialized) G4cout << " Physics processes" << G4endl;
294 G4cout << "has been modified since last Run." << G4endl;
295 }
296 Initialize();
297 }
298 return true;
299}
300
301// --------------------------------------------------------------------
303{
304 if (!(kernel->RunInitialization(fakeRun))) return;
305
306 runAborted = false;
308
310 if (verboseLevel > 2 && currentRun!=nullptr) {
311 G4cout << "Deleting G4Run (id:" << currentRun->GetRunID() << ") ";
312 if(currentRun->GetEventVectorSize()>0) {
313 G4cout << " that has " << currentRun->GetEventVectorSize()
314 << " events kept in eventVector";
315 }
316 G4cout << G4endl;
317 }
318 delete currentRun;
319 currentRun = nullptr;
320
321 if (fakeRun) return;
322
324
325 if (userRunAction != nullptr) currentRun = userRunAction->GenerateRun();
326 if (currentRun == nullptr) currentRun = new G4Run();
327
328 currentRun->SetRunID(runIDCounter);
329 currentRun->SetNumberOfEventToBeProcessed(numberOfEventToBeProcessed);
330
331 currentRun->SetDCtable(DCtable);
333 if (fSDM != nullptr) {
334 currentRun->SetHCtable(fSDM->GetHCtable());
335 }
336
337 if (G4VScoreNtupleWriter::Instance() != nullptr) {
338 auto hce = (fSDM != nullptr) ? fSDM->PrepareNewEvent() : nullptr;
340 delete hce;
341 }
342
343 std::ostringstream oss;
344 G4Random::saveFullState(oss);
346 currentRun->SetRandomNumberStatus(randomNumberStatusForThisRun);
347
348 for (G4int i_prev = 0; i_prev < n_perviousEventsToBeStored; ++i_prev) {
349 previousEvents->push_back(nullptr);
350 }
351
352 if (printModulo >= 0 || verboseLevel > 0) {
353 G4cout << "### Run " << currentRun->GetRunID() << " starts." << G4endl;
354 }
355 if (userRunAction != nullptr) userRunAction->BeginOfRunAction(currentRun);
356
359 }
360
362 G4String fileN = "currentRun";
364 std::ostringstream os;
365 os << "run" << currentRun->GetRunID();
366 fileN = os.str();
367 }
368 StoreRNGStatus(fileN);
369 }
370}
371
372// --------------------------------------------------------------------
373void G4RunManager::DoEventLoop(G4int n_event, const char* macroFile, G4int n_select)
374{
375 InitializeEventLoop(n_event, macroFile, n_select);
376
377 // Event loop
378 for (G4int i_event = 0; i_event < n_event; ++i_event) {
379 ProcessOneEvent(i_event);
381 if (runAborted) break;
382 }
383
384 // For G4MTRunManager, TerminateEventLoop() is invoked after all threads are
385 // finished.
387}
388
389// --------------------------------------------------------------------
390void G4RunManager::InitializeEventLoop(G4int n_event, const char* macroFile, G4int n_select)
391{
392 if (verboseLevel > 0) {
393 timer->Start();
394 }
395
396 n_select_msg = n_select;
397 if (macroFile != nullptr) {
398 if (n_select_msg < 0) n_select_msg = n_event;
399 msgText = "/control/execute ";
400 msgText += macroFile;
401 selectMacro = macroFile;
402 }
403 else {
404 n_select_msg = -1;
405 selectMacro = "";
406 }
407}
408
409// --------------------------------------------------------------------
418
419// --------------------------------------------------------------------
426
427// --------------------------------------------------------------------
429{
430 if (verboseLevel > 0 && !fakeRun) {
431 timer->Stop();
432 G4cout << " Run terminated." << G4endl;
433 G4cout << "Run Summary" << G4endl;
434 if (runAborted) {
435 G4cout << " Run Aborted after " << numberOfEventProcessed << " events processed." << G4endl;
436 }
437 else {
438 G4cout << " Number of events processed : " << numberOfEventProcessed << G4endl;
439 }
440 G4cout << " " << *timer << G4endl;
441 }
443}
444
445// --------------------------------------------------------------------
447{
448 if (userPrimaryGeneratorAction == nullptr) {
449 G4Exception("G4RunManager::GenerateEvent()", "Run0032", FatalException,
450 "G4VUserPrimaryGeneratorAction is not defined!");
451 return nullptr;
452 }
453
454 auto anEvent = new G4Event(i_event);
455
457 std::ostringstream oss;
458 G4Random::saveFullState(oss);
460 anEvent->SetRandomNumberStatus(randomNumberStatusForThisEvent);
461 }
462
464 G4String fileN = "currentEvent";
466 std::ostringstream os;
467 os << "run" << currentRun->GetRunID() << "evt" << anEvent->GetEventID();
468 fileN = os.str();
469 }
470 StoreRNGStatus(fileN);
471 }
472
473 if (printModulo > 0 && anEvent->GetEventID() % printModulo == 0) {
474 G4cout << "--> Event " << anEvent->GetEventID() << " starts." << G4endl;
475 }
476 userPrimaryGeneratorAction->GeneratePrimaries(anEvent);
477 return anEvent;
478}
479
480// --------------------------------------------------------------------
482{
483 G4String fileN = randomNumberStatusDir + fnpref + ".rndm";
484 G4Random::saveEngineStatus(fileN);
485}
486
487// --------------------------------------------------------------------
489{
491 if (fPersM != nullptr) fPersM->Store(anEvent);
492 currentRun->RecordEvent(anEvent);
493}
494
495// --------------------------------------------------------------------
497{
498 if (!fakeRun) {
500// if(G4int(previousEvents->size())>0) {
501// G4ExceptionDescription ed;
502// ed << "Run still has " << previousEvents->size() << " unfinished events!!";
503// G4Exception("G4RunManager::RunTermination()","RM09009",FatalException,ed);
504// }
505 // tasking occasionally will call this function even
506 // if there was not a current run
507 if (currentRun != nullptr) {
508 if (userRunAction != nullptr) userRunAction->EndOfRunAction(currentRun);
510 if (fPersM != nullptr) fPersM->Store(currentRun);
511 // write & close analysis output
514 }
515 }
516 ++runIDCounter;
517 }
518
519 kernel->RunTermination();
520}
521
522// --------------------------------------------------------------------
524{
525 // Delete all events carried over from previous run.
526 // This method is invoked at the beginning of the next run
527 // or from the destructor of G4RunManager at the very end of
528 // the program.
529 // N.B. If ToBeKept() is true, the pointer of this event is
530 // kept in G4Run of the previous run, and deleted along with
531 // the deletion of G4Run.
532
533 auto evItr = previousEvents->cbegin();
534 while (evItr != previousEvents->cend()) {
535 G4Event* evt = *evItr;
536 if (evt != nullptr && !(evt->ToBeKept())) {
538 delete evt;
539 }
540 evItr = previousEvents->erase(evItr);
541 }
542
543}
544
545// --------------------------------------------------------------------
547{
548 // Delete events that are no longer necessary for post
549 // processing such as visualization.
550 // N.B. If ToBeKept() is true, the pointer of this event is
551 // kept in G4Run of the previous run, and deleted along with
552 // the deletion of G4Run.
553
554 auto evItr = previousEvents->cbegin();
555 while (evItr != previousEvents->cend()) {
556 if (G4int(previousEvents->size()) <= keepNEvents) return;
557
558 G4Event* evt = *evItr;
559 if (evt != nullptr) {
560 if (evt->GetNumberOfGrips() == 0) {
561 if (!(evt->ToBeKept())) {
563 delete evt;
564 }
565 evItr = previousEvents->erase(evItr);
566 }
567 else {
568 ++evItr;
569 }
570 }
571 else {
572 evItr = previousEvents->erase(evItr);
573 }
574 }
575}
576
577// --------------------------------------------------------------------
579{
580 if (anEvent->ToBeKept()) currentRun->StoreEvent(anEvent);
581
583 if (anEvent->GetNumberOfGrips() == 0) {
584 if (!(anEvent->ToBeKept())) {
585 ReportEventDeletion(anEvent);
586 delete anEvent;
587 }
588 }
589 else {
590 previousEvents->push_back(anEvent);
591 }
592 }
593 else {
594 previousEvents->push_back(anEvent);
595 }
596
598}
599
600// --------------------------------------------------------------------
602{
603 if(verboseLevel > 3) {
604 G4cout << "deleting G4Event(" << evt << ") eventID = " << evt->GetEventID()
605 << " -- grips = " << evt->GetNumberOfGrips()
606 << " keepFlag = " << evt->KeepTheEventFlag()
607 << " subEvt = " << evt->GetNumberOfRemainingSubEvents();
608 if(evt->GetNumberOfCompletedSubEvent()>0) {
609 G4cout << " -- contains " << evt->GetNumberOfCompletedSubEvent() << " completed sub-events";
610 }
611 G4cout << G4endl;
612 }
613}
614// --------------------------------------------------------------------
616{
618 G4ApplicationState currentState = stateManager->GetCurrentState();
619 if (currentState != G4State_PreInit && currentState != G4State_Idle) {
620 G4cerr << "Illegal application state - "
621 << "G4RunManager::Initialize() ignored." << G4endl;
622 return;
623 }
624
625 stateManager->SetNewState(G4State_Init);
629 if (stateManager->GetCurrentState() != G4State_Idle) {
630 stateManager->SetNewState(G4State_Idle);
631 }
632}
633
634// --------------------------------------------------------------------
636{
637 if (userDetector == nullptr) {
638 G4Exception("G4RunManager::InitializeGeometry", "Run0033", FatalException,
639 "G4VUserDetectorConstruction is not defined!");
640 return;
641 }
642
643 if (verboseLevel > 1) G4cout << "userDetector->Construct() start." << G4endl;
644
646 G4ApplicationState currentState = stateManager->GetCurrentState();
647 if (currentState == G4State_PreInit || currentState == G4State_Idle) {
648 stateManager->SetNewState(G4State_Init);
649 }
651 kernel->DefineWorldVolume(userDetector->Construct(), false);
652 userDetector->ConstructSDandField();
653 nParallelWorlds = userDetector->ConstructParallelGeometries();
654 userDetector->ConstructParallelSD();
655 kernel->SetNumberOfParallelWorld(nParallelWorlds);
656 }
657 // Notify the VisManager as well
660 if (pVVisManager != nullptr) pVVisManager->GeometryHasChanged();
661 }
662
664 geometryInitialized = true;
665 stateManager->SetNewState(currentState);
666}
667
668// --------------------------------------------------------------------
670{
672 G4ApplicationState currentState = stateManager->GetCurrentState();
673 if (currentState == G4State_PreInit || currentState == G4State_Idle) {
674 stateManager->SetNewState(G4State_Init);
675 }
676 if (physicsList != nullptr) {
677 kernel->InitializePhysics();
678 }
679 else {
680 G4Exception("G4RunManager::InitializePhysics()", "Run0034", FatalException,
681 "G4VUserPhysicsList is not defined!");
682 }
683 physicsInitialized = true;
684 stateManager->SetNewState(currentState);
685}
686
687// --------------------------------------------------------------------
689{
690 // This method is valid only for GeomClosed or EventProc state
692 if (currentState == G4State_GeomClosed || currentState == G4State_EventProc) {
693 runAborted = true;
694 if (currentState == G4State_EventProc && !softAbort) {
695 currentEvent->SetEventAborted();
696 eventManager->AbortCurrentEvent();
697 }
698 }
699 else {
700 G4cerr << "Run is not in progress. AbortRun() ignored." << G4endl;
701 }
702}
703
704// --------------------------------------------------------------------
706{
707 // This method is valid only for EventProc state
709 if (currentState == G4State_EventProc) {
710 currentEvent->SetEventAborted();
711 eventManager->AbortCurrentEvent();
712 }
713 else {
714 G4cerr << "Event is not in progress. AbortEevnt() ignored." << G4endl;
715 }
716}
717
718// --------------------------------------------------------------------
720{
721 kernel->DefineWorldVolume(worldVol, topologyIsChanged);
722}
723
724// --------------------------------------------------------------------
726{
727 G4int runNumber = 0;
728 if (currentRun != nullptr) runNumber = currentRun->GetRunID();
730 G4cerr << "Warning from G4RunManager::rndmSaveThisRun():"
731 << " Random number status was not stored prior to this run." << G4endl
732 << "/random/setSavingFlag command must be issued. "
733 << "Command ignored." << G4endl;
734 return;
735 }
736
737 G4fs::path fileIn = randomNumberStatusDir + "currentRun.rndm";
738
739 std::ostringstream os;
740 os << "run" << runNumber << ".rndm" << '\0';
741 G4fs::path fileOut = randomNumberStatusDir + os.str();
742
743 if (G4CopyRandomState(fileIn, fileOut, "G4RunManager::rndmSaveThisRun()") && verboseLevel > 0)
744 {
745 G4cout << fileIn << " is copied to " << fileOut << G4endl;
746 }
747}
748
749// --------------------------------------------------------------------
751{
752 if (currentEvent == nullptr) {
753 G4cerr << "Warning from G4RunManager::rndmSaveThisEvent():"
754 << " there is no currentEvent available." << G4endl << "Command ignored." << G4endl;
755 return;
756 }
757
759 G4cerr << "Warning from G4RunManager::rndmSaveThisEvent():"
760 << " Random number engine status is not available." << G4endl
761 << "/random/setSavingFlag command must be issued "
762 << "prior to the start of the run. Command ignored." << G4endl;
763 return;
764 }
765
766 G4fs::path fileIn = randomNumberStatusDir + "currentEvent.rndm";
767
768 std::ostringstream os;
769 os << "run" << currentRun->GetRunID() << "evt" << currentEvent->GetEventID() << ".rndm" << '\0';
770 G4fs::path fileOut = randomNumberStatusDir + os.str();
771
772 if (G4CopyRandomState(fileIn, fileOut, "G4RunManager::rndmSaveThisEvent()") && verboseLevel > 0)
773 {
774 G4cout << fileIn << " is copied to " << fileOut << G4endl;
775 }
776}
777
778// --------------------------------------------------------------------
780{
781 G4String fileNameWithDirectory;
782 if (fileN.find('/') == std::string::npos) {
783 fileNameWithDirectory = randomNumberStatusDir + fileN;
784 }
785 else {
786 fileNameWithDirectory = fileN;
787 }
788
789 G4Random::restoreEngineStatus(fileNameWithDirectory);
790 if (verboseLevel > 0)
791 G4cout << "RandomNumberEngineStatus restored from file: " << fileNameWithDirectory << G4endl;
792 G4Random::showEngineStatus();
793}
794
795// --------------------------------------------------------------------
796void G4RunManager::DumpRegion(const G4String& rname) const
797{
798 kernel->DumpRegion(rname);
799}
800
801// --------------------------------------------------------------------
803{
804 kernel->DumpRegion(region);
805}
806
807// --------------------------------------------------------------------
809{
810 using MeshShape = G4VScoringMesh::MeshShape;
811
813 if (ScM == nullptr) return;
814
815 auto nPar = (G4int)ScM->GetNumberOfMesh();
816 if (nPar < 1) return;
817
819 for (G4int iw = 0; iw < nPar; ++iw) {
820 G4VScoringMesh* mesh = ScM->GetMesh(iw);
822 G4VPhysicalVolume* pWorld = nullptr;
823 if (mesh->GetShape() != MeshShape::realWorldLogVol) {
824 pWorld =
826 if (pWorld == nullptr) {
828 ScM->GetWorldName(iw));
829 pWorld->SetName(ScM->GetWorldName(iw));
830
831 G4ParallelWorldProcess* theParallelWorldProcess = mesh->GetParallelWorldProcess();
832 if (theParallelWorldProcess != nullptr) {
833 theParallelWorldProcess->SetParallelWorld(ScM->GetWorldName(iw));
834 }
835 else {
836 theParallelWorldProcess = new G4ParallelWorldProcess(ScM->GetWorldName(iw));
837 mesh->SetParallelWorldProcess(theParallelWorldProcess);
838 theParallelWorldProcess->SetParallelWorld(ScM->GetWorldName(iw));
839
840 theParticleIterator->reset();
841 while ((*theParticleIterator)()) {
842 G4ParticleDefinition* particle = theParticleIterator->value();
843 G4ProcessManager* pmanager = particle->GetProcessManager();
844 if (pmanager != nullptr) {
845 pmanager->AddProcess(theParallelWorldProcess);
846 if (theParallelWorldProcess->IsAtRestRequired(particle)) {
847 pmanager->SetProcessOrdering(theParallelWorldProcess, idxAtRest, 9900);
848 }
849 pmanager->SetProcessOrderingToSecond(theParallelWorldProcess, idxAlongStep);
850 pmanager->SetProcessOrdering(theParallelWorldProcess, idxPostStep, 9900);
851 }
852 }
853 }
854 theParallelWorldProcess->SetLayeredMaterialFlag(mesh->LayeredMassFlg());
855 }
856 }
857 mesh->Construct(pWorld);
858 }
860}
861
862// --------------------------------------------------------------------
864{
865 if(evt==nullptr) evt = currentEvent;
866
867//MAMAMAMA need revisiting
868 if(evt->ScoresAlreadyRecorded()) return;
869//MAMAMAMA need revisiting
870
873 }
874
875 if(evt->ScoresAlreadyRecorded()) {
876 G4Exception("G4RunManager::UpdateScoring()","RMSubEvt001",FatalException,
877 "Double-counting!!!");
878 }
879
880 evt->ScoresRecorded();
881
883 if (ScM == nullptr) return;
884 auto nPar = (G4int)ScM->GetNumberOfMesh();
885 if (nPar < 1) return;
886
887 G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
888 if (HCE == nullptr) return;
889 auto nColl = (G4int)HCE->GetCapacity();
890 for (G4int i = 0; i < nColl; ++i) {
891 G4VHitsCollection* HC = HCE->GetHC(i);
892 if (HC != nullptr) ScM->Accumulate(HC);
893 }
894}
895
896// --------------------------------------------------------------------
898{
899 G4LogicalVolume* pMotherL = pPhys->GetMotherLogical();
900 if (pMotherL != nullptr) ReOptimize(pMotherL);
901}
902
903// --------------------------------------------------------------------
905{
906 G4Timer localtimer;
907 if (verboseLevel > 1) {
908 localtimer.Start();
909 }
910 G4SmartVoxelHeader* header = pLog->GetVoxelHeader();
911 delete header;
912 header = new G4SmartVoxelHeader(pLog);
913 pLog->SetVoxelHeader(header);
914 if (verboseLevel > 1) {
915 localtimer.Stop();
916 G4SmartVoxelStat stat(pLog, header, localtimer.GetSystemElapsed(), localtimer.GetUserElapsed());
917 G4cout << G4endl << "Voxelisation of logical volume <" << pLog->GetName() << ">" << G4endl;
918 G4cout << " heads : " << stat.GetNumberHeads() << " - nodes : " << stat.GetNumberNodes()
919 << " - pointers : " << stat.GetNumberPointers() << G4endl;
920 G4cout << " Memory used : " << (stat.GetMemoryUse() + 512) / 1024
921 << "k - total time : " << stat.GetTotalTime() << " - system time : " << stat.GetSysTime()
922 << G4endl;
923 }
924}
925
926// --------------------------------------------------------------------
931
932// --------------------------------------------------------------------
934{
935 physicsList = userInit;
936 kernel->SetPhysics(userInit);
937}
938
939// --------------------------------------------------------------------
941{
942 G4Exception("G4RunManager::SetUserInitialization()", "Run3001", FatalException,
943 "Base-class G4RunManager cannot take G4UserWorkerInitialization. Use "
944 "G4MTRunManager.");
945}
946
947// --------------------------------------------------------------------
949{
950 G4Exception("G4RunManager::SetUserThreadInitialization()", "Run3001", FatalException,
951 "Base-class G4RunManager cannot take G4UserWorkerThreadInitialization. "
952 "Use G4MTRunManager.");
953}
954
955// --------------------------------------------------------------------
961
962// --------------------------------------------------------------------
964{
965 userRunAction = userAction;
966}
967
968// --------------------------------------------------------------------
973
974// --------------------------------------------------------------------
976{
977 eventManager->SetUserAction(userAction);
978 userEventAction = userAction;
979}
980
981// --------------------------------------------------------------------
983{
984 eventManager->SetUserAction(userAction);
985 userStackingAction = userAction;
986}
987
988// --------------------------------------------------------------------
990{
991 eventManager->SetUserAction(userAction);
992 userTrackingAction = userAction;
993}
994
995// --------------------------------------------------------------------
997{
998 eventManager->SetUserAction(userAction);
999 userSteppingAction = userAction;
1000}
1001
1002// --------------------------------------------------------------------
1004{
1005 if (prop) {
1006 G4UImanager::GetUIpointer()->ApplyCommand("/run/geometryModified");
1007 }
1008 else {
1009 kernel->GeometryHasBeenModified();
1010 }
1011}
1012
1013// --------------------------------------------------------------------
1015{
1016 if (destroyFirst && G4Threading::IsMasterThread()) {
1017 if (verboseLevel > 0) {
1018 G4cout << "#### Assemblies, Volumes and Solids Stores are wiped out." << G4endl;
1019 }
1025
1026 // remove all logical volume pointers from regions
1027 // exception: world logical volume pointer must be kept
1029 for (const auto& rItr : *regionStore) {
1030 if (rItr->GetName() == "DefaultRegionForTheWorld") continue;
1031 auto lvItr = rItr->GetRootLogicalVolumeIterator();
1032 for (std::size_t iRLV = 0; iRLV < rItr->GetNumberOfRootVolumes(); ++iRLV) {
1033 rItr->RemoveRootLogicalVolume(*lvItr, false);
1034 ++lvItr;
1035 }
1036 if (verboseLevel > 0) {
1037 G4cout << "#### Region <" << rItr->GetName() << "> is cleared." << G4endl;
1038 }
1039 }
1040
1041 // clear transportation manager
1044 }
1045 if (prop) {
1046 G4UImanager::GetUIpointer()->ApplyCommand("/run/reinitializeGeometry");
1047 }
1048 else {
1049 kernel->GeometryHasBeenModified();
1050 geometryInitialized = false;
1051 // Notify the VisManager as well
1054 if (pVVisManager != nullptr) pVVisManager->GeometryHasChanged();
1055 }
1056 // Reinitialize field builder
1059 }
1060 }
1061}
1062
1063// --------------------------------------------------------------------
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:302
void ScoresRecorded() const
Definition G4Event.hh:301
G4int GetNumberOfRemainingSubEvents() const
Definition G4Event.cc:277
static G4bool IsInstance()
Return the information if an instance exists.
static G4FieldBuilder * Instance()
static G4GeometryManager * GetInstance()
void OpenGeometry(G4VPhysicalVolume *vol=nullptr)
std::size_t GetCapacity()
G4VHitsCollection * GetHC(G4int i)
static G4LogicalVolumeStore * GetInstance()
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()
static G4RegionStore * GetInstance()
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()
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
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