From 35a6acc8f8061b3f558dbbb42f79d4b621d7436c Mon Sep 17 00:00:00 2001 From: Matteo Concas Date: Tue, 15 Jun 2021 15:50:26 +0200 Subject: [PATCH 1/4] Use MCTruthContainer --- .../tracking/include/ITStracking/ROframe.h | 51 ++++++--- .../include/ITStracking/StandaloneDebugger.h | 4 +- Detectors/ITSMFT/ITS/tracking/src/IOUtils.cxx | 104 +++++++++--------- Detectors/ITSMFT/ITS/tracking/src/ROframe.cxx | 2 +- .../ITS/tracking/src/StandaloneDebugger.cxx | 18 +-- Detectors/ITSMFT/ITS/tracking/src/Tracker.cxx | 46 ++++---- .../ITS/tracking/src/VertexerTraits.cxx | 24 ++-- 7 files changed, 134 insertions(+), 115 deletions(-) diff --git a/Detectors/ITSMFT/ITS/tracking/include/ITStracking/ROframe.h b/Detectors/ITSMFT/ITS/tracking/include/ITStracking/ROframe.h index 45ba3e4498ce3..ace5c23d72f2b 100644 --- a/Detectors/ITSMFT/ITS/tracking/include/ITStracking/ROframe.h +++ b/Detectors/ITSMFT/ITS/tracking/include/ITStracking/ROframe.h @@ -55,8 +55,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); @@ -64,7 +66,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; @@ -72,10 +74,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; }; @@ -102,14 +104,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 @@ -121,7 +133,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; } @@ -138,7 +150,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) { @@ -150,20 +165,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 6ad62f9247a06..2e9c42bda283d 100644 --- a/Detectors/ITSMFT/ITS/tracking/include/ITStracking/StandaloneDebugger.h +++ b/Detectors/ITSMFT/ITS/tracking/include/ITStracking/StandaloneDebugger.h @@ -59,7 +59,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) { @@ -95,7 +95,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/src/IOUtils.cxx b/Detectors/ITSMFT/ITS/tracking/src/IOUtils.cxx index e21d75cf2adb2..9da4dfcc64320 100644 --- a/Detectors/ITSMFT/ITS/tracking/src/IOUtils.cxx +++ b/Detectors/ITSMFT/ITS/tracking/src/IOUtils.cxx @@ -77,55 +77,55 @@ 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; - } - } - } - } +// 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; -} +// return events; +// } void ioutils::loadEventData(ROframe& event, gsl::span clusters, gsl::span::iterator& pattIt, const itsmft::TopologyDictionary& dict, @@ -172,7 +172,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++; @@ -221,7 +222,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++; @@ -349,7 +351,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 76ba90171c3cf..bea3fb7cd1d99 100644 --- a/Detectors/ITSMFT/ITS/tracking/src/ROframe.cxx +++ b/Detectors/ITSMFT/ITS/tracking/src/ROframe.cxx @@ -25,7 +25,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 32625e1ed643d..3d5beb6efc47a 100644 --- a/Detectors/ITSMFT/ITS/tracking/src/StandaloneDebugger.cxx +++ b/Detectors/ITSMFT/ITS/tracking/src/StandaloneDebugger.cxx @@ -40,8 +40,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; } @@ -54,8 +54,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}; @@ -72,8 +72,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}; @@ -100,9 +100,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]].phiCoordinate - comb12[trackletPair[1]].phiCoordinate}; float deltaTanLambda{comb01[trackletPair[0]].tanLambda - comb12[trackletPair[1]].tanLambda}; diff --git a/Detectors/ITSMFT/ITS/tracking/src/Tracker.cxx b/Detectors/ITSMFT/ITS/tracking/src/Tracker.cxx index 367e2163472be..97dddab6ce706 100644 --- a/Detectors/ITSMFT/ITS/tracking/src/Tracker.cxx +++ b/Detectors/ITSMFT/ITS/tracking/src/Tracker.cxx @@ -511,12 +511,12 @@ void Tracker::computeRoadsMClabels(const ROframe& event) if (isFirstRoadCell) { const int cl0index{mPrimaryVertexContext->getClusters()[iCell][currentCell.getFirstClusterIndex()].clusterId}; - auto& cl0labs{event.getClusterLabels(iCell, cl0index)}; + auto& cl0labs{*(event.getClusterLabels(iCell, cl0index).begin())}; maxOccurrencesValue = cl0labs; count = 1; const int cl1index{mPrimaryVertexContext->getClusters()[iCell + 1][currentCell.getSecondClusterIndex()].clusterId}; - const auto& cl1labs{event.getClusterLabels(iCell + 1, cl1index)}; + const auto& cl1labs{*(event.getClusterLabels(iCell + 1, cl1index).begin())}; if (cl1labs == maxOccurrencesValue) { ++count; @@ -530,7 +530,7 @@ void Tracker::computeRoadsMClabels(const ROframe& event) } const int cl2index{mPrimaryVertexContext->getClusters()[iCell + 2][currentCell.getThirdClusterIndex()].clusterId}; - const auto& cl2labs{event.getClusterLabels(iCell + 2, cl2index)}; + const auto& cl2labs{*(event.getClusterLabels(iCell + 2, cl2index).begin())}; if (cl2labs == maxOccurrencesValue) { ++count; @@ -551,18 +551,13 @@ void Tracker::computeRoadsMClabels(const ROframe& event) void Tracker::computeTracksMClabels(const ROframe& event) { - /// Moore's Voting Algorithm if (!event.hasMCinformation()) { return; } - int tracksNum{static_cast(mTracks.size())}; - for (auto& track : mTracks) { - - 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) { @@ -570,23 +565,30 @@ void Tracker::computeTracksMClabels(const ROframe& event) if (index == constants::its::UnusedIndex) { continue; } - const MCCompLabel& currentLabel = event.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; + auto labels = event.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; + } } - if (count == 0) { - maxOccurrencesValue = currentLabel; - count = 1; + } + if (!found) { + for (auto& label : labels) { + occurrences.emplace_back(label, 1); } } track.setExternalClusterIndex(iCluster, event.getClusterExternalIndex(iCluster, index)); } - - if (isFakeTrack) { + std::sort(std::begin(occurrences), std::end(occurrences), [](auto e1, auto e2) { + return e1.second > e2.second; + }); + auto maxOccurrencesValue = occurrences[0].first; + if (occurrences[0].second < track.getNumberOfClusters()) { maxOccurrencesValue.setFakeFlag(); } mTrackLabels.emplace_back(maxOccurrencesValue); diff --git a/Detectors/ITSMFT/ITS/tracking/src/VertexerTraits.cxx b/Detectors/ITSMFT/ITS/tracking/src/VertexerTraits.cxx index 5e4b1ad94157e..2ed3bed7049a6 100644 --- a/Detectors/ITSMFT/ITS/tracking/src/VertexerTraits.cxx +++ b/Detectors/ITSMFT/ITS/tracking/src/VertexerTraits.cxx @@ -258,8 +258,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); } @@ -270,8 +270,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); } @@ -366,8 +366,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 @@ -375,8 +375,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 @@ -693,8 +693,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; @@ -711,8 +711,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; From 7d56193b132d18dc54f6eae546b63ee36b6e085c Mon Sep 17 00:00:00 2001 From: Matteo Concas Date: Thu, 17 Jun 2021 11:51:00 +0200 Subject: [PATCH 2/4] Set track patterns for clusters and MC --- .../ITS/include/DataFormatsITS/TrackITS.h | 24 +++++++++++++++---- Detectors/ITSMFT/ITS/tracking/src/Tracker.cxx | 18 +++++++++++++- .../ITSMFT/ITS/workflow/src/TrackerSpec.cxx | 4 +--- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/DataFormats/Detectors/ITSMFT/ITS/include/DataFormatsITS/TrackITS.h b/DataFormats/Detectors/ITSMFT/ITS/include/DataFormatsITS/TrackITS.h index a2b774d75071e..a574c1a9edb1a 100644 --- a/DataFormats/Detectors/ITSMFT/ITS/include/DataFormatsITS/TrackITS.h +++ b/DataFormats/Detectors/ITSMFT/ITS/include/DataFormatsITS/TrackITS.h @@ -88,17 +88,18 @@ 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))); } private: 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 @@ -106,7 +107,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 TrackITSExt(o2::track::TrackParCov&& parCov, short ncl, float chi2, o2::track::TrackParCov&& outer, std::array cls) @@ -115,6 +116,13 @@ class TrackITSExt : public TrackITS setNumberOfClusters(ncl); } + 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(); @@ -128,10 +136,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/src/Tracker.cxx b/Detectors/ITSMFT/ITS/tracking/src/Tracker.cxx index 97dddab6ce706..cd91c4b192c5a 100644 --- a/Detectors/ITSMFT/ITS/tracking/src/Tracker.cxx +++ b/Detectors/ITSMFT/ITS/tracking/src/Tracker.cxx @@ -582,12 +582,28 @@ void Tracker::computeTracksMClabels(const ROframe& event) occurrences.emplace_back(label, 1); } } - track.setExternalClusterIndex(iCluster, event.getClusterExternalIndex(iCluster, index)); } 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 = event.getClusterLabels(ic, clid); + for (auto& currentLabel : labelsSpan) { + if (currentLabel == maxOccurrencesValue) { + pattern |= 0x1 << (16 + ic); // set bit if correct + break; + } + } + track.setExternalClusterIndex(ic, event.getClusterExternalIndex(ic, clid)); + } + } + track.setPattern(pattern); if (occurrences[0].second < track.getNumberOfClusters()) { maxOccurrencesValue.setFakeFlag(); } diff --git a/Detectors/ITSMFT/ITS/workflow/src/TrackerSpec.cxx b/Detectors/ITSMFT/ITS/workflow/src/TrackerSpec.cxx index 82045bfa67664..d5a151720a050 100644 --- a/Detectors/ITSMFT/ITS/workflow/src/TrackerSpec.cxx +++ b/Detectors/ITSMFT/ITS/workflow/src/TrackerSpec.cxx @@ -197,17 +197,15 @@ void TrackerDPL::run(ProcessingContext& pc) for (auto& trc : tracks) { trc.setFirstClusterEntry(allClusIdx.size()); // before adding tracks, create final cluster indices int ncl = trc.getNumberOfClusters(), nclf = 0; - uint8_t patt = 0; for (int ic = TrackITSExt::MaxClusters; ic--;) { // track internally keeps in->out cluster indices, but we want to store the references as out->in!!! auto clid = trc.getClusterIndex(ic); if (clid >= 0) { allClusIdx.push_back(clid + offset); nclf++; - patt |= 0x1 << ic; } } assert(ncl == nclf); - trc.setPattern(patt); + LOG(WARN) << trc.getPattern(); allTracks.emplace_back(trc); } }; From df173a1dfcbb86022b2f1a5ae582e10192b65f19 Mon Sep 17 00:00:00 2001 From: Matteo Concas Date: Thu, 17 Jun 2021 12:46:18 +0200 Subject: [PATCH 3/4] Update computeRoadsMClabels() to label span logic --- Detectors/ITSMFT/ITS/tracking/src/Tracker.cxx | 82 +++++++++++++------ 1 file changed, 56 insertions(+), 26 deletions(-) diff --git a/Detectors/ITSMFT/ITS/tracking/src/Tracker.cxx b/Detectors/ITSMFT/ITS/tracking/src/Tracker.cxx index cd91c4b192c5a..d85fd6835900a 100644 --- a/Detectors/ITSMFT/ITS/tracking/src/Tracker.cxx +++ b/Detectors/ITSMFT/ITS/tracking/src/Tracker.cxx @@ -477,7 +477,6 @@ void Tracker::traverseCellsTree(const int currentCellId, const int currentLayerI void Tracker::computeRoadsMClabels(const ROframe& event) { - /// Moore's Voting Algorithm if (!event.hasMCinformation()) { return; } @@ -489,9 +488,8 @@ void Tracker::computeRoadsMClabels(const ROframe& event) for (int iRoad{0}; iRoad < roadsNum; ++iRoad) { Road& currentRoad{mPrimaryVertexContext->getRoads()[iRoad]}; - MCCompLabel maxOccurrencesValue{constants::its::UnusedIndex, constants::its::UnusedIndex, - constants::its::UnusedIndex, false}; - int count{0}; + std::vector> occurrences; + occurrences.clear(); bool isFakeRoad{false}; bool isFirstRoadCell{true}; @@ -511,40 +509,72 @@ void Tracker::computeRoadsMClabels(const ROframe& event) if (isFirstRoadCell) { const int cl0index{mPrimaryVertexContext->getClusters()[iCell][currentCell.getFirstClusterIndex()].clusterId}; - auto& cl0labs{*(event.getClusterLabels(iCell, cl0index).begin())}; - maxOccurrencesValue = cl0labs; - count = 1; + auto cl0labs{event.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{mPrimaryVertexContext->getClusters()[iCell + 1][currentCell.getSecondClusterIndex()].clusterId}; - const auto& cl1labs{*(event.getClusterLabels(iCell + 1, cl1index).begin())}; - if (cl1labs == maxOccurrencesValue) { - ++count; - } else { - maxOccurrencesValue = cl1labs; - count = 1; - isFakeRoad = true; + const auto& cl1labs{event.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{mPrimaryVertexContext->getClusters()[iCell + 2][currentCell.getThirdClusterIndex()].clusterId}; - const auto& cl2labs{*(event.getClusterLabels(iCell + 2, cl2index).begin())}; - - if (cl2labs == maxOccurrencesValue) { - ++count; - } else { - --count; - isFakeRoad = true; + const auto& cl2labs{event.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(std::begin(occurrences), std::end(occurrences), [](auto e1, auto e2) { + return e1.second > e2.second; + }); + + auto maxOccurrencesValue = occurrences[0].first; mPrimaryVertexContext->setRoadLabel(iRoad, maxOccurrencesValue.getRawValue(), isFakeRoad); } } @@ -573,7 +603,7 @@ void Tracker::computeTracksMClabels(const ROframe& event) if (label == occurrence.first) { ++occurrence.second; found = true; - break; + // break; // uncomment to stop to the first hit } } } From 8c85252f8ce202a35c455f5cc9ff8edcbdc62246 Mon Sep 17 00:00:00 2001 From: Matteo Concas Date: Wed, 30 Jun 2021 14:02:47 +0200 Subject: [PATCH 4/4] Fix alice3 macros check --- Detectors/Upgrades/ALICE3/TRK/macros/ALICE3toAO2D.C | 2 +- macro/run_trac_alice3.C | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Detectors/Upgrades/ALICE3/TRK/macros/ALICE3toAO2D.C b/Detectors/Upgrades/ALICE3/TRK/macros/ALICE3toAO2D.C index f7ebbe8dc9129..6aeb6d92336d0 100644 --- a/Detectors/Upgrades/ALICE3/TRK/macros/ALICE3toAO2D.C +++ b/Detectors/Upgrades/ALICE3/TRK/macros/ALICE3toAO2D.C @@ -428,7 +428,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; diff --git a/macro/run_trac_alice3.C b/macro/run_trac_alice3.C index 8fe3f7af9da37..9ae460030ea2a 100644 --- a/macro/run_trac_alice3.C +++ b/macro/run_trac_alice3.C @@ -175,7 +175,7 @@ void run_trac_alice3(const string hitsFileName = "o2sim_HitsTRK.root") 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++); if (mapPDG.find(hit.GetTrackID()) == mapPDG.end()) { mapPDG[hit.GetTrackID()] = particle();