gdata
Loading...
Searching...
No Matches
gDigitizedData.cc
Go to the documentation of this file.
1
10// See header for API docs.
11
12#include "gDigitizedData.h"
13#include "gdataConventions.h"
14
15// c++
16#include <string>
17#include <map>
18#include <vector>
19
20#include "gdynamicDigitization/gdynamicdigitization_options.h"
21
27std::atomic<int> GDigitizedData::globalDigitizedDataCounter{0};
28
29GDigitizedData::GDigitizedData(const std::shared_ptr<GOptions>& gopts, const GHit* ghit)
31 // Copy hit identity (sector/layer/component...) from the originating hit.
32 //
33 // Ownership and lifetime:
34 // - ghit is not owned.
35 // - gidentity is copied so the digitized object is self-contained and remains valid
36 // even after the originating hit is destroyed.
37 gidentity = ghit->getGID();
38}
39
40std::map<std::string, int> GDigitizedData::getIntObservablesMap(int which) const {
41 // Return a filtered copy of the integer observables.
42 //
43 // which=0 -> return non-SRO variables (digitization outputs / physics-like quantities)
44 // which=1 -> return only SRO variables (crate/slot/channel/timeAtElectronics/chargeAtElectronics)
45 std::map<std::string, int> filteredIntObservablesMap;
46 for (const auto& [varName, value] : intObservablesMap) {
47 if (validVarName(varName, which)) { filteredIntObservablesMap[varName] = value; }
48 }
49 log->info(2, " getting ", which, " from intObservablesMap.");
50 return filteredIntObservablesMap;
51}
52
53std::map<std::string, double> GDigitizedData::getDblObservablesMap(int which) const {
54 // Return a filtered copy of the double observables.
55 //
56 // Uses the same filtering semantics as getIntObservablesMap().
57 std::map<std::string, double> filteredDblObservablesMap;
58 for (const auto& [varName, value] : doubleObservablesMap) {
59 if (validVarName(varName, which)) { filteredDblObservablesMap[varName] = value; }
60 }
61 log->info(2, " getting ", which, " from doubleObservablesMap.");
62 return filteredDblObservablesMap;
63}
64
65// SRO:
66bool GDigitizedData::validVarName(const std::string& varName, int which) {
67 // Decide whether \p varName should be included in a filtered view.
68 //
69 // A variable is considered SRO if it matches one of the conventional keys defined in
70 // gdataConventions.h.
71 bool isSROVar = (varName == CRATESTRINGID || varName == SLOTSTRINGID || varName == CHANNELSTRINGID ||
72 varName == CHARGEATELECTRONICS || varName == TIMEATELECTRONICS);
73
74 if (which == 0) {
75 // Return only non-SRO keys.
76 if (isSROVar) { return false; }
77 }
78 else if (which == 1) {
79 // Return only SRO keys.
80 if (!isSROVar) { return false; }
81 }
82
83 return true;
84}
85
86void GDigitizedData::includeVariable(const std::string& vname, int value) {
87 // Store/overwrite a per-hit integer observable (event-level).
88 log->info(2, "Including int variable ", vname, " with value ", value);
89 intObservablesMap[vname] = value;
90}
91
92void GDigitizedData::includeVariable(const std::string& vname, double value) {
93 // Store/overwrite a per-hit floating observable (event-level).
94 log->info(2, "Including double variable ", vname, " with value ", value);
95 doubleObservablesMap[vname] = value;
96}
97
98void GDigitizedData::accumulateVariable(const std::string& vname, int value) {
99 // Accumulate an integer observable for run-level integration (summation).
100 if (intObservablesMap.find(vname) == intObservablesMap.end()) {
101 log->info(2, "Accumulating new int variable ", vname, " with value ", value);
102 intObservablesMap[vname] = value;
103 }
104 else {
105 log->info(2, "Accumulating int variable ", vname, " with value ", value);
106 intObservablesMap[vname] += value;
107 }
108}
109
110void GDigitizedData::accumulateVariable(const std::string& vname, double value) {
111 // Accumulate a double observable for run-level integration (summation).
112 if (doubleObservablesMap.find(vname) == doubleObservablesMap.end()) {
113 log->info(2, "Accumulating double variable ", vname, " with value ", value);
114 doubleObservablesMap[vname] = value;
115 }
116 else {
117 log->info(2, "Accumulating double variable ", vname, " with value ", value);
118 doubleObservablesMap[vname] += value;
119 }
120}
121
123 // Convenience accessor for TIMEATELECTRONICS.
124 if (intObservablesMap.find(TIMEATELECTRONICS) == intObservablesMap.end()) { return TIMEATELECTRONICSNOTDEFINED; }
125 log->info(2, "Getting TIMEATELECTRONICS from intObservablesMap.");
126 return intObservablesMap[TIMEATELECTRONICS];
127}
128
129int GDigitizedData::getIntObservable(const std::string& varName) {
130 // Retrieve one integer observable by name.
131 if (intObservablesMap.find(varName) == intObservablesMap.end()) {
133 "variable name <" + varName + "> not found in GDigitizedData::intObservablesMap");
134 }
135 return intObservablesMap[varName];
136}
137
138double GDigitizedData::getDblObservable(const std::string& varName) {
139 // Retrieve one double observable by name.
140 if (doubleObservablesMap.find(varName) == doubleObservablesMap.end()) {
142 "variable name <" + varName + "> not found in GDigitizedData::doubleObservablesMap");
143 }
144 return doubleObservablesMap[varName];
145}
146
148 // Build a concise identity label from the \c gidentity vector.
149 std::string identifierString;
150 for (size_t i = 0; i < gidentity.size() - 1; i++) {
151 identifierString += gidentity[i].getName() + "->" + std::to_string(gidentity[i].getValue()) + ", ";
152 }
153 identifierString += gidentity.back().getName() + "->" + std::to_string(gidentity.back().getValue());
154 return identifierString;
155}
std::shared_ptr< GLogger > log
void accumulateVariable(const std::string &vname, int value)
Accumulate an integer observable (run-level integration).
int getIntObservable(const std::string &varName)
Retrieve one integer observable by name.
std::map< std::string, int > getIntObservablesMap(int which) const
Return a filtered copy of the integer observables map.
int getTimeAtElectronics()
Convenience accessor for TIMEATELECTRONICS.
void includeVariable(const std::string &vname, int value)
Store/overwrite an integer observable for this hit (event-level).
std::map< std::string, double > getDblObservablesMap(int which) const
Return a filtered copy of the double observables map.
GDigitizedData(const std::shared_ptr< GOptions > &gopts, const GHit *ghit)
Construct digitized data by copying identity from a hit.
double getDblObservable(const std::string &varName)
Retrieve one double observable by name.
std::string getIdentityString() const
Return a human-readable identity string for debugging and labeling.
std::vector< GIdentifier > getGID() const
void info(int level, Args &&... args) const
void error(int exit_code, Args &&... args) const
constexpr const char * GDIGITIZED_DATA_LOGGER
Logger domain name used by GDigitizedData (controls verbosity/category in GLogger).
Shared constants and error codes for the GData library.
constexpr const char * TIMEATELECTRONICS
Time (or TDC proxy) at electronics stage.
constexpr const char * CRATESTRINGID
Electronics crate index.
constexpr const char * CHANNELSTRINGID
Channel index within a slot/module.
constexpr int ERR_VARIABLENOTFOUND
Requested observable key is missing from an observables map.
constexpr const char * SLOTSTRINGID
Slot index within a crate (module position).
constexpr int TIMEATELECTRONICSNOTDEFINED
Sentinel value returned when TIMEATELECTRONICS is requested but not present.
constexpr const char * CHARGEATELECTRONICS
Charge (or ADC-integrated proxy) at electronics stage.