4 // See the class description in the header file.
6 #include "TG4RunManager.h"
7 #include "TG4RunMessenger.h"
8 #include "TG4VRunConfiguration.h"
10 #include "TG4Globals.h"
11 #include "TG4GeometryManager.h"
12 #include "TG4PhysicsManager.h"
13 //#include "TG4StepManager.h"
15 #include <G4RunManager.hh>
16 #include <G4StateManager.hh>
17 #include <G4UIsession.hh>
18 #include <G4UImanager.hh>
19 #include <G4UIterminal.hh>
33 TG4RunManager* TG4RunManager::fgInstance = 0;
35 TG4RunManager::TG4RunManager(TG4VRunConfiguration* runConfiguration,
36 int argc, char** argv)
37 : fRunConfiguration(runConfiguration),
47 TG4Globals::Exception(
48 "TG4RunManager: attempt to create two instances of singleton.");
51 if (!fRunConfiguration) {
52 TG4Globals::Exception(
53 "TG4RunManager: attempt to create instance without runConfiguration.");
58 // create and configure geant4 run manager
59 fRunManager = new G4RunManager();
60 fRunConfiguration->ConfigureRunManager(fRunManager);
62 //G4cout << "G4RunManager has been created." << endl;
66 // must be created before TG4VisManager::Initialize()
67 // (that is invoked in TGeant4 constructor)
73 fMessenger = new TG4RunMessenger(this);
76 TG4RunManager::TG4RunManager(TG4VRunConfiguration* runConfiguration)
77 : fRunConfiguration(runConfiguration),
87 TG4Globals::Exception(
88 "TG4RunManager: attempt to create two instances of singleton.");
91 if (!fRunConfiguration) {
92 TG4Globals::Exception(
93 "TG4RunManager: attempt to create instance without runConfiguration.");
99 fRootUISession = gROOT->GetApplication();
100 if (fRootUISession) {
101 fARGC = fRootUISession->Argc();
102 fARGV = fRootUISession->Argv();
105 // create and configure geant4 run manager
106 fRunManager = new G4RunManager();
107 fRunConfiguration->ConfigureRunManager(fRunManager);
109 //G4cout << "G4RunManager has been created." << endl;
113 // must be created before TG4VisManager::Initialize()
114 // (that is invoked in TGeant4 constructor)
120 fMessenger = new TG4RunMessenger(this);
123 TG4RunManager::TG4RunManager() {
127 TG4RunManager::TG4RunManager(const TG4RunManager& right) {
129 TG4Globals::Exception(
130 "Attempt to copy TG4RunManager singleton.");
133 TG4RunManager::~TG4RunManager() {
135 delete fRunConfiguration;
137 delete fGeantUISession;
138 if (fRootUIOwner) delete fRootUISession;
144 TG4RunManager& TG4RunManager::operator=(const TG4RunManager& right)
146 // check assignement to self
147 if (this == &right) return *this;
149 TG4Globals::Exception(
150 "Attempt to assign TG4RunManager singleton.");
157 void TG4RunManager::CreateGeantUI()
159 // Creates interactive Geant4.
162 if (!fGeantUISession)
165 G4UImanager* pUI = G4UImanager::GetUIpointer();
168 fGeantUISession = new G4UIGAG();
170 fGeantUISession = new G4UIterminal();
173 else if (strcmp (fARGV[1], "dumb") == 0) {
174 fGeantUISession = new G4UIterminal();
177 else if (strcmp (fARGV[1], "Wo") == 0) {
178 fGeantUISession = new G4UIWo(fARGC, fARGV);
182 else if (strcmp (fARGV[1], "Xm") == 0) {
183 fGeantUISession = new G4UIXm(fARGC, fARGV);
187 else if (strcmp (fARGV[1], "Xaw") == 0) {
188 fGeantUISession = new G4UIXaw(fARGC, fARGV);
192 else if (strcmp (fARGV[1], "GAG") == 0) {
193 fGeantUISession = new G4UIGAG ();
196 if (fGeantUISession) {
197 pUI->SetSession(fGeantUISession);
202 void TG4RunManager::CreateRootUI()
204 // Creates interactive Root.
209 // create session if it does not exist
210 fRootUISession = new TRint("aliroot", 0, 0, 0, 0);
212 // set ownership of Root UI
219 void TG4RunManager::Initialize()
225 fRunManager->Initialize();
227 // activate/inactivate physics processes
228 // (this operation is not allowed in "Init" phase)
229 TG4PhysicsManager* physicsManager = TG4PhysicsManager::Instance();
230 physicsManager->SetProcessActivation();
233 void TG4RunManager::ProcessEvent()
235 // Not yet implemented.
238 TG4Globals::Warning("TG4RunManager::ProcessEvent(): is not yet implemented.");
241 void TG4RunManager::ProcessRun(G4int nofEvents)
243 // Processes Geant4 run.
246 fRunManager->BeamOn(nofEvents);
249 void TG4RunManager::StartGeantUI()
251 // Starts interactive/batch Geant4.
254 if (!fGeantUISession) CreateGeantUI();
255 if (fGeantUISession) {
256 // interactive session
257 G4cout << "Welcome back in Geant4" << endl;
258 fGeantUISession->SessionStart();
259 G4cout << "Welcome back in Root" << endl;
262 // execute Geant4 macro if file is specified as an argument
263 G4String fileName = fARGV[1];
264 ProcessGeantMacro(fileName);
268 void TG4RunManager::StartRootUI()
270 // Starts interactive Root.
273 if (!fRootUISession) CreateRootUI();
274 if (fRootUISession) {
275 G4cout << "Welcome back in Root" << endl;
276 fRootUISession->Run(kTRUE);
277 G4cout << "Welcome back in Geant4" << endl;
281 void TG4RunManager::ProcessGeantMacro(G4String macroName)
283 // Processes Geant4 macro.
286 G4String command = "/control/execute " + macroName;
287 ProcessGeantCommand(command);
290 void TG4RunManager::ProcessRootMacro(G4String macroName)
292 // Processes Root macro.
296 G4String macroFile = macroName;
297 macroFile.append(".C");
298 gROOT->LoadMacro(macroFile);
300 // execute macro function
301 G4String macroFunction = macroName;
302 macroFunction.append("()");
303 gInterpreter->ProcessLine(macroFunction);
306 void TG4RunManager::ProcessGeantCommand(G4String command)
308 // Processes Geant4 command.
311 G4UImanager* pUI = G4UImanager::GetUIpointer();
312 pUI->ApplyCommand(command);
315 void TG4RunManager::ProcessRootCommand(G4String command)
317 // Processes Root command.
320 gInterpreter->ProcessLine(command);
323 void TG4RunManager::UseG3Defaults()
325 // Controls G3 defaults usage.
328 TG4GeometryManager::Instance()->UseG3TrackingMediaLimits();
329 TG4PhysicsManager::Instance()->SetG3DefaultCuts();
330 TG4PhysicsManager::Instance()->SetG3DefaultProcesses();
333 Int_t TG4RunManager::CurrentEvent() const
335 // Returns the number of the current event.
338 G4int eventID = fRunManager->GetCurrentEvent()->GetEventID();