96GPUTRDTracker_t<TRDTRK, PROP>::GPUTRDTracker_t() : mR(nullptr), mIsInitialized(false), mGenerateSpacePoints(false), mProcessPerTimeFrame(false), mNAngleHistogramBins(25), mAngleHistogramRange(50), mMemoryPermanent(-1), mMemoryTracklets(-1), mMemoryTracks(-1), mNMaxCollisions(0), mNMaxTracks(0), mNMaxSpacePoints(0), mTracks(nullptr), mTrackAttribs(nullptr), mNCandidates(1), mNTracks(0), mNEvents(0), mMaxBackendThreads(100), mTrackletIndexArray(nullptr), mHypothesis(nullptr), mCandidates(nullptr), mSpacePoints(nullptr), mGeo(nullptr), mRecoParam(nullptr), mDebugOutput(false), mMaxEta(0.84f), mRoadZ(18.f), mTPCVdrift(2.58f), mTPCTDriftOffset(0.f), mDebug(new
GPUTRDTrackerDebug<TRDTRK>())
103template <
class TRDTRK,
class PROP>
112template <
class TRDTRK,
class PROP>
118 mRecoParam = GetConstantMem()->calibObjects.trdRecoParam;
120 mDebug->ExpandVectors();
121 mIsInitialized =
true;
124template <
class TRDTRK,
class PROP>
130 mGeo = (
const GPUTRDGeometry*)GetConstantMem()->calibObjects.trdGeometry;
132 GPUFatal(
"TRD geometry must be provided externally");
135 float x0[kNLayers] = {300.2f, 312.8f, 325.4f, 338.0f, 350.6f, 363.2f};
136 auto* matrix = mGeo->GetClusterMatrix(0);
137 float loc[3] = {mGeo->AnodePos(), 0.f, 0.f};
138 float glb[3] = {0.f, 0.f, 0.f};
139 for (int32_t iDet = 0; iDet < kNChambers; ++iDet) {
140 matrix = mGeo->GetClusterMatrix(iDet);
142 mR[iDet] =
x0[mGeo->GetLayer(iDet)];
145 matrix->LocalToMaster(loc, glb);
150template <
class TRDTRK,
class PROP>
159template <
class TRDTRK,
class PROP>
167 for (uint32_t iColl = 0; iColl < GetConstantMem()->ioPtrs.nTRDTriggerRecords; ++iColl) {
168 if (GetConstantMem()->ioPtrs.trdTrigRecMask && GetConstantMem()->ioPtrs.trdTrigRecMask[iColl] == 0) {
173 int32_t idxOffset = 0;
174 if (mProcessPerTimeFrame) {
175 idxOffset = GetConstantMem()->ioPtrs.trdTrackletIdxFirst[iColl];
176 nTrklts = (iColl < GetConstantMem()->ioPtrs.nTRDTriggerRecords - 1) ? GetConstantMem()->ioPtrs.trdTrackletIdxFirst[iColl + 1] - GetConstantMem()->ioPtrs.trdTrackletIdxFirst[iColl] : GetConstantMem()->ioPtrs.nTRDTracklets - GetConstantMem()->ioPtrs.trdTrackletIdxFirst[iColl];
178 nTrklts = GetConstantMem()->ioPtrs.nTRDTracklets;
181 int32_t* trkltIndexArray = &mTrackletIndexArray[iColl * (kNChambers + 1) + 1];
182 trkltIndexArray[-1] = 0;
185 int32_t trkltCounter = 0;
186 for (int32_t iTrklt = 0; iTrklt < nTrklts; ++iTrklt) {
187 if (
tracklets[iTrklt].GetDetector() > currDet) {
188 nextDet =
tracklets[iTrklt].GetDetector();
189 for (int32_t iDet = currDet; iDet < nextDet; ++iDet) {
190 trkltIndexArray[iDet] = trkltCounter;
196 for (int32_t iDet = currDet; iDet <= kNChambers; ++iDet) {
197 trkltIndexArray[iDet] = trkltCounter;
199 if (mGenerateSpacePoints) {
200 if (!CalculateSpacePoints(iColl)) {
201 GPUError(
"Space points for at least one chamber could not be calculated (for interaction %i)", iColl);
206 if (mGenerateSpacePoints) {
212template <
class TRDTRK,
class PROP>
218 if (!mIsInitialized) {
221 GPUError(
"Cannot change mNCandidates after initialization");
225template <
class TRDTRK,
class PROP>
231 GPUInfo(
"##############################################################");
232 GPUInfo(
"Current settings for GPU TRD tracker:");
233 GPUInfo(
" maxChi2(%.2f), chi2Penalty(%.2f), nCandidates(%i), maxMissingLayers(%i)", Param().
rec.trd.maxChi2, Param().
rec.trd.penaltyChi2, mNCandidates, Param().
rec.trd.stopTrkAfterNMissLy);
234 GPUInfo(
" ptCut = %.2f GeV, abs(eta) < %.2f", Param().
rec.trd.minTrackPt, mMaxEta);
235 GPUInfo(
"##############################################################");
238template <
class TRDTRK,
class PROP>
241 mDebug->CreateStreamer();
249 return &Param().polynomialField;
252template <
class TRDTRK,
class PROP>
255 return GetConstantMem()->calibObjects.o2Propagator;
258template <
class TRDTRK,
class PROP>
261 if (!trk.CheckNumericalQuality()) {
264 if (CAMath::Abs(trk.getEta()) > mMaxEta) {
267 if (trk.getPt() < Param().
rec.trd.minTrackPt) {
273template <
class TRDTRK,
class PROP>
274GPUd() int32_t
GPUTRDTracker_t<TRDTRK, PROP>::LoadTrack(const TRDTRK& trk, uint32_t tpcTrackId,
bool checkTrack, HelperTrackAttributes* attribs)
276 if (mNTracks >= mNMaxTracks) {
278 GPUError(
"Error: Track dropped (no memory available) -> must not happen");
282 if (checkTrack && !CheckTrackTRDCandidate(trk)) {
285 mTracks[mNTracks] = trk;
286 mTracks[mNTracks].setRefGlobalTrackIdRaw(tpcTrackId);
288 mTrackAttribs[mNTracks] = *attribs;
294template <
class TRDTRK,
class PROP>
300 GPUInfo(
"There are in total %i tracklets loaded", GetConstantMem()->ioPtrs.nTRDTracklets);
301 GPUInfo(
"There are %i tracks loaded. mNMaxTracks(%i)", mNTracks, mNMaxTracks);
302 for (int32_t
i = 0;
i < mNTracks; ++
i) {
303 auto* trk = &(mTracks[
i]);
304 GPUInfo(
"track %i: x=%f, alpha=%f, nTracklets=%i, pt=%f, time=%f",
i, trk->getX(), trk->getAlpha(), trk->getNtracklets(), trk->getPt(), mTrackAttribs[
i].mTime);
308template <
class TRDTRK,
class PROP>
309GPUd() int32_t
GPUTRDTracker_t<TRDTRK, PROP>::GetCollisionIDs(int32_t iTrk, int32_t* collisionIds)
const
319 for (uint32_t iColl = 0; iColl < GetConstantMem()->ioPtrs.nTRDTriggerRecords; ++iColl) {
320 if (GetConstantMem()->ioPtrs.trdTrigRecMask && GetConstantMem()->ioPtrs.trdTrigRecMask[iColl] == 0) {
323 if (GetConstantMem()->ioPtrs.trdTriggerTimes[iColl] > mTrackAttribs[iTrk].GetTimeMin() && GetConstantMem()->ioPtrs.trdTriggerTimes[iColl] < mTrackAttribs[iTrk].GetTimeMax()) {
325 GPUError(
"Found too many collision candidates for track with tMin(%f) and tMax(%f)", mTrackAttribs[iTrk].GetTimeMin(), mTrackAttribs[iTrk].GetTimeMax());
328 collisionIds[nColls++] = iColl;
334template <
class TRDTRK,
class PROP>
340 int32_t collisionIds[20] = {0};
341 int32_t nCollisionIds = 1;
342 if (mProcessPerTimeFrame) {
343 nCollisionIds = GetCollisionIDs(iTrk, collisionIds);
344 if (nCollisionIds == 0) {
346 GPUInfo(
"Did not find TRD data for track %i with t=%f. tMin(%f), tMax(%f)", iTrk, mTrackAttribs[iTrk].mTime, mTrackAttribs[iTrk].GetTimeMin(), mTrackAttribs[iTrk].GetTimeMax());
352 PROP prop(getPropagatorParam());
353 mTracks[iTrk].setChi2(Param().
rec.trd.penaltyChi2);
354 auto trkStart = mTracks[iTrk];
355 for (int32_t iColl = 0; iColl < nCollisionIds; ++iColl) {
357 auto trkCopy = trkStart;
358 prop.setTrack(&trkCopy);
359 prop.setFitInProjections(
true);
360 if (!FollowProlongation(&prop, &trkCopy, iTrk, threadId, collisionIds[iColl])) {
364 if (trkCopy.getReducedChi2() < mTracks[iTrk].getReducedChi2()) {
365 mTracks[iTrk] = trkCopy;
370template <
class TRDTRK,
class PROP>
379 int32_t idxOffset = iCollision * (kNChambers + 1);
383 for (int32_t iDet = 0; iDet < kNChambers; ++iDet) {
384 int32_t iFirstTrackletInDet = mTrackletIndexArray[idxOffset + iDet];
385 int32_t iFirstTrackletInNextDet = mTrackletIndexArray[idxOffset + iDet + 1];
386 int32_t nTrackletsInDet = iFirstTrackletInNextDet - iFirstTrackletInDet;
387 if (nTrackletsInDet == 0) {
390 if (!mGeo->ChamberInGeometry(iDet)) {
391 GPUError(
"Found TRD tracklets in chamber %i which is not included in the geometry", iDet);
394 auto* matrix = mGeo->GetClusterMatrix(iDet);
396 GPUError(
"No cluster matrix available for chamber %i. Skipping it...", iDet);
402 int32_t trkltIdxOffset = (mProcessPerTimeFrame) ? GetConstantMem()->ioPtrs.trdTrackletIdxFirst[iCollision] : 0;
403 int32_t trkltIdxStart = trkltIdxOffset + iFirstTrackletInDet;
404 for (int32_t trkltIdx = trkltIdxStart; trkltIdx < trkltIdxStart + nTrackletsInDet; ++trkltIdx) {
405 int32_t trkltZbin =
tracklets[trkltIdx].GetZbin();
406 float xTrkltDet[3] = {0.f};
407 float xTrkltSec[3] = {0.f};
408 xTrkltDet[0] = mGeo->AnodePos() + sRadialOffset;
409 xTrkltDet[1] =
tracklets[trkltIdx].GetY();
410 xTrkltDet[2] = pp->GetRowPos(trkltZbin) - pp->GetRowSize(trkltZbin) / 2.f - pp->GetRowPos(pp->GetNrows() / 2);
412 matrix->LocalToMaster(xTrkltDet, xTrkltSec);
413 mSpacePoints[trkltIdx].setX(xTrkltSec[0]);
414 mSpacePoints[trkltIdx].setY(xTrkltSec[1]);
415 mSpacePoints[trkltIdx].setZ(xTrkltSec[2]);
416 mSpacePoints[trkltIdx].setDy(
tracklets[trkltIdx].GetdY());
424template <
class TRDTRK,
class PROP>
425GPUd() bool
GPUTRDTracker_t<TRDTRK, PROP>::FollowProlongation(PROP* prop, TRDTRK* t, int32_t iTrk, int32_t threadId, int32_t collisionId)
435 GPUInfo(
"Start track following for track %i at x=%f with pt=%f", t->getRefGlobalTrackIdRaw(), t->getX(), t->getPt());
439 float zShiftTrk = 0.f;
440 if (mProcessPerTimeFrame) {
441 zShiftTrk = (mTrackAttribs[iTrk].mTime - GetConstantMem()->ioPtrs.trdTriggerTimes[collisionId]) * mTPCVdrift * mTrackAttribs[iTrk].mSide;
449 const GPUTRDSpacePoint* spacePoints = GetConstantMem()->ioPtrs.trdSpacePoints;
451#ifdef ENABLE_GPUTRDDEBUG
452 TRDTRK trackNoUp(*t);
455 int32_t candidateIdxOffset = threadId * 2 * mNCandidates;
456 int32_t hypothesisIdxOffset = threadId * mNCandidates;
457 int32_t trkltIdxOffset = collisionId * (kNChambers + 1);
458 int32_t glbTrkltIdxOffset = (mProcessPerTimeFrame) ? GetConstantMem()->ioPtrs.trdTrackletIdxFirst[collisionId] : 0;
461 if (mNCandidates > 1) {
463 mCandidates[candidateIdxOffset] = *t;
466 int32_t nCandidates = 1;
467 int32_t nCurrHypothesis = 0;
472 const int32_t nMaxChambersToSearch = 4;
474 mDebug->SetGeneralInfo(mNEvents, mNTracks, iTrk, t->getPt());
476 for (int32_t iLayer = 0; iLayer < kNLayers; ++iLayer) {
479 int32_t currIdx = candidateIdxOffset + iLayer % 2;
480 int32_t nextIdx = candidateIdxOffset + (iLayer + 1) % 2;
481 pad = mGeo->GetPadPlane(iLayer, 0);
482 float tilt = CAMath::Tan(CAMath::Pi() / 180.f * pad->GetTiltingAngle());
483 const float zMaxTRD = pad->GetRow0();
490 for (int32_t iCandidate = 0; iCandidate < nCandidates; iCandidate++) {
492 int32_t det[nMaxChambersToSearch] = {-1, -1, -1, -1};
494 if (mNCandidates > 1) {
495 trkWork = &mCandidates[2 * iCandidate + currIdx];
496 prop->setTrack(trkWork);
499 if (trkWork->getIsStopped()) {
500 Hypothesis hypo(trkWork->getNlayersFindable(), iCandidate, -1, trkWork->getChi2());
501 InsertHypothesis(hypo, nCurrHypothesis, hypothesisIdxOffset);
507 if (!prop->propagateToX(mR[2 * kNLayers + iLayer], .8f, 2.f)) {
509 GPUInfo(
"Track propagation failed for track %i candidate %i in layer %i (pt=%f, x=%f, mR[layer]=%f)", iTrk, iCandidate, iLayer, trkWork->getPt(), trkWork->getX(), mR[2 * kNLayers + iLayer]);
515 if (!AdjustSector(prop, trkWork)) {
517 GPUInfo(
"Adjusting sector failed for track %i candidate %i in layer %i", iTrk, iCandidate, iLayer);
523 if (IsGeoFindable(trkWork, iLayer, prop->getAlpha(), zShiftTrk)) {
524 trkWork->setIsFindable(iLayer);
528 roadY = 7.f * CAMath::Sqrt(trkWork->getSigmaY2() + 0.1f * 0.1f) + Param().rec.trd.extraRoadY;
530 roadZ = mRoadZ + Param().rec.trd.extraRoadZ;
532 if (CAMath::Abs(trkWork->getZ() + zShiftTrk) - roadZ >= zMaxTRD) {
534 GPUInfo(
"Track out of TRD acceptance with z=%f in layer %i (eta=%f)", trkWork->getZ() + zShiftTrk, iLayer, trkWork->getEta());
540 FindChambersInRoad(trkWork, roadY, roadZ, iLayer, det, zMaxTRD, prop->getAlpha(), zShiftTrk);
543 mDebug->SetTrackParameter(*trkWork, iLayer);
546 for (int32_t iDet = 0; iDet < nMaxChambersToSearch; iDet++) {
547 int32_t currDet = det[iDet];
551 pad = mGeo->GetPadPlane(currDet);
552 int32_t currSec = mGeo->GetSector(currDet);
553 if (currSec != GetSector(prop->getAlpha())) {
554 if (!prop->rotate(GetAlphaOfSector(currSec))) {
556 GPUWarning(
"Track could not be rotated in tracklet coordinate system");
561 if (currSec != GetSector(prop->getAlpha())) {
562 GPUError(
"Track is in sector %i and sector %i is searched for tracklets", GetSector(prop->getAlpha()), currSec);
566 if (!prop->propagateToX(mR[currDet], .8f, .2f)) {
568 GPUWarning(
"Track parameter for track %i, x=%f at chamber %i x=%f in layer %i cannot be retrieved", iTrk, trkWork->getX(), currDet, mR[currDet], iLayer);
572 for (int32_t trkltIdx = glbTrkltIdxOffset + mTrackletIndexArray[trkltIdxOffset + currDet]; trkltIdx < glbTrkltIdxOffset + mTrackletIndexArray[trkltIdxOffset + currDet + 1]; ++trkltIdx) {
573 if (CAMath::Abs(trkWork->getY() - spacePoints[trkltIdx].getY()) > roadY || CAMath::Abs(trkWork->getZ() + zShiftTrk - spacePoints[trkltIdx].getZ()) > roadZ) {
579 prop->getPropagatedYZ(spacePoints[trkltIdx].
getX(), projY, projZ);
581 float tiltCorr = tilt * (spacePoints[trkltIdx].getZ() - projZ);
582 float dyTiltCorr = tilt * trkWork->getTgl() * mGeo->GetCdrHght();
583 float lPad = pad->GetRowSize(
tracklets[trkltIdx].GetZbin());
584 if (!((CAMath::Abs(spacePoints[trkltIdx].getZ() - projZ) < lPad) && (trkWork->getSigmaZ2() < (lPad * lPad / 12.f)))) {
589 float zPosCorr = spacePoints[trkltIdx].getZ() + mRecoParam->getZCorrCoeffNRC() * trkWork->getTgl();
590 float yPosCorr = spacePoints[trkltIdx].getY() - tiltCorr;
591 zPosCorr -= zShiftTrk;
592 float deltaY = yPosCorr - projY;
593 float deltaZ = zPosCorr - projZ;
594 float trkltPosTmpYZ[2] = {yPosCorr, zPosCorr};
595 float trkltCovTmp[3] = {0.f};
596 if ((CAMath::Abs(deltaY) < roadY) && (CAMath::Abs(deltaZ) < roadZ)) {
598 RecalcTrkltCov(tilt, trkWork->getSnp(), pad->GetRowSize(
tracklets[trkltIdx].GetZbin()), trkltCovTmp);
599 float chi2 = prop->getPredictedChi2(trkltPosTmpYZ, trkltCovTmp);
600 if (Param().
rec.trd.addDeflectionInChi2 && (trkWork->getSnp() < 1.f - 1e-6f) && (trkWork->getSnp() > -1.f + 1e-6f)) {
602 float trkltCovTmpWithDy[6] = {trkltCovTmp[0], trkltCovTmp[1], trkltCovTmp[2], 0.f, 0.f, 0.f};
603 RecalcTrkltCovDy(tilt, trkWork->getSnp(), trkltCovTmpWithDy);
604 trkltCovTmpWithDy[0] += trkWork->getSigmaY2();
605 trkltCovTmpWithDy[1] += trkWork->getSigmaZY();
606 trkltCovTmpWithDy[2] += trkWork->getSigmaZ2();
609 if (InvertCov(trkltCovTmpWithDy)) {
610 float deltaDy = spacePoints[trkltIdx].getDy() + dyTiltCorr - mRecoParam->convertAngleToDy(trkWork->getSnp());
611 chi2 = deltaY * trkltCovTmpWithDy[0] * deltaY + 2 * deltaY * trkltCovTmpWithDy[1] * deltaZ + 2 * deltaY * trkltCovTmpWithDy[3] * deltaDy + deltaZ * trkltCovTmpWithDy[2] * deltaZ + 2 * deltaZ * trkltCovTmpWithDy[4] * deltaDy + deltaDy * trkltCovTmpWithDy[5] * deltaDy;
615 if ((chi2 > Param().
rec.trd.maxChi2) || (Param().
rec.trd.applyDeflectionCut && CAMath::Abs(GetAngularPull(spacePoints[trkltIdx].getDy() + dyTiltCorr, trkWork->getSnp())) > 4)) {
618 Hypothesis hypo(trkWork->getNlayersFindable(), iCandidate, trkltIdx, trkWork->getChi2() + chi2);
619 InsertHypothesis(hypo, nCurrHypothesis, hypothesisIdxOffset);
625 Hypothesis hypoNoUpdate(trkWork->getNlayersFindable(), iCandidate, -1, trkWork->getChi2() + Param().
rec.trd.penaltyChi2);
626 InsertHypothesis(hypoNoUpdate, nCurrHypothesis, hypothesisIdxOffset);
630 mDebug->SetChi2Update(mHypothesis[0 + hypothesisIdxOffset].mChi2 - t->getChi2(), iLayer);
631 mDebug->SetRoad(roadY, roadZ, iLayer);
632 bool wasTrackStored =
false;
640 for (int32_t iUpdate = 0; iUpdate < nCurrHypothesis && iUpdate < mNCandidates; iUpdate++) {
641 if (mHypothesis[iUpdate + hypothesisIdxOffset].mCandidateId == -1) {
648 nCandidates = iUpdate + 1;
649 if (mNCandidates > 1) {
650 mCandidates[2 * iUpdate + nextIdx] = mCandidates[2 * mHypothesis[iUpdate + hypothesisIdxOffset].mCandidateId + currIdx];
651 trkWork = &mCandidates[2 * iUpdate + nextIdx];
653 if (mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId == -1) {
655 if (trkWork->getIsFindable(iLayer)) {
656 if (trkWork->getNmissingConsecLayers(iLayer) > Param().
rec.trd.stopTrkAfterNMissLy) {
657 trkWork->setIsStopped();
659 trkWork->setChi2(trkWork->getChi2() + Param().
rec.trd.penaltyChi2);
661 if (iUpdate == 0 && mNCandidates > 1) {
662 *t = mCandidates[2 * iUpdate + nextIdx];
667 if (mNCandidates > 1) {
668 prop->setTrack(trkWork);
670 int32_t trkltSec = mGeo->GetSector(
tracklets[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].GetDetector());
671 if (trkltSec != GetSector(prop->getAlpha())) {
673 prop->rotate(GetAlphaOfSector(trkltSec));
675 if (!prop->propagateToX(spacePoints[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].getX(), .8f, 2.f)) {
677 GPUWarning(
"Final track propagation for track %i update %i in layer %i failed", iTrk, iUpdate, iLayer);
679 trkWork->setChi2(trkWork->getChi2() + Param().
rec.trd.penaltyChi2);
680 if (trkWork->getIsFindable(iLayer)) {
681 if (trkWork->getNmissingConsecLayers(iLayer) >= Param().
rec.trd.stopTrkAfterNMissLy) {
682 trkWork->setIsStopped();
685 if (iUpdate == 0 && mNCandidates > 1) {
686 *t = mCandidates[2 * iUpdate + nextIdx];
691 pad = mGeo->GetPadPlane(
tracklets[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].GetDetector());
692 float tiltCorrUp = tilt * (spacePoints[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].getZ() - trkWork->getZ());
693 float zPosCorrUp = spacePoints[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].getZ() + mRecoParam->getZCorrCoeffNRC() * trkWork->getTgl();
694 zPosCorrUp -= zShiftTrk;
695 float padLength = pad->GetRowSize(
tracklets[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].GetZbin());
696 if (!((trkWork->getSigmaZ2() < (padLength * padLength / 12.f)) && (CAMath::Abs(spacePoints[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].getZ() - trkWork->getZ()) < padLength))) {
699 float trkltPosUp[2] = {spacePoints[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].getY() - tiltCorrUp, zPosCorrUp};
700 float trkltCovUp[3] = {0.f};
701 RecalcTrkltCov(tilt, trkWork->getSnp(), pad->GetRowSize(
tracklets[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].GetZbin()), trkltCovUp);
703#ifdef ENABLE_GPUTRDDEBUG
704 prop->setTrack(&trackNoUp);
705 prop->rotate(GetAlphaOfSector(trkltSec));
707 prop->propagateToX(mR[
tracklets[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].GetDetector()], .8f, 2.f);
708 prop->setTrack(trkWork);
711 if (!wasTrackStored) {
712#ifdef ENABLE_GPUTRDDEBUG
713 mDebug->SetTrackParameterNoUp(trackNoUp, iLayer);
715 mDebug->SetTrackParameter(*trkWork, iLayer);
716 mDebug->SetRawTrackletPosition(spacePoints[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].
getX(), spacePoints[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].
getY(), spacePoints[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].getZ(), iLayer);
717 mDebug->SetCorrectedTrackletPosition(trkltPosUp, iLayer);
718 mDebug->SetTrackletCovariance(trkltCovUp, iLayer);
719 mDebug->SetTrackletProperties(spacePoints[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].getDy(),
tracklets[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].GetDetector(), iLayer);
720 wasTrackStored =
true;
723 if (!prop->update(trkltPosUp, trkltCovUp)) {
725 GPUWarning(
"Failed to update track %i with space point in layer %i", iTrk, iLayer);
727 trkWork->setChi2(trkWork->getChi2() + Param().
rec.trd.penaltyChi2);
728 if (trkWork->getIsFindable(iLayer)) {
729 if (trkWork->getNmissingConsecLayers(iLayer) >= Param().
rec.trd.stopTrkAfterNMissLy) {
730 trkWork->setIsStopped();
733 if (iUpdate == 0 && mNCandidates > 1) {
734 *t = mCandidates[2 * iUpdate + nextIdx];
738 if (!trkWork->CheckNumericalQuality()) {
740 GPUInfo(
"Track %i has invalid covariance matrix. Aborting track following\n", iTrk);
744 trkWork->addTracklet(iLayer, mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId);
745 trkWork->setChi2(mHypothesis[iUpdate + hypothesisIdxOffset].mChi2);
746 trkWork->setIsFindable(iLayer);
747 trkWork->setCollisionId(collisionId);
749 float projZEntry, projYEntry;
751 prop->getPropagatedYZ(trkWork->getX() - mGeo->GetCdrHght(), projYEntry, projZEntry);
757 const auto padrowEntry = pad->GetPadRowNumber(projZEntry);
758 const auto padrowExit = pad->GetPadRowNumber(trkWork->getZ());
759 if (padrowEntry != padrowExit) {
760 trkWork->setIsCrossingNeighbor(iLayer);
761 trkWork->setHasPadrowCrossing();
763 const auto currDet =
tracklets[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].GetDetector();
765 for (int32_t trkltIdx = glbTrkltIdxOffset + mTrackletIndexArray[trkltIdxOffset + currDet]; trkltIdx < glbTrkltIdxOffset + mTrackletIndexArray[trkltIdxOffset + currDet + 1]; ++trkltIdx) {
767 if (mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId == trkltIdx) {
770 if (CAMath::Abs(
tracklets[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].GetZbin() -
tracklets[trkltIdx].GetZbin()) == 1 &&
771 CAMath::Abs(
tracklets[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].GetY() -
tracklets[trkltIdx].GetY()) < 1) {
772 trkWork->setIsCrossingNeighbor(iLayer);
773 trkWork->setHasNeighbor();
777 if (iUpdate == 0 && mNCandidates > 1) {
778 *t = mCandidates[2 * iUpdate + nextIdx];
784 GPUInfo(
"Track %i cannot be followed. Stopped in layer %i", iTrk, iLayer);
795 mDebug->SetTrack(*t);
799 GPUInfo(
"Ended track following for track %i at x=%f with pt=%f. Attached %i tracklets", t->getRefGlobalTrackIdRaw(), t->getX(), t->getPt(), t->getNtracklets());
801 if (nCurrHypothesis > 1) {
802 if (CAMath::Abs(mHypothesis[hypothesisIdxOffset + 1].GetReducedChi2() - mHypothesis[hypothesisIdxOffset].GetReducedChi2()) < Param().
rec.trd.chi2SeparationCut) {
809template <
class TRDTRK,
class PROP>
810GPUd()
void GPUTRDTracker_t<TRDTRK, PROP>::InsertHypothesis(Hypothesis hypo, int32_t& nCurrHypothesis, int32_t idxOffset)
816 if (nCurrHypothesis == 0) {
818 mHypothesis[idxOffset] = hypo;
820 }
else if (nCurrHypothesis > 0 && nCurrHypothesis < mNCandidates) {
822 for (int32_t
i = idxOffset;
i < nCurrHypothesis + idxOffset; ++
i) {
823 if (hypo.GetReducedChi2() < mHypothesis[
i].GetReducedChi2()) {
824 for (int32_t k = nCurrHypothesis + idxOffset; k >
i; --k) {
825 mHypothesis[k] = mHypothesis[k - 1];
827 mHypothesis[
i] = hypo;
832 mHypothesis[nCurrHypothesis + idxOffset] = hypo;
837 int32_t
i = nCurrHypothesis + idxOffset - 1;
838 for (;
i >= idxOffset; --
i) {
839 if (mHypothesis[
i].GetReducedChi2() < hypo.GetReducedChi2()) {
843 if (
i < (nCurrHypothesis + idxOffset - 1)) {
845 for (int32_t k = nCurrHypothesis + idxOffset - 1; k >
i + 1; --k) {
846 mHypothesis[k] = mHypothesis[k - 1];
848 mHypothesis[
i + 1] = hypo;
853template <
class TRDTRK,
class PROP>
864 int32_t sector = GetSector(
alpha);
866 return mGeo->GetDetector(
layer,
stack, sector);
869template <
class TRDTRK,
class PROP>
877 float alpha = mGeo->GetAlpha();
878 float xTmp = t->getX();
880 float yMax = t->getX() * CAMath::Tan(0.5f *
alpha);
881 float alphaCurr = t->getAlpha();
883 if (CAMath::Abs(
y) > 2.f *
yMax) {
885 GPUInfo(
"AdjustSector: Track %i with pT = %f crossing two sector boundaries at x = %f", t->getRefGlobalTrackIdRaw(), t->getPt(), t->getX());
891 while (CAMath::Abs(
y) >
yMax) {
895 int32_t sign = (
y > 0) ? 1 : -1;
896 float alphaNew = alphaCurr +
alpha * sign;
897 if (alphaNew > CAMath::Pi()) {
898 alphaNew -= 2 * CAMath::Pi();
899 }
else if (alphaNew < -CAMath::Pi()) {
900 alphaNew += 2 * CAMath::Pi();
902 if (!prop->rotate(alphaNew)) {
905 if (!prop->propagateToX(xTmp, .8f, 2.f)) {
914template <
class TRDTRK,
class PROP>
921 alpha += 2.f * CAMath::Pi();
922 }
else if (
alpha >= 2.f * CAMath::Pi()) {
923 alpha -= 2.f * CAMath::Pi();
925 return (int32_t)(
alpha * (float)kNSectors / (2.f * CAMath::Pi()));
928template <
class TRDTRK,
class PROP>
934 float alpha = 2.0f * CAMath::Pi() / (float)kNSectors * ((
float)sec + 0.5f);
935 if (
alpha > CAMath::Pi()) {
936 alpha -= 2 * CAMath::Pi();
941template <
class TRDTRK,
class PROP>
942GPUd()
void GPUTRDTracker_t<TRDTRK, PROP>::RecalcTrkltCov(const
float tilt, const
float snp, const
float rowSize,
float (&cov)[3])
948 float t2 = tilt * tilt;
949 float c2 = 1.f / (1.f + t2);
950 float sy2 = mRecoParam->getRPhiRes(snp);
951 float sz2 = rowSize * rowSize / 12.f;
952 cov[0] = c2 * (sy2 + t2 * sz2);
953 cov[1] = c2 * tilt * (sz2 - sy2);
954 cov[2] = c2 * (t2 * sy2 + sz2);
957template <
class TRDTRK,
class PROP>
960 float t2 = tilt * tilt;
961 float c2 = 1.f / (1.f + t2);
962 float sy2 = mRecoParam->getRPhiRes(snp);
963 float sdy2 = mRecoParam->getDyRes(snp);
964 cov[3] = mRecoParam->getCorrYDy(snp) * CAMath::Sqrt(sdy2 * c2 * sy2);
965 cov[4] = -tilt * mRecoParam->getCorrYDy(snp) * CAMath::Sqrt(sdy2 * c2 * sy2);
969template <
class TRDTRK,
class PROP>
974 float c00 = cov[2] * cov[5] - cov[4] * cov[4];
975 float c01 = cov[4] * cov[3] - cov[1] * cov[5];
976 float c02 = cov[1] * cov[4] - cov[2] * cov[3];
977 float c11 = cov[5] * cov[0] - cov[3] * cov[3];
978 float c12 = cov[3] * cov[1] - cov[4] * cov[0];
979 float c22 = cov[0] * cov[2] - cov[1] * cov[1];
981 float t0 = CAMath::Abs(cov[0]);
982 float t1 = CAMath::Abs(cov[1]);
983 float t2 = CAMath::Abs(cov[3]);
991 det = c12 * c01 - c11 * c02;
994 det = c11 * c22 - c12 * c12;
996 }
else if (t2 >=
t1) {
998 det = c12 * c01 - c11 * c02;
1001 det = c02 * c12 - c01 * c22;
1004 if (det == 0 || tmp == 0) {
1008 float s = tmp / det;
1020template <
class TRDTRK,
class PROP>
1021GPUd() float
GPUTRDTracker_t<TRDTRK, PROP>::GetAngularPull(
float dYtracklet,
float snp)
const
1023 float dYtrack = mRecoParam->convertAngleToDy(snp);
1024 float dYresolution = mRecoParam->getDyRes(snp);
1025 if (dYresolution < 1e-6f) {
1028 return (dYtracklet - dYtrack) / CAMath::Sqrt(dYresolution);
1031template <
class TRDTRK,
class PROP>
1032GPUd()
void GPUTRDTracker_t<TRDTRK, PROP>::FindChambersInRoad(const TRDTRK* t, const
float roadY, const
float roadZ, const int32_t iLayer, int32_t* det, const
float zMax, const
float alpha, const
float zShiftTrk)
const
1040 const float yMax = CAMath::Abs(mGeo->GetCol0(iLayer));
1041 float zTrk = t->getZ() + zShiftTrk;
1043 int32_t currStack = mGeo->GetStack(zTrk, iLayer);
1044 int32_t currSec = GetSector(
alpha);
1049 if (currStack > -1) {
1051 currDet = mGeo->GetDetector(iLayer, currStack, currSec);
1052 det[nDets++] = currDet;
1054 int32_t lastPadRow = mGeo->GetRowMax(iLayer, currStack, 0);
1055 float zCenter = pp->GetRowPos(lastPadRow / 2);
1056 if ((zTrk + roadZ) > pp->GetRow0() || (zTrk - roadZ) < pp->GetRowEnd()) {
1057 int32_t addStack = zTrk > zCenter ? currStack - 1 : currStack + 1;
1058 if (addStack < kNStacks && addStack > -1) {
1059 det[nDets++] = mGeo->GetDetector(iLayer, addStack, currSec);
1063 if (CAMath::Abs(zTrk) >
zMax) {
1066 currDet = mGeo->GetDetector(iLayer, 0, currSec);
1068 currDet = mGeo->GetDetector(iLayer, kNStacks - 1, currSec);
1070 det[nDets++] = currDet;
1071 currStack = mGeo->GetStack(currDet);
1075 currDet = GetDetectorNumber(zTrk + 4.0f,
alpha, iLayer);
1076 if (currDet != -1) {
1077 det[nDets++] = currDet;
1079 currDet = GetDetectorNumber(zTrk - 4.0f,
alpha, iLayer);
1080 if (currDet != -1) {
1081 det[nDets++] = currDet;
1086 if ((CAMath::Abs(t->getY()) + roadY) >
yMax) {
1087 const int32_t nStacksToSearch = nDets;
1089 if (t->getY() > 0) {
1090 newSec = (currSec + 1) % kNSectors;
1092 newSec = (currSec > 0) ? currSec - 1 : kNSectors - 1;
1094 for (int32_t idx = 0;
idx < nStacksToSearch; ++
idx) {
1095 currStack = mGeo->GetStack(det[idx]);
1096 det[nDets++] = mGeo->GetDetector(iLayer, currStack, newSec);
1100 for (int32_t iDet = 0; iDet < nDets; iDet++) {
1101 if (!mGeo->ChamberInGeometry(det[iDet])) {
1107template <
class TRDTRK,
class PROP>
1108GPUd() bool
GPUTRDTracker_t<TRDTRK, PROP>::IsGeoFindable(const TRDTRK* t, const int32_t
layer, const
float alpha, const
float zShiftTrk)
const
1115 float zTrk = t->getZ() + zShiftTrk;
1117 int32_t det = GetDetectorNumber(zTrk,
alpha,
layer);
1125 if (!mGeo->ChamberInGeometry(det)) {
1130 float yMax = pp->GetColEnd();
1131 float zMax = pp->GetRow0();
1132 float zMin = pp->GetRowEnd();
1138 if (
yMax - CAMath::Abs(t->getY()) < epsY) {
1142 if (!((zTrk >
zMin + epsZ) && (zTrk <
zMax - epsZ))) {
1149#ifndef GPUCA_GPUCODE