]>
Commit | Line | Data |
---|---|---|
1 | // $Id$ | |
2 | // Category: run | |
3 | // | |
4 | // Author: I. Hrivnacova | |
5 | // | |
6 | // Class TG4RunManager | |
7 | // ------------------- | |
8 | // See the class description in the header file. | |
9 | ||
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" | |
19 | ||
20 | #include <G4RunManager.hh> | |
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 | |
31 | ||
32 | #include <TROOT.h> | |
33 | #include <TRint.h> | |
34 | #include <TCint.h> | |
35 | ||
36 | TG4RunManager* TG4RunManager::fgInstance = 0; | |
37 | ||
38 | //_____________________________________________________________________________ | |
39 | TG4RunManager::TG4RunManager(TG4VRunConfiguration* runConfiguration, | |
40 | int argc, char** argv) | |
41 | : fMessenger(this), | |
42 | fRunConfiguration(runConfiguration), | |
43 | fGeantUISession(0), | |
44 | fRootUISession(0), | |
45 | fRootUIOwner(false), | |
46 | fARGC(argc), | |
47 | fARGV(argv) | |
48 | { | |
49 | // | |
50 | if (fgInstance) { | |
51 | TG4Globals::Exception( | |
52 | "TG4RunManager: attempt to create two instances of singleton."); | |
53 | } | |
54 | ||
55 | if (!fRunConfiguration) { | |
56 | TG4Globals::Exception( | |
57 | "TG4RunManager: attempt to create instance without runConfiguration."); | |
58 | } | |
59 | ||
60 | fgInstance = this; | |
61 | ||
62 | // create and configure geant4 run manager | |
63 | fRunManager = new G4RunManager(); | |
64 | fRunConfiguration->ConfigureRunManager(fRunManager); | |
65 | // add verbose level | |
66 | //G4cout << "G4RunManager has been created." << G4endl; | |
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(); | |
75 | } | |
76 | ||
77 | //_____________________________________________________________________________ | |
78 | TG4RunManager::TG4RunManager(TG4VRunConfiguration* runConfiguration) | |
79 | : fMessenger(this), | |
80 | fRunConfiguration(runConfiguration), | |
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."); | |
92 | } | |
93 | ||
94 | if (!fRunConfiguration) { | |
95 | TG4Globals::Exception( | |
96 | "TG4RunManager: attempt to create instance without runConfiguration."); | |
97 | } | |
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 | |
112 | //G4cout << "G4RunManager has been created." << G4endl; | |
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(); | |
121 | } | |
122 | ||
123 | //_____________________________________________________________________________ | |
124 | TG4RunManager::TG4RunManager() | |
125 | : fMessenger(this) { | |
126 | // | |
127 | } | |
128 | ||
129 | //_____________________________________________________________________________ | |
130 | TG4RunManager::TG4RunManager(const TG4RunManager& right) | |
131 | : fMessenger(this) { | |
132 | // | |
133 | TG4Globals::Exception( | |
134 | "Attempt to copy TG4RunManager singleton."); | |
135 | } | |
136 | ||
137 | //_____________________________________________________________________________ | |
138 | TG4RunManager::~TG4RunManager() { | |
139 | // | |
140 | delete fRunConfiguration; | |
141 | delete fRunManager; | |
142 | delete fGeantUISession; | |
143 | if (fRootUIOwner) delete fRootUISession; | |
144 | } | |
145 | ||
146 | // operators | |
147 | ||
148 | //_____________________________________________________________________________ | |
149 | TG4RunManager& 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 | ||
162 | //_____________________________________________________________________________ | |
163 | void 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(); | |
175 | #else | |
176 | #ifdef G4UI_USE_TCSH | |
177 | fGeantUISession = new G4UIterminal(new G4UItcsh); | |
178 | #else | |
179 | fGeantUISession = new G4UIterminal(); | |
180 | #endif | |
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 | ||
212 | //_____________________________________________________________________________ | |
213 | void 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 | ||
230 | //_____________________________________________________________________________ | |
231 | void TG4RunManager::Initialize() | |
232 | { | |
233 | // Initializes G4. | |
234 | // --- | |
235 | ||
236 | // create physics constructor | |
237 | // (this operation has to precede the "Init" phase) | |
238 | TG4PhysicsManager::Instance()->CreatePhysicsConstructors(); | |
239 | ||
240 | // initialize Geant4 | |
241 | fRunManager->Initialize(); | |
242 | ||
243 | // initialize SD manager | |
244 | TG4SDManager::Instance()->Initialize(); | |
245 | } | |
246 | ||
247 | //_____________________________________________________________________________ | |
248 | void TG4RunManager::LateInitialize() | |
249 | { | |
250 | // Finishes initialization of G4 after the AliRoot initialization | |
251 | // is finished. | |
252 | // --- | |
253 | ||
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 | ||
262 | // activate/inactivate physics processes | |
263 | TG4PhysicsManager::Instance()->SetProcessActivation(); | |
264 | ||
265 | // print statistics | |
266 | TG4GeometryServices::Instance()->PrintStatistics(true, false); | |
267 | TG4SDServices::Instance()->PrintStatistics(false, true); | |
268 | } | |
269 | ||
270 | //_____________________________________________________________________________ | |
271 | void TG4RunManager::ProcessEvent() | |
272 | { | |
273 | // Not yet implemented. | |
274 | // --- | |
275 | ||
276 | TG4Globals::Warning("TG4RunManager::ProcessEvent(): is not yet implemented."); | |
277 | } | |
278 | ||
279 | //_____________________________________________________________________________ | |
280 | void TG4RunManager::ProcessRun(G4int nofEvents) | |
281 | { | |
282 | // Processes Geant4 run. | |
283 | // --- | |
284 | ||
285 | fRunManager->BeamOn(nofEvents); | |
286 | } | |
287 | ||
288 | //_____________________________________________________________________________ | |
289 | void TG4RunManager::StartGeantUI() | |
290 | { | |
291 | // Starts interactive/batch Geant4. | |
292 | // --- | |
293 | ||
294 | if (!fGeantUISession) CreateGeantUI(); | |
295 | if (fGeantUISession) { | |
296 | // interactive session | |
297 | G4cout << "Welcome back in Geant4" << G4endl; | |
298 | fGeantUISession->SessionStart(); | |
299 | G4cout << "Welcome back in Root" << G4endl; | |
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 | ||
308 | //_____________________________________________________________________________ | |
309 | void TG4RunManager::StartRootUI() | |
310 | { | |
311 | // Starts interactive Root. | |
312 | // --- | |
313 | ||
314 | if (!fRootUISession) CreateRootUI(); | |
315 | if (fRootUISession) { | |
316 | G4cout << "Welcome back in Root" << G4endl; | |
317 | fRootUISession->Run(kTRUE); | |
318 | G4cout << "Welcome back in Geant4" << G4endl; | |
319 | } | |
320 | } | |
321 | ||
322 | //_____________________________________________________________________________ | |
323 | void TG4RunManager::ProcessGeantMacro(G4String macroName) | |
324 | { | |
325 | // Processes Geant4 macro. | |
326 | // --- | |
327 | ||
328 | G4String command = "/control/execute " + macroName; | |
329 | ProcessGeantCommand(command); | |
330 | } | |
331 | ||
332 | //_____________________________________________________________________________ | |
333 | void 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 | ||
349 | //_____________________________________________________________________________ | |
350 | void TG4RunManager::ProcessGeantCommand(G4String command) | |
351 | { | |
352 | // Processes Geant4 command. | |
353 | // --- | |
354 | ||
355 | G4UImanager* pUI = G4UImanager::GetUIpointer(); | |
356 | pUI->ApplyCommand(command); | |
357 | } | |
358 | ||
359 | //_____________________________________________________________________________ | |
360 | void TG4RunManager::ProcessRootCommand(G4String command) | |
361 | { | |
362 | // Processes Root command. | |
363 | // --- | |
364 | ||
365 | gInterpreter->ProcessLine(command); | |
366 | } | |
367 | ||
368 | //_____________________________________________________________________________ | |
369 | void TG4RunManager::UseG3Defaults() | |
370 | { | |
371 | // Controls G3 defaults usage. | |
372 | // --- | |
373 | ||
374 | TG4GeometryManager::Instance()->UseG3TrackingMediaLimits(); | |
375 | TG4G3PhysicsManager::Instance()->SetG3DefaultCuts(); | |
376 | TG4G3PhysicsManager::Instance()->SetG3DefaultControls(); | |
377 | } | |
378 | ||
379 | //_____________________________________________________________________________ | |
380 | Int_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 | } |