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