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