gtouchable
Loading...
Searching...
No Matches
gtouchable.h
Go to the documentation of this file.
1#pragma once
2
3// gemc
4#include "gbase.h"
5
6// c++
7#include <vector>
8#include <string>
9#include <memory>
10
11// gtouchable
12#include "gtouchable_options.h"
13
14// - readout: electronic Time Window is the discriminating factor.
15// parameters and hitBitSet determined by defineReadoutSpecs in the plugin
16// - flux: track id is the discriminating factor, standard true infos variable
17// - particleCounter: no other discriminating factors, standard true infos variable
18// - dosimeter: track id is the discriminating factor, radiation digitization
19
20
32
33// ------------------------------------------------------------------------
34// Convert enum to string for logging / debugging.
35// ------------------------------------------------------------------------
36namespace gtouchable {
37inline const char* to_string(GTouchableType t) {
38 switch (t) {
39 case GTouchableType::readout: return "readout";
40 case GTouchableType::flux: return "flux";
41 case GTouchableType::particleCounter: return "particleCounter";
42 case GTouchableType::dosimeter: return "dosimeter";
43 default: return "unknown‑gtouchable";
44 }
45}
46}
47
54
55public:
61 GIdentifier(const std::string& n, int v) : idName{n}, idValue{v} {
62 }
63
69 bool operator==(const GIdentifier& gid) const { return this->idValue == gid.idValue; }
70
75 [[nodiscard]] inline std::string getName() const { return idName; }
76
81 [[nodiscard]] inline int getValue() const { return idValue; }
82
83private:
84 std::string idName;
85 int idValue;
86
88 friend std::ostream& operator<<(std::ostream& stream, const GIdentifier& gidentifier);
89
90};
91
92
103class GTouchable : public GBase<GTouchable> {
104
105public:
106 GTouchable(const GTouchable&) = default;
107 GTouchable& operator=(const GTouchable&) = default;
108
120 GTouchable(const std::shared_ptr<GOptions>& gopt,
121 const std::string& digitization,
122 const std::string& gidentityString,
123 const std::vector<double>& dimensions);
124
125
126 GTouchable(const std::shared_ptr<GLogger>& logger,
127 const std::string& digitization,
128 const std::string& gidentityString,
129 const std::vector<double>& dimensions);
141 GTouchable(const std::shared_ptr<GTouchable>& base, int newTimeIndex)
142 : GBase<GTouchable>(*base),
143 gType(base->gType),
144 gidentity(base->gidentity),
145 trackId(base->trackId),
146 eMultiplier(base->eMultiplier),
147 stepTimeAtElectronicsIndex(newTimeIndex) { log->debug(CONSTRUCTOR, "Copy-with-time-index", gtouchable::to_string(gType), " ", getIdentityString()); }
148
149 ~GTouchable() { log->debug(DESTRUCTOR, gtouchable::to_string(gType), " ", getIdentityString()); }
150
159 bool operator==(const GTouchable& gtouchable) const;
160
166 inline void assignTrackId(int tid) { trackId = tid; }
167
172 [[nodiscard]] inline double getEnergyMultiplier() const { return eMultiplier; }
173
178 inline void assignStepTimeAtElectronicsIndex(int timeIndex) { stepTimeAtElectronicsIndex = timeIndex; }
179
184 [[nodiscard]] inline int getStepTimeAtElectronicsIndex() const { return stepTimeAtElectronicsIndex; }
185
190 [[nodiscard]] inline std::vector<GIdentifier> getIdentity() const { return gidentity; }
191
196 [[nodiscard]] inline std::string getIdentityString() const {
197 std::string idString;
198 for (const auto& id : gidentity) { idString += id.getName() + ": " + std::to_string(id.getValue()) + " "; }
199 return idString;
200 }
201
206 [[nodiscard]] inline std::vector<double> getDetectorDimensions() const { return detectorDimensions; }
207
214 [[nodiscard]] bool exists_in_vector(const std::vector<GTouchable>& v) const {
215 for (const auto& gt : v) {
216 if (*this == gt) {
217 log->info(2, "GTouchable", this, " exists in vector.");
218 return true;
219 }
220 }
221 log->info(2, "GTouchable", this, " does not exist in vector.");
222
223 return false;
224 }
225
226 // create fake gtouchable for testing purposes, using sector and fake dimensions
227 static std::shared_ptr<GTouchable> create(const std::shared_ptr<GOptions>& gopt) {
228 int touchableNumber = globalGTouchableCounter.fetch_add(1, std::memory_order_relaxed);
229 int sector = (touchableNumber % 6) + 1;
230 int paddle = (touchableNumber % 20) + 1;
231 std::string identity = "sector: " + std::to_string(sector) + ", paddle: " + std::to_string(paddle);
232 const auto& dimensions = {10.0, 20.0, 30.0};
233
234 return std::make_shared<GTouchable>(gopt, "readout", identity, dimensions);
235 }
236
237 // create fake gtouchable for testing purposes, using sector and fake dimensions
238 static std::shared_ptr<GTouchable> create(const std::shared_ptr<GLogger>& logger) {
239 int touchableNumber = globalGTouchableCounter.fetch_add(1, std::memory_order_relaxed);
240 int sector = (touchableNumber % 6) + 1;
241 int paddle = (touchableNumber % 20) + 1;
242 std::string identity = "sector: " + std::to_string(sector) + ", paddle: " + std::to_string(paddle);
243 const auto& dimensions = {10.0, 20.0, 30.0};
244
245 return std::make_shared<GTouchable>(logger, "readout", identity, dimensions);
246 }
247
248private:
249 GTouchableType gType;
250 std::vector<GIdentifier> gidentity;
251 int trackId;
252 double eMultiplier;
253 int stepTimeAtElectronicsIndex;
255 std::vector<double> detectorDimensions;
256
257
259 friend std::ostream& operator<<(std::ostream& stream, const GTouchable& gtouchable);
260
262 static std::atomic<int> globalGTouchableCounter;
263};
Represents a touchable sensitive detector element.
Definition gtouchable.h:103
GTouchable(const GTouchable &)=default
static std::shared_ptr< GTouchable > create(const std::shared_ptr< GOptions > &gopt)
Definition gtouchable.h:227
std::vector< GIdentifier > getIdentity() const
Returns the identifier vector.
Definition gtouchable.h:190
bool operator==(const GTouchable &gtouchable) const
Equality operator comparing two GTouchable objects.
Definition gtouchable.cc:77
void assignTrackId(int tid)
Assigns a track identifier.
Definition gtouchable.h:166
void assignStepTimeAtElectronicsIndex(int timeIndex)
Assigns the step time index used in electronics.
Definition gtouchable.h:178
friend std::ostream & operator<<(std::ostream &stream, const GTouchable &gtouchable)
Overloaded output operator for GTouchable.
double getEnergyMultiplier() const
Gets the energy multiplier.
Definition gtouchable.h:172
static std::shared_ptr< GTouchable > create(const std::shared_ptr< GLogger > &logger)
Definition gtouchable.h:238
GTouchable & operator=(const GTouchable &)=default
int getStepTimeAtElectronicsIndex() const
Gets the electronics time index.
Definition gtouchable.h:184
bool exists_in_vector(const std::vector< GTouchable > &v) const
Checks if the GTouchable is found in a vector of GTouchable objects.
Definition gtouchable.h:214
std::string getIdentityString() const
Returns a string formed by all identifiers.
Definition gtouchable.h:196
std::vector< double > getDetectorDimensions() const
Returns the detector dimensions.
Definition gtouchable.h:206
GTouchable(const std::shared_ptr< GTouchable > &base, int newTimeIndex)
Copy constructor for updating the electronic time index. Used to create a new hit,...
Definition gtouchable.h:141
GTouchableType
Enumeration representing the type of GTouchable element.
Definition gtouchable.h:26
@ flux
Track-based discrimination.
Definition gtouchable.h:28
@ particleCounter
No additional discriminating factors.
Definition gtouchable.h:29
@ readout
Electronic readout with time window discrimination.
Definition gtouchable.h:27
@ dosimeter
Radiation digitization using track id.
Definition gtouchable.h:30
const char * to_string(GTouchableType t)
Definition gtouchable.h:37
Represents a unique identifier for a sensitive detector element.
Definition gtouchable.h:53
GIdentifier(const std::string &n, int v)
Constructs a GIdentifier.
Definition gtouchable.h:61
friend std::ostream & operator<<(std::ostream &stream, const GIdentifier &gidentifier)
Overloaded output operator for GIdentifier.
std::string getName() const
Gets the identifier name.
Definition gtouchable.h:75
bool operator==(const GIdentifier &gid) const
Equality operator comparing only the identifier value.
Definition gtouchable.h:69
int getValue() const
Gets the identifier value.
Definition gtouchable.h:81