4#include "gfactory_options.h"
10#include "gDigitizedData.h"
11#include "gTrueInfoData.h"
12#include "gtranslationTable.h"
43 std::map<std::string, std::vector<double>> modifierWeightsMap;
46 std::map<std::string, std::vector<double>> modifierWeightsAndTimesMap;
55 void insertIdAndWeight(
const std::string& touchableName,
int idValue,
double weight);
64 void insertIdWeightAndTime(
const std::string& touchableName,
int idValue,
double weight,
double time);
82 [[nodiscard]]
inline bool isWeightsOnly()
const {
return !modifierWeightsMap.empty(); }
91 inline std::vector<double>
getModifierWeightsVector(
const std::string& touchableName) {
return modifierWeightsMap[touchableName]; }
122 [[nodiscard]]
double processStepTime(
const std::shared_ptr<GTouchable>& gTouchID, [[maybe_unused]] G4Step* thisStep) {
124 log->debug(NORMAL, FUNCTION_NAME);
128 [[nodiscard]]
virtual double processStepTimeImpl(
const std::shared_ptr<GTouchable>& gTouchID, [[maybe_unused]] G4Step* thisStep);
141 [[nodiscard]] std::vector<std::shared_ptr<GTouchable>>
processTouchable(std::shared_ptr<GTouchable> gtouchable, G4Step* thisStep) {
143 log->debug(NORMAL, FUNCTION_NAME);
147 [[nodiscard]]
virtual std::vector<std::shared_ptr<GTouchable>>
processTouchableImpl(std::shared_ptr<GTouchable> gtouchable, G4Step* thisStep);
160 log->debug(NORMAL, FUNCTION_NAME);
178 log->info(2,
"GDynamicDigitization::collect true information for hit number ", hitn,
" with size ", ghit->nsteps(),
" steps");
191 [[nodiscard]] std::unique_ptr<GDigitizedData>
digitizeHit(GHit* ghit, [[maybe_unused]]
size_t hitn) {
193 log->info(2,
"GDynamicDigitization::digitize hit number ", hitn,
" with size ", ghit->nsteps(),
" steps");
197 [[nodiscard]]
virtual std::unique_ptr<GDigitizedData>
digitizeHitImpl([[maybe_unused]] GHit* ghit, [[maybe_unused]]
size_t hitn) {
return nullptr; }
206 [[nodiscard]]
bool loadConstants([[maybe_unused]]
int runno, [[maybe_unused]] std::string
const& variation) {
208 log->debug(NORMAL,
"GDynamicDigitization::load constants");
212 virtual bool loadConstantsImpl([[maybe_unused]]
int runno, [[maybe_unused]] std::string
const& variation) {
return true; }
221 [[nodiscard]]
bool loadTT([[maybe_unused]]
int runno, [[maybe_unused]] std::string
const& variation) {
223 log->debug(NORMAL,
"GDynamicDigitization::load Translation Table for run ", runno,
" with variation ", variation);
227 virtual bool loadTTImpl([[maybe_unused]]
int runno, [[maybe_unused]] std::string
const& variation) {
return true; }
252 log->debug(NORMAL,
"GDynamicDigitization::define readout specs");
279 if (!h)
return nullptr;
283 auto sym = dlsym(h,
"GDynamicDigitizationFactory");
284 if (!sym)
return nullptr;
286 auto func =
reinterpret_cast<fptr
>(sym);
293 if (energy == 0 && !recordZeroEdep) {
return true; }
309 bool recordZeroEdep =
false;
321 if (
gopts ==
nullptr) {
323 "Fatal Error: GDynamicDigitization: goption is not set for this plugin or one of the loggers is null."
325 std::cerr <<
"The set_loggers function needs to be called." << std::endl;
326 std::cerr <<
"For example: dynamicRoutines[\"ctof\"]->set_loggers(gopts);" << std::endl;
327 std::cerr << RST << std::endl;
336using dRoutinesMap = std::unordered_map<std::string, std::shared_ptr<GDynamicDigitization>>;
339 GManager manager(gopts);
344inline std::shared_ptr<const dRoutinesMap>
dynamicRoutinesMap(
const std::vector<std::string>& plugin_names,
const std::shared_ptr<GOptions>& gopts) {
346 GManager manager(gopts);
348 auto routines = std::make_shared<dRoutinesMap>();
350 for (
const auto& plugin : plugin_names) {
351 routines->emplace(plugin, manager.LoadAndRegisterObjectFromLibrary<
GDynamicDigitization>(plugin, gopts));
352 log->info(0,
"dynamicRoutinesMap[", plugin,
"]: ", (*routines)[plugin]);
Abstract base class for dynamic digitization functionality.
std::shared_ptr< GOptions > gopts
Optional pointer to GOptions.
virtual ~GDynamicDigitization()=default
Virtual destructor.
virtual bool defineReadoutSpecsImpl()=0
bool loadConstants(int runno, std::string const &variation)
Loads digitization constants.
virtual std::unique_ptr< GTrueInfoData > collectTrueInformationImpl(GHit *ghit, size_t hitn)
Collects true hit information from a GHit.
GDynamicDigitization(const std::shared_ptr< GOptions > &g)
bool loadTT(int runno, std::string const &variation)
Loads the translation table.
double processStepTime(const std::shared_ptr< GTouchable > &gTouchID, G4Step *thisStep)
Processes the step time.
virtual std::vector< std::shared_ptr< GTouchable > > processGTouchableModifiersImpl(const std::shared_ptr< GTouchable > &gTouchID, const GTouchableModifiers &gmods)
Default implementation for processing touchable modifiers.
void check_if_log_defined() const
Checks that all required loggers and options are defined.
virtual double processStepTimeImpl(const std::shared_ptr< GTouchable > &gTouchID, G4Step *thisStep)
Default implementation of processStepTime.
std::unique_ptr< GTrueInfoData > collectTrueInformation(GHit *ghit, size_t hitn)
Collects true hit information into a GTrueInfoData object.
std::shared_ptr< const GTranslationTable > translationTable
std::vector< std::shared_ptr< GTouchable > > processTouchable(std::shared_ptr< GTouchable > gtouchable, G4Step *thisStep)
Processes a GTouchable based on a G4Step.
static GDynamicDigitization * instantiate(const dlhandle h, std::shared_ptr< GOptions > g)
Dynamically instantiates a GDynamicDigitization object from a dynamic library.
virtual std::vector< std::shared_ptr< GTouchable > > processTouchableImpl(std::shared_ptr< GTouchable > gtouchable, G4Step *thisStep)
Processes a GTouchable based on the current G4Step.
std::shared_ptr< const GReadoutSpecs > readoutSpecs
After init, we never mutate these:
virtual bool loadTTImpl(int runno, std::string const &variation)
void set_loggers(const std::shared_ptr< GOptions > &g)
Sets the loggers for the digitization process.
virtual std::unique_ptr< GDigitizedData > digitizeHitImpl(GHit *ghit, size_t hitn)
virtual bool decisionToSkipHit(double energy)
std::unique_ptr< GDigitizedData > digitizeHit(GHit *ghit, size_t hitn)
Digitizes hit information into a GDigitizedData object.
void chargeAndTimeAtHardware(int time, int q, const GHit *ghit, GDigitizedData &gdata)
Sets hardware-level charge and time information in the digitized data.
virtual bool loadConstantsImpl(int runno, std::string const &variation)
std::vector< std::shared_ptr< GTouchable > > processGTouchableModifiers(const std::shared_ptr< GTouchable > &gTouchID, const GTouchableModifiers &gmods)
Processes touchable modifiers.
bool defineReadoutSpecs()
Pure virtual function to initialize readout specifications.
Class to manage modifications to a GTouchable using defined modifier weights.
void insertIdAndWeight(const std::string &touchableName, int idValue, double weight)
Inserts a new (id, weight) pair for given touchable.
std::vector< double > getModifierWeightsVector(const std::string &touchableName)
Gets the modifier weights vector for a given touchable.
std::vector< double > getModifierWeightsAndTimeVector(const std::string &touchableName)
Gets the modifier weights and time vector for a given touchable.
bool isWeightsOnly() const
Checks whether only weight modifiers (without time) are defined.
void insertIdWeightAndTime(const std::string &touchableName, int idValue, double weight, double time)
Inserts a new (id, weight, time) triplet for given touchable.
void assignOverallWeight(const std::string &touchableName, double totalWeight)
Normalizes the modifier weights using a total weight.
GTouchableModifiers(const std::vector< std::string > &touchableNames)
Constructs GTouchableModifiers with a list of touchable names.
Defines the options for the GDynamicDigitization module.
constexpr const char * GDIGITIZATION_LOGGER
std::shared_ptr< GDynamicDigitization > load_dynamicRoutine(const std::string &plugin_name, const std::shared_ptr< GOptions > &gopts)
std::shared_ptr< const dRoutinesMap > dynamicRoutinesMap(const std::vector< std::string > &plugin_names, const std::shared_ptr< GOptions > &gopts)
std::unordered_map< std::string, std::shared_ptr< GDynamicDigitization > > dRoutinesMap
const std::string plugin_name