actions
Loading...
Searching...
No Matches
gEventAction.h
Go to the documentation of this file.
1#pragma once
2
3// geant4
4#include "G4UserEventAction.hh"
5
6// gemc
7#include <gemc/gbase/gbase.h>
9
10// c++
11#include <chrono>
12
14
21
22constexpr const char* EVENTACTION_LOGGER = "geventaction";
23
32constexpr const char* LOG_EVERY_OPTION = "log_every";
33constexpr const char* SAVE_ORIGINAL_TRACK_SWITCH = "save_original_track";
34constexpr const char* SAVE_ALL_ANCESTORS_SWITCH = "save_all_ancestors";
35constexpr const char* NO_DIGITIZED_OPTION = "no_digitized";
36constexpr const char* NO_TRUE_INFO_OPTION = "no_true_info";
37
43namespace geventaction {
51
52 std::string help = "Print a progress log line every N events, with the average event rate.\n \n";
53 help += guts::GTAB;
54 help += "The value is a string of the form N or N-NTH, where N is the log module:\n";
55 help += guts::GTABTAB;
56 help += "N : every worker thread prints 'Starting event n. <k> in thread <tid>.\n";
57 help += guts::GTABTABTAB;
58 help += "Average rate: <r> events / second' every time it has processed a multiple\n";
59 help += guts::GTABTABTAB;
60 help += "of N events. <k> is that thread's own 1-based event count (not the global\n";
61 help += guts::GTABTABTAB;
62 help += "Geant4 event id), and <r> is that thread's average rate.\n";
63 help += guts::GTABTAB;
64 help += "N-NTH : as above, but only the worker thread with id NTH prints. NTH must be\n";
65 help += guts::GTABTABTAB;
66 help += "in the range [0, nthreads-1].\n \n";
67 help += guts::GTAB;
68 help += "Examples: -log_every=100 (all threads, every 100 events)\n";
69 help += guts::GTABTAB;
70 help += "-log_every=100-2 (only thread 2, every 100 events)\n";
71 goptions.defineOption(
72 GVariable(LOG_EVERY_OPTION, std::nullopt,
73 "log module: print event progress and average rate every N events per thread"),
74 help);
75
77 "save the original Geant4 track ID in each true-information hit");
79 "save initial information for hit-producing tracks and all their ancestors");
80 goptions.defineOption(
81 GVariable(NO_DIGITIZED_OPTION, std::nullopt, "detectors for which digitization is disabled"),
82 "Disable digitization for a comma- or whitespace-separated list of detector names.\n"
83 "Use \"all\" to disable digitization for every detector. Default: none.\n \n"
84 "Example: -no_digitized=\"ftof, ecal\"");
85 goptions.defineOption(
86 GVariable(NO_TRUE_INFO_OPTION, std::nullopt,
87 "detectors for which true-information output is disabled"),
88 "Disable true-information output for a comma- or whitespace-separated list of detector names.\n"
89 "Use \"all\" to disable true-information output for every detector. Default: none.\n \n"
90 "Example: -no_true_info=\"ftof, ecal\"");
91
92 return goptions;
93 }
94} // namespace geventaction
95
96
121class GEventAction : public GBase<GEventAction>, public G4UserEventAction
122{
123public:
132 explicit GEventAction(const std::shared_ptr<GOptions>& gopt, GRunAction* run_a,
133 std::shared_ptr<GTrackProvenance> provenance = nullptr);
134
135 ~GEventAction() override = default;
136
137 GEventAction(const GEventAction&) = delete;
141
150 void BeginOfEventAction(const G4Event* event) override;
151
166 void EndOfEventAction(const G4Event* event) override;
167
168private:
174 void publish_event_data(const std::shared_ptr<GEventDataCollection>& event_data) const;
175
188 void log_event_start(int thread_id);
189
193 long long log_events_seen = 0;
194
198 std::chrono::steady_clock::time_point log_start_time;
199
203 std::shared_ptr<GOptions> goptions;
204
208 int log_every_n = 0;
209
213 int log_every_thread = -1;
214
223 GRunAction* run_action = nullptr;
224
226 std::shared_ptr<GTrackProvenance> track_provenance;
227
228 bool save_original_track = false;
229 bool save_all_ancestors = false;
230};
231
232// looping over output factories
233// for (auto [factoryName, streamerFactory] : *gstreamerFactoryMap) {
234// if (streamerFactory->getStreamType() == "event") {
235// logSummary("Writing event data using streamer factory >" + factoryName + "<");
236// map<string, bool> streamReport = streamerFactory->publishEventRunData(goptions, theRun->getRunData());
237//
238// for (auto [reportName, result] : streamReport) {
239// string resultString = result ? " success" : " failure";
240// logSummary("Factory <" + factoryName + "> " + reportName + resultString);
241// }
242// }
243// }
GBase(const std::shared_ptr< GOptions > &gopt, std::string logger_name="")
GEventAction & operator=(const GEventAction &)=delete
GEventAction(GEventAction &&)=delete
void EndOfEventAction(const G4Event *event) override
Called by Geant4 at the end of an event.
GEventAction & operator=(GEventAction &&)=delete
~GEventAction() override=default
GEventAction(const std::shared_ptr< GOptions > &gopt, GRunAction *run_a, std::shared_ptr< GTrackProvenance > provenance=nullptr)
Constructs the event action.
GEventAction(const GEventAction &)=delete
void BeginOfEventAction(const G4Event *event) override
Called by Geant4 at the beginning of an event.
Handles run begin/end callbacks and creates the thread-local GRun object.
Definition gRunAction.h:70
Worker-local, event-scoped track ancestry registry.
constexpr const char * EVENTACTION_LOGGER
constexpr const char * LOG_EVERY_OPTION
Name of the option controlling periodic per-event log messages.
constexpr const char * SAVE_ORIGINAL_TRACK_SWITCH
constexpr const char * NO_DIGITIZED_OPTION
constexpr const char * NO_TRUE_INFO_OPTION
constexpr const char * SAVE_ALL_ANCESTORS_SWITCH
Declares GRunAction, the run-lifecycle action for the GEMC actions module.
event
Namespace containing helpers related to event-action configuration.
GOptions defineOptions()
Returns the options associated with the event-action logger scope.
constexpr char GTABTAB[]
constexpr char GTABTABTAB[]
constexpr char GTAB[]