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