gtouchable
Loading...
Searching...
No Matches
gtouchable.h
Go to the documentation of this file.
1#pragma once
2
3// gemc
4#include <gemc/gbase/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
41
42// ------------------------------------------------------------------------
43// Convert enum to string for logging / debugging.
44// ------------------------------------------------------------------------
45namespace gtouchable {
57 inline const char* to_string(GTouchableType t) {
58 switch (t) {
59 case GTouchableType::readout: return "readout";
60 case GTouchableType::flux: return FLUXNAME;
65 default: return "unknown-gtouchable";
66 }
67 }
68}
69
81{
82public:
89 GIdentifier(const std::string& n, int v) : idName{n}, idValue{v} {
90 }
91
100 bool operator==(const GIdentifier& gid) const { return this->idValue == gid.idValue; }
101
106 [[nodiscard]] inline std::string getName() const { return idName; }
107
112 [[nodiscard]] inline int getValue() const { return idValue; }
113
115 inline void setValue(int v) { idValue = v; }
116
117private:
118 std::string idName;
119 int idValue;
120
122 friend std::ostream& operator<<(std::ostream& stream, const GIdentifier& gidentifier);
123};
124
125
147class GTouchable : public GBase<GTouchable>
148{
149public:
150 GTouchable(const GTouchable&) = default;
151 GTouchable& operator=(const GTouchable&) = default;
152
167 GTouchable(const std::shared_ptr<GOptions>& gopt,
168 const std::string& digitization,
169 const std::string& gidentityString,
170 const std::vector<double>& dimensions,
171 const double& mass);
172
186 GTouchable(const std::shared_ptr<GLogger>& logger,
187 const std::string& digitization,
188 const std::string& gidentityString,
189 const std::vector<double>& dimensions,
190 const double& mass);
191
204 GTouchable(const std::shared_ptr<GTouchable>& base, int newTimeIndex)
205 : GBase<GTouchable>(*base),
206 gType(base->gType),
207 gidentity(base->gidentity),
208 trackId(base->trackId),
209 eMultiplier(base->eMultiplier),
210 stepTimeAtElectronicsIndex(newTimeIndex) {
211 log->debug(CONSTRUCTOR, "Copy-with-time-index", gtouchable::to_string(gType), " ", getIdentityString());
212 }
213
221
228 bool operator==(const GTouchable& gtouchable) const;
229
240 [[nodiscard]] std::string cellKey() const;
241
249 inline void assignTrackId(int tid) { trackId = tid; }
250
258 inline void assignPId(int p) { pid = p; }
259
268 [[nodiscard]] inline double getEnergyMultiplier() const { return eMultiplier; }
269
275 inline void assignStepTimeAtElectronicsIndex(int timeIndex) { stepTimeAtElectronicsIndex = timeIndex; }
276
282 [[nodiscard]] inline int getStepTimeAtElectronicsIndex() const { return stepTimeAtElectronicsIndex; }
283
289 [[nodiscard]] inline std::vector<GIdentifier> getIdentity() const { return gidentity; }
290
292 inline void setIdentityValue(size_t index, int value) { gidentity.at(index).setValue(value); }
293
302 [[nodiscard]] inline std::string getIdentityString() const {
303 std::string idString;
304 for (const auto& id : gidentity) { idString += id.getName() + ": " + std::to_string(id.getValue()) + " "; }
305 return idString;
306 }
307
315 [[nodiscard]] inline std::vector<double> getDetectorDimensions() const { return detectorDimensions; }
316
322 [[nodiscard]] inline double getMass() const { return mass; }
323
333 [[nodiscard]] bool exists_in_vector(const std::vector<GTouchable>& v) const {
334 for (const auto& gt : v) {
335 if (*this == gt) {
336 log->info(2, "GTouchable", this, " exists in vector.");
337 return true;
338 }
339 }
340 log->info(2, "GTouchable", this, " does not exist in vector.");
341
342 return false;
343 }
344
355 static std::shared_ptr<GTouchable> create(const std::shared_ptr<GOptions>& gopt) {
356 int touchableNumber = globalGTouchableCounter.fetch_add(1, std::memory_order_relaxed);
357 int sector = ( touchableNumber % 6 ) + 1;
358 int paddle = ( touchableNumber % 20 ) + 1;
359 std::string identity = "sector: " + std::to_string(sector) + ", paddle: " + std::to_string(paddle);
360 const auto& dimensions = {10.0, 20.0, 30.0};
361 const double& mass = 100 * CLHEP::g;
362
363 return std::make_shared<GTouchable>(gopt, "readout", identity, dimensions, mass);
364 }
365
376 static std::shared_ptr<GTouchable> create(const std::shared_ptr<GLogger>& logger) {
377 int touchableNumber = globalGTouchableCounter.fetch_add(1, std::memory_order_relaxed);
378 int sector = ( touchableNumber % 6 ) + 1;
379 int paddle = ( touchableNumber % 20 ) + 1;
380 std::string identity = "sector: " + std::to_string(sector) + ", paddle: " + std::to_string(paddle);
381 const auto& dimensions = {10.0, 20.0, 30.0};
382 const double& mass = 100 * CLHEP::g;
383
384 return std::make_shared<GTouchable>(logger, "readout", identity, dimensions, mass);
385 }
386
387private:
388 GTouchableType gType;
389 std::vector<GIdentifier> gidentity;
390 int trackId;
391 int pid;
392 double eMultiplier;
393 int stepTimeAtElectronicsIndex;
394 std::vector<double> detectorDimensions;
395 double mass;
396
398 friend std::ostream& operator<<(std::ostream& stream, const GTouchable& gtouchable);
399
401 inline static std::atomic<int> globalGTouchableCounter{0};
402};
GBase(const std::shared_ptr< GOptions > &gopt, std::string logger_name="")
std::shared_ptr< GLogger > log
Represents a touchable sensitive detector element used as a hit-collection discriminator.
Definition gtouchable.h:148
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:355
std::vector< GIdentifier > getIdentity() const
Returns a copy of the identity vector.
Definition gtouchable.h:289
~GTouchable()
Destructor with debug trace.
Definition gtouchable.h:220
void assignPId(int p)
Assigns the particle id used by particle counter discrimination.
Definition gtouchable.h:258
bool operator==(const GTouchable &gtouchable) const
Compares two GTouchable instances using the module comparison semantics.
Definition gtouchable.cc:90
void assignTrackId(int tid)
Assigns the track id used by flux and dosimeter discrimination.
Definition gtouchable.h:249
void setIdentityValue(size_t index, int value)
Overwrites the value of the identity element at index. Throws std::out_of_range if out of bounds.
Definition gtouchable.h:292
void assignStepTimeAtElectronicsIndex(int timeIndex)
Assigns the electronics time-cell index used by readout discrimination.
Definition gtouchable.h:275
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:268
static std::shared_ptr< GTouchable > create(const std::shared_ptr< GLogger > &logger)
Creates a synthetic readout touchable for testing (logger-based).
Definition gtouchable.h:376
GTouchable & operator=(const GTouchable &)=default
double getMass() const
Returns the mass of the sensitive g4volume.
Definition gtouchable.h:322
int getStepTimeAtElectronicsIndex() const
Returns the electronics time-cell index.
Definition gtouchable.h:282
std::string cellKey() const
Builds a compact key identifying the hit cell of this touchable.
bool exists_in_vector(const std::vector< GTouchable > &v) const
Checks whether this touchable exists in a vector using operator== semantics.
Definition gtouchable.h:333
std::string getIdentityString() const
Builds a human-readable identity string from the stored identifiers.
Definition gtouchable.h:302
std::vector< double > getDetectorDimensions() const
Returns the detector dimensions stored at construction time.
Definition gtouchable.h:315
GTouchable(const std::shared_ptr< GTouchable > &base, int newTimeIndex)
Copy constructor that preserves identity but updates the electronics time-cell index.
Definition gtouchable.h:204
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.
#define GPHOTON_DETECTORNAME
Digitization type name for optical-photon flux detectors.
GTouchableType
Enumeration representing the type of a touchable sensitive element.
Definition gtouchable.h:33
@ flux
Definition gtouchable.h:35
@ integral_counter
Definition gtouchable.h:39
@ readout
Definition gtouchable.h:34
@ dosimeter
Definition gtouchable.h:38
@ particle_counter
Definition gtouchable.h:37
@ gPhotonDetector
Definition gtouchable.h:36
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:57
A single (name,value) identifier element used to build a touchable identity vector.
Definition gtouchable.h:81
GIdentifier(const std::string &n, int v)
Constructs a GIdentifier.
Definition gtouchable.h:89
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:106
bool operator==(const GIdentifier &gid) const
Compares identifiers by value only.
Definition gtouchable.h:100
int getValue() const
Returns the identifier value.
Definition gtouchable.h:112
void setValue(int v)
Sets the identifier value. Used by digitization plugins that recompute the wire/layer address.
Definition gtouchable.h:115