@@ -85,10 +85,8 @@ GPUd() bool GPUTPCGMTrackParam::Fit(GPUTPCGMMerger* GPUrestrict() merger, int32_
8585 float sumInvSqrtCharge = 0 .f ;
8686 int32_t nAvgCharge = 0 ;
8787
88- if (iWay) {
89- if (iWay && ((nWays - iWay) & 1 ) == 1 ) {
90- StoreOuter (&track.OuterParam (), prop.GetAlpha ());
91- }
88+ if (iWay && ((nWays - iWay) & 1 ) == 1 ) {
89+ StoreOuter (&track.OuterParam (), prop.GetAlpha ());
9290 }
9391
9492 int32_t resetT0 = initResetT0 ();
@@ -106,16 +104,14 @@ GPUd() bool GPUTPCGMTrackParam::Fit(GPUTPCGMMerger* GPUrestrict() merger, int32_
106104
107105 N = 0 ;
108106 lastUpdateX = -1 ;
109- const bool inFlyDirection = ( track.Leg () & 1 );
107+ const bool inFlyDirection = !(( track.Leg () ^ iWay ^ nWays ) & 1 );
110108 const int32_t wayDirection = (iWay & 1 ) ? -1 : 1 ;
111109
112- bool noFollowCircle = false , noFollowCircle2 = false ;
113110 int32_t goodRows = 0 ;
114111 for (int32_t ihit = ihitStart; ihit >= 0 && ihit < maxN; ihit += wayDirection) {
115112 const bool crossCE = lastSector != 255 && ((lastSector < 18 ) ^ (clusters[ihit].sector < 18 ));
116113 if (crossCE) {
117114 lastSector = clusters[ihit].sector ;
118- noFollowCircle2 = true ;
119115 }
120116
121117 if ((param.rec .tpc .trackFitRejectMode > 0 && nMissed >= param.rec .tpc .trackFitRejectMode ) || nMissed2 >= param.rec .tpc .trackFitMaxRowMissedHard || clusters[ihit].state & GPUTPCGMMergedTrackHit::flagReject) {
@@ -160,14 +156,7 @@ GPUd() bool GPUTPCGMTrackParam::Fit(GPUTPCGMMerger* GPUrestrict() merger, int32_
160156 // clang-format off
161157 CADEBUG (printf (" \t Sector %2d %4sTrack Alpha %8.3f %s, X %8.3f - Y %8.3f, Z %8.3f - QPt %7.2f (%7.2f), SP %5.2f (%5.2f) %28s --- Cov sY %8.3f sZ %8.3f sSP %8.3f sPt %8.3f - YPt %8.3f\n " , (int32_t )cluster.sector , " " , prop.GetAlpha (), (CAMath::Abs (prop.GetAlpha () - clAlpha) < 0.01 ? " " : " R!" ), mX , mP [0 ], mP [1 ], mP [4 ], prop.GetQPt0 (), mP [2 ], prop.GetSinPhi0 (), " " , sqrtf (mC [0 ]), sqrtf (mC [2 ]), sqrtf (mC [5 ]), sqrtf (mC [14 ]), mC [10 ]));
162158 // clang-format on
163- if (allowModification && false /* changeDirection*/ && !noFollowCircle && !noFollowCircle2) {
164- if (lastRow != 255 ) {
165- if (!(merger->Param ().rec .tpc .disableRefitAttachment & 4 )) {
166- StoreAttachMirror (merger, lastSector, lastRow, iTrk, clAlpha, yy, xx, cluster.sector , cluster.row , inFlyDirection, prop.GetAlpha ());
167- noFollowCircle = true ;
168- }
169- }
170- } else if (allowModification && lastRow != 255 && CAMath::Abs (cluster.row - lastRow) > 1 ) {
159+ if (allowModification && lastRow != 255 && CAMath::Abs (cluster.row - lastRow) > 1 ) {
171160 if GPUCA_RTC_CONSTEXPR (GPUCA_GET_CONSTEXPR (param.par , dodEdx)) {
172161 bool dodEdx = param.dodEdxEnabled && param.rec .tpc .adddEdxSubThresholdClusters && iWay == nWays - 1 && CAMath::Abs (cluster.row - lastRow) == 2 ;
173162 dodEdx = AttachClustersPropagate (merger, cluster.sector , lastRow, cluster.row , iTrk, track.Leg () == 0 , prop, inFlyDirection, GPUCA_MAX_SIN_PHI, dodEdx);
@@ -180,23 +169,23 @@ GPUd() bool GPUTPCGMTrackParam::Fit(GPUTPCGMMerger* GPUrestrict() merger, int32_
180169 }
181170 }
182171
183- int32_t err = prop.PropagateToXAlpha (xx, clAlpha, inFlyDirection);
172+ int32_t retValProp = prop.PropagateToXAlpha (xx, clAlpha, inFlyDirection);
184173 // clang-format off
185174 CADEBUG (if (!CheckCov ()){printf (" INVALID COV AFTER PROPAGATE!!!\n " );});
186175 // clang-format on
187- if (err == -2 ) // Rotation failed, try to bring to new x with old alpha first, rotate, and then propagate to x, alpha
176+ if (retValProp == -2 ) // Rotation failed, try to bring to new x with old alpha first, rotate, and then propagate to x, alpha
188177 {
189178 CADEBUG (printf (" REROTATE\n " ));
190179 if (prop.PropagateToXAlpha (xx, prop.GetAlpha (), inFlyDirection) == 0 ) {
191- err = prop.PropagateToXAlpha (xx, clAlpha, inFlyDirection);
180+ retValProp = prop.PropagateToXAlpha (xx, clAlpha, inFlyDirection);
192181 }
193182 }
194183 if (lastRow == 255 || CAMath::Abs ((int32_t )lastRow - (int32_t )cluster.row ) > 5 || lastSector != cluster.sector || (param.rec .tpc .trackFitRejectMode < 0 && -nMissed <= param.rec .tpc .trackFitRejectMode )) {
195184 goodRows = 0 ;
196185 } else {
197186 goodRows++;
198187 }
199- if (err == 0 ) {
188+ if (retValProp == 0 ) {
200189 lastRow = cluster.row ;
201190 lastSector = cluster.sector ;
202191 }
@@ -216,51 +205,28 @@ GPUd() bool GPUTPCGMTrackParam::Fit(GPUTPCGMMerger* GPUrestrict() merger, int32_
216205 }
217206 }
218207
219- if (err == 0 && false /* changeDirection*/ ) {
220- const float mirrordY = prop.GetMirroredYTrack ();
221- CADEBUG (printf (" -- MirroredY: %f --> %f" , mP [0 ], mirrordY));
222- if (CAMath::Abs (yy - mP [0 ]) > CAMath::Abs (yy - mirrordY)) {
223- CADEBUG (printf (" - Mirroring!!!" ));
224- if (allowModification && !(merger->Param ().rec .tpc .disableRefitAttachment & 8 )) {
225- StoreAttachMirror (merger, cluster.sector , cluster.row , iTrk, 0 , yy, 0 , -1 , 0 , 0 , prop.GetAlpha ());
226- }
227- MirrorTo (prop, yy, zz, inFlyDirection, param, cluster.row , clusterState, true , cluster.sector );
228- noFollowCircle = false ;
229-
230- lastUpdateX = mX ;
231- lastRow = 255 ;
232- N++;
233- resetT0 = initResetT0 ();
234- // clang-format off
235- CADEBUG (printf (" \n " ));
236- CADEBUG (printf (" \t %21sMirror Alpha %8.3f , X %8.3f - Y %8.3f, Z %8.3f - QPt %7.2f (%7.2f), SP %5.2f (%5.2f) %28s --- Cov sY %8.3f sZ %8.3f sSP %8.3f sPt %8.3f - YPt %8.3f\n " , " " , prop.GetAlpha (), mX , mP [0 ], mP [1 ], mP [4 ], prop.GetQPt0 (), mP [2 ], prop.GetSinPhi0 (), " " , sqrtf (mC [0 ]), sqrtf (mC [2 ]), sqrtf (mC [5 ]), sqrtf (mC [14 ]), mC [10 ]));
237- // clang-format on
238- continue ;
239- }
240- }
241-
242208 float uncorrectedY = -1e6f;
243209 if (allowModification) {
244210 uncorrectedY = AttachClusters (merger, cluster.sector , cluster.row , iTrk, track.Leg () == 0 , prop);
245211 }
246212
247- const int32_t err2 = mNDF > 0 && CAMath::Abs (prop.GetSinPhi0 ()) >= maxSinForUpdate;
248- if (err || err2 ) {
213+ const bool sinPhiErr = mNDF > 0 && CAMath::Abs (prop.GetSinPhi0 ()) >= maxSinForUpdate;
214+ if (retValProp || sinPhiErr ) {
249215 if (mC [0 ] > param.rec .tpc .trackFitCovLimit || mC [2 ] > param.rec .tpc .trackFitCovLimit ) {
250216 break ;
251217 }
252218 MarkClusters (clusters, ihitMergeFirst, ihit, wayDirection, GPUTPCGMMergedTrackHit::flagHighIncl);
253219 nMissed2++;
254220 NTolerated++;
255- CADEBUG (printf (" --- break (%d, %d)\n " , err, err2 ));
221+ CADEBUG (printf (" --- break (%d, %d)\n " , retValProp, ( int32_t )sinPhiErr ));
256222 continue ;
257223 }
258224 CADEBUG (printf (" \n " ));
259225
260- int32_t retVal ;
226+ int32_t retValUpd ;
261227 float threshold = 3 .f + (lastUpdateX >= 0 ? (CAMath::Abs (mX - lastUpdateX) / 2 ) : 0 .f );
262228 if (mNDF > 5 && (CAMath::Abs (yy - mP [0 ]) > threshold || CAMath::Abs (zz - mP [1 ]) > threshold)) {
263- retVal = GPUTPCGMPropagator::updateErrorClusterRejectedDistance;
229+ retValUpd = GPUTPCGMPropagator::updateErrorClusterRejectedDistance;
264230 } else {
265231 int8_t rejectChi2 = attempt ? 0 : ((param.rec .tpc .mergerInterpolateErrors && CAMath::Abs (ihit - ihitMergeFirst) <= 1 ) ? (refit ? (GPUTPCGMPropagator::rejectInterFill + ((nWays - iWay) & 1 )) : 0 ) : (allowModification && goodRows > 5 ));
266232#if EXTRACT_RESIDUALS == 1
@@ -284,28 +250,27 @@ GPUd() bool GPUTPCGMTrackParam::Fit(GPUTPCGMMerger* GPUrestrict() merger, int32_
284250#endif
285251 GPUCA_DEBUG_STREAMER_CHECK (GPUTPCGMPropagator::DebugStreamerVals debugVals;);
286252 if (param.rec .tpc .rejectEdgeClustersInTrackFit && uncorrectedY > -1e6f && param.rejectEdgeClusterByY (uncorrectedY, cluster.row , CAMath::Sqrt (mC [0 ]))) { // uncorrectedY > -1e6f implies allowModification
287- retVal = GPUTPCGMPropagator::updateErrorClusterRejectedEdge;
253+ retValUpd = GPUTPCGMPropagator::updateErrorClusterRejectedEdge;
288254 } else {
289255 const float time = merger->GetConstantMem ()->ioPtrs .clustersNative ? merger->GetConstantMem ()->ioPtrs .clustersNative ->clustersLinear [cluster.num ].getTime () : -1 .f ;
290256 const float invSqrtCharge = merger->GetConstantMem ()->ioPtrs .clustersNative ? CAMath::InvSqrt (merger->GetConstantMem ()->ioPtrs .clustersNative ->clustersLinear [cluster.num ].qMax ) : 0 .f ;
291257 const float invCharge = merger->GetConstantMem ()->ioPtrs .clustersNative ? (1 .f / merger->GetConstantMem ()->ioPtrs .clustersNative ->clustersLinear [cluster.num ].qMax ) : 0 .f ;
292258 float invAvgCharge = (sumInvSqrtCharge += invSqrtCharge) / ++nAvgCharge;
293259 invAvgCharge *= invAvgCharge;
294- retVal = prop.Update (yy, zz, cluster.row , param, clusterState, rejectChi2, &interpolation.hit [ihit], refit, cluster.sector , time, invAvgCharge, invCharge GPUCA_DEBUG_STREAMER_CHECK (, &debugVals));
260+ retValUpd = prop.Update (yy, zz, cluster.row , param, clusterState, rejectChi2, &interpolation.hit [ihit], refit, cluster.sector , time, invAvgCharge, invCharge GPUCA_DEBUG_STREAMER_CHECK (, &debugVals));
295261 }
296262 GPUCA_DEBUG_STREAMER_CHECK (if (o2::utils::DebugStreamer::checkStream (o2::utils::StreamFlags::streamUpdateTrack, iTrk)) {
297- merger->DebugStreamerUpdate (iTrk, ihit, xx, yy, zz, cluster, merger->GetConstantMem ()->ioPtrs .clustersNative ->clustersLinear [cluster.num ], *this , prop, interpolation.hit [ihit], rejectChi2, refit, retVal , sumInvSqrtCharge / nAvgCharge * sumInvSqrtCharge / nAvgCharge, yy, zz, clusterState, debugVals.retVal , debugVals.err2Y , debugVals.err2Z );
263+ merger->DebugStreamerUpdate (iTrk, ihit, xx, yy, zz, cluster, merger->GetConstantMem ()->ioPtrs .clustersNative ->clustersLinear [cluster.num ], *this , prop, interpolation.hit [ihit], rejectChi2, refit, retValUpd , sumInvSqrtCharge / nAvgCharge * sumInvSqrtCharge / nAvgCharge, yy, zz, clusterState, debugVals.retVal , debugVals.err2Y , debugVals.err2Z );
298264 });
299265 }
300266 // clang-format off
301267 CADEBUG (if (!CheckCov ()) GPUError (" INVALID COV AFTER UPDATE!!!" ));
302- CADEBUG (printf (" \t %21sFit Alpha %8.3f , X %8.3f - Y %8.3f, Z %8.3f - QPt %7.2f (%7.2f), SP %5.2f (%5.2f), DzDs %5.2f %16s --- Cov sY %8.3f sZ %8.3f sSP %8.3f sPt %8.3f - YPt %8.3f - Err %d\n " , " " , prop.GetAlpha (), mX , mP [0 ], mP [1 ], mP [4 ], prop.GetQPt0 (), mP [2 ], prop.GetSinPhi0 (), mP [3 ], " " , sqrtf (mC [0 ]), sqrtf (mC [2 ]), sqrtf (mC [5 ]), sqrtf (mC [14 ]), mC [10 ], retVal ));
268+ CADEBUG (printf (" \t %21sFit Alpha %8.3f , X %8.3f - Y %8.3f, Z %8.3f - QPt %7.2f (%7.2f), SP %5.2f (%5.2f), DzDs %5.2f %16s --- Cov sY %8.3f sZ %8.3f sSP %8.3f sPt %8.3f - YPt %8.3f - Err %d\n " , " " , prop.GetAlpha (), mX , mP [0 ], mP [1 ], mP [4 ], prop.GetQPt0 (), mP [2 ], prop.GetSinPhi0 (), mP [3 ], " " , sqrtf (mC [0 ]), sqrtf (mC [2 ]), sqrtf (mC [5 ]), sqrtf (mC [14 ]), mC [10 ], retValUpd ));
303269 // clang-format on
304270
305271 ConstrainSinPhi ();
306- if (retVal == 0 ) // track is updated
272+ if (retValUpd == 0 ) // track is updated
307273 {
308- noFollowCircle2 = false ;
309274 lastUpdateX = mX ;
310275 covYYUpd = mC [0 ];
311276 nMissed = nMissed2 = 0 ;
@@ -346,7 +311,7 @@ GPUd() bool GPUTPCGMTrackParam::Fit(GPUTPCGMMerger* GPUrestrict() merger, int32_
346311 }
347312 }
348313 }
349- } else if (retVal >= GPUTPCGMPropagator::updateErrorClusterRejected) { // cluster far away form the track
314+ } else if (retValUpd >= GPUTPCGMPropagator::updateErrorClusterRejected) { // cluster far away form the track
350315 if (allowModification) {
351316 MarkClusters (clusters, ihitMergeFirst, ihit, wayDirection, GPUTPCGMMergedTrackHit::flagRejectDistance);
352317 } else if (iWay == nWays - 1 ) {
@@ -358,6 +323,9 @@ GPUd() bool GPUTPCGMTrackParam::Fit(GPUTPCGMMerger* GPUrestrict() merger, int32_
358323 break ; // bad chi2 for the whole track, stop the fit
359324 }
360325 }
326+ if (nWays - iWay <= 2 && !(merger->Param ().rec .tpc .disableRefitAttachment & 4 )) {
327+ StoreLoopPropagation (merger, lastSector, lastRow, iTrk, inFlyDirection, prop.GetAlpha ());
328+ }
361329 if (((nWays - iWay) & 1 ) && (iWay != nWays - 1 ) && !track.CCE () && !track.Looper ()) {
362330 ShiftZ (clusters, merger, maxN);
363331 }
@@ -639,7 +607,7 @@ GPUdii() void GPUTPCGMTrackParam::StoreOuter(gputpcgmmergertypes::GPUTPCOuterPar
639607 outerParam->alpha = alpha;
640608}
641609
642- GPUdic (0 , 1 ) void GPUTPCGMTrackParam::StoreAttachMirror (const GPUTPCGMMerger* GPUrestrict () Merger, int32_t sector, int32_t iRow, int32_t iTrack, float toAlpha, float toY, float toX, int32_t toSector, int32_t toRow , bool inFlyDirection, float alpha)
610+ GPUdic (0 , 1 ) void GPUTPCGMTrackParam::StoreLoopPropagation (const GPUTPCGMMerger* GPUrestrict () Merger, int32_t sector, int32_t iRow, int32_t iTrack, bool inFlyDirection, float alpha)
643611{
644612 uint32_t nLoopData = CAMath::AtomicAdd (&Merger->Memory ()->nLoopData , 1u );
645613 if (nLoopData >= Merger->NMaxTracks ()) {
@@ -649,20 +617,14 @@ GPUdic(0, 1) void GPUTPCGMTrackParam::StoreAttachMirror(const GPUTPCGMMerger* GP
649617 }
650618 GPUTPCGMLoopData data;
651619 data.param = *this ;
652- data.alpha = alpha;
653620 data.track = iTrack;
654- data.toAlpha = toAlpha;
655- data.toY = toY;
656- data.toX = toX;
621+ data.alpha = alpha;
657622 data.sector = sector;
658- data.row = iRow;
659- data.toSector = toSector;
660- data.toRow = toRow;
661623 data.inFlyDirection = inFlyDirection;
662624 Merger->LoopData ()[nLoopData] = data;
663625}
664626
665- GPUdii () void GPUTPCGMTrackParam::RefitLoop (const GPUTPCGMMerger* GPUrestrict () Merger, int32_t loopIdx)
627+ GPUdii () void GPUTPCGMTrackParam::PropagateLooper (const GPUTPCGMMerger* GPUrestrict () Merger, int32_t loopIdx)
666628{
667629 GPUTPCGMPropagator prop;
668630 prop.SetMaterialTPC ();
@@ -675,11 +637,8 @@ GPUdii() void GPUTPCGMTrackParam::RefitLoop(const GPUTPCGMMerger* GPUrestrict()
675637
676638 GPUTPCGMLoopData& data = Merger->LoopData ()[loopIdx];
677639 prop.SetTrack (&data.param , data.alpha );
678- if (data.toSector == -1 ) {
679- data.param .AttachClustersMirror (Merger, data.sector , data.row , data.track , data.toY , prop);
680- } else {
681- data.param .FollowCircle (Merger, prop, data.sector , data.row , data.track , data.toAlpha , data.toX , data.toY , data.toSector , data.toRow , data.inFlyDirection );
682- }
640+ data.param .AttachClustersLooper (Merger, data.sector , data.row , data.track , prop);
641+ // data.param.FollowCircle(Merger, prop, data.sector, data.row, data.track, data.toAlpha, data.toX, data.toY, data.toSector, data.toRow, data.inFlyDirection);
683642}
684643
685644GPUdi () int32_t GPUTPCGMTrackParam::FollowCircle(const GPUTPCGMMerger* GPUrestrict () Merger, GPUTPCGMPropagator& GPUrestrict() prop, int32_t sector, int32_t iRow, int32_t iTrack, float toAlpha, float toX, float toY, int32_t toSector, int32_t toRow, bool inFlyDirection)
@@ -778,12 +737,11 @@ GPUdi() int32_t GPUTPCGMTrackParam::FollowCircle(const GPUTPCGMMerger* GPUrestri
778737 return (0 );
779738}
780739
781- GPUdi () void GPUTPCGMTrackParam::AttachClustersMirror (const GPUTPCGMMerger* GPUrestrict () Merger, int32_t sector, int32_t iRow, int32_t iTrack, float toY , GPUTPCGMPropagator& GPUrestrict() prop)
740+ GPUdi () void GPUTPCGMTrackParam::AttachClustersLooper (const GPUTPCGMMerger* GPUrestrict () Merger, int32_t sector, int32_t iRow, int32_t iTrack, GPUTPCGMPropagator& GPUrestrict() prop)
782741{
783742 static constexpr float kSectAngle = 2 * M_PI / 18 .f ;
784743 // Note that the coordinate system is rotated by 90 degree swapping X and Y!
785744 float X = mP [2 ] > 0 ? mP [0 ] : -mP [0 ];
786- float toX = mP [2 ] > 0 ? toY : -toY;
787745 float Y = mP [2 ] > 0 ? -mX : mX ;
788746 float Z = mP [1 ];
789747 if (CAMath::Abs (mP [2 ]) >= GPUCA_MAX_SIN_PHI_LOW) {
@@ -795,16 +753,13 @@ GPUdi() void GPUTPCGMTrackParam::AttachClustersMirror(const GPUTPCGMMerger* GPUr
795753 }
796754 float b = prop.GetBz (prop.GetAlpha (), mX , mP [0 ], mP [1 ]);
797755
798- int32_t count = CAMath::Float2IntRn (CAMath::Abs ((toX - X) * 2 .f ));
799- if (count == 0 ) {
800- return ;
801- }
802- float dx = (toX - X) / count;
756+ float dx = 0 .5f ;
803757 const float myRowX = GPUTPCGeometry::Row2X (iRow);
804758 // printf("AttachMirror\n");
805759 // printf("X %f Y %f Z %f SinPhi %f toY %f -->\n", mX, mP[0], mP[1], mP[2], toY);
806760 // printf("X %f Y %f Z %f SinPhi %f, count %d dx %f (to: %f)\n", X, Y, Z, SinPhi, count, dx, X + count * dx);
807- while (count--) {
761+ uint32_t maxT ries = 100 ;
762+ while (maxTries--) {
808763 float ex = CAMath::Sqrt (1 - SinPhi * SinPhi);
809764 float exi = 1 .f / ex;
810765 float dxBzQ = dx * -b * mP [4 ];
0 commit comments