diff --git a/DataFormats/Detectors/ITSMFT/ITS/include/DataFormatsITS/TrackITS.h b/DataFormats/Detectors/ITSMFT/ITS/include/DataFormatsITS/TrackITS.h index 62bf846f65205..a4b1510e0a289 100644 --- a/DataFormats/Detectors/ITSMFT/ITS/include/DataFormatsITS/TrackITS.h +++ b/DataFormats/Detectors/ITSMFT/ITS/include/DataFormatsITS/TrackITS.h @@ -94,9 +94,10 @@ class TrackITS : public o2::track::TrackParCov o2::track::TrackParCov& getParamOut() { return mParamOut; } const o2::track::TrackParCov& getParamOut() const { return mParamOut; } - void setPattern(uint16_t p) { mPattern = p; } + void setPattern(uint32_t p) { mPattern = p; } int getPattern() const { return mPattern; } bool hasHitOnLayer(int i) { return mPattern & (0x1 << i); } + bool isFakeOnLayer(int i) { return !(mPattern & (0x1 << (16 + i))); } void setNextROFbit(bool toggle = true) { setUserField((getUserField() & ~kNextROF) | (-toggle & kNextROF)); } bool hasHitInNextROF() const { return getUserField() & kNextROF; } @@ -105,9 +106,9 @@ class TrackITS : public o2::track::TrackParCov o2::track::TrackParCov mParamOut; ///< parameter at largest radius ClusRefs mClusRef; ///< references on clusters float mChi2 = 0.; ///< Chi2 for this track - uint16_t mPattern = 0; ///< layers pattern + uint32_t mPattern = 0; ///< layers pattern - ClassDefNV(TrackITS, 4); + ClassDefNV(TrackITS, 5); }; class TrackITSExt : public TrackITS @@ -115,7 +116,7 @@ class TrackITSExt : public TrackITS ///< heavy version of TrackITS, with clusters embedded public: static constexpr int MaxClusters = 16; /// Prepare for overlaps and new detector configurations - using TrackITS::TrackITS; // inherit base constructors + using TrackITS::TrackITS; // inherit base constructors GPUd() TrackITSExt(o2::track::TrackParCov&& parCov, short ncl, float chi2, o2::track::TrackParCov&& outer, std::array cls) @@ -124,6 +125,13 @@ class TrackITSExt : public TrackITS setNumberOfClusters(ncl); } + GPUd() TrackITSExt(o2::track::TrackParCov& parCov, short ncl, float chi2, std::uint32_t rof, + o2::track::TrackParCov& outer, std::array cls) + : TrackITS(parCov, chi2, outer), mIndex{cls} + { + setNumberOfClusters(ncl); + } + void setClusterIndex(int l, int i) { int ncl = getNumberOfClusters(); @@ -137,10 +145,18 @@ class TrackITSExt : public TrackITS { if (newCluster) { getClusterRefs().setEntries(getNumberOfClusters() + 1); + uint32_t pattern = getPattern(); + pattern |= 0x1 << layer; + setPattern(pattern); } mIndex[layer] = idx; } + std::array& getClusterIndexes() + { + return mIndex; + } + private: std::array mIndex = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; ///< Indices of associated clusters ClassDefNV(TrackITSExt, 2); diff --git a/Detectors/ITSMFT/ITS/tracking/include/ITStracking/IOUtils.h b/Detectors/ITSMFT/ITS/tracking/include/ITStracking/IOUtils.h index 87e8f2557e87c..7ff05ebacc054 100644 --- a/Detectors/ITSMFT/ITS/tracking/include/ITStracking/IOUtils.h +++ b/Detectors/ITSMFT/ITS/tracking/include/ITStracking/IOUtils.h @@ -56,14 +56,12 @@ constexpr float DefClusErrorCol = o2::itsmft::SegmentationAlpide::PitchCol * 0.5 constexpr float DefClusError2Row = DefClusErrorRow * DefClusErrorRow; constexpr float DefClusError2Col = DefClusErrorCol * DefClusErrorCol; -std::vector loadEventData(const std::string&); void loadEventData(ROframe& events, gsl::span clusters, gsl::span::iterator& pattIt, const itsmft::TopologyDictionary& dict, const dataformats::MCTruthContainer* clsLabels = nullptr); int loadROFrameData(const o2::itsmft::ROFRecord& rof, ROframe& events, gsl::span clusters, gsl::span::iterator& pattIt, const itsmft::TopologyDictionary& dict, const dataformats::MCTruthContainer* mClsLabels = nullptr); -// void generateSimpleData(ROframe& event, const int phiDivs, const int zDivs); void convertCompactClusters(gsl::span clusters, gsl::span::iterator& pattIt, diff --git a/Detectors/ITSMFT/ITS/tracking/include/ITStracking/ROframe.h b/Detectors/ITSMFT/ITS/tracking/include/ITStracking/ROframe.h index a4fcb659f7d6d..a39ee1b96c72a 100644 --- a/Detectors/ITSMFT/ITS/tracking/include/ITStracking/ROframe.h +++ b/Detectors/ITSMFT/ITS/tracking/include/ITStracking/ROframe.h @@ -56,8 +56,10 @@ class ROframe final const auto& getTrackingFrameInfo() const { return mTrackingFrameInfo; } const TrackingFrameInfo& getClusterTrackingFrameInfo(int layerId, const Cluster& cl) const; - const MCCompLabel& getClusterLabels(int layerId, const Cluster& cl) const; - const MCCompLabel& getClusterLabels(int layerId, const int clId) const; + const MCCompLabel& getClusterFirstLabel(int layerId, const Cluster& cl) const; + const MCCompLabel& getClusterFirstLabel(int layerId, const int clId) const; + gsl::span getClusterLabels(int layerId, const int clId) const; + gsl::span getClusterLabels(int layerId, const Cluster& cl) const; int getClusterExternalIndex(int layerId, const int clId) const; std::vector getTracksId(const int layerId, const std::vector& cl); @@ -65,7 +67,7 @@ class ROframe final void addClusterToLayer(int layer, T&&... args); template void addTrackingFrameInfoToLayer(int layer, T&&... args); - void addClusterLabelToLayer(int layer, const MCCompLabel label); + void setMClabelsContainer(const dataformats::MCTruthContainer* ptr); void addClusterExternalIndexToLayer(int layer, const int idx); bool hasMCinformation() const; @@ -73,10 +75,10 @@ class ROframe final private: const int mROframeId; + o2::dataformats::MCTruthContainer* mMClabels = nullptr; std::vector mPrimaryVertices; std::vector> mClusters; std::vector> mTrackingFrameInfo; - std::vector> mClusterLabels; std::vector> mClusterExternalIndices; }; @@ -103,14 +105,24 @@ inline const TrackingFrameInfo& ROframe::getClusterTrackingFrameInfo(int layerId return mTrackingFrameInfo[layerId][cl.clusterId]; } -inline const MCCompLabel& ROframe::getClusterLabels(int layerId, const Cluster& cl) const +inline const MCCompLabel& ROframe::getClusterFirstLabel(int layerId, const Cluster& cl) const { - return mClusterLabels[layerId][cl.clusterId]; + return getClusterFirstLabel(layerId, cl.clusterId); } -inline const MCCompLabel& ROframe::getClusterLabels(int layerId, const int clId) const +inline const MCCompLabel& ROframe::getClusterFirstLabel(int layerId, const int clId) const { - return mClusterLabels[layerId][clId]; + return *(mMClabels->getLabels(getClusterExternalIndex(layerId, clId)).begin()); +} + +inline gsl::span ROframe::getClusterLabels(int layerId, const int clId) const +{ + return mMClabels->getLabels(getClusterExternalIndex(layerId, clId)); +} + +inline gsl::span ROframe::getClusterLabels(int layerId, const Cluster& cl) const +{ + return getClusterLabels(layerId, cl.clusterId); } inline int ROframe::getClusterExternalIndex(int layerId, const int clId) const @@ -122,7 +134,7 @@ inline std::vector ROframe::getTracksId(const int layerId, const std::vecto { std::vector tracksId; for (auto& cluster : cl) { - tracksId.push_back(getClusterLabels(layerId, cluster).isNoise() ? -1 : getClusterLabels(layerId, cluster).getTrackID()); + tracksId.push_back(getClusterFirstLabel(layerId, cluster).isNoise() ? -1 : getClusterFirstLabel(layerId, cluster).getTrackID()); } return tracksId; } @@ -139,7 +151,10 @@ void ROframe::addTrackingFrameInfoToLayer(int layer, T&&... values) mTrackingFrameInfo[layer].emplace_back(std::forward(values)...); } -inline void ROframe::addClusterLabelToLayer(int layer, const MCCompLabel label) { mClusterLabels[layer].emplace_back(label); } +inline void ROframe::setMClabelsContainer(const dataformats::MCTruthContainer* ptr) +{ + mMClabels = const_cast*>(ptr); +} inline void ROframe::addClusterExternalIndexToLayer(int layer, const int idx) { @@ -151,20 +166,22 @@ inline void ROframe::clear() for (unsigned int iL = 0; iL < mClusters.size(); ++iL) { mClusters[iL].clear(); mTrackingFrameInfo[iL].clear(); - mClusterLabels[iL].clear(); + // mClusterLabels[iL].clear(); mClusterExternalIndices[iL].clear(); } mPrimaryVertices.clear(); + mMClabels = nullptr; } inline bool ROframe::hasMCinformation() const { - for (const auto& vect : mClusterLabels) { - if (!vect.empty()) { - return true; - } - } - return false; + // for (const auto& vect : mClusterLabels) { + // if (!vect.empty()) { + // return true; + // } + // } + // return false; + return mMClabels; } } // namespace its diff --git a/Detectors/ITSMFT/ITS/tracking/include/ITStracking/StandaloneDebugger.h b/Detectors/ITSMFT/ITS/tracking/include/ITStracking/StandaloneDebugger.h index c00bf889656d8..c89fe704dfbe2 100644 --- a/Detectors/ITSMFT/ITS/tracking/include/ITStracking/StandaloneDebugger.h +++ b/Detectors/ITSMFT/ITS/tracking/include/ITStracking/StandaloneDebugger.h @@ -60,7 +60,7 @@ struct FakeTrackInfo { if (extIndex == -1) { continue; } - o2::MCCompLabel mcLabel = event.getClusterLabels(iCluster, extIndex); + o2::MCCompLabel mcLabel = *(event.getClusterLabels(iCluster, extIndex).begin()); bool found = false; for (size_t iOcc{0}; iOcc < occurrences.size(); ++iOcc) { @@ -96,7 +96,7 @@ struct FakeTrackInfo { if (extIndex == -1) { continue; } - o2::MCCompLabel lbl = event.getClusterLabels(iCluster, extIndex); + o2::MCCompLabel lbl = *(event.getClusterLabels(iCluster, extIndex).begin()); if (lbl == mainLabel && occurrences[0].second > 1 && !lbl.isNoise()) { // if we have MaxClusters fake clusters -> occurrences[0].second = 1 clusStatuses[iCluster] = 1; } else { diff --git a/Detectors/ITSMFT/ITS/tracking/include/ITStracking/TimeFrame.h b/Detectors/ITSMFT/ITS/tracking/include/ITStracking/TimeFrame.h index 40f723b895f0e..011d13acf410f 100644 --- a/Detectors/ITSMFT/ITS/tracking/include/ITStracking/TimeFrame.h +++ b/Detectors/ITSMFT/ITS/tracking/include/ITStracking/TimeFrame.h @@ -86,8 +86,8 @@ class TimeFrame final const std::vector& getTrackingFrameInfoOnLayer(int layerId) const; const TrackingFrameInfo& getClusterTrackingFrameInfo(int layerId, const Cluster& cl) const; - const MCCompLabel& getClusterLabels(int layerId, const Cluster& cl) const; - const MCCompLabel& getClusterLabels(int layerId, const int clId) const; + const gsl::span getClusterLabels(int layerId, const Cluster& cl) const; + const gsl::span getClusterLabels(int layerId, const int clId) const; int getClusterExternalIndex(int layerId, const int clId) const; std::vector& getTrackletsLabel(int layer) { return mTrackletLabels[layer]; } @@ -135,7 +135,6 @@ class TimeFrame final void addClusterToLayer(int layer, T&&... args); template void addTrackingFrameInfoToLayer(int layer, T&&... args); - void addClusterLabelToLayer(int layer, const MCCompLabel label); void addClusterExternalIndexToLayer(int layer, const int idx); int mNrof = 0; @@ -150,7 +149,7 @@ class TimeFrame final std::vector> mUnsortedClusters; std::vector> mUsedClusters; std::vector> mTrackingFrameInfo; - std::vector> mClusterLabels; + const dataformats::MCTruthContainer* mClusterLabels = nullptr; std::vector> mTrackletLabels; std::vector> mCellLabels; std::vector> mClusterExternalIndices; @@ -239,14 +238,14 @@ inline const TrackingFrameInfo& TimeFrame::getClusterTrackingFrameInfo(int layer return mTrackingFrameInfo[layerId][cl.clusterId]; } -inline const MCCompLabel& TimeFrame::getClusterLabels(int layerId, const Cluster& cl) const +inline const gsl::span TimeFrame::getClusterLabels(int layerId, const Cluster& cl) const { - return mClusterLabels[layerId][cl.clusterId]; + return getClusterLabels(layerId, cl.clusterId); } -inline const MCCompLabel& TimeFrame::getClusterLabels(int layerId, const int clId) const +inline const gsl::span TimeFrame::getClusterLabels(int layerId, int clId) const { - return mClusterLabels[layerId][clId]; + return mClusterLabels->getLabels(mClusterExternalIndices[layerId][clId]); } inline int TimeFrame::getClusterExternalIndex(int layerId, const int clId) const @@ -271,8 +270,6 @@ void TimeFrame::addTrackingFrameInfoToLayer(int layer, T&&... values) mTrackingFrameInfo[layer].emplace_back(std::forward(values)...); } -inline void TimeFrame::addClusterLabelToLayer(int layer, const MCCompLabel label) { mClusterLabels[layer].emplace_back(label); } - inline void TimeFrame::addClusterExternalIndexToLayer(int layer, const int idx) { mClusterExternalIndices[layer].push_back(idx); @@ -283,7 +280,7 @@ inline void TimeFrame::clear() for (unsigned int iL = 0; iL < mClusters.size(); ++iL) { mClusters[iL].clear(); mTrackingFrameInfo[iL].clear(); - mClusterLabels[iL].clear(); + mClusterLabels = nullptr; mClusterExternalIndices[iL].clear(); } mPrimaryVertices.clear(); @@ -291,12 +288,7 @@ inline void TimeFrame::clear() inline bool TimeFrame::hasMCinformation() const { - for (const auto& vect : mClusterLabels) { - if (!vect.empty()) { - return true; - } - } - return false; + return mClusterLabels; } inline bool TimeFrame::isClusterUsed(int layer, int clusterId) const diff --git a/Detectors/ITSMFT/ITS/tracking/src/IOUtils.cxx b/Detectors/ITSMFT/ITS/tracking/src/IOUtils.cxx index b03374b2c5ee4..ddd2ca8934115 100644 --- a/Detectors/ITSMFT/ITS/tracking/src/IOUtils.cxx +++ b/Detectors/ITSMFT/ITS/tracking/src/IOUtils.cxx @@ -78,56 +78,6 @@ void ioutils::convertCompactClusters(gsl::span clu } } -std::vector ioutils::loadEventData(const std::string& fileName) -{ - std::vector events{}; - std::ifstream inputStream{}; - std::string line{}, unusedVariable{}; - int layerId{}, monteCarlo{}; - int clusterId{EventLabelsSeparator}; - float xCoordinate{}, yCoordinate{}, zCoordinate{}, alphaAngle{}; - float varZ{-1.f}, varY{-1.f}; - - inputStream.open(fileName); - - /// THIS IS LEAKING IN THE BACKWARD COMPATIBLE MODE. KEEP IT IN MIND. - dataformats::MCTruthContainer* mcLabels = nullptr; - while (std::getline(inputStream, line)) { - - std::istringstream inputStringStream(line); - if (inputStringStream >> layerId >> xCoordinate >> yCoordinate >> zCoordinate) { - - if (layerId == PrimaryVertexLayerId) { - - if (clusterId != 0) { - events.emplace_back(events.size(), 7); - } - - events.back().addPrimaryVertex(xCoordinate, yCoordinate, zCoordinate); - clusterId = 0; - - } else { - - if (inputStringStream >> varY >> varZ >> unusedVariable >> alphaAngle >> monteCarlo) { - events.back().addClusterToLayer(layerId, xCoordinate, yCoordinate, zCoordinate, - events.back().getClustersOnLayer(layerId).size()); - const float sinAlpha = std::sin(alphaAngle); - const float cosAlpha = std::cos(alphaAngle); - const float xTF = xCoordinate * cosAlpha - yCoordinate * sinAlpha; - const float yTF = xCoordinate * sinAlpha + yCoordinate * cosAlpha; - events.back().addTrackingFrameInfoToLayer(layerId, xCoordinate, yCoordinate, zCoordinate, xTF, alphaAngle, - std::array{yTF, zCoordinate}, std::array{varY, 0.f, varZ}); - events.back().addClusterLabelToLayer(layerId, MCCompLabel(monteCarlo)); - - ++clusterId; - } - } - } - } - - return events; -} - void ioutils::loadEventData(ROframe& event, gsl::span clusters, gsl::span::iterator& pattIt, const itsmft::TopologyDictionary& dict, const dataformats::MCTruthContainer* clsLabels) @@ -173,7 +123,8 @@ void ioutils::loadEventData(ROframe& event, gsl::spangetLabels(clusterId).begin())); + // event.addClusterLabelToLayer(layer, *(clsLabels->getLabels(clusterId).begin())); + event.setMClabelsContainer(clsLabels); } event.addClusterExternalIndexToLayer(layer, clusterId); clusterId++; @@ -222,7 +173,8 @@ int ioutils::loadROFrameData(const o2::itsmft::ROFRecord& rof, ROframe& event, g /// Rotate to the global frame event.addClusterToLayer(layer, gloXYZ.x(), gloXYZ.y(), gloXYZ.z(), event.getClustersOnLayer(layer).size()); if (mcLabels) { - event.addClusterLabelToLayer(layer, *(mcLabels->getLabels(first + clusterId).begin())); + // event.addClusterLabelToLayer(layer, *(mcLabels->getLabels(first + clusterId).begin())); + event.setMClabelsContainer(mcLabels); } event.addClusterExternalIndexToLayer(layer, first + clusterId); clusterId++; @@ -230,34 +182,6 @@ int ioutils::loadROFrameData(const o2::itsmft::ROFRecord& rof, ROframe& event, g return clusters_in_frame.size(); } -// void ioutils::generateSimpleData(ROframe& event, const int phiDivs, const int zDivs = 1) -// { -// const float angleOffset = constants::math::TwoPi / static_cast(phiDivs); -// // Maximum z allowed on innermost layer should be: ~9,75 -// const float zOffsetFirstLayer = (zDivs == 1) ? 0 : 1.5 * (LayersZCoordinate()[6] * LayersRCoordinate()[0]) / (LayersRCoordinate()[6] * (static_cast(zDivs) - 1)); -// std::vector x, y; -// std::array, 7> z; -// for (size_t j{0}; j < zDivs; ++j) { -// for (size_t i{0}; i < phiDivs; ++i) { -// x.emplace_back(cos(i * angleOffset + 0.001)); // put an epsilon to move from periods (e.g. 20 clusters vs 20 cells) -// y.emplace_back(sin(i * angleOffset + 0.001)); -// const float zFirstLayer{-static_cast((zDivs - 1.) / 2.) * zOffsetFirstLayer + zOffsetFirstLayer * static_cast(j)}; -// z[0].emplace_back(zFirstLayer); -// for (size_t iLayer{1}; iLayer < 7; ++iLayer) { -// z[iLayer].emplace_back(zFirstLayer * LayersRCoordinate()[iLayer] / LayersRCoordinate()[0]); -// } -// } -// } - -// for (int iLayer{0}; iLayer < 7; ++iLayer) { -// for (int i = 0; i < phiDivs * zDivs; i++) { -// o2::MCCompLabel label{i, 0, 0, false}; -// event.addClusterLabelToLayer(iLayer, label); //last argument : label, goes into mClustersLabel -// event.addClusterToLayer(iLayer, LayersRCoordinate()[iLayer] * x[i], LayersRCoordinate()[iLayer] * y[i], z[iLayer][i], i); //uses 1st constructor for clusters -// } -// } -// } - std::vector> ioutils::loadLabels(const int eventsNum, const std::string& fileName) { std::vector> labelsMap{}; @@ -350,7 +274,5 @@ void ioutils::writeRoadsReport(std::ofstream& correctRoadsOutputStream, std::ofs } } - - } // namespace its } // namespace o2 diff --git a/Detectors/ITSMFT/ITS/tracking/src/ROframe.cxx b/Detectors/ITSMFT/ITS/tracking/src/ROframe.cxx index 19bfabadd605a..ee885db3c49ea 100644 --- a/Detectors/ITSMFT/ITS/tracking/src/ROframe.cxx +++ b/Detectors/ITSMFT/ITS/tracking/src/ROframe.cxx @@ -26,7 +26,7 @@ ROframe::ROframe(int ROframeId, int nLayers) : mROframeId{ROframeId} { mClusters.resize(nLayers); mTrackingFrameInfo.resize(nLayers); - mClusterLabels.resize(nLayers); + // mClusterLabels.resize(nLayers); mClusterExternalIndices.resize(nLayers); } diff --git a/Detectors/ITSMFT/ITS/tracking/src/StandaloneDebugger.cxx b/Detectors/ITSMFT/ITS/tracking/src/StandaloneDebugger.cxx index 662fc1a0f6ff4..84e80b02e07ce 100644 --- a/Detectors/ITSMFT/ITS/tracking/src/StandaloneDebugger.cxx +++ b/Detectors/ITSMFT/ITS/tracking/src/StandaloneDebugger.cxx @@ -41,8 +41,8 @@ StandaloneDebugger::~StandaloneDebugger() // Monte carlo oracle part int StandaloneDebugger::getEventId(int firstClusterId, int secondClusterId, ROframe* event) { - o2::MCCompLabel lblClus0 = event->getClusterLabels(0, firstClusterId); - o2::MCCompLabel lblClus1 = event->getClusterLabels(1, secondClusterId); + o2::MCCompLabel lblClus0 = *(event->getClusterLabels(0, firstClusterId).begin()); + o2::MCCompLabel lblClus1 = *(event->getClusterLabels(1, secondClusterId).begin()); return lblClus0.compare(lblClus1) == 1 ? lblClus0.getEventID() : -1; } @@ -55,8 +55,8 @@ void StandaloneDebugger::fillCombinatoricsTree(std::array, assert(mTreeStream != nullptr); for (auto& combination : comb01) { - o2::MCCompLabel lblClus0 = event->getClusterLabels(0, clusters[0][combination.firstClusterIndex].clusterId); - o2::MCCompLabel lblClus1 = event->getClusterLabels(1, clusters[1][combination.secondClusterIndex].clusterId); + o2::MCCompLabel lblClus0 = *(event->getClusterLabels(0, clusters[0][combination.firstClusterIndex].clusterId).begin()); + o2::MCCompLabel lblClus1 = *(event->getClusterLabels(1, clusters[1][combination.secondClusterIndex].clusterId).begin()); float c0z{clusters[0][combination.firstClusterIndex].zCoordinate}; float c1z{clusters[1][combination.secondClusterIndex].zCoordinate}; unsigned char isValidated{lblClus0.compare(lblClus1) == 1}; @@ -73,8 +73,8 @@ void StandaloneDebugger::fillCombinatoricsTree(std::array, } for (auto& combination : comb12) { - o2::MCCompLabel lblClus1 = event->getClusterLabels(1, clusters[1][combination.secondClusterIndex].clusterId); - o2::MCCompLabel lblClus2 = event->getClusterLabels(2, clusters[2][combination.secondClusterIndex].clusterId); + o2::MCCompLabel lblClus1 = *(event->getClusterLabels(1, clusters[1][combination.secondClusterIndex].clusterId).begin()); + o2::MCCompLabel lblClus2 = *(event->getClusterLabels(2, clusters[2][combination.secondClusterIndex].clusterId).begin()); float c1z{clusters[1][combination.firstClusterIndex].zCoordinate}; float c2z{clusters[2][combination.secondClusterIndex].zCoordinate}; unsigned char isValidated{lblClus1.compare(lblClus2) == 1}; @@ -101,9 +101,9 @@ void StandaloneDebugger::fillTrackletSelectionTree(std::arraygetROFrameId(); for (auto& trackletPair : allowedTracklets) { - o2::MCCompLabel lblClus0 = event->getClusterLabels(0, clusters[0][comb01[trackletPair[0]].firstClusterIndex].clusterId); - o2::MCCompLabel lblClus1 = event->getClusterLabels(1, clusters[1][comb01[trackletPair[0]].secondClusterIndex].clusterId); - o2::MCCompLabel lblClus2 = event->getClusterLabels(2, clusters[2][comb12[trackletPair[1]].secondClusterIndex].clusterId); + o2::MCCompLabel lblClus0 = *(event->getClusterLabels(0, clusters[0][comb01[trackletPair[0]].firstClusterIndex].clusterId).begin()); + o2::MCCompLabel lblClus1 = *(event->getClusterLabels(1, clusters[1][comb01[trackletPair[0]].secondClusterIndex].clusterId).begin()); + o2::MCCompLabel lblClus2 = *(event->getClusterLabels(2, clusters[2][comb12[trackletPair[1]].secondClusterIndex].clusterId).begin()); unsigned char isValidated{lblClus0.compare(lblClus1) == 1 && lblClus0.compare(lblClus2) == 1}; float deltaPhi{comb01[trackletPair[0]].phi - comb12[trackletPair[1]].phi}; float deltaTanLambda{comb01[trackletPair[0]].tanLambda - comb12[trackletPair[1]].tanLambda}; diff --git a/Detectors/ITSMFT/ITS/tracking/src/TimeFrame.cxx b/Detectors/ITSMFT/ITS/tracking/src/TimeFrame.cxx index 1afe7c2b020ee..a973a74866b96 100644 --- a/Detectors/ITSMFT/ITS/tracking/src/TimeFrame.cxx +++ b/Detectors/ITSMFT/ITS/tracking/src/TimeFrame.cxx @@ -50,7 +50,6 @@ TimeFrame::TimeFrame(int nLayers) mClusters.resize(nLayers); mUnsortedClusters.resize(nLayers); mTrackingFrameInfo.resize(nLayers); - mClusterLabels.resize(nLayers); mClusterExternalIndices.resize(nLayers); mUsedClusters.resize(nLayers); mROframesClusters.resize(nLayers, {0}); ///TBC: if resetting the timeframe is required, then this has to be done @@ -88,9 +87,6 @@ int TimeFrame::loadROFrameData(const o2::itsmft::ROFRecord& rof, gsl::spangetLabels(first + clusterId).begin())); - } addClusterExternalIndexToLayer(layer, first + clusterId); clusterId++; } @@ -98,6 +94,9 @@ int TimeFrame::loadROFrameData(const o2::itsmft::ROFRecord& rof, gsl::span rofs, gsl::span< /// Rotate to the global frame addClusterToLayer(layer, gloXYZ.x(), gloXYZ.y(), gloXYZ.z(), mUnsortedClusters[layer].size()); - if (mcLabels) { - addClusterLabelToLayer(layer, *(mcLabels->getLabels(clusterId).begin())); - } addClusterExternalIndexToLayer(layer, clusterId); if (clusterId == rofs[mNrof].getFirstEntry() + rofs[mNrof].getNEntries() - 1) { @@ -153,6 +149,9 @@ int TimeFrame::loadROFrameData(gsl::span rofs, gsl::span< mNrof++; } } + if (mcLabels) { + mClusterLabels = mcLabels; + } return mNrof; } diff --git a/Detectors/ITSMFT/ITS/tracking/src/Tracker.cxx b/Detectors/ITSMFT/ITS/tracking/src/Tracker.cxx index a45b16ccf9670..b50f61c9c3b05 100644 --- a/Detectors/ITSMFT/ITS/tracking/src/Tracker.cxx +++ b/Detectors/ITSMFT/ITS/tracking/src/Tracker.cxx @@ -306,7 +306,6 @@ void Tracker::findTracks() // temporaryTrack.setROFrame(rof); tracks.emplace_back(temporaryTrack); } - //mTraits->refitTracks(event.getTrackingFrameInfo(), tracks); std::sort(tracks.begin(), tracks.end(), [](TrackITSExt& track1, TrackITSExt& track2) { return track1.isBetter(track2, 1.e6f); }); @@ -432,9 +431,7 @@ void Tracker::computeRoadsMClabels() for (int iRoad{0}; iRoad < roadsNum; ++iRoad) { Road& currentRoad{mTimeFrame->getRoads()[iRoad]}; - MCCompLabel maxOccurrencesValue{constants::its::UnusedIndex, constants::its::UnusedIndex, - constants::its::UnusedIndex, false}; - int count{0}; + std::vector> occurrences; bool isFakeRoad{false}; bool isFirstRoadCell{true}; @@ -454,91 +451,135 @@ void Tracker::computeRoadsMClabels() if (isFirstRoadCell) { const int cl0index{mTimeFrame->getClusters()[iCell][currentCell.getFirstClusterIndex()].clusterId}; - auto& cl0labs{mTimeFrame->getClusterLabels(iCell, cl0index)}; - maxOccurrencesValue = cl0labs; - count = 1; + auto cl0labs{mTimeFrame->getClusterLabels(iCell, cl0index)}; + bool found{false}; + for (size_t iOcc{0}; iOcc < occurrences.size(); ++iOcc) { + std::pair& occurrence = occurrences[iOcc]; + for (auto& label : cl0labs) { + if (label == occurrence.first) { + ++occurrence.second; + found = true; + // break; // uncomment to stop to the first hit + } + } + } + if (!found) { + for (auto& label : cl0labs) { + occurrences.emplace_back(label, 1); + } + } const int cl1index{mTimeFrame->getClusters()[iCell + 1][currentCell.getSecondClusterIndex()].clusterId}; - auto& cl1labs{mTimeFrame->getClusterLabels(iCell + 1, cl1index)}; - const int secondMonteCarlo{cl1labs.getTrackID()}; - if (cl1labs == maxOccurrencesValue) { - ++count; - } else { - maxOccurrencesValue = cl1labs; - count = 1; - isFakeRoad = true; + const auto& cl1labs{mTimeFrame->getClusterLabels(iCell + 1, cl1index)}; + found = false; + for (size_t iOcc{0}; iOcc < occurrences.size(); ++iOcc) { + std::pair& occurrence = occurrences[iOcc]; + for (auto& label : cl1labs) { + if (label == occurrence.first) { + ++occurrence.second; + found = true; + // break; // uncomment to stop to the first hit + } + } + } + if (!found) { + for (auto& label : cl1labs) { + occurrences.emplace_back(label, 1); + } } isFirstRoadCell = false; } const int cl2index{mTimeFrame->getClusters()[iCell + 2][currentCell.getThirdClusterIndex()].clusterId}; - auto& cl2labs{mTimeFrame->getClusterLabels(iCell + 2, cl2index)}; - const int currentMonteCarlo = {cl2labs.getTrackID()}; - - if (cl2labs == maxOccurrencesValue) { - ++count; - } else { - --count; - isFakeRoad = true; + const auto& cl2labs{mTimeFrame->getClusterLabels(iCell + 2, cl2index)}; + bool found{false}; + for (size_t iOcc{0}; iOcc < occurrences.size(); ++iOcc) { + std::pair& occurrence = occurrences[iOcc]; + for (auto& label : cl2labs) { + if (label == occurrence.first) { + ++occurrence.second; + found = true; + // break; // uncomment to stop to the first hit + } + } } - - if (count == 0) { - maxOccurrencesValue = cl2labs; - count = 1; + if (!found) { + for (auto& label : cl2labs) { + occurrences.emplace_back(label, 1); + } } } + std::sort(occurrences.begin(), occurrences.end(), [](auto e1, auto e2) { + return e1.second > e2.second; + }); + + auto maxOccurrencesValue = occurrences[0].first; mTimeFrame->setRoadLabel(iRoad, maxOccurrencesValue.getRawValue(), isFakeRoad); } } void Tracker::computeTracksMClabels() { - /// Moore's Voting Algorithm if (!mTimeFrame->hasMCinformation()) { return; } for (int iROF{0}; iROF < mTimeFrame->getNrof(); ++iROF) { for (auto& track : mTimeFrame->getTracks(iROF)) { - MCCompLabel maxOccurrencesValue{constants::its::UnusedIndex, constants::its::UnusedIndex, - constants::its::UnusedIndex, false}; - int count{0}; + std::vector> occurrences; + occurrences.clear(); bool isFakeTrack{false}; + for (int iCluster = 0; iCluster < TrackITSExt::MaxClusters; ++iCluster) { const int index = track.getClusterIndex(iCluster); if (index == constants::its::UnusedIndex) { continue; } - const MCCompLabel& currentLabel = mTimeFrame->getClusterLabels(iCluster, index); - if (currentLabel == maxOccurrencesValue) { - ++count; - } else { - if (count != 0) { // only in the first iteration count can be 0 at this point - isFakeTrack = true; - --count; - } - - if (currentLabel == maxOccurrencesValue) { - ++count; - } else { - if (count != 0) { // only in the first iteration count can be 0 at this point - isFakeTrack = true; - --count; - } - if (count == 0) { - maxOccurrencesValue = currentLabel; - count = 1; + auto labels = mTimeFrame->getClusterLabels(iCluster, index); + bool found{false}; + for (size_t iOcc{0}; iOcc < occurrences.size(); ++iOcc) { + std::pair& occurrence = occurrences[iOcc]; + for (auto& label : labels) { + if (label == occurrence.first) { + ++occurrence.second; + found = true; + // break; // uncomment to stop to the first hit } } } - - if (isFakeTrack) { - maxOccurrencesValue.setFakeFlag(); + if (!found) { + for (auto& label : labels) { + occurrences.emplace_back(label, 1); + } } } + std::sort(std::begin(occurrences), std::end(occurrences), [](auto e1, auto e2) { + return e1.second > e2.second; + }); + + auto maxOccurrencesValue = occurrences[0].first; + uint32_t pattern = track.getPattern(); + // set fake clusters pattern + for (int ic{TrackITSExt::MaxClusters}; ic--;) { + auto clid = track.getClusterIndex(ic); + if (clid != constants::its::UnusedIndex) { + auto labelsSpan = mTimeFrame->getClusterLabels(ic, clid); + for (auto& currentLabel : labelsSpan) { + if (currentLabel == maxOccurrencesValue) { + pattern |= 0x1 << (16 + ic); // set bit if correct + break; + } + } + track.setExternalClusterIndex(ic, mTimeFrame->getClusterExternalIndex(ic, clid)); + } + } + track.setPattern(pattern); + if (occurrences[0].second < track.getNumberOfClusters()) { + maxOccurrencesValue.setFakeFlag(); + } mTimeFrame->getTracksLabel(iROF).emplace_back(maxOccurrencesValue); } } diff --git a/Detectors/ITSMFT/ITS/tracking/src/TrackerTraitsCPU.cxx b/Detectors/ITSMFT/ITS/tracking/src/TrackerTraitsCPU.cxx index cb8df35162e52..4e354d75e410c 100644 --- a/Detectors/ITSMFT/ITS/tracking/src/TrackerTraitsCPU.cxx +++ b/Detectors/ITSMFT/ITS/tracking/src/TrackerTraitsCPU.cxx @@ -177,11 +177,21 @@ void TrackerTraitsCPU::computeLayerTracklets() if (tf->hasMCinformation()) { for (int iLayer{0}; iLayer < mTrkParams.TrackletsPerRoad(); ++iLayer) { for (auto& trk : tf->getTracklets()[iLayer]) { + MCCompLabel label; int currentId{tf->getClusters()[iLayer][trk.firstClusterIndex].clusterId}; int nextId{tf->getClusters()[iLayer + 1][trk.secondClusterIndex].clusterId}; - MCCompLabel currentLab{tf->getClusterLabels(iLayer, currentId)}; - MCCompLabel nextLab{tf->getClusterLabels(iLayer + 1, nextId)}; - tf->getTrackletsLabel(iLayer).emplace_back(currentLab == nextLab ? currentLab : MCCompLabel()); + for (auto& lab1 : tf->getClusterLabels(iLayer, currentId)) { + for (auto& lab2 : tf->getClusterLabels(iLayer, nextId)) { + if (lab1 == lab2 && lab1.isValid()) { + label = lab1; + break; + } + } + if (label.isValid()) { + break; + } + } + tf->getTrackletsLabel(iLayer).emplace_back(label); } } } diff --git a/Detectors/ITSMFT/ITS/tracking/src/VertexerTraits.cxx b/Detectors/ITSMFT/ITS/tracking/src/VertexerTraits.cxx index 37db06873d17e..d21ea31585872 100644 --- a/Detectors/ITSMFT/ITS/tracking/src/VertexerTraits.cxx +++ b/Detectors/ITSMFT/ITS/tracking/src/VertexerTraits.cxx @@ -259,8 +259,8 @@ void VertexerTraits::computeTrackletsPureMontecarlo() auto& currentCluster{mClusters[0][iCurrentLayerClusterIndex]}; for (unsigned int iNextLayerClusterIndex = 0; iNextLayerClusterIndex < mClusters[1].size(); iNextLayerClusterIndex++) { const Cluster& nextCluster{mClusters[1][iNextLayerClusterIndex]}; - const auto& lblNext = mEvent->getClusterLabels(1, nextCluster.clusterId); - const auto& lblCurr = mEvent->getClusterLabels(0, currentCluster.clusterId); + const auto& lblNext = *(mEvent->getClusterLabels(1, nextCluster.clusterId).begin()); + const auto& lblCurr = *(mEvent->getClusterLabels(0, currentCluster.clusterId).begin()); if (lblNext.compare(lblCurr) == 1 && lblCurr.getSourceID() == 0) { mComb01.emplace_back(iCurrentLayerClusterIndex, iNextLayerClusterIndex, currentCluster, nextCluster); } @@ -271,8 +271,8 @@ void VertexerTraits::computeTrackletsPureMontecarlo() auto& currentCluster{mClusters[2][iCurrentLayerClusterIndex]}; for (unsigned int iNextLayerClusterIndex = 0; iNextLayerClusterIndex < mClusters[1].size(); iNextLayerClusterIndex++) { const Cluster& nextCluster{mClusters[1][iNextLayerClusterIndex]}; - const auto& lblNext = mEvent->getClusterLabels(1, nextCluster.clusterId); - const auto& lblCurr = mEvent->getClusterLabels(2, currentCluster.clusterId); + const auto& lblNext = *(mEvent->getClusterLabels(1, nextCluster.clusterId).begin()); + const auto& lblCurr = *(mEvent->getClusterLabels(2, currentCluster.clusterId).begin()); if (lblNext.compare(lblCurr) == 1 && lblCurr.getSourceID() == 0) { mComb12.emplace_back(iNextLayerClusterIndex, iCurrentLayerClusterIndex, nextCluster, currentCluster); } @@ -367,8 +367,8 @@ void VertexerTraits::computeMCFiltering() { assert(mEvent != nullptr); for (size_t iTracklet{0}; iTracklet < mComb01.size(); ++iTracklet) { - const auto& lbl0 = mEvent->getClusterLabels(0, mClusters[0][mComb01[iTracklet].firstClusterIndex].clusterId); - const auto& lbl1 = mEvent->getClusterLabels(1, mClusters[1][mComb01[iTracklet].secondClusterIndex].clusterId); + const auto& lbl0 = *(mEvent->getClusterLabels(0, mClusters[0][mComb01[iTracklet].firstClusterIndex].clusterId).begin()); + const auto& lbl1 = *(mEvent->getClusterLabels(1, mClusters[1][mComb01[iTracklet].secondClusterIndex].clusterId).begin()); if (!(lbl0.compare(lbl1) == 1 && lbl0.getSourceID() == 0)) { // evtId && trackId && isValid mComb01.erase(mComb01.begin() + iTracklet); --iTracklet; // vector size has been decreased @@ -376,8 +376,8 @@ void VertexerTraits::computeMCFiltering() } for (size_t iTracklet{0}; iTracklet < mComb12.size(); ++iTracklet) { - const auto& lbl1 = mEvent->getClusterLabels(1, mClusters[1][mComb12[iTracklet].firstClusterIndex].clusterId); - const auto& lbl2 = mEvent->getClusterLabels(2, mClusters[2][mComb12[iTracklet].secondClusterIndex].clusterId); + const auto& lbl1 = *(mEvent->getClusterLabels(1, mClusters[1][mComb12[iTracklet].firstClusterIndex].clusterId).begin()); + const auto& lbl2 = *(mEvent->getClusterLabels(2, mClusters[2][mComb12[iTracklet].secondClusterIndex].clusterId).begin()); if (!(lbl1.compare(lbl2) == 1 && lbl1.getSourceID() == 0)) { // evtId && trackId && isValid mComb12.erase(mComb12.begin() + iTracklet); --iTracklet; // vector size has been decreased @@ -694,8 +694,8 @@ void VertexerTraits::filterTrackletsWithMC(std::vector& tracklets01, int removed{0}; for (size_t iTrackletIndex{0}; iTrackletIndex < indices01[iFoundTrackletIndex]; ++iTrackletIndex) { const size_t iTracklet{offset + iTrackletIndex}; - const auto& lbl0 = mEvent->getClusterLabels(0, mClusters[0][tracklets01[iTracklet].firstClusterIndex].clusterId); - const auto& lbl1 = mEvent->getClusterLabels(1, mClusters[1][tracklets01[iTracklet].secondClusterIndex].clusterId); + const auto& lbl0 = *(mEvent->getClusterLabels(0, mClusters[0][tracklets01[iTracklet].firstClusterIndex].clusterId).begin()); + const auto& lbl1 = *(mEvent->getClusterLabels(1, mClusters[1][tracklets01[iTracklet].secondClusterIndex].clusterId).begin()); if (!(lbl0.compare(lbl1) == 1 && lbl0.getSourceID() == 0)) { tracklets01[iTracklet] = Tracklet(); ++removed; @@ -712,8 +712,8 @@ void VertexerTraits::filterTrackletsWithMC(std::vector& tracklets01, int removed{0}; for (size_t iTrackletIndex{0}; iTrackletIndex < indices12[iFoundTrackletIndex]; ++iTrackletIndex) { const size_t iTracklet{offset + iTrackletIndex}; - const auto& lbl1 = mEvent->getClusterLabels(1, mClusters[1][tracklets12[iTracklet].firstClusterIndex].clusterId); - const auto& lbl2 = mEvent->getClusterLabels(2, mClusters[2][tracklets12[iTracklet].secondClusterIndex].clusterId); + const auto& lbl1 = *(mEvent->getClusterLabels(1, mClusters[1][tracklets12[iTracklet].firstClusterIndex].clusterId).begin()); + const auto& lbl2 = *(mEvent->getClusterLabels(2, mClusters[2][tracklets12[iTracklet].secondClusterIndex].clusterId).begin()); if (!(lbl1.compare(lbl2) == 1 && lbl1.getSourceID() == 0)) { tracklets12[iTracklet] = Tracklet(); ++removed; diff --git a/Detectors/Upgrades/ALICE3/TRK/macros/ALICE3toAO2D.C b/Detectors/Upgrades/ALICE3/TRK/macros/ALICE3toAO2D.C index 971682b5f65b4..eaf4840d1da5e 100644 --- a/Detectors/Upgrades/ALICE3/TRK/macros/ALICE3toAO2D.C +++ b/Detectors/Upgrades/ALICE3/TRK/macros/ALICE3toAO2D.C @@ -430,7 +430,7 @@ void ALICE3toAO2D() event.addTrackingFrameInfoToLayer(layer, xyz[0], xyz[1], xyz[2], r, phi, std::array{0.f, xyz[2]}, std::array{0.0005f * 0.0005f, 0.f, 0.0005f * 0.0005f}); event.addClusterToLayer(layer, xyz[0], xyz[1], xyz[2], event.getClustersOnLayer(layer).size()); - event.addClusterLabelToLayer(layer, o2::MCCompLabel(hit.GetTrackID(), iEvent, iEvent, false)); + // event.addClusterLabelToLayer(layer, o2::MCCompLabel(hit.GetTrackID(), iEvent, iEvent, false)); event.addClusterExternalIndexToLayer(layer, id++); } roFrame = iEvent;