From 961a3bb4719ee50b23a1845878634319f886ae5c Mon Sep 17 00:00:00 2001 From: Sandro Wenzel Date: Tue, 1 Dec 2026 14:11:27 +0100 Subject: [PATCH] Fix lost TPC hits and simplify the hit grouping This is fixing a bug where the TPC simulation lost a hit whenever a track had only one hit in a sector. Such a hit was buffered until the next one, then overwritten, and left an empty hit group behind. The last hit of an event could be lost in the same way. In 100 pp events this concerned 0.1% of the TPC hits but 2.6% of the TPC charge, since the lost hits carry on average 30 times the charge of a typical hit. The grouping now starts a new group whenever the track or the sector changes and stores every hit directly. The buffer and most of the grouping state are no longer needed, which makes the code considerably simpler. Note that hits inside a group are now in step order, so digits are only statistically identical to before. --- .../include/TPCSimulation/Detector.h | 5 +-- Detectors/TPC/simulation/src/Detector.cxx | 43 +++---------------- 2 files changed, 8 insertions(+), 40 deletions(-) diff --git a/Detectors/TPC/simulation/include/TPCSimulation/Detector.h b/Detectors/TPC/simulation/include/TPCSimulation/Detector.h index d937f2054383c..ff39966c346e3 100644 --- a/Detectors/TPC/simulation/include/TPCSimulation/Detector.h +++ b/Detectors/TPC/simulation/include/TPCSimulation/Detector.h @@ -157,11 +157,8 @@ class Detector : public o2::base::DetImpl int mElectronCounter = 0; int mStepCounter = 0; double mLastReferenceR = 0; /// put it into the container - if (mGroupCounter == 0) { - mHitsPerSectorCollection[sectorID]->emplace_back(trackID); - mCurrentGroup = &(mHitsPerSectorCollection[sectorID]->back()); - } - if (trackID == mOldTrackId && mOldSectorId == sectorID) { - mGroupCounter++; - mHitCounter++; - mElectronCounter += numberOfElectrons; - mCurrentGroup->addHit(position.X(), position.Y(), position.Z(), time, numberOfElectrons); - - // add last buffered hit, which was not yet added to the current group - if (mHitLast.GetEnergyLoss() >= 0) { - mCurrentGroup->addHit(mHitLast.GetX(), mHitLast.GetY(), mHitLast.GetZ(), mHitLast.GetTime(), mHitLast.GetEnergyLoss()); - mGroupCounter++; - mHitCounter++; - mElectronCounter += mHitLast.GetEnergyLoss(); - mHitLast.mELoss = -1; - } - } - // finish group - else { - mOldTrackId = trackID; - mOldSectorId = sectorID; - mGroupCounter = 0; - - // buffer this hit, otherwise it wouldnt be stored in the HitGroup - mHitLast = ElementalHit(position.X(), position.Y(), position.Z(), time, numberOfElectrons); + // start a new group for the first hit of an event and whenever the track or the sector changes + if (!mCurrentGroup || mCurrentGroup->GetTrackID() != trackID || mCurrentSector != sectorID) { + mCurrentGroup = &mHitsPerSectorCollection[sectorID]->emplace_back(trackID); + mCurrentSector = sectorID; } + mCurrentGroup->addHit(position.X(), position.Y(), position.Z(), time, numberOfElectrons); + mHitCounter++; + mElectronCounter += numberOfElectrons; // LOG(info) << "tpc::AddHit" << FairLogger::endl //<< " -- " << trackNumberID <<"," << volumeID << " " << vol->GetName() @@ -335,7 +307,6 @@ void Detector::EndOfEvent() { // the hit grouping must not carry over into the next event mCurrentGroup = nullptr; - mHitLast.mELoss = -1; if (!o2::utils::ShmManager::Instance().isOperational()) { for (int i = 0; i < Sector::MAXSECTOR; ++i) { mHitsPerSectorCollection[i]->clear();