gsd
Loading...
Searching...
No Matches
gsd.h
Go to the documentation of this file.
1#pragma once
2
3// geant4
4#include "G4VSensitiveDetector.hh"
5
6// gemc
7#include "goptions.h"
9#include "gbase.h"
10
30constexpr int ERR_DYNAMICPLUGINNOTFOUND = 2001;
31
35constexpr int ERR_HITNOTFOUNDINCOLLECTION = 2002;
36
40constexpr int ERR_NOCOLLECTION = 2003;
41
47constexpr const char* GSENSITIVE_LOGGER = "gsd";
48
52
63
64} // namespace gsensitivedetector
65
73using GHitsCollection = G4THitsCollection<GHit>;
74
100class GSensitiveDetector : public GBase<GSensitiveDetector>, public G4VSensitiveDetector {
101
102public:
112 GSensitiveDetector(const std::string& sdName,
113 const std::shared_ptr<GOptions>& goptions);
114
126 void Initialize(G4HCofThisEvent* g4hc) override;
127
140 G4bool ProcessHits(G4Step* thisStep, G4TouchableHistory* g4th) override;
141
150 void EndOfEvent(G4HCofThisEvent* g4HitCollection) override;
151
159 void assign_digi_routine(std::shared_ptr<GDynamicDigitization> digi_routine) { digitization_routine = digi_routine; }
160
161private:
170 std::shared_ptr<GDynamicDigitization> digitization_routine;
171
178 HitBitSet gHitBitSet;
179
186 std::map<std::string, std::shared_ptr<GTouchable>> gTouchableMap;
187
197 inline std::shared_ptr<GTouchable> getGTouchable(const G4Step* thisStep) {
198 std::string vname = thisStep->GetPreStepPoint()->GetTouchable()->GetVolume()->GetName();
199
200 auto it = gTouchableMap.find(vname);
201 if (it != gTouchableMap.end()) { return it->second; }
202 // If not found, log an error. The calling code assumes a valid pointer.
203 log->error(ERR_DYNAMICPLUGINNOTFOUND, "GTouchable for volume " + vname + " not found in gTouchableMap");
204 }
205
212 std::vector<GTouchable> touchableVector;
213
223 bool isThisANewTouchable(const std::shared_ptr<GTouchable>& thisTouchable);
224
231 GHitsCollection* gHitsCollection;
232
241 GHit* getHitInHitCollectionUsingTouchable(const std::shared_ptr<GTouchable>& gtouchable);
242
243public:
253 inline void registerGVolumeTouchable(const std::string& name, std::shared_ptr<GTouchable> gt) {
254 log->info(2, "Registering touchable gvolume <" + name + "> with value: " + gt->getIdentityString());
255
256 // Store the GTouchable in the map; this module retains a shared ownership reference.
257 gTouchableMap[name] = gt;
258 }
259};
std::shared_ptr< GLogger > log
void info(int level, Args &&... args) const
void error(int exit_code, Args &&... args) const
Thread-local sensitive detector bridging Geant4 steps to GEMC hits via digitization plugins.
Definition gsd.h:100
GSensitiveDetector(const std::string &sdName, const std::shared_ptr< GOptions > &goptions)
Constructs a sensitive detector instance for a given detector name.
Definition gsd.cc:9
void EndOfEvent(G4HCofThisEvent *g4HitCollection) override
End-of-event hook called by Geant4.
Definition gsd.cc:133
void Initialize(G4HCofThisEvent *g4hc) override
Per-event initialization hook called by Geant4.
Definition gsd.cc:26
void assign_digi_routine(std::shared_ptr< GDynamicDigitization > digi_routine)
Assigns the digitization routine used to interpret steps and define hit content.
Definition gsd.h:159
G4bool ProcessHits(G4Step *thisStep, G4TouchableHistory *g4th) override
Processes a Geant4 step and creates or updates hits in the current hits collection.
Definition gsd.cc:50
void registerGVolumeTouchable(const std::string &name, std::shared_ptr< GTouchable > gt)
Registers a GTouchable for a given gvolume name into the internal lookup map.
Definition gsd.h:253
std::bitset< NHITBITS > HitBitSet
G4THitsCollection< GHit > GHitsCollection
GOptions defineOptions()
Defines the module options for GSensitiveDetector.
Definition gsd.h:62
constexpr int ERR_NOCOLLECTION
Error code used when the Geant4 hits collection is unexpectedly missing.
Definition gsd.h:40
constexpr int ERR_DYNAMICPLUGINNOTFOUND
Error code used when a required dynamic plugin-dependent resource is missing.
Definition gsd.h:30
constexpr int ERR_HITNOTFOUNDINCOLLECTION
Error code used when a hit is expected to exist but cannot be found in the current hit collection.
Definition gsd.h:35
constexpr const char * GSENSITIVE_LOGGER
Logger name used by this module.
Definition gsd.h:47