@@ -156,7 +156,6 @@ Bool_t Detector::ProcessHits(FairVolume* vol)
156156
157157 const float time = fMC ->TrackTime () * 1.0e9 ;
158158 const int trackID = fMC ->GetStack ()->GetCurrentTrackNumber ();
159- const int detID = vol->getMCid ();
160159 o2::data::Stack* stack = (o2::data::Stack*)fMC ->GetStack ();
161160 if (fMC ->IsTrackEntering () || fMC ->IsTrackExiting ()) {
162161 stack->addTrackReference (o2::TrackReference (position.X (), position.Y (), position.Z (), momentum.X (), momentum.Y (),
@@ -258,37 +257,38 @@ Bool_t Detector::ProcessHits(FairVolume* vol)
258257 }
259258
260259 // ADD HIT
261- static thread_local int oldTrackId = trackID;
262- static thread_local int oldDetId = detID;
263- static thread_local int groupCounter = 0 ;
264- static thread_local int oldSectorId = sectorID;
260+ // the first hit of an event starts the grouping afresh
261+ if (!mCurrentGroup ) {
262+ mOldTrackId = trackID;
263+ mOldSectorId = sectorID;
264+ mGroupCounter = 0 ;
265+ }
265266
266267 // a new group is starting -> put it into the container
267- static thread_local HitGroup* currentgroup = nullptr ;
268- if (groupCounter == 0 ) {
268+ if (mGroupCounter == 0 ) {
269269 mHitsPerSectorCollection [sectorID]->emplace_back (trackID);
270- currentgroup = &(mHitsPerSectorCollection [sectorID]->back ());
270+ mCurrentGroup = &(mHitsPerSectorCollection [sectorID]->back ());
271271 }
272- if (trackID == oldTrackId && oldSectorId == sectorID) {
273- groupCounter ++;
272+ if (trackID == mOldTrackId && mOldSectorId == sectorID) {
273+ mGroupCounter ++;
274274 mHitCounter ++;
275275 mElectronCounter += numberOfElectrons;
276- currentgroup ->addHit (position.X (), position.Y (), position.Z (), time, numberOfElectrons);
276+ mCurrentGroup ->addHit (position.X (), position.Y (), position.Z (), time, numberOfElectrons);
277277
278- // add last buffered hit, which was not yet added to the currentgroup
278+ // add last buffered hit, which was not yet added to the current group
279279 if (mHitLast .GetEnergyLoss () >= 0 ) {
280- currentgroup ->addHit (mHitLast .GetX (), mHitLast .GetY (), mHitLast .GetZ (), mHitLast .GetTime (), mHitLast .GetEnergyLoss ());
280+ mCurrentGroup ->addHit (mHitLast .GetX (), mHitLast .GetY (), mHitLast .GetZ (), mHitLast .GetTime (), mHitLast .GetEnergyLoss ());
281281 mHitLast .mELoss = -1 ;
282- groupCounter ++;
282+ mGroupCounter ++;
283283 mHitCounter ++;
284284 mElectronCounter += mHitLast .GetEnergyLoss ();
285285 }
286286 }
287287 // finish group
288288 else {
289- oldTrackId = trackID;
290- oldSectorId = sectorID;
291- groupCounter = 0 ;
289+ mOldTrackId = trackID;
290+ mOldSectorId = sectorID;
291+ mGroupCounter = 0 ;
292292
293293 // buffer this hit, otherwise it wouldnt be stored in the HitGroup
294294 mHitLast = ElementalHit (position.X (), position.Y (), position.Z (), time, numberOfElectrons);
@@ -310,6 +310,9 @@ Bool_t Detector::ProcessHits(FairVolume* vol)
310310
311311void Detector::EndOfEvent ()
312312{
313+ // the hit grouping must not carry over into the next event
314+ mCurrentGroup = nullptr ;
315+ mHitLast .mELoss = -1 ;
313316 if (!o2::utils::ShmManager::Instance ().isOperational ()) {
314317 for (int i = 0 ; i < Sector::MAXSECTOR ; ++i) {
315318 mHitsPerSectorCollection [i]->clear ();
0 commit comments