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 auto hitBitSet = HitBitSet("100000"); // bitset defining which hit information is computed/stored
11
12 // The readoutSpecs object is shared and treated as immutable after initialization.
13 readoutSpecs = std::make_shared<GReadoutSpecs>(timeWindow, gridStartTime, hitBitSet, log);
14
15 return true;
16}
17
18bool GPlugin_test_example::loadConstantsImpl(int runno, [[maybe_unused]] std::string const& variation) {
19 var1 = 2.0;
20
21 // Fill the small fixed-size array with deterministic values.
22 // NOTE: the original code assigned var2[0] twice. We do not change code here; this comment
23 // documents the likely intent of populating both entries.
24 var2[0] = 1;
25 var2[0] = 2;
26
27 // Populate the vector with a few values to show container usage.
28 var3.push_back(3.0);
29 var3.push_back(4.0);
30 var3.push_back(5.0);
31 var3.push_back(6.0);
32
33 // Simple string constant.
34 var4 = "hello";
35
36 log->info(0, " Constants loaded for run number ", runno, " for ctof. var1 is ", var1,
37 ", var2 pointer is ", var2, ", variation is ", variation);
38
39 return true;
40}
41
42bool GPlugin_test_example::loadTTImpl([[maybe_unused]] int runno, [[maybe_unused]] std::string const& variation) {
43 std::vector<int> element1 = {1, 2, 3, 4, 5};
44 std::vector<int> element2 = {2, 2, 3, 4, 5};
45
46 GElectronic crate1(2, 1, 3, 2);
47 GElectronic crate2(2, 1, 4, 2);
48
49 translationTable = std::make_shared<GTranslationTable>(gopts);
50
51 translationTable->addGElectronicWithIdentity(element1, crate1);
52 translationTable->addGElectronicWithIdentity(element2, crate2);
53
54 // Example: retrieving the electronics would look like:
55 // auto retrievedElectronic = translationTable->getElectronics(element1);
56
57 return true;
58}
59
60[[nodiscard]] std::unique_ptr<GDigitizedData> GPlugin_test_example::digitizeHitImpl(
61 GHit* ghit, [[maybe_unused]] size_t hitn) {
62 // Return a new GDigitizedData object with some data derived from the hit.
63 auto digitizedData = std::make_unique<GDigitizedData>(gopts, ghit);
64
65 auto edep = ghit->getTotalEnergyDeposited();
66
67 double digi_time = 0;
68
69 // Example time shaping: scale each recorded time and sum.
70 for (auto& time : ghit->getTimes()) {
71 digi_time += time * 10;
72 }
73
74 digitizedData->includeVariable("voltage", edep);
75 digitizedData->includeVariable("digi_time", digi_time);
76
77 return digitizedData;
78}
79
80// Tells the DLL how to create a GPlugin_test_example in each plugin .so/.dylib.
81// The dynamic plugin loader expects an extern "C" function named GDynamicDigitizationFactory.
82extern "C" GDynamicDigitization* GDynamicDigitizationFactory(const std::shared_ptr<GOptions>& g) {
83 return static_cast<GDynamicDigitization*>(new GPlugin_test_example(g));
84}
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)
std::bitset< NHITBITS > HitBitSet
GDynamicDigitization * GDynamicDigitizationFactory(const std::shared_ptr< GOptions > &g)
Example dynamic digitization plugin used by the gdynamic digitization examples.