13#ifndef TRACKINGITSU_INCLUDE_TIMEFRAME_H_
14#define TRACKINGITSU_INCLUDE_TIMEFRAME_H_
54class TopologyDictionary;
66template <
int nLayers = 7>
94 gsl::span<const itsmft::CompClusterExt>
clusters,
95 gsl::span<const unsigned char>::iterator& pattIt,
108 void setBeamPosition(
const float x,
const float y,
const float s2,
const float base = 50.f,
const float systematic = 0.f)
110 isBeamPositionOverridden =
true;
111 resetBeamXY(
x,
y, s2 / o2::gpu::CAMath::Sqrt(base * base + systematic));
157 mTotVertPerIteration.resize(1);
191 void setMemoryPool(std::shared_ptr<BoundedMemoryResource>& pool);
206 auto&
getLines(
int rofId) {
return mLines[rofId]; }
209 return std::accumulate(mLines.begin(), mLines.end(), 0, [](
int sum,
const auto& l) { return sum + l.size(); });
226 const unsigned long long&
getRoadLabel(
int i)
const {
return mRoadLabels[
i].first; }
230 void setROFMask(
const std::vector<uint8_t>& rofMask) { mROFMask = rofMask; }
233 int hasBogusClusters()
const {
return std::accumulate(mBogusClusters.begin(), mBogusClusters.end(), 0); }
241 LOGP(
debug,
"Setting timeFrame allocator to external");
245 LOGP(fatal,
"External allocator is currently only supported for GPU");
257 template <
typename... T>
259 template <
typename... T>
305 std::vector<bounded_vector<CellSeedN>>
mCells;
307 std::vector<bounded_vector<TrackITSExt>>
mTracks;
317 void prepareClusters(
const TrackingParameters& trkParam,
const int maxLayers = nLayers);
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;
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;
339 int mCutClusterMult{-999};
340 int mCutVertexMult{-999};
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;
355 std::shared_ptr<BoundedMemoryResource> mMemoryPool;
358template <
int nLayers>
361 if (mPrimaryVertices.empty()) {
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;
367 return {&mPrimaryVertices[
start],
static_cast<gsl::span<const Vertex>::size_type
>(delta)};
370template <
int nLayers>
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;
376 return {&(mVerticesMCRecInfo[
start]),
static_cast<gsl::span<const std::pair<MCCompLabel, float>
>::size_type>(delta)};
379template <
int nLayers>
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();
388 const auto& pvsIn = getPrimaryVertices(rofId);
389 for (
const auto& pv : pvsIn) {
390 delta += pv.getNContributors();
392 return {&(mVerticesContributorLabels[
start]),
static_cast<gsl::span<const MCCompLabel>::size_type
>(delta)};
395template <
int nLayers>
398 if (mPrimaryVertices.empty()) {
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])};
405template <
int nLayers>
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;
411 return {&(mPValphaX[
start]),
static_cast<gsl::span<const std::array<float, 2>
>::size_type>(delta)};
414template <
int nLayers>
417 return rofId < 0 ? mPrimaryVertices.size() : mROFramesPV[rofId + 1] - mROFramesPV[rofId];
420template <
int nLayers>
428template <
int nLayers>
431 return {&mROFramesClusters[layerId][0],
static_cast<gsl::span<const int>::size_type
>(mROFramesClusters[layerId].size())};
434template <
int nLayers>
437 if (rofId < 0 || rofId >= mNrof) {
440 int startIdx{mROFramesClusters[layerId][rofId]};
441 return {&mClusters[layerId][startIdx],
static_cast<gsl::span<Cluster>::size_type
>(mROFramesClusters[layerId][rofId + 1] - startIdx)};
444template <
int nLayers>
447 if (rofId < 0 || rofId >= mNrof) {
450 int startIdx{mROFramesClusters[layerId][rofId]};
451 return {&mClusters[layerId][startIdx],
static_cast<gsl::span<const Cluster>::size_type
>(mROFramesClusters[layerId][rofId + 1] - startIdx)};
454template <
int nLayers>
457 if (rofId < 0 || rofId >= mNrof) {
460 int startIdx{mROFramesClusters[layerId][rofId]};
461 return {&mUsedClusters[layerId][startIdx],
static_cast<gsl::span<uint8_t>::size_type
>(mROFramesClusters[layerId][rofId + 1] - startIdx)};
464template <
int nLayers>
467 if (rofId < 0 || rofId >= mNrof) {
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)};
474template <
int nLayers>
477 if (rofMin < 0 || rofMin >= mNrof) {
480 int startIdx{mROFramesClusters[layerId][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)};
485template <
int nLayers>
488 int chkdRange{o2::gpu::CAMath::Min(
range, mNrof - rofMin)};
489 return {&mROFramesClusters[layerId][rofMin],
static_cast<gsl::span<int>::size_type
>(chkdRange)};
492template <
int nLayers>
495 int chkdRange{o2::gpu::CAMath::Min(
range, mNrof - rofMin)};
496 return {&mNClustersPerROF[layerId][rofMin],
static_cast<gsl::span<int>::size_type
>(chkdRange)};
499template <
int nLayers>
502 int startIdx{rofMin};
503 int endIdx{o2::gpu::CAMath::Min(rofMin +
range, mNrof)};
504 return mROFramesClusters[layerId][endIdx] - mROFramesClusters[layerId][startIdx];
507template <
int nLayers>
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)};
515template <
int nLayers>
518 return std::lower_bound(mROFramesClusters[iLayer].begin(), mROFramesClusters[iLayer].
end(), iCluster + 1) - mROFramesClusters[iLayer].begin() - 1;
521template <
int nLayers>
524 if (rofId < 0 || rofId >= mNrof) {
527 int startIdx{mROFramesClusters[layerId][rofId]};
528 return {&mUnsortedClusters[layerId][startIdx],
static_cast<gsl::span<Cluster>::size_type
>(mROFramesClusters[layerId][rofId + 1] - startIdx)};
531template <
int nLayers>
534 if (rofId < 0 || rofId >= mNrof) {
537 const int tableSize = mIndexTableUtils.getNphiBins() * mIndexTableUtils.getNzBins() + 1;
538 return {&mIndexTables[
layer][rofId * tableSize],
static_cast<gsl::span<int>::size_type
>(tableSize)};
541template <
int nLayers>
542template <
typename... T>
545 mUnsortedClusters[
layer].emplace_back(std::forward<T>(
values)...);
548template <
int nLayers>
549template <
typename... T>
552 mTrackingFrameInfo[
layer].emplace_back(std::forward<T>(
values)...);
555template <
int nLayers>
558 return {&mUsedClusters[
layer][0],
static_cast<gsl::span<uint8_t>::size_type
>(mUsedClusters[
layer].size())};
561template <
int nLayers>
565 mRoadLabels.resize(mRoads.size());
568template <
int nLayers>
571 mRoadLabels[
i].first = lab;
572 mRoadLabels[
i].second = fake;
575template <
int nLayers>
578 if (rofId < 0 || rofId >= mNrof) {
581 auto startIdx{mROFramesClusters[1][rofId]};
582 return {&mNTrackletsPerCluster[combId][startIdx],
static_cast<gsl::span<int>::size_type
>(mROFramesClusters[1][rofId + 1] - startIdx)};
585template <
int nLayers>
588 if (rofId < 0 || rofId >= mNrof) {
591 auto clusStartIdx{mROFramesClusters[1][rofId]};
593 return {&mNTrackletsPerClusterSum[combId][clusStartIdx],
static_cast<gsl::span<int>::size_type
>(mROFramesClusters[1][rofId + 1] - clusStartIdx)};
596template <
int nLayers>
599 if (rofId < 0 || rofId >= mNrof || mTracklets[combId].
empty()) {
602 auto startIdx{mNTrackletsPerROF[combId][rofId]};
603 return {&mTracklets[combId][startIdx],
static_cast<gsl::span<Tracklet>::size_type
>(mNTrackletsPerROF[combId][rofId + 1] - startIdx)};
606template <
int nLayers>
609 if (rofId < 0 || rofId >= mNrof) {
612 auto startIdx{mNTrackletsPerROF[combId][rofId]};
613 return {&mTracklets[combId][startIdx],
static_cast<gsl::span<Tracklet>::size_type
>(mNTrackletsPerROF[combId][rofId + 1] - startIdx)};
616template <
int nLayers>
619 if (rofId < 0 || rofId >= mNrof || !hasMCinformation()) {
622 auto startIdx{mNTrackletsPerROF[combId][rofId]};
623 return {&mTrackletLabels[combId][startIdx],
static_cast<gsl::span<Tracklet>::size_type
>(mNTrackletsPerROF[combId][rofId + 1] - startIdx)};
626template <
int nLayers>
629 size_t totalClusters{0};
630 for (
const auto&
clusters : mUnsortedClusters) {
633 return int(totalClusters);
636template <
int nLayers>
640 for (
const auto&
layer : mClusters) {
646template <
int nLayers>
650 for (
const auto&
layer : mCells) {
651 nCells +=
layer.size();
656template <
int nLayers>
660 for (
const auto&
layer : mTracklets) {
661 nTracklets +=
layer.size();
666template <
int nLayers>
670 for (
const auto& l : mCellsNeighbours) {
676template <
int nLayers>
680 for (
const auto& t : mTracks) {
686template <
int nLayers>
690 for (
const auto&
layer : mUsedClusters) {
696template <
int nLayers>
699 int rofId =
vertex.getTimeStamp().getTimeStamp();
700 mPrimaryVertices.insert(mPrimaryVertices.begin() + mROFramesPV[rofId],
vertex);
701 for (
int i = rofId + 1;
i < mROFramesPV.size(); ++
i) {
704 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
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 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)
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()
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::vector< bounded_vector< CellSeedN > > mCells
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 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
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
IndexTableUtilsN mIndexTableUtils
const Vertex & getPrimaryVertex(const int ivtx) const
ExternalAllocator * getExternalAllocator()
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 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