SLIC  6.1.1
Simulation for the Linear Collider (SLIC) - Geant4 simulation application
RunManager.cc
Go to the documentation of this file.
1 // SLIC
2 #include "RunManager.hh"
3 #include "EventAction.hh"
4 #include "EventSourceManager.hh"
5 #include "ModuleRegistry.hh"
6 #include "PhysicsListManager.hh"
8 #include "RunAction.hh"
9 #include "SlicApplication.hh"
10 #include "StackingAction.hh"
11 #include "SteppingAction.hh"
12 #include "TrackingAction.hh"
13 #include "PluginMessenger.hh"
14 
15 // LCDD
16 #include "lcdd/core/LCDDParser.hh"
17 #include "lcdd/core/LCDDProcessor.hh"
18 
19 // Geant4
20 #include "G4StateManager.hh"
21 #include "G4UImanager.hh"
22 
23 namespace slic {
24 
26  Module("RunManager", false), m_abortRun(false) {
27 }
28 
30  delete m_pluginManager;
31 }
32 
34 
35  // Init physics list.
36  G4VUserPhysicsList* list = PhysicsListManager::instance()->createPhysicsList();
37  G4RunManager::GetRunManager()->SetUserInitialization(list);
38 
39  // This makes sure that physics initialization occurs before other user actions.
40  G4RunManager::Initialize();
41 
44 
46  RunAction* runAction = new RunAction;
47  EventAction* eventAction = new EventAction;
48  TrackingAction* trackingAction = new TrackingAction;
49  SteppingAction* steppingAction = new SteppingAction;
50  StackingAction* stackingAction = new StackingAction;
51 
54  eventAction->setPluginManager(m_pluginManager);
55  trackingAction->setPluginManager(m_pluginManager);
56  steppingAction->setPluginManager(m_pluginManager);
57  stackingAction->setPluginManager(m_pluginManager);
58 
59  SetUserAction(genAction);
60  SetUserAction(runAction);
61  SetUserAction(eventAction);
62  SetUserAction(trackingAction);
63  SetUserAction(steppingAction);
64  SetUserAction(stackingAction);
65 
66  // Initialize the event generation manager.
68 
69  // Setup the default event source.
70  EventSourceManager::instance()->setupEventSource();
71 
72  // Print list of registered modules.
73 #ifdef SLIC_LOG
74  ModuleRegistry::instance()->print();
75 #endif
76 }
77 
79 
80  // Call the G4RunManager's intitialization method.
81  G4RunManager::InitializePhysics();
82 
83  // Check if the LCDD subsystem got some limits.
84  LCDDProcessor* lcdd = LCDDProcessor::instance();
86  if (lcdd->getLimitSetsBegin() != lcdd->getLimitSetsEnd()) {
87  std::cout << "enabling phys limits" << std::endl;
88  pmgr->enableLimits(true);
89  }
90 
91  // Enable physics limits, if necessary.
92  if (pmgr->enableLimits()) {
93  std::cout << "setting up user limits processes" << std::endl;
95  }
96 
97  // Print out particle table.
98  //G4ParticleTable::GetParticleTable()->DumpTable();
99 }
100 
102  // Was a valid LCDD setup given?
103  if (!LCDDParser::instance()->isValidSetup()) {
104  // Abort the run as the LCDD URL was probably not set.
106  this->abortRun();
107  } else {
108  // Initialize the geometry.
109  G4RunManager::InitializeGeometry();
110  }
111 }
112 
113 void RunManager::BeamOn(G4int n_event, const char* macroFile, G4int n_select) {
114 
115  // Reset abort run flag.
116  m_abortRun = false;
117 
118  // Attempt to initialize Geant4 if not in idle state.
119  if (G4StateManager::GetStateManager()->GetCurrentState() != G4State_Idle) {
120  this->Initialize();
121  }
122 
123  // Check if a generator was setup.
124  if (EventSourceManager::instance()->getCurrentSource() == 0) {
125  log() << LOG::fatal << "No event generator was setup." << LOG::done;
127  }
128 
129  // Check if run should be aborted due to initialization errors.
130  if (!this->isRunAborted()) {
131 
132  // Run number of events that were requested.
133  m_numberOfEventsToRun = n_event;
134  G4RunManager::BeamOn(n_event, macroFile, n_select);
135 
136  // Print number of events that were actually generated.
138  eventManager->printNumEventsGenerated();
139 
140  // Check if event underflow occurred where number of events provided was less than requested.
141  int nEventsGenerated = eventManager->getNumEventsGenerated();
142  if (nEventsGenerated < m_numberOfEventsToRun) {
143  log() << LOG::warning << LOG::head << "Generated " << nEventsGenerated << " events but " << n_event << " were requested." << LOG::done;
144  // Set event underflow error but do not override an existing return code.
145  if (SlicApplication::instance()->getReturnCode() == SlicApplication::OKAY) {
147  }
148  }
149  } else {
150  log() << LOG::warning << LOG::head << "Run was aborted before G4 event loop was executed." << LOG::done;
151  }
152 }
153 
155  return m_numberOfEventsToRun;
156 }
157 
159  return m_abortRun;
160 }
161 } // namespace slic
162 
static PhysicsListManager * instance()
Implementation of G4UserEventAction.
Definition: EventAction.hh:25
This singleton is responsible for managing physics event sources.
Base class for slic code modules that provides common functionality, such as logging to an output str...
Definition: Module.hh:25
LogStream & log()
Definition: Module.hh:99
Provides management of user physics lists.
void enableLimits(bool enableLimits)
void setPluginManager(PluginManager *pluginManager)
Manages user sim plugins.
Messenger class for loading and destroying user sim plugins using macro commands.
Implementation of G4VUserPrimaryGeneratorAction.
Implementation of G4UserRunAction.
Definition: RunAction.hh:18
virtual ~RunManager()
Definition: RunManager.cc:29
void InitializeGeometry()
Definition: RunManager.cc:101
PluginManager * m_pluginManager
Definition: RunManager.hh:109
void InitializePhysics()
Definition: RunManager.cc:78
void BeamOn(G4int nevent, const char *macroFile=0, G4int nselect=-1)
Definition: RunManager.cc:113
int getNumberOfEventsToRun()
Definition: RunManager.cc:154
Implemention of Geant4's G4UserStackingAction.
Implementation of G4UserSteppingAction.
Implementation of G4UserTrackingAction.
@ fatal
Definition: LogStream.hh:33
@ warning
Definition: LogStream.hh:33
@ head
Definition: LogStream.hh:26
@ endl
Definition: LogStream.hh:26
@ done
Definition: LogStream.hh:26