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 sro_factory(GSROFactory::from_options(goptions)),
21 sharedParticles_(std::make_shared<std::vector<GparticlePtr>>(
22 gparticle::getGParticlesFromOption(goptions, log))) {
23
25
26}
27
28
29// Register the master-thread actions.
30// In GEMC, the master needs only the run action because it does not execute
31// primary generation or per-event processing.
33 log->debug(NORMAL, FUNCTION_NAME);
34
35 SetUserAction(new GRunAction(goptions, digitization_routines_map, analysis_accumulator, sro_factory));
36}
37
38// Register the worker-thread actions.
39// Workers execute the full event lifecycle, so they need the primary generator,
40// the run action, and the event action.
41void GAction::Build() const {
42 const auto thread_id = G4Threading::G4GetThreadId();
43
44 log->debug(NORMAL, FUNCTION_NAME, "thread id: " + std::to_string(thread_id));
45
46 // Primary generation is event-scoped and therefore worker-owned.
47 SetUserAction(new GPrimaryGeneratorAction(goptions, sharedParticles_));
48
49 // The run action is shared conceptually across the worker-thread lifecycle and
50 // is passed to the event action so event processing can access run services.
51 auto* run_action = new GRunAction(goptions, digitization_routines_map, analysis_accumulator, sro_factory);
52 SetUserAction(run_action);
53
54 std::shared_ptr<GTrackProvenance> track_provenance;
55 const bool save_ancestors = goptions->getSwitch(SAVE_ALL_ANCESTORS_SWITCH);
56 if (goptions->getSwitch(SAVE_ORIGINAL_TRACK_SWITCH) || save_ancestors) {
57 track_provenance = std::make_shared<GTrackProvenance>(save_ancestors);
58 SetUserAction(new GTrackingAction(track_provenance));
59 }
60
61 // Per-step track guards (kill trapped optical photons, stuck tracks, Kryptonite).
62 SetUserAction(new GSteppingAction());
63
64 // The event action consumes the run action as a non-owning dependency.
65 SetUserAction(new GEventAction(goptions, run_action, track_provenance));
66}
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:41
void BuildForMaster() const override
Registers the user actions required by the master thread.
Definition gaction.cc:32
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:71
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