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 += GTAB;
54 help += "The value is a string of the form N or N-NTH, where N is the log module:\n";
55 help += GTABTAB;
56 help += "N : every worker thread prints 'Starting event n. <k> in thread <tid>.\n";
57 help += GTABTABTAB;
58 help += "Average rate: <r> events / second' every time it has processed a multiple\n";
59 help += GTABTABTAB;
60 help += "of N events. <k> is that thread's own 1-based event count (not the global\n";
61 help += GTABTABTAB;
62 help += "Geant4 event id), and <r> is that thread's average rate.\n";
63 help += GTABTAB;
64 help += "N-NTH : as above, but only the worker thread with id NTH prints. NTH must be\n";
65 help += GTABTABTAB;
66 help += "in the range [0, nthreads-1].\n \n";
67 help += GTAB;
68 help += "Examples: -log_every=100 (all threads, every 100 events)\n";
69 help += GTABTAB;
70 help += "-log_every=100-2 (only thread 2, every 100 events)\n";
71 goptions.defineOption(
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, "none", "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, "none", "detectors for which true-information output is disabled"),
87 "Disable true-information output for a comma- or whitespace-separated list of detector names.\n"
88 "Use \"all\" to disable true-information output for every detector. Default: none.\n \n"
89 "Example: -no_true_info=\"ftof, ecal\"");
90
91 return goptions;
92 }
93} // namespace geventaction
94
95
120class GEventAction : public GBase<GEventAction>, public G4UserEventAction
121{
122public:
131 explicit GEventAction(const std::shared_ptr<GOptions>& gopt, GRunAction* run_a,
132 std::shared_ptr<GTrackProvenance> provenance = nullptr);
133
134 ~GEventAction() override = default;
135
136 GEventAction(const GEventAction&) = delete;
140
149 void BeginOfEventAction(const G4Event* event) override;
150
165 void EndOfEventAction(const G4Event* event) override;
166
167private:
173 void publish_event_data(const std::shared_ptr<GEventDataCollection>& event_data) const;
174
187 void log_event_start(int thread_id);
188
192 long long log_events_seen = 0;
193
197 std::chrono::steady_clock::time_point log_start_time;
198
202 std::shared_ptr<GOptions> goptions;
203
207 int log_every_n = 0;
208
212 int log_every_thread = -1;
213
222 GRunAction* run_action = nullptr;
223
225 std::shared_ptr<GTrackProvenance> track_provenance;
226
227 bool save_original_track = false;
228 bool save_all_ancestors = false;
229};
230
231// looping over output factories
232// for (auto [factoryName, streamerFactory] : *gstreamerFactoryMap) {
233// if (streamerFactory->getStreamType() == "event") {
234// logSummary("Writing event data using streamer factory >" + factoryName + "<");
235// map<string, bool> streamReport = streamerFactory->publishEventRunData(goptions, theRun->getRunData());
236//
237// for (auto [reportName, result] : streamReport) {
238// string resultString = result ? " success" : " failure";
239// logSummary("Factory <" + factoryName + "> " + reportName + resultString);
240// }
241// }
242// }
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:68
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
#define GTABTABTAB
#define UNINITIALIZEDSTRINGQUANTITY
#define GTAB
#define GTABTAB
Namespace containing helpers related to event-action configuration.
GOptions defineOptions()
Returns the options associated with the event-action logger scope.