Project
Loading...
Searching...
No Matches
GPUTRDTracker.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15// #define ENABLE_GPUTRDDEBUG
16#define ENABLE_WARNING 0
17#define ENABLE_INFO 0
18
19#include "GPUTRDTracker.h"
20#include "GPUTRDTrackletWord.h"
21#include "GPUTRDGeometry.h"
22#include "GPUTRDTrackerDebug.h"
23#include "GPUCommonMath.h"
24#include "GPUCommonAlgorithm.h"
25#include "GPUConstantMem.h"
26#include "GPUTRDRecoParam.h"
27
28using namespace o2::gpu;
29
31
32#ifndef GPUCA_GPUCODE
33#include "GPUMemoryResource.h"
34#include "GPUReconstruction.h"
35#include <chrono>
36#include <vector>
37
38#include "GPUChainTracking.h"
39
40template <class TRDTRK, class PROP>
42{
43 mNMaxTracks = std::max(std::max(io.nOutputTracksTPCO2, io.nTracksTPCITSO2), std::max(io.nMergedTracks, io.nOutputTracksTPCO2)); // TODO: This is a bit stupid, we should just take the correct number, not the max of all
44 mNMaxSpacePoints = io.nTRDTracklets;
45 mNMaxCollisions = io.nTRDTriggerRecords;
46}
47
48template <class TRDTRK, class PROP>
50{
51 AllocateAndInitializeLate();
52 mMemoryPermanent = mRec->RegisterMemoryAllocation(this, &GPUTRDTracker_t<TRDTRK, PROP>::SetPointersBase, GPUMemoryResource::MEMORY_PERMANENT, "TRDInitialize");
53 mMemoryTracklets = mRec->RegisterMemoryAllocation(this, &GPUTRDTracker_t<TRDTRK, PROP>::SetPointersTracklets, GPUMemoryResource::MEMORY_INPUT, "TRDTracklets");
54 mMemoryTracks = mRec->RegisterMemoryAllocation(this, &GPUTRDTracker_t<TRDTRK, PROP>::SetPointersTracks, GPUMemoryResource::MEMORY_INOUT, "TRDTracks");
57template <class TRDTRK, class PROP>
60 //--------------------------------------------------------------------
61 // Allocate memory for fixed size objects (needs to be done only once)
62 //--------------------------------------------------------------------
63 mMaxBackendThreads = mRec->GetMaxBackendThreads();
64 computePointerWithAlignment(base, mR, kNChambers);
65 computePointerWithAlignment(base, mHypothesis, mNCandidates * mMaxBackendThreads);
66 computePointerWithAlignment(base, mCandidates, mNCandidates * 2 * mMaxBackendThreads);
67 return base;
68}
69
70template <class TRDTRK, class PROP>
72{
73 //--------------------------------------------------------------------
74 // Allocate memory for tracklets and space points
75 // (size might change for different events)
76 //--------------------------------------------------------------------
77 if (mGenerateSpacePoints) {
78 computePointerWithAlignment(base, mSpacePoints, mNMaxSpacePoints);
79 }
80 computePointerWithAlignment(base, mTrackletIndexArray, (kNChambers + 1) * mNMaxCollisions);
81 return base;
82}
83
84template <class TRDTRK, class PROP>
86{
87 //--------------------------------------------------------------------
88 // Allocate memory for tracks (this is done once per event)
89 //--------------------------------------------------------------------
90 computePointerWithAlignment(base, mTracks, mNMaxTracks);
91 computePointerWithAlignment(base, mTrackAttribs, mNMaxTracks);
92 return base;
93}
94
95template <class TRDTRK, class PROP>
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>())
97{
98 //--------------------------------------------------------------------
99 // Default constructor
100 //--------------------------------------------------------------------
101}
102
103template <class TRDTRK, class PROP>
105{
106 //--------------------------------------------------------------------
107 // Destructor
108 //--------------------------------------------------------------------
109 delete mDebug;
110}
111
112template <class TRDTRK, class PROP>
114{
115 //--------------------------------------------------------------------
116 // Initialise tracker
117 //--------------------------------------------------------------------
118 mRecoParam = GetConstantMem()->calibObjects.trdRecoParam;
119 UpdateGeometry();
120 mDebug->ExpandVectors();
121 mIsInitialized = true;
122}
123
124template <class TRDTRK, class PROP>
126{
127 //--------------------------------------------------------------------
128 // Update Geometry of TRDTracker
129 //--------------------------------------------------------------------
130 mGeo = (const GPUTRDGeometry*)GetConstantMem()->calibObjects.trdGeometry;
131 if (!mGeo) {
132 GPUFatal("TRD geometry must be provided externally");
133 }
134 // obtain average radius of TRD chambers
135 float x0[kNLayers] = {300.2f, 312.8f, 325.4f, 338.0f, 350.6f, 363.2f}; // used as default value in case no transformation matrix can be obtained
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);
141 if (!matrix) {
142 mR[iDet] = x0[mGeo->GetLayer(iDet)];
143 continue;
144 }
145 matrix->LocalToMaster(loc, glb);
146 mR[iDet] = glb[0];
147 }
148}
149
150template <class TRDTRK, class PROP>
152{
153 //--------------------------------------------------------------------
154 // Reset tracker
155 //--------------------------------------------------------------------
156 mNTracks = 0;
157}
158
159template <class TRDTRK, class PROP>
161{
162 //--------------------------------------------------------------------
163 // Prepare tracklet index array and if requested calculate space points
164 // in part duplicated from DoTracking() method to allow for calling
165 // this function on the host prior to GPU processing
166 //--------------------------------------------------------------------
167 for (uint32_t iColl = 0; iColl < GetConstantMem()->ioPtrs.nTRDTriggerRecords; ++iColl) {
168 if (GetConstantMem()->ioPtrs.trdTrigRecMask && GetConstantMem()->ioPtrs.trdTrigRecMask[iColl] == 0) {
169 // this trigger is masked as there is no ITS information available for it
170 continue;
171 }
172 int32_t nTrklts = 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];
177 } else {
178 nTrklts = GetConstantMem()->ioPtrs.nTRDTracklets;
179 }
180 const GPUTRDTrackletWord* tracklets = &((GetConstantMem()->ioPtrs.trdTracklets)[idxOffset]);
181 int32_t* trkltIndexArray = &mTrackletIndexArray[iColl * (kNChambers + 1) + 1];
182 trkltIndexArray[-1] = 0;
183 int32_t currDet = 0;
184 int32_t nextDet = 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;
191 }
192 currDet = nextDet;
193 }
194 ++trkltCounter;
195 }
196 for (int32_t iDet = currDet; iDet <= kNChambers; ++iDet) {
197 trkltIndexArray[iDet] = trkltCounter;
198 }
199 if (mGenerateSpacePoints) {
200 if (!CalculateSpacePoints(iColl)) {
201 GPUError("Space points for at least one chamber could not be calculated (for interaction %i)", iColl);
202 break;
203 }
204 }
205 }
206 if (mGenerateSpacePoints) {
207 chainTracking->mIOPtrs.trdSpacePoints = mSpacePoints;
208 }
209 mNEvents++;
210}
211
212template <class TRDTRK, class PROP>
214{
215 //--------------------------------------------------------------------
216 // set the number of candidates to be used
217 //--------------------------------------------------------------------
218 if (!mIsInitialized) {
219 mNCandidates = n;
220 } else {
221 GPUError("Cannot change mNCandidates after initialization");
222 }
223}
224
225template <class TRDTRK, class PROP>
227{
228 //--------------------------------------------------------------------
229 // print current settings to screen
230 //--------------------------------------------------------------------
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("##############################################################");
236}
237
238template <class TRDTRK, class PROP>
240{
241 mDebug->CreateStreamer();
242}
243
244#endif
245
246template <>
247GPUdi() const GPUTRDPropagatorGPU::propagatorParam* GPUTRDTracker_t<GPUTRDTrackGPU, GPUTRDPropagatorGPU>::getPropagatorParam()
248{
249 return &Param().polynomialField;
250}
251
252template <class TRDTRK, class PROP>
253GPUdi() const typename PROP::propagatorParam* GPUTRDTracker_t<TRDTRK, PROP>::getPropagatorParam()
254{
255 return GetConstantMem()->calibObjects.o2Propagator;
256}
257
258template <class TRDTRK, class PROP>
259GPUd() bool GPUTRDTracker_t<TRDTRK, PROP>::CheckTrackTRDCandidate(const TRDTRK& trk) const
260{
261 if (!trk.CheckNumericalQuality()) {
262 return false;
263 }
264 if (CAMath::Abs(trk.getEta()) > mMaxEta) {
265 return false;
266 }
267 if (trk.getPt() < Param().rec.trd.minTrackPt) {
268 return false;
269 }
270 return true;
271}
272
273template <class TRDTRK, class PROP>
274GPUd() int32_t GPUTRDTracker_t<TRDTRK, PROP>::LoadTrack(const TRDTRK& trk, uint32_t tpcTrackId, bool checkTrack, HelperTrackAttributes* attribs)
275{
276 if (mNTracks >= mNMaxTracks) {
277#ifndef GPUCA_GPUCODE
278 GPUError("Error: Track dropped (no memory available) -> must not happen");
279#endif
280 return (1);
281 }
282 if (checkTrack && !CheckTrackTRDCandidate(trk)) {
283 return 2;
284 }
285 mTracks[mNTracks] = trk;
286 mTracks[mNTracks].setRefGlobalTrackIdRaw(tpcTrackId);
287 if (attribs) {
288 mTrackAttribs[mNTracks] = *attribs;
289 }
290 mNTracks++;
291 return (0);
292}
293
294template <class TRDTRK, class PROP>
295GPUd() void GPUTRDTracker_t<TRDTRK, PROP>::DumpTracks()
296{
297 //--------------------------------------------------------------------
298 // helper function (only for debugging purposes)
299 //--------------------------------------------------------------------
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);
305 }
306}
307
308template <class TRDTRK, class PROP>
309GPUd() int32_t GPUTRDTracker_t<TRDTRK, PROP>::GetCollisionIDs(int32_t iTrk, int32_t* collisionIds) const
310{
311 //--------------------------------------------------------------------
312 // Check which TRD trigger times possibly match given input track.
313 // If ITS-TPC matches or CE-crossing TPC tracks the time is precisely
314 // known and max 1 trigger time can be assigned.
315 // For TPC-only tracks the collision IDs are stored in collisionIds array
316 // and the number of valid entries in the array is returned
317 //--------------------------------------------------------------------
318 int32_t nColls = 0;
319 for (uint32_t iColl = 0; iColl < GetConstantMem()->ioPtrs.nTRDTriggerRecords; ++iColl) {
320 if (GetConstantMem()->ioPtrs.trdTrigRecMask && GetConstantMem()->ioPtrs.trdTrigRecMask[iColl] == 0) {
321 continue;
322 }
323 if (GetConstantMem()->ioPtrs.trdTriggerTimes[iColl] > mTrackAttribs[iTrk].GetTimeMin() && GetConstantMem()->ioPtrs.trdTriggerTimes[iColl] < mTrackAttribs[iTrk].GetTimeMax()) {
324 if (nColls == 20) {
325 GPUError("Found too many collision candidates for track with tMin(%f) and tMax(%f)", mTrackAttribs[iTrk].GetTimeMin(), mTrackAttribs[iTrk].GetTimeMax());
326 return nColls;
327 }
328 collisionIds[nColls++] = iColl;
329 }
330 }
331 return nColls;
332}
333
334template <class TRDTRK, class PROP>
335GPUd() void GPUTRDTracker_t<TRDTRK, PROP>::DoTrackingThread(int32_t iTrk, int32_t threadId)
336{
337 //--------------------------------------------------------------------
338 // perform the tracking for one track (must be threadsafe)
339 //--------------------------------------------------------------------
340 int32_t collisionIds[20] = {0}; // due to the dead time there will never exist more possible TRD triggers for a single track
341 int32_t nCollisionIds = 1; // initialize with 1 for AliRoot compatibility
342 if (mProcessPerTimeFrame) {
343 nCollisionIds = GetCollisionIDs(iTrk, collisionIds);
344 if (nCollisionIds == 0) {
345 if (ENABLE_INFO) {
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());
347 }
348 // no TRD data available for the bunch crossing this track originates from
349 return;
350 }
351 }
352 PROP prop(getPropagatorParam());
353 mTracks[iTrk].setChi2(Param().rec.trd.penaltyChi2); // TODO check if this should not be higher
354 auto trkStart = mTracks[iTrk];
355 for (int32_t iColl = 0; iColl < nCollisionIds; ++iColl) {
356 // do track following for each collision candidate and keep best track
357 auto trkCopy = trkStart;
358 prop.setTrack(&trkCopy);
359 prop.setFitInProjections(true);
360 if (!FollowProlongation(&prop, &trkCopy, iTrk, threadId, collisionIds[iColl])) {
361 // track following failed
362 continue;
363 }
364 if (trkCopy.getReducedChi2() < mTracks[iTrk].getReducedChi2()) {
365 mTracks[iTrk] = trkCopy; // copy back the resulting track
366 }
367 }
368}
369
370template <class TRDTRK, class PROP>
371GPUd() bool GPUTRDTracker_t<TRDTRK, PROP>::CalculateSpacePoints(int32_t iCollision)
372{
373 //--------------------------------------------------------------------
374 // Calculates TRD space points in sector tracking coordinates
375 // from online tracklets
376 //--------------------------------------------------------------------
377
378 bool result = true;
379 int32_t idxOffset = iCollision * (kNChambers + 1); // offset for accessing mTrackletIndexArray for collision iCollision
380
381 const GPUTRDTrackletWord* tracklets = GetConstantMem()->ioPtrs.trdTracklets;
382
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) {
388 continue;
389 }
390 if (!mGeo->ChamberInGeometry(iDet)) {
391 GPUError("Found TRD tracklets in chamber %i which is not included in the geometry", iDet);
392 return false;
393 }
394 auto* matrix = mGeo->GetClusterMatrix(iDet);
395 if (!matrix) {
396 GPUError("No cluster matrix available for chamber %i. Skipping it...", iDet);
397 result = false;
398 continue;
399 }
400 const GPUTRDpadPlane* pp = mGeo->GetPadPlane(iDet);
401
402 int32_t trkltIdxOffset = (mProcessPerTimeFrame) ? GetConstantMem()->ioPtrs.trdTrackletIdxFirst[iCollision] : 0; // global index of first tracklet in iCollision
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}; // trklt position in chamber coordinates
407 float xTrkltSec[3] = {0.f}; // trklt position in sector coordinates
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);
411 // GPUInfo("Space point local %i: x=%f, y=%f, z=%f", trkltIdx, xTrkltDet[0], xTrkltDet[1], xTrkltDet[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());
417
418 // GPUInfo("Space point global %i: x=%f, y=%f, z=%f", trkltIdx, mSpacePoints[trkltIdx].getX(), mSpacePoints[trkltIdx].getY(), mSpacePoints[trkltIdx].getZ());
419 }
420 }
421 return result;
422}
423
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)
426{
427 //--------------------------------------------------------------------
428 // Propagate TPC track layerwise through TRD and pick up closest
429 // tracklet(s) on the way
430 // -> returns false if prolongation could not be executed fully
431 // or track does not fullfill threshold conditions
432 //--------------------------------------------------------------------
433
434 if (ENABLE_INFO) {
435 GPUInfo("Start track following for track %i at x=%f with pt=%f", t->getRefGlobalTrackIdRaw(), t->getX(), t->getPt());
436 }
437 mDebug->Reset();
438 t->setChi2(0.f);
439 float zShiftTrk = 0.f;
440 if (mProcessPerTimeFrame) {
441 zShiftTrk = (mTrackAttribs[iTrk].mTime - GetConstantMem()->ioPtrs.trdTriggerTimes[collisionId]) * mTPCVdrift * mTrackAttribs[iTrk].mSide;
442 // float addZerr = (mTrackAttribs[iTrk].mTimeAddMax + mTrackAttribs[iTrk].mTimeSubMax) * .5f * mTPCVdrift;
443 // increase Z error based on time window
444 // -> this is here since it was done before, but the efficiency seems to be better if the covariance is not updated (more tracklets are attached)
445 // t->updateCovZ2(addZerr * addZerr); // TODO check again once detailed performance study tools are available, maybe this can be tuned
446 }
447 const GPUTRDpadPlane* pad = nullptr;
448 const GPUTRDTrackletWord* tracklets = GetConstantMem()->ioPtrs.trdTracklets;
449 const GPUTRDSpacePoint* spacePoints = GetConstantMem()->ioPtrs.trdSpacePoints;
450
451#ifdef ENABLE_GPUTRDDEBUG
452 TRDTRK trackNoUp(*t);
453#endif
454
455 int32_t candidateIdxOffset = threadId * 2 * mNCandidates;
456 int32_t hypothesisIdxOffset = threadId * mNCandidates;
457 int32_t trkltIdxOffset = collisionId * (kNChambers + 1); // offset for accessing mTrackletIndexArray for given collision
458 int32_t glbTrkltIdxOffset = (mProcessPerTimeFrame) ? GetConstantMem()->ioPtrs.trdTrackletIdxFirst[collisionId] : 0; // offset of first tracklet in given collision in global tracklet array
459
460 auto trkWork = t;
461 if (mNCandidates > 1) {
462 // copy input track to first candidate
463 mCandidates[candidateIdxOffset] = *t;
464 }
465
466 int32_t nCandidates = 1; // we always start with one candidate
467 int32_t nCurrHypothesis = 0; // the number of track hypothesis in given iLayer
468
469 // search window
470 float roadY = 0.f;
471 float roadZ = 0.f;
472 const int32_t nMaxChambersToSearch = 4;
473
474 mDebug->SetGeneralInfo(mNEvents, mNTracks, iTrk, t->getPt());
475
476 for (int32_t iLayer = 0; iLayer < kNLayers; ++iLayer) {
477 nCurrHypothesis = 0;
478 bool isOK = false; // if at least one candidate could be propagated or the track was stopped this becomes true
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()); // tilt is signed!
483 const float zMaxTRD = pad->GetRow0();
484
485 // --------------------------------------------------------------------------------
486 //
487 // for each candidate, propagate to layer radius and look for close tracklets
488 //
489 // --------------------------------------------------------------------------------
490 for (int32_t iCandidate = 0; iCandidate < nCandidates; iCandidate++) {
491
492 int32_t det[nMaxChambersToSearch] = {-1, -1, -1, -1}; // TRD chambers to be searched for tracklets
493
494 if (mNCandidates > 1) {
495 trkWork = &mCandidates[2 * iCandidate + currIdx];
496 prop->setTrack(trkWork);
497 }
498
499 if (trkWork->getIsStopped()) {
500 Hypothesis hypo(trkWork->getNlayersFindable(), iCandidate, -1, trkWork->getChi2());
501 InsertHypothesis(hypo, nCurrHypothesis, hypothesisIdxOffset);
502 isOK = true;
503 continue;
504 }
505
506 // propagate track to average radius of TRD layer iLayer (sector 0, stack 2 is chosen as a reference)
507 if (!prop->propagateToX(mR[2 * kNLayers + iLayer], .8f, 2.f)) {
508 if (ENABLE_INFO) {
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]);
510 }
511 continue;
512 }
513
514 // rotate track in new sector in case of sector crossing
515 if (!AdjustSector(prop, trkWork)) {
516 if (ENABLE_INFO) {
517 GPUInfo("Adjusting sector failed for track %i candidate %i in layer %i", iTrk, iCandidate, iLayer);
518 }
519 continue;
520 }
521
522 // check if track is findable
523 if (IsGeoFindable(trkWork, iLayer, prop->getAlpha(), zShiftTrk)) {
524 trkWork->setIsFindable(iLayer);
525 }
526
527 // define search window
528 roadY = 7.f * CAMath::Sqrt(trkWork->getSigmaY2() + 0.1f * 0.1f) + Param().rec.trd.extraRoadY; // add constant to the road to account for uncertainty due to radial deviations (few mm)
529 // roadZ = 7.f * CAMath::Sqrt(trkWork->getSigmaZ2() + 9.f * 9.f / 12.f); // take longest pad length
530 roadZ = mRoadZ + Param().rec.trd.extraRoadZ; // simply twice the longest pad length -> efficiency 99.996%
531 //
532 if (CAMath::Abs(trkWork->getZ() + zShiftTrk) - roadZ >= zMaxTRD) {
533 if (ENABLE_INFO) {
534 GPUInfo("Track out of TRD acceptance with z=%f in layer %i (eta=%f)", trkWork->getZ() + zShiftTrk, iLayer, trkWork->getEta());
535 }
536 continue;
537 }
538
539 // determine chamber(s) to be searched for tracklets
540 FindChambersInRoad(trkWork, roadY, roadZ, iLayer, det, zMaxTRD, prop->getAlpha(), zShiftTrk);
541
542 // track debug information to be stored in case no matching tracklet can be found
543 mDebug->SetTrackParameter(*trkWork, iLayer);
544
545 // look for tracklets in chamber(s)
546 for (int32_t iDet = 0; iDet < nMaxChambersToSearch; iDet++) {
547 int32_t currDet = det[iDet];
548 if (currDet == -1) {
549 continue;
550 }
551 pad = mGeo->GetPadPlane(currDet);
552 int32_t currSec = mGeo->GetSector(currDet);
553 if (currSec != GetSector(prop->getAlpha())) {
554 if (!prop->rotate(GetAlphaOfSector(currSec))) {
555 if (ENABLE_WARNING) {
556 GPUWarning("Track could not be rotated in tracklet coordinate system");
557 }
558 break;
559 }
560 }
561 if (currSec != GetSector(prop->getAlpha())) {
562 GPUError("Track is in sector %i and sector %i is searched for tracklets", GetSector(prop->getAlpha()), currSec);
563 continue;
564 }
565 // propagate track to radius of chamber
566 if (!prop->propagateToX(mR[currDet], .8f, .2f)) {
567 if (ENABLE_WARNING) {
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);
569 }
570 }
571 // first propagate track to x of tracklet
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) {
574 // skip tracklets which are too far away
575 // although the radii of space points and tracks may differ by ~ few mm the roads are large enough to allow no efficiency loss by this cut
576 continue;
577 }
578 float projY, projZ;
579 prop->getPropagatedYZ(spacePoints[trkltIdx].getX(), projY, projZ);
580 // correction for tilted pads (only applied if deltaZ < lPad && track z err << lPad)
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)))) {
584 tiltCorr = 0.f; // will be zero also for TPC tracks which are shifted in z
585 }
586 // correction for mean z position of tracklet (is not the center of the pad if track eta != 0)
587 float zPosCorr = spacePoints[trkltIdx].getZ() + mZCorrCoefNRC * trkWork->getTgl();
588 float yPosCorr = spacePoints[trkltIdx].getY() - tiltCorr;
589 zPosCorr -= zShiftTrk; // shift tracklet instead of track in order to avoid having to do a re-fit for each collision
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)) { // TODO: check if this is still necessary after the cut before propagation of track
595 // tracklet is in windwow: get predicted chi2 for update and store tracklet index if best guess
596 RecalcTrkltCov(tilt, trkWork->getSnp(), pad->GetRowSize(tracklets[trkltIdx].GetZbin()), trkltCovTmp);
597 float chi2 = prop->getPredictedChi2(trkltPosTmpYZ, trkltCovTmp);
598 // TODO cut on angular pull should be made stricter when proper v-drift calibration for the TRD tracklets is implemented
599 if ((chi2 > Param().rec.trd.maxChi2) || (Param().rec.trd.applyDeflectionCut && CAMath::Abs(GetAngularPull(spacePoints[trkltIdx].getDy(), trkWork->getSnp())) > 4)) {
600 continue;
601 }
602 Hypothesis hypo(trkWork->getNlayersFindable(), iCandidate, trkltIdx, trkWork->getChi2() + chi2);
603 InsertHypothesis(hypo, nCurrHypothesis, hypothesisIdxOffset);
604 } // end tracklet in window
605 } // tracklet loop
606 } // chamber loop
607
608 // add no update to hypothesis list
609 Hypothesis hypoNoUpdate(trkWork->getNlayersFindable(), iCandidate, -1, trkWork->getChi2() + Param().rec.trd.penaltyChi2);
610 InsertHypothesis(hypoNoUpdate, nCurrHypothesis, hypothesisIdxOffset);
611 isOK = true;
612 } // end candidate loop
613
614 mDebug->SetChi2Update(mHypothesis[0 + hypothesisIdxOffset].mChi2 - t->getChi2(), iLayer); // only meaningful for ONE candidate!!!
615 mDebug->SetRoad(roadY, roadZ, iLayer); // only meaningful for ONE candidate
616 bool wasTrackStored = false;
617 // --------------------------------------------------------------------------------
618 //
619 // loop over the best N_candidates hypothesis
620 //
621 // --------------------------------------------------------------------------------
622 // GPUInfo("nCurrHypothesis=%i, nCandidates=%i", nCurrHypothesis, nCandidates);
623 // for (int32_t idx=0; idx<10; ++idx) { GPUInfo("mHypothesis[%i]: candidateId=%i, nLayers=%i, trackletId=%i, chi2=%f", idx, mHypothesis[idx].mCandidateId, mHypothesis[idx].mLayers, mHypothesis[idx].mTrackletId, mHypothesis[idx].mChi2); }
624 for (int32_t iUpdate = 0; iUpdate < nCurrHypothesis && iUpdate < mNCandidates; iUpdate++) {
625 if (mHypothesis[iUpdate + hypothesisIdxOffset].mCandidateId == -1) {
626 // no more candidates
627 if (iUpdate == 0) {
628 return false; // no valid candidates for this track (probably propagation failed)
629 }
630 break; // go to next layer
631 }
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];
636 }
637 if (mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId == -1) {
638 // no matching tracklet found
639 if (trkWork->getIsFindable(iLayer)) {
640 if (trkWork->getNmissingConsecLayers(iLayer) > Param().rec.trd.stopTrkAfterNMissLy) {
641 trkWork->setIsStopped();
642 }
643 trkWork->setChi2(trkWork->getChi2() + Param().rec.trd.penaltyChi2);
644 }
645 if (iUpdate == 0 && mNCandidates > 1) { // TODO: is thie really necessary????? CHECK!
646 *t = mCandidates[2 * iUpdate + nextIdx];
647 }
648 continue;
649 }
650 // matching tracklet found
651 if (mNCandidates > 1) {
652 prop->setTrack(trkWork);
653 }
654 int32_t trkltSec = mGeo->GetSector(tracklets[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].GetDetector());
655 if (trkltSec != GetSector(prop->getAlpha())) {
656 // if after a matching tracklet was found another sector was searched for tracklets the track needs to be rotated back
657 prop->rotate(GetAlphaOfSector(trkltSec));
658 }
659 if (!prop->propagateToX(spacePoints[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].getX(), .8f, 2.f)) {
660 if (ENABLE_WARNING) {
661 GPUWarning("Final track propagation for track %i update %i in layer %i failed", iTrk, iUpdate, iLayer);
662 }
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();
667 }
668 }
669 if (iUpdate == 0 && mNCandidates > 1) {
670 *t = mCandidates[2 * iUpdate + nextIdx];
671 }
672 continue;
673 }
674
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))) {
681 tiltCorrUp = 0.f;
682 }
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);
686
687#ifdef ENABLE_GPUTRDDEBUG
688 prop->setTrack(&trackNoUp);
689 prop->rotate(GetAlphaOfSector(trkltSec));
690 // prop->propagateToX(spacePoints[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].getX(), .8f, 2.f);
691 prop->propagateToX(mR[tracklets[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].GetDetector()], .8f, 2.f);
692 prop->setTrack(trkWork);
693#endif
694
695 if (!wasTrackStored) {
696#ifdef ENABLE_GPUTRDDEBUG
697 mDebug->SetTrackParameterNoUp(trackNoUp, iLayer);
698#endif
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;
705 }
706
707 if (!prop->update(trkltPosUp, trkltCovUp)) {
708 if (ENABLE_WARNING) {
709 GPUWarning("Failed to update track %i with space point in layer %i", iTrk, iLayer);
710 }
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();
715 }
716 }
717 if (iUpdate == 0 && mNCandidates > 1) {
718 *t = mCandidates[2 * iUpdate + nextIdx];
719 }
720 continue;
721 }
722 if (!trkWork->CheckNumericalQuality()) {
723 if (ENABLE_INFO) {
724 GPUInfo("Track %i has invalid covariance matrix. Aborting track following\n", iTrk);
725 }
726 return false;
727 }
728 trkWork->addTracklet(iLayer, mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId);
729 trkWork->setChi2(mHypothesis[iUpdate + hypothesisIdxOffset].mChi2);
730 trkWork->setIsFindable(iLayer);
731 trkWork->setCollisionId(collisionId);
732 // check if track crosses padrows
733 float projZEntry, projYEntry;
734 // Get Z for Entry of Track
735 prop->getPropagatedYZ(trkWork->getX() - mGeo->GetCdrHght(), projYEntry, projZEntry);
736 // Get Padrow number for Exit&Entry and compare. If is not equal mark
737 // as padrow crossing. While simple, this comes with the cost of not
738 // properly handling Tracklets that hit a different Pad but still get
739 // attached to the Track. It is estimated that the probability for
740 // this is low.
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();
746 }
747 const auto currDet = tracklets[mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId].GetDetector();
748 // Mark tracklets as Padrow crossing if they have a neighboring tracklet.
749 for (int32_t trkltIdx = glbTrkltIdxOffset + mTrackletIndexArray[trkltIdxOffset + currDet]; trkltIdx < glbTrkltIdxOffset + mTrackletIndexArray[trkltIdxOffset + currDet + 1]; ++trkltIdx) {
750 // skip orig tracklet
751 if (mHypothesis[iUpdate + hypothesisIdxOffset].mTrackletId == trkltIdx) {
752 continue;
753 }
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();
758 break;
759 }
760 }
761 if (iUpdate == 0 && mNCandidates > 1) {
762 *t = mCandidates[2 * iUpdate + nextIdx];
763 }
764 } // end update loop
765
766 if (!isOK) {
767 if (ENABLE_INFO) {
768 GPUInfo("Track %i cannot be followed. Stopped in layer %i", iTrk, iLayer);
769 }
770 return false;
771 }
772 } // end layer loop
773
774 // --------------------------------------------------------------------------------
775 // add some debug information (compare labels of attached tracklets to track label)
776 // and store full track information
777 // --------------------------------------------------------------------------------
778 if (mDebugOutput) {
779 mDebug->SetTrack(*t);
780 mDebug->Output();
781 }
782 if (ENABLE_INFO) {
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());
784 }
785 if (nCurrHypothesis > 1) {
786 if (CAMath::Abs(mHypothesis[hypothesisIdxOffset + 1].GetReducedChi2() - mHypothesis[hypothesisIdxOffset].GetReducedChi2()) < Param().rec.trd.chi2SeparationCut) {
787 t->setIsAmbiguous();
788 }
789 }
790 return true;
791}
792
793template <class TRDTRK, class PROP>
794GPUd() void GPUTRDTracker_t<TRDTRK, PROP>::InsertHypothesis(Hypothesis hypo, int32_t& nCurrHypothesis, int32_t idxOffset)
795{
796 // Insert hypothesis into the array. If the array is full and the reduced chi2 is worse
797 // than the worst hypothesis in the array it is dropped.
798 // The hypothesis array is always sorted.
799
800 if (nCurrHypothesis == 0) {
801 // this is the first hypothesis in the array
802 mHypothesis[idxOffset] = hypo;
803 ++nCurrHypothesis;
804 } else if (nCurrHypothesis > 0 && nCurrHypothesis < mNCandidates) {
805 // insert the hypothesis into the right position and shift all worse hypothesis to the right
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];
810 }
811 mHypothesis[i] = hypo;
812 ++nCurrHypothesis;
813 return;
814 }
815 }
816 mHypothesis[nCurrHypothesis + idxOffset] = hypo;
817 ++nCurrHypothesis;
818 return;
819 } else {
820 // array is already full, check if new hypothesis should be inserted
821 int32_t i = nCurrHypothesis + idxOffset - 1;
822 for (; i >= idxOffset; --i) {
823 if (mHypothesis[i].GetReducedChi2() < hypo.GetReducedChi2()) {
824 break;
825 }
826 }
827 if (i < (nCurrHypothesis + idxOffset - 1)) {
828 // new hypothesis should be inserted into the array
829 for (int32_t k = nCurrHypothesis + idxOffset - 1; k > i + 1; --k) {
830 mHypothesis[k] = mHypothesis[k - 1];
831 }
832 mHypothesis[i + 1] = hypo;
833 }
834 }
835}
836
837template <class TRDTRK, class PROP>
838GPUd() int32_t GPUTRDTracker_t<TRDTRK, PROP>::GetDetectorNumber(const float zPos, const float alpha, const int32_t layer) const
839{
840 //--------------------------------------------------------------------
841 // if track position is within chamber return the chamber number
842 // otherwise return -1
843 //--------------------------------------------------------------------
844 int32_t stack = mGeo->GetStack(zPos, layer);
845 if (stack < 0) {
846 return -1;
847 }
848 int32_t sector = GetSector(alpha);
849
850 return mGeo->GetDetector(layer, stack, sector);
851}
852
853template <class TRDTRK, class PROP>
854GPUd() bool GPUTRDTracker_t<TRDTRK, PROP>::AdjustSector(PROP* prop, TRDTRK* t) const
855{
856 //--------------------------------------------------------------------
857 // rotate track in new sector if necessary and
858 // propagate to previous x afterwards
859 // cancel if track crosses two sector boundaries
860 //--------------------------------------------------------------------
861 float alpha = mGeo->GetAlpha();
862 float xTmp = t->getX();
863 float y = t->getY();
864 float yMax = t->getX() * CAMath::Tan(0.5f * alpha);
865 float alphaCurr = t->getAlpha();
866
867 if (CAMath::Abs(y) > 2.f * yMax) {
868 if (ENABLE_INFO) {
869 GPUInfo("AdjustSector: Track %i with pT = %f crossing two sector boundaries at x = %f", t->getRefGlobalTrackIdRaw(), t->getPt(), t->getX());
870 }
871 return false;
872 }
873
874 int32_t nTries = 0;
875 while (CAMath::Abs(y) > yMax) {
876 if (nTries >= 2) {
877 return false;
878 }
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();
885 }
886 if (!prop->rotate(alphaNew)) {
887 return false;
888 }
889 if (!prop->propagateToX(xTmp, .8f, 2.f)) {
890 return false;
891 }
892 y = t->getY();
893 ++nTries;
894 }
895 return true;
896}
897
898template <class TRDTRK, class PROP>
899GPUd() int32_t GPUTRDTracker_t<TRDTRK, PROP>::GetSector(float alpha) const
900{
901 //--------------------------------------------------------------------
902 // TRD sector number for reference system alpha
903 //--------------------------------------------------------------------
904 if (alpha < 0) {
905 alpha += 2.f * CAMath::Pi();
906 } else if (alpha >= 2.f * CAMath::Pi()) {
907 alpha -= 2.f * CAMath::Pi();
908 }
909 return (int32_t)(alpha * (float)kNSectors / (2.f * CAMath::Pi()));
910}
911
912template <class TRDTRK, class PROP>
913GPUd() float GPUTRDTracker_t<TRDTRK, PROP>::GetAlphaOfSector(const int32_t sec) const
914{
915 //--------------------------------------------------------------------
916 // rotation angle for TRD sector sec
917 //--------------------------------------------------------------------
918 float alpha = 2.0f * CAMath::Pi() / (float)kNSectors * ((float)sec + 0.5f);
919 if (alpha > CAMath::Pi()) {
920 alpha -= 2 * CAMath::Pi();
921 }
922 return alpha;
923}
924
925template <class TRDTRK, class PROP>
926GPUd() void GPUTRDTracker_t<TRDTRK, PROP>::RecalcTrkltCov(const float tilt, const float snp, const float rowSize, float (&cov)[3])
927{
928 //--------------------------------------------------------------------
929 // recalculate tracklet covariance taking track phi angle into account
930 // store the new values in cov
931 //--------------------------------------------------------------------
932 float t2 = tilt * tilt; // tan^2 (tilt)
933 float c2 = 1.f / (1.f + t2); // cos^2 (tilt)
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);
939}
940
941template <class TRDTRK, class PROP>
942GPUd() float GPUTRDTracker_t<TRDTRK, PROP>::GetAngularPull(float dYtracklet, float snp) const
943{
944 float dYtrack = mRecoParam->convertAngleToDy(snp);
945 float dYresolution = mRecoParam->getDyRes(snp);
946 if (dYresolution < 1e-6f) {
947 return 999.f;
948 }
949 return (dYtracklet - dYtrack) / CAMath::Sqrt(dYresolution);
950}
951
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
954{
955 //--------------------------------------------------------------------
956 // determine initial chamber where the track ends up
957 // add more chambers of the same sector or (and) neighbouring
958 // stack if track is close the edge(s) of the chamber
959 //--------------------------------------------------------------------
960
961 const float yMax = CAMath::Abs(mGeo->GetCol0(iLayer));
962 float zTrk = t->getZ() + zShiftTrk;
963
964 int32_t currStack = mGeo->GetStack(zTrk, iLayer);
965 int32_t currSec = GetSector(alpha);
966 int32_t currDet;
967
968 int32_t nDets = 0;
969
970 if (currStack > -1) {
971 // chamber unambiguous
972 currDet = mGeo->GetDetector(iLayer, currStack, currSec);
973 det[nDets++] = currDet;
974 const GPUTRDpadPlane* pp = mGeo->GetPadPlane(iLayer, currStack);
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);
981 }
982 }
983 } else {
984 if (CAMath::Abs(zTrk) > zMax) {
985 // shift track in z so it is in the TRD acceptance
986 if (zTrk > 0) {
987 currDet = mGeo->GetDetector(iLayer, 0, currSec);
988 } else {
989 currDet = mGeo->GetDetector(iLayer, kNStacks - 1, currSec);
990 }
991 det[nDets++] = currDet;
992 currStack = mGeo->GetStack(currDet);
993 } else {
994 // track in between two stacks, add both surrounding chambers
995 // gap between two stacks is 4 cm wide
996 currDet = GetDetectorNumber(zTrk + 4.0f, alpha, iLayer);
997 if (currDet != -1) {
998 det[nDets++] = currDet;
999 }
1000 currDet = GetDetectorNumber(zTrk - 4.0f, alpha, iLayer);
1001 if (currDet != -1) {
1002 det[nDets++] = currDet;
1003 }
1004 }
1005 }
1006 // add chamber(s) from neighbouring sector in case the track is close to the boundary
1007 if ((CAMath::Abs(t->getY()) + roadY) > yMax) {
1008 const int32_t nStacksToSearch = nDets;
1009 int32_t newSec;
1010 if (t->getY() > 0) {
1011 newSec = (currSec + 1) % kNSectors;
1012 } else {
1013 newSec = (currSec > 0) ? currSec - 1 : kNSectors - 1;
1014 }
1015 for (int32_t idx = 0; idx < nStacksToSearch; ++idx) {
1016 currStack = mGeo->GetStack(det[idx]);
1017 det[nDets++] = mGeo->GetDetector(iLayer, currStack, newSec);
1018 }
1019 }
1020 // skip PHOS hole and non-existing chamber 17_4_4
1021 for (int32_t iDet = 0; iDet < nDets; iDet++) {
1022 if (!mGeo->ChamberInGeometry(det[iDet])) {
1023 det[iDet] = -1;
1024 }
1025 }
1026}
1027
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
1030{
1031 //--------------------------------------------------------------------
1032 // returns true if track position inside active area of the TRD
1033 // and not too close to the boundaries
1034 //--------------------------------------------------------------------
1035
1036 float zTrk = t->getZ() + zShiftTrk;
1037
1038 int32_t det = GetDetectorNumber(zTrk, alpha, layer);
1039
1040 // reject tracks between stacks
1041 if (det < 0) {
1042 return false;
1043 }
1044
1045 // reject tracks in PHOS hole and for non existent chamber 17_4_4
1046 if (!mGeo->ChamberInGeometry(det)) {
1047 return false;
1048 }
1049
1050 const GPUTRDpadPlane* pp = mGeo->GetPadPlane(det);
1051 float yMax = pp->GetColEnd();
1052 float zMax = pp->GetRow0();
1053 float zMin = pp->GetRowEnd();
1054
1055 float epsY = 5.f;
1056 float epsZ = 5.f;
1057
1058 // reject tracks closer than epsY cm to pad plane boundary
1059 if (yMax - CAMath::Abs(t->getY()) < epsY) {
1060 return false;
1061 }
1062 // reject tracks closer than epsZ cm to stack boundary
1063 if (!((zTrk > zMin + epsZ) && (zTrk < zMax - epsZ))) {
1064 return false;
1065 }
1066
1067 return true;
1068}
1069
1070#ifndef GPUCA_GPUCODE
1071namespace o2::gpu
1072{
1075} // namespace o2::gpu
1076#endif
int32_t i
float float float & zMax
float float & zMin
float & yMax
For performance analysis + error parametrization of the TRD tracker.
#define ENABLE_INFO
#define ENABLE_WARNING
Online TRD tracker based on extrapolated TPC tracks.
TRD Tracklet word for GPU tracker - 32bit tracklet info + half chamber ID + index.
uint32_t stack
Definition RawData.h:1
GPUTrackingInOutPointers & mIOPtrs
void * SetPointersTracks(void *base)
void * SetPointersBase(void *base)
void SetNCandidates(int32_t n)
void SetMaxData(const GPUTrackingInOutPointers &io)
void PrepareTracking(GPUChainTracking *chainTracking)
void * SetPointersTracklets(void *base)
GLdouble n
Definition glcorearb.h:1982
GLfloat GLfloat GLfloat alpha
Definition glcorearb.h:279
GLuint64EXT * result
Definition glcorearb.h:5662
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLuint GLfloat x0
Definition glcorearb.h:5034
GLenum GLuint GLint GLint layer
Definition glcorearb.h:1310
GPUdi() o2
Definition TrackTRD.h:38
GPUd() const expr uint32_t MultivariatePolynomialHelper< Dim
double * getX(double *xyDxy, int N)
double * getY(double *xyDxy, int N)
bool isOK(const SanityError &error)
GPUReconstruction * rec
GPUChainTracking * chainTracking
const GPUTRDSpacePoint * trdSpacePoints
std::vector< Tracklet64 > tracklets