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), mZCorrCoefNRC(1.4f), 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 lPad = pad->GetRowSize(
tracklets[trkltIdx].GetZbin());
583 if (!((CAMath::Abs(spacePoints[trkltIdx].getZ() - projZ) < lPad) && (trkWork->getSigmaZ2() < (lPad * lPad / 12.f)))) {
587 float zPosCorr = spacePoints[trkltIdx].getZ() + mZCorrCoefNRC * trkWork->getTgl();
588 float yPosCorr = spacePoints[trkltIdx].getY() - tiltCorr;
589 zPosCorr -= zShiftTrk;
590 float deltaY = yPosCorr - projY;
591 float deltaZ = zPosCorr - projZ;
592 float trkltPosTmpYZ[2] = {yPosCorr, zPosCorr};
593 float trkltCovTmp[3] = {0.f};
594 if ((CAMath::Abs(deltaY) < roadY) && (CAMath::Abs(deltaZ) < roadZ)) {
596 RecalcTrkltCov(tilt, trkWork->getSnp(), pad->GetRowSize(
tracklets[trkltIdx].GetZbin()), trkltCovTmp);
597 float chi2 = prop->getPredictedChi2(trkltPosTmpYZ, trkltCovTmp);
599 if ((chi2 > Param().
rec.trd.maxChi2) || (Param().
rec.trd.applyDeflectionCut && CAMath::Abs(GetAngularPull(spacePoints[trkltIdx].getDy(), trkWork->getSnp())) > 4)) {
602 Hypothesis hypo(trkWork->getNlayersFindable(), iCandidate, trkltIdx, trkWork->getChi2() + chi2);
603 InsertHypothesis(hypo, nCurrHypothesis, hypothesisIdxOffset);
609 Hypothesis hypoNoUpdate(trkWork->getNlayersFindable(), iCandidate, -1, trkWork->getChi2() + Param().
rec.trd.penaltyChi2);
610 InsertHypothesis(hypoNoUpdate, nCurrHypothesis, hypothesisIdxOffset);
614 mDebug->SetChi2Update(mHypothesis[0 + hypothesisIdxOffset].mChi2 - t->getChi2(), iLayer);
615 mDebug->SetRoad(roadY, roadZ, iLayer);
616 bool wasTrackStored =
false;
624 for (int32_t iUpdate = 0; iUpdate < nCurrHypothesis && iUpdate < mNCandidates; iUpdate++) {
625 if (mHypothesis[iUpdate + hypothesisIdxOffset].mCandidateId == -1) {
632 nCandidates = iUpdate + 1;
633 if (mNCandidates > 1) {
634 mCandidates[2 * iUpdate + nextIdx] = mCandidates[2 * mHypothesis[iUpdate + hypothesisIdxOffset].mCandidateId + currIdx];
635 trkWork = &mCandidates[2 * iUpdate + nextIdx];
637 if (mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId == -1) {
639 if (trkWork->getIsFindable(iLayer)) {
640 if (trkWork->getNmissingConsecLayers(iLayer) > Param().
rec.trd.stopTrkAfterNMissLy) {
641 trkWork->setIsStopped();
643 trkWork->setChi2(trkWork->getChi2() + Param().
rec.trd.penaltyChi2);
645 if (iUpdate == 0 && mNCandidates > 1) {
646 *t = mCandidates[2 * iUpdate + nextIdx];
651 if (mNCandidates > 1) {
652 prop->setTrack(trkWork);
654 int32_t trkltSec = mGeo->GetSector(
tracklets[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].GetDetector());
655 if (trkltSec != GetSector(prop->getAlpha())) {
657 prop->rotate(GetAlphaOfSector(trkltSec));
659 if (!prop->propagateToX(spacePoints[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].getX(), .8f, 2.f)) {
661 GPUWarning(
"Final track propagation for track %i update %i in layer %i failed", iTrk, iUpdate, iLayer);
663 trkWork->setChi2(trkWork->getChi2() + Param().
rec.trd.penaltyChi2);
664 if (trkWork->getIsFindable(iLayer)) {
665 if (trkWork->getNmissingConsecLayers(iLayer) >= Param().
rec.trd.stopTrkAfterNMissLy) {
666 trkWork->setIsStopped();
669 if (iUpdate == 0 && mNCandidates > 1) {
670 *t = mCandidates[2 * iUpdate + nextIdx];
675 pad = mGeo->GetPadPlane(
tracklets[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].GetDetector());
676 float tiltCorrUp = tilt * (spacePoints[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].getZ() - trkWork->getZ());
677 float zPosCorrUp = spacePoints[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].getZ() + mZCorrCoefNRC * trkWork->getTgl();
678 zPosCorrUp -= zShiftTrk;
679 float padLength = pad->GetRowSize(
tracklets[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].GetZbin());
680 if (!((trkWork->getSigmaZ2() < (padLength * padLength / 12.f)) && (CAMath::Abs(spacePoints[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].getZ() - trkWork->getZ()) < padLength))) {
683 float trkltPosUp[2] = {spacePoints[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].getY() - tiltCorrUp, zPosCorrUp};
684 float trkltCovUp[3] = {0.f};
685 RecalcTrkltCov(tilt, trkWork->getSnp(), pad->GetRowSize(
tracklets[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].GetZbin()), trkltCovUp);
687#ifdef ENABLE_GPUTRDDEBUG
688 prop->setTrack(&trackNoUp);
689 prop->rotate(GetAlphaOfSector(trkltSec));
691 prop->propagateToX(mR[
tracklets[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].GetDetector()], .8f, 2.f);
692 prop->setTrack(trkWork);
695 if (!wasTrackStored) {
696#ifdef ENABLE_GPUTRDDEBUG
697 mDebug->SetTrackParameterNoUp(trackNoUp, iLayer);
699 mDebug->SetTrackParameter(*trkWork, iLayer);
700 mDebug->SetRawTrackletPosition(spacePoints[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].
getX(), spacePoints[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].
getY(), spacePoints[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].getZ(), iLayer);
701 mDebug->SetCorrectedTrackletPosition(trkltPosUp, iLayer);
702 mDebug->SetTrackletCovariance(trkltCovUp, iLayer);
703 mDebug->SetTrackletProperties(spacePoints[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].getDy(),
tracklets[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].GetDetector(), iLayer);
704 wasTrackStored =
true;
707 if (!prop->update(trkltPosUp, trkltCovUp)) {
709 GPUWarning(
"Failed to update track %i with space point in layer %i", iTrk, iLayer);
711 trkWork->setChi2(trkWork->getChi2() + Param().
rec.trd.penaltyChi2);
712 if (trkWork->getIsFindable(iLayer)) {
713 if (trkWork->getNmissingConsecLayers(iLayer) >= Param().
rec.trd.stopTrkAfterNMissLy) {
714 trkWork->setIsStopped();
717 if (iUpdate == 0 && mNCandidates > 1) {
718 *t = mCandidates[2 * iUpdate + nextIdx];
722 if (!trkWork->CheckNumericalQuality()) {
724 GPUInfo(
"Track %i has invalid covariance matrix. Aborting track following\n", iTrk);
728 trkWork->addTracklet(iLayer, mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId);
729 trkWork->setChi2(mHypothesis[iUpdate + hypothesisIdxOffset].mChi2);
730 trkWork->setIsFindable(iLayer);
731 trkWork->setCollisionId(collisionId);
733 float projZEntry, projYEntry;
735 prop->getPropagatedYZ(trkWork->getX() - mGeo->GetCdrHght(), projYEntry, projZEntry);
741 const auto padrowEntry = pad->GetPadRowNumber(projZEntry);
742 const auto padrowExit = pad->GetPadRowNumber(trkWork->getZ());
743 if (padrowEntry != padrowExit) {
744 trkWork->setIsCrossingNeighbor(iLayer);
745 trkWork->setHasPadrowCrossing();
747 const auto currDet =
tracklets[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].GetDetector();
749 for (int32_t trkltIdx = glbTrkltIdxOffset + mTrackletIndexArray[trkltIdxOffset + currDet]; trkltIdx < glbTrkltIdxOffset + mTrackletIndexArray[trkltIdxOffset + currDet + 1]; ++trkltIdx) {
751 if (mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId == trkltIdx) {
754 if (CAMath::Abs(
tracklets[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].GetZbin() -
tracklets[trkltIdx].GetZbin()) == 1 &&
755 CAMath::Abs(
tracklets[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].GetY() -
tracklets[trkltIdx].GetY()) < 1) {
756 trkWork->setIsCrossingNeighbor(iLayer);
757 trkWork->setHasNeighbor();
761 if (iUpdate == 0 && mNCandidates > 1) {
762 *t = mCandidates[2 * iUpdate + nextIdx];
768 GPUInfo(
"Track %i cannot be followed. Stopped in layer %i", iTrk, iLayer);
779 mDebug->SetTrack(*t);
783 GPUInfo(
"Ended track following for track %i at x=%f with pt=%f. Attached %i tracklets", t->getRefGlobalTrackIdRaw(), t->getX(), t->getPt(), t->getNtracklets());
785 if (nCurrHypothesis > 1) {
786 if (CAMath::Abs(mHypothesis[hypothesisIdxOffset + 1].GetReducedChi2() - mHypothesis[hypothesisIdxOffset].GetReducedChi2()) < Param().
rec.trd.chi2SeparationCut) {
793template <
class TRDTRK,
class PROP>
794GPUd()
void GPUTRDTracker_t<TRDTRK, PROP>::InsertHypothesis(Hypothesis hypo, int32_t& nCurrHypothesis, int32_t idxOffset)
800 if (nCurrHypothesis == 0) {
802 mHypothesis[idxOffset] = hypo;
804 }
else if (nCurrHypothesis > 0 && nCurrHypothesis < mNCandidates) {
806 for (int32_t
i = idxOffset;
i < nCurrHypothesis + idxOffset; ++
i) {
807 if (hypo.GetReducedChi2() < mHypothesis[
i].GetReducedChi2()) {
808 for (int32_t k = nCurrHypothesis + idxOffset; k >
i; --k) {
809 mHypothesis[k] = mHypothesis[k - 1];
811 mHypothesis[
i] = hypo;
816 mHypothesis[nCurrHypothesis + idxOffset] = hypo;
821 int32_t
i = nCurrHypothesis + idxOffset - 1;
822 for (;
i >= idxOffset; --
i) {
823 if (mHypothesis[
i].GetReducedChi2() < hypo.GetReducedChi2()) {
827 if (
i < (nCurrHypothesis + idxOffset - 1)) {
829 for (int32_t k = nCurrHypothesis + idxOffset - 1; k >
i + 1; --k) {
830 mHypothesis[k] = mHypothesis[k - 1];
832 mHypothesis[
i + 1] = hypo;
837template <
class TRDTRK,
class PROP>
848 int32_t sector = GetSector(
alpha);
850 return mGeo->GetDetector(
layer,
stack, sector);
853template <
class TRDTRK,
class PROP>
861 float alpha = mGeo->GetAlpha();
862 float xTmp = t->getX();
864 float yMax = t->getX() * CAMath::Tan(0.5f *
alpha);
865 float alphaCurr = t->getAlpha();
867 if (CAMath::Abs(
y) > 2.f *
yMax) {
869 GPUInfo(
"AdjustSector: Track %i with pT = %f crossing two sector boundaries at x = %f", t->getRefGlobalTrackIdRaw(), t->getPt(), t->getX());
875 while (CAMath::Abs(
y) >
yMax) {
879 int32_t sign = (
y > 0) ? 1 : -1;
880 float alphaNew = alphaCurr +
alpha * sign;
881 if (alphaNew > CAMath::Pi()) {
882 alphaNew -= 2 * CAMath::Pi();
883 }
else if (alphaNew < -CAMath::Pi()) {
884 alphaNew += 2 * CAMath::Pi();
886 if (!prop->rotate(alphaNew)) {
889 if (!prop->propagateToX(xTmp, .8f, 2.f)) {
898template <
class TRDTRK,
class PROP>
905 alpha += 2.f * CAMath::Pi();
906 }
else if (
alpha >= 2.f * CAMath::Pi()) {
907 alpha -= 2.f * CAMath::Pi();
909 return (int32_t)(
alpha * (float)kNSectors / (2.f * CAMath::Pi()));
912template <
class TRDTRK,
class PROP>
918 float alpha = 2.0f * CAMath::Pi() / (float)kNSectors * ((
float)sec + 0.5f);
919 if (
alpha > CAMath::Pi()) {
920 alpha -= 2 * CAMath::Pi();
925template <
class TRDTRK,
class PROP>
926GPUd()
void GPUTRDTracker_t<TRDTRK, PROP>::RecalcTrkltCov(const
float tilt, const
float snp, const
float rowSize,
float (&cov)[3])
932 float t2 = tilt * tilt;
933 float c2 = 1.f / (1.f + t2);
934 float sy2 = mRecoParam->getRPhiRes(snp);
935 float sz2 = rowSize * rowSize / 12.f;
936 cov[0] = c2 * (sy2 + t2 * sz2);
937 cov[1] = c2 * tilt * (sz2 - sy2);
938 cov[2] = c2 * (t2 * sy2 + sz2);
941template <
class TRDTRK,
class PROP>
942GPUd() float
GPUTRDTracker_t<TRDTRK, PROP>::GetAngularPull(
float dYtracklet,
float snp)
const
944 float dYtrack = mRecoParam->convertAngleToDy(snp);
945 float dYresolution = mRecoParam->getDyRes(snp);
946 if (dYresolution < 1e-6f) {
949 return (dYtracklet - dYtrack) / CAMath::Sqrt(dYresolution);
952template <
class TRDTRK,
class PROP>
953GPUd()
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
961 const float yMax = CAMath::Abs(mGeo->GetCol0(iLayer));
962 float zTrk = t->getZ() + zShiftTrk;
964 int32_t currStack = mGeo->GetStack(zTrk, iLayer);
965 int32_t currSec = GetSector(
alpha);
970 if (currStack > -1) {
972 currDet = mGeo->GetDetector(iLayer, currStack, currSec);
973 det[nDets++] = currDet;
975 int32_t lastPadRow = mGeo->GetRowMax(iLayer, currStack, 0);
976 float zCenter = pp->GetRowPos(lastPadRow / 2);
977 if ((zTrk + roadZ) > pp->GetRow0() || (zTrk - roadZ) < pp->GetRowEnd()) {
978 int32_t addStack = zTrk > zCenter ? currStack - 1 : currStack + 1;
979 if (addStack < kNStacks && addStack > -1) {
980 det[nDets++] = mGeo->GetDetector(iLayer, addStack, currSec);
984 if (CAMath::Abs(zTrk) >
zMax) {
987 currDet = mGeo->GetDetector(iLayer, 0, currSec);
989 currDet = mGeo->GetDetector(iLayer, kNStacks - 1, currSec);
991 det[nDets++] = currDet;
992 currStack = mGeo->GetStack(currDet);
996 currDet = GetDetectorNumber(zTrk + 4.0f,
alpha, iLayer);
998 det[nDets++] = currDet;
1000 currDet = GetDetectorNumber(zTrk - 4.0f,
alpha, iLayer);
1001 if (currDet != -1) {
1002 det[nDets++] = currDet;
1007 if ((CAMath::Abs(t->getY()) + roadY) >
yMax) {
1008 const int32_t nStacksToSearch = nDets;
1010 if (t->getY() > 0) {
1011 newSec = (currSec + 1) % kNSectors;
1013 newSec = (currSec > 0) ? currSec - 1 : kNSectors - 1;
1015 for (int32_t idx = 0;
idx < nStacksToSearch; ++
idx) {
1016 currStack = mGeo->GetStack(det[idx]);
1017 det[nDets++] = mGeo->GetDetector(iLayer, currStack, newSec);
1021 for (int32_t iDet = 0; iDet < nDets; iDet++) {
1022 if (!mGeo->ChamberInGeometry(det[iDet])) {
1028template <
class TRDTRK,
class PROP>
1029GPUd() bool
GPUTRDTracker_t<TRDTRK, PROP>::IsGeoFindable(const TRDTRK* t, const int32_t
layer, const
float alpha, const
float zShiftTrk)
const
1036 float zTrk = t->getZ() + zShiftTrk;
1038 int32_t det = GetDetectorNumber(zTrk,
alpha,
layer);
1046 if (!mGeo->ChamberInGeometry(det)) {
1051 float yMax = pp->GetColEnd();
1052 float zMax = pp->GetRow0();
1053 float zMin = pp->GetRowEnd();
1059 if (
yMax - CAMath::Abs(t->getY()) < epsY) {
1063 if (!((zTrk >
zMin + epsZ) && (zTrk <
zMax - epsZ))) {
1070#ifndef GPUCA_GPUCODE