@@ -1348,23 +1348,15 @@ GPUd() void GPUTPCGMMerger::MergeCE(int32_t nBlocks, int32_t nThreads, int32_t i
13481348 continue ;
13491349 }
13501350 bool celooper = (trk[0 ]->GetParam ().GetQPt () * Param ().qptB5Scaler > 1 && trk[0 ]->GetParam ().GetQPt () * trk[1 ]->GetParam ().GetQPt () < 0 );
1351+ celooper |= trk[0 ]->PrevSegment () != -1 && trk[1 ]->PrevSegment () != -1 ;
13511352 if (!celooper && trk[0 ]->GetParam ().GetPar (3 ) * trk[1 ]->GetParam ().GetPar (3 ) < 0 ) {
13521353 continue ;
13531354 }
13541355
1355- uint32_t newRef = CAMath::AtomicAdd (&mMemory ->nMergedTrackClusters , trk[0 ]->NClusters () + trk[1 ]->NClusters ());
1356- if (newRef + trk[0 ]->NClusters () + trk[1 ]->NClusters () >= mNMaxMergedTrackClusters ) {
1357- raiseError (GPUErrors::ERROR_MERGER_CE_HIT_OVERFLOW, newRef + trk[0 ]->NClusters () + trk[1 ]->NClusters (), mNMaxMergedTrackClusters );
1358- for (uint32_t k = newRef; k < mNMaxMergedTrackClusters ; k++) {
1359- mClusters [k].num = 0 ;
1360- mClusters [k].state = 0 ;
1361- }
1362- CAMath::AtomicExch (&mMemory ->nMergedTrackClusters , mNMaxMergedTrackClusters );
1363- return ;
1364- }
1365-
13661356 bool needswap = false ;
1367- if (celooper) {
1357+ if (trk[0 ]->PrevSegment () == -1 && trk[1 ]->PrevSegment () >= 0 ) {
1358+ needswap = true ;
1359+ } else if (celooper) {
13681360 const float z0max = -CAMath::Min (cls[mClusters [trk[0 ]->FirstClusterRef ()].num ].getTime (), cls[mClusters [trk[0 ]->FirstClusterRef () + trk[0 ]->NClusters () - 1 ].num ].getTime ());
13691361 const float z1max = -CAMath::Min (cls[mClusters [trk[1 ]->FirstClusterRef ()].num ].getTime (), cls[mClusters [trk[1 ]->FirstClusterRef () + trk[1 ]->NClusters () - 1 ].num ].getTime ());
13701362 if (z1max < z0max) {
@@ -1379,15 +1371,27 @@ GPUd() void GPUTPCGMMerger::MergeCE(int32_t nBlocks, int32_t nThreads, int32_t i
13791371 GPUCommonAlgorithm::swap (trk[0 ], trk[1 ]);
13801372 }
13811373
1382- if (celooper) {
1374+ if (celooper) { // TODO: Need propper handling, avoid falsely flagging the primary leg as looper
13831375 trk[0 ]->SetMergedLooperConnected (true );
13841376 trk[0 ]->SetCCE (true );
13851377 trk[0 ]->SetLooper (true );
1378+ trk[1 ]->SetMergedLooperConnected (true );
13861379 trk[1 ]->SetCCE (true );
13871380 trk[1 ]->SetLooper (true );
13881381 continue ;
13891382 }
13901383
1384+ uint32_t newRef = CAMath::AtomicAdd (&mMemory ->nMergedTrackClusters , trk[0 ]->NClusters () + trk[1 ]->NClusters ());
1385+ if (newRef + trk[0 ]->NClusters () + trk[1 ]->NClusters () >= mNMaxMergedTrackClusters ) {
1386+ raiseError (GPUErrors::ERROR_MERGER_CE_HIT_OVERFLOW, newRef + trk[0 ]->NClusters () + trk[1 ]->NClusters (), mNMaxMergedTrackClusters );
1387+ for (uint32_t k = newRef; k < mNMaxMergedTrackClusters ; k++) {
1388+ mClusters [k].num = 0 ;
1389+ mClusters [k].state = 0 ;
1390+ }
1391+ CAMath::AtomicExch (&mMemory ->nMergedTrackClusters , mNMaxMergedTrackClusters );
1392+ return ;
1393+ }
1394+
13911395 if (Param ().par .continuousTracking ) {
13921396 GPUTPCGMMergedTrackHit* clsmax;
13931397 const float tmax = CAMath::MaxWithRef (cls[mClusters [trk[0 ]->FirstClusterRef ()].num ].getTime (), cls[mClusters [trk[0 ]->FirstClusterRef () + trk[0 ]->NClusters () - 1 ].num ].getTime (),
@@ -1747,7 +1751,7 @@ GPUd() void GPUTPCGMMerger::CollectMergedTracks(int32_t nBlocks, int32_t nThread
17471751 mergedTrack.SetNClusters(0);
17481752 }
17491753 if (mergedTrack.NClusters() && mergedTrack.OK()) */
1750- if (Param ().rec .tpc .mergeCE ) {
1754+ if (leg == 0 && Param ().rec .tpc .mergeCE ) {
17511755 auto & cls = mConstantMem ->ioPtrs .clustersNative ->clustersLinear ;
17521756 bool CEside = cls[cl[0 ].num ].getTime () < cls[cl[nHits - 1 ].num ].getTime ();
17531757 MergeCEFill (trackParts[CEside ? lastTrackIndex : firstTrackIndex], cl[CEside ? (nHits - 1 ) : 0 ], iOutputTrack);
0 commit comments