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