13#ifndef TRACKINGITSU_INCLUDE_TIMEFRAME_H_
14#define TRACKINGITSU_INCLUDE_TIMEFRAME_H_
53class TopologyDictionary;
65template <
int nLayers = 7>
93 gsl::span<const itsmft::CompClusterExt>
clusters,
94 gsl::span<const unsigned char>::iterator& pattIt,
99 gsl::span<const itsmft::CompClusterExt>
clusters);
109 void setBeamPosition(
const float x,
const float y,
const float s2,
const float base = 50.f,
const float systematic = 0.f)
111 isBeamPositionOverridden =
true;
112 resetBeamXY(
x,
y, s2 / o2::gpu::CAMath::Sqrt(base * base + systematic));
158 mTotVertPerIteration.resize(1);
192 void setMemoryPool(std::shared_ptr<BoundedMemoryResource> pool);
207 auto&
getLines(
int rofId) {
return mLines[rofId]; }
225 const unsigned long long&
getRoadLabel(
int i)
const {
return mRoadLabels[
i].first; }
229 void setROFMask(
const std::vector<uint8_t>& rofMask) { mROFMask = rofMask; }
232 int hasBogusClusters()
const {
return std::accumulate(mBogusClusters.begin(), mBogusClusters.end(), 0); }
249 template <
typename... T>
251 template <
typename... T>
287 std::vector<bounded_vector<CellSeedN>>
mCells;
289 std::vector<bounded_vector<TrackITSExt>>
mTracks;
299 virtual bool isGPU() const noexcept {
return false; }
300 virtual const char*
getName() const noexcept {
return "CPU"; }
303 void prepareClusters(
const TrackingParameters& trkParam,
const int maxLayers = nLayers);
305 unsigned int mNTotalLowPtVertices = 0;
306 int mBeamPosWeight = 0;
307 std::array<float, 2> mBeamPos = {0.f, 0.f};
308 bool isBeamPositionOverridden =
false;
309 std::array<float, nLayers> mMinR;
310 std::array<float, nLayers> mMaxR;
311 bounded_vector<float> mMSangles;
312 bounded_vector<float> mPhiCuts;
313 bounded_vector<float> mPositionResolution;
314 bounded_vector<uint8_t> mClusterSize;
316 std::vector<uint8_t> mROFMask;
317 bounded_vector<std::array<float, 2>> mPValphaX;
318 std::vector<bounded_vector<MCCompLabel>> mTrackletLabels;
319 std::vector<bounded_vector<MCCompLabel>> mCellLabels;
320 std::vector<bounded_vector<int>> mCellsNeighboursLUT;
321 std::vector<bounded_vector<MCCompLabel>> mTracksLabel;
322 bounded_vector<int> mBogusClusters;
324 bounded_vector<std::pair<unsigned long long, bool>> mRoadLabels;
325 int mCutClusterMult{-999};
326 int mCutVertexMult{-999};
329 std::vector<bounded_vector<int>> mNTrackletsPerROF;
330 std::vector<bounded_vector<Line>> mLines;
331 std::vector<bounded_vector<ClusterLines>> mTrackletClusters;
332 std::array<bounded_vector<int>, 2> mTrackletsIndexROF;
333 std::vector<bounded_vector<MCCompLabel>> mLinesLabels;
334 std::vector<std::pair<MCCompLabel, float>> mVerticesMCRecInfo;
335 bounded_vector<MCCompLabel> mVerticesContributorLabels;
336 std::array<uint32_t, 2> mTotalTracklets = {0, 0};
337 uint32_t mTotalLines = 0;
338 unsigned int mNoVertexROF = 0;
339 bounded_vector<int> mTotVertPerIteration;
342 std::shared_ptr<BoundedMemoryResource> mMemoryPool;
345template <
int nLayers>
348 if (mPrimaryVertices.empty()) {
351 const int start = mROFramesPV[rofId];
352 const int stop_idx = rofId >= mNrof - 1 ? mNrof : rofId + 1;
353 int delta = mMultiplicityCutMask[rofId] ? mROFramesPV[stop_idx] -
start : 0;
354 return {&mPrimaryVertices[
start],
static_cast<gsl::span<const Vertex>::size_type
>(delta)};
357template <
int nLayers>
360 const int start = mROFramesPV[rofId];
361 const int stop_idx = rofId >= mNrof - 1 ? mNrof : rofId + 1;
362 int delta = mMultiplicityCutMask[rofId] ? mROFramesPV[stop_idx] -
start : 0;
363 return {&(mVerticesMCRecInfo[
start]),
static_cast<gsl::span<const std::pair<MCCompLabel, float>
>::size_type>(delta)};
366template <
int nLayers>
370 unsigned int start{0}, delta{0};
371 const auto& pvsBefore = getPrimaryVertices(0, rofId - 1);
372 for (
const auto& pv : pvsBefore) {
373 start += pv.getNContributors();
375 const auto& pvsIn = getPrimaryVertices(rofId);
376 for (
const auto& pv : pvsIn) {
377 delta += pv.getNContributors();
379 return {&(mVerticesContributorLabels[
start]),
static_cast<gsl::span<const MCCompLabel>::size_type
>(delta)};
382template <
int nLayers>
385 if (mPrimaryVertices.empty()) {
388 const int stop_idx = romax >= mNrof - 1 ? mNrof : romax + 1;
389 return {&mPrimaryVertices[mROFramesPV[romin]],
static_cast<gsl::span<const Vertex>::size_type
>(mROFramesPV[stop_idx] - mROFramesPV[romin])};
392template <
int nLayers>
395 const int start = mROFramesPV[rofId];
396 const int stop_idx = rofId >= mNrof - 1 ? mNrof : rofId + 1;
397 int delta = mMultiplicityCutMask[rofId] ? mROFramesPV[stop_idx] -
start : 0;
398 return {&(mPValphaX[
start]),
static_cast<gsl::span<const std::array<float, 2>
>::size_type>(delta)};
401template <
int nLayers>
404 return rofId < 0 ? mPrimaryVertices.size() : mROFramesPV[rofId + 1] - mROFramesPV[rofId];
407template <
int nLayers>
415template <
int nLayers>
418 return {&mROFramesClusters[layerId][0],
static_cast<gsl::span<const int>::size_type
>(mROFramesClusters[layerId].size())};
421template <
int nLayers>
424 if (rofId < 0 || rofId >= mNrof) {
427 int startIdx{mROFramesClusters[layerId][rofId]};
428 return {&mClusters[layerId][startIdx],
static_cast<gsl::span<Cluster>::size_type
>(mROFramesClusters[layerId][rofId + 1] - startIdx)};
431template <
int nLayers>
434 if (rofId < 0 || rofId >= mNrof) {
437 int startIdx{mROFramesClusters[layerId][rofId]};
438 return {&mClusters[layerId][startIdx],
static_cast<gsl::span<const Cluster>::size_type
>(mROFramesClusters[layerId][rofId + 1] - startIdx)};
441template <
int nLayers>
444 if (rofId < 0 || rofId >= mNrof) {
447 int startIdx{mROFramesClusters[layerId][rofId]};
448 return {&mUsedClusters[layerId][startIdx],
static_cast<gsl::span<uint8_t>::size_type
>(mROFramesClusters[layerId][rofId + 1] - startIdx)};
451template <
int nLayers>
454 if (rofId < 0 || rofId >= mNrof) {
457 int startIdx{mROFramesClusters[layerId][rofId]};
458 return {&mUsedClusters[layerId][startIdx],
static_cast<gsl::span<const uint8_t>::size_type
>(mROFramesClusters[layerId][rofId + 1] - startIdx)};
461template <
int nLayers>
464 if (rofMin < 0 || rofMin >= mNrof) {
467 int startIdx{mROFramesClusters[layerId][rofMin]};
468 int endIdx{mROFramesClusters[layerId][o2::gpu::CAMath::Min(rofMin +
range, mNrof)]};
469 return {&mClusters[layerId][startIdx],
static_cast<gsl::span<Cluster>::size_type
>(endIdx - startIdx)};
472template <
int nLayers>
475 int chkdRange{o2::gpu::CAMath::Min(
range, mNrof - rofMin)};
476 return {&mROFramesClusters[layerId][rofMin],
static_cast<gsl::span<int>::size_type
>(chkdRange)};
479template <
int nLayers>
482 int chkdRange{o2::gpu::CAMath::Min(
range, mNrof - rofMin)};
483 return {&mNClustersPerROF[layerId][rofMin],
static_cast<gsl::span<int>::size_type
>(chkdRange)};
486template <
int nLayers>
489 int startIdx{rofMin};
490 int endIdx{o2::gpu::CAMath::Min(rofMin +
range, mNrof)};
491 return mROFramesClusters[layerId][endIdx] - mROFramesClusters[layerId][startIdx];
494template <
int nLayers>
497 const int iTableSize{mIndexTableUtils.getNphiBins() * mIndexTableUtils.getNzBins() + 1};
498 int chkdRange{o2::gpu::CAMath::Min(
range, mNrof - rofMin)};
499 return {&mIndexTables[layerId][rofMin * iTableSize],
static_cast<gsl::span<int>::size_type
>(chkdRange * iTableSize)};
502template <
int nLayers>
505 return std::lower_bound(mROFramesClusters[iLayer].begin(), mROFramesClusters[iLayer].
end(), iCluster + 1) - mROFramesClusters[iLayer].begin() - 1;
508template <
int nLayers>
511 if (rofId < 0 || rofId >= mNrof) {
514 int startIdx{mROFramesClusters[layerId][rofId]};
515 return {&mUnsortedClusters[layerId][startIdx],
static_cast<gsl::span<Cluster>::size_type
>(mROFramesClusters[layerId][rofId + 1] - startIdx)};
518template <
int nLayers>
521 if (rofId < 0 || rofId >= mNrof) {
524 const int tableSize = mIndexTableUtils.getNphiBins() * mIndexTableUtils.getNzBins() + 1;
525 return {&mIndexTables[
layer][rofId * tableSize],
static_cast<gsl::span<int>::size_type
>(tableSize)};
528template <
int nLayers>
529template <
typename... T>
532 mUnsortedClusters[
layer].emplace_back(std::forward<T>(
values)...);
535template <
int nLayers>
536template <
typename... T>
539 mTrackingFrameInfo[
layer].emplace_back(std::forward<T>(
values)...);
542template <
int nLayers>
545 return {&mUsedClusters[
layer][0],
static_cast<gsl::span<uint8_t>::size_type
>(mUsedClusters[
layer].size())};
548template <
int nLayers>
552 mRoadLabels.resize(mRoads.size());
555template <
int nLayers>
558 mRoadLabels[
i].first = lab;
559 mRoadLabels[
i].second = fake;
562template <
int nLayers>
565 if (rofId < 0 || rofId >= mNrof) {
568 auto startIdx{mROFramesClusters[1][rofId]};
569 return {&mNTrackletsPerCluster[combId][startIdx],
static_cast<gsl::span<int>::size_type
>(mROFramesClusters[1][rofId + 1] - startIdx)};
572template <
int nLayers>
575 if (rofId < 0 || rofId >= mNrof) {
578 auto clusStartIdx{mROFramesClusters[1][rofId]};
580 return {&mNTrackletsPerClusterSum[combId][clusStartIdx],
static_cast<gsl::span<int>::size_type
>(mROFramesClusters[1][rofId + 1] - clusStartIdx)};
583template <
int nLayers>
586 if (rofId < 0 || rofId >= mNrof || mTracklets[combId].
empty()) {
589 auto startIdx{mNTrackletsPerROF[combId][rofId]};
590 return {&mTracklets[combId][startIdx],
static_cast<gsl::span<Tracklet>::size_type
>(mNTrackletsPerROF[combId][rofId + 1] - startIdx)};
593template <
int nLayers>
596 if (rofId < 0 || rofId >= mNrof) {
599 auto startIdx{mNTrackletsPerROF[combId][rofId]};
600 return {&mTracklets[combId][startIdx],
static_cast<gsl::span<Tracklet>::size_type
>(mNTrackletsPerROF[combId][rofId + 1] - startIdx)};
603template <
int nLayers>
606 if (rofId < 0 || rofId >= mNrof || !hasMCinformation()) {
609 auto startIdx{mNTrackletsPerROF[combId][rofId]};
610 return {&mTrackletLabels[combId][startIdx],
static_cast<gsl::span<Tracklet>::size_type
>(mNTrackletsPerROF[combId][rofId + 1] - startIdx)};
613template <
int nLayers>
616 size_t totalClusters{0};
617 for (
const auto&
clusters : mUnsortedClusters) {
620 return int(totalClusters);
623template <
int nLayers>
627 for (
const auto&
layer : mClusters) {
633template <
int nLayers>
637 for (
const auto&
layer : mCells) {
638 nCells +=
layer.size();
643template <
int nLayers>
647 for (
const auto&
layer : mTracklets) {
648 nTracklets +=
layer.size();
653template <
int nLayers>
657 for (
const auto& l : mCellsNeighbours) {
663template <
int nLayers>
667 for (
const auto& t : mTracks) {
673template <
int nLayers>
677 for (
const auto&
layer : mUsedClusters) {
683template <
int nLayers>
686 int rofId =
vertex.getTimeStamp().getTimeStamp();
687 mPrimaryVertices.insert(mPrimaryVertices.begin() + mROFramesPV[rofId],
vertex);
688 for (
int i = rofId + 1;
i < mROFramesPV.size(); ++
i) {
691 mTotVertPerIteration[iteration]++;
std::vector< std::string > labels
Definition of a container to keep Monte Carlo truth external to simulation objects.
Definition of the ITS track.
HMPID cluster implementation.
GLenum GLsizei GLsizei GLint * values
GLenum GLuint GLint GLint layer
GLboolean GLboolean GLboolean GLboolean a
GLubyte GLubyte GLubyte GLubyte w
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 ...
auto & getPositionResolutions()
void addTrackingFrameInfoToLayer(int layer, T &&... args)
gsl::span< const MCCompLabel > getPrimaryVerticesContributors(const int rofId) const
void setFrameworkAllocator(ExternalAllocator *ext)
void checkTrackletLUTs()
Debug and printing.
gsl::span< const Tracklet > getFoundTracklets(int rofId, int combId) const
bool checkMemory(unsigned long max)
int getClusterROF(int iLayer, int iCluster)
auto & getCellsLabel(int layer)
void printTrackletLUTonLayer(int i)
bool isClusterUsed(int layer, int clusterId) const
auto getFrameworkAllocator()
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)
float getMSangle(int layer) const
std::vector< bounded_vector< int > > mCellsLookupTable
bool hasMCinformation() const
auto & getIndexTableWhole(int layerId)
std::array< bounded_vector< int >, 2 > mNTrackletsPerClusterSum
gsl::span< const MCCompLabel > getClusterLabels(int layerId, const int clId) const
auto & getTracks(int rofId)
size_t getNumberOfTracks() const
unsigned int & getNoVertexROF()
int getTotalClustersPerROFrange(int rofMin, int range, int layerId) const
virtual int getNumberOfTracklets() const
auto & getTrackletsLabel(int layer)
ExternalAllocator * mExternalAllocator
State if memory will be externally managed by the GPU framework.
std::vector< bounded_vector< Tracklet > > mTracklets
gsl::span< const std::pair< MCCompLabel, float > > getPrimaryVerticesMCRecInfo(const int rofId) const
void computeTracletsPerClusterScans()
gsl::span< uint8_t > getUsedClustersROF(int rofId, int layerId)
const TrackingFrameInfo & getClusterTrackingFrameInfo(int layerId, const Cluster &cl) const
int getClusterExternalIndex(int layerId, const int clId) const
void resetBeamXY(const float x, const float y, const float w=0)
void addPrimaryVerticesInROF(const bounded_vector< Vertex > &vertices, const int rofId, const int iteration)
gsl::span< const int > getIndexTablePerROFrange(int rofMin, int range, int layerId) const
gsl::span< const Cluster > getClustersOnLayer(int rofId, int layerId) const
bounded_vector< int > mROFramesPV
std::array< float, 2 > & getBeamXY()
virtual const char * getName() const noexcept
std::vector< bounded_vector< CellSeedN > > mCells
std::array< bounded_vector< int >, nLayers > mClusterExternalIndices
bool hasFrameworkAllocator() const noexcept
bool isRoadFake(int i) const
gsl::span< const Vertex > getPrimaryVertices(int romin, int romax) const
void setMemoryPool(std::shared_ptr< BoundedMemoryResource > pool)
memory management
void printSliceInfo(const int, const int)
auto & getTrackletsLookupTable()
void setClusterSize(bounded_vector< uint8_t > &v)
bounded_vector< Vertex > mPrimaryVertices
int getROFCutAllMult() const
int getROFCutVertexMult() const
std::array< bounded_vector< int >, nLayers > mROFramesClusters
std::vector< uint8_t > mMultiplicityCutMask
float getPhiCut(int layer) const
void prepareROFrameData(gsl::span< const o2::itsmft::ROFRecord > rofs, gsl::span< const itsmft::CompClusterExt > clusters)
int getTotalClusters() const
gsl::span< int > getExclusiveNTrackletsCluster(int rofId, int combId)
int getNLinesTotal() const noexcept
void setMultiplicityCutMask(const std::vector< uint8_t > &cutMask)
auto & getTrackletClusters(int rofId)
std::vector< bounded_vector< int > > mTrackletsLookupTable
virtual bool isGPU() const noexcept
int mNExtendedUsedClusters
gsl::span< const Cluster > getUnsortedClustersOnLayer(int rofId, int layerId) const
const o2::base::PropagatorImpl< float > * getDevicePropagator() const
void computeTrackletsPerROFScans()
gsl::span< const std::array< float, 2 > > getPrimaryVerticesXAlpha(int rofId) const
size_t getNumberOfUsedClusters() const
gsl::span< int > getIndexTable(int rofId, int layerId)
void addPrimaryVerticesLabelsInROF(const bounded_vector< std::pair< MCCompLabel, float > > &labels, const int rofId)
auto & getCellsLookupTable()
void setBeamPosition(const float x, const float y, const float s2, const float base=50.f, const float systematic=0.f)
bounded_vector< Road< nLayers - 2 > > mRoads
std::array< bounded_vector< int >, nLayers > mIndexTables
const auto & getTrackingFrameInfoOnLayer(int layerId) const
auto & getTotVertIteration()
float getMaxR(int layer) const
auto & getVerticesMCRecInfo()
void insertPastVertex(const Vertex &vertex, const int refROFId)
gsl::span< const int > getROFramesClustersPerROFrange(int rofMin, int range, int layerId) const
float getPositionResolution(int layer) const
std::vector< bounded_vector< TrackITSExt > > mTracks
int getPrimaryVerticesNum(int rofId=-1) const
void setNLinesTotal(uint32_t a) noexcept
void addPrimaryVerticesContributorLabelsInROF(const bounded_vector< MCCompLabel > &labels, const int rofId)
void setROFMask(const std::vector< uint8_t > &rofMask)
gsl::span< unsigned char > getUsedClusters(const int layer)
void addClusterExternalIndexToLayer(int layer, const int idx)
void addPrimaryVerticesLabels(bounded_vector< std::pair< MCCompLabel, float > > &labels)
gsl::span< const MCCompLabel > getLabelsFoundTracklets(int rofId, int combId) const
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
virtual int getNumberOfCells() const
gsl::span< const Cluster > getClustersPerROFrange(int rofMin, int range, int layerId) const
gsl::span< const Vertex > getPrimaryVertices(int rofId) const
void fillPrimaryVerticesXandAlpha()
const dataformats::MCTruthContainer< MCCompLabel > * mClusterLabels
void initialiseRoadLabels()
auto getNumberOfUsedExtendedClusters() const
std::pmr::memory_resource * getMaybeFrameworkHostResource(bool forceHost=false)
std::shared_ptr< BoundedMemoryResource > mExtMemoryPool
virtual ~TimeFrame()=default
gsl::span< Cluster > getClustersOnLayer(int rofId, int layerId)
auto & getLinesLabel(const int rofId)
int getSortedStartIndex(const int rofId, const int layer) const
gsl::span< const MCCompLabel > getClusterLabels(int layerId, const Cluster &cl) const
IndexTableUtilsN mIndexTableUtils
const Vertex & getPrimaryVertex(const int ivtx) const
virtual void setDevicePropagator(const o2::base::PropagatorImpl< float > *)
std::vector< bounded_vector< int > > mCellsNeighbours
gsl::span< Tracklet > getFoundTracklets(int rofId, int combId)
std::array< bounded_vector< Cluster >, nLayers > mUnsortedClusters
void addClusterToLayer(int layer, T &&... args)
unsigned long getArtefactsMemory() const
float getMinR(int layer) const
std::array< bounded_vector< uint8_t >, nLayers > mUsedClusters
gsl::span< const int > getROFrameClusters(int layerId) const
void removePrimaryVerticesInROf(const int rofId)
const o2::base::PropagatorImpl< float > * mPropagatorDevice
void printCellLUTonLayer(int i)
virtual int getNumberOfNeighbours() const
void printArtefactsMemory() const
auto & getTracksLabel(const int rofId)
std::array< bounded_vector< int >, nLayers > mNClustersPerROF
int getROFCutClusterMult() const
ROF cuts.
std::array< bounded_vector< TrackingFrameInfo >, nLayers > mTrackingFrameInfo
gsl::span< int > getNTrackletsCluster(int rofId, int combId)
auto & getCellsNeighbours()
void markUsedCluster(int layer, int clusterId)
std::array< bounded_vector< Cluster >, nLayers > mClusters
uint32_t getTotalTrackletsTF(const int iLayer)
void addPrimaryVerticesContributorLabels(bounded_vector< MCCompLabel > &labels)
auto getNumberOfExtendedTracks() const
int hasBogusClusters() const
auto & getUnsortedClusters()
auto & getCellsNeighboursLUT()
int & getNTrackletsROF(int rofId, int combId)
int getNumberOfClusters() const
void resetROFrameData(size_t nROFs)
void setRoadLabel(int i, const unsigned long long &lab, bool fake)
auto & getMemoryPool() const noexcept
auto & getLines(int rofId)
int getClusterSize(int clusterId) const
gsl::span< const uint8_t > getUsedClustersROF(int rofId, int layerId) const
gsl::span< const int > getNClustersROFrange(int rofMin, int range, int layerId) const
int getSortedIndex(int rofId, int layer, int idx) const
const unsigned long long & getRoadLabel(int i) const
IndexTableUtils< nLayers > IndexTableUtilsN
std::vector< Cluster > clusters