ATLAS Offline Software
G4AtlasSvc.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "G4AtlasSvc.h"
6 #include "GaudiKernel/ServiceHandle.h"
7 
8 // header files from Geant4
9 #include "G4VUserPhysicsList.hh"
10 #include "G4VModularPhysicsList.hh"
11 #include "G4ParallelWorldPhysics.hh"
12 #include "G4RunManager.hh"
13 
14 G4AtlasSvc::G4AtlasSvc( const std::string& name, ISvcLocator* pSvcLocator )
15  : base_class(name,pSvcLocator)
16 {
17 }
18 
20  // go through all tools and retrieve them
21  // This fires initialize() for each of those tools
22 
23  ATH_MSG_DEBUG( "this is G4AtlasSvc::initialize() " );
24  auto* rm = G4RunManager::GetRunManager();
25  if (!rm) {
26  ATH_MSG_ERROR("Run manager retrieval has failed");
27  return StatusCode::FAILURE;
28  }
29  rm->Initialize(); // Initialization differs slightly in multi-threading.
30  // TODO: add more details about why this is here.
31  if (!m_isMT && rm->ConfirmBeamOnCondition()) {
32  rm->RunInitialization();
33  }
34 
35  ATH_CHECK(m_detGeoSvc.retrieve());
36 
37  ATH_CHECK(m_physicsListSvc.retrieve());
38  ATH_CHECK(m_userLimitsSvc.retrieve());
39 
41  G4VModularPhysicsList* thePhysicsList=dynamic_cast<G4VModularPhysicsList*>(m_physicsListSvc->GetPhysicsList());
42  if (!thePhysicsList) {
43  ATH_MSG_FATAL("Failed dynamic_cast!! this is not a G4VModularPhysicsList!");
44  return StatusCode::FAILURE;
45  }
46 #if G4VERSION_NUMBER >= 1010
47  std::vector<std::string>& parallelWorldNames=m_detGeoSvc->GetParallelWorldNames();
48  for (auto& it: parallelWorldNames) {
49  thePhysicsList->RegisterPhysics(new G4ParallelWorldPhysics(it,true));
50  }
51 #endif
52  }
53 
54  return StatusCode::SUCCESS;
55 }
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
G4AtlasSvc::G4AtlasSvc
G4AtlasSvc(const std::string &name, ISvcLocator *pSvcLocator)
Definition: G4AtlasSvc.cxx:14
G4AtlasSvc::m_isMT
Gaudi::Property< bool > m_isMT
Definition: G4AtlasSvc.h:31
G4AtlasSvc::m_detGeoSvc
ServiceHandle< IDetectorGeometrySvc > m_detGeoSvc
Definition: G4AtlasSvc.h:28
skel.it
it
Definition: skel.GENtoEVGEN.py:423
G4AtlasSvc::m_userLimitsSvc
ServiceHandle< IUserLimitsSvc > m_userLimitsSvc
Definition: G4AtlasSvc.h:30
G4AtlasSvc::initialize
StatusCode initialize() override final
Definition: G4AtlasSvc.cxx:19
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
G4AtlasSvc::m_physicsListSvc
ServiceHandle< IPhysicsListSvc > m_physicsListSvc
Definition: G4AtlasSvc.h:29
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
G4AtlasSvc::m_activateParallelGeometries
Gaudi::Property< bool > m_activateParallelGeometries
Definition: G4AtlasSvc.h:32
G4AtlasSvc.h