]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TGeant4/TG4RunManager.cxx
removed call to private G4EnergyLossTables::GetTables()
[u/mrichter/AliRoot.git] / TGeant4 / TG4RunManager.cxx
CommitLineData
2817d3e2 1// $Id$
2// Category: run
3//
e5967ab3 4// Author: I. Hrivnacova
5//
6// Class TG4RunManager
7// -------------------
2817d3e2 8// See the class description in the header file.
9
10#include "TG4RunManager.h"
2817d3e2 11#include "TG4VRunConfiguration.h"
2817d3e2 12#include "TG4Globals.h"
13#include "TG4GeometryManager.h"
e5967ab3 14#include "TG4GeometryServices.h"
286b8190 15#include "TG4SDManager.h"
e5967ab3 16#include "TG4SDServices.h"
2817d3e2 17#include "TG4PhysicsManager.h"
43eead53 18#include "TG4G3PhysicsManager.h"
2817d3e2 19
20#include <G4RunManager.hh>
2817d3e2 21#include <G4UIsession.hh>
22#include <G4UImanager.hh>
23#include <G4UIterminal.hh>
24#include <G4UIXm.hh>
25#ifdef G4UI_USE_WO
26#include <G4UIWo.hh>
27#endif
28#ifdef G4UI_USE_GAG
29#include <G4UIGAG.hh>
30#endif
2817d3e2 31
2817d3e2 32#include <TROOT.h>
14d0f123 33#include <TRint.h>
2817d3e2 34#include <TCint.h>
35
36TG4RunManager* TG4RunManager::fgInstance = 0;
37
286b8190 38//_____________________________________________________________________________
2817d3e2 39TG4RunManager::TG4RunManager(TG4VRunConfiguration* runConfiguration,
40 int argc, char** argv)
5b6ecd36 41 : TG4Verbose("runManager"),
42 fMessenger(this),
e5967ab3 43 fRunConfiguration(runConfiguration),
2817d3e2 44 fGeantUISession(0),
45 fRootUISession(0),
46 fRootUIOwner(false),
47 fARGC(argc),
e5967ab3 48 fARGV(argv)
2817d3e2 49{
50//
51 if (fgInstance) {
52 TG4Globals::Exception(
53 "TG4RunManager: attempt to create two instances of singleton.");
286b8190 54 }
2817d3e2 55
56 if (!fRunConfiguration) {
57 TG4Globals::Exception(
58 "TG4RunManager: attempt to create instance without runConfiguration.");
286b8190 59 }
2817d3e2 60
61 fgInstance = this;
62
63 // create and configure geant4 run manager
64 fRunManager = new G4RunManager();
65 fRunConfiguration->ConfigureRunManager(fRunManager);
5b6ecd36 66
67 if (VerboseLevel() > 1) {
68 G4cout << "G4RunManager has been created." << G4endl;
69 }
2817d3e2 70
71 // create geant4 UI
72 CreateGeantUI();
73 // must be created before TG4VisManager::Initialize()
74 // (that is invoked in TGeant4 constructor)
75
76 // create root UI
77 CreateRootUI();
2817d3e2 78}
79
286b8190 80//_____________________________________________________________________________
2817d3e2 81TG4RunManager::TG4RunManager(TG4VRunConfiguration* runConfiguration)
5b6ecd36 82 : TG4Verbose("runManager"),
83 fMessenger(this),
e5967ab3 84 fRunConfiguration(runConfiguration),
2817d3e2 85 fGeantUISession(0),
86 fRootUISession(0),
87 fRootUIOwner(false),
88 fARGC(0),
89 fARGV(0)
90
91{
92//
93 if (fgInstance) {
94 TG4Globals::Exception(
95 "TG4RunManager: attempt to create two instances of singleton.");
286b8190 96 }
2817d3e2 97
98 if (!fRunConfiguration) {
99 TG4Globals::Exception(
100 "TG4RunManager: attempt to create instance without runConfiguration.");
286b8190 101 }
2817d3e2 102
103 fgInstance = this;
104
105 // set primary UI
106 fRootUISession = gROOT->GetApplication();
107 if (fRootUISession) {
108 fARGC = fRootUISession->Argc();
109 fARGV = fRootUISession->Argv();
110 }
111
112 // create and configure geant4 run manager
113 fRunManager = new G4RunManager();
114 fRunConfiguration->ConfigureRunManager(fRunManager);
5b6ecd36 115
116 if (VerboseLevel() > 1) {
117 G4cout << "G4RunManager has been created." << G4endl;
118 }
2817d3e2 119
120 // create geant4 UI
121 CreateGeantUI();
122 // must be created before TG4VisManager::Initialize()
123 // (that is invoked in TGeant4 constructor)
124
125 // create root UI
126 CreateRootUI();
2817d3e2 127}
128
286b8190 129//_____________________________________________________________________________
e5967ab3 130TG4RunManager::TG4RunManager()
5b6ecd36 131 : TG4Verbose("runManager"),
132 fMessenger(this) {
2817d3e2 133//
134}
135
286b8190 136//_____________________________________________________________________________
e5967ab3 137TG4RunManager::TG4RunManager(const TG4RunManager& right)
5b6ecd36 138 : TG4Verbose("runManager"),
139 fMessenger(this) {
2817d3e2 140//
141 TG4Globals::Exception(
142 "Attempt to copy TG4RunManager singleton.");
143}
144
286b8190 145//_____________________________________________________________________________
2817d3e2 146TG4RunManager::~TG4RunManager() {
147//
148 delete fRunConfiguration;
149 delete fRunManager;
150 delete fGeantUISession;
151 if (fRootUIOwner) delete fRootUISession;
2817d3e2 152}
153
154// operators
155
286b8190 156//_____________________________________________________________________________
2817d3e2 157TG4RunManager& TG4RunManager::operator=(const TG4RunManager& right)
158{
159 // check assignement to self
160 if (this == &right) return *this;
161
162 TG4Globals::Exception(
163 "Attempt to assign TG4RunManager singleton.");
164
165 return *this;
166}
167
168// private methods
169
286b8190 170//_____________________________________________________________________________
2817d3e2 171void TG4RunManager::CreateGeantUI()
172{
173// Creates interactive Geant4.
174// ---
175
176 if (!fGeantUISession)
177 {
178 // create geant4 UI
179 G4UImanager* pUI = G4UImanager::GetUIpointer();
180 if (fARGC == 1) {
181#ifdef G4UI_USE_GAG
182 fGeantUISession = new G4UIGAG();
e5967ab3 183#else
184 #ifdef G4UI_USE_TCSH
185 fGeantUISession = new G4UIterminal(new G4UItcsh);
186 #else
2817d3e2 187 fGeantUISession = new G4UIterminal();
e5967ab3 188 #endif
2817d3e2 189#endif
190 }
191 else if (strcmp (fARGV[1], "dumb") == 0) {
192 fGeantUISession = new G4UIterminal();
193 }
194#ifdef G4UI_USE_WO
195 else if (strcmp (fARGV[1], "Wo") == 0) {
196 fGeantUISession = new G4UIWo(fARGC, fARGV);
197 }
198#endif
199#ifdef G4UI_USE_XM
200 else if (strcmp (fARGV[1], "Xm") == 0) {
201 fGeantUISession = new G4UIXm(fARGC, fARGV);
202 }
203#endif
204#ifdef G4UI_USE_XAW
205 else if (strcmp (fARGV[1], "Xaw") == 0) {
206 fGeantUISession = new G4UIXaw(fARGC, fARGV);
207 }
208#endif
209#ifdef G4UI_USE_GAG
210 else if (strcmp (fARGV[1], "GAG") == 0) {
211 fGeantUISession = new G4UIGAG ();
212 }
213#endif
214 if (fGeantUISession) {
215 pUI->SetSession(fGeantUISession);
216 }
217 }
218}
219
286b8190 220//_____________________________________________________________________________
2817d3e2 221void TG4RunManager::CreateRootUI()
222{
223// Creates interactive Root.
224// ---
225
226 if (!fRootUISession)
227 {
228 // create session if it does not exist
229 fRootUISession = new TRint("aliroot", 0, 0, 0, 0);
230
231 // set ownership of Root UI
232 fRootUIOwner = true;
233 }
234}
235
236// public methods
237
286b8190 238//_____________________________________________________________________________
2817d3e2 239void TG4RunManager::Initialize()
240{
241// Initializes G4.
242// ---
243
43eead53 244 // create physics constructor
245 // (this operation has to precede the "Init" phase)
286b8190 246 TG4PhysicsManager::Instance()->CreatePhysicsConstructors();
43eead53 247
2817d3e2 248 // initialize Geant4
249 fRunManager->Initialize();
250
286b8190 251 // initialize SD manager
252 TG4SDManager::Instance()->Initialize();
e5967ab3 253}
254
255//_____________________________________________________________________________
256void TG4RunManager::LateInitialize()
257{
258// Finishes initialization of G4 after the AliRoot initialization
259// is finished.
260// ---
286b8190 261
e5967ab3 262 // set user limits
263 TG4GeometryManager::Instance()
264 ->SetUserLimits(*TG4G3PhysicsManager::Instance()->GetCutVector(),
265 *TG4G3PhysicsManager::Instance()->GetControlVector());
266
267 // final clear of G3toG4 objects
268 TG4GeometryManager::Instance()->ClearG3TablesFinal();
269
2817d3e2 270 // activate/inactivate physics processes
286b8190 271 TG4PhysicsManager::Instance()->SetProcessActivation();
e5967ab3 272
273 // print statistics
274 TG4GeometryServices::Instance()->PrintStatistics(true, false);
275 TG4SDServices::Instance()->PrintStatistics(false, true);
2817d3e2 276}
277
286b8190 278//_____________________________________________________________________________
2817d3e2 279void TG4RunManager::ProcessEvent()
280{
281// Not yet implemented.
282// ---
283
284 TG4Globals::Warning("TG4RunManager::ProcessEvent(): is not yet implemented.");
285}
286
286b8190 287//_____________________________________________________________________________
2817d3e2 288void TG4RunManager::ProcessRun(G4int nofEvents)
289{
290// Processes Geant4 run.
291// ---
292
293 fRunManager->BeamOn(nofEvents);
294}
295
286b8190 296//_____________________________________________________________________________
2817d3e2 297void TG4RunManager::StartGeantUI()
298{
299// Starts interactive/batch Geant4.
300// ---
301
302 if (!fGeantUISession) CreateGeantUI();
303 if (fGeantUISession) {
304 // interactive session
3c7cd15a 305 G4cout << "Welcome back in Geant4" << G4endl;
2817d3e2 306 fGeantUISession->SessionStart();
3c7cd15a 307 G4cout << "Welcome back in Root" << G4endl;
2817d3e2 308 }
309 else {
310 // execute Geant4 macro if file is specified as an argument
311 G4String fileName = fARGV[1];
312 ProcessGeantMacro(fileName);
313 }
314}
315
286b8190 316//_____________________________________________________________________________
2817d3e2 317void TG4RunManager::StartRootUI()
318{
319// Starts interactive Root.
320// ---
321
322 if (!fRootUISession) CreateRootUI();
323 if (fRootUISession) {
3c7cd15a 324 G4cout << "Welcome back in Root" << G4endl;
2817d3e2 325 fRootUISession->Run(kTRUE);
3c7cd15a 326 G4cout << "Welcome back in Geant4" << G4endl;
2817d3e2 327 }
328}
329
286b8190 330//_____________________________________________________________________________
2817d3e2 331void TG4RunManager::ProcessGeantMacro(G4String macroName)
332{
333// Processes Geant4 macro.
334// ---
335
336 G4String command = "/control/execute " + macroName;
337 ProcessGeantCommand(command);
338}
339
286b8190 340//_____________________________________________________________________________
2817d3e2 341void TG4RunManager::ProcessRootMacro(G4String macroName)
342{
343// Processes Root macro.
344// ---
345
346 // load macro file
347 G4String macroFile = macroName;
348 macroFile.append(".C");
349 gROOT->LoadMacro(macroFile);
350
351 // execute macro function
352 G4String macroFunction = macroName;
353 macroFunction.append("()");
354 gInterpreter->ProcessLine(macroFunction);
355}
356
286b8190 357//_____________________________________________________________________________
2817d3e2 358void TG4RunManager::ProcessGeantCommand(G4String command)
359{
360// Processes Geant4 command.
361// ---
362
363 G4UImanager* pUI = G4UImanager::GetUIpointer();
364 pUI->ApplyCommand(command);
365}
366
286b8190 367//_____________________________________________________________________________
2817d3e2 368void TG4RunManager::ProcessRootCommand(G4String command)
369{
370// Processes Root command.
371// ---
372
373 gInterpreter->ProcessLine(command);
374}
375
286b8190 376//_____________________________________________________________________________
2817d3e2 377void TG4RunManager::UseG3Defaults()
378{
379// Controls G3 defaults usage.
380// ---
381
382 TG4GeometryManager::Instance()->UseG3TrackingMediaLimits();
43eead53 383 TG4G3PhysicsManager::Instance()->SetG3DefaultCuts();
384 TG4G3PhysicsManager::Instance()->SetG3DefaultControls();
2817d3e2 385}
386
286b8190 387//_____________________________________________________________________________
2817d3e2 388Int_t TG4RunManager::CurrentEvent() const
389{
390// Returns the number of the current event.
391// ---
392
393 G4int eventID = fRunManager->GetCurrentEvent()->GetEventID();
394 return eventID;
395}