Skip to content

Commit d80c5cb

Browse files
sawenzelclaude
andcommitted
Fix out-of-range hit access in the TOF hit merging
This fixes a crash in TOF ProcessHits when the first step of an event cannot be assigned to a pad. - Geo::getIndex returns -1 when the position does not resolve to a valid sector/plate/strip. - mLastChannelID is -1 at the start of every event, so channel == mLastChannelID holds, the || does not short-circuit, and mHits->back() is called on an empty vector, giving "free(): invalid pointer". - The merging condition now requires a non-empty hit vector and a valid channel, so an off-pad step always starts a new hit. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent e4eaccd commit d80c5cb

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

Detectors/TOF/simulation/src/Detector.cxx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ Bool_t Detector::ProcessHits(FairVolume* v)
103103
Geo::getPadDxDyDz(pos, det, delta);
104104
auto channel = Geo::getIndex(det);
105105
HitType newhit(posx, posy, posz, time, enDep, trackID, sensID);
106-
if (channel != mLastChannelID || !isMergable(newhit, mHits->back())) {
106+
// an invalid channel (getIndex returns -1 off a valid pad) never merges, and
107+
// there is nothing to merge with before the first hit of the event
108+
if (channel < 0 || mHits->empty() || channel != mLastChannelID || !isMergable(newhit, mHits->back())) {
107109
mHits->push_back(newhit);
108110
stack->addHit(GetDetId());
109111
} else {

0 commit comments

Comments
 (0)