13#ifndef TRACKINGITSU_INCLUDE_TIMEFRAME_H_
14#define TRACKINGITSU_INCLUDE_TIMEFRAME_H_
54class TopologyDictionary;
66template <
int nLayers = 7>
93 gsl::span<const itsmft::CompClusterExt>
clusters,
94 gsl::span<const unsigned char>::iterator& pattIt,
107 void setBeamPosition(
const float x,
const float y,
const float s2,
const float base = 50.f,
const float systematic = 0.f)
109 isBeamPositionOverridden =
true;
110 resetBeamXY(
x,
y, s2 / o2::gpu::CAMath::Sqrt(base * base + systematic));
156 mTotVertPerIteration.resize(1);
190 void setMemoryPool(std::shared_ptr<BoundedMemoryResource>& pool);
205 auto&
getLines(
int rofId) {
return mLines[rofId]; }
208 return std::accumulate(mLines.begin(), mLines.end(), 0, [](
int sum,
const auto& l) { return sum + l.size(); });
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); }
240 LOGP(
debug,
"Setting timeFrame allocator to external");
244 LOGP(fatal,
"External allocator is currently only supported for GPU");
256 template <
typename... T>
258 template <
typename... T>
304 std::vector<bounded_vector<CellSeedN>>
mCells;
306 std::vector<bounded_vector<TrackITSExt>>
mTracks;
316 void prepareClusters(
const TrackingParameters& trkParam,
const int maxLayers = nLayers);
318 unsigned int mNTotalLowPtVertices = 0;
319 int mBeamPosWeight = 0;
320 std::array<float, 2> mBeamPos = {0.f, 0.f};
321 bool isBeamPositionOverridden =
false;
322 std::array<float, nLayers> mMinR;
323 std::array<float, nLayers> mMaxR;
329 std::vector<uint8_t> mROFMask;
331 std::vector<bounded_vector<MCCompLabel>> mTrackletLabels;
332 std::vector<bounded_vector<MCCompLabel>> mCellLabels;
333 std::vector<bounded_vector<int>> mCellsNeighboursLUT;
334 std::vector<bounded_vector<MCCompLabel>> mTracksLabel;
338 int mCutClusterMult{-999};
339 int mCutVertexMult{-999};
342 std::vector<bounded_vector<int>> mNTrackletsPerROF;
343 std::vector<bounded_vector<Line>> mLines;
344 std::vector<bounded_vector<ClusterLines>> mTrackletClusters;
345 std::array<bounded_vector<int>, 2> mTrackletsIndexROF;
346 std::vector<bounded_vector<MCCompLabel>> mLinesLabels;
347 std::vector<std::pair<MCCompLabel, float>> mVerticesMCRecInfo;
348 bounded_vector<MCCompLabel> mVerticesContributorLabels;
349 std::array<uint32_t, 2> mTotalTracklets = {0, 0};
350 unsigned int mNoVertexROF = 0;
351 bounded_vector<int> mTotVertPerIteration;
354 std::shared_ptr<BoundedMemoryResource> mMemoryPool;
357template <
int nLayers>
360 if (mPrimaryVertices.empty()) {
363 const int start = mROFramesPV[rofId];
364 const int stop_idx = rofId >= mNrof - 1 ? mNrof : rofId + 1;
365 int delta = mMultiplicityCutMask[rofId] ? mROFramesPV[stop_idx] -
start : 0;
366 return {&mPrimaryVertices[
start],
static_cast<gsl::span<const Vertex>::size_type
>(delta)};
369template <
int nLayers>
372 const int start = mROFramesPV[rofId];
373 const int stop_idx = rofId >= mNrof - 1 ? mNrof : rofId + 1;
374 int delta = mMultiplicityCutMask[rofId] ? mROFramesPV[stop_idx] -
start : 0;
375 return {&(mVerticesMCRecInfo[
start]),
static_cast<gsl::span<const std::pair<MCCompLabel, float>
>::size_type>(delta)};
378template <
int nLayers>
382 unsigned int start{0}, delta{0};
383 const auto& pvsBefore = getPrimaryVertices(0, rofId - 1);
384 for (
const auto& pv : pvsBefore) {
385 start += pv.getNContributors();
387 const auto& pvsIn = getPrimaryVertices(rofId);
388 for (
const auto& pv : pvsIn) {
389 delta += pv.getNContributors();
391 return {&(mVerticesContributorLabels[
start]),
static_cast<gsl::span<const MCCompLabel>::size_type
>(delta)};
394template <
int nLayers>
397 if (mPrimaryVertices.empty()) {
400 const int stop_idx = romax >= mNrof - 1 ? mNrof : romax + 1;
401 return {&mPrimaryVertices[mROFramesPV[romin]],
static_cast<gsl::span<const Vertex>::size_type
>(mROFramesPV[stop_idx] - mROFramesPV[romin])};
404template <
int nLayers>
407 const int start = mROFramesPV[rofId];
408 const int stop_idx = rofId >= mNrof - 1 ? mNrof : rofId + 1;
409 int delta = mMultiplicityCutMask[rofId] ? mROFramesPV[stop_idx] -
start : 0;
410 return {&(mPValphaX[
start]),
static_cast<gsl::span<const std::array<float, 2>
>::size_type>(delta)};
413template <
int nLayers>
416 return rofId < 0 ? mPrimaryVertices.size() : mROFramesPV[rofId + 1] - mROFramesPV[rofId];
419template <
int nLayers>
427template <
int nLayers>
430 return {&mROFramesClusters[layerId][0],
static_cast<gsl::span<const int>::size_type
>(mROFramesClusters[layerId].size())};
433template <
int nLayers>
436 if (rofId < 0 || rofId >= mNrof) {
439 int startIdx{mROFramesClusters[layerId][rofId]};
440 return {&mClusters[layerId][startIdx],
static_cast<gsl::span<Cluster>::size_type
>(mROFramesClusters[layerId][rofId + 1] - startIdx)};
443template <
int nLayers>
446 if (rofId < 0 || rofId >= mNrof) {
449 int startIdx{mROFramesClusters[layerId][rofId]};
450 return {&mClusters[layerId][startIdx],
static_cast<gsl::span<const Cluster>::size_type
>(mROFramesClusters[layerId][rofId + 1] - startIdx)};
453template <
int nLayers>
456 if (rofId < 0 || rofId >= mNrof) {
459 int startIdx{mROFramesClusters[layerId][rofId]};
460 return {&mUsedClusters[layerId][startIdx],
static_cast<gsl::span<uint8_t>::size_type
>(mROFramesClusters[layerId][rofId + 1] - startIdx)};
463template <
int nLayers>
466 if (rofId < 0 || rofId >= mNrof) {
469 int startIdx{mROFramesClusters[layerId][rofId]};
470 return {&mUsedClusters[layerId][startIdx],
static_cast<gsl::span<const uint8_t>::size_type
>(mROFramesClusters[layerId][rofId + 1] - startIdx)};
473template <
int nLayers>
476 if (rofMin < 0 || rofMin >= mNrof) {
479 int startIdx{mROFramesClusters[layerId][rofMin]};
480 int endIdx{mROFramesClusters[layerId][o2::gpu::CAMath::Min(rofMin +
range, mNrof)]};
481 return {&mClusters[layerId][startIdx],
static_cast<gsl::span<Cluster>::size_type
>(endIdx - startIdx)};
484template <
int nLayers>
487 int chkdRange{o2::gpu::CAMath::Min(
range, mNrof - rofMin)};
488 return {&mROFramesClusters[layerId][rofMin],
static_cast<gsl::span<int>::size_type
>(chkdRange)};
491template <
int nLayers>
494 int chkdRange{o2::gpu::CAMath::Min(
range, mNrof - rofMin)};
495 return {&mNClustersPerROF[layerId][rofMin],
static_cast<gsl::span<int>::size_type
>(chkdRange)};
498template <
int nLayers>
501 int startIdx{rofMin};
502 int endIdx{o2::gpu::CAMath::Min(rofMin +
range, mNrof)};
503 return mROFramesClusters[layerId][endIdx] - mROFramesClusters[layerId][startIdx];
506template <
int nLayers>
509 const int iTableSize{mIndexTableUtils.getNphiBins() * mIndexTableUtils.getNzBins() + 1};
510 int chkdRange{o2::gpu::CAMath::Min(
range, mNrof - rofMin)};
511 return {&mIndexTables[layerId][rofMin * iTableSize],
static_cast<gsl::span<int>::size_type
>(chkdRange * iTableSize)};
514template <
int nLayers>
517 return std::lower_bound(mROFramesClusters[iLayer].begin(), mROFramesClusters[iLayer].
end(), iCluster + 1) - mROFramesClusters[iLayer].begin() - 1;
520template <
int nLayers>
523 if (rofId < 0 || rofId >= mNrof) {
526 int startIdx{mROFramesClusters[layerId][rofId]};
527 return {&mUnsortedClusters[layerId][startIdx],
static_cast<gsl::span<Cluster>::size_type
>(mROFramesClusters[layerId][rofId + 1] - startIdx)};
530template <
int nLayers>
533 if (rofId < 0 || rofId >= mNrof) {
536 const int tableSize = mIndexTableUtils.getNphiBins() * mIndexTableUtils.getNzBins() + 1;
537 return {&mIndexTables[
layer][rofId * tableSize],
static_cast<gsl::span<int>::size_type
>(tableSize)};
540template <
int nLayers>
541template <
typename... T>
544 mUnsortedClusters[
layer].emplace_back(std::forward<T>(
values)...);
547template <
int nLayers>
548template <
typename... T>
551 mTrackingFrameInfo[
layer].emplace_back(std::forward<T>(
values)...);
554template <
int nLayers>
557 return {&mUsedClusters[
layer][0],
static_cast<gsl::span<uint8_t>::size_type
>(mUsedClusters[
layer].size())};
560template <
int nLayers>
564 mRoadLabels.resize(mRoads.size());
567template <
int nLayers>
570 mRoadLabels[
i].first = lab;
571 mRoadLabels[
i].second = fake;
574template <
int nLayers>
577 if (rofId < 0 || rofId >= mNrof) {
580 auto startIdx{mROFramesClusters[1][rofId]};
581 return {&mNTrackletsPerCluster[combId][startIdx],
static_cast<gsl::span<int>::size_type
>(mROFramesClusters[1][rofId + 1] - startIdx)};
584template <
int nLayers>
587 if (rofId < 0 || rofId >= mNrof) {
590 auto clusStartIdx{mROFramesClusters[1][rofId]};
592 return {&mNTrackletsPerClusterSum[combId][clusStartIdx],
static_cast<gsl::span<int>::size_type
>(mROFramesClusters[1][rofId + 1] - clusStartIdx)};
595template <
int nLayers>
598 if (rofId < 0 || rofId >= mNrof || mTracklets[combId].
empty()) {
601 auto startIdx{mNTrackletsPerROF[combId][rofId]};
602 return {&mTracklets[combId][startIdx],
static_cast<gsl::span<Tracklet>::size_type
>(mNTrackletsPerROF[combId][rofId + 1] - startIdx)};
605template <
int nLayers>
608 if (rofId < 0 || rofId >= mNrof) {
611 auto startIdx{mNTrackletsPerROF[combId][rofId]};
612 return {&mTracklets[combId][startIdx],
static_cast<gsl::span<Tracklet>::size_type
>(mNTrackletsPerROF[combId][rofId + 1] - startIdx)};
615template <
int nLayers>
618 if (rofId < 0 || rofId >= mNrof || !hasMCinformation()) {
621 auto startIdx{mNTrackletsPerROF[combId][rofId]};
622 return {&mTrackletLabels[combId][startIdx],
static_cast<gsl::span<Tracklet>::size_type
>(mNTrackletsPerROF[combId][rofId + 1] - startIdx)};
625template <
int nLayers>
628 size_t totalClusters{0};
629 for (
const auto&
clusters : mUnsortedClusters) {
632 return int(totalClusters);
635template <
int nLayers>
639 for (
const auto&
layer : mClusters) {
645template <
int nLayers>
649 for (
const auto&
layer : mCells) {
650 nCells +=
layer.size();
655template <
int nLayers>
659 for (
const auto&
layer : mTracklets) {
660 nTracklets +=
layer.size();
665template <
int nLayers>
669 for (
const auto& l : mCellsNeighbours) {
675template <
int nLayers>
679 for (
const auto& t : mTracks) {
685template <
int nLayers>
689 for (
const auto&
layer : mUsedClusters) {
695template <
int nLayers>
698 int rofId =
vertex.getTimeStamp().getTimeStamp();
699 mPrimaryVertices.insert(mPrimaryVertices.begin() + mROFramesPV[rofId],
vertex);
700 for (
int i = rofId + 1;
i < mROFramesPV.size(); ++
i) {
703 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::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
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
std::vector< Cluster > clusters