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 "TG4SDManager.h"
12 #include "TG4PhysicsManager.h"
13 #include "TG4G3PhysicsManager.h"
15 #include <G4RunManager.hh>
16 #include <G4UIsession.hh>
17 #include <G4UImanager.hh>
18 #include <G4UIterminal.hh>
31 TG4RunManager* TG4RunManager::fgInstance = 0;
33 //_____________________________________________________________________________
34 TG4RunManager::TG4RunManager(TG4VRunConfiguration* runConfiguration,
35 int argc, char** argv)
36 : fRunConfiguration(runConfiguration),
46 TG4Globals::Exception(
47 "TG4RunManager: attempt to create two instances of singleton.");
50 if (!fRunConfiguration) {
51 TG4Globals::Exception(
52 "TG4RunManager: attempt to create instance without runConfiguration.");
57 // create and configure geant4 run manager
58 fRunManager = new G4RunManager();
59 fRunConfiguration->ConfigureRunManager(fRunManager);
61 //G4cout << "G4RunManager has been created." << G4endl;
65 // must be created before TG4VisManager::Initialize()
66 // (that is invoked in TGeant4 constructor)
72 fMessenger = new TG4RunMessenger(this);
75 //_____________________________________________________________________________
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." << G4endl;
113 // must be created before TG4VisManager::Initialize()
114 // (that is invoked in TGeant4 constructor)
120 fMessenger = new TG4RunMessenger(this);
123 //_____________________________________________________________________________
124 TG4RunManager::TG4RunManager() {
128 //_____________________________________________________________________________
129 TG4RunManager::TG4RunManager(const TG4RunManager& right) {
131 TG4Globals::Exception(
132 "Attempt to copy TG4RunManager singleton.");
135 //_____________________________________________________________________________
136 TG4RunManager::~TG4RunManager() {
138 delete fRunConfiguration;
140 delete fGeantUISession;
141 if (fRootUIOwner) delete fRootUISession;
147 //_____________________________________________________________________________
148 TG4RunManager& TG4RunManager::operator=(const TG4RunManager& right)
150 // check assignement to self
151 if (this == &right) return *this;
153 TG4Globals::Exception(
154 "Attempt to assign TG4RunManager singleton.");
161 //_____________________________________________________________________________
162 void TG4RunManager::CreateGeantUI()
164 // Creates interactive Geant4.
167 if (!fGeantUISession)
170 G4UImanager* pUI = G4UImanager::GetUIpointer();
173 fGeantUISession = new G4UIGAG();
175 fGeantUISession = new G4UIterminal();
178 else if (strcmp (fARGV[1], "dumb") == 0) {
179 fGeantUISession = new G4UIterminal();
182 else if (strcmp (fARGV[1], "Wo") == 0) {
183 fGeantUISession = new G4UIWo(fARGC, fARGV);
187 else if (strcmp (fARGV[1], "Xm") == 0) {
188 fGeantUISession = new G4UIXm(fARGC, fARGV);
192 else if (strcmp (fARGV[1], "Xaw") == 0) {
193 fGeantUISession = new G4UIXaw(fARGC, fARGV);
197 else if (strcmp (fARGV[1], "GAG") == 0) {
198 fGeantUISession = new G4UIGAG ();
201 if (fGeantUISession) {
202 pUI->SetSession(fGeantUISession);
207 //_____________________________________________________________________________
208 void TG4RunManager::CreateRootUI()
210 // Creates interactive Root.
215 // create session if it does not exist
216 fRootUISession = new TRint("aliroot", 0, 0, 0, 0);
218 // set ownership of Root UI
225 //_____________________________________________________________________________
226 void TG4RunManager::Initialize()
231 // create physics constructor
232 // (this operation has to precede the "Init" phase)
233 TG4PhysicsManager::Instance()->CreatePhysicsConstructors();
236 fRunManager->Initialize();
238 // initialize SD manager
239 TG4SDManager::Instance()->Initialize();
241 // activate/inactivate physics processes
242 // (this operation is not allowed in "Init" phase)
243 TG4PhysicsManager::Instance()->SetProcessActivation();
246 //_____________________________________________________________________________
247 void TG4RunManager::ProcessEvent()
249 // Not yet implemented.
252 TG4Globals::Warning("TG4RunManager::ProcessEvent(): is not yet implemented.");
255 //_____________________________________________________________________________
256 void TG4RunManager::ProcessRun(G4int nofEvents)
258 // Processes Geant4 run.
261 fRunManager->BeamOn(nofEvents);
264 //_____________________________________________________________________________
265 void TG4RunManager::StartGeantUI()
267 // Starts interactive/batch Geant4.
270 if (!fGeantUISession) CreateGeantUI();
271 if (fGeantUISession) {
272 // interactive session
273 G4cout << "Welcome back in Geant4" << G4endl;
274 fGeantUISession->SessionStart();
275 G4cout << "Welcome back in Root" << G4endl;
278 // execute Geant4 macro if file is specified as an argument
279 G4String fileName = fARGV[1];
280 ProcessGeantMacro(fileName);
284 //_____________________________________________________________________________
285 void TG4RunManager::StartRootUI()
287 // Starts interactive Root.
290 if (!fRootUISession) CreateRootUI();
291 if (fRootUISession) {
292 G4cout << "Welcome back in Root" << G4endl;
293 fRootUISession->Run(kTRUE);
294 G4cout << "Welcome back in Geant4" << G4endl;
298 //_____________________________________________________________________________
299 void TG4RunManager::ProcessGeantMacro(G4String macroName)
301 // Processes Geant4 macro.
304 G4String command = "/control/execute " + macroName;
305 ProcessGeantCommand(command);
308 //_____________________________________________________________________________
309 void TG4RunManager::ProcessRootMacro(G4String macroName)
311 // Processes Root macro.
315 G4String macroFile = macroName;
316 macroFile.append(".C");
317 gROOT->LoadMacro(macroFile);
319 // execute macro function
320 G4String macroFunction = macroName;
321 macroFunction.append("()");
322 gInterpreter->ProcessLine(macroFunction);
325 //_____________________________________________________________________________
326 void TG4RunManager::ProcessGeantCommand(G4String command)
328 // Processes Geant4 command.
331 G4UImanager* pUI = G4UImanager::GetUIpointer();
332 pUI->ApplyCommand(command);
335 //_____________________________________________________________________________
336 void TG4RunManager::ProcessRootCommand(G4String command)
338 // Processes Root command.
341 gInterpreter->ProcessLine(command);
344 //_____________________________________________________________________________
345 void TG4RunManager::UseG3Defaults()
347 // Controls G3 defaults usage.
350 TG4GeometryManager::Instance()->UseG3TrackingMediaLimits();
351 TG4G3PhysicsManager::Instance()->SetG3DefaultCuts();
352 TG4G3PhysicsManager::Instance()->SetG3DefaultControls();
355 //_____________________________________________________________________________
356 Int_t TG4RunManager::CurrentEvent() const
358 // Returns the number of the current event.
361 G4int eventID = fRunManager->GetCurrentEvent()->GetEventID();