gdata
Loading...
Searching...
No Matches
gDataCollection.h
Go to the documentation of this file.
1#pragma once
2
31#include "gDigitizedData.h"
32#include "gTrueInfoData.h"
33
34// c++
35#include <memory>
36#include <ostream>
37#include <vector>
38
65{
66public:
74 explicit GDataCollection() = default;
75
83 ~GDataCollection() = default;
84
101 void collectTrueInfosData(const std::unique_ptr<GTrueInfoData>& data) {
102 // The first integrated contribution creates the detector-local accumulator entry.
103 if (trueInfosData.empty()) {
104 trueInfosData.push_back(std::make_unique<GTrueInfoData>(*data));
105 }
106 else {
107 // Subsequent contributions add only numeric observables into the first stored entry.
108 for (const auto& [varName, value] : data->getDoubleVariablesMap()) {
109 trueInfosData.front()->accumulateVariable(varName, value);
110 }
111 }
112 }
113
131 void collectDigitizedData(const std::unique_ptr<GDigitizedData>& data) {
132 // The first integrated contribution creates the detector-local accumulator entry.
133 if (digitizedData.empty()) {
134 digitizedData.push_back(std::make_unique<GDigitizedData>(*data));
135 }
136 else {
137 // Only non-SRO scalar observables are accumulated in integrated mode.
138 for (const auto& [varName, value] : data->getIntObservablesMap(0)) {
139 digitizedData.front()->accumulateVariable(varName, value);
140 }
141 for (const auto& [varName, value] : data->getDblObservablesMap(0)) {
142 digitizedData.front()->accumulateVariable(varName, value);
143 }
144 }
145 }
146
156 void addDigitizedData(std::unique_ptr<GDigitizedData> data) {
157 // Event-mode insertion appends the new hit object and transfers ownership into the container.
158 digitizedData.push_back(std::move(data));
159 }
160
170 void addTrueInfoData(std::unique_ptr<GTrueInfoData> data) {
171 // Event-mode insertion appends the new hit object and transfers ownership into the container.
172 trueInfosData.push_back(std::move(data));
173 }
174
185 [[nodiscard]] auto getTrueInfoData() const -> const std::vector<std::unique_ptr<GTrueInfoData>>& {
186 return trueInfosData;
187 }
188
199 [[nodiscard]] auto getDigitizedData() const -> const std::vector<std::unique_ptr<GDigitizedData>>& {
200 return digitizedData;
201 }
202
212 [[nodiscard]] auto getMutableDigitizedData() -> std::vector<std::unique_ptr<GDigitizedData>>& {
213 return digitizedData;
214 }
215
216private:
227 std::vector<std::unique_ptr<GTrueInfoData>> trueInfosData;
228
239 std::vector<std::unique_ptr<GDigitizedData>> digitizedData;
240
241protected:
242 friend std::ostream& operator<<(std::ostream& os, const GDataCollection& collection) {
243 os << "GDataCollection{";
244
245 os << "trueInfosData=[";
246 for (size_t i = 0; i < collection.trueInfosData.size(); ++i) {
247 if (i != 0) {
248 os << ", ";
249 }
250 if (collection.trueInfosData[i]) {
251 os << *collection.trueInfosData[i];
252 }
253 else {
254 os << "null";
255 }
256 }
257 os << "]";
258
259 os << ", digitizedData=[";
260 for (size_t i = 0; i < collection.digitizedData.size(); ++i) {
261 if (i != 0) {
262 os << ", ";
263 }
264 if (collection.digitizedData[i]) {
265 os << *collection.digitizedData[i];
266 }
267 else {
268 os << "null";
269 }
270 }
271 os << "]";
272
273 os << "}";
274 return os;
275 }
276};
Per-sensitive-detector container that owns truth and digitized data objects.
void addTrueInfoData(std::unique_ptr< GTrueInfoData > data)
Appends one truth object in event mode.
auto getDigitizedData() const -> const std::vector< std::unique_ptr< GDigitizedData > > &
Returns read-only access to the stored digitized objects.
GDataCollection()=default
Constructs an empty detector-local data collection.
friend std::ostream & operator<<(std::ostream &os, const GDataCollection &collection)
auto getMutableDigitizedData() -> std::vector< std::unique_ptr< GDigitizedData > > &
Returns mutable access to the stored digitized objects.
~GDataCollection()=default
Destroys the collection and all owned hit objects.
void addDigitizedData(std::unique_ptr< GDigitizedData > data)
Appends one digitized object in event mode.
void collectTrueInfosData(const std::unique_ptr< GTrueInfoData > &data)
Integrates one truth object into the detector-level accumulator.
auto getTrueInfoData() const -> const std::vector< std::unique_ptr< GTrueInfoData > > &
Returns read-only access to the stored truth objects.
void collectDigitizedData(const std::unique_ptr< GDigitizedData > &data)
Integrates one digitized object into the detector-level accumulator.
Stores digitized, electronics-level observables for one hit.
Stores simulation-level observables for one hit.
Container for digitized observables associated with one simulated hit.
Container for simulation-level observables associated with a single hit.