13#ifndef TRACKINGITSU_INCLUDE_TIMEFRAME_H_
14#define TRACKINGITSU_INCLUDE_TIMEFRAME_H_
54class TopologyDictionary;
67template <
int nLayers = 7>
82 void addPrimaryVertices(
const gsl::span<const Vertex>& vertices,
const int rofId,
const int iteration);
90 gsl::span<const itsmft::CompClusterExt>
clusters,
91 gsl::span<const unsigned char>::iterator& pattIt,
104 void setBeamPosition(
const float x,
const float y,
const float s2,
const float base = 50.f,
const float systematic = 0.f)
106 isBeamPositionOverridden =
true;
107 resetBeamXY(
x,
y, s2 / o2::gpu::CAMath::Sqrt(base * base + systematic));
153 mTotVertPerIteration.resize(1);
187 void setMemoryPool(std::shared_ptr<BoundedMemoryResource>& pool);
202 auto&
getLines(
int rofId) {
return mLines[rofId]; }
205 return std::accumulate(mLines.begin(), mLines.end(), 0, [](
int sum,
const auto& l) { return sum + l.size(); });
222 const unsigned long long&
getRoadLabel(
int i)
const {
return mRoadLabels[
i].first; }
226 void setROFMask(
const std::vector<uint8_t>& rofMask) { mROFMask = rofMask; }
229 int hasBogusClusters()
const {
return std::accumulate(mBogusClusters.begin(), mBogusClusters.end(), 0); }
237 LOGP(
debug,
"Setting timeFrame allocator to external");
241 LOGP(fatal,
"External allocator is currently only supported for GPU");
253 template <
typename... T>
255 template <
typename... T>
301 std::vector<bounded_vector<CellSeed>>
mCells;
303 std::vector<bounded_vector<TrackITSExt>>
mTracks;
313 void prepareClusters(
const TrackingParameters& trkParam,
const int maxLayers = nLayers);
315 unsigned int mNTotalLowPtVertices = 0;
316 int mBeamPosWeight = 0;
317 std::array<float, 2> mBeamPos = {0.f, 0.f};
318 bool isBeamPositionOverridden =
false;
319 std::array<float, nLayers> mMinR;
320 std::array<float, nLayers> mMaxR;
326 std::vector<uint8_t> mROFMask;
328 std::vector<bounded_vector<MCCompLabel>> mTrackletLabels;
329 std::vector<bounded_vector<MCCompLabel>> mCellLabels;
330 std::vector<bounded_vector<int>> mCellsNeighboursLUT;
331 std::vector<bounded_vector<MCCompLabel>> mTracksLabel;
335 int mCutClusterMult{-999};
336 int mCutVertexMult{-999};
339 std::vector<bounded_vector<int>> mNTrackletsPerROF;
340 std::vector<bounded_vector<Line>> mLines;
341 std::vector<bounded_vector<ClusterLines>> mTrackletClusters;
342 std::array<bounded_vector<int>, 2> mTrackletsIndexROF;
343 std::vector<bounded_vector<MCCompLabel>> mLinesLabels;
344 std::vector<std::pair<MCCompLabel, float>> mVerticesMCRecInfo;
345 std::array<uint32_t, 2> mTotalTracklets = {0, 0};
346 unsigned int mNoVertexROF = 0;
347 bounded_vector<int> mTotVertPerIteration;
350 std::shared_ptr<BoundedMemoryResource> mMemoryPool;
353template <
int nLayers>
356 if (mPrimaryVertices.empty()) {
359 const int start = mROFramesPV[rofId];
360 const int stop_idx = rofId >= mNrof - 1 ? mNrof : rofId + 1;
361 int delta = mMultiplicityCutMask[rofId] ? mROFramesPV[stop_idx] -
start : 0;
362 return {&mPrimaryVertices[
start],
static_cast<gsl::span<const Vertex>::size_type
>(delta)};
365template <
int nLayers>
368 const int start = mROFramesPV[rofId];
369 const int stop_idx = rofId >= mNrof - 1 ? mNrof : rofId + 1;
370 int delta = mMultiplicityCutMask[rofId] ? mROFramesPV[stop_idx] -
start : 0;
371 return {&(mVerticesMCRecInfo[
start]),
static_cast<gsl::span<const std::pair<MCCompLabel, float>
>::size_type>(delta)};
374template <
int nLayers>
377 if (mPrimaryVertices.empty()) {
380 return {&mPrimaryVertices[mROFramesPV[romin]],
static_cast<gsl::span<const Vertex>::size_type
>(mROFramesPV[romax + 1] - mROFramesPV[romin])};
383template <
int nLayers>
386 const int start = mROFramesPV[rofId];
387 const int stop_idx = rofId >= mNrof - 1 ? mNrof : rofId + 1;
388 int delta = mMultiplicityCutMask[rofId] ? mROFramesPV[stop_idx] -
start : 0;
389 return {&(mPValphaX[
start]),
static_cast<gsl::span<const std::array<float, 2>
>::size_type>(delta)};
392template <
int nLayers>
395 return rofId < 0 ? mPrimaryVertices.size() : mROFramesPV[rofId + 1] - mROFramesPV[rofId];
398template <
int nLayers>
406template <
int nLayers>
409 return {&mROFramesClusters[layerId][0],
static_cast<gsl::span<const int>::size_type
>(mROFramesClusters[layerId].size())};
412template <
int nLayers>
415 if (rofId < 0 || rofId >= mNrof) {
418 int startIdx{mROFramesClusters[layerId][rofId]};
419 return {&mClusters[layerId][startIdx],
static_cast<gsl::span<Cluster>::size_type
>(mROFramesClusters[layerId][rofId + 1] - startIdx)};
422template <
int nLayers>
425 if (rofId < 0 || rofId >= mNrof) {
428 int startIdx{mROFramesClusters[layerId][rofId]};
429 return {&mClusters[layerId][startIdx],
static_cast<gsl::span<const Cluster>::size_type
>(mROFramesClusters[layerId][rofId + 1] - startIdx)};
432template <
int nLayers>
435 if (rofId < 0 || rofId >= mNrof) {
438 int startIdx{mROFramesClusters[layerId][rofId]};
439 return {&mUsedClusters[layerId][startIdx],
static_cast<gsl::span<uint8_t>::size_type
>(mROFramesClusters[layerId][rofId + 1] - startIdx)};
442template <
int nLayers>
445 if (rofId < 0 || rofId >= mNrof) {
448 int startIdx{mROFramesClusters[layerId][rofId]};
449 return {&mUsedClusters[layerId][startIdx],
static_cast<gsl::span<const uint8_t>::size_type
>(mROFramesClusters[layerId][rofId + 1] - startIdx)};
452template <
int nLayers>
455 if (rofMin < 0 || rofMin >= mNrof) {
458 int startIdx{mROFramesClusters[layerId][rofMin]};
459 int endIdx{mROFramesClusters[layerId][o2::gpu::CAMath::Min(rofMin +
range, mNrof)]};
460 return {&mClusters[layerId][startIdx],
static_cast<gsl::span<Cluster>::size_type
>(endIdx - startIdx)};
463template <
int nLayers>
466 int chkdRange{o2::gpu::CAMath::Min(
range, mNrof - rofMin)};
467 return {&mROFramesClusters[layerId][rofMin],
static_cast<gsl::span<int>::size_type
>(chkdRange)};
470template <
int nLayers>
473 int chkdRange{o2::gpu::CAMath::Min(
range, mNrof - rofMin)};
474 return {&mNClustersPerROF[layerId][rofMin],
static_cast<gsl::span<int>::size_type
>(chkdRange)};
477template <
int nLayers>
480 int startIdx{rofMin};
481 int endIdx{o2::gpu::CAMath::Min(rofMin +
range, mNrof)};
482 return mROFramesClusters[layerId][endIdx] - mROFramesClusters[layerId][startIdx];
485template <
int nLayers>
488 const int iTableSize{mIndexTableUtils.getNphiBins() * mIndexTableUtils.getNzBins() + 1};
489 int chkdRange{o2::gpu::CAMath::Min(
range, mNrof - rofMin)};
490 return {&mIndexTables[layerId][rofMin * iTableSize],
static_cast<gsl::span<int>::size_type
>(chkdRange * iTableSize)};
493template <
int nLayers>
496 return std::lower_bound(mROFramesClusters[iLayer].begin(), mROFramesClusters[iLayer].
end(), iCluster + 1) - mROFramesClusters[iLayer].begin() - 1;
499template <
int nLayers>
502 if (rofId < 0 || rofId >= mNrof) {
505 int startIdx{mROFramesClusters[layerId][rofId]};
506 return {&mUnsortedClusters[layerId][startIdx],
static_cast<gsl::span<Cluster>::size_type
>(mROFramesClusters[layerId][rofId + 1] - startIdx)};
509template <
int nLayers>
512 if (rofId < 0 || rofId >= mNrof) {
515 return {&mIndexTables[
layer][rofId * (mIndexTableUtils.getNphiBins() * mIndexTableUtils.getNzBins() + 1)],
516 static_cast<gsl::span<int>::size_type
>(mIndexTableUtils.getNphiBins() * mIndexTableUtils.getNzBins() + 1)};
519template <
int nLayers>
520template <
typename... T>
523 mUnsortedClusters[
layer].emplace_back(std::forward<T>(
values)...);
526template <
int nLayers>
527template <
typename... T>
530 mTrackingFrameInfo[
layer].emplace_back(std::forward<T>(
values)...);
533template <
int nLayers>
536 return {&mUsedClusters[
layer][0],
static_cast<gsl::span<uint8_t>::size_type
>(mUsedClusters[
layer].size())};
539template <
int nLayers>
543 mRoadLabels.resize(mRoads.size());
546template <
int nLayers>
549 mRoadLabels[
i].first = lab;
550 mRoadLabels[
i].second = fake;
553template <
int nLayers>
556 if (rofId < 0 || rofId >= mNrof) {
559 auto startIdx{mROFramesClusters[1][rofId]};
560 return {&mNTrackletsPerCluster[combId][startIdx],
static_cast<gsl::span<int>::size_type
>(mROFramesClusters[1][rofId + 1] - startIdx)};
563template <
int nLayers>
566 if (rofId < 0 || rofId >= mNrof) {
569 auto clusStartIdx{mROFramesClusters[1][rofId]};
571 return {&mNTrackletsPerClusterSum[combId][clusStartIdx],
static_cast<gsl::span<int>::size_type
>(mROFramesClusters[1][rofId + 1] - clusStartIdx)};
574template <
int nLayers>
577 if (rofId < 0 || rofId >= mNrof) {
580 auto startIdx{mNTrackletsPerROF[combId][rofId]};
581 return {&mTracklets[combId][startIdx],
static_cast<gsl::span<Tracklet>::size_type
>(mNTrackletsPerROF[combId][rofId + 1] - startIdx)};
584template <
int nLayers>
587 if (rofId < 0 || rofId >= mNrof) {
590 auto startIdx{mNTrackletsPerROF[combId][rofId]};
591 return {&mTracklets[combId][startIdx],
static_cast<gsl::span<Tracklet>::size_type
>(mNTrackletsPerROF[combId][rofId + 1] - startIdx)};
594template <
int nLayers>
597 if (rofId < 0 || rofId >= mNrof || !hasMCinformation()) {
600 auto startIdx{mNTrackletsPerROF[combId][rofId]};
601 return {&mTrackletLabels[combId][startIdx],
static_cast<gsl::span<Tracklet>::size_type
>(mNTrackletsPerROF[combId][rofId + 1] - startIdx)};
604template <
int nLayers>
607 size_t totalClusters{0};
608 for (
const auto&
clusters : mUnsortedClusters) {
611 return int(totalClusters);
614template <
int nLayers>
618 for (
const auto&
layer : mClusters) {
624template <
int nLayers>
628 for (
const auto&
layer : mCells) {
629 nCells +=
layer.size();
634template <
int nLayers>
638 for (
const auto&
layer : mTracklets) {
639 nTracklets +=
layer.size();
644template <
int nLayers>
648 for (
const auto& l : mCellsNeighbours) {
654template <
int nLayers>
658 for (
const auto& t : mTracks) {
664template <
int nLayers>
668 for (
const auto&
layer : mUsedClusters) {
674template <
int nLayers>
677 int rofId =
vertex.getTimeStamp().getTimeStamp();
678 mPrimaryVertices.insert(mPrimaryVertices.begin() + mROFramesPV[rofId],
vertex);
679 for (
int i = rofId + 1;
i < mROFramesPV.size(); ++
i) {
682 mTotVertPerIteration[iteration]++;
Definition of a container to keep Monte Carlo truth external to simulation objects.
Definition of the ITS track.
HMPID cluster implementation.
float sum(float s, o2::dcs::DataPointValue v)
GLenum GLsizei GLsizei GLint * values
GLenum GLuint GLint GLint layer
GLubyte GLubyte GLubyte GLubyte w
void deepVectorClear(std::vector< T > &vec)
std::pmr::vector< T > bounded_vector
o2::dataformats::Vertex< o2::dataformats::TimeStamp< int > > Vertex
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
auto & getPositionResolutions()
void addTrackingFrameInfoToLayer(int layer, T &&... args)
IndexTableUtils mIndexTableUtils
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
void initialise(const int iteration, const TrackingParameters &trkParam, const int maxLayers=7, bool resetVertices=true)
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()
ExternalAllocator * mAllocator
int getTotalClustersPerROFrange(int rofMin, int range, int layerId) const
virtual int getNumberOfTracklets() const
auto & getTrackletsLabel(int layer)
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()
std::array< bounded_vector< int >, nLayers > mClusterExternalIndices
bool getExtAllocator() const
bool isRoadFake(int i) const
gsl::span< const Vertex > getPrimaryVertices(int romin, int romax) const
void printSliceInfo(const int, const int)
int getNLinesTotal() const
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
int getTotalClusters() const
gsl::span< int > getExclusiveNTrackletsCluster(int rofId, int combId)
void setMultiplicityCutMask(const std::vector< uint8_t > &cutMask)
auto & getTrackletClusters(int rofId)
std::vector< bounded_vector< int > > mTrackletsLookupTable
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 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
void setExternalAllocator(ExternalAllocator *allocator)
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
void setMemoryPool(std::shared_ptr< BoundedMemoryResource > &pool)
memory management
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
const Vertex & getPrimaryVertex(const int ivtx) const
ExternalAllocator * getExternalAllocator()
virtual void setDevicePropagator(const o2::base::PropagatorImpl< float > *)
std::vector< bounded_vector< int > > mCellsNeighbours
std::vector< bounded_vector< CellSeed > > mCells
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)
auto getNumberOfExtendedTracks() const
int hasBogusClusters() const
auto & getUnsortedClusters()
auto & getCellsNeighboursLUT()
int & getNTrackletsROF(int rofId, int combId)
int getNumberOfClusters() const
void setRoadLabel(int i, const unsigned long long &lab, bool fake)
auto & getMemoryPool() const noexcept
auto & getLines(int rofId)
int getClusterSize(int clusterId) const
void addPrimaryVertices(const bounded_vector< Vertex > &vertices)
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
std::vector< Cluster > clusters