Project
Loading...
Searching...
No Matches
TimeFrame.h
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.
12
13#ifndef TRACKINGITSU_INCLUDE_TIMEFRAME_H_
14#define TRACKINGITSU_INCLUDE_TIMEFRAME_H_
15
16#include <array>
17#include <vector>
18#include <utility>
19#include <algorithm>
20#include <numeric>
21#include <gsl/gsl>
22
24
25#include "ITStracking/Cell.h"
26#include "ITStracking/Cluster.h"
31#include "ITStracking/Road.h"
38
41
42namespace o2
43{
44namespace gpu
45{
46class GPUChainITS;
47}
48
49namespace itsmft
50{
51class Cluster;
52class CompClusterExt;
53class TopologyDictionary;
54class ROFRecord;
55} // namespace itsmft
56
57namespace its
58{
59namespace gpu
60{
61template <int>
62class TimeFrameGPU;
63}
64
65template <int nLayers = 7>
66struct TimeFrame {
69 friend class gpu::TimeFrameGPU<nLayers>;
70
71 TimeFrame() = default;
72 virtual ~TimeFrame() = default;
73
74 const Vertex& getPrimaryVertex(const int ivtx) const { return mPrimaryVertices[ivtx]; }
75 gsl::span<const Vertex> getPrimaryVertices(int rofId) const;
76 gsl::span<const Vertex> getPrimaryVertices(int romin, int romax) const;
77 gsl::span<const std::pair<MCCompLabel, float>> getPrimaryVerticesMCRecInfo(const int rofId) const;
78 gsl::span<const MCCompLabel> getPrimaryVerticesContributors(const int rofId) const;
79 gsl::span<const std::array<float, 2>> getPrimaryVerticesXAlpha(int rofId) const;
81 int getPrimaryVerticesNum(int rofId = -1) const;
82 void addPrimaryVerticesLabels(bounded_vector<std::pair<MCCompLabel, float>>& labels);
84 void addPrimaryVertices(const bounded_vector<Vertex>& vertices, const int iteration);
85 void addPrimaryVerticesInROF(const bounded_vector<Vertex>& vertices, const int rofId, const int iteration);
86 void addPrimaryVerticesLabelsInROF(const bounded_vector<std::pair<MCCompLabel, float>>& labels, const int rofId);
88 void removePrimaryVerticesInROf(const int rofId);
89 int loadROFrameData(const o2::itsmft::ROFRecord& rof, gsl::span<const itsmft::Cluster> clusters,
90 const dataformats::MCTruthContainer<MCCompLabel>* mcLabels = nullptr);
91
92 int loadROFrameData(gsl::span<const o2::itsmft::ROFRecord> rofs,
93 gsl::span<const itsmft::CompClusterExt> clusters,
94 gsl::span<const unsigned char>::iterator& pattIt,
96 const dataformats::MCTruthContainer<MCCompLabel>* mcLabels = nullptr);
97 void resetROFrameData(size_t nROFs);
98 void prepareROFrameData(gsl::span<const o2::itsmft::ROFRecord> rofs,
99 gsl::span<const itsmft::CompClusterExt> clusters);
100
101 int getTotalClusters() const;
102 auto& getTotVertIteration() { return mTotVertPerIteration; }
103 bool empty() const { return getTotalClusters() == 0; }
104 int getSortedIndex(int rofId, int layer, int idx) const { return mROFramesClusters[layer][rofId] + idx; }
105 int getSortedStartIndex(const int rofId, const int layer) const { return mROFramesClusters[layer][rofId]; }
106 int getNrof() const { return mNrof; }
107
108 void resetBeamXY(const float x, const float y, const float w = 0);
109 void setBeamPosition(const float x, const float y, const float s2, const float base = 50.f, const float systematic = 0.f)
110 {
111 isBeamPositionOverridden = true;
112 resetBeamXY(x, y, s2 / o2::gpu::CAMath::Sqrt(base * base + systematic));
113 }
114
115 float getBeamX() const { return mBeamPos[0]; }
116 float getBeamY() const { return mBeamPos[1]; }
117 auto& getMinRs() { return mMinR; }
118 auto& getMaxRs() { return mMaxR; }
119 float getMinR(int layer) const { return mMinR[layer]; }
120 float getMaxR(int layer) const { return mMaxR[layer]; }
121 float getMSangle(int layer) const { return mMSangles[layer]; }
122 auto& getMSangles() { return mMSangles; }
123 float getPhiCut(int layer) const { return mPhiCuts[layer]; }
124 auto& getPhiCuts() { return mPhiCuts; }
125 float getPositionResolution(int layer) const { return mPositionResolution[layer]; }
126 auto& getPositionResolutions() { return mPositionResolution; }
127
128 gsl::span<Cluster> getClustersOnLayer(int rofId, int layerId);
129 gsl::span<const Cluster> getClustersOnLayer(int rofId, int layerId) const;
130 gsl::span<const Cluster> getClustersPerROFrange(int rofMin, int range, int layerId) const;
131 gsl::span<const Cluster> getUnsortedClustersOnLayer(int rofId, int layerId) const;
132 gsl::span<uint8_t> getUsedClustersROF(int rofId, int layerId);
133 gsl::span<const uint8_t> getUsedClustersROF(int rofId, int layerId) const;
134 gsl::span<const int> getROFramesClustersPerROFrange(int rofMin, int range, int layerId) const;
135 gsl::span<const int> getROFrameClusters(int layerId) const;
136 gsl::span<const int> getNClustersROFrange(int rofMin, int range, int layerId) const;
137 gsl::span<const int> getIndexTablePerROFrange(int rofMin, int range, int layerId) const;
138 gsl::span<int> getIndexTable(int rofId, int layerId);
139 auto& getIndexTableWhole(int layerId) { return mIndexTables[layerId]; }
140 const auto& getTrackingFrameInfoOnLayer(int layerId) const { return mTrackingFrameInfo[layerId]; }
141
142 const TrackingFrameInfo& getClusterTrackingFrameInfo(int layerId, const Cluster& cl) const;
143 gsl::span<const MCCompLabel> getClusterLabels(int layerId, const Cluster& cl) const { return getClusterLabels(layerId, cl.clusterId); }
144 gsl::span<const MCCompLabel> getClusterLabels(int layerId, const int clId) const { return mClusterLabels->getLabels(mClusterExternalIndices[layerId][clId]); }
145 int getClusterExternalIndex(int layerId, const int clId) const { return mClusterExternalIndices[layerId][clId]; }
146 int getClusterSize(int clusterId) const { return mClusterSize[clusterId]; }
147 void setClusterSize(bounded_vector<uint8_t>& v) { mClusterSize = std::move(v); }
148
149 auto& getTrackletsLabel(int layer) { return mTrackletLabels[layer]; }
150 auto& getCellsLabel(int layer) { return mCellLabels[layer]; }
151
152 bool hasMCinformation() const { return mClusterLabels; }
153 void initialise(const int iteration, const TrackingParameters& trkParam, const int maxLayers = 7, bool resetVertices = true);
155 {
157 mROFramesPV.resize(1, 0);
158 mTotVertPerIteration.resize(1);
159 }
160
161 bool isClusterUsed(int layer, int clusterId) const { return mUsedClusters[layer][clusterId]; }
162 void markUsedCluster(int layer, int clusterId) { mUsedClusters[layer][clusterId] = true; }
163 gsl::span<unsigned char> getUsedClusters(const int layer);
164
165 auto& getTracklets() { return mTracklets; }
167
168 auto& getClusters() { return mClusters; }
170 int getClusterROF(int iLayer, int iCluster);
171 auto& getCells() { return mCells; }
172
175 auto& getCellsNeighboursLUT() { return mCellsNeighboursLUT; }
176 auto& getRoads() { return mRoads; }
177 auto& getTracks(int rofId) { return mTracks[rofId]; }
178 auto& getTracksLabel(const int rofId) { return mTracksLabel[rofId]; }
179 auto& getLinesLabel(const int rofId) { return mLinesLabels[rofId]; }
180 auto& getVerticesMCRecInfo() { return mVerticesMCRecInfo; }
181
183 virtual int getNumberOfCells() const;
184 virtual int getNumberOfTracklets() const;
185 virtual int getNumberOfNeighbours() const;
186 size_t getNumberOfTracks() const;
190
192 void setMemoryPool(std::shared_ptr<BoundedMemoryResource> pool);
193 auto& getMemoryPool() const noexcept { return mMemoryPool; }
194 bool checkMemory(unsigned long max) { return getArtefactsMemory() < max; }
195 unsigned long getArtefactsMemory() const;
196 void printArtefactsMemory() const;
197
199 int getROFCutClusterMult() const { return mCutClusterMult; };
200 int getROFCutVertexMult() const { return mCutVertexMult; };
201 int getROFCutAllMult() const { return mCutClusterMult + mCutVertexMult; }
202
203 // Vertexer
206 int& getNTrackletsROF(int rofId, int combId) { return mNTrackletsPerROF[combId][rofId]; }
207 auto& getLines(int rofId) { return mLines[rofId]; }
208 int getNLinesTotal() const noexcept { return mTotalLines; }
209 void setNLinesTotal(uint32_t a) noexcept { mTotalLines = a; }
210 auto& getTrackletClusters(int rofId) { return mTrackletClusters[rofId]; }
211 gsl::span<const Tracklet> getFoundTracklets(int rofId, int combId) const;
212 gsl::span<Tracklet> getFoundTracklets(int rofId, int combId);
213 gsl::span<const MCCompLabel> getLabelsFoundTracklets(int rofId, int combId) const;
214 gsl::span<int> getNTrackletsCluster(int rofId, int combId);
215 gsl::span<int> getExclusiveNTrackletsCluster(int rofId, int combId);
216 uint32_t getTotalTrackletsTF(const int iLayer) { return mTotalTracklets[iLayer]; }
217 int getTotalClustersPerROFrange(int rofMin, int range, int layerId) const;
218 std::array<float, 2>& getBeamXY() { return mBeamPos; }
219 unsigned int& getNoVertexROF() { return mNoVertexROF; }
220 void insertPastVertex(const Vertex& vertex, const int refROFId);
221 // \Vertexer
222
224 void setRoadLabel(int i, const unsigned long long& lab, bool fake);
225 const unsigned long long& getRoadLabel(int i) const { return mRoadLabels[i].first; }
226 bool isRoadFake(int i) const { return mRoadLabels[i].second; }
227
228 void setMultiplicityCutMask(const std::vector<uint8_t>& cutMask) { mMultiplicityCutMask = cutMask; }
229 void setROFMask(const std::vector<uint8_t>& rofMask) { mROFMask = rofMask; }
230 void swapMasks() { mMultiplicityCutMask.swap(mROFMask); }
231
232 int hasBogusClusters() const { return std::accumulate(mBogusClusters.begin(), mBogusClusters.end(), 0); }
233
234 void setBz(float bz) { mBz = bz; }
235 float getBz() const { return mBz; }
236
239 std::shared_ptr<BoundedMemoryResource> mExtMemoryPool; // host memory pool managed by the framework
242 bool hasFrameworkAllocator() const noexcept { return mExternalAllocator != nullptr; }
243 std::pmr::memory_resource* getMaybeFrameworkHostResource(bool forceHost = false) { return (hasFrameworkAllocator() && !forceHost) ? mExtMemoryPool.get() : mMemoryPool.get(); }
244
245 // Propagator
248
249 template <typename... T>
250 void addClusterToLayer(int layer, T&&... args);
251 template <typename... T>
252 void addTrackingFrameInfoToLayer(int layer, T&&... args);
253 void addClusterExternalIndexToLayer(int layer, const int idx) { mClusterExternalIndices[layer].push_back(idx); }
254
256 void checkTrackletLUTs();
257 void printROFoffsets();
258 void printNClsPerROF();
259 void printVertices();
260 void printTrackletLUTonLayer(int i);
261 void printCellLUTonLayer(int i);
262 void printTrackletLUTs();
263 void printCellLUTs();
264 void printSliceInfo(const int, const int);
265
267
268 std::array<bounded_vector<Cluster>, nLayers> mClusters;
269 std::array<bounded_vector<TrackingFrameInfo>, nLayers> mTrackingFrameInfo;
270 std::array<bounded_vector<int>, nLayers> mClusterExternalIndices;
271 std::array<bounded_vector<int>, nLayers> mROFramesClusters;
273 std::array<bounded_vector<int>, 2> mNTrackletsPerCluster;
274 std::array<bounded_vector<int>, 2> mNTrackletsPerClusterSum;
275 std::array<bounded_vector<int>, nLayers> mNClustersPerROF;
276 std::array<bounded_vector<int>, nLayers> mIndexTables;
277 std::vector<bounded_vector<int>> mTrackletsLookupTable;
278 std::array<bounded_vector<uint8_t>, nLayers> mUsedClusters;
279 int mNrof = 0;
284
285 std::array<bounded_vector<Cluster>, nLayers> mUnsortedClusters;
286 std::vector<bounded_vector<Tracklet>> mTracklets;
287 std::vector<bounded_vector<CellSeedN>> mCells;
289 std::vector<bounded_vector<TrackITSExt>> mTracks;
290 std::vector<bounded_vector<int>> mCellsNeighbours;
291 std::vector<bounded_vector<int>> mCellsLookupTable;
292 std::vector<uint8_t> mMultiplicityCutMask;
293
294 const o2::base::PropagatorImpl<float>* mPropagatorDevice = nullptr; // Needed only for GPU
295
296 virtual void wipe();
297
298 // interface
299 virtual bool isGPU() const noexcept { return false; }
300 virtual const char* getName() const noexcept { return "CPU"; }
301
302 private:
303 void prepareClusters(const TrackingParameters& trkParam, const int maxLayers = nLayers);
304 float mBz = 5.;
305 unsigned int mNTotalLowPtVertices = 0;
306 int mBeamPosWeight = 0;
307 std::array<float, 2> mBeamPos = {0.f, 0.f};
308 bool isBeamPositionOverridden = false;
309 std::array<float, nLayers> mMinR;
310 std::array<float, nLayers> mMaxR;
311 bounded_vector<float> mMSangles;
312 bounded_vector<float> mPhiCuts;
313 bounded_vector<float> mPositionResolution;
314 bounded_vector<uint8_t> mClusterSize;
315
316 std::vector<uint8_t> mROFMask;
317 bounded_vector<std::array<float, 2>> mPValphaX;
318 std::vector<bounded_vector<MCCompLabel>> mTrackletLabels;
319 std::vector<bounded_vector<MCCompLabel>> mCellLabels;
320 std::vector<bounded_vector<int>> mCellsNeighboursLUT;
321 std::vector<bounded_vector<MCCompLabel>> mTracksLabel;
322 bounded_vector<int> mBogusClusters;
323
324 bounded_vector<std::pair<unsigned long long, bool>> mRoadLabels;
325 int mCutClusterMult{-999};
326 int mCutVertexMult{-999};
327
328 // Vertexer
329 std::vector<bounded_vector<int>> mNTrackletsPerROF;
330 std::vector<bounded_vector<Line>> mLines;
331 std::vector<bounded_vector<ClusterLines>> mTrackletClusters;
332 std::array<bounded_vector<int>, 2> mTrackletsIndexROF;
333 std::vector<bounded_vector<MCCompLabel>> mLinesLabels;
334 std::vector<std::pair<MCCompLabel, float>> mVerticesMCRecInfo;
335 bounded_vector<MCCompLabel> mVerticesContributorLabels;
336 std::array<uint32_t, 2> mTotalTracklets = {0, 0};
337 uint32_t mTotalLines = 0;
338 unsigned int mNoVertexROF = 0;
339 bounded_vector<int> mTotVertPerIteration;
340 // \Vertexer
341
342 std::shared_ptr<BoundedMemoryResource> mMemoryPool;
343};
344
345template <int nLayers>
346inline gsl::span<const Vertex> TimeFrame<nLayers>::getPrimaryVertices(int rofId) const
347{
348 if (mPrimaryVertices.empty()) {
349 return {};
350 }
351 const int start = mROFramesPV[rofId];
352 const int stop_idx = rofId >= mNrof - 1 ? mNrof : rofId + 1;
353 int delta = mMultiplicityCutMask[rofId] ? mROFramesPV[stop_idx] - start : 0; // return empty span if Rof is excluded
354 return {&mPrimaryVertices[start], static_cast<gsl::span<const Vertex>::size_type>(delta)};
355}
356
357template <int nLayers>
358inline gsl::span<const std::pair<MCCompLabel, float>> TimeFrame<nLayers>::getPrimaryVerticesMCRecInfo(const int rofId) const
359{
360 const int start = mROFramesPV[rofId];
361 const int stop_idx = rofId >= mNrof - 1 ? mNrof : rofId + 1;
362 int delta = mMultiplicityCutMask[rofId] ? mROFramesPV[stop_idx] - start : 0; // return empty span if Rof is excluded
363 return {&(mVerticesMCRecInfo[start]), static_cast<gsl::span<const std::pair<MCCompLabel, float>>::size_type>(delta)};
364}
365
366template <int nLayers>
367inline gsl::span<const MCCompLabel> TimeFrame<nLayers>::getPrimaryVerticesContributors(const int rofId) const
368{
369 // count the number of cont. in rofs before target rof
370 unsigned int start{0}, delta{0};
371 const auto& pvsBefore = getPrimaryVertices(0, rofId - 1);
372 for (const auto& pv : pvsBefore) {
373 start += pv.getNContributors();
374 }
375 const auto& pvsIn = getPrimaryVertices(rofId);
376 for (const auto& pv : pvsIn) {
377 delta += pv.getNContributors();
378 }
379 return {&(mVerticesContributorLabels[start]), static_cast<gsl::span<const MCCompLabel>::size_type>(delta)};
380}
381
382template <int nLayers>
383inline gsl::span<const Vertex> TimeFrame<nLayers>::getPrimaryVertices(int romin, int romax) const
384{
385 if (mPrimaryVertices.empty()) {
386 return {};
387 }
388 const int stop_idx = romax >= mNrof - 1 ? mNrof : romax + 1;
389 return {&mPrimaryVertices[mROFramesPV[romin]], static_cast<gsl::span<const Vertex>::size_type>(mROFramesPV[stop_idx] - mROFramesPV[romin])};
390}
391
392template <int nLayers>
393inline gsl::span<const std::array<float, 2>> TimeFrame<nLayers>::getPrimaryVerticesXAlpha(int rofId) const
394{
395 const int start = mROFramesPV[rofId];
396 const int stop_idx = rofId >= mNrof - 1 ? mNrof : rofId + 1;
397 int delta = mMultiplicityCutMask[rofId] ? mROFramesPV[stop_idx] - start : 0; // return empty span if Rof is excluded
398 return {&(mPValphaX[start]), static_cast<gsl::span<const std::array<float, 2>>::size_type>(delta)};
399}
400
401template <int nLayers>
403{
404 return rofId < 0 ? mPrimaryVertices.size() : mROFramesPV[rofId + 1] - mROFramesPV[rofId];
405}
406
407template <int nLayers>
408inline void TimeFrame<nLayers>::resetBeamXY(const float x, const float y, const float w)
409{
410 mBeamPos[0] = x;
411 mBeamPos[1] = y;
412 mBeamPosWeight = w;
413}
414
415template <int nLayers>
416inline gsl::span<const int> TimeFrame<nLayers>::getROFrameClusters(int layerId) const
417{
418 return {&mROFramesClusters[layerId][0], static_cast<gsl::span<const int>::size_type>(mROFramesClusters[layerId].size())};
419}
420
421template <int nLayers>
422inline gsl::span<Cluster> TimeFrame<nLayers>::getClustersOnLayer(int rofId, int layerId)
423{
424 if (rofId < 0 || rofId >= mNrof) {
425 return {};
426 }
427 int startIdx{mROFramesClusters[layerId][rofId]};
428 return {&mClusters[layerId][startIdx], static_cast<gsl::span<Cluster>::size_type>(mROFramesClusters[layerId][rofId + 1] - startIdx)};
429}
430
431template <int nLayers>
432inline gsl::span<const Cluster> TimeFrame<nLayers>::getClustersOnLayer(int rofId, int layerId) const
433{
434 if (rofId < 0 || rofId >= mNrof) {
435 return {};
436 }
437 int startIdx{mROFramesClusters[layerId][rofId]};
438 return {&mClusters[layerId][startIdx], static_cast<gsl::span<const Cluster>::size_type>(mROFramesClusters[layerId][rofId + 1] - startIdx)};
439}
440
441template <int nLayers>
442inline gsl::span<uint8_t> TimeFrame<nLayers>::getUsedClustersROF(int rofId, int layerId)
443{
444 if (rofId < 0 || rofId >= mNrof) {
445 return {};
446 }
447 int startIdx{mROFramesClusters[layerId][rofId]};
448 return {&mUsedClusters[layerId][startIdx], static_cast<gsl::span<uint8_t>::size_type>(mROFramesClusters[layerId][rofId + 1] - startIdx)};
449}
450
451template <int nLayers>
452inline gsl::span<const uint8_t> TimeFrame<nLayers>::getUsedClustersROF(int rofId, int layerId) const
453{
454 if (rofId < 0 || rofId >= mNrof) {
455 return {};
456 }
457 int startIdx{mROFramesClusters[layerId][rofId]};
458 return {&mUsedClusters[layerId][startIdx], static_cast<gsl::span<const uint8_t>::size_type>(mROFramesClusters[layerId][rofId + 1] - startIdx)};
459}
460
461template <int nLayers>
462inline gsl::span<const Cluster> TimeFrame<nLayers>::getClustersPerROFrange(int rofMin, int range, int layerId) const
463{
464 if (rofMin < 0 || rofMin >= mNrof) {
465 return {};
466 }
467 int startIdx{mROFramesClusters[layerId][rofMin]}; // First cluster of rofMin
468 int endIdx{mROFramesClusters[layerId][o2::gpu::CAMath::Min(rofMin + range, mNrof)]};
469 return {&mClusters[layerId][startIdx], static_cast<gsl::span<Cluster>::size_type>(endIdx - startIdx)};
470}
471
472template <int nLayers>
473inline gsl::span<const int> TimeFrame<nLayers>::getROFramesClustersPerROFrange(int rofMin, int range, int layerId) const
474{
475 int chkdRange{o2::gpu::CAMath::Min(range, mNrof - rofMin)};
476 return {&mROFramesClusters[layerId][rofMin], static_cast<gsl::span<int>::size_type>(chkdRange)};
477}
478
479template <int nLayers>
480inline gsl::span<const int> TimeFrame<nLayers>::getNClustersROFrange(int rofMin, int range, int layerId) const
481{
482 int chkdRange{o2::gpu::CAMath::Min(range, mNrof - rofMin)};
483 return {&mNClustersPerROF[layerId][rofMin], static_cast<gsl::span<int>::size_type>(chkdRange)};
484}
485
486template <int nLayers>
487inline int TimeFrame<nLayers>::getTotalClustersPerROFrange(int rofMin, int range, int layerId) const
488{
489 int startIdx{rofMin}; // First cluster of rofMin
490 int endIdx{o2::gpu::CAMath::Min(rofMin + range, mNrof)};
491 return mROFramesClusters[layerId][endIdx] - mROFramesClusters[layerId][startIdx];
492}
493
494template <int nLayers>
495inline gsl::span<const int> TimeFrame<nLayers>::getIndexTablePerROFrange(int rofMin, int range, int layerId) const
496{
497 const int iTableSize{mIndexTableUtils.getNphiBins() * mIndexTableUtils.getNzBins() + 1};
498 int chkdRange{o2::gpu::CAMath::Min(range, mNrof - rofMin)};
499 return {&mIndexTables[layerId][rofMin * iTableSize], static_cast<gsl::span<int>::size_type>(chkdRange * iTableSize)};
500}
501
502template <int nLayers>
503inline int TimeFrame<nLayers>::getClusterROF(int iLayer, int iCluster)
504{
505 return std::lower_bound(mROFramesClusters[iLayer].begin(), mROFramesClusters[iLayer].end(), iCluster + 1) - mROFramesClusters[iLayer].begin() - 1;
506}
507
508template <int nLayers>
509inline gsl::span<const Cluster> TimeFrame<nLayers>::getUnsortedClustersOnLayer(int rofId, int layerId) const
510{
511 if (rofId < 0 || rofId >= mNrof) {
512 return {};
513 }
514 int startIdx{mROFramesClusters[layerId][rofId]};
515 return {&mUnsortedClusters[layerId][startIdx], static_cast<gsl::span<Cluster>::size_type>(mROFramesClusters[layerId][rofId + 1] - startIdx)};
516}
517
518template <int nLayers>
519inline gsl::span<int> TimeFrame<nLayers>::getIndexTable(int rofId, int layer)
520{
521 if (rofId < 0 || rofId >= mNrof) {
522 return {};
523 }
524 const int tableSize = mIndexTableUtils.getNphiBins() * mIndexTableUtils.getNzBins() + 1;
525 return {&mIndexTables[layer][rofId * tableSize], static_cast<gsl::span<int>::size_type>(tableSize)};
526}
527
528template <int nLayers>
529template <typename... T>
531{
532 mUnsortedClusters[layer].emplace_back(std::forward<T>(values)...);
533}
534
535template <int nLayers>
536template <typename... T>
538{
539 mTrackingFrameInfo[layer].emplace_back(std::forward<T>(values)...);
540}
541
542template <int nLayers>
543inline gsl::span<uint8_t> TimeFrame<nLayers>::getUsedClusters(const int layer)
544{
545 return {&mUsedClusters[layer][0], static_cast<gsl::span<uint8_t>::size_type>(mUsedClusters[layer].size())};
546}
547
548template <int nLayers>
550{
551 mRoadLabels.clear();
552 mRoadLabels.resize(mRoads.size());
553}
554
555template <int nLayers>
556inline void TimeFrame<nLayers>::setRoadLabel(int i, const unsigned long long& lab, bool fake)
557{
558 mRoadLabels[i].first = lab;
559 mRoadLabels[i].second = fake;
560}
561
562template <int nLayers>
563inline gsl::span<int> TimeFrame<nLayers>::getNTrackletsCluster(int rofId, int combId)
564{
565 if (rofId < 0 || rofId >= mNrof) {
566 return {};
567 }
568 auto startIdx{mROFramesClusters[1][rofId]};
569 return {&mNTrackletsPerCluster[combId][startIdx], static_cast<gsl::span<int>::size_type>(mROFramesClusters[1][rofId + 1] - startIdx)};
570}
571
572template <int nLayers>
573inline gsl::span<int> TimeFrame<nLayers>::getExclusiveNTrackletsCluster(int rofId, int combId)
574{
575 if (rofId < 0 || rofId >= mNrof) {
576 return {};
577 }
578 auto clusStartIdx{mROFramesClusters[1][rofId]};
579
580 return {&mNTrackletsPerClusterSum[combId][clusStartIdx], static_cast<gsl::span<int>::size_type>(mROFramesClusters[1][rofId + 1] - clusStartIdx)};
581}
582
583template <int nLayers>
584inline gsl::span<Tracklet> TimeFrame<nLayers>::getFoundTracklets(int rofId, int combId)
585{
586 if (rofId < 0 || rofId >= mNrof || mTracklets[combId].empty()) {
587 return {};
588 }
589 auto startIdx{mNTrackletsPerROF[combId][rofId]};
590 return {&mTracklets[combId][startIdx], static_cast<gsl::span<Tracklet>::size_type>(mNTrackletsPerROF[combId][rofId + 1] - startIdx)};
591}
592
593template <int nLayers>
594inline gsl::span<const Tracklet> TimeFrame<nLayers>::getFoundTracklets(int rofId, int combId) const
595{
596 if (rofId < 0 || rofId >= mNrof) {
597 return {};
598 }
599 auto startIdx{mNTrackletsPerROF[combId][rofId]};
600 return {&mTracklets[combId][startIdx], static_cast<gsl::span<Tracklet>::size_type>(mNTrackletsPerROF[combId][rofId + 1] - startIdx)};
601}
602
603template <int nLayers>
604inline gsl::span<const MCCompLabel> TimeFrame<nLayers>::getLabelsFoundTracklets(int rofId, int combId) const
605{
606 if (rofId < 0 || rofId >= mNrof || !hasMCinformation()) {
607 return {};
608 }
609 auto startIdx{mNTrackletsPerROF[combId][rofId]};
610 return {&mTrackletLabels[combId][startIdx], static_cast<gsl::span<Tracklet>::size_type>(mNTrackletsPerROF[combId][rofId + 1] - startIdx)};
611}
612
613template <int nLayers>
615{
616 size_t totalClusters{0};
617 for (const auto& clusters : mUnsortedClusters) {
618 totalClusters += clusters.size();
619 }
620 return int(totalClusters);
621}
622
623template <int nLayers>
625{
626 int nClusters = 0;
627 for (const auto& layer : mClusters) {
628 nClusters += layer.size();
629 }
630 return nClusters;
631}
632
633template <int nLayers>
635{
636 int nCells = 0;
637 for (const auto& layer : mCells) {
638 nCells += layer.size();
639 }
640 return nCells;
641}
642
643template <int nLayers>
645{
646 int nTracklets = 0;
647 for (const auto& layer : mTracklets) {
648 nTracklets += layer.size();
649 }
650 return nTracklets;
651}
652
653template <int nLayers>
655{
656 int n{0};
657 for (const auto& l : mCellsNeighbours) {
658 n += l.size();
659 }
660 return n;
661}
662
663template <int nLayers>
665{
666 int nTracks = 0;
667 for (const auto& t : mTracks) {
668 nTracks += t.size();
669 }
670 return nTracks;
671}
672
673template <int nLayers>
675{
676 size_t nClusters = 0;
677 for (const auto& layer : mUsedClusters) {
678 nClusters += std::count(layer.begin(), layer.end(), true);
679 }
680 return nClusters;
681}
682
683template <int nLayers>
684inline void TimeFrame<nLayers>::insertPastVertex(const Vertex& vertex, const int iteration)
685{
686 int rofId = vertex.getTimeStamp().getTimeStamp();
687 mPrimaryVertices.insert(mPrimaryVertices.begin() + mROFramesPV[rofId], vertex);
688 for (int i = rofId + 1; i < mROFramesPV.size(); ++i) {
689 mROFramesPV[i]++;
690 }
691 mTotVertPerIteration[iteration]++;
692}
693
694} // namespace its
695} // namespace o2
696
697#endif
std::vector< std::string > labels
uint64_t vertex
Definition RawEventData.h:9
int32_t i
Definition of a container to keep Monte Carlo truth external to simulation objects.
Definition of the ITS track.
int nClusters
A container to hold and manage MC truth information/labels.
HMPID cluster implementation.
Definition Cluster.h:27
GLdouble n
Definition glcorearb.h:1982
GLint GLenum GLint x
Definition glcorearb.h:403
GLuint GLuint end
Definition glcorearb.h:469
const GLdouble * v
Definition glcorearb.h:832
GLenum GLint * range
Definition glcorearb.h:1899
GLint y
Definition glcorearb.h:270
GLenum GLsizei GLsizei GLint * values
Definition glcorearb.h:1576
GLenum GLuint GLint GLint layer
Definition glcorearb.h:1310
GLuint start
Definition glcorearb.h:469
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
GLubyte GLubyte GLubyte GLubyte w
Definition glcorearb.h:852
void deepVectorClear(std::vector< T > &vec)
std::pmr::vector< T > bounded_vector
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
void empty(int)
auto & getPositionResolutions()
Definition TimeFrame.h:126
void addTrackingFrameInfoToLayer(int layer, T &&... args)
Definition TimeFrame.h:537
gsl::span< const MCCompLabel > getPrimaryVerticesContributors(const int rofId) const
Definition TimeFrame.h:367
void setFrameworkAllocator(ExternalAllocator *ext)
void checkTrackletLUTs()
Debug and printing.
gsl::span< const Tracklet > getFoundTracklets(int rofId, int combId) const
Definition TimeFrame.h:594
bool checkMemory(unsigned long max)
Definition TimeFrame.h:194
int getClusterROF(int iLayer, int iCluster)
Definition TimeFrame.h:503
auto & getCellsLabel(int layer)
Definition TimeFrame.h:150
void printTrackletLUTonLayer(int i)
bool isClusterUsed(int layer, int clusterId) const
Definition TimeFrame.h:161
int getNrof() const
Definition TimeFrame.h:106
auto getFrameworkAllocator()
Definition TimeFrame.h:240
void initialise(const int iteration, const TrackingParameters &trkParam, const int maxLayers=7, bool resetVertices=true)
void addPrimaryVertices(const bounded_vector< Vertex > &vertices, const int iteration)
Definition TimeFrame.cxx:50
float getBeamX() const
Definition TimeFrame.h:115
float getMSangle(int layer) const
Definition TimeFrame.h:121
std::vector< bounded_vector< int > > mCellsLookupTable
Definition TimeFrame.h:291
bool hasMCinformation() const
Definition TimeFrame.h:152
auto & getIndexTableWhole(int layerId)
Definition TimeFrame.h:139
std::array< bounded_vector< int >, 2 > mNTrackletsPerClusterSum
Definition TimeFrame.h:274
gsl::span< const MCCompLabel > getClusterLabels(int layerId, const int clId) const
Definition TimeFrame.h:144
auto & getTracks(int rofId)
Definition TimeFrame.h:177
size_t getNumberOfTracks() const
Definition TimeFrame.h:664
unsigned int & getNoVertexROF()
Definition TimeFrame.h:219
int getTotalClustersPerROFrange(int rofMin, int range, int layerId) const
Definition TimeFrame.h:487
virtual int getNumberOfTracklets() const
Definition TimeFrame.h:644
auto & getTrackletsLabel(int layer)
Definition TimeFrame.h:149
ExternalAllocator * mExternalAllocator
State if memory will be externally managed by the GPU framework.
Definition TimeFrame.h:238
std::vector< bounded_vector< Tracklet > > mTracklets
Definition TimeFrame.h:286
gsl::span< const std::pair< MCCompLabel, float > > getPrimaryVerticesMCRecInfo(const int rofId) const
Definition TimeFrame.h:358
void computeTracletsPerClusterScans()
void setBz(float bz)
Definition TimeFrame.h:234
gsl::span< uint8_t > getUsedClustersROF(int rofId, int layerId)
Definition TimeFrame.h:442
const TrackingFrameInfo & getClusterTrackingFrameInfo(int layerId, const Cluster &cl) const
auto & getMSangles()
Definition TimeFrame.h:122
int getClusterExternalIndex(int layerId, const int clId) const
Definition TimeFrame.h:145
virtual void wipe()
void resetBeamXY(const float x, const float y, const float w=0)
Definition TimeFrame.h:408
void addPrimaryVerticesInROF(const bounded_vector< Vertex > &vertices, const int rofId, const int iteration)
Definition TimeFrame.cxx:78
gsl::span< const int > getIndexTablePerROFrange(int rofMin, int range, int layerId) const
Definition TimeFrame.h:495
gsl::span< const Cluster > getClustersOnLayer(int rofId, int layerId) const
Definition TimeFrame.h:432
bounded_vector< int > mROFramesPV
Definition TimeFrame.h:282
std::array< float, 2 > & getBeamXY()
Definition TimeFrame.h:218
virtual const char * getName() const noexcept
Definition TimeFrame.h:300
std::vector< bounded_vector< CellSeedN > > mCells
Definition TimeFrame.h:287
std::array< bounded_vector< int >, nLayers > mClusterExternalIndices
Definition TimeFrame.h:270
bool hasFrameworkAllocator() const noexcept
Definition TimeFrame.h:242
bool isRoadFake(int i) const
Definition TimeFrame.h:226
gsl::span< const Vertex > getPrimaryVertices(int romin, int romax) const
Definition TimeFrame.h:383
void setMemoryPool(std::shared_ptr< BoundedMemoryResource > pool)
memory management
void printSliceInfo(const int, const int)
auto & getTrackletsLookupTable()
Definition TimeFrame.h:166
void setClusterSize(bounded_vector< uint8_t > &v)
Definition TimeFrame.h:147
float getBz() const
Definition TimeFrame.h:235
bounded_vector< Vertex > mPrimaryVertices
Definition TimeFrame.h:283
int getROFCutAllMult() const
Definition TimeFrame.h:201
int getROFCutVertexMult() const
Definition TimeFrame.h:200
std::array< bounded_vector< int >, nLayers > mROFramesClusters
Definition TimeFrame.h:271
std::vector< uint8_t > mMultiplicityCutMask
Definition TimeFrame.h:292
float getPhiCut(int layer) const
Definition TimeFrame.h:123
auto & getTracklets()
Definition TimeFrame.h:165
void prepareROFrameData(gsl::span< const o2::itsmft::ROFRecord > rofs, gsl::span< const itsmft::CompClusterExt > clusters)
int getTotalClusters() const
Definition TimeFrame.h:614
gsl::span< int > getExclusiveNTrackletsCluster(int rofId, int combId)
Definition TimeFrame.h:573
int getNLinesTotal() const noexcept
Definition TimeFrame.h:208
void setMultiplicityCutMask(const std::vector< uint8_t > &cutMask)
Definition TimeFrame.h:228
auto & getTrackletClusters(int rofId)
Definition TimeFrame.h:210
std::vector< bounded_vector< int > > mTrackletsLookupTable
Definition TimeFrame.h:277
virtual bool isGPU() const noexcept
Definition TimeFrame.h:299
gsl::span< const Cluster > getUnsortedClustersOnLayer(int rofId, int layerId) const
Definition TimeFrame.h:509
const o2::base::PropagatorImpl< float > * getDevicePropagator() const
Definition TimeFrame.h:246
void computeTrackletsPerROFScans()
gsl::span< const std::array< float, 2 > > getPrimaryVerticesXAlpha(int rofId) const
Definition TimeFrame.h:393
size_t getNumberOfUsedClusters() const
Definition TimeFrame.h:674
gsl::span< int > getIndexTable(int rofId, int layerId)
Definition TimeFrame.h:519
void addPrimaryVerticesLabelsInROF(const bounded_vector< std::pair< MCCompLabel, float > > &labels, const int rofId)
Definition TimeFrame.cxx:88
auto & getCellsLookupTable()
Definition TimeFrame.h:173
void setBeamPosition(const float x, const float y, const float s2, const float base=50.f, const float systematic=0.f)
Definition TimeFrame.h:109
bounded_vector< Road< nLayers - 2 > > mRoads
Definition TimeFrame.h:288
std::array< bounded_vector< int >, nLayers > mIndexTables
Definition TimeFrame.h:276
const auto & getTrackingFrameInfoOnLayer(int layerId) const
Definition TimeFrame.h:140
auto & getTotVertIteration()
Definition TimeFrame.h:102
float getMaxR(int layer) const
Definition TimeFrame.h:120
auto & getVerticesMCRecInfo()
Definition TimeFrame.h:180
void insertPastVertex(const Vertex &vertex, const int refROFId)
Definition TimeFrame.h:684
gsl::span< const int > getROFramesClustersPerROFrange(int rofMin, int range, int layerId) const
Definition TimeFrame.h:473
float getPositionResolution(int layer) const
Definition TimeFrame.h:125
std::vector< bounded_vector< TrackITSExt > > mTracks
Definition TimeFrame.h:289
int getPrimaryVerticesNum(int rofId=-1) const
Definition TimeFrame.h:402
void setNLinesTotal(uint32_t a) noexcept
Definition TimeFrame.h:209
void addPrimaryVerticesContributorLabelsInROF(const bounded_vector< MCCompLabel > &labels, const int rofId)
Definition TimeFrame.cxx:94
void setROFMask(const std::vector< uint8_t > &rofMask)
Definition TimeFrame.h:229
gsl::span< unsigned char > getUsedClusters(const int layer)
Definition TimeFrame.h:543
void addClusterExternalIndexToLayer(int layer, const int idx)
Definition TimeFrame.h:253
void addPrimaryVerticesLabels(bounded_vector< std::pair< MCCompLabel, float > > &labels)
Definition TimeFrame.cxx:66
gsl::span< const MCCompLabel > getLabelsFoundTracklets(int rofId, int combId) const
Definition TimeFrame.h:604
int loadROFrameData(const o2::itsmft::ROFRecord &rof, gsl::span< const itsmft::Cluster > clusters, const dataformats::MCTruthContainer< MCCompLabel > *mcLabels=nullptr)
std::array< bounded_vector< int >, 2 > mNTrackletsPerCluster
Definition TimeFrame.h:273
virtual int getNumberOfCells() const
Definition TimeFrame.h:634
gsl::span< const Cluster > getClustersPerROFrange(int rofMin, int range, int layerId) const
Definition TimeFrame.h:462
gsl::span< const Vertex > getPrimaryVertices(int rofId) const
Definition TimeFrame.h:346
void fillPrimaryVerticesXandAlpha()
const dataformats::MCTruthContainer< MCCompLabel > * mClusterLabels
Definition TimeFrame.h:272
void initialiseRoadLabels()
Definition TimeFrame.h:549
auto getNumberOfUsedExtendedClusters() const
Definition TimeFrame.h:189
std::pmr::memory_resource * getMaybeFrameworkHostResource(bool forceHost=false)
Definition TimeFrame.h:243
std::shared_ptr< BoundedMemoryResource > mExtMemoryPool
Definition TimeFrame.h:239
virtual ~TimeFrame()=default
gsl::span< Cluster > getClustersOnLayer(int rofId, int layerId)
Definition TimeFrame.h:422
bool empty() const
Definition TimeFrame.h:103
auto & getPhiCuts()
Definition TimeFrame.h:124
auto & getLinesLabel(const int rofId)
Definition TimeFrame.h:179
int getSortedStartIndex(const int rofId, const int layer) const
Definition TimeFrame.h:105
auto & getClusters()
Definition TimeFrame.h:168
gsl::span< const MCCompLabel > getClusterLabels(int layerId, const Cluster &cl) const
Definition TimeFrame.h:143
IndexTableUtilsN mIndexTableUtils
Definition TimeFrame.h:266
const Vertex & getPrimaryVertex(const int ivtx) const
Definition TimeFrame.h:74
virtual void setDevicePropagator(const o2::base::PropagatorImpl< float > *)
Definition TimeFrame.h:247
std::vector< bounded_vector< int > > mCellsNeighbours
Definition TimeFrame.h:290
gsl::span< Tracklet > getFoundTracklets(int rofId, int combId)
Definition TimeFrame.h:584
std::array< bounded_vector< Cluster >, nLayers > mUnsortedClusters
Definition TimeFrame.h:285
void addClusterToLayer(int layer, T &&... args)
Definition TimeFrame.h:530
unsigned long getArtefactsMemory() const
float getMinR(int layer) const
Definition TimeFrame.h:119
std::array< bounded_vector< uint8_t >, nLayers > mUsedClusters
Definition TimeFrame.h:278
gsl::span< const int > getROFrameClusters(int layerId) const
Definition TimeFrame.h:416
void removePrimaryVerticesInROf(const int rofId)
const o2::base::PropagatorImpl< float > * mPropagatorDevice
Definition TimeFrame.h:294
void printCellLUTonLayer(int i)
virtual int getNumberOfNeighbours() const
Definition TimeFrame.h:654
void printArtefactsMemory() const
auto & getTracksLabel(const int rofId)
Definition TimeFrame.h:178
float getBeamY() const
Definition TimeFrame.h:116
std::array< bounded_vector< int >, nLayers > mNClustersPerROF
Definition TimeFrame.h:275
int getROFCutClusterMult() const
ROF cuts.
Definition TimeFrame.h:199
std::array< bounded_vector< TrackingFrameInfo >, nLayers > mTrackingFrameInfo
Definition TimeFrame.h:269
gsl::span< int > getNTrackletsCluster(int rofId, int combId)
Definition TimeFrame.h:563
auto & getCellsNeighbours()
Definition TimeFrame.h:174
void markUsedCluster(int layer, int clusterId)
Definition TimeFrame.h:162
std::array< bounded_vector< Cluster >, nLayers > mClusters
Definition TimeFrame.h:268
uint32_t getTotalTrackletsTF(const int iLayer)
Definition TimeFrame.h:216
void addPrimaryVerticesContributorLabels(bounded_vector< MCCompLabel > &labels)
Definition TimeFrame.cxx:72
auto getNumberOfExtendedTracks() const
Definition TimeFrame.h:188
int hasBogusClusters() const
Definition TimeFrame.h:232
auto & getUnsortedClusters()
Definition TimeFrame.h:169
auto & getCellsNeighboursLUT()
Definition TimeFrame.h:175
int & getNTrackletsROF(int rofId, int combId)
Definition TimeFrame.h:206
int getNumberOfClusters() const
Definition TimeFrame.h:624
void resetROFrameData(size_t nROFs)
void setRoadLabel(int i, const unsigned long long &lab, bool fake)
Definition TimeFrame.h:556
auto & getMemoryPool() const noexcept
Definition TimeFrame.h:193
auto & getLines(int rofId)
Definition TimeFrame.h:207
int getClusterSize(int clusterId) const
Definition TimeFrame.h:146
gsl::span< const uint8_t > getUsedClustersROF(int rofId, int layerId) const
Definition TimeFrame.h:452
gsl::span< const int > getNClustersROFrange(int rofMin, int range, int layerId) const
Definition TimeFrame.h:480
int getSortedIndex(int rofId, int layer, int idx) const
Definition TimeFrame.h:104
const unsigned long long & getRoadLabel(int i) const
Definition TimeFrame.h:225
IndexTableUtils< nLayers > IndexTableUtilsN
Definition TimeFrame.h:67
constexpr size_t max
std::vector< Cluster > clusters