4 // Author: I. Hrivnacova
8 // See the class description in the header file.
10 #include "TG4RunManager.h"
11 #include "TG4VRunConfiguration.h"
12 #include "TG4Globals.h"
13 #include "TG4GeometryManager.h"
14 #include "TG4GeometryServices.h"
15 #include "TG4SDManager.h"
16 #include "TG4SDServices.h"
17 #include "TG4PhysicsManager.h"
18 #include "TG4G3PhysicsManager.h"
20 #include <G4RunManager.hh>
21 #include <G4UIsession.hh>
22 #include <G4UImanager.hh>
23 #include <G4UIterminal.hh>
36 TG4RunManager* TG4RunManager::fgInstance = 0;
38 //_____________________________________________________________________________
39 TG4RunManager::TG4RunManager(TG4VRunConfiguration* runConfiguration,
40 int argc, char** argv)
41 : TG4Verbose("runManager"),
43 fRunConfiguration(runConfiguration),
52 TG4Globals::Exception(
53 "TG4RunManager: attempt to create two instances of singleton.");
56 if (!fRunConfiguration) {
57 TG4Globals::Exception(
58 "TG4RunManager: attempt to create instance without runConfiguration.");
63 // create and configure geant4 run manager
64 fRunManager = new G4RunManager();
65 fRunConfiguration->ConfigureRunManager(fRunManager);
67 if (VerboseLevel() > 1) {
68 G4cout << "G4RunManager has been created." << G4endl;
73 // must be created before TG4VisManager::Initialize()
74 // (that is invoked in TGeant4 constructor)
80 //_____________________________________________________________________________
81 TG4RunManager::TG4RunManager(TG4VRunConfiguration* runConfiguration)
82 : TG4Verbose("runManager"),
84 fRunConfiguration(runConfiguration),
94 TG4Globals::Exception(
95 "TG4RunManager: attempt to create two instances of singleton.");
98 if (!fRunConfiguration) {
99 TG4Globals::Exception(
100 "TG4RunManager: attempt to create instance without runConfiguration.");
106 fRootUISession = gROOT->GetApplication();
107 if (fRootUISession) {
108 fARGC = fRootUISession->Argc();
109 fARGV = fRootUISession->Argv();
112 // create and configure geant4 run manager
113 fRunManager = new G4RunManager();
114 fRunConfiguration->ConfigureRunManager(fRunManager);
116 if (VerboseLevel() > 1) {
117 G4cout << "G4RunManager has been created." << G4endl;
122 // must be created before TG4VisManager::Initialize()
123 // (that is invoked in TGeant4 constructor)
129 //_____________________________________________________________________________
130 TG4RunManager::TG4RunManager()
131 : TG4Verbose("runManager"),
136 //_____________________________________________________________________________
137 TG4RunManager::TG4RunManager(const TG4RunManager& right)
138 : TG4Verbose("runManager"),
141 TG4Globals::Exception(
142 "Attempt to copy TG4RunManager singleton.");
145 //_____________________________________________________________________________
146 TG4RunManager::~TG4RunManager() {
148 delete fRunConfiguration;
150 delete fGeantUISession;
151 if (fRootUIOwner) delete fRootUISession;
156 //_____________________________________________________________________________
157 TG4RunManager& TG4RunManager::operator=(const TG4RunManager& right)
159 // check assignement to self
160 if (this == &right) return *this;
162 TG4Globals::Exception(
163 "Attempt to assign TG4RunManager singleton.");
170 //_____________________________________________________________________________
171 void TG4RunManager::CreateGeantUI()
173 // Creates interactive Geant4.
176 if (!fGeantUISession)
179 G4UImanager* pUI = G4UImanager::GetUIpointer();
182 fGeantUISession = new G4UIGAG();
185 fGeantUISession = new G4UIterminal(new G4UItcsh);
187 fGeantUISession = new G4UIterminal();
191 else if (strcmp (fARGV[1], "dumb") == 0) {
192 fGeantUISession = new G4UIterminal();
195 else if (strcmp (fARGV[1], "Wo") == 0) {
196 fGeantUISession = new G4UIWo(fARGC, fARGV);
200 else if (strcmp (fARGV[1], "Xm") == 0) {
201 fGeantUISession = new G4UIXm(fARGC, fARGV);
205 else if (strcmp (fARGV[1], "Xaw") == 0) {
206 fGeantUISession = new G4UIXaw(fARGC, fARGV);
210 else if (strcmp (fARGV[1], "GAG") == 0) {
211 fGeantUISession = new G4UIGAG ();
214 if (fGeantUISession) {
215 pUI->SetSession(fGeantUISession);
220 //_____________________________________________________________________________
221 void TG4RunManager::CreateRootUI()
223 // Creates interactive Root.
228 // create session if it does not exist
229 fRootUISession = new TRint("aliroot", 0, 0, 0, 0);
231 // set ownership of Root UI
238 //_____________________________________________________________________________
239 void TG4RunManager::Initialize()
244 // create physics constructor
245 // (this operation has to precede the "Init" phase)
246 TG4PhysicsManager::Instance()->CreatePhysicsConstructors();
249 fRunManager->Initialize();
251 // initialize SD manager
252 TG4SDManager::Instance()->Initialize();
255 //_____________________________________________________________________________
256 void TG4RunManager::LateInitialize()
258 // Finishes initialization of G4 after the AliRoot initialization
263 TG4GeometryManager::Instance()
264 ->SetUserLimits(*TG4G3PhysicsManager::Instance()->GetCutVector(),
265 *TG4G3PhysicsManager::Instance()->GetControlVector());
267 // final clear of G3toG4 objects
268 TG4GeometryManager::Instance()->ClearG3TablesFinal();
270 // activate/inactivate physics processes
271 TG4PhysicsManager::Instance()->SetProcessActivation();
274 TG4GeometryServices::Instance()->PrintStatistics(true, false);
275 TG4SDServices::Instance()->PrintStatistics(false, true);
278 //_____________________________________________________________________________
279 void TG4RunManager::ProcessEvent()
281 // Not yet implemented.
284 TG4Globals::Warning("TG4RunManager::ProcessEvent(): is not yet implemented.");
287 //_____________________________________________________________________________
288 void TG4RunManager::ProcessRun(G4int nofEvents)
290 // Processes Geant4 run.
293 fRunManager->BeamOn(nofEvents);
296 //_____________________________________________________________________________
297 void TG4RunManager::StartGeantUI()
299 // Starts interactive/batch Geant4.
302 if (!fGeantUISession) CreateGeantUI();
303 if (fGeantUISession) {
304 // interactive session
305 G4cout << "Welcome back in Geant4" << G4endl;
306 fGeantUISession->SessionStart();
307 G4cout << "Welcome back in Root" << G4endl;
310 // execute Geant4 macro if file is specified as an argument
311 G4String fileName = fARGV[1];
312 ProcessGeantMacro(fileName);
316 //_____________________________________________________________________________
317 void TG4RunManager::StartRootUI()
319 // Starts interactive Root.
322 if (!fRootUISession) CreateRootUI();
323 if (fRootUISession) {
324 G4cout << "Welcome back in Root" << G4endl;
325 fRootUISession->Run(kTRUE);
326 G4cout << "Welcome back in Geant4" << G4endl;
330 //_____________________________________________________________________________
331 void TG4RunManager::ProcessGeantMacro(G4String macroName)
333 // Processes Geant4 macro.
336 G4String command = "/control/execute " + macroName;
337 ProcessGeantCommand(command);
340 //_____________________________________________________________________________
341 void TG4RunManager::ProcessRootMacro(G4String macroName)
343 // Processes Root macro.
347 G4String macroFile = macroName;
348 macroFile.append(".C");
349 gROOT->LoadMacro(macroFile);
351 // execute macro function
352 G4String macroFunction = macroName;
353 macroFunction.append("()");
354 gInterpreter->ProcessLine(macroFunction);
357 //_____________________________________________________________________________
358 void TG4RunManager::ProcessGeantCommand(G4String command)
360 // Processes Geant4 command.
363 G4UImanager* pUI = G4UImanager::GetUIpointer();
364 pUI->ApplyCommand(command);
367 //_____________________________________________________________________________
368 void TG4RunManager::ProcessRootCommand(G4String command)
370 // Processes Root command.
373 gInterpreter->ProcessLine(command);
376 //_____________________________________________________________________________
377 void TG4RunManager::UseG3Defaults()
379 // Controls G3 defaults usage.
382 TG4GeometryManager::Instance()->UseG3TrackingMediaLimits();
383 TG4G3PhysicsManager::Instance()->SetG3DefaultCuts();
384 TG4G3PhysicsManager::Instance()->SetG3DefaultControls();
387 //_____________________________________________________________________________
388 Int_t TG4RunManager::CurrentEvent() const
390 // Returns the number of the current event.
393 G4int eventID = fRunManager->GetCurrentEvent()->GetEventID();