40#include <G4Threading.hh>
43#include <G4MTRunManager.hh>
45#include <G4RunManager.hh>
48#include <G4ScoringManager.hh>
49#include <G4VScoringMesh.hh>
51#include <G4UIExecutive.hh>
52#include <G4UImanager.hh>
53#include <G4UIsession.hh>
54#include <G4Version.hh>
55#include <Randomize.hh>
59#include <TG4RootNavMgr.h>
62#include <TGeoManager.h>
63#include <TInterpreter.h>
64#include <TMCManager.h>
65#include <TMCManagerStack.h>
69#include <TVirtualMC.h>
70#include <TVirtualMCApplication.h>
78 G4RunManager::GetRunManager()->GetUserEventAction()));
109 G4cout <<
"TG4RunManager::TG4RunManager " <<
this << G4endl;
114 "Cannot create two instances of singleton.");
119 "Cannot create instance without runConfiguration.");
128 fARGV[0] = StrDup(
"undefined");
131 G4bool isMaster = !G4Threading::IsWorkerThread();
141 G4ScoringManager::GetScoringManager();
157 G4cout <<
"TG4RunManager has been created." <<
this << G4endl;
166 G4bool isMaster = !G4Threading::IsWorkerThread();
192 G4cout <<
"TG4RunManager::ConfigureRunManager " <<
this << G4endl;
204 TG4RootNavMgr* rootNavMgr = 0;
205 if (userGeometry ==
"VMCtoRoot" || userGeometry ==
"Root") {
206 if (!TMCManager::Instance()) {
208#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 22, 8)
210 TGeoManager::LockDefaultUnits(
false);
211 TGeoManager::SetDefaultUnits(TGeoManager::kRootUnits);
212 TGeoManager::LockDefaultUnits(
true);
217 G4cout <<
"Running TVirtualMCApplication::ConstructGeometry"
221 TVirtualMCApplication::Instance()->ConstructGeometry();
225 if (!gGeoManager->IsClosed()) {
226 TGeoVolume* top = (TGeoVolume*)gGeoManager->GetListOfVolumes()->First();
227 gGeoManager->SetTopVolume(top);
228 gGeoManager->CloseGeometry();
233 TVirtualMCApplication::Instance()->MisalignGeometry();
237 rootNavMgr = TG4RootNavMgr::GetInstance(gGeoManager);
242#ifdef G4MULTITHREADED
254 G4cout <<
"G4RunManager has been created." << G4endl;
257 if (userGeometry !=
"VMCtoRoot" && userGeometry !=
"Root") {
261 G4cout <<
"CreateDetectorConstruction done." << G4endl;
266#ifdef G4MULTITHREADED
268 nthreads = G4MTRunManager::GetMasterRunManager()->GetNumberOfThreads();
271 rootNavMgr->Initialize(
new TG4PostDetConstruction(), nthreads);
272 rootNavMgr->ConnectToG4();
275 "geomVMCtoRoot and geomRoot options require Geant4 VMC built with "
283 if (
VerboseLevel() > 1) G4cout <<
"CreatePhysicsList done." << G4endl;
288 if (userFastSimulation) {
295 "TG4SpecialPhysicsList must be instantiated to use fast simulation");
302 G4cout <<
"Create ActionInitialization done." << G4endl;
316 G4cout <<
"TG4RunManager::ConfigureRunManager done " <<
this << G4endl;
326 if (userGeometry !=
"VMCtoRoot" && userGeometry !=
"Root")
return;
329 G4cout <<
"TG4RunManager::CloneRootNavigatorForWorker " <<
this << G4endl;
332 TG4RootNavMgr* masterRootNavMgr = TG4RootNavMgr::GetMasterInstance();
335 TG4RootNavMgr* rootNavMgr = TG4RootNavMgr::GetInstance(*masterRootNavMgr);
337 G4cout <<
"TG4RootNavMgr has been created." << rootNavMgr << G4endl;
340 rootNavMgr->ConnectToG4();
343 G4cout <<
"TG4RunManager::CloneRootNavigatorForWorker done " <<
this
370 argv = (
char**)
new char*[
fARGC];
374 for (
int i = 0; i <
fARGC; i++) {
375 argv[i] = StrDup(
fARGV[i]);
389 if (
fARGC <= 1)
return;
391 G4bool isArg =
false;
392 for (G4int i = 0; i <
fARGC; i++) {
393 if (G4String(
fARGV[i]) == arg) isArg =
true;
407 seeds[0] = gRandom->GetSeed();
408 seeds[1] = gRandom->GetSeed();
410 CLHEP::HepRandom::setTheSeeds(seeds);
421 G4cout <<
"TG4RunManager::Initialize " <<
this << G4endl;
426#if G4VERSION_NUMBER == 1100
441 G4cout <<
"TG4RunManager::Initialize done " <<
this << G4endl;
451 G4cout <<
"TG4RunManager::LateInitialize " <<
this << G4endl;
453 G4bool isMaster = !G4Threading::IsWorkerThread();
484 if (GetEventAction()) {
485 GetEventAction()->LateInitialize();
502 G4cout <<
"TG4RunManager::LateInitialize done " <<
this << G4endl;
514 TVirtualMCStack* mcStack = gMC->GetStack();
517 "TG4RunManager",
"CacheMCStack",
"VMC stack is not set");
521 TMCManagerStack* mcManagerStack = gMC->GetManagerStack();
524 if (GetEventAction()) {
525 GetEventAction()->SetMCStack(mcStack);
553 G4bool cond =
fRunManager->ConfirmBeamOnCondition();
556 "Bad beam condition in G4RunManager. No event processed.");
563 GetEventAction()->SetIsInterruptibleEvent(isInterruptible);
579 "Current run is terminated first, then the requested run is processed");
595 "You are processing a run. To stop it, call StopRun()");
615 auto g4ScoringManager = G4ScoringManager::GetScoringManager();
616 for (std::size_t i = 0; i < g4ScoringManager->GetNumberOfMesh(); ++i) {
617 auto meshName = g4ScoringManager->GetMesh(i)->GetWorldName();
618 auto fileName = meshName +
".txt";
619 g4ScoringManager->DumpAllQuantitiesToFile(meshName, fileName);
646 G4cout <<
"Welcome (back) in Geant4" << G4endl;
648 G4cout <<
"Welcome (back) in Root" << G4endl;
651 G4cout <<
"Geant4 UI not available." << G4endl;
662 G4cout <<
"Welcome (back) in Root" << G4endl;
664 G4cout <<
"Welcome (back) in Geant4" << G4endl;
673 G4String command =
"/control/execute " + macroName;
683 G4String macroFile = macroName;
684 macroFile.append(
".C");
685 gROOT->LoadMacro(macroFile);
688 G4String macroFunction = macroName;
689 macroFunction.append(
"()");
690 gInterpreter->ProcessLine(macroFunction);
698 G4UImanager* pUI = G4UImanager::GetUIpointer();
699 G4int result = pUI->ApplyCommand(command);
703 case fCommandSucceeded:
705 case fCommandNotFound:
706 G4cerr <<
"***** COMMAND NOT FOUND <" << command <<
"> *****" << G4endl;
708 case fIllegalApplicationState:
709 G4cerr <<
"***** Illegal application state <" << command <<
"> *****"
713 G4int pn = result % 100;
714 G4cerr <<
"***** Illegal parameter (" << pn <<
") <" << command
715 <<
"> *****" << G4endl;
724 gInterpreter->ProcessLine(command);
741 G4int eventID =
fRunManager->GetCurrentEvent()->GetEventID();
Definition of the TG4ActionInitialization class.
Definition of the TG4DetConstruction class.
Definition of the TG4EventAction class.
Definition of the TG4G3PhysicsManager class.
Definition of the TG4GeometryManager class.
Definition of the TG4GeometryServices class.
Definition of the TG4Globals class and basic container types.
Definition of the TG4PhysicsManager class.
Definition of the TG4PostDetConstruction class.
Definition of the TG4RegionsManager2 class.
Definition of the TG4RegionsManager class.
Definition of the TG4RunConfiguration class.
Definition of the TG4RunManager.h class.
Definition of the TG4SDConstruction class.
Definition of the TG4SDManager class.
Definition of the TG4SDServices class.
Definition of the TG4SpecialPhysicsList class.
Definition of the TG4StackPopper class.
Definition of the TG4StateManager class.
Definition of the TG4StepManager class.
Definition of the TG4SteppingAction class.
Definition of the TG4TrackManager class.
Definition of the TG4TrackingAction class.
Definition of the TG4WorkerInitialization class.
Action Initialization class (required for MT mode)
Actions at the beginning and the end of event.
static TG4G3PhysicsManager * Instance()
void SetG3DefaultControls()
void SetUserPostDetConstruction(TG4VUserPostDetConstruction *userPostDetConstruction)
void PrintFieldStatistics() const
void SetUserRegionConstruction(TG4VUserRegionConstruction *userRegionConstruction)
static TG4GeometryManager * Instance()
void SetUserLimits(const TG4G3CutVector &cuts, const TG4G3ControlVector &controls) const
void PrintLogicalVolumeStore() const
void PrintStatistics(G4bool open, G4bool close) const
static TG4GeometryServices * Instance()
static void Warning(const TString &className, const TString &methodName, const TString &text)
static void Exception(const TString &className, const TString &methodName, const TString &text)
static TG4PhysicsManager * Instance()
void RetrieveOpBoundaryProcess()
void SetProcessActivation()
Manager class for setting VMC cuts in energy in G4 regions.
Manager class for converting VMC cuts in energy in G4 regions.
Takes care of creating Geant4 user action classes using VMC.
Bool_t IsUseOfG4Scoring() const
Geant4 implementation of the TVirtualMC interface methods for access to Geant4 at run level.
void ProcessGeantCommand(G4String command)
void ConfigureRunManager()
G4bool fIsMCStackCached
the flag to cache MC stack only once
G4bool fHasEventByEventInitialization
Flag event-by-event processing.
G4int fNEventsProcessed
Number of events processed in event-by-event mode.
void SetRandomSeed()
picks up random seed from ROOT gRandom and propagates to Geant4
Bool_t SecondariesAreOrdered() const
TG4VRegionsManager * fRegionsManager
regions manager
static TG4RunManager * fgMasterInstance
master instance
TApplication * fRootUISession
Root UI.
Int_t CurrentEvent() const
void ProcessRootCommand(G4String command)
static G4ThreadLocal TG4RunManager * fgInstance
thread local instance
G4bool fRootUIOwner
ownership of Root UI
G4RunManager * fRunManager
G4RunManager.
TG4RunManager()
Not implemented.
G4UIExecutive * fGeantUISession
G4 UI.
G4bool fUseRootRandom
the option to use Root random number seed
void CloneRootNavigatorForWorker()
TG4RunConfiguration * fRunConfiguration
TG4RunConfiguration.
void ProcessRootMacro(G4String macroName)
void ProcessGeantMacro(G4String macroName)
Bool_t ProcessRun(G4int nofEvents)
TG4RunMessenger fMessenger
messenger
void FilterARGV(const G4String &option)
G4bool fInProcessRun
flag while being in BeamOn
void SetIsStopRun(G4bool stopRun)
void PrintStatistics(G4bool open, G4bool close) const
G4bool GetIsStopRun() const
static TG4SDServices * Instance()
void SetUserFastSimulation(TG4VUserFastSimulation *fastSimulation)
static TG4SpecialPhysicsList * Instance()
static TG4StackPopper * Instance()
void SetMCStack(TVirtualMCStack *mcStack)
void SetNewState(TG4ApplicationState state)
static TG4StateManager * Instance()
static TG4StepManager * Instance()
static TG4SteppingAction * Instance()
void SetMCStack(TVirtualMCStack *mcStack)
static TG4TrackManager * Instance()
void SetMCManagerStack(TMCManagerStack *mcManagerStack)
void SetMCStack(TVirtualMCStack *mcStack)
static TG4TrackingAction * Instance()
The abstract base class which is used to build fast simulation models.
virtual G4int VerboseLevel() const
TG4Verbose(const G4String &cmdName)
Actions at start and end of run on a worker (call in MT mode only)
@ kMisalignGeometry
in MisalignGeometry
@ kConstructGeometry
in ConstructGeometry
@ kNotInApplication
not in VMC application