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();