5#include "G4SDManager.hh"
9 const std::shared_ptr<GOptions>&
goptions) :
11 G4VSensitiveDetector(sdName) {
16 std::string hitCollectionName = sdName +
"__HitCollection";
17 collectionName.insert(hitCollectionName);
26 std::string sdName = GetName();
32 touchableVector.clear();
41 auto hcID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
42 g4hc->AddHitsCollection(hcID, gHitsCollection);
44 log->
info(2,
"Added collection id ", hcID,
" to G4HCofThisEvent");
51 double depe = thisStep->GetTotalEnergyDeposit();
57 std::vector<std::shared_ptr<GTouchable>> thisStepProcessedTouchables = digitization_routine->
processTouchable(getGTouchable(thisStep), thisStep);
59 auto hcsize = gHitsCollection->GetSize();
62 " with ", std::to_string(thisStepProcessedTouchables.size()),
" touchable(s), edep: ",
63 std::to_string(depe),
", Hit collection size: ", hcsize);
67 for (
auto thisGTouchable : thisStepProcessedTouchables) {
69 thisGTouchable->assignTrackId(thisStep->GetTrack()->GetTrackID());
71 if (isThisANewTouchable(thisGTouchable)) {
74 gHitsCollection->insert(
new GHit(thisGTouchable, gHitBitSet, thisStep));
79 GHit* existingHit = getHitInHitCollectionUsingTouchable(thisGTouchable);
88bool GSensitiveDetector::isThisANewTouchable(
const std::shared_ptr<GTouchable>& thisTouchable) {
89 log->
info(2,
"GSensitiveDetector::isThisANewTouchable for " + GetName(),
90 " with touchable: " + thisTouchable->getIdentityString());
92 if (thisTouchable->exists_in_vector(touchableVector)) {
93 log->
info(2,
" ❌ not a new GTouchable, it is found, retrieving hit...");
97 log->
info(2,
" ✅ yes, new GTouchable. Adding it to touchableVector.");
98 touchableVector.push_back(*thisTouchable);
104GHit* GSensitiveDetector::getHitInHitCollectionUsingTouchable(
const std::shared_ptr<GTouchable>&
gtouchable) {
105 for (
unsigned int i = 0; i < gHitsCollection->GetSize(); i++) {
106 GHit* thisHit = (*gHitsCollection)[i];
107 const std::shared_ptr<GTouchable>& thisHitGTouchable = thisHit->
getGTouchable();
110 log->
info(2,
"GSensitiveDetector::getHitInHitCollectionUsingTouchable for " + GetName() +
111 " found existing hit in collection for touchable: " +
gtouchable->getIdentityString() +
112 " at index: " + std::to_string(i));
std::shared_ptr< GLogger > log
std::vector< std::shared_ptr< GTouchable > > processTouchable(std::shared_ptr< GTouchable > gtouchable, G4Step *thisStep)
std::shared_ptr< const GReadoutSpecs > readoutSpecs
virtual bool decisionToSkipHit(double energy)
void addHitInfosForBitset(HitBitSet hbs, const G4Step *thisStep)
std::shared_ptr< GTouchable > getGTouchable() const
void debug(debug_type type, Args &&... args) const
void info(int level, Args &&... args) const
void error(int exit_code, Args &&... args) const
HitBitSet getHitBitSet() const
GSensitiveDetector(const std::string &sdName, const std::shared_ptr< GOptions > &goptions)
void EndOfEvent(G4HCofThisEvent *g4HitCollection) override
void Initialize(G4HCofThisEvent *g4hc) override
G4bool ProcessHits(G4Step *thisStep, G4TouchableHistory *g4th) override
constexpr int ERR_NOCOLLECTION
G4THitsCollection< GHit > GHitsCollection
constexpr int ERR_HITNOTFOUNDINCOLLECTION
constexpr const char * GSENSITIVE_LOGGER