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 "TG4G3PhysicsManager.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()
221 // create physics constructor
222 // (this operation has to precede the "Init" phase)
223 TG4PhysicsManager* physicsManager = TG4PhysicsManager::Instance();
224 physicsManager->CreatePhysicsConstructors();
227 fRunManager->Initialize();
229 // activate/inactivate physics processes
230 // (this operation is not allowed in "Init" phase)
231 physicsManager->SetProcessActivation();
234 void TG4RunManager::ProcessEvent()
236 // Not yet implemented.
239 TG4Globals::Warning("TG4RunManager::ProcessEvent(): is not yet implemented.");
242 void TG4RunManager::ProcessRun(G4int nofEvents)
244 // Processes Geant4 run.
247 fRunManager->BeamOn(nofEvents);
250 void TG4RunManager::StartGeantUI()
252 // Starts interactive/batch Geant4.
255 if (!fGeantUISession) CreateGeantUI();
256 if (fGeantUISession) {
257 // interactive session
258 G4cout << "Welcome back in Geant4" << G4endl;
259 fGeantUISession->SessionStart();
260 G4cout << "Welcome back in Root" << G4endl;
263 // execute Geant4 macro if file is specified as an argument
264 G4String fileName = fARGV[1];
265 ProcessGeantMacro(fileName);
269 void TG4RunManager::StartRootUI()
271 // Starts interactive Root.
274 if (!fRootUISession) CreateRootUI();
275 if (fRootUISession) {
276 G4cout << "Welcome back in Root" << G4endl;
277 fRootUISession->Run(kTRUE);
278 G4cout << "Welcome back in Geant4" << G4endl;
282 void TG4RunManager::ProcessGeantMacro(G4String macroName)
284 // Processes Geant4 macro.
287 G4String command = "/control/execute " + macroName;
288 ProcessGeantCommand(command);
291 void TG4RunManager::ProcessRootMacro(G4String macroName)
293 // Processes Root macro.
297 G4String macroFile = macroName;
298 macroFile.append(".C");
299 gROOT->LoadMacro(macroFile);
301 // execute macro function
302 G4String macroFunction = macroName;
303 macroFunction.append("()");
304 gInterpreter->ProcessLine(macroFunction);
307 void TG4RunManager::ProcessGeantCommand(G4String command)
309 // Processes Geant4 command.
312 G4UImanager* pUI = G4UImanager::GetUIpointer();
313 pUI->ApplyCommand(command);
316 void TG4RunManager::ProcessRootCommand(G4String command)
318 // Processes Root command.
321 gInterpreter->ProcessLine(command);
324 void TG4RunManager::UseG3Defaults()
326 // Controls G3 defaults usage.
329 TG4GeometryManager::Instance()->UseG3TrackingMediaLimits();
330 TG4G3PhysicsManager::Instance()->SetG3DefaultCuts();
331 TG4G3PhysicsManager::Instance()->SetG3DefaultControls();
334 Int_t TG4RunManager::CurrentEvent() const
336 // Returns the number of the current event.
339 G4int eventID = fRunManager->GetCurrentEvent()->GetEventID();