ATLAS Offline Software
Loading...
Searching...
No Matches
SyncPrimaryGeneratorAction.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include "GaudiKernel/StatusCode.h"
7
9
10#include "G4RunManager.hh"
11#include "G4Event.hh"
12#include "G4SystemOfUnits.hh"
13#include "Randomize.hh"
14
15namespace G4UA
16{
17
19 : G4VUserPrimaryGeneratorAction(), m_g4RunTool(g4RunTool)
20{
21}
22
24{
25 // get an event from the shared queue
26 if(auto inputEventInfo = m_g4RunTool->GetEvent()) {
27 // setup rng engine seeded by Athena
28 G4Random::setTheEngine(inputEventInfo->HepRandomEngine());
29 // convert Genevent to G4Event
30 if(inputEventInfo->EventFactory()(*anEvent, std::move(inputEventInfo)).isFailure()) {
31 G4cout << "Failed to prepare G4Event from Athena event" << G4endl;
32 }
33 }
34 // if get_Event returns nullptr, this means that no more events are available and the run should be aborted.
35 // Because Geant4 will still go through and finish the current event after calling AbortRun,
36 // and it reset the G4Event::Aborted flag after GeneratePrimaries, abortRun must be called in the BeginOfEventAction
37}
38
39} // namespace G4UA
virtual void GeneratePrimaries(G4Event *) override
Provides an interface to interact with the Geant4 run.
Definition IG4RunTool.h:22