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 <CLHEP/Units/SystemOfUnits.h>
13
14#include "gtouchable_options.h"
16
17
39
40// ------------------------------------------------------------------------
41// Convert enum to string for logging / debugging.
42// ------------------------------------------------------------------------
43namespace gtouchable {
55 inline const char* to_string(GTouchableType t) {
56 switch (t) {
57 case GTouchableType::readout: return "readout";
58 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
140class GTouchable : public GBase<GTouchable>
141{
142public:
143 GTouchable(const GTouchable&) = default;
144 GTouchable& operator=(const GTouchable&) = default;
145
160 GTouchable(const std::shared_ptr<GOptions>& gopt,
161 const std::string& digitization,
162 const std::string& gidentityString,
163 const std::vector<double>& dimensions,
164 const double& mass);
165
179 GTouchable(const std::shared_ptr<GLogger>& logger,
180 const std::string& digitization,
181 const std::string& gidentityString,
182 const std::vector<double>& dimensions,
183 const double& mass);
184
197 GTouchable(const std::shared_ptr<GTouchable>& base, int newTimeIndex)
198 : GBase<GTouchable>(*base),
199 gType(base->gType),
200 gidentity(base->gidentity),
201 trackId(base->trackId),
202 eMultiplier(base->eMultiplier),
203 stepTimeAtElectronicsIndex(newTimeIndex) {
204 log->debug(CONSTRUCTOR, "Copy-with-time-index", gtouchable::to_string(gType), " ", getIdentityString());
205 }
206
214
221 bool operator==(const GTouchable& gtouchable) const;
222
230 inline void assignTrackId(int tid) { trackId = tid; }
231
239 inline void assignPId(int p) { pid = p; }
240
249 [[nodiscard]] inline double getEnergyMultiplier() const { return eMultiplier; }
250
256 inline void assignStepTimeAtElectronicsIndex(int timeIndex) { stepTimeAtElectronicsIndex = timeIndex; }
257
263 [[nodiscard]] inline int getStepTimeAtElectronicsIndex() const { return stepTimeAtElectronicsIndex; }
264
270 [[nodiscard]] inline std::vector<GIdentifier> getIdentity() const { return gidentity; }
271
280 [[nodiscard]] inline std::string getIdentityString() const {
281 std::string idString;
282 for (const auto& id : gidentity) { idString += id.getName() + ": " + std::to_string(id.getValue()) + " "; }
283 return idString;
284 }
285
293 [[nodiscard]] inline std::vector<double> getDetectorDimensions() const { return detectorDimensions; }
294
300 [[nodiscard]] inline double getMass() const { return mass; }
301
311 [[nodiscard]] bool exists_in_vector(const std::vector<GTouchable>& v) const {
312 for (const auto& gt : v) {
313 if (*this == gt) {
314 log->info(2, "GTouchable", this, " exists in vector.");
315 return true;
316 }
317 }
318 log->info(2, "GTouchable", this, " does not exist in vector.");
319
320 return false;
321 }
322
333 static std::shared_ptr<GTouchable> create(const std::shared_ptr<GOptions>& gopt) {
334 int touchableNumber = globalGTouchableCounter.fetch_add(1, std::memory_order_relaxed);
335 int sector = ( touchableNumber % 6 ) + 1;
336 int paddle = ( touchableNumber % 20 ) + 1;
337 std::string identity = "sector: " + std::to_string(sector) + ", paddle: " + std::to_string(paddle);
338 const auto& dimensions = {10.0, 20.0, 30.0};
339 const double& mass = 100 * CLHEP::g;
340
341 return std::make_shared<GTouchable>(gopt, "readout", identity, dimensions, mass);
342 }
343
354 static std::shared_ptr<GTouchable> create(const std::shared_ptr<GLogger>& logger) {
355 int touchableNumber = globalGTouchableCounter.fetch_add(1, std::memory_order_relaxed);
356 int sector = ( touchableNumber % 6 ) + 1;
357 int paddle = ( touchableNumber % 20 ) + 1;
358 std::string identity = "sector: " + std::to_string(sector) + ", paddle: " + std::to_string(paddle);
359 const auto& dimensions = {10.0, 20.0, 30.0};
360 const double& mass = 100 * CLHEP::g;
361
362 return std::make_shared<GTouchable>(logger, "readout", identity, dimensions, mass);
363 }
364
365private:
366 GTouchableType gType;
367 std::vector<GIdentifier> gidentity;
368 int trackId;
369 int pid;
370 double eMultiplier;
371 int stepTimeAtElectronicsIndex;
372 std::vector<double> detectorDimensions;
373 double mass;
374
376 friend std::ostream& operator<<(std::ostream& stream, const GTouchable& gtouchable);
377
379 static std::atomic<int> globalGTouchableCounter;
380};
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:141
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:333
std::vector< GIdentifier > getIdentity() const
Returns a copy of the identity vector.
Definition gtouchable.h:270
~GTouchable()
Destructor with debug trace.
Definition gtouchable.h:213
void assignPId(int p)
Assigns the particle id used by particle counter discrimination.
Definition gtouchable.h:239
bool operator==(const GTouchable &gtouchable) const
Compares two GTouchable instances using the module comparison semantics.
Definition gtouchable.cc:91
void assignTrackId(int tid)
Assigns the track id used by flux and dosimeter discrimination.
Definition gtouchable.h:230
void assignStepTimeAtElectronicsIndex(int timeIndex)
Assigns the electronics time-cell index used by readout discrimination.
Definition gtouchable.h:256
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:249
static std::shared_ptr< GTouchable > create(const std::shared_ptr< GLogger > &logger)
Creates a synthetic readout touchable for testing (logger-based).
Definition gtouchable.h:354
GTouchable & operator=(const GTouchable &)=default
double getMass() const
Returns the mass of the sensitive g4volume.
Definition gtouchable.h:300
int getStepTimeAtElectronicsIndex() const
Returns the electronics time-cell index.
Definition gtouchable.h:263
bool exists_in_vector(const std::vector< GTouchable > &v) const
Checks whether this touchable exists in a vector using operator== semantics.
Definition gtouchable.h:311
std::string getIdentityString() const
Builds a human-readable identity string from the stored identifiers.
Definition gtouchable.h:280
std::vector< double > getDetectorDimensions() const
Returns the detector dimensions stored at construction time.
Definition gtouchable.h:293
GTouchable(const std::shared_ptr< GTouchable > &base, int newTimeIndex)
Copy constructor that preserves identity but updates the electronics time-cell index.
Definition gtouchable.h:197
CONSTRUCTOR
DESTRUCTOR
Conventions and constants used by the gtouchable module.
#define INTEGRAL_COUNTERNAME
Digitization type name for integral_counter.
#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:32
@ flux
Definition gtouchable.h:34
@ integral_counter
Definition gtouchable.h:37
@ readout
Definition gtouchable.h:33
@ dosimeter
Definition gtouchable.h:36
@ particle_counter
Definition gtouchable.h:35
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:55
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