diff --git a/gemc/gsd/gsd.h b/gemc/gsd/gsd.h index 334a44aa..4f516d54 100644 --- a/gemc/gsd/gsd.h +++ b/gemc/gsd/gsd.h @@ -195,7 +195,9 @@ class GSensitiveDetector : public GBase, public G4VSensitive std::string vname = thisStep->GetPreStepPoint()->GetTouchable()->GetVolume()->GetName(); auto it = gTouchableMap.find(vname); - if (it != gTouchableMap.end()) { return it->second; } + // Return a per-step copy: ProcessHits and processTouchable mutate trackId, pid and the + // time-cell index, so the registry entry must stay pristine across steps and events. + if (it != gTouchableMap.end()) { return std::make_shared(*it->second); } // If not found, log an error. The calling code assumes a valid pointer. log->error(ERR_DYNAMICPLUGINNOTFOUND, "GTouchable for volume " + vname + " not found in gTouchableMap"); }