ATLAS Offline Software
Loading...
Searching...
No Matches
G4UA::SyncPrimaryGeneratorAction Class Reference

#include <SyncPrimaryGeneratorAction.h>

Inheritance diagram for G4UA::SyncPrimaryGeneratorAction:
Collaboration diagram for G4UA::SyncPrimaryGeneratorAction:

Public Member Functions

 SyncPrimaryGeneratorAction (IG4RunTool *)
virtual void GeneratePrimaries (G4Event *) override

Private Attributes

IG4RunToolm_g4RunTool {}

Detailed Description

Definition at line 18 of file SyncPrimaryGeneratorAction.h.

Constructor & Destructor Documentation

◆ SyncPrimaryGeneratorAction()

G4UA::SyncPrimaryGeneratorAction::SyncPrimaryGeneratorAction ( IG4RunTool * g4RunTool)

Definition at line 20 of file SyncPrimaryGeneratorAction.cxx.

21 : G4VUserPrimaryGeneratorAction(), m_g4RunTool(g4RunTool)
22{
23}

Member Function Documentation

◆ GeneratePrimaries()

void G4UA::SyncPrimaryGeneratorAction::GeneratePrimaries ( G4Event * anEvent)
overridevirtual

Definition at line 25 of file SyncPrimaryGeneratorAction.cxx.

26{
27 // get an event from the shared queue
28 if(auto inputEventInfo = m_g4RunTool->GetEvent()) {
29 // setup rng engine seeded by Athena
30 G4Random::setTheEngine(inputEventInfo->HepRandomEngine());
31
32 // Transfer ownership before calling the event factory so that Athena can
33 // still be notified if event preparation fails.
34 auto* eventInfo = inputEventInfo.get();
35 anEvent->SetEventID(eventInfo->AthenaEventID());
36 anEvent->SetUserInformation(inputEventInfo.release());
37
38 bool eventPreparationFailed = false;
39 try {
40 // convert Genevent to G4Event
41 eventPreparationFailed =
42 eventInfo->EventFactory()(*anEvent).isFailure();
43 if(eventPreparationFailed) {
44 G4cerr << "Failed to prepare G4Event from Athena event" << G4endl;
45 }
46 }
47 catch(const std::exception& error) {
48 eventPreparationFailed = true;
49 G4cerr << "Exception while preparing G4Event from Athena event: "
50 << error.what() << G4endl;
51 }
52 catch(...) {
53 eventPreparationFailed = true;
54 G4cerr << "Unknown exception while preparing G4Event from Athena event"
55 << G4endl;
56 }
57
58 if(eventPreparationFailed) {
59 eventInfo->SetEventPreparationFailed();
60 // AbortCurrentEvent cannot be called until Geant4 enters EventProc.
61 // SyncEventAction will abort this event at BeginOfEventAction.
62 }
63 }
64 // If GetEvent returns nullptr, the event queue has been closed and the run
65 // should be aborted.
66 // Because GeneratePrimaries runs before Geant4 enters EventProc, AbortRun
67 // must be called in BeginOfEventAction.
68}

Member Data Documentation

◆ m_g4RunTool

IG4RunTool* G4UA::SyncPrimaryGeneratorAction::m_g4RunTool {}
private

Definition at line 26 of file SyncPrimaryGeneratorAction.h.

26{};

The documentation for this class was generated from the following files: