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>
58#include <TG4RootNavMgr.h>
61#include <TGeoManager.h>
62#include <TInterpreter.h>
63#include <TMCManager.h>
64#include <TMCManagerStack.h>
68#include <TVirtualMC.h>
69#include <TVirtualMCApplication.h>
77 G4RunManager::GetRunManager()->GetUserEventAction()));
108 G4cout <<
"TG4RunManager::TG4RunManager " <<
this << G4endl;
113 "Cannot create two instances of singleton.");
118 "Cannot create instance without runConfiguration.");
127 fARGV[0] = StrDup(
"undefined");
130 G4bool isMaster = !G4Threading::IsWorkerThread();
136 G4ScoringManager::GetScoringManager();
154 G4cout <<
"TG4RunManager has been created." <<
this << G4endl;
163 G4bool isMaster = !G4Threading::IsWorkerThread();
189 G4cout <<
"TG4RunManager::ConfigureRunManager " <<
this << G4endl;
201 TG4RootNavMgr* rootNavMgr = 0;
202 if (userGeometry ==
"VMCtoRoot" || userGeometry ==
"Root") {
203 if (!TMCManager::Instance()) {
205#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 22, 8)
207 TGeoManager::LockDefaultUnits(
false);
208 TGeoManager::SetDefaultUnits(TGeoManager::kRootUnits);
209 TGeoManager::LockDefaultUnits(
true);
214 G4cout <<
"Running TVirtualMCApplication::ConstructGeometry"
218 TVirtualMCApplication::Instance()->ConstructGeometry();
222 if (!gGeoManager->IsClosed()) {
223 TGeoVolume* top = (TGeoVolume*)gGeoManager->GetListOfVolumes()->First();
224 gGeoManager->SetTopVolume(top);
225 gGeoManager->CloseGeometry();
230 TVirtualMCApplication::Instance()->MisalignGeometry();
234 rootNavMgr = TG4RootNavMgr::GetInstance(gGeoManager);
239#ifdef G4MULTITHREADED
251 G4cout <<
"G4RunManager has been created." << G4endl;
254 if (userGeometry !=
"VMCtoRoot" && userGeometry !=
"Root") {
258 G4cout <<
"CreateDetectorConstruction done." << G4endl;
263#ifdef G4MULTITHREADED
265 nthreads = G4MTRunManager::GetMasterRunManager()->GetNumberOfThreads();
268 rootNavMgr->Initialize(
new TG4PostDetConstruction(), nthreads);
269 rootNavMgr->ConnectToG4();
272 "geomVMCtoRoot and geomRoot options require Geant4 VMC built with "
280 if (
VerboseLevel() > 1) G4cout <<
"CreatePhysicsList done." << G4endl;
285 if (userFastSimulation) {
292 "TG4SpecialPhysicsList must be instantiated to use fast simulation");
299 G4cout <<
"Create ActionInitialization done." << G4endl;
313 G4cout <<
"TG4RunManager::ConfigureRunManager done " <<
this << G4endl;
323 if (userGeometry !=
"VMCtoRoot" && userGeometry !=
"Root")
return;
326 G4cout <<
"TG4RunManager::CloneRootNavigatorForWorker " <<
this << G4endl;
329 TG4RootNavMgr* masterRootNavMgr = TG4RootNavMgr::GetMasterInstance();
332 TG4RootNavMgr* rootNavMgr = TG4RootNavMgr::GetInstance(*masterRootNavMgr);
334 G4cout <<
"TG4RootNavMgr has been created." << rootNavMgr << G4endl;
337 rootNavMgr->ConnectToG4();
340 G4cout <<
"TG4RunManager::CloneRootNavigatorForWorker done " <<
this
367 argv = (
char**)
new char*[
fARGC];
371 for (
int i = 0; i <
fARGC; i++) {
372 argv[i] = StrDup(
fARGV[i]);
386 if (
fARGC <= 1)
return;
388 G4bool isArg =
false;
389 for (G4int i = 0; i <
fARGC; i++) {
390 if (G4String(
fARGV[i]) == arg) isArg =
true;
404 seeds[0] = gRandom->GetSeed();
405 seeds[1] = gRandom->GetSeed();
407 CLHEP::HepRandom::setTheSeeds(seeds);
418 G4cout <<
"TG4RunManager::Initialize " <<
this << G4endl;
423#if G4VERSION_NUMBER == 1100
438 G4cout <<
"TG4RunManager::Initialize done " <<
this << G4endl;
448 G4cout <<
"TG4RunManager::LateInitialize " <<
this << G4endl;
450 G4bool isMaster = !G4Threading::IsWorkerThread();
487 if (GetEventAction()) {
488 GetEventAction()->LateInitialize();
505 G4cout <<
"TG4RunManager::LateInitialize done " <<
this << G4endl;
517 TVirtualMCStack* mcStack = gMC->GetStack();
520 "TG4RunManager",
"CacheMCStack",
"VMC stack is not set");
524 TMCManagerStack* mcManagerStack = gMC->GetManagerStack();
527 if (GetEventAction()) {
528 GetEventAction()->SetMCStack(mcStack);
556 G4bool cond =
fRunManager->ConfirmBeamOnCondition();
559 "Bad beam condition in G4RunManager. No event processed.");
566 GetEventAction()->SetIsInterruptibleEvent(isInterruptible);
582 "Current run is terminated first, then the requested run is processed");
598 "You are processing a run. To stop it, call StopRun()");
618 auto g4ScoringManager = G4ScoringManager::GetScoringManager();
619 for (std::size_t i = 0; i < g4ScoringManager->GetNumberOfMesh(); ++i) {
620 auto meshName = g4ScoringManager->GetMesh(i)->GetWorldName();
621 auto fileName = meshName +
".txt";
622 g4ScoringManager->DumpAllQuantitiesToFile(meshName, fileName);
649 G4cout <<
"Welcome (back) in Geant4" << G4endl;
651 G4cout <<
"Welcome (back) in Root" << G4endl;
654 G4cout <<
"Geant4 UI not available." << G4endl;
665 G4cout <<
"Welcome (back) in Root" << G4endl;
667 G4cout <<
"Welcome (back) in Geant4" << G4endl;
676 G4String command =
"/control/execute " + macroName;
686 G4String macroFile = macroName;
687 macroFile.append(
".C");
688 gROOT->LoadMacro(macroFile);
691 G4String macroFunction = macroName;
692 macroFunction.append(
"()");
693 gInterpreter->ProcessLine(macroFunction);
701 G4UImanager* pUI = G4UImanager::GetUIpointer();
702 G4int result = pUI->ApplyCommand(command);
706 case fCommandSucceeded:
708 case fCommandNotFound:
709 G4cerr <<
"***** COMMAND NOT FOUND <" << command <<
"> *****" << G4endl;
711 case fIllegalApplicationState:
712 G4cerr <<
"***** Illegal application state <" << command <<
"> *****"
716 G4int pn = result % 100;
717 G4cerr <<
"***** Illegal parameter (" << pn <<
") <" << command
718 <<
"> *****" << G4endl;
727 gInterpreter->ProcessLine(command);
744 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
static TG4SDManager * Instance()
void LateInitialize(TG4ScoreWeightCalculator swc)
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