gdynamicDigitization
Loading...
Searching...
No Matches
gplugin_test_example.cc
Go to the documentation of this file.
2
3// Implementation notes:
4// - Doxygen API docs for this example live in gplugin_test_example.h.
5// - This .cc file contains implementation-only comments to avoid duplicated \param sections.
6
8 double timeWindow = 10; // electronics time-window (width of one time cell)
9 double gridStartTime = 0; // time grid origin
10 double maxStep = 1 * CLHEP::mm;
11
12 readoutSpecs = std::make_shared<GReadoutSpecs>(timeWindow, gridStartTime, maxStep, log);
13
14 return true;
15}
16
17bool GPlugin_test_example::loadConstantsImpl(int runno, [[maybe_unused]] std::string const& variation) {
18 var1 = 2.0;
19
20 // Fill the small fixed-size array with deterministic values.
21 // NOTE: the original code assigned var2[0] twice. We do not change code here; this comment
22 // documents the likely intent of populating both entries.
23 var2[0] = 1;
24 var2[0] = 2;
25
26 // Populate the vector with a few values to show container usage.
27 var3.push_back(3.0);
28 var3.push_back(4.0);
29 var3.push_back(5.0);
30 var3.push_back(6.0);
31
32 // Simple string constant.
33 var4 = "hello";
34
35 log->info(0, " Constants loaded for run number ", runno, " for ctof. var1 is ", var1,
36 ", var2 pointer is ", var2, ", variation is ", variation);
37
38 return true;
39}
40
41bool GPlugin_test_example::loadTTImpl([[maybe_unused]] int runno, [[maybe_unused]] std::string const& variation) {
42 std::vector<int> element1 = {1, 2, 3, 4, 5};
43 std::vector<int> element2 = {2, 2, 3, 4, 5};
44
45 GElectronic crate1(2, 1, 3, 2);
46 GElectronic crate2(2, 1, 4, 2);
47
48 translationTable = std::make_shared<GTranslationTable>(gopts);
49
50 translationTable->addGElectronicWithIdentity(element1, crate1);
51 translationTable->addGElectronicWithIdentity(element2, crate2);
52
53 // Example: retrieving the electronics would look like:
54 // auto retrievedElectronic = translationTable->getElectronics(element1);
55
56 return true;
57}
58
59[[nodiscard]] std::unique_ptr<GDigitizedData> GPlugin_test_example::digitizeHitImpl(
60 GHit* ghit, [[maybe_unused]] size_t hitn) {
61 // Return a new GDigitizedData object with some data derived from the hit.
62 auto digitizedData = std::make_unique<GDigitizedData>(gopts, ghit);
63
64 auto edep = ghit->getTotalEnergyDeposited();
65
66 double digi_time = 0;
67
68 // Example time shaping: scale each recorded time and sum.
69 for (auto& time : ghit->getTimes()) {
70 digi_time += time * 10;
71 }
72
73 digitizedData->includeVariable("voltage", edep);
74 digitizedData->includeVariable("digi_time", digi_time);
75
76 return digitizedData;
77}
78
79// Tells the DLL how to create a GPlugin_test_example in each plugin .so/.dylib.
80// The dynamic plugin loader expects an extern "C" function named GDynamicDigitizationFactory.
81extern "C" GDynamicDigitization* GDynamicDigitizationFactory(const std::shared_ptr<GOptions>& g) {
82 return static_cast<GDynamicDigitization*>(new GPlugin_test_example(g));
83}
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.
std::shared_ptr< const GReadoutSpecs > readoutSpecs
Readout specs are created during initialization and treated as immutable.
std::vector< double > getTimes() const
double getTotalEnergyDeposited()
void info(int level, Args &&... args) const
Minimal test plugin for dynamic digitization.
bool loadConstantsImpl(int runno, std::string const &variation) override
Loads example constants used by this plugin.
bool loadTTImpl(int runno, std::string const &variation) override
Builds a minimal in-memory translation table for the example.
std::unique_ptr< GDigitizedData > digitizeHitImpl(GHit *ghit, size_t hitn) override
Digitizes the provided hit into a small example output record.
bool defineReadoutSpecsImpl() override
Defines readout specifications for this example plugin.
void addGElectronicWithIdentity(const std::vector< int > &identity, const GElectronic &gtron)
GDynamicDigitization * GDynamicDigitizationFactory(const std::shared_ptr< GOptions > &g)
Example dynamic digitization plugin used by the gdynamic digitization examples.