16#ifndef _RMG_V_OUTPUT_SCHEME_HH_
17#define _RMG_V_OUTPUT_SCHEME_HH_
22#include "G4AnalysisManager.hh"
26#include "G4UserStackingAction.hh"
28#include "RMGDetectorMetadata.hh"
40class RMGVOutputScheme {
44 RMGVOutputScheme() =
default;
45 virtual ~RMGVOutputScheme() =
default;
82 [[nodiscard]]
virtual bool StoreAlways()
const {
return false; }
164 void SetEventIDOffset(
int offset) { fEventIDOffset = offset; }
166 static inline std::string fUIDKeyFormatString =
"det{:03}";
170 [[nodiscard]]
virtual std::string GetNtupleName(RMGDetectorMetadata det)
const {
171 if (fNtuplePerDetector) {
172 if (!det.
name.empty() && fNtupleUseVolumeName) {
175 return fmt::format(fmt::runtime(fUIDKeyFormatString), det.
uid);
177 return GetNtupleNameFlat();
179 [[nodiscard]]
virtual std::string GetNtupleNameFlat()
const {
180 throw new std::logic_error(
"GetNtupleNameFlat not implemented");
184 void CreateNtupleFOrDColumn(G4AnalysisManager* ana_man,
int nt, std::string name,
bool use_float) {
185 if (use_float) ana_man->CreateNtupleFColumn(nt, name);
186 else ana_man->CreateNtupleDColumn(nt, name);
188 void FillNtupleFOrDColumn(G4AnalysisManager* ana_man,
int nt,
int col,
double val,
bool use_float) {
190 ana_man->FillNtupleFColumn(nt, col, val);
191 else ana_man->FillNtupleDColumn(nt, col, val);
194 [[nodiscard]]
int GetEventIDForStorage(
const G4Event* evt)
const {
195 return fEventIDOffset + evt->GetEventID();
199 bool fNtuplePerDetector =
true;
200 bool fNtupleUseVolumeName =
false;
202 int fEventIDOffset = 0;
virtual void ClearBeforeEvent()
Clear any event-specific data.
Definition RMGVOutputScheme.hh:63
void SetNtuplePerDetector(bool ntuple_per_det)
Specify whether to create separate ntuples for each detector.
Definition RMGVOutputScheme.hh:155
virtual std::optional< bool > StackingActionNewStage(const int)
Hook for transitioning to a new stacking stage.
Definition RMGVOutputScheme.hh:116
virtual void SteppingAction(const G4Step *)
Hook called after each step.
Definition RMGVOutputScheme.hh:139
virtual void EndOfRunAction(const G4Run *)
Perform final actions at the end of a run.
Definition RMGVOutputScheme.hh:146
virtual void TrackingActionPost(const G4Track *)
Hook called after tracking a new particle.
Definition RMGVOutputScheme.hh:131
virtual void TrackingActionPre(const G4Track *)
Hook called before tracking a new particle.
Definition RMGVOutputScheme.hh:124
virtual bool StoreAlways() const
Indicates whether the output scheme always stores event data.
Definition RMGVOutputScheme.hh:82
virtual bool ShouldDiscardEvent(const G4Event *)
Decide whether to discard the current event.
Definition RMGVOutputScheme.hh:72
void SetNtupleUseVolumeName(bool use_vol_name)
Specify whether to use the physical volume name for naming ntuples.
Definition RMGVOutputScheme.hh:162
virtual std::optional< G4ClassificationOfNewTrack > StackingActionClassify(const G4Track *, const int)
Hook for classifying new tracks during the stacking phase.
Definition RMGVOutputScheme.hh:103
virtual void AssignOutputNames(G4AnalysisManager *)
Initialize ntuple column names for this output scheme.
Definition RMGVOutputScheme.hh:54
virtual void StoreEvent(const G4Event *)
Store the event data.
Definition RMGVOutputScheme.hh:89