10#include "G4EventManager.hh"
11#include "G4GDMLParser.hh"
12#include "G4TrackingManager.hh"
13#include "G4PhysicalVolumeStore.hh"
14#include "G4GeometryManager.hh"
41 if(!m_simplifiedGeoPath.empty()) {
43 if (geoFile.empty()) {
44 ATH_MSG_FATAL(
"Could not find simplified geometry file: " << m_simplifiedGeoPath);
45 return StatusCode::FAILURE;
48 parser.Read(geoFile,
false);
53 ATH_MSG_INFO(
"- Using ISF TruthRecordSvc : " << m_truthRecordSvc.typeAndName());
55 ATH_MSG_INFO(
"- Using ISF GeoIDSvc : " << m_geoIDSvc.typeAndName());
63 ATH_MSG_INFO(
"Waiting on G4RunTool to be ready for run");
67 m_g4RunTool->WaitBeginRun();
77 ATH_CHECK(m_inputTruthCollectionKey.initialize());
78 ATH_CHECK(m_outputTruthCollectionKey.initialize());
82 if (!m_truthPreselectionTool.empty()) {
83 ATH_CHECK(m_truthPreselectionTool.retrieve());
86 if (!m_qspatcher.empty()) {
91 return StatusCode::SUCCESS;
98 static std::atomic<unsigned int> n_Event=0;
103 if (n_Event<=10 || (n_Event%100) == 0) {
113 catch(
const std::exception& e) {
114 ATH_MSG_ERROR(
"Failure in G4RunAlg::releaseGeoModel: " << e.what());
115 return StatusCode::FAILURE;
125 if (!inputTruthCollection.
isValid()) {
126 ATH_MSG_FATAL(
"Unable to read input GenEvent collection " << inputTruthCollection.
name() <<
" in store " << inputTruthCollection.
store());
127 return StatusCode::FAILURE;
129 ATH_MSG_DEBUG(
"Found input GenEvent collection " << inputTruthCollection.
name() <<
" in store " << inputTruthCollection.
store());
132 std::unique_ptr<McEventCollection> shadowTruth{};
134 outputTruthCollection = std::make_unique<McEventCollection>();
136 shadowTruth = std::make_unique<McEventCollection>(*inputTruthCollection);
144 outputTruthCollection->push_back(outputEvent.release());
149 outputTruthCollection = std::make_unique<McEventCollection>(*inputTruthCollection);
151 shadowTruth = std::make_unique<McEventCollection>();
160 ATH_MSG_DEBUG(
"Recorded output GenEvent collection " << outputTruthCollection.
name() <<
" in store " << outputTruthCollection.
store());
162 const int largestGeneratedParticleBC = (outputTruthCollection->empty()) ?
HepMC::UNDEFINED_ID
164 const int largestGeneratedVertexBC = (outputTruthCollection->empty()) ?
HepMC::UNDEFINED_ID
169 auto prepare_event = [
this, &outputTruthCollection, &shadowTruth, largestGeneratedParticleBC, largestGeneratedVertexBC](G4Event& event, std::unique_ptr<AtlasG4SyncEventUserInfo> g4eventInfo) -> StatusCode {
172 event.SetEventID(g4eventInfo->AthenaEventID());
173 event.SetUserInformation(g4eventInfo.release());
175 *outputTruthCollection, event, *shadowTruth));
176 return StatusCode::SUCCESS;
179 auto eventInfo = std::make_unique<AtlasG4SyncEventUserInfo>(rngWrapper->
getEngine(ctx), std::move(prepare_event), ctx);
182 std::shared_ptr<HitCollectionMap> hitCollections = eventInfo->GetHitCollectionMap();
188 auto syncInterface = eventInfo->SyncInterface();
190 ATH_MSG_DEBUG(
"Pushing Athena event " << ctx.eventID().event_number() <<
" onto event buffer");
194 syncInterface->WaitStatusDone();
196 if (syncInterface->EventAborted()) {
207 "Failed to retrieve xAOD::EventInfo while trying to update the "
209 return StatusCode::FAILURE;
231 return StatusCode::SUCCESS;
238 SmartIF<IGeoModelSvc> geoModel{Gaudi::svcLocator()->service(
"GeoModelSvc")};
243 if (geoModel->clear().isFailure()) {
247 ATH_MSG_INFO(
" ----> GeoModelSvc::clear() succeeded " );
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ALWAYS(x)
#define ATH_MSG_WARNING(x)
static std::once_flag releaseGeoModelOnceFlag
StatusCode G4RunAlg::initialize ATLAS_NOT_THREAD_SAFE()
Install fatal handler with default options.
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
A wrapper class for event-slot-local random engines.
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
virtual void setFilterPassed(bool state, const EventContext &ctx) const
Gaudi::Property< bool > m_releaseGeoModel
ToolHandle< ISF::IGenEventFilter > m_truthPreselectionTool
Tool for filtering out quasi-stable particle daughters.
ServiceHandle< Simulation::IZeroLifetimePatcher > m_qspatcher
Quasi-Stable Particle Simulation Patcher.
ServiceHandle< IAthRNGSvc > m_rndmGenSvc
Random number service.
PublicToolHandle< IG4RunTool > m_g4RunTool
G4Atlas Tool for thread management and data interface.
void releaseGeoModel()
Releases the GeoModel geometry from memory once it has been used to build the G4 geometry and is no-l...
Gaudi::Property< bool > m_useShadowEvent
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
PublicToolHandle< ISensitiveDetectorMasterTool > m_senDetTool
Sensitive Detector Master Tool.
ServiceHandle< G4UA::IUserActionSvc > m_userActionSvc
User Action Service.
ServiceHandle< ISF::ITruthSvc > m_truthRecordSvc
Central Truth Service.
virtual StatusCode execute(const EventContext &ctx) override
Simulate one Athena event.
Gaudi::Property< bool > m_killAbortedEvents
Gaudi::Property< std::string > m_randomStreamName
PublicToolHandle< IFastSimulationMasterTool > m_fastSimTool
Fast Simulation Master Tool.
SG::WriteHandleKey< McEventCollection > m_outputTruthCollectionKey
ServiceHandle< ISF::IInputConverter > m_inputConverter
Service to convert ISF_Particles into a G4Event.
SG::ReadHandleKey< McEventCollection > m_inputTruthCollectionKey
Gaudi::Property< bool > m_flagAbortedEvents
virtual bool isValid() override final
Can the handle be successfully dereferenced?
std::string store() const
Return the name of the store holding the object we are proxying.
const std::string & name() const
Return the StoreGate ID for the referenced object.
Singleton class for creating truth incidents.
void SetISFGeoIDSvc(ISF::IGeoIDSvc *geoIDSvc)
Define which ISF GeoIDSvc to use.
void SetISFTruthSvc(ISF::ITruthSvc *truthSvc)
Define which ISF TruthService to use.
@ Core
Core flags describing the event.
@ Error
The sub-detector issued an error.
int maxGeneratedVertexBarcode(const HepMC::GenEvent *genEvent)
Get the maximal absolute value of barcode of vertex present in the event. Returns a negative number.
constexpr int UNDEFINED_ID
int maxGeneratedParticleBarcode(const HepMC::GenEvent *genEvent)
Get the maximal value of barcode of particle present in the event.
HepMC3::GenEvent GenEvent