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// - readout: electronic Time Window is the discriminating factor.
18// parameters and hitBitSet determined by defineReadoutSpecs in the plugin
19// - flux: track id is the discriminating factor, standard true infos variable
20// - particleCounter: no other discriminating factors, standard true infos variable
21// - dosimeter: track id is the discriminating factor, radiation digitization
22
23
42
43// ------------------------------------------------------------------------
44// Convert enum to string for logging / debugging.
45// ------------------------------------------------------------------------
46namespace gtouchable {
58 inline const char* to_string(GTouchableType t) {
59 switch (t) {
60 case GTouchableType::readout: return "readout";
61 case GTouchableType::flux: return FLUXNAME;
64 default: return "unknown-gtouchable";
65 }
66 }
67}
68
80{
81public:
88 GIdentifier(const std::string& n, int v) : idName{n}, idValue{v} {
89 }
90
99 bool operator==(const GIdentifier& gid) const { return this->idValue == gid.idValue; }
100
105 [[nodiscard]] inline std::string getName() const { return idName; }
106
111 [[nodiscard]] inline int getValue() const { return idValue; }
112
113private:
114 std::string idName;
115 int idValue;
116
118 friend std::ostream& operator<<(std::ostream& stream, const GIdentifier& gidentifier);
119};
120
121
141class GTouchable : public GBase<GTouchable>
142{
143public:
144 GTouchable(const GTouchable&) = default;
145 GTouchable& operator=(const GTouchable&) = default;
146
161 GTouchable(const std::shared_ptr<GOptions>& gopt,
162 const std::string& digitization,
163 const std::string& gidentityString,
164 const std::vector<double>& dimensions,
165 const double& mass);
166
180 GTouchable(const std::shared_ptr<GLogger>& logger,
181 const std::string& digitization,
182 const std::string& gidentityString,
183 const std::vector<double>& dimensions,
184 const double& mass);
185
198 GTouchable(const std::shared_ptr<GTouchable>& base, int newTimeIndex)
199 : GBase<GTouchable>(*base),
200 gType(base->gType),
201 gidentity(base->gidentity),
202 trackId(base->trackId),
203 eMultiplier(base->eMultiplier),
204 stepTimeAtElectronicsIndex(newTimeIndex) {
205 log->debug(CONSTRUCTOR, "Copy-with-time-index", gtouchable::to_string(gType), " ", getIdentityString());
206 }
207
215
222 bool operator==(const GTouchable& gtouchable) const;
223
231 inline void assignTrackId(int tid) { trackId = tid; }
232
241 [[nodiscard]] inline double getEnergyMultiplier() const { return eMultiplier; }
242
248 inline void assignStepTimeAtElectronicsIndex(int timeIndex) { stepTimeAtElectronicsIndex = timeIndex; }
249
255 [[nodiscard]] inline int getStepTimeAtElectronicsIndex() const { return stepTimeAtElectronicsIndex; }
256
262 [[nodiscard]] inline std::vector<GIdentifier> getIdentity() const { return gidentity; }
263
272 [[nodiscard]] inline std::string getIdentityString() const {
273 std::string idString;
274 for (const auto& id : gidentity) { idString += id.getName() + ": " + std::to_string(id.getValue()) + " "; }
275 return idString;
276 }
277
285 [[nodiscard]] inline std::vector<double> getDetectorDimensions() const { return detectorDimensions; }
286
292 [[nodiscard]] inline double getMass() const { return mass; }
293
303 [[nodiscard]] bool exists_in_vector(const std::vector<GTouchable>& v) const {
304 for (const auto& gt : v) {
305 if (*this == gt) {
306 log->info(2, "GTouchable", this, " exists in vector.");
307 return true;
308 }
309 }
310 log->info(2, "GTouchable", this, " does not exist in vector.");
311
312 return false;
313 }
314
325 static std::shared_ptr<GTouchable> create(const std::shared_ptr<GOptions>& gopt) {
326 int touchableNumber = globalGTouchableCounter.fetch_add(1, std::memory_order_relaxed);
327 int sector = ( touchableNumber % 6 ) + 1;
328 int paddle = ( touchableNumber % 20 ) + 1;
329 std::string identity = "sector: " + std::to_string(sector) + ", paddle: " + std::to_string(paddle);
330 const auto& dimensions = {10.0, 20.0, 30.0};
331 const double& mass = 100 * CLHEP::g;
332
333 return std::make_shared<GTouchable>(gopt, "readout", identity, dimensions, mass);
334 }
335
346 static std::shared_ptr<GTouchable> create(const std::shared_ptr<GLogger>& logger) {
347 int touchableNumber = globalGTouchableCounter.fetch_add(1, std::memory_order_relaxed);
348 int sector = ( touchableNumber % 6 ) + 1;
349 int paddle = ( touchableNumber % 20 ) + 1;
350 std::string identity = "sector: " + std::to_string(sector) + ", paddle: " + std::to_string(paddle);
351 const auto& dimensions = {10.0, 20.0, 30.0};
352 const double& mass = 100 * CLHEP::g;
353
354 return std::make_shared<GTouchable>(logger, "readout", identity, dimensions, mass);
355 }
356
357private:
358 GTouchableType gType;
359 std::vector<GIdentifier> gidentity;
360 int trackId;
361 double eMultiplier;
362 int stepTimeAtElectronicsIndex;
363 std::vector<double> detectorDimensions;
364 double mass;
365
367 friend std::ostream& operator<<(std::ostream& stream, const GTouchable& gtouchable);
368
370 static std::atomic<int> globalGTouchableCounter;
371};
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:142
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:325
std::vector< GIdentifier > getIdentity() const
Returns a copy of the identity vector.
Definition gtouchable.h:262
~GTouchable()
Destructor with debug trace.
Definition gtouchable.h:214
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:231
void assignStepTimeAtElectronicsIndex(int timeIndex)
Assigns the electronics time-cell index used by readout discrimination.
Definition gtouchable.h:248
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:241
static std::shared_ptr< GTouchable > create(const std::shared_ptr< GLogger > &logger)
Creates a synthetic readout touchable for testing (logger-based).
Definition gtouchable.h:346
GTouchable & operator=(const GTouchable &)=default
double getMass() const
Returns the mass of the sensitive g4volume.
Definition gtouchable.h:292
int getStepTimeAtElectronicsIndex() const
Returns the electronics time-cell index.
Definition gtouchable.h:255
bool exists_in_vector(const std::vector< GTouchable > &v) const
Checks whether this touchable exists in a vector using operator== semantics.
Definition gtouchable.h:303
std::string getIdentityString() const
Builds a human-readable identity string from the stored identifiers.
Definition gtouchable.h:272
std::vector< double > getDetectorDimensions() const
Returns the detector dimensions stored at construction time.
Definition gtouchable.h:285
GTouchable(const std::shared_ptr< GTouchable > &base, int newTimeIndex)
Copy constructor that preserves identity but updates the electronics time-cell index.
Definition gtouchable.h:198
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:36
@ flux
Flux-like discrimination using track id.
Definition gtouchable.h:38
@ particleCounter
Identity vector only; no additional discriminating factor.
Definition gtouchable.h:39
@ readout
Electronic readout with time-window discrimination (time-cell index).
Definition gtouchable.h:37
@ dosimeter
Radiation digitization; discrimination using track id.
Definition gtouchable.h:40
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:58
A single (name,value) identifier element used to build a touchable identity vector.
Definition gtouchable.h:80
GIdentifier(const std::string &n, int v)
Constructs a GIdentifier.
Definition gtouchable.h:88
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:105
bool operator==(const GIdentifier &gid) const
Compares identifiers by value only.
Definition gtouchable.h:99
int getValue() const
Returns the identifier value.
Definition gtouchable.h:111