40#include <G4Threading.hh>
43#include <G4MTRunManager.hh>
45#include <G4RunManager.hh>
48#include <G4UIExecutive.hh>
49#include <G4UImanager.hh>
50#include <G4UIsession.hh>
51#include <G4Version.hh>
52#include <Randomize.hh>
55#include <TG4RootNavMgr.h>
58#include <TGeoManager.h>
59#include <TInterpreter.h>
60#include <TMCManager.h>
61#include <TMCManagerStack.h>
65#include <TVirtualMC.h>
66#include <TVirtualMCApplication.h>
74 G4RunManager::GetRunManager()->GetUserEventAction()));
89 fRunConfiguration(runConfiguration),
97 fIsMCStackCached(false),
98 fHasEventByEventInitialization(false),
105 G4cout <<
"TG4RunManager::TG4RunManager " <<
this << G4endl;
110 "Cannot create two instances of singleton.");
115 "Cannot create instance without runConfiguration.");
124 fARGV[0] = StrDup(
"undefined");
127 G4bool isMaster = !G4Threading::IsWorkerThread();
148 G4cout <<
"TG4RunManager has been created." <<
this << G4endl;
157 G4bool isMaster = !G4Threading::IsWorkerThread();
183 G4cout <<
"TG4RunManager::ConfigureRunManager " <<
this << G4endl;
195 TG4RootNavMgr* rootNavMgr = 0;
196 if (userGeometry ==
"VMCtoRoot" || userGeometry ==
"Root") {
197 if (!TMCManager::Instance()) {
199#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 22, 8)
201 TGeoManager::LockDefaultUnits(
false);
202 TGeoManager::SetDefaultUnits(TGeoManager::kRootUnits);
203 TGeoManager::LockDefaultUnits(
true);
208 G4cout <<
"Running TVirtualMCApplication::ConstructGeometry"
212 TVirtualMCApplication::Instance()->ConstructGeometry();
216 if (!gGeoManager->IsClosed()) {
217 TGeoVolume* top = (TGeoVolume*)gGeoManager->GetListOfVolumes()->First();
218 gGeoManager->SetTopVolume(top);
219 gGeoManager->CloseGeometry();
224 TVirtualMCApplication::Instance()->MisalignGeometry();
228 rootNavMgr = TG4RootNavMgr::GetInstance(gGeoManager);
233#ifdef G4MULTITHREADED
245 G4cout <<
"G4RunManager has been created." << G4endl;
248 if (userGeometry !=
"VMCtoRoot" && userGeometry !=
"Root") {
252 G4cout <<
"CreateDetectorConstruction done." << G4endl;
257#ifdef G4MULTITHREADED
259 nthreads = G4MTRunManager::GetMasterRunManager()->GetNumberOfThreads();
262 rootNavMgr->Initialize(
new TG4PostDetConstruction(), nthreads);
263 rootNavMgr->ConnectToG4();
266 "geomVMCtoRoot and geomRoot options require Geant4 VMC built with "
274 if (
VerboseLevel() > 1) G4cout <<
"CreatePhysicsList done." << G4endl;
279 if (userFastSimulation) {
286 "TG4SpecialPhysicsList must be instantiated to use fast simulation");
293 G4cout <<
"Create ActionInitialization done." << G4endl;
307 G4cout <<
"TG4RunManager::ConfigureRunManager done " <<
this << G4endl;
317 if (userGeometry !=
"VMCtoRoot" && userGeometry !=
"Root")
return;
320 G4cout <<
"TG4RunManager::CloneRootNavigatorForWorker " <<
this << G4endl;
323 TG4RootNavMgr* masterRootNavMgr = TG4RootNavMgr::GetMasterInstance();
326 TG4RootNavMgr* rootNavMgr = TG4RootNavMgr::GetInstance(*masterRootNavMgr);
328 G4cout <<
"TG4RootNavMgr has been created." << rootNavMgr << G4endl;
331 rootNavMgr->ConnectToG4();
334 G4cout <<
"TG4RunManager::CloneRootNavigatorForWorker done " <<
this
361 argv = (
char**)
new char*[
fARGC];
365 for (
int i = 0; i <
fARGC; i++) {
366 argv[i] = StrDup(
fARGV[i]);
380 if (
fARGC <= 1)
return;
382 G4bool isArg =
false;
383 for (G4int i = 0; i <
fARGC; i++) {
384 if (G4String(
fARGV[i]) == arg) isArg =
true;
398 seeds[0] = gRandom->GetSeed();
399 seeds[1] = gRandom->GetSeed();
401 CLHEP::HepRandom::setTheSeeds(seeds);
412 G4cout <<
"TG4RunManager::Initialize " <<
this << G4endl;
417#if G4VERSION_NUMBER == 1100
432 G4cout <<
"TG4RunManager::Initialize done " <<
this << G4endl;
442 G4cout <<
"TG4RunManager::LateInitialize " <<
this << G4endl;
444 G4bool isMaster = !G4Threading::IsWorkerThread();
475 if (GetEventAction()) {
476 GetEventAction()->LateInitialize();
493 G4cout <<
"TG4RunManager::LateInitialize done " <<
this << G4endl;
505 TVirtualMCStack* mcStack = gMC->GetStack();
508 "TG4RunManager",
"CacheMCStack",
"VMC stack is not set");
512 TMCManagerStack* mcManagerStack = gMC->GetManagerStack();
515 if (GetEventAction()) {
516 GetEventAction()->SetMCStack(mcStack);
544 G4bool cond =
fRunManager->ConfirmBeamOnCondition();
547 "Bad beam condition in G4RunManager. No event processed.");
554 GetEventAction()->SetIsInterruptibleEvent(isInterruptible);
570 "Current run is terminated first, then the requested run is processed");
586 "You are processing a run. To stop it, call StopRun()");
627 G4cout <<
"Welcome (back) in Geant4" << G4endl;
629 G4cout <<
"Welcome (back) in Root" << G4endl;
632 G4cout <<
"Geant4 UI not available." << G4endl;
643 G4cout <<
"Welcome (back) in Root" << G4endl;
645 G4cout <<
"Welcome (back) in Geant4" << G4endl;
654 G4String command =
"/control/execute " + macroName;
664 G4String macroFile = macroName;
665 macroFile.append(
".C");
666 gROOT->LoadMacro(macroFile);
669 G4String macroFunction = macroName;
670 macroFunction.append(
"()");
671 gInterpreter->ProcessLine(macroFunction);
679 G4UImanager* pUI = G4UImanager::GetUIpointer();
680 G4int result = pUI->ApplyCommand(command);
684 case fCommandSucceeded:
686 case fCommandNotFound:
687 G4cerr <<
"***** COMMAND NOT FOUND <" << command <<
"> *****" << G4endl;
689 case fIllegalApplicationState:
690 G4cerr <<
"***** Illegal application state <" << command <<
"> *****"
694 G4int pn = result % 100;
695 G4cerr <<
"***** Illegal parameter (" << pn <<
") <" << command
696 <<
"> *****" << G4endl;
705 gInterpreter->ProcessLine(command);
722 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.
virtual G4VUserPhysicsList * CreatePhysicsList()
Bool_t IsSpecialCutsOld() const
Bool_t IsSpecialCuts() const
virtual TG4VUserFastSimulation * CreateUserFastSimulation()
virtual G4VUserDetectorConstruction * CreateDetectorConstruction()
virtual TG4VUserRegionConstruction * CreateUserRegionConstruction()
TString GetUserGeometry() const
Bool_t IsMTApplication() const
virtual TG4VUserPostDetConstruction * CreateUserPostDetConstruction()
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)
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()
virtual void DefineRegions()=0
virtual void UpdateProductionCutsTable()=0
The abstract base class which is used to build fast simulation models.
Base class for defining the verbose level and a common messenger.
virtual G4int VerboseLevel() const
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