Install fatal handler with default options.
This is meant to be easy to call from python via ctypes.
103{
104
106
107 if (m_g4RunManagerHelper.retrieve().isFailure()) {
108 throw std::runtime_error("Could not initialize G4RunManagerHelper!");
109 }
111 m_pRunMgr = m_g4RunManagerHelper ? m_g4RunManagerHelper->g4RunManager() : nullptr;
112 if (!m_pRunMgr) {
113 throw std::runtime_error("G4RunManagerHelper::g4RunManager() returned nullptr.");
114 }
115
116 if(m_physListSvc.retrieve().isFailure()) {
117 throw std::runtime_error("Could not initialize ATLAS PhysicsListSvc!");
118 }
119 m_physListSvc->SetPhysicsList();
120 ATH_MSG_INFO(
"retireving the Detector Construction tool" );
121 if(m_detConstruction.retrieve().isFailure()) {
122 throw std::runtime_error("Could not initialize ATLAS DetectorConstruction!");
123 }
124
125 m_pRunMgr->SetRecordFlux( m_recordFlux, std::make_unique<ISFFluxRecorder>() );
126 m_pRunMgr->SetLogLevel(
int(
msg().
level()) );
127 m_pRunMgr->SetDetConstructionTool( m_detConstruction.get() );
128 m_pRunMgr->SetPhysListSvc(m_physListSvc.typeAndName() );
129 m_pRunMgr->SetQuietMode( m_quietMode );
130 std::unique_ptr<G4AtlasActionInitialization> actionInitialization =
131 std::make_unique<G4AtlasActionInitialization>(&*m_userActionSvc);
132 m_pRunMgr->SetUserInitialization(actionInitialization.release());
133
134 G4UImanager *ui = G4UImanager::GetUIpointer();
135
136 if (!m_libList.empty()) {
137 ATH_MSG_INFO(
"G4AtlasAlg specific libraries requested ") ;
138 std::string temp="/load "+m_libList;
139 ui->ApplyCommand(temp);
140 }
141
142 if (!m_physList.empty()) {
143 ATH_MSG_INFO(
"requesting a specific physics list "<< m_physList) ;
144 std::string temp="/Physics/GetPhysicsList "+m_physList;
145 ui->ApplyCommand(temp);
146 }
147
148 if (!m_fieldMap.empty()) {
149 ATH_MSG_INFO(
"requesting a specific field map "<< m_fieldMap) ;
150 ATH_MSG_INFO(
"the field is initialized straight away") ;
151 std::string temp="/MagneticField/Select "+m_fieldMap;
152 ui->ApplyCommand(temp);
153 ui->ApplyCommand("/MagneticField/Initialize");
154 }
155
156
157 ATH_MSG_DEBUG(
"G4 Command: Trying at the end of initializeOnce()");
158 for (const auto& g4command : m_g4commands) {
159 int returnCode = ui->ApplyCommand( g4command );
160 commandLog(returnCode, g4command);
161 }
162
163
164 auto* rm = G4RunManager::GetRunManager();
165 if(!rm) {
166 throw std::runtime_error("Run manager retrieval has failed");
167 }
168 rm->Initialize();
169
170 if(!m_useMT && rm->ConfirmBeamOnCondition()) {
171 rm->RunInitialization();
172 }
173
174 ATH_MSG_INFO(
"Initializing " << m_physicsInitializationTools.size() <<
" physics initialization tools");
175 for(auto& physicsTool : m_physicsInitializationTools) {
176 if (physicsTool->initializePhysics().isFailure()) {
177 throw std::runtime_error("Failed to initialize physics with tool " + physicsTool.name());
178 }
179 }
180
181 if(m_userLimitsSvc.retrieve().isFailure()) {
182 throw std::runtime_error("Could not initialize ATLAS UserLimitsSvc!");
183 }
184
185 if (m_activateParallelGeometries) {
186 G4VModularPhysicsList* thePhysicsList=dynamic_cast<G4VModularPhysicsList*>(m_physListSvc->GetPhysicsList());
187 if (!thePhysicsList) {
188 throw std::runtime_error("Failed dynamic_cast!! this is not a G4VModularPhysicsList!");
189 }
190#if G4VERSION_NUMBER >= 1010
191 std::vector<std::string>& parallelWorldNames=m_detConstruction->GetParallelWorldNames();
192 for (auto& it: parallelWorldNames) {
193 thePhysicsList->RegisterPhysics(new G4ParallelWorldPhysics(it,true));
194 }
195#endif
196 }
197
198 return;
199}