9#include "GaudiKernel/ServiceHandle.h"
12#include "G4MTRunManager.hh"
13#include "G4StateManager.hh"
14#include "G4UImanager.hh"
15#include "G4GeometryManager.hh"
16#include "G4PhysicalVolumeStore.hh"
17#include "G4EventManager.hh"
38 ATH_MSG_DEBUG(
"Geant4main thread created, id=" <<
m_thread->get_id() <<
", now waiting for G4 run manager");
39 return StatusCode::SUCCESS;
56 catch(
const std::exception& e) {
57 ATH_MSG_ERROR(
"Failure in G4RunTool::finalize, joining Geant4 main thread:" << e.what());
61 return StatusCode::SUCCESS;
88 m_cv.wait(lk, [
this, status]{
return m_status == status; });
127 ATH_MSG_INFO(
"Geant4 main thread starts with id " << std::this_thread::get_id());
130 auto runManager = std::make_unique<G4MTRunManager>();
133 constexpr int seedFirstEventOnly = 1;
135 runManager->SetSeedOncePerCommunication(seedFirstEventOnly);
159 ATH_MSG_INFO(
"retrieving action tool " + action_tool.name());
161 throw std::runtime_error(
"Failed to add action tool " + action_tool.name());
169 runManager->SetUserInitialization(
m_detConstruction->GetDetectorConstruction().release());
178 runManager->SetUserInitialization(
179 std::make_unique<G4RunToolWorkerThreadInitialization>().
release());
180 runManager->SetUserInitialization(
181 std::make_unique<G4AtlasActionInitialization>(
m_userActionSvc.get()).release());
184 G4UImanager *ui = G4UImanager::GetUIpointer();
188 ATH_MSG_INFO(
"G4AtlasAlg specific libraries requested ");
190 ui->ApplyCommand(temp);
195 std::string temp=
"/Physics/GetPhysicsList "+
m_physList;
196 ui->ApplyCommand(temp);
202 std::string temp=
"/MagneticField/Select "+
m_fieldMap;
203 ui->ApplyCommand(temp);
204 ui->ApplyCommand(
"/MagneticField/Initialize");
208 ATH_MSG_DEBUG(
"G4 Command: Trying at the end of initializeOnce()");
210 int returnCode = ui->ApplyCommand( g4command );
215 runManager->Initialize();
223 if (physicsTool->initializePhysics().isFailure()) {
224 throw std::runtime_error(
"Failed to initialize physics with tool " + physicsTool.name());
229 throw std::runtime_error(
"Could not initialize ATLAS UserLimitsSvc!");
240 G4GeometryManager::GetInstance()->OpenGeometry();
241 G4PhysicalVolumeStore::GetInstance()->Clean();
248 case 0: {
ATH_MSG_DEBUG(
"G4 Command: " << commandString <<
" - Command Succeeded"); }
break;
249 case 100: {
ATH_MSG_ERROR(
"G4 Command: " << commandString <<
" - Command Not Found!"); }
break;
251 auto* stateManager = G4StateManager::GetStateManager();
252 ATH_MSG_DEBUG(
"G4 Command: " << commandString <<
" - Illegal Application State (" <<
253 stateManager->GetStateString(stateManager->GetCurrentState()) <<
")!");
255 case 300: {
ATH_MSG_ERROR(
"G4 Command: " << commandString <<
" - Parameter Out of Range!"); }
break;
256 case 400: {
ATH_MSG_ERROR(
"G4 Command: " << commandString <<
" - Parameter Unreadable!"); }
break;
257 case 500: {
ATH_MSG_ERROR(
"G4 Command: " << commandString <<
" - Parameter Out of Candidates!"); }
break;
258 case 600: {
ATH_MSG_ERROR(
"G4 Command: " << commandString <<
" - Alias Not Found!"); }
break;
259 default: {
ATH_MSG_ERROR(
"G4 Command: " << commandString <<
" - Unknown Status!"); }
break;
static std::string release