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 {
69 friend class gpu::TimeFrameGPU<nLayers>;
70
71 TimeFrame();
72 virtual ~TimeFrame();
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<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();
98
99 int getTotalClusters() const;
100 auto& getTotVertIteration() { return mTotVertPerIteration; }
101 bool empty() const { return getTotalClusters() == 0; }
102 int getSortedIndex(int rofId, int layer, int idx) const { return mROFramesClusters[layer][rofId] + idx; }
103 int getSortedStartIndex(const int rofId, const int layer) const { return mROFramesClusters[layer][rofId]; }
104 int getNrof() const { return mNrof; }
105
106 void resetBeamXY(const float x, const float y, const float w = 0);
107 void setBeamPosition(const float x, const float y, const float s2, const float base = 50.f, const float systematic = 0.f)
108 {
109 isBeamPositionOverridden = true;
110 resetBeamXY(x, y, s2 / o2::gpu::CAMath::Sqrt(base * base + systematic));
111 }
112
113 float getBeamX() const { return mBeamPos[0]; }
114 float getBeamY() const { return mBeamPos[1]; }
115 auto& getMinRs() { return mMinR; }
116 auto& getMaxRs() { return mMaxR; }
117 float getMinR(int layer) const { return mMinR[layer]; }
118 float getMaxR(int layer) const { return mMaxR[layer]; }
119 float getMSangle(int layer) const { return mMSangles[layer]; }
120 auto& getMSangles() { return mMSangles; }
121 float getPhiCut(int layer) const { return mPhiCuts[layer]; }
122 auto& getPhiCuts() { return mPhiCuts; }
123 float getPositionResolution(int layer) const { return mPositionResolution[layer]; }
124 auto& getPositionResolutions() { return mPositionResolution; }
125
126 gsl::span<Cluster> getClustersOnLayer(int rofId, int layerId);
127 gsl::span<const Cluster> getClustersOnLayer(int rofId, int layerId) const;
128 gsl::span<const Cluster> getClustersPerROFrange(int rofMin, int range, int layerId) const;
129 gsl::span<const Cluster> getUnsortedClustersOnLayer(int rofId, int layerId) const;
130 gsl::span<uint8_t> getUsedClustersROF(int rofId, int layerId);
131 gsl::span<const uint8_t> getUsedClustersROF(int rofId, int layerId) const;
132 gsl::span<const int> getROFramesClustersPerROFrange(int rofMin, int range, int layerId) const;
133 gsl::span<const int> getROFrameClusters(int layerId) const;
134 gsl::span<const int> getNClustersROFrange(int rofMin, int range, int layerId) const;
135 gsl::span<const int> getIndexTablePerROFrange(int rofMin, int range, int layerId) const;
136 gsl::span<int> getIndexTable(int rofId, int layerId);
137 auto& getIndexTableWhole(int layerId) { return mIndexTables[layerId]; }
138 const auto& getTrackingFrameInfoOnLayer(int layerId) const { return mTrackingFrameInfo[layerId]; }
139
140 const TrackingFrameInfo& getClusterTrackingFrameInfo(int layerId, const Cluster& cl) const;
141 gsl::span<const MCCompLabel> getClusterLabels(int layerId, const Cluster& cl) const { return getClusterLabels(layerId, cl.clusterId); }
142 gsl::span<const MCCompLabel> getClusterLabels(int layerId, const int clId) const { return mClusterLabels->getLabels(mClusterExternalIndices[layerId][clId]); }
143 int getClusterExternalIndex(int layerId, const int clId) const { return mClusterExternalIndices[layerId][clId]; }
144 int getClusterSize(int clusterId) const { return mClusterSize[clusterId]; }
145 void setClusterSize(bounded_vector<uint8_t>& v) { mClusterSize = std::move(v); }
146
147 auto& getTrackletsLabel(int layer) { return mTrackletLabels[layer]; }
148 auto& getCellsLabel(int layer) { return mCellLabels[layer]; }
149
150 bool hasMCinformation() const { return mClusterLabels; }
151 void initialise(const int iteration, const TrackingParameters& trkParam, const int maxLayers = 7, bool resetVertices = true);
153 {
155 mROFramesPV.resize(1, 0);
156 mTotVertPerIteration.resize(1);
157 }
158
159 bool isClusterUsed(int layer, int clusterId) const { return mUsedClusters[layer][clusterId]; }
160 void markUsedCluster(int layer, int clusterId) { mUsedClusters[layer][clusterId] = true; }
161 gsl::span<unsigned char> getUsedClusters(const int layer);
162
163 auto& getTracklets() { return mTracklets; }
165
166 auto& getClusters() { return mClusters; }
168 int getClusterROF(int iLayer, int iCluster);
169 auto& getCells() { return mCells; }
170
173 auto& getCellsNeighboursLUT() { return mCellsNeighboursLUT; }
174 auto& getRoads() { return mRoads; }
175 auto& getTracks(int rofId) { return mTracks[rofId]; }
176 auto& getTracksLabel(const int rofId) { return mTracksLabel[rofId]; }
177 auto& getLinesLabel(const int rofId) { return mLinesLabels[rofId]; }
178 auto& getVerticesMCRecInfo() { return mVerticesMCRecInfo; }
179
181 virtual int getNumberOfCells() const;
182 virtual int getNumberOfTracklets() const;
183 virtual int getNumberOfNeighbours() const;
184 size_t getNumberOfTracks() const;
188
190 void setMemoryPool(std::shared_ptr<BoundedMemoryResource>& pool);
191 auto& getMemoryPool() const noexcept { return mMemoryPool; }
192 bool checkMemory(unsigned long max) { return getArtefactsMemory() < max; }
193 unsigned long getArtefactsMemory() const;
194 void printArtefactsMemory() const;
195
197 int getROFCutClusterMult() const { return mCutClusterMult; };
198 int getROFCutVertexMult() const { return mCutVertexMult; };
199 int getROFCutAllMult() const { return mCutClusterMult + mCutVertexMult; }
200
201 // Vertexer
204 int& getNTrackletsROF(int rofId, int combId) { return mNTrackletsPerROF[combId][rofId]; }
205 auto& getLines(int rofId) { return mLines[rofId]; }
206 int getNLinesTotal() const
207 {
208 return std::accumulate(mLines.begin(), mLines.end(), 0, [](int sum, const auto& l) { return sum + l.size(); });
209 }
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
238 {
239 if (mIsGPU) {
240 LOGP(debug, "Setting timeFrame allocator to external");
241 mAllocator = allocator;
242 mExtAllocator = true; // to be removed
243 } else {
244 LOGP(fatal, "External allocator is currently only supported for GPU");
245 }
246 }
247
249
251 {
252 return;
253 };
255
256 template <typename... T>
257 void addClusterToLayer(int layer, T&&... args);
258 template <typename... T>
259 void addTrackingFrameInfoToLayer(int layer, T&&... args);
260 void addClusterExternalIndexToLayer(int layer, const int idx) { mClusterExternalIndices[layer].push_back(idx); }
261
262 void resetVectors();
263 void resetTracklets();
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 bool mIsGPU = false;
279
280 std::array<bounded_vector<Cluster>, nLayers> mClusters;
281 std::array<bounded_vector<TrackingFrameInfo>, nLayers> mTrackingFrameInfo;
282 std::array<bounded_vector<int>, nLayers> mClusterExternalIndices;
283 std::array<bounded_vector<int>, nLayers> mROFramesClusters;
285 std::array<bounded_vector<int>, 2> mNTrackletsPerCluster;
286 std::array<bounded_vector<int>, 2> mNTrackletsPerClusterSum;
287 std::array<bounded_vector<int>, nLayers> mNClustersPerROF;
288 std::array<bounded_vector<int>, nLayers> mIndexTables;
289 std::vector<bounded_vector<int>> mTrackletsLookupTable;
290 std::array<bounded_vector<uint8_t>, nLayers> mUsedClusters;
291 int mNrof = 0;
296
297 // State if memory will be externally managed.
298 bool mExtAllocator = false;
300 bool getExtAllocator() const { return mExtAllocator; }
301
302 std::array<bounded_vector<Cluster>, nLayers> mUnsortedClusters;
303 std::vector<bounded_vector<Tracklet>> mTracklets;
304 std::vector<bounded_vector<CellSeedN>> mCells;
306 std::vector<bounded_vector<TrackITSExt>> mTracks;
307 std::vector<bounded_vector<int>> mCellsNeighbours;
308 std::vector<bounded_vector<int>> mCellsLookupTable;
309 std::vector<uint8_t> mMultiplicityCutMask;
310
311 const o2::base::PropagatorImpl<float>* mPropagatorDevice = nullptr; // Needed only for GPU
312
313 virtual void wipe();
314
315 private:
316 void prepareClusters(const TrackingParameters& trkParam, const int maxLayers = nLayers);
317 float mBz = 5.;
318 unsigned int mNTotalLowPtVertices = 0;
319 int mBeamPosWeight = 0;
320 std::array<float, 2> mBeamPos = {0.f, 0.f};
321 bool isBeamPositionOverridden = false;
322 std::array<float, nLayers> mMinR;
323 std::array<float, nLayers> mMaxR;
324 bounded_vector<float> mMSangles;
325 bounded_vector<float> mPhiCuts;
326 bounded_vector<float> mPositionResolution;
327 bounded_vector<uint8_t> mClusterSize;
328
329 std::vector<uint8_t> mROFMask;
331 std::vector<bounded_vector<MCCompLabel>> mTrackletLabels;
332 std::vector<bounded_vector<MCCompLabel>> mCellLabels;
333 std::vector<bounded_vector<int>> mCellsNeighboursLUT;
334 std::vector<bounded_vector<MCCompLabel>> mTracksLabel;
335 bounded_vector<int> mBogusClusters;
336
338 int mCutClusterMult{-999};
339 int mCutVertexMult{-999};
340
341 // Vertexer
342 std::vector<bounded_vector<int>> mNTrackletsPerROF;
343 std::vector<bounded_vector<Line>> mLines;
344 std::vector<bounded_vector<ClusterLines>> mTrackletClusters;
345 std::array<bounded_vector<int>, 2> mTrackletsIndexROF;
346 std::vector<bounded_vector<MCCompLabel>> mLinesLabels;
347 std::vector<std::pair<MCCompLabel, float>> mVerticesMCRecInfo;
348 bounded_vector<MCCompLabel> mVerticesContributorLabels;
349 std::array<uint32_t, 2> mTotalTracklets = {0, 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
float sum(float s, o2::dcs::DataPointValue v)
Definition dcs-ccdb.cxx:39
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
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:124
void addTrackingFrameInfoToLayer(int layer, T &&... args)
Definition TimeFrame.h:549
IndexTableUtils mIndexTableUtils
Definition TimeFrame.h:276
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:192
int getClusterROF(int iLayer, int iCluster)
Definition TimeFrame.h:515
auto & getCellsLabel(int layer)
Definition TimeFrame.h:148
void printTrackletLUTonLayer(int i)
bool isClusterUsed(int layer, int clusterId) const
Definition TimeFrame.h:159
int getNrof() const
Definition TimeFrame.h:104
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:113
float getMSangle(int layer) const
Definition TimeFrame.h:119
std::vector< bounded_vector< int > > mCellsLookupTable
Definition TimeFrame.h:308
bool hasMCinformation() const
Definition TimeFrame.h:150
auto & getIndexTableWhole(int layerId)
Definition TimeFrame.h:137
std::array< bounded_vector< int >, 2 > mNTrackletsPerClusterSum
Definition TimeFrame.h:286
gsl::span< const MCCompLabel > getClusterLabels(int layerId, const int clId) const
Definition TimeFrame.h:142
auto & getTracks(int rofId)
Definition TimeFrame.h:175
size_t getNumberOfTracks() const
Definition TimeFrame.h:676
unsigned int & getNoVertexROF()
Definition TimeFrame.h:219
ExternalAllocator * mAllocator
Definition TimeFrame.h:299
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:147
std::vector< bounded_vector< Tracklet > > mTracklets
Definition TimeFrame.h:303
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:234
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:120
int getClusterExternalIndex(int layerId, const int clId) const
Definition TimeFrame.h:143
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:294
std::array< float, 2 > & getBeamXY()
Definition TimeFrame.h:218
std::vector< bounded_vector< CellSeedN > > mCells
Definition TimeFrame.h:304
std::array< bounded_vector< int >, nLayers > mClusterExternalIndices
Definition TimeFrame.h:282
bool getExtAllocator() const
Definition TimeFrame.h:300
bool isRoadFake(int i) const
Definition TimeFrame.h:226
gsl::span< const Vertex > getPrimaryVertices(int romin, int romax) const
Definition TimeFrame.h:395
void printSliceInfo(const int, const int)
int getNLinesTotal() const
Definition TimeFrame.h:206
auto & getTrackletsLookupTable()
Definition TimeFrame.h:164
void setClusterSize(bounded_vector< uint8_t > &v)
Definition TimeFrame.h:145
float getBz() const
Definition TimeFrame.h:235
bounded_vector< Vertex > mPrimaryVertices
Definition TimeFrame.h:295
int getROFCutAllMult() const
Definition TimeFrame.h:199
int getROFCutVertexMult() const
Definition TimeFrame.h:198
std::array< bounded_vector< int >, nLayers > mROFramesClusters
Definition TimeFrame.h:283
std::vector< uint8_t > mMultiplicityCutMask
Definition TimeFrame.h:309
float getPhiCut(int layer) const
Definition TimeFrame.h:121
auto & getTracklets()
Definition TimeFrame.h:163
int getTotalClusters() const
Definition TimeFrame.h:626
gsl::span< int > getExclusiveNTrackletsCluster(int rofId, int combId)
Definition TimeFrame.h:585
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:289
gsl::span< const Cluster > getUnsortedClustersOnLayer(int rofId, int layerId) const
Definition TimeFrame.h:521
const o2::base::PropagatorImpl< float > * getDevicePropagator() const
Definition TimeFrame.h:254
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:171
void setBeamPosition(const float x, const float y, const float s2, const float base=50.f, const float systematic=0.f)
Definition TimeFrame.h:107
bounded_vector< Road< nLayers - 2 > > mRoads
Definition TimeFrame.h:305
std::array< bounded_vector< int >, nLayers > mIndexTables
Definition TimeFrame.h:288
const auto & getTrackingFrameInfoOnLayer(int layerId) const
Definition TimeFrame.h:138
auto & getTotVertIteration()
Definition TimeFrame.h:100
float getMaxR(int layer) const
Definition TimeFrame.h:118
auto & getVerticesMCRecInfo()
Definition TimeFrame.h:178
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:123
std::vector< bounded_vector< TrackITSExt > > mTracks
Definition TimeFrame.h:306
int getPrimaryVerticesNum(int rofId=-1) const
Definition TimeFrame.h:414
void addPrimaryVerticesContributorLabelsInROF(const bounded_vector< MCCompLabel > &labels, const int rofId)
void setROFMask(const std::vector< uint8_t > &rofMask)
Definition TimeFrame.h:229
gsl::span< unsigned char > getUsedClusters(const int layer)
Definition TimeFrame.h:555
void addClusterExternalIndexToLayer(int layer, const int idx)
Definition TimeFrame.h:260
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:285
virtual int getNumberOfCells() const
Definition TimeFrame.h:646
void setExternalAllocator(ExternalAllocator *allocator)
Definition TimeFrame.h:237
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:284
void initialiseRoadLabels()
Definition TimeFrame.h:561
auto getNumberOfUsedExtendedClusters() const
Definition TimeFrame.h:187
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:101
auto & getPhiCuts()
Definition TimeFrame.h:122
auto & getLinesLabel(const int rofId)
Definition TimeFrame.h:177
int getSortedStartIndex(const int rofId, const int layer) const
Definition TimeFrame.h:103
auto & getClusters()
Definition TimeFrame.h:166
gsl::span< const MCCompLabel > getClusterLabels(int layerId, const Cluster &cl) const
Definition TimeFrame.h:141
const Vertex & getPrimaryVertex(const int ivtx) const
Definition TimeFrame.h:74
ExternalAllocator * getExternalAllocator()
Definition TimeFrame.h:248
virtual void setDevicePropagator(const o2::base::PropagatorImpl< float > *)
Definition TimeFrame.h:250
std::vector< bounded_vector< int > > mCellsNeighbours
Definition TimeFrame.h:307
gsl::span< Tracklet > getFoundTracklets(int rofId, int combId)
Definition TimeFrame.h:596
std::array< bounded_vector< Cluster >, nLayers > mUnsortedClusters
Definition TimeFrame.h:302
void addClusterToLayer(int layer, T &&... args)
Definition TimeFrame.h:542
unsigned long getArtefactsMemory() const
float getMinR(int layer) const
Definition TimeFrame.h:117
std::array< bounded_vector< uint8_t >, nLayers > mUsedClusters
Definition TimeFrame.h:290
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:311
void printCellLUTonLayer(int i)
virtual int getNumberOfNeighbours() const
Definition TimeFrame.h:666
void printArtefactsMemory() const
auto & getTracksLabel(const int rofId)
Definition TimeFrame.h:176
float getBeamY() const
Definition TimeFrame.h:114
std::array< bounded_vector< int >, nLayers > mNClustersPerROF
Definition TimeFrame.h:287
int getROFCutClusterMult() const
ROF cuts.
Definition TimeFrame.h:197
std::array< bounded_vector< TrackingFrameInfo >, nLayers > mTrackingFrameInfo
Definition TimeFrame.h:281
gsl::span< int > getNTrackletsCluster(int rofId, int combId)
Definition TimeFrame.h:575
auto & getCellsNeighbours()
Definition TimeFrame.h:172
void markUsedCluster(int layer, int clusterId)
Definition TimeFrame.h:160
std::array< bounded_vector< Cluster >, nLayers > mClusters
Definition TimeFrame.h:280
uint32_t getTotalTrackletsTF(const int iLayer)
Definition TimeFrame.h:216
void addPrimaryVerticesContributorLabels(bounded_vector< MCCompLabel > &labels)
Definition TimeFrame.cxx:84
auto getNumberOfExtendedTracks() const
Definition TimeFrame.h:186
int hasBogusClusters() const
Definition TimeFrame.h:232
auto & getUnsortedClusters()
Definition TimeFrame.h:167
auto & getCellsNeighboursLUT()
Definition TimeFrame.h:173
int & getNTrackletsROF(int rofId, int combId)
Definition TimeFrame.h:204
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:191
auto & getLines(int rofId)
Definition TimeFrame.h:205
int getClusterSize(int clusterId) const
Definition TimeFrame.h:144
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:102
const unsigned long long & getRoadLabel(int i) const
Definition TimeFrame.h:225
constexpr size_t max
std::vector< Cluster > clusters