gdata
Loading...
Searching...
No Matches
gTrueInfoData.h
Go to the documentation of this file.
1#pragma once
2
41#include <atomic>
42#include <map>
43#include <ostream>
44#include <string>
45#include <vector>
46
47// gemc
48#include "gbase.h"
49#include "ghit.h"
50
52constexpr const char* GTRUEDATA_LOGGER = "true_data";
53
54namespace gtrue_data {
55
67 return goptions;
68}
69
70} // namespace gtrue_data
71
105class GTrueInfoData : public GBase<GTrueInfoData>
106{
107public:
123 GTrueInfoData(const std::shared_ptr<GOptions>& gopts, const GHit* ghit);
124
141 [[nodiscard]] std::string getIdentityString() const;
142
158 void includeVariable(const std::string& varName, double var);
159
175 void includeVariable(const std::string& varName, std::string var);
176
190 void accumulateVariable(const std::string& vname, double value);
191
200 [[nodiscard]] inline std::map<std::string, double> getDoubleVariablesMap() const {
201 return doubleObservablesMap;
202 }
203
213 [[nodiscard]] inline std::map<std::string, std::string> getStringVariablesMap() const {
214 return stringVariablesMap;
215 }
216
237 static std::unique_ptr<GTrueInfoData> create(const std::shared_ptr<GOptions>& gopts) {
238 auto hit = GHit::create(gopts);
239 auto true_info_data = std::make_unique<GTrueInfoData>(gopts, hit);
240 auto counter = globalTrueInfoDataCounter.fetch_add(1, std::memory_order_relaxed);
241
242 true_info_data->includeVariable("totalEDeposited", counter * 0.1);
243 true_info_data->includeVariable("avgTime", counter * 1.0);
244 true_info_data->includeVariable("avgx", counter * 0.01);
245 true_info_data->includeVariable("avgy", counter * 0.02);
246 true_info_data->includeVariable("avgz", counter * 0.03);
247 true_info_data->includeVariable("hitn", counter);
248
249 return true_info_data;
250 }
251
252private:
263 std::map<std::string, double> doubleObservablesMap;
264
271 std::map<std::string, std::string> stringVariablesMap;
272
280 std::vector<GIdentifier> gidentity;
281
288 static std::atomic<int> globalTrueInfoDataCounter;
289
290protected:
291 friend std::ostream& operator<<(std::ostream& os, const GTrueInfoData& data);
292};
static GHit * create(const std::shared_ptr< GOptions > &gopts)
Stores simulation-level observables for one hit.
void includeVariable(const std::string &varName, double var)
Stores or overwrites one numeric truth observable.
void accumulateVariable(const std::string &vname, double value)
Accumulates a numeric observable into the current object.
std::map< std::string, double > getDoubleVariablesMap() const
Returns a copy of the numeric truth observables.
GTrueInfoData(const std::shared_ptr< GOptions > &gopts, const GHit *ghit)
Constructs the object and copies the hit identity from the source hit.
static std::unique_ptr< GTrueInfoData > create(const std::shared_ptr< GOptions > &gopts)
Creates deterministic example data for tests and examples.
std::map< std::string, std::string > getStringVariablesMap() const
Returns a copy of the string truth observables.
friend std::ostream & operator<<(std::ostream &os, const GTrueInfoData &data)
std::string getIdentityString() const
Builds a readable identity string from the stored hit identifiers.
constexpr const char * GTRUEDATA_LOGGER
Logger domain name used by GTrueInfoData.
GOptions defineOptions()
Defines the options subtree used by the true-data logger domain.