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"
14
15// - readout: electronic Time Window is the discriminating factor.
16// parameters and hitBitSet determined by defineReadoutSpecs in the plugin
17// - flux: track id is the discriminating factor, standard true infos variable
18// - particleCounter: no other discriminating factors, standard true infos variable
19// - dosimeter: track id is the discriminating factor, radiation digitization
20
21
40
41// ------------------------------------------------------------------------
42// Convert enum to string for logging / debugging.
43// ------------------------------------------------------------------------
44namespace gtouchable {
56inline const char* to_string(GTouchableType t) {
57 switch (t) {
58 case GTouchableType::readout: return "readout";
59 case GTouchableType::flux: return FLUXNAME;
62 default: return "unknown-gtouchable";
63 }
64}
65}
66
78{
79public:
86 GIdentifier(const std::string& n, int v) : idName{n}, idValue{v} {
87 }
88
97 bool operator==(const GIdentifier& gid) const { return this->idValue == gid.idValue; }
98
103 [[nodiscard]] inline std::string getName() const { return idName; }
104
109 [[nodiscard]] inline int getValue() const { return idValue; }
110
111private:
112 std::string idName;
113 int idValue;
114
116 friend std::ostream& operator<<(std::ostream& stream, const GIdentifier& gidentifier);
117};
118
119
139class GTouchable : public GBase<GTouchable>
140{
141public:
142 GTouchable(const GTouchable&) = default;
143 GTouchable& operator=(const GTouchable&) = default;
144
158 GTouchable(const std::shared_ptr<GOptions>& gopt,
159 const std::string& digitization,
160 const std::string& gidentityString,
161 const std::vector<double>& dimensions);
162
174 GTouchable(const std::shared_ptr<GLogger>& logger,
175 const std::string& digitization,
176 const std::string& gidentityString,
177 const std::vector<double>& dimensions);
178
191 GTouchable(const std::shared_ptr<GTouchable>& base, int newTimeIndex)
192 : GBase<GTouchable>(*base),
193 gType(base->gType),
194 gidentity(base->gidentity),
195 trackId(base->trackId),
196 eMultiplier(base->eMultiplier),
197 stepTimeAtElectronicsIndex(newTimeIndex) {
198 log->debug(CONSTRUCTOR, "Copy-with-time-index", gtouchable::to_string(gType), " ", getIdentityString());
199 }
200
208
215 bool operator==(const GTouchable& gtouchable) const;
216
224 inline void assignTrackId(int tid) { trackId = tid; }
225
234 [[nodiscard]] inline double getEnergyMultiplier() const { return eMultiplier; }
235
241 inline void assignStepTimeAtElectronicsIndex(int timeIndex) { stepTimeAtElectronicsIndex = timeIndex; }
242
248 [[nodiscard]] inline int getStepTimeAtElectronicsIndex() const { return stepTimeAtElectronicsIndex; }
249
255 [[nodiscard]] inline std::vector<GIdentifier> getIdentity() const { return gidentity; }
256
265 [[nodiscard]] inline std::string getIdentityString() const {
266 std::string idString;
267 for (const auto& id : gidentity) { idString += id.getName() + ": " + std::to_string(id.getValue()) + " "; }
268 return idString;
269 }
270
278 [[nodiscard]] inline std::vector<double> getDetectorDimensions() const { return detectorDimensions; }
279
289 [[nodiscard]] bool exists_in_vector(const std::vector<GTouchable>& v) const {
290 for (const auto& gt : v) {
291 if (*this == gt) {
292 log->info(2, "GTouchable", this, " exists in vector.");
293 return true;
294 }
295 }
296 log->info(2, "GTouchable", this, " does not exist in vector.");
297
298 return false;
299 }
300
311 static std::shared_ptr<GTouchable> create(const std::shared_ptr<GOptions>& gopt) {
312 int touchableNumber = globalGTouchableCounter.fetch_add(1, std::memory_order_relaxed);
313 int sector = (touchableNumber % 6) + 1;
314 int paddle = (touchableNumber % 20) + 1;
315 std::string identity = "sector: " + std::to_string(sector) + ", paddle: " + std::to_string(paddle);
316 const auto& dimensions = {10.0, 20.0, 30.0};
317
318 return std::make_shared<GTouchable>(gopt, "readout", identity, dimensions);
319 }
320
331 static std::shared_ptr<GTouchable> create(const std::shared_ptr<GLogger>& logger) {
332 int touchableNumber = globalGTouchableCounter.fetch_add(1, std::memory_order_relaxed);
333 int sector = (touchableNumber % 6) + 1;
334 int paddle = (touchableNumber % 20) + 1;
335 std::string identity = "sector: " + std::to_string(sector) + ", paddle: " + std::to_string(paddle);
336 const auto& dimensions = {10.0, 20.0, 30.0};
337
338 return std::make_shared<GTouchable>(logger, "readout", identity, dimensions);
339 }
340
341private:
342 GTouchableType gType;
343 std::vector<GIdentifier> gidentity;
344 int trackId;
345 double eMultiplier;
346 int stepTimeAtElectronicsIndex;
347 std::vector<double> detectorDimensions;
348
350 friend std::ostream& operator<<(std::ostream& stream, const GTouchable& gtouchable);
351
353 static std::atomic<int> globalGTouchableCounter;
354};
std::shared_ptr< GLogger > log
void debug(debug_type type, Args &&... args) const
void info(int level, Args &&... args) const
Represents a touchable sensitive detector element used as a hit-collection discriminator.
Definition gtouchable.h:140
GTouchable(const GTouchable &)=default
static std::shared_ptr< GTouchable > create(const std::shared_ptr< GOptions > &gopt)
Creates a synthetic readout touchable for testing (options-based).
Definition gtouchable.h:311
std::vector< GIdentifier > getIdentity() const
Returns a copy of the identity vector.
Definition gtouchable.h:255
~GTouchable()
Destructor with debug trace.
Definition gtouchable.h:207
bool operator==(const GTouchable &gtouchable) const
Compares two GTouchable instances using the module comparison semantics.
Definition gtouchable.cc:87
void assignTrackId(int tid)
Assigns the track id used by flux and dosimeter discrimination.
Definition gtouchable.h:224
void assignStepTimeAtElectronicsIndex(int timeIndex)
Assigns the electronics time-cell index used by readout discrimination.
Definition gtouchable.h:241
friend std::ostream & operator<<(std::ostream &stream, const GTouchable &gtouchable)
Stream output helper used in logs and diagnostics.
double getEnergyMultiplier() const
Returns the energy multiplier used for energy sharing.
Definition gtouchable.h:234
static std::shared_ptr< GTouchable > create(const std::shared_ptr< GLogger > &logger)
Creates a synthetic readout touchable for testing (logger-based).
Definition gtouchable.h:331
GTouchable & operator=(const GTouchable &)=default
int getStepTimeAtElectronicsIndex() const
Returns the electronics time-cell index.
Definition gtouchable.h:248
bool exists_in_vector(const std::vector< GTouchable > &v) const
Checks whether this touchable exists in a vector using operator== semantics.
Definition gtouchable.h:289
std::string getIdentityString() const
Builds a human-readable identity string from the stored identifiers.
Definition gtouchable.h:265
std::vector< double > getDetectorDimensions() const
Returns the detector dimensions stored at construction time.
Definition gtouchable.h:278
GTouchable(const std::shared_ptr< GTouchable > &base, int newTimeIndex)
Copy constructor that preserves identity but updates the electronics time-cell index.
Definition gtouchable.h:191
CONSTRUCTOR
DESTRUCTOR
Conventions and constants used by the gtouchable module.
#define FLUXNAME
Digitization type name for flux-like detectors.
#define DOSIMETERNAME
Digitization type name for dosimeters.
#define COUNTERNAME
Digitization type name for simple particle counters.
GTouchableType
Enumeration representing the type of a touchable sensitive element.
Definition gtouchable.h:34
@ flux
Flux-like discrimination using track id.
Definition gtouchable.h:36
@ particleCounter
Identity vector only; no additional discriminating factor.
Definition gtouchable.h:37
@ readout
Electronic readout with time-window discrimination (time-cell index).
Definition gtouchable.h:35
@ dosimeter
Radiation digitization; discrimination using track id.
Definition gtouchable.h:38
Options definition entry point for the gtouchable module.
const char * to_string(GTouchableType t)
Converts a GTouchableType value to a stable string for logging.
Definition gtouchable.h:56
A single (name,value) identifier element used to build a touchable identity vector.
Definition gtouchable.h:78
GIdentifier(const std::string &n, int v)
Constructs a GIdentifier.
Definition gtouchable.h:86
friend std::ostream & operator<<(std::ostream &stream, const GIdentifier &gidentifier)
Stream output helper used in logs and diagnostics.
std::string getName() const
Returns the identifier name.
Definition gtouchable.h:103
bool operator==(const GIdentifier &gid) const
Compares identifiers by value only.
Definition gtouchable.h:97
int getValue() const
Returns the identifier value.
Definition gtouchable.h:109