62 std::map<std::string, std::vector<double>> modifierWeightsMap;
72 std::map<std::string, std::vector<double>> modifierWeightsAndTimesMap;
82 void insertIdAndWeight(
const std::string& touchableName,
int idValue,
double weight);
92 void insertIdWeightAndTime(
const std::string& touchableName,
int idValue,
double weight,
double time);
114 [[nodiscard]]
inline bool isWeightsOnly()
const {
return !modifierWeightsMap.empty(); }
126 return modifierWeightsMap[touchableName];
139 return modifierWeightsAndTimesMap[touchableName];
184 [[maybe_unused]] G4Step* thisStep) {
199 [[nodiscard]]
virtual double processStepTimeImpl(
const std::shared_ptr<GTouchable>& gTouchID,
200 [[maybe_unused]] G4Step* thisStep);
214 std::shared_ptr<GTouchable>
gtouchable, G4Step* thisStep) {
228 std::shared_ptr<GTouchable>
gtouchable, G4Step* thisStep);
256 [[maybe_unused]]
const std::shared_ptr<GTouchable>& gTouchID,
270 log->
info(2,
"GDynamicDigitization::collect true information for hit number ", hitn,
" with size ",
271 ghit->
nsteps(),
" steps");
293 [[nodiscard]] std::unique_ptr<GDigitizedData>
digitizeHit(
GHit* ghit, [[maybe_unused]]
size_t hitn) {
295 log->
info(2,
"GDynamicDigitization::digitize hit number ", hitn,
" with size ", ghit->
nsteps(),
" steps");
309 [[maybe_unused]]
GHit* ghit, [[maybe_unused]]
size_t hitn) {
return nullptr; }
320 [[nodiscard]]
bool loadConstants([[maybe_unused]]
int runno, [[maybe_unused]] std::string
const& variation) {
335 virtual bool loadConstantsImpl([[maybe_unused]]
int runno, [[maybe_unused]] std::string
const& variation) {
348 [[nodiscard]]
bool loadTT([[maybe_unused]]
int runno, [[maybe_unused]] std::string
const& variation) {
350 log->
debug(
NORMAL,
"GDynamicDigitization::load Translation Table for run ", runno,
" with variation ",
364 virtual bool loadTTImpl([[maybe_unused]]
int runno, [[maybe_unused]] std::string
const& variation) {
return true; }
418 if (!h)
return nullptr;
421 auto sym = dlsym(h,
"GDynamicDigitizationFactory");
422 if (!sym)
return nullptr;
424 auto func =
reinterpret_cast<fptr
>(sym);
438 if (energy == 0 && !recordZeroEdep) {
457 bool recordZeroEdep =
false;
469 if (
gopts ==
nullptr) {
471 <<
"Fatal Error: GDynamicDigitization: goption is not set for this plugin or one of the loggers is null."
473 std::cerr <<
"The set_loggers function needs to be called." << std::endl;
474 std::cerr <<
"For example: dynamicRoutines[\"ctof\"]->set_loggers(gopts);" << std::endl;
475 std::cerr <<
RST << std::endl;
482using dRoutinesMap = std::unordered_map<std::string, std::shared_ptr<GDynamicDigitization>>;
492 const std::shared_ptr<GOptions>& gopts) {
507inline std::shared_ptr<const dRoutinesMap>
dynamicRoutinesMap(
const std::vector<std::string>& plugin_names,
508 const std::shared_ptr<GOptions>& gopts) {
512 auto routines = std::make_shared<dRoutinesMap>();
514 for (
const auto& plugin : plugin_names) {
516 log->info(0,
"dynamicRoutinesMap[", plugin,
"]: ", (*routines)[plugin]);
std::shared_ptr< GLogger > log
Abstract base class for dynamically loaded digitization plugins.
std::shared_ptr< GOptions > gopts
Options used by the digitization plugin instance.
virtual ~GDynamicDigitization()=default
Virtual destructor.
virtual bool defineReadoutSpecsImpl()=0
Implementation hook to define readout specs.
bool loadConstants(int runno, std::string const &variation)
Loads digitization constants (calibration/configuration).
virtual std::unique_ptr< GTrueInfoData > collectTrueInformationImpl(GHit *ghit, size_t hitn)
Implementation hook for true-information collection.
GDynamicDigitization(const std::shared_ptr< GOptions > &g)
Constructs the digitization base object.
bool loadTT(int runno, std::string const &variation)
Loads the translation table (identity -> electronics address).
double processStepTime(const std::shared_ptr< GTouchable > &gTouchID, G4Step *thisStep)
Computes the time associated with a simulation step for electronics binning.
virtual std::vector< std::shared_ptr< GTouchable > > processGTouchableModifiersImpl(const std::shared_ptr< GTouchable > &gTouchID, const GTouchableModifiers &gmods)
Implementation hook for touchable modifier application.
void check_if_log_defined() const
Ensures options/logging are configured before plugin methods run.
virtual double processStepTimeImpl(const std::shared_ptr< GTouchable > &gTouchID, G4Step *thisStep)
Implementation hook for step time computation.
std::unique_ptr< GTrueInfoData > collectTrueInformation(GHit *ghit, size_t hitn)
Collects standardized “true hit information” into a GTrueInfoData record.
std::shared_ptr< const GTranslationTable > translationTable
Translation table is typically loaded during initialization and treated as immutable.
std::vector< std::shared_ptr< GTouchable > > processTouchable(std::shared_ptr< GTouchable > gtouchable, G4Step *thisStep)
Processes a touchable based on the current step and readout specs.
static GDynamicDigitization * instantiate(const dlhandle h, std::shared_ptr< GOptions > g)
Dynamically instantiates a plugin instance from a dynamic library.
virtual std::vector< std::shared_ptr< GTouchable > > processTouchableImpl(std::shared_ptr< GTouchable > gtouchable, G4Step *thisStep)
Implementation hook for touchable processing.
std::shared_ptr< const GReadoutSpecs > readoutSpecs
Readout specs are created during initialization and treated as immutable.
virtual bool loadTTImpl(int runno, std::string const &variation)
Implementation hook for translation table loading.
void set_loggers(const std::shared_ptr< GOptions > &g)
Sets the options pointer required by the digitization base.
virtual std::unique_ptr< GDigitizedData > digitizeHitImpl(GHit *ghit, size_t hitn)
Implementation hook for hit digitization.
virtual bool decisionToSkipHit(double energy)
Decides whether a hit should be skipped based on deposited energy.
std::unique_ptr< GDigitizedData > digitizeHit(GHit *ghit, size_t hitn)
Digitizes a hit into a GDigitizedData record.
void chargeAndTimeAtHardware(int time, int q, const GHit *ghit, GDigitizedData &gdata)
Adds hardware-level time/charge and address fields to a digitized record.
virtual bool loadConstantsImpl(int runno, std::string const &variation)
Implementation hook for constant loading.
std::vector< std::shared_ptr< GTouchable > > processGTouchableModifiers(const std::shared_ptr< GTouchable > &gTouchID, const GTouchableModifiers &gmods)
Applies touchable modifiers.
bool defineReadoutSpecs()
Initializes readout specifications.
void debug(debug_type type, Args &&... args) const
void info(int level, Args &&... args) const
std::shared_ptr< T > LoadAndRegisterObjectFromLibrary(std::string_view name, const std::shared_ptr< GOptions > &gopts)
Helper container for representing touchable “modifier” information.
void insertIdAndWeight(const std::string &touchableName, int idValue, double weight)
Inserts a new (id, weight) pair for the specified touchable.
std::vector< double > getModifierWeightsVector(const std::string &touchableName)
Returns the weights vector for a touchable.
std::vector< double > getModifierWeightsAndTimeVector(const std::string &touchableName)
Returns the weights-and-times vector for a touchable.
bool isWeightsOnly() const
Returns whether the container currently reports weights-only modifiers.
void insertIdWeightAndTime(const std::string &touchableName, int idValue, double weight, double time)
Inserts a new (id, weight, time) triplet for the specified touchable.
void assignOverallWeight(const std::string &touchableName, double totalWeight)
Normalizes modifier weights by dividing by a provided total.
GTouchableModifiers(const std::vector< std::string > &touchableNames)
Constructs the container and declares supported touchable names.
Options for the GDynamicDigitization module.
constexpr const char * GDIGITIZATION_LOGGER
Logger name used by this module.
Readout electronics specifications used by time-binning and hit organization.
const std::string plugin_name
std::shared_ptr< GDynamicDigitization > load_dynamicRoutine(const std::string &plugin_name, const std::shared_ptr< GOptions > &gopts)
Loads a single dynamic routine and returns it.
std::shared_ptr< const dRoutinesMap > dynamicRoutinesMap(const std::vector< std::string > &plugin_names, const std::shared_ptr< GOptions > &gopts)
Loads multiple dynamic routines and returns an immutable shared map.
std::unordered_map< std::string, std::shared_ptr< GDynamicDigitization > > dRoutinesMap