actions
Loading...
Searching...
No Matches
gaction.cc
Go to the documentation of this file.
1// gemc
2#include "gaction.h"
5#include "run/gRunAction.h"
9#include "gparticle_options.h"
10
11// Construct the action initializer and keep shared services available for later
12// action registration on worker and master execution contexts.
13GAction::GAction(std::shared_ptr<GOptions> gopts,
14 std::shared_ptr<gdynamicdigitization::dRoutinesMap> digi_map,
15 std::shared_ptr<GAnalysisAccumulator> analyzer) :
16 GBase(gopts, GACTION_LOGGER),
17 goptions(std::move(gopts)),
18 digitization_routines_map(std::move(digi_map)),
19 analysis_accumulator(std::move(analyzer)),
20 sharedParticles_(std::make_shared<std::vector<GparticlePtr>>(
21 gparticle::getGParticlesFromOption(goptions, log))) {
22
24
25}
26
27
28// Register the master-thread actions.
29// In GEMC, the master needs only the run action because it does not execute
30// primary generation or per-event processing.
32 log->debug(NORMAL, FUNCTION_NAME);
33
34 SetUserAction(new GRunAction(goptions, digitization_routines_map, analysis_accumulator));
35}
36
37// Register the worker-thread actions.
38// Workers execute the full event lifecycle, so they need the primary generator,
39// the run action, and the event action.
40void GAction::Build() const {
41 const auto thread_id = G4Threading::G4GetThreadId();
42
43 log->debug(NORMAL, FUNCTION_NAME, "thread id: " + std::to_string(thread_id));
44
45 // Primary generation is event-scoped and therefore worker-owned.
46 SetUserAction(new GPrimaryGeneratorAction(goptions, sharedParticles_));
47
48 // The run action is shared conceptually across the worker-thread lifecycle and
49 // is passed to the event action so event processing can access run services.
50 auto* run_action = new GRunAction(goptions, digitization_routines_map, analysis_accumulator);
51 SetUserAction(run_action);
52
53 std::shared_ptr<GTrackProvenance> track_provenance;
54 const bool save_ancestors = goptions->getSwitch(SAVE_ALL_ANCESTORS_SWITCH);
55 if (goptions->getSwitch(SAVE_ORIGINAL_TRACK_SWITCH) || save_ancestors) {
56 track_provenance = std::make_shared<GTrackProvenance>(save_ancestors);
57 SetUserAction(new GTrackingAction(track_provenance));
58 }
59
60 // Per-step track guards (kill trapped optical photons, stuck tracks, Kryptonite).
61 SetUserAction(new GSteppingAction());
62
63 // The event action consumes the run action as a non-owning dependency.
64 SetUserAction(new GEventAction(goptions, run_action, track_provenance));
65}
GAction(std::shared_ptr< GOptions > gopts, std::shared_ptr< gdynamicdigitization::dRoutinesMap > digi_map, std::shared_ptr< GAnalysisAccumulator > analysis_accumulator=nullptr)
Constructs the action initializer used by the Geant4 run manager.
Definition gaction.cc:13
void Build() const override
Registers the user actions required by worker threads and sequential execution.
Definition gaction.cc:40
void BuildForMaster() const override
Registers the user actions required by the master thread.
Definition gaction.cc:31
GBase(const std::shared_ptr< GOptions > &gopt, std::string logger_name="")
std::shared_ptr< GLogger > log
Handles event begin/end callbacks, hit digitization, and event-level publication.
Generates the primary vertices for each Geant4 event.
Handles run begin/end callbacks and creates the thread-local GRun object.
Definition gRunAction.h:68
Applies per-step track guards for one Geant4 worker.
Records initial track provenance for one Geant4 worker.
Declares GEventAction, the per-event processing action for the GEMC actions module.
constexpr const char * SAVE_ORIGINAL_TRACK_SWITCH
constexpr const char * SAVE_ALL_ANCESTORS_SWITCH
Declares GPrimaryGeneratorAction, the primary-particle generation action for the GEMC actions module.
Declares GRunAction, the run-lifecycle action for the GEMC actions module.
Declares GAction, the Geant4 action-initialization entry point for the GEMC actions module.
constexpr const char * GACTION_LOGGER
Definition gaction.h:30
#define FUNCTION_NAME
CONSTRUCTOR
NORMAL
std::shared_ptr< Gparticle > GparticlePtr