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