ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Simulation
G4Utilities
G4RunManagement
src
SyncPrimaryGeneratorAction.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
SyncPrimaryGeneratorAction.h
"
6
#include "GaudiKernel/StatusCode.h"
7
8
#include "
G4RunManagement/AtlasG4SyncEventUserInfo.h
"
9
10
#include "G4RunManager.hh"
11
#include "G4Event.hh"
12
#include "G4SystemOfUnits.hh"
13
#include "Randomize.hh"
14
15
#include <exception>
16
17
namespace
G4UA
18
{
19
20
SyncPrimaryGeneratorAction::SyncPrimaryGeneratorAction
(
IG4RunTool
* g4RunTool)
21
: G4VUserPrimaryGeneratorAction(),
m_g4RunTool
(g4RunTool)
22
{
23
}
24
25
void
SyncPrimaryGeneratorAction::GeneratePrimaries
(G4Event* anEvent)
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
}
69
70
}
// namespace G4UA
AtlasG4SyncEventUserInfo.h
SyncPrimaryGeneratorAction.h
G4UA::SyncPrimaryGeneratorAction::GeneratePrimaries
virtual void GeneratePrimaries(G4Event *) override
Definition
SyncPrimaryGeneratorAction.cxx:25
G4UA::SyncPrimaryGeneratorAction::SyncPrimaryGeneratorAction
SyncPrimaryGeneratorAction(IG4RunTool *)
Definition
SyncPrimaryGeneratorAction.cxx:20
G4UA::SyncPrimaryGeneratorAction::m_g4RunTool
IG4RunTool * m_g4RunTool
Definition
SyncPrimaryGeneratorAction.h:26
IG4RunTool
Provides an interface to interact with the Geant4 run.
Definition
IG4RunTool.h:22
G4UA
for nSW
Definition
CalibrationDefaultProcessing.h:19
error
Definition
IImpactPoint3dEstimator.h:72
Generated on
for ATLAS Offline Software by
1.17.0