8#include "GaudiKernel/ServiceHandle.h"
11#include "G4MTRunManager.hh"
12#include "G4StateManager.hh"
13#include "G4UImanager.hh"
14#include "G4GeometryManager.hh"
15#include "G4PhysicalVolumeStore.hh"
16#include "G4EventManager.hh"
37 ATH_MSG_DEBUG(
"Geant4main thread created, id=" <<
m_thread->get_id() <<
", now waiting for G4 run manager");
38 return StatusCode::SUCCESS;
55 catch(
const std::exception& e) {
56 ATH_MSG_ERROR(
"Failure in G4RunTool::finalize, joining Geant4 main thread:" << e.what());
60 return StatusCode::SUCCESS;
87 m_cv.wait(lk, [
this, status]{
return m_status == status; });
126 ATH_MSG_INFO(
"Geant4 main thread starts with id " << std::this_thread::get_id());
129 auto runManager = std::make_unique<G4MTRunManager>();
132 constexpr int seedFirstEventOnly = 1;
134 runManager->SetSeedOncePerCommunication(seedFirstEventOnly);
158 ATH_MSG_INFO(
"retrieving action tool " + action_tool.name());
160 throw std::runtime_error(
"Failed to add action tool " + action_tool.name());
168 runManager->SetUserInitialization(
m_detConstruction->GetDetectorConstruction().release());
173 runManager->SetUserInitialization(std::make_unique<G4AtlasActionInitialization>(
m_userActionSvc.get()).release());
176 G4UImanager *ui = G4UImanager::GetUIpointer();
180 ATH_MSG_INFO(
"G4AtlasAlg specific libraries requested ");
182 ui->ApplyCommand(temp);
187 std::string temp=
"/Physics/GetPhysicsList "+
m_physList;
188 ui->ApplyCommand(temp);
194 std::string temp=
"/MagneticField/Select "+
m_fieldMap;
195 ui->ApplyCommand(temp);
196 ui->ApplyCommand(
"/MagneticField/Initialize");
200 ATH_MSG_DEBUG(
"G4 Command: Trying at the end of initializeOnce()");
202 int returnCode = ui->ApplyCommand( g4command );
207 runManager->Initialize();
213 if (physicsTool->initializePhysics().isFailure()) {
214 throw std::runtime_error(
"Failed to initialize physics with tool " + physicsTool.name());
219 throw std::runtime_error(
"Could not initialize ATLAS UserLimitsSvc!");
230 G4GeometryManager::GetInstance()->OpenGeometry();
231 G4PhysicalVolumeStore::GetInstance()->Clean();
238 case 0: {
ATH_MSG_DEBUG(
"G4 Command: " << commandString <<
" - Command Succeeded"); }
break;
239 case 100: {
ATH_MSG_ERROR(
"G4 Command: " << commandString <<
" - Command Not Found!"); }
break;
241 auto* stateManager = G4StateManager::GetStateManager();
242 ATH_MSG_DEBUG(
"G4 Command: " << commandString <<
" - Illegal Application State (" <<
243 stateManager->GetStateString(stateManager->GetCurrentState()) <<
")!");
245 case 300: {
ATH_MSG_ERROR(
"G4 Command: " << commandString <<
" - Parameter Out of Range!"); }
break;
246 case 400: {
ATH_MSG_ERROR(
"G4 Command: " << commandString <<
" - Parameter Unreadable!"); }
break;
247 case 500: {
ATH_MSG_ERROR(
"G4 Command: " << commandString <<
" - Parameter Out of Candidates!"); }
break;
248 case 600: {
ATH_MSG_ERROR(
"G4 Command: " << commandString <<
" - Alias Not Found!"); }
break;
249 default: {
ATH_MSG_ERROR(
"G4 Command: " << commandString <<
" - Unknown Status!"); }
break;