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
11constexpr int ERR_DYNAMICPLUGINNOTFOUND = 2001;
12constexpr int ERR_HITNOTFOUNDINCOLLECTION = 2002;
13constexpr int ERR_NOCOLLECTION = 2003;
14constexpr const char* GSENSITIVE_LOGGER = "gsd";
15
19
20
21using GHitsCollection = G4THitsCollection<GHit>;
22
23// this is thread-local
24class GSensitiveDetector : public GBase<GSensitiveDetector>, public G4VSensitiveDetector {
25
26public:
27 GSensitiveDetector(const std::string& sdName,
28 const std::shared_ptr<GOptions>& goptions);
29
30
31 // G4VSensitiveDetector geant4 methods to be overloaded
32 void Initialize(G4HCofThisEvent* g4hc) override; // Beginning of sensitive Hit
33 G4bool ProcessHits(G4Step* thisStep, G4TouchableHistory* g4th) override; // Process Step, add new hit to gHitsCollection or new step to a ghit
34 void EndOfEvent(G4HCofThisEvent* g4HitCollection) override; // End of sensitive Hit
35
36 void assign_digi_routine(std::shared_ptr<GDynamicDigitization> digi_routine) { digitization_routine = digi_routine; }
37
38private:
39
40 // thread local - digitization for this sensitive detector
41 std::shared_ptr<GDynamicDigitization> digitization_routine;
42
43 // defines what information to be stored in the hit
44 // set at construction, so we do not spend time retrieving it
45 HitBitSet gHitBitSet;
46
47 // map of touchables. one entry per gvolume
48 // used to retrieve the touchable from the geant4 volume in which the step occurs during processHit
49 std::map<std::string, std::shared_ptr<GTouchable>> gTouchableMap;
50
51 // retrieve GTouchable from map
52 // gTouchableMap[vname] is guaranteed to exist because
53 // the map is populated (registered) at detector construction (GDetectorConstruction::ConstructSDandField)
54 // using the public function registerGVolumeTouchable
55 inline std::shared_ptr<GTouchable> getGTouchable(const G4Step* thisStep) {
56 std::string vname = thisStep->GetPreStepPoint()->GetTouchable()->GetVolume()->GetName();
57
58 auto it = gTouchableMap.find(vname);
59 if (it != gTouchableMap.end()) { return it->second; }
60 // if not found, log an error
61 log->error(ERR_DYNAMICPLUGINNOTFOUND, "GTouchable for volume " + vname + " not found in gTouchableMap");
62 }
63
64 // GTouchable vector, reset each event,
65 // used to decide if this is a new hit or not
66 std::vector<GTouchable> touchableVector;
67
68 // checking if it is present in the map. If not, add it
69 bool isThisANewTouchable(const std::shared_ptr<GTouchable>& thisTouchable);
70
71 // GHitsCollection is G4THitsCollection<GHit>
72 // GHit is a G4VHit. Its thread memory management comes with geant4
73 // The collection of pointers is used in G4GRun, passed to the digitizer plugins
74 GHitsCollection* gHitsCollection;
75
76 // retrieve hit with existing gtouchable
77 GHit* getHitInHitCollectionUsingTouchable(const std::shared_ptr<GTouchable>& gtouchable);
78
79public:
80 // register GTouchable in gTouchableMap
81
82 // used in GDetectorConstruction::ConstructSDandField()
83 inline void registerGVolumeTouchable(const std::string& name, std::shared_ptr<GTouchable> gt) {
84 log->info(2, "Registering touchable gvolume <" + name + "> with value: " + gt->getIdentityString());
85
86 gTouchableMap[name] = gt; // store the GTouchable in the map, we own it now
87 }
88
89
90};
std::shared_ptr< GLogger > log
void info(int level, Args &&... args) const
void error(int exit_code, Args &&... args) const
GSensitiveDetector(const std::string &sdName, const std::shared_ptr< GOptions > &goptions)
Definition gsd.cc:8
void EndOfEvent(G4HCofThisEvent *g4HitCollection) override
Definition gsd.cc:122
void Initialize(G4HCofThisEvent *g4hc) override
Definition gsd.cc:25
void assign_digi_routine(std::shared_ptr< GDynamicDigitization > digi_routine)
Definition gsd.h:36
G4bool ProcessHits(G4Step *thisStep, G4TouchableHistory *g4th) override
Definition gsd.cc:49
void registerGVolumeTouchable(const std::string &name, std::shared_ptr< GTouchable > gt)
Definition gsd.h:83
std::bitset< NHITBITS > HitBitSet
G4THitsCollection< GHit > GHitsCollection
constexpr int ERR_NOCOLLECTION
Definition gsd.h:13
constexpr int ERR_DYNAMICPLUGINNOTFOUND
Definition gsd.h:11
constexpr int ERR_HITNOTFOUNDINCOLLECTION
Definition gsd.h:12
constexpr const char * GSENSITIVE_LOGGER
Definition gsd.h:14
GOptions defineOptions()
Definition gsd.h:17