gdynamicDigitization
Loading...
Searching...
No Matches
gdynamicdigitization.cc
Go to the documentation of this file.
1
13
14// gemc
15#include "gtranslationTableConventions.h"
16#include "gdataConventions.h"
17#include "gtouchableConventions.h"
18
19// c++
20#include <iostream>
21
33std::unique_ptr<GTrueInfoData> GDynamicDigitization::collectTrueInformationImpl(GHit* ghit, size_t hitn) {
34 auto trueInfoData = std::make_unique<GTrueInfoData>(gopts, ghit);
35
36 std::vector<GIdentifier> identities = ghit->getGID();
37
38 // Loop over all identities and include them in the true info data.
39 for (auto& identity : identities) { trueInfoData->includeVariable(identity.getName(), identity.getValue()); }
40
41 // Process bit 0: always present values.
42 ghit->calculateInfosForBit(0);
43 G4ThreeVector avgGlobalPos = ghit->getAvgGlobaPosition();
44 G4ThreeVector avgLocalPos = ghit->getAvgLocalPosition();
45
46 trueInfoData->includeVariable("totalEDeposited", ghit->getTotalEnergyDeposited());
47 trueInfoData->includeVariable("avgTime", ghit->getAverageTime());
48 trueInfoData->includeVariable("avgx", avgGlobalPos.getX());
49 trueInfoData->includeVariable("avgy", avgGlobalPos.getY());
50 trueInfoData->includeVariable("avgz", avgGlobalPos.getZ());
51 trueInfoData->includeVariable("avglx", avgLocalPos.getX());
52 trueInfoData->includeVariable("avgly", avgLocalPos.getY());
53 trueInfoData->includeVariable("avglz", avgLocalPos.getZ());
54 trueInfoData->includeVariable("hitn", static_cast<int>(hitn)); // reasonable to assume hitn is less than INT_MAX
55
56 // Process bit 1: include process name.
57 trueInfoData->includeVariable("processName", ghit->getProcessName());
58
59 return trueInfoData;
60}
61
73void GDynamicDigitization::chargeAndTimeAtHardware(int time, int q, const GHit* ghit, GDigitizedData& gdata) {
75 // Exit if the translation table is not defined.
76 if (translationTable == nullptr) {
77 log->error(EC__TTNOTFOUNDINTT, "Translation Table not found");
78 }
79 else {
80 // Obtain the hardware address (crate, slot, channel) from the translation table.
81 std::vector<int> haddress = translationTable->getElectronics(ghit->getTTID()).getHAddress();
82 // Exit if the hardware address is not properly initialized.
83 if (haddress.front() == UNINITIALIZEDNUMBERQUANTITY) {
84 log->error(EC__GIDENTITYNOTFOUNDINTT, "Translation Table found, but haddress was not initialized");
85 }
86 else {
87 // Include hardware address, time, and charge in the digitized data.
88 gdata.includeVariable(CRATESTRINGID, haddress[0]);
89 gdata.includeVariable(SLOTSTRINGID, haddress[1]);
90 gdata.includeVariable(CHANNELSTRINGID, haddress[2]);
91 gdata.includeVariable(TIMEATELECTRONICS, time);
92 gdata.includeVariable(CHARGEATELECTRONICS, q);
93 }
94 }
95}
96
104GTouchableModifiers::GTouchableModifiers(const std::vector<std::string>& touchableNames) { for (const auto& tname : touchableNames) { modifierWeightsMap[tname] = {}; } }
105
113void GTouchableModifiers::insertIdAndWeight(const std::string& touchableName, int idValue, double weight) {
114 modifierWeightsMap[touchableName].push_back(idValue);
115 modifierWeightsMap[touchableName].push_back(weight);
116}
117
126void GTouchableModifiers::insertIdWeightAndTime(const std::string& touchableName, int idValue, double weight, double time) {
127 modifierWeightsAndTimesMap[touchableName].push_back(idValue);
128 modifierWeightsAndTimesMap[touchableName].push_back(weight);
129 modifierWeightsAndTimesMap[touchableName].push_back(time);
130}
131
142void GTouchableModifiers::assignOverallWeight(const std::string& tname, double totalWeight) {
143 size_t countWeights = modifierWeightsMap[tname].size() / 2;
144 for (size_t h = 0; h < countWeights; h++) { modifierWeightsMap[tname][h * 2 + 1] = modifierWeightsMap[tname][h * 2 + 1] / totalWeight; }
145 size_t countWeightsAndTimes = modifierWeightsAndTimesMap[tname].size() / 3; // Triplets: (id, weight, time)
146 for (size_t h = 0; h < countWeightsAndTimes; h++) {
147 // Normalize the weight in each triplet (index: h*3 + 1).
148 modifierWeightsAndTimesMap[tname][h * 3 + 1] = modifierWeightsAndTimesMap[tname][h * 3 + 1] / totalWeight;
149 }
150}
151
161double GDynamicDigitization::processStepTimeImpl([[maybe_unused]] const std::shared_ptr<GTouchable>& gTouchID, [[maybe_unused]] G4Step* thisStep) {
162 return thisStep->GetPostStepPoint()->GetGlobalTime();
163}
164
176std::vector<std::shared_ptr<GTouchable>> GDynamicDigitization::processTouchableImpl(std::shared_ptr<GTouchable> gtouchable, G4Step* thisStep) {
177
178 double stepTimeAtElectronics = processStepTime(gtouchable, thisStep);
179 int stepTimeAtElectronicsIndex = readoutSpecs->timeCellIndex(stepTimeAtElectronics);
180
181 std::vector<std::shared_ptr<GTouchable>> result;
182
183 if (stepTimeAtElectronicsIndex == gtouchable->getStepTimeAtElectronicsIndex() ||
184 gtouchable->getStepTimeAtElectronicsIndex() == GTOUCHABLEUNSETTIMEINDEX) {
185 gtouchable->assignStepTimeAtElectronicsIndex(stepTimeAtElectronicsIndex);
186
187 result.emplace_back(gtouchable);
188 }
189 else {
190 // Create a new GTouchable with the updated time index.
191 auto cloned = std::make_shared<GTouchable>(gtouchable, stepTimeAtElectronicsIndex);
192
193 // release ownership of the original touchable and return both.
194 // std::initializer_list requires copyable elements, so we need to create the vector first
195 result.emplace_back(gtouchable);
196 result.emplace_back(cloned);
197 }
198
199 return result;
200}
201
211// TODO: are we using this anywhere? pass readonly touchId or move it?
212std::vector<std::shared_ptr<GTouchable>> GDynamicDigitization::processGTouchableModifiersImpl([[maybe_unused]] const std::shared_ptr<GTouchable>& gTouchID,
213 [[maybe_unused]] const GTouchableModifiers& gmods) {
214 std::vector<std::shared_ptr<GTouchable>> touchables;
215
216 // touchables.emplace_back(std::make_unique<GTouchable>(*gTouchID, 1)); // Ensure we have a valid touchable to return
217
218 return touchables;
219}
std::shared_ptr< GOptions > gopts
Optional pointer to GOptions.
virtual std::unique_ptr< GTrueInfoData > collectTrueInformationImpl(GHit *ghit, size_t hitn)
Collects true hit information from a GHit.
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::shared_ptr< const GTranslationTable > translationTable
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:
void chargeAndTimeAtHardware(int time, int q, const GHit *ghit, GDigitizedData &gdata)
Sets hardware-level charge and time information in the digitized data.
int timeCellIndex(double time) const
Computes the time cell index for a given time.
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.
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.