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>
32 #include "G4UItcsh.hh"
39 TG4RunManager* TG4RunManager::fgInstance = 0;
41 //_____________________________________________________________________________
42 TG4RunManager::TG4RunManager(TG4VRunConfiguration* runConfiguration,
43 int argc, char** argv)
44 : TG4Verbose("runManager"),
46 fRunConfiguration(runConfiguration),
55 TG4Globals::Exception(
56 "TG4RunManager: attempt to create two instances of singleton.");
59 if (!fRunConfiguration) {
60 TG4Globals::Exception(
61 "TG4RunManager: attempt to create instance without runConfiguration.");
66 // create and configure geant4 run manager
67 fRunManager = new G4RunManager();
68 fRunConfiguration->ConfigureRunManager(fRunManager);
70 if (VerboseLevel() > 1) {
71 G4cout << "G4RunManager has been created." << G4endl;
76 // must be created before TG4VisManager::Initialize()
77 // (that is invoked in TGeant4 constructor)
83 //_____________________________________________________________________________
84 TG4RunManager::TG4RunManager(TG4VRunConfiguration* runConfiguration)
85 : TG4Verbose("runManager"),
87 fRunConfiguration(runConfiguration),
97 TG4Globals::Exception(
98 "TG4RunManager: attempt to create two instances of singleton.");
101 if (!fRunConfiguration) {
102 TG4Globals::Exception(
103 "TG4RunManager: attempt to create instance without runConfiguration.");
109 fRootUISession = gROOT->GetApplication();
110 if (fRootUISession) {
111 fARGC = fRootUISession->Argc();
112 fARGV = fRootUISession->Argv();
115 // create and configure geant4 run manager
116 fRunManager = new G4RunManager();
117 fRunConfiguration->ConfigureRunManager(fRunManager);
119 if (VerboseLevel() > 1) {
120 G4cout << "G4RunManager has been created." << G4endl;
125 // must be created before TG4VisManager::Initialize()
126 // (that is invoked in TGeant4 constructor)
132 //_____________________________________________________________________________
133 TG4RunManager::TG4RunManager()
134 : TG4Verbose("runManager"),
139 //_____________________________________________________________________________
140 TG4RunManager::TG4RunManager(const TG4RunManager& right)
141 : TG4Verbose("runManager"),
144 TG4Globals::Exception(
145 "Attempt to copy TG4RunManager singleton.");
148 //_____________________________________________________________________________
149 TG4RunManager::~TG4RunManager() {
151 delete fRunConfiguration;
153 delete fGeantUISession;
154 if (fRootUIOwner) delete fRootUISession;
159 //_____________________________________________________________________________
160 TG4RunManager& TG4RunManager::operator=(const TG4RunManager& right)
162 // check assignement to self
163 if (this == &right) return *this;
165 TG4Globals::Exception(
166 "Attempt to assign TG4RunManager singleton.");
173 //_____________________________________________________________________________
174 void TG4RunManager::CreateGeantUI()
176 // Creates interactive Geant4.
179 if (!fGeantUISession)
182 G4UImanager* pUI = G4UImanager::GetUIpointer();
185 fGeantUISession = new G4UIGAG();
188 fGeantUISession = new G4UIterminal(new G4UItcsh);
190 fGeantUISession = new G4UIterminal();
194 else if (strcmp (fARGV[1], "dumb") == 0) {
195 fGeantUISession = new G4UIterminal();
198 else if (strcmp (fARGV[1], "Wo") == 0) {
199 fGeantUISession = new G4UIWo(fARGC, fARGV);
203 else if (strcmp (fARGV[1], "Xm") == 0) {
204 fGeantUISession = new G4UIXm(fARGC, fARGV);
208 else if (strcmp (fARGV[1], "Xaw") == 0) {
209 fGeantUISession = new G4UIXaw(fARGC, fARGV);
213 else if (strcmp (fARGV[1], "GAG") == 0) {
214 fGeantUISession = new G4UIGAG ();
217 if (fGeantUISession) {
218 pUI->SetSession(fGeantUISession);
223 //_____________________________________________________________________________
224 void TG4RunManager::CreateRootUI()
226 // Creates interactive Root.
231 // create session if it does not exist
232 fRootUISession = new TRint("aliroot", 0, 0, 0, 0);
234 // set ownership of Root UI
241 //_____________________________________________________________________________
242 void TG4RunManager::Initialize()
247 // create physics constructor
248 // (this operation has to precede the "Init" phase)
249 TG4PhysicsManager::Instance()->CreatePhysicsConstructors();
252 fRunManager->Initialize();
254 // initialize SD manager
255 TG4SDManager::Instance()->Initialize();
258 //_____________________________________________________________________________
259 void TG4RunManager::LateInitialize()
261 // Finishes initialization of G4 after the AliRoot initialization
266 TG4GeometryManager::Instance()
267 ->SetUserLimits(*TG4G3PhysicsManager::Instance()->GetCutVector(),
268 *TG4G3PhysicsManager::Instance()->GetControlVector());
270 // final clear of G3toG4 objects
271 TG4GeometryManager::Instance()->ClearG3TablesFinal();
273 // activate/inactivate physics processes
274 TG4PhysicsManager::Instance()->SetProcessActivation();
277 TG4GeometryServices::Instance()->PrintStatistics(true, false);
278 TG4SDServices::Instance()->PrintStatistics(false, true);
280 if (VerboseLevel() > 2) {
281 TG4GeometryServices::Instance()->PrintLogicalVolumeStore();
285 //_____________________________________________________________________________
286 void TG4RunManager::ProcessEvent()
288 // Not yet implemented.
291 TG4Globals::Warning("TG4RunManager::ProcessEvent(): is not yet implemented.");
294 //_____________________________________________________________________________
295 void TG4RunManager::ProcessRun(G4int nofEvents)
297 // Processes Geant4 run.
300 fRunManager->BeamOn(nofEvents);
303 //_____________________________________________________________________________
304 void TG4RunManager::StartGeantUI()
306 // Starts interactive/batch Geant4.
309 if (!fGeantUISession) CreateGeantUI();
310 if (fGeantUISession) {
311 // interactive session
312 G4cout << "Welcome back in Geant4" << G4endl;
313 fGeantUISession->SessionStart();
314 G4cout << "Welcome back in Root" << G4endl;
317 // execute Geant4 macro if file is specified as an argument
318 G4String fileName = fARGV[1];
319 ProcessGeantMacro(fileName);
323 //_____________________________________________________________________________
324 void TG4RunManager::StartRootUI()
326 // Starts interactive Root.
329 if (!fRootUISession) CreateRootUI();
330 if (fRootUISession) {
331 G4cout << "Welcome back in Root" << G4endl;
332 fRootUISession->Run(kTRUE);
333 G4cout << "Welcome back in Geant4" << G4endl;
337 //_____________________________________________________________________________
338 void TG4RunManager::ProcessGeantMacro(G4String macroName)
340 // Processes Geant4 macro.
343 G4String command = "/control/execute " + macroName;
344 ProcessGeantCommand(command);
347 //_____________________________________________________________________________
348 void TG4RunManager::ProcessRootMacro(G4String macroName)
350 // Processes Root macro.
354 G4String macroFile = macroName;
355 macroFile.append(".C");
356 gROOT->LoadMacro(macroFile);
358 // execute macro function
359 G4String macroFunction = macroName;
360 macroFunction.append("()");
361 gInterpreter->ProcessLine(macroFunction);
364 //_____________________________________________________________________________
365 void TG4RunManager::ProcessGeantCommand(G4String command)
367 // Processes Geant4 command.
370 G4UImanager* pUI = G4UImanager::GetUIpointer();
371 pUI->ApplyCommand(command);
374 //_____________________________________________________________________________
375 void TG4RunManager::ProcessRootCommand(G4String command)
377 // Processes Root command.
380 gInterpreter->ProcessLine(command);
383 //_____________________________________________________________________________
384 void TG4RunManager::UseG3Defaults()
386 // Controls G3 defaults usage.
389 TG4GeometryManager::Instance()->UseG3TrackingMediaLimits();
390 TG4G3PhysicsManager::Instance()->SetG3DefaultCuts();
391 TG4G3PhysicsManager::Instance()->SetG3DefaultControls();
394 //_____________________________________________________________________________
395 Int_t TG4RunManager::CurrentEvent() const
397 // Returns the number of the current event.
400 G4int eventID = fRunManager->GetCurrentEvent()->GetEventID();