GGS(GenericGEANT4Simulation)Software  2.7.0
 All Data Structures Namespaces Files Functions Variables Typedefs Macros
Public Member Functions | Static Public Member Functions
GGSRunManager Class Reference

A run manager for GGS simulations. More...

#include <GGSRunManager.h>

Inheritance diagram for GGSRunManager:
Inheritance graph
[legend]
Collaboration diagram for GGSRunManager:
Collaboration graph
[legend]

Public Member Functions

 GGSRunManager ()
 Constructor.
 
 ~GGSRunManager ()
 Destructor.
 
void DoEventLoop (G4int n_event, const char *macroFile, G4int n_select)
 Override of G4RunManager::DoEventLoop. More...
 
void SetGGSGeneratorAction (G4VUserPrimaryGeneratorAction *userAction)
 Replacement of the SetUserAction method. More...
 
void PrintLogVols ()
 Print a list of logical volumes in current geometries.
 
int GetNDiscardedEvents ()
 Getter method for number of discarded events. More...
 
int GetNKilledEvents ()
 Getter method for number of killed events. More...
 
void KillEvent ()
 Kills the current event. More...
 
void SimulateAgainKilledEvent ()
 Simulates again a killed event. More...
 
bool IsCurrentEventKilled ()
 Getter method for killed event flag. More...
 
const long int * GetRandomSeedsAtBeginOfEvent ()
 Getter methos for random seeds at the beginning of the current event. More...
 

Static Public Member Functions

static GGSRunManagerGetRunManager ()
 Static getter function the run manager. More...
 

Detailed Description

A run manager for GGS simulations.

This class inherits from G4RunManager and adds some GGS-specific features.

Definition at line 23 of file GGSRunManager.h.

Member Function Documentation

void GGSRunManager::DoEventLoop ( G4int  n_event,
const char *  macroFile,
G4int  n_select 
)

Override of G4RunManager::DoEventLoop.

This override adds the possibility of re-generate and re-simulate a killed event when the killer routine calls #RedoKilled. No other change is made with respect to G4RunManager::DoEventLoop.

Parameters
n_event
macroFile
n_select

Definition at line 53 of file GGSRunManager.cpp.

53  {
54  static const std::string routineName("GGSRunManager::DoEventLoop");
55  InitializeEventLoop(n_event, macroFile, n_select);
56  _isCurrEvKilled = false;
57  _simAgainKilledEv = false;
58  _nKilledEvs = 0;
59 
60  // Event loop
61  for (G4int i_event = 0; i_event < n_event; i_event++) {
62  // Store random seeds at begin of event
63  _currEvSeeds[0] = CLHEP::HepRandom::getTheSeeds()[0];
64  _currEvSeeds[1] = CLHEP::HepRandom::getTheSeeds()[1];
65 
66  ProcessOneEvent(i_event);
67  TerminateOneEvent();
68  if (runAborted)
69  break;
70 
71  // Check if the event has been killed
72  if (_isCurrEvKilled) {
73  COUT(DEEPDEB) << "Event " << i_event << " has been killed. " << ENDL;
74  if (_ggsGeneratorAction) {
75  CCOUT(DEEPDEB) << "Discarded at generation: " << _ggsGeneratorAction->GetNDiscarded()
76  << " (total: " << _nDiscardedEvsInKilledEvs << ")" << ENDL;
77  }
78  if (_simAgainKilledEv) {
79  i_event--;
80  CCOUT(DEEPDEB) << "Will be simulated again." << ENDL;
81  }
82  } else {
83  COUT(DEEPDEB) << "Finished simulating event " << i_event << ENDL;
84  if (_ggsGeneratorAction) {
85  CCOUT(DEEPDEB) << "Discarded at generation: " << _ggsGeneratorAction->GetNDiscarded()
86  << " (total: " << GetNDiscardedEvents() << ")" << ENDL;
87  }
88  CCOUT(DEEPDEB) << "Killed: " << _nKilledEvs << ENDL;
89  // Reset discarded and killed event counters
90  _nDiscardedEvsInKilledEvs = 0;
91  _nKilledEvs = 0;
92  if (_simAgainKilledEv) {
93  static bool printDone = false;
94  if (!printDone) {
95  COUT(WARNING) << "Request to re-simulate an event which has not been flagged as killed. Ignoring." << ENDL;
96  CCOUT(WARNING) << "This message will be printed only once." << ENDL;
97  printDone = true;
98  }
99  }
100  }
101  _isCurrEvKilled = false;
102  _simAgainKilledEv = false;
103  }
104 
105  TerminateEventLoop();
106 }
#define ENDL
Definition: GGSSmartLog.h:105
#define COUT(level)
Smart log macro. It writes on stdout only if the specified verbosity level is lesser than the maximum...
Definition: GGSSmartLog.h:76
#define CCOUT(level)
Smart log utility which prints no header at the beginning of the line.
Definition: GGSSmartLog.h:100
int GetNDiscardedEvents()
Getter method for number of discarded events.
Definition: GGSRunManager.h:85
unsigned int GetNDiscarded() const
Returns the number of discarded events for the current event generation.
int GGSRunManager::GetNDiscardedEvents ( )
inline

Getter method for number of discarded events.

This method returns the number of discarded events. Discarded events are events which are generated but not simulated because they do not fulfill the acceptance criterion defined by the geometry. The counter is reset every time an event is successfully generated inside acceptance and simulated (i.e. not killed). This method will always return 0 if the particle generator does not inherit from GGSGeneratorAction.

Returns
The number of discarded events since the last simulated one.

Definition at line 85 of file GGSRunManager.h.

85  {
86  if (_ggsGeneratorAction)
87  return _nDiscardedEvsInKilledEvs + _ggsGeneratorAction->GetNDiscarded();
88  return 0;
89  }
unsigned int GetNDiscarded() const
Returns the number of discarded events for the current event generation.
int GGSRunManager::GetNKilledEvents ( )
inline

Getter method for number of killed events.

This method returns the number of killed events since the last non-killed one.

Returns
The number of killed events since the last non-killed one.

Definition at line 98 of file GGSRunManager.h.

98 { return _nKilledEvs; }
const long int* GGSRunManager::GetRandomSeedsAtBeginOfEvent ( )
inline

Getter methos for random seeds at the beginning of the current event.

Returns
a long int array with the two seeds;

Definition at line 135 of file GGSRunManager.h.

135 { return _currEvSeeds; }
GGSRunManager * GGSRunManager::GetRunManager ( )
static

Static getter function the run manager.

Returns
Pointer to the GGS run manager.

Definition at line 22 of file GGSRunManager.cpp.

22  {
23  if (!_runManager) {
24  G4Exception("GGSRunManager::GetRunManager()", "GGS", FatalException, "GGSRunManager not yet constructed.");
25  }
26  return _runManager;
27 }
bool GGSRunManager::IsCurrentEventKilled ( )

Getter method for killed event flag.

This method returns true if SetEventAsKilled has been called during current event.

Returns
true if the current event has been killed

Definition at line 140 of file GGSRunManager.cpp.

140 { return _isCurrEvKilled; }
void GGSRunManager::KillEvent ( )

Kills the current event.

This method can be called by user actions to kill an event. The difference between this method and G4EventManager::AbortCurrentEvent is that calling KillEvent and then SimulateAgainKilledEvent it is possible to simulate a new event without increasing the number of simulated events. In other words, when using KillEvent and SimulateAgainKilledEvent killed events won't contribute to the count of total simulated events.

See Also
SimulateAgainKilledEvent
GetNKilledEvents

Definition at line 122 of file GGSRunManager.cpp.

122  {
123  static const std::string routineName("GGSRunManager::KillEvent");
124  if (!_isCurrEvKilled) {
125  COUT(DEEPDEB) << "Kill event" << std::endl;
126  G4EventManager::GetEventManager()->AbortCurrentEvent();
127  _isCurrEvKilled = true;
128  _nKilledEvs++;
129  if (_ggsGeneratorAction)
130  _nDiscardedEvsInKilledEvs += _ggsGeneratorAction->GetNDiscarded();
131  }
132 }
#define COUT(level)
Smart log macro. It writes on stdout only if the specified verbosity level is lesser than the maximum...
Definition: GGSSmartLog.h:76
unsigned int GetNDiscarded() const
Returns the number of discarded events for the current event generation.
void GGSRunManager::SetGGSGeneratorAction ( G4VUserPrimaryGeneratorAction *  userAction)
inline

Replacement of the SetUserAction method.

This version checks whether the generator action inherits from GGSGeneratorAction and then registers it in the parent G4RunManager. The GGSGeneratorAction can then be retrieved by means of the GetGGSGeneratorAction method.

Note: use this method to register a generator action inheriting from GGSGeneratorAction (instead of the standard SetUserAction method) to take advantage of the mechanism to avoid dynamic_cast described in GetGGSGeneratorAction; that mechanism will not work if SetUserAction is used to register the generator action in the run manager, but all other functionalities will not be affected.

Parameters
userActionThe user defined primary generator action.

Definition at line 65 of file GGSRunManager.h.

65  {
66  _ggsGeneratorAction = dynamic_cast<GGSGeneratorAction *>(userAction);
67  G4RunManager::SetUserAction(userAction);
68  }
Base class for GGS generator actions.
void GGSRunManager::SimulateAgainKilledEvent ( )

Simulates again a killed event.

This method must be called by user actions after killing an event if the killed event has to be re-generated and re-simulated. The method #SetEventAsKilled must be called before, in order to enable re-generation and simulation, otherwise a warning message is displayed and the event is not re-generated and simulated.

Definition at line 136 of file GGSRunManager.cpp.

136 { _simAgainKilledEv = true; }

The documentation for this class was generated from the following files: