13#ifndef TRACKINGITSU_INCLUDE_TIMEFRAME_H_
14#define TRACKINGITSU_INCLUDE_TIMEFRAME_H_
54class TopologyDictionary;
67template <
int nLayers = 7>
91 gsl::span<const itsmft::CompClusterExt>
clusters,
92 gsl::span<const unsigned char>::iterator& pattIt,
105 void setBeamPosition(
const float x,
const float y,
const float s2,
const float base = 50.f,
const float systematic = 0.f)
107 isBeamPositionOverridden =
true;
108 resetBeamXY(
x,
y, s2 / o2::gpu::CAMath::Sqrt(base * base + systematic));
154 mTotVertPerIteration.resize(1);
188 void setMemoryPool(std::shared_ptr<BoundedMemoryResource>& pool);
203 auto&
getLines(
int rofId) {
return mLines[rofId]; }
206 return std::accumulate(mLines.begin(), mLines.end(), 0, [](
int sum,
const auto& l) { return sum + l.size(); });
223 const unsigned long long&
getRoadLabel(
int i)
const {
return mRoadLabels[
i].first; }
227 void setROFMask(
const std::vector<uint8_t>& rofMask) { mROFMask = rofMask; }
230 int hasBogusClusters()
const {
return std::accumulate(mBogusClusters.begin(), mBogusClusters.end(), 0); }
238 LOGP(
debug,
"Setting timeFrame allocator to external");
242 LOGP(fatal,
"External allocator is currently only supported for GPU");
254 template <
typename... T>
256 template <
typename... T>
302 std::vector<bounded_vector<CellSeed>>
mCells;
304 std::vector<bounded_vector<TrackITSExt>>
mTracks;
314 void prepareClusters(
const TrackingParameters& trkParam,
const int maxLayers = nLayers);
316 unsigned int mNTotalLowPtVertices = 0;
317 int mBeamPosWeight = 0;
318 std::array<float, 2> mBeamPos = {0.f, 0.f};
319 bool isBeamPositionOverridden =
false;
320 std::array<float, nLayers> mMinR;
321 std::array<float, nLayers> mMaxR;
327 std::vector<uint8_t> mROFMask;
329 std::vector<bounded_vector<MCCompLabel>> mTrackletLabels;
330 std::vector<bounded_vector<MCCompLabel>> mCellLabels;
331 std::vector<bounded_vector<int>> mCellsNeighboursLUT;
332 std::vector<bounded_vector<MCCompLabel>> mTracksLabel;
336 int mCutClusterMult{-999};
337 int mCutVertexMult{-999};
340 std::vector<bounded_vector<int>> mNTrackletsPerROF;
341 std::vector<bounded_vector<Line>> mLines;
342 std::vector<bounded_vector<ClusterLines>> mTrackletClusters;
343 std::array<bounded_vector<int>, 2> mTrackletsIndexROF;
344 std::vector<bounded_vector<MCCompLabel>> mLinesLabels;
345 std::vector<std::pair<MCCompLabel, float>> mVerticesMCRecInfo;
346 bounded_vector<MCCompLabel> mVerticesContributorLabels;
347 std::array<uint32_t, 2> mTotalTracklets = {0, 0};
348 unsigned int mNoVertexROF = 0;
349 bounded_vector<int> mTotVertPerIteration;
352 std::shared_ptr<BoundedMemoryResource> mMemoryPool;
355template <
int nLayers>
358 if (mPrimaryVertices.empty()) {
361 const int start = mROFramesPV[rofId];
362 const int stop_idx = rofId >= mNrof - 1 ? mNrof : rofId + 1;
363 int delta = mMultiplicityCutMask[rofId] ? mROFramesPV[stop_idx] -
start : 0;
364 return {&mPrimaryVertices[
start],
static_cast<gsl::span<const Vertex>::size_type
>(delta)};
367template <
int nLayers>
370 const int start = mROFramesPV[rofId];
371 const int stop_idx = rofId >= mNrof - 1 ? mNrof : rofId + 1;
372 int delta = mMultiplicityCutMask[rofId] ? mROFramesPV[stop_idx] -
start : 0;
373 return {&(mVerticesMCRecInfo[
start]),
static_cast<gsl::span<const std::pair<MCCompLabel, float>
>::size_type>(delta)};
376template <
int nLayers>
380 unsigned int start{0}, delta{0};
381 const auto& pvsBefore = getPrimaryVertices(0, rofId - 1);
382 for (
const auto& pv : pvsBefore) {
383 start += pv.getNContributors();
385 const auto& pvsIn = getPrimaryVertices(rofId);
386 for (
const auto& pv : pvsIn) {
387 delta += pv.getNContributors();
389 return {&(mVerticesContributorLabels[
start]),
static_cast<gsl::span<const MCCompLabel>::size_type
>(delta)};
392template <
int nLayers>
395 if (mPrimaryVertices.empty()) {
398 const int stop_idx = romax >= mNrof - 1 ? mNrof : romax + 1;
399 return {&mPrimaryVertices[mROFramesPV[romin]],
static_cast<gsl::span<const Vertex>::size_type
>(mROFramesPV[stop_idx] - mROFramesPV[romin])};
402template <
int nLayers>
405 const int start = mROFramesPV[rofId];
406 const int stop_idx = rofId >= mNrof - 1 ? mNrof : rofId + 1;
407 int delta = mMultiplicityCutMask[rofId] ? mROFramesPV[stop_idx] -
start : 0;
408 return {&(mPValphaX[
start]),
static_cast<gsl::span<const std::array<float, 2>
>::size_type>(delta)};
411template <
int nLayers>
414 return rofId < 0 ? mPrimaryVertices.size() : mROFramesPV[rofId + 1] - mROFramesPV[rofId];
417template <
int nLayers>
425template <
int nLayers>
428 return {&mROFramesClusters[layerId][0],
static_cast<gsl::span<const int>::size_type
>(mROFramesClusters[layerId].size())};
431template <
int nLayers>
434 if (rofId < 0 || rofId >= mNrof) {
437 int startIdx{mROFramesClusters[layerId][rofId]};
438 return {&mClusters[layerId][startIdx],
static_cast<gsl::span<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 {&mClusters[layerId][startIdx],
static_cast<gsl::span<const Cluster>::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<uint8_t>::size_type
>(mROFramesClusters[layerId][rofId + 1] - startIdx)};
461template <
int nLayers>
464 if (rofId < 0 || rofId >= mNrof) {
467 int startIdx{mROFramesClusters[layerId][rofId]};
468 return {&mUsedClusters[layerId][startIdx],
static_cast<gsl::span<const uint8_t>::size_type
>(mROFramesClusters[layerId][rofId + 1] - startIdx)};
471template <
int nLayers>
474 if (rofMin < 0 || rofMin >= mNrof) {
477 int startIdx{mROFramesClusters[layerId][rofMin]};
478 int endIdx{mROFramesClusters[layerId][o2::gpu::CAMath::Min(rofMin +
range, mNrof)]};
479 return {&mClusters[layerId][startIdx],
static_cast<gsl::span<Cluster>::size_type
>(endIdx - startIdx)};
482template <
int nLayers>
485 int chkdRange{o2::gpu::CAMath::Min(
range, mNrof - rofMin)};
486 return {&mROFramesClusters[layerId][rofMin],
static_cast<gsl::span<int>::size_type
>(chkdRange)};
489template <
int nLayers>
492 int chkdRange{o2::gpu::CAMath::Min(
range, mNrof - rofMin)};
493 return {&mNClustersPerROF[layerId][rofMin],
static_cast<gsl::span<int>::size_type
>(chkdRange)};
496template <
int nLayers>
499 int startIdx{rofMin};
500 int endIdx{o2::gpu::CAMath::Min(rofMin +
range, mNrof)};
501 return mROFramesClusters[layerId][endIdx] - mROFramesClusters[layerId][startIdx];
504template <
int nLayers>
507 const int iTableSize{mIndexTableUtils.getNphiBins() * mIndexTableUtils.getNzBins() + 1};
508 int chkdRange{o2::gpu::CAMath::Min(
range, mNrof - rofMin)};
509 return {&mIndexTables[layerId][rofMin * iTableSize],
static_cast<gsl::span<int>::size_type
>(chkdRange * iTableSize)};
512template <
int nLayers>
515 return std::lower_bound(mROFramesClusters[iLayer].begin(), mROFramesClusters[iLayer].
end(), iCluster + 1) - mROFramesClusters[iLayer].begin() - 1;
518template <
int nLayers>
521 if (rofId < 0 || rofId >= mNrof) {
524 int startIdx{mROFramesClusters[layerId][rofId]};
525 return {&mUnsortedClusters[layerId][startIdx],
static_cast<gsl::span<Cluster>::size_type
>(mROFramesClusters[layerId][rofId + 1] - startIdx)};
528template <
int nLayers>
531 if (rofId < 0 || rofId >= mNrof) {
534 const int tableSize = mIndexTableUtils.getNphiBins() * mIndexTableUtils.getNzBins() + 1;
535 return {&mIndexTables[
layer][rofId * tableSize],
static_cast<gsl::span<int>::size_type
>(tableSize)};
538template <
int nLayers>
539template <
typename... T>
542 mUnsortedClusters[
layer].emplace_back(std::forward<T>(
values)...);
545template <
int nLayers>
546template <
typename... T>
549 mTrackingFrameInfo[
layer].emplace_back(std::forward<T>(
values)...);
552template <
int nLayers>
555 return {&mUsedClusters[
layer][0],
static_cast<gsl::span<uint8_t>::size_type
>(mUsedClusters[
layer].size())};
558template <
int nLayers>
562 mRoadLabels.resize(mRoads.size());
565template <
int nLayers>
568 mRoadLabels[
i].first = lab;
569 mRoadLabels[
i].second = fake;
572template <
int nLayers>
575 if (rofId < 0 || rofId >= mNrof) {
578 auto startIdx{mROFramesClusters[1][rofId]};
579 return {&mNTrackletsPerCluster[combId][startIdx],
static_cast<gsl::span<int>::size_type
>(mROFramesClusters[1][rofId + 1] - startIdx)};
582template <
int nLayers>
585 if (rofId < 0 || rofId >= mNrof) {
588 auto clusStartIdx{mROFramesClusters[1][rofId]};
590 return {&mNTrackletsPerClusterSum[combId][clusStartIdx],
static_cast<gsl::span<int>::size_type
>(mROFramesClusters[1][rofId + 1] - clusStartIdx)};
593template <
int nLayers>
596 if (rofId < 0 || rofId >= mNrof || mTracklets[combId].
empty()) {
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) {
609 auto startIdx{mNTrackletsPerROF[combId][rofId]};
610 return {&mTracklets[combId][startIdx],
static_cast<gsl::span<Tracklet>::size_type
>(mNTrackletsPerROF[combId][rofId + 1] - startIdx)};
613template <
int nLayers>
616 if (rofId < 0 || rofId >= mNrof || !hasMCinformation()) {
619 auto startIdx{mNTrackletsPerROF[combId][rofId]};
620 return {&mTrackletLabels[combId][startIdx],
static_cast<gsl::span<Tracklet>::size_type
>(mNTrackletsPerROF[combId][rofId + 1] - startIdx)};
623template <
int nLayers>
626 size_t totalClusters{0};
627 for (
const auto&
clusters : mUnsortedClusters) {
630 return int(totalClusters);
633template <
int nLayers>
637 for (
const auto&
layer : mClusters) {
643template <
int nLayers>
647 for (
const auto&
layer : mCells) {
648 nCells +=
layer.size();
653template <
int nLayers>
657 for (
const auto&
layer : mTracklets) {
658 nTracklets +=
layer.size();
663template <
int nLayers>
667 for (
const auto& l : mCellsNeighbours) {
673template <
int nLayers>
677 for (
const auto& t : mTracks) {
683template <
int nLayers>
687 for (
const auto&
layer : mUsedClusters) {
693template <
int nLayers>
696 int rofId =
vertex.getTimeStamp().getTimeStamp();
697 mPrimaryVertices.insert(mPrimaryVertices.begin() + mROFramesPV[rofId],
vertex);
698 for (
int i = rofId + 1;
i < mROFramesPV.size(); ++
i) {
701 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)
IndexTableUtils mIndexTableUtils
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::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
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)
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
std::vector< Cluster > clusters