Geant4
9.6.p02
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
geant4_9_6_p02
source
run
include
G4RunManager.hh
Go to the documentation of this file.
1
//
2
// ********************************************************************
3
// * License and Disclaimer *
4
// * *
5
// * The Geant4 software is copyright of the Copyright Holders of *
6
// * the Geant4 Collaboration. It is provided under the terms and *
7
// * conditions of the Geant4 Software License, included in the file *
8
// * LICENSE and available at http://cern.ch/geant4/license . These *
9
// * include a list of copyright holders. *
10
// * *
11
// * Neither the authors of this software system, nor their employing *
12
// * institutes,nor the agencies providing financial support for this *
13
// * work make any representation or warranty, express or implied, *
14
// * regarding this software system or assume any liability for its *
15
// * use. Please see the license in the file LICENSE and URL above *
16
// * for the full disclaimer and the limitation of liability. *
17
// * *
18
// * This code implementation is the result of the scientific and *
19
// * technical work of the GEANT4 collaboration. *
20
// * By using, copying, modifying or distributing the software (or *
21
// * any work based on the software) you agree to acknowledge its *
22
// * use in resulting scientific publications, and indicate your *
23
// * acceptance of all terms of the Geant4 Software license. *
24
// ********************************************************************
25
//
26
//
27
// $Id$
28
//
29
//
30
31
// class description:
32
//
33
// This is a class for run control in GEANT4
34
//
35
// User must provide his own classes derived from the following
36
// three abstract classes and register them to the RunManager.
37
// G4VUserDetectorConstruction - Detector Geometry, Materials
38
// G4VUserPhysicsList - Particle types and Processes
39
// G4VUserPrimaryGeneratorAction - Event Generator selection
40
//
41
// In addition to the above mandatory classes, user can easily
42
// customize of the default functionality of GEANT4 simulation
43
// by making his own classes derived from the following 5 user
44
// action classes.
45
// G4UserRunAction - Actions for each Run
46
// G4UserEventAction - Actions for each Event
47
// G4UserStackingAction - Tracks Stacking selection
48
// G4UserTrackingAction - Actions for each Track
49
// G4UserSteppingAction - Actions for each Step
50
//
51
// G4RunManager is the only manager class in Geant4 kernel which
52
// the user MUST construct an object by him/herself in the main().
53
// Also, G4RunManager is the only manager class in Geant4 kernel
54
// which the user CAN derive it to costomize the behavior of the
55
// run control. For this case, user should use protected methods
56
// provided in this class for procedures he/she does not want to
57
// change.
58
//
59
// G4RunManager or the derived class of it MUST be a singleton.
60
// The user MUST NOT construct more than one object even if there
61
// are two different concrete implementations.
62
//
63
// G4RunManager controls all of state changes. See G4ApplicationState.hh
64
// in intercoms category for the meanings of each state.
65
//
66
67
#ifndef G4RunManager_h
68
#define G4RunManager_h 1
69
70
// userAction classes
71
class
G4VUserDetectorConstruction
;
72
class
G4VUserPhysicsList
;
73
class
G4UserRunAction
;
74
class
G4VUserPrimaryGeneratorAction
;
75
class
G4UserEventAction
;
76
class
G4UserStackingAction
;
77
class
G4UserTrackingAction
;
78
class
G4UserSteppingAction
;
79
80
class
G4VPhysicalVolume
;
81
class
G4LogicalVolume
;
82
class
G4Region
;
83
class
G4Timer
;
84
class
G4RunMessenger
;
85
class
G4DCtable
;
86
class
G4Run
;
87
class
G4PrimaryTransformer
;
88
89
#include "
G4RunManagerKernel.hh
"
90
#include "
G4Event.hh
"
91
#include "
G4EventManager.hh
"
92
#include "
globals.hh
"
93
#include <vector>
94
#include <algorithm>
95
96
class
G4RunManager
97
{
98
public
:
// with description
99
static
G4RunManager
*
GetRunManager
();
100
// Static method which returns the singleton pointer of G4RunManager or
101
// its derived class.
102
103
private
:
104
static
G4RunManager
* fRunManager;
105
106
public
:
// with description
107
G4RunManager
();
108
virtual
~G4RunManager
();
109
// The constructor and the destructor. The user must construct this class
110
// object at the beginning of his/her main() and must delete it at the
111
// bottom of the main().
112
113
public
:
// with description
114
virtual
void
BeamOn
(
G4int
n_event,
const
char
* macroFile=0,
G4int
n_select=-1);
115
// This method starts an event loof of "n_event" events. The condition of Geant4
116
// is examined before starting the event loop. This method must be invoked at
117
// Idle state. The state will be changed to GeomClosed during the event loop and
118
// will go back to Idle when the loop is over or aborted.
119
// In case a string "macroFile" which represents the name of a macro file is given,
120
// this macro file will be executed AT THE END of each event processing. In case
121
// "n_select" is greater than zero, at the ond of first "n_select" events the macro
122
// file is executed.
123
virtual
void
Initialize
();
124
// This method invokes all the necessary initialization procedures for an event
125
// loop. This method must be invoked at the Geant4 state of PreInit or Idle. The
126
// state will be changed to Init during the initialization procedures and then
127
// changed to Idle.
128
// This method invokes two protected methods, InitializeGeometry() and
129
// InitializePhysics().
130
// After some event loops, the user can invoke this method once again. It is
131
// required if the user changes geometry, physics process, and/or cut off value.
132
// If the user forget the second invokation, G4RunManager will invoke BeamOn()
133
// method will invoke this method. (Note that this feature is not valid for the
134
// first initialization.)
135
virtual
void
DefineWorldVolume
(
G4VPhysicalVolume
* worldVol,
136
G4bool
topologyIsChanged=
true
);
137
// This method must be invoked if the geometry setup has been changed between
138
// runs. The flag 'topologyIsChanged' will specify if the geometry topology is
139
// different from the original one used in the previous run; if not, it must be
140
// set to false, so that the original optimisation and navigation history is
141
// preserved. This method is invoked also at initialisation.
143
// Resets the state of the navigator for tracking; needed for geometry updates.
144
// It forces the optimisation and navigation history to be reset.
145
virtual
void
AbortRun
(
G4bool
softAbort=
false
);
146
// This method safely aborts the current event loop even if an event is in progress.
147
// This method is available for Geant4 states of GeomClosed and EventProc. The state
148
// will be changed to Idle, so that another event loop can be done.
149
// If softAbort is true, the event loop is aborted after processing the current
150
// event, while the current event is aborted if it is false.
151
virtual
void
AbortEvent
();
152
// This method aborts the currently processing event, remaining events in the
153
// current event loop will be processed. This method is available only for
154
// EventProc state.
155
156
public
:
// with description
157
158
virtual
void
InitializeGeometry
();
159
virtual
void
InitializePhysics
();
160
// These protected methods are invoked from Initialize() method for the
161
// initializations of geometry and physics processes. The user's concrete
162
// G4VUserDetectorConstruction class will be accessed from InitializeGeometry() and
163
// G4VUserPhysicsList class will be accessed from InitializePhysics().
164
165
virtual
G4bool
ConfirmBeamOnCondition
();
166
virtual
void
RunInitialization
();
167
virtual
void
DoEventLoop
(
G4int
n_event,
const
char
* macroFile=0,
G4int
n_select=-1);
168
virtual
void
RunTermination
();
169
// These four protected methods are invoked from BeamOn() method. These four methods
170
// are invoked in this order.
171
// ConfirmBeamOnCondition() method checks if all the necessary initializations have
172
// already done. If the condition is not satisfied, false is returned and the follwing
173
// three methods will be skipped.
174
// RunInitialization() method initializes a run. For example, a G4Run class object
175
// is constructed in this method.
176
// DoEventLoop() method control an event loop. Arguments are same as BeamOn() method.
177
// Inide the event loop, two following protected methods are invoked at the begining
178
// and the end of each event.
179
// RunTermination() method terminates a run processing. For example, a G4Run class
180
// object is deleted in this class. If the user uses ODBMS and wants to store the
181
// G4Run class object, he/she must override this method.
182
183
virtual
void
InitializeEventLoop
(
G4int
n_event,
const
char
* macroFile=0,
G4int
n_select=-1);
184
virtual
void
ProcessOneEvent
(
G4int
i_event);
185
virtual
void
TerminateOneEvent
();
186
virtual
void
TerminateEventLoop
();
187
// Granular virtual methods invoked from DoEventLoop() method.
188
190
// This method is invoked from RunInitialization() to create physics tables.
191
192
virtual
G4Event
*
GenerateEvent
(
G4int
i_event);
193
virtual
void
AnalyzeEvent
(
G4Event
* anEvent);
194
// These two protected methods are invoked from DoEventLoop() method at the begining
195
// and the end of each event processing.
196
// GenerateEvent() method constructs a G4Event class object and invoke the user's
197
// G4VUserPrimaryGeneratorAction concrete class. If the user is using ODBMS and event
198
// objects have been created and stored in the data base, he/she must override this
199
// method.
200
// AnalyzeEvent() stores an event to a data base if a concrete G4VPersistentManager
201
// class is defined.
202
203
public
:
// with description
205
// Update region list.
206
// This method is mandatory before invoking following two dump methods.
207
// At RunInitialization(), this method is automatically invoked, and thus
208
// the user needs not invoke.
209
210
void
DumpRegion
(
const
G4String
& rname)
const
;
211
// Dump information of a region.
212
213
void
DumpRegion
(
G4Region
* region=0)
const
;
214
// Dump information of a region.
215
// If the pointer is NULL, all regions are shown.
216
217
protected
:
218
void
StackPreviousEvent
(
G4Event
* anEvent);
219
220
protected
:
221
G4RunManagerKernel
*
kernel
;
222
G4EventManager
*
eventManager
;
223
224
G4VUserDetectorConstruction
*
userDetector
;
225
G4VUserPhysicsList
*
physicsList
;
226
G4UserRunAction
*
userRunAction
;
227
G4VUserPrimaryGeneratorAction
*
userPrimaryGeneratorAction
;
228
G4UserEventAction
*
userEventAction
;
229
G4UserStackingAction
*
userStackingAction
;
230
G4UserTrackingAction
*
userTrackingAction
;
231
G4UserSteppingAction
*
userSteppingAction
;
232
233
private
:
234
G4RunMessenger
* runMessenger;
235
236
protected
:
237
G4bool
geometryInitialized
;
238
G4bool
physicsInitialized
;
239
G4bool
runAborted
;
240
G4bool
initializedAtLeastOnce
;
241
G4bool
geometryToBeOptimized
;
242
243
G4int
runIDCounter
;
244
G4int
verboseLevel
;
245
G4Timer
*
timer
;
246
G4DCtable
*
DCtable
;
247
248
G4Run
*
currentRun
;
249
G4Event
*
currentEvent
;
250
std::vector<G4Event*>*
previousEvents
;
251
G4int
n_perviousEventsToBeStored
;
252
G4int
numberOfEventToBeProcessed
;
253
254
G4bool
storeRandomNumberStatus
;
255
G4int
storeRandomNumberStatusToG4Event
;
256
G4String
randomNumberStatusDir
;
257
G4String
randomNumberStatusForThisRun
;
258
G4String
randomNumberStatusForThisEvent
;
259
260
G4VPhysicalVolume
*
currentWorld
;
261
262
G4int
nParallelWorlds
;
263
264
G4String
msgText
;
265
G4int
n_select_msg
;
266
G4int
numberOfEventProcessed
;
267
268
public
:
269
virtual
void
rndmSaveThisRun
();
270
virtual
void
rndmSaveThisEvent
();
271
virtual
void
RestoreRandomNumberStatus
(
const
G4String
& fileN);
272
273
public
:
// with description
274
inline
void
SetUserInitialization
(
G4VUserDetectorConstruction
* userInit)
275
{
userDetector
= userInit; }
276
inline
void
SetUserInitialization
(
G4VUserPhysicsList
* userInit)
277
{
278
physicsList
= userInit;
279
kernel
->
SetPhysics
(userInit);
280
}
281
inline
void
SetUserAction
(
G4UserRunAction
* userAction)
282
{
userRunAction
= userAction; }
283
inline
void
SetUserAction
(
G4VUserPrimaryGeneratorAction
* userAction)
284
{
userPrimaryGeneratorAction
= userAction; }
285
inline
void
SetUserAction
(
G4UserEventAction
* userAction)
286
{
287
eventManager
->
SetUserAction
(userAction);
288
userEventAction
= userAction;
289
}
290
inline
void
SetUserAction
(
G4UserStackingAction
* userAction)
291
{
292
eventManager
->
SetUserAction
(userAction);
293
userStackingAction
= userAction;
294
}
295
inline
void
SetUserAction
(
G4UserTrackingAction
* userAction)
296
{
297
eventManager
->
SetUserAction
(userAction);
298
userTrackingAction
= userAction;
299
}
300
inline
void
SetUserAction
(
G4UserSteppingAction
* userAction)
301
{
302
eventManager
->
SetUserAction
(userAction);
303
userSteppingAction
= userAction;
304
}
305
// These methods store respective user initialization and action classes.
306
inline
const
G4VUserDetectorConstruction
*
GetUserDetectorConstruction
()
const
307
{
return
userDetector
; }
308
inline
const
G4VUserPhysicsList
*
GetUserPhysicsList
()
const
309
{
return
physicsList
; }
310
inline
const
G4UserRunAction
*
GetUserRunAction
()
const
311
{
return
userRunAction
; }
312
inline
const
G4VUserPrimaryGeneratorAction
*
GetUserPrimaryGeneratorAction
()
const
313
{
return
userPrimaryGeneratorAction
; }
314
inline
const
G4UserEventAction
*
GetUserEventAction
()
const
315
{
return
userEventAction
; }
316
inline
const
G4UserStackingAction
*
GetUserStackingAction
()
const
317
{
return
userStackingAction
; }
318
inline
const
G4UserTrackingAction
*
GetUserTrackingAction
()
const
319
{
return
userTrackingAction
; }
320
inline
const
G4UserSteppingAction
*
GetUserSteppingAction
()
const
321
{
return
userSteppingAction
; }
322
// These methods returns respective user initialization and action classes.
323
324
inline
void
SetNumberOfAdditionalWaitingStacks
(
G4int
iAdd)
325
{
eventManager
->
SetNumberOfAdditionalWaitingStacks
(iAdd); }
326
// Set the number of additional (optional) waiting stacks.
327
// This method must be invoked at PreInit, Init or Idle states.
328
// Once the user set the number of additional waiting stacks,
329
// he/she can use the corresponding ENUM in G4ClassificationOfNewTrack.
330
331
inline
const
G4String
&
GetVersionString
()
const
332
{
return
kernel
->
GetVersionString
(); }
333
334
inline
void
SetPrimaryTransformer
(
G4PrimaryTransformer
*
pt
)
335
{
kernel
->
SetPrimaryTransformer
(pt); }
336
337
inline
void
StoreRandomNumberStatusToG4Event
(
G4int
vl)
338
// if vl = 1 : status before primary particle generation is stored
339
// if vl = 2 : status before event processing (after primary particle generation) is stored
340
// if vl = 3 : both are stored
341
// if vl = 0 : none is stored (default)
342
{
343
storeRandomNumberStatusToG4Event
= vl;
344
eventManager
->
StoreRandomNumberStatusToG4Event
(vl);
345
}
346
inline
G4int
GetFlagRandomNumberStatusToG4Event
()
const
347
{
return
storeRandomNumberStatusToG4Event
; }
348
349
public
:
350
inline
void
SetRandomNumberStore
(
G4bool
flag)
351
{
storeRandomNumberStatus
= flag; }
352
inline
G4bool
GetRandomNumberStore
()
const
353
{
return
storeRandomNumberStatus
; }
354
inline
void
SetRandomNumberStoreDir
(
const
G4String
&
dir
)
355
{
356
G4String
dirStr =
dir
;
357
if
( dirStr(dirStr.length()-1) !=
'/'
) dirStr +=
"/"
;
358
#ifndef WIN32
359
G4String
shellCmd =
"mkdir -p "
;
360
#else
361
std::replace(dirStr.begin(), dirStr.end(),
'/'
,
'\\'
);
362
G4String
shellCmd =
"if not exist "
+ dirStr +
" mkdir "
;
363
#endif
364
shellCmd += dirStr;
365
randomNumberStatusDir
= dirStr;
366
G4int
sysret = system(shellCmd);
367
if
(sysret!=0)
368
{
369
G4String
errmsg =
"\""
+ shellCmd +
"\" returns non-zero value. Directory creation failed."
;
370
G4Exception
(
"GrRunManager::SetRandomNumberStoreDir"
,
"Run0071"
,
JustWarning
,errmsg);
371
G4cerr
<<
" return value = "
<< sysret <<
G4endl
;
372
}
373
}
374
inline
const
G4String
&
GetRandomNumberStoreDir
()
const
375
{
return
randomNumberStatusDir
; }
376
inline
const
G4String
&
GetRandomNumberStatusForThisRun
()
const
377
{
return
randomNumberStatusForThisRun
; }
378
inline
const
G4String
&
GetRandomNumberStatusForThisEvent
()
const
379
{
380
if
(
storeRandomNumberStatusToG4Event
==0 ||
storeRandomNumberStatusToG4Event
==2)
381
{
G4Exception
(
"GrRunManager::SetRandomNumberStoreDir"
,
382
"Run0072"
,
JustWarning
,
383
"Random number status is not available for this event."
); }
384
return
randomNumberStatusForThisEvent
;
385
}
386
387
public
:
// with description
388
inline
void
GeometryHasBeenModified
()
389
{
kernel
->
GeometryHasBeenModified
(); }
390
// This method must be invoked (or equivalent UI command can be used)
391
// in case the user changes his/her detector geometry after
392
// Initialize() metho has been invoked. Then, at the begining of the next BeamOn(),
393
// all necessary re-initialization will be done.
394
395
inline
void
PhysicsHasBeenModified
()
396
{
kernel
->
PhysicsHasBeenModified
(); }
397
// This method must be invoked (or equivalent UI command can be used)
398
// in case the user changes his/her physics process(es), e.g. (in)activate
399
// some processes. Once this method is invoked, regardless of cuts are
400
// changed or not, BuildPhysicsTable() of PhysicsList is invoked for
401
// refreshing all physics tables.
402
403
inline
void
CutOffHasBeenModified
()
404
{
405
G4cerr
<<
"CutOffHasBeenModified becomes obsolete."
<<
G4endl
;
406
G4cerr
<<
"It is safe to remove invoking this method."
<<
G4endl
;
407
}
408
409
public
:
// with description
410
void
ReOptimizeMotherOf
(
G4VPhysicalVolume
*);
411
// This method may be used if the orientation and/or size of this
412
// particular physical volume has been modified while rest of the
413
// geometries in the world has not been changed. This avoids the
414
// full re-optimization of the entire geometry tree which is forced
415
// if GeometryHasBeenModified() method is invoked.
416
417
void
ReOptimize
(
G4LogicalVolume
*);
418
// Same as above, but the mother logical volume is specified.
419
420
public
:
421
inline
void
SetVerboseLevel
(
G4int
vl)
422
{
verboseLevel
= vl;
423
kernel
->
SetVerboseLevel
(vl); }
424
inline
G4int
GetVerboseLevel
()
const
425
{
return
verboseLevel
; }
426
427
inline
void
SetGeometryToBeOptimized
(
G4bool
vl)
428
{
429
if
(
geometryToBeOptimized
!= vl)
430
{
431
geometryToBeOptimized
= vl;
432
kernel
->
GeometryHasBeenModified
();
433
kernel
->
SetGeometryToBeOptimized
(vl);
434
}
435
}
436
inline
G4bool
GetGeometryToBeOptimized
()
437
{
return
geometryToBeOptimized
; }
438
439
public
:
// with description
440
inline
void
SetNumberOfEventsToBeStored
(
G4int
val)
441
{
n_perviousEventsToBeStored
= val; }
442
// Sets the number of events to be kept after processing. That is, "val" previous
443
// events can be used with the most recent event for digitizing pileup. "val"+1
444
// previous event is deleted.
445
// This method must be invoked before starting the event loop.
446
inline
const
G4Run
*
GetCurrentRun
()
const
447
{
return
currentRun
; }
448
// Returns the pointer to the current run. This method is available for Geant4
449
// states of GeomClosed and EventProc.
450
inline
const
G4Event
*
GetCurrentEvent
()
const
451
{
return
currentEvent
; }
452
// Returns the pointer to the current event. This method is available for EventProc
453
// state.
454
inline
const
G4Event
*
GetPreviousEvent
(
G4int
i)
const
455
{
456
if
(i>=1 && i<=
n_perviousEventsToBeStored
)
457
{
return
(*
previousEvents
)[i-1]; }
458
return
0;
459
}
460
// Returns the pointer to the "i" previous event. This method is availavle for
461
// EventProc state. In case the event loop has not yet to reach to the requested
462
// event, null will be returned. To use this method, SetNumberOfEventsToBeStored()
463
// method mentioned above must be invoked previously to the event loop.
464
inline
void
SetRunIDCounter
(
G4int
i)
465
{
runIDCounter
= i; }
466
// Set the run number counter. Initially, the counter is initialized to zero and
467
// incremented by one for every BeamOn().
468
469
public
:
470
inline
G4int
GetNumberOfParallelWorld
()
const
471
{
return
nParallelWorlds
; }
472
inline
void
SetNumberOfEventsToBeProcessed
(
G4int
val)
473
{
numberOfEventToBeProcessed
= val; }
474
inline
void
SetDCtable
(
G4DCtable
* DCtbl)
475
{
DCtable
= DCtbl; }
476
477
public
:
478
void
ConstructScoringWorlds
();
479
protected
:
480
void
UpdateScoring
();
481
};
482
483
#endif
484
Generated on Sat May 25 2013 14:34:11 for Geant4 by
1.8.4