4 // See the class description in the header file.
6 #include "TG4RunManager.h"
7 #include "TG4RunMessenger.h"
8 #include "TG4VRunConfiguration.h"
9 #include "TG4Globals.h"
10 #include "TG4GeometryManager.h"
11 #include "TG4PhysicsManager.h"
12 //#include "TG4StepManager.h"
14 #include <G4RunManager.hh>
15 #include <G4UIsession.hh>
16 #include <G4UImanager.hh>
17 #include <G4UIterminal.hh>
30 TG4RunManager* TG4RunManager::fgInstance = 0;
32 TG4RunManager::TG4RunManager(TG4VRunConfiguration* runConfiguration,
33 int argc, char** argv)
34 : fRunConfiguration(runConfiguration),
44 TG4Globals::Exception(
45 "TG4RunManager: attempt to create two instances of singleton.");
48 if (!fRunConfiguration) {
49 TG4Globals::Exception(
50 "TG4RunManager: attempt to create instance without runConfiguration.");
55 // create and configure geant4 run manager
56 fRunManager = new G4RunManager();
57 fRunConfiguration->ConfigureRunManager(fRunManager);
59 //G4cout << "G4RunManager has been created." << G4endl;
63 // must be created before TG4VisManager::Initialize()
64 // (that is invoked in TGeant4 constructor)
70 fMessenger = new TG4RunMessenger(this);
73 TG4RunManager::TG4RunManager(TG4VRunConfiguration* runConfiguration)
74 : fRunConfiguration(runConfiguration),
84 TG4Globals::Exception(
85 "TG4RunManager: attempt to create two instances of singleton.");
88 if (!fRunConfiguration) {
89 TG4Globals::Exception(
90 "TG4RunManager: attempt to create instance without runConfiguration.");
96 fRootUISession = gROOT->GetApplication();
98 fARGC = fRootUISession->Argc();
99 fARGV = fRootUISession->Argv();
102 // create and configure geant4 run manager
103 fRunManager = new G4RunManager();
104 fRunConfiguration->ConfigureRunManager(fRunManager);
106 //G4cout << "G4RunManager has been created." << G4endl;
110 // must be created before TG4VisManager::Initialize()
111 // (that is invoked in TGeant4 constructor)
117 fMessenger = new TG4RunMessenger(this);
120 TG4RunManager::TG4RunManager() {
124 TG4RunManager::TG4RunManager(const TG4RunManager& right) {
126 TG4Globals::Exception(
127 "Attempt to copy TG4RunManager singleton.");
130 TG4RunManager::~TG4RunManager() {
132 delete fRunConfiguration;
134 delete fGeantUISession;
135 if (fRootUIOwner) delete fRootUISession;
141 TG4RunManager& TG4RunManager::operator=(const TG4RunManager& right)
143 // check assignement to self
144 if (this == &right) return *this;
146 TG4Globals::Exception(
147 "Attempt to assign TG4RunManager singleton.");
154 void TG4RunManager::CreateGeantUI()
156 // Creates interactive Geant4.
159 if (!fGeantUISession)
162 G4UImanager* pUI = G4UImanager::GetUIpointer();
165 fGeantUISession = new G4UIGAG();
167 fGeantUISession = new G4UIterminal();
170 else if (strcmp (fARGV[1], "dumb") == 0) {
171 fGeantUISession = new G4UIterminal();
174 else if (strcmp (fARGV[1], "Wo") == 0) {
175 fGeantUISession = new G4UIWo(fARGC, fARGV);
179 else if (strcmp (fARGV[1], "Xm") == 0) {
180 fGeantUISession = new G4UIXm(fARGC, fARGV);
184 else if (strcmp (fARGV[1], "Xaw") == 0) {
185 fGeantUISession = new G4UIXaw(fARGC, fARGV);
189 else if (strcmp (fARGV[1], "GAG") == 0) {
190 fGeantUISession = new G4UIGAG ();
193 if (fGeantUISession) {
194 pUI->SetSession(fGeantUISession);
199 void TG4RunManager::CreateRootUI()
201 // Creates interactive Root.
206 // create session if it does not exist
207 fRootUISession = new TRint("aliroot", 0, 0, 0, 0);
209 // set ownership of Root UI
216 void TG4RunManager::Initialize()
222 fRunManager->Initialize();
224 // activate/inactivate physics processes
225 // (this operation is not allowed in "Init" phase)
226 TG4PhysicsManager* physicsManager = TG4PhysicsManager::Instance();
227 physicsManager->SetProcessActivation();
230 void TG4RunManager::ProcessEvent()
232 // Not yet implemented.
235 TG4Globals::Warning("TG4RunManager::ProcessEvent(): is not yet implemented.");
238 void TG4RunManager::ProcessRun(G4int nofEvents)
240 // Processes Geant4 run.
243 fRunManager->BeamOn(nofEvents);
246 void TG4RunManager::StartGeantUI()
248 // Starts interactive/batch Geant4.
251 if (!fGeantUISession) CreateGeantUI();
252 if (fGeantUISession) {
253 // interactive session
254 G4cout << "Welcome back in Geant4" << G4endl;
255 fGeantUISession->SessionStart();
256 G4cout << "Welcome back in Root" << G4endl;
259 // execute Geant4 macro if file is specified as an argument
260 G4String fileName = fARGV[1];
261 ProcessGeantMacro(fileName);
265 void TG4RunManager::StartRootUI()
267 // Starts interactive Root.
270 if (!fRootUISession) CreateRootUI();
271 if (fRootUISession) {
272 G4cout << "Welcome back in Root" << G4endl;
273 fRootUISession->Run(kTRUE);
274 G4cout << "Welcome back in Geant4" << G4endl;
278 void TG4RunManager::ProcessGeantMacro(G4String macroName)
280 // Processes Geant4 macro.
283 G4String command = "/control/execute " + macroName;
284 ProcessGeantCommand(command);
287 void TG4RunManager::ProcessRootMacro(G4String macroName)
289 // Processes Root macro.
293 G4String macroFile = macroName;
294 macroFile.append(".C");
295 gROOT->LoadMacro(macroFile);
297 // execute macro function
298 G4String macroFunction = macroName;
299 macroFunction.append("()");
300 gInterpreter->ProcessLine(macroFunction);
303 void TG4RunManager::ProcessGeantCommand(G4String command)
305 // Processes Geant4 command.
308 G4UImanager* pUI = G4UImanager::GetUIpointer();
309 pUI->ApplyCommand(command);
312 void TG4RunManager::ProcessRootCommand(G4String command)
314 // Processes Root command.
317 gInterpreter->ProcessLine(command);
320 void TG4RunManager::UseG3Defaults()
322 // Controls G3 defaults usage.
325 TG4GeometryManager::Instance()->UseG3TrackingMediaLimits();
326 TG4PhysicsManager::Instance()->SetG3DefaultCuts();
327 TG4PhysicsManager::Instance()->SetG3DefaultProcesses();
330 Int_t TG4RunManager::CurrentEvent() const
332 // Returns the number of the current event.
335 G4int eventID = fRunManager->GetCurrentEvent()->GetEventID();