diff --git a/Detectors/GLOQC/src/MatchITSTPCQC.cxx b/Detectors/GLOQC/src/MatchITSTPCQC.cxx index e1832056f072c..724ba2c3da01e 100644 --- a/Detectors/GLOQC/src/MatchITSTPCQC.cxx +++ b/Detectors/GLOQC/src/MatchITSTPCQC.cxx @@ -10,6 +10,8 @@ // or submit itself to any jurisdiction. #include +#include +#include #include "GLOQC/MatchITSTPCQC.h" #include "ReconstructionDataFormats/TrackTPCITS.h" @@ -563,6 +565,27 @@ void MatchITSTPCQC::run(o2::framework::ProcessingContext& ctx) } } + // physical-primary flag of all labelled tracks, per (source, event); the kinematics are read and released one event at a time + std::map, std::unordered_map> physPrimary; + auto isPhysPrimary = [&physPrimary](const o2::MCCompLabel& lbl) { return physPrimary.at({lbl.getSourceID(), lbl.getEventID()}).at(lbl.getTrackID()); }; + if (mUseMC) { + for (auto const& labels : {mRecoCont.getTPCITSTracksMCLabels(), mRecoCont.getTPCTracksMCLabels(), mRecoCont.getITSTracksMCLabels()}) { + for (auto const& lbl : labels) { + if (lbl.isValid()) { + physPrimary[{lbl.getSourceID(), lbl.getEventID()}][lbl.getTrackID()] = false; + } + } + } + for (auto& [sourceAndEvent, flags] : physPrimary) { + const auto [source, event] = sourceAndEvent; + const std::vector& pcontainer = mcReader.getTracks(source, event); + for (auto& [trackID, flag] : flags) { + flag = static_cast(trackID) < pcontainer.size() && MCTrackNavigator::isPhysicalPrimary(pcontainer[trackID], pcontainer); + } + mcReader.releaseTracksForSourceAndEvent(source, event); + } + } + // numerator + eta, chi2... if (mUseMC) { for (int i = 0; i < matchType::SIZE; ++i) { @@ -580,11 +603,7 @@ void MatchITSTPCQC::run(o2::framework::ProcessingContext& ctx) continue; } if (mMapLabels[matchType::TPC].find(lbl) == mMapLabels[matchType::TPC].end()) { - int source = lbl.getSourceID(); - int event = lbl.getEventID(); - const std::vector& pcontainer = mcReader.getTracks(source, event); - const o2::MCTrack& p = pcontainer[lbl.getTrackID()]; - if (MCTrackNavigator::isPhysicalPrimary(p, pcontainer)) { + if (isPhysPrimary(lbl)) { mMapLabels[matchType::TPC].insert({lbl, {.mIdx = itrk, .mIsPhysicalPrimary = true}}); } else { mMapLabels[matchType::TPC].insert({lbl, {.mIdx = itrk, .mIsPhysicalPrimary = false}}); @@ -603,11 +622,7 @@ void MatchITSTPCQC::run(o2::framework::ProcessingContext& ctx) continue; } if (mMapLabels[matchType::ITS].find(lbl) == mMapLabels[matchType::ITS].end()) { - int source = lbl.getSourceID(); - int event = lbl.getEventID(); - const std::vector& pcontainer = mcReader.getTracks(source, event); - const o2::MCTrack& p = pcontainer[lbl.getTrackID()]; - if (MCTrackNavigator::isPhysicalPrimary(p, pcontainer)) { + if (isPhysPrimary(lbl)) { mMapLabels[matchType::ITS].insert({lbl, {.mIdx = itrk, .mIsPhysicalPrimary = true}}); } else { mMapLabels[matchType::ITS].insert({lbl, {.mIdx = itrk, .mIsPhysicalPrimary = false}}); @@ -828,11 +843,7 @@ void MatchITSTPCQC::run(o2::framework::ProcessingContext& ctx) continue; } if (mMapRefLabels[matchType::TPC].find(lbl) == mMapRefLabels[matchType::TPC].end()) { - int source = lbl.getSourceID(); - int event = lbl.getEventID(); - const std::vector& pcontainer = mcReader.getTracks(source, event); - const o2::MCTrack& p = pcontainer[lbl.getTrackID()]; - if (MCTrackNavigator::isPhysicalPrimary(p, pcontainer)) { + if (isPhysPrimary(lbl)) { mMapRefLabels[matchType::TPC].insert({lbl, {itrk, true}}); } else { mMapRefLabels[matchType::TPC].insert({lbl, {itrk, false}}); @@ -860,11 +871,7 @@ void MatchITSTPCQC::run(o2::framework::ProcessingContext& ctx) continue; } if (mMapRefLabels[matchType::ITS].find(lbl) == mMapRefLabels[matchType::ITS].end()) { - int source = lbl.getSourceID(); - int event = lbl.getEventID(); - const std::vector& pcontainer = mcReader.getTracks(source, event); - const o2::MCTrack& p = pcontainer[lbl.getTrackID()]; - if (MCTrackNavigator::isPhysicalPrimary(p, pcontainer)) { + if (isPhysPrimary(lbl)) { mMapRefLabels[matchType::ITS].insert({lbl, {itrk, true}}); } else { mMapRefLabels[matchType::ITS].insert({lbl, {itrk, false}}); diff --git a/Steer/include/Steer/MCKinematicsReader.h b/Steer/include/Steer/MCKinematicsReader.h index 793711c61de87..e94111688da57 100644 --- a/Steer/include/Steer/MCKinematicsReader.h +++ b/Steer/include/Steer/MCKinematicsReader.h @@ -42,6 +42,10 @@ class MCKinematicsReader /// destructor ~MCKinematicsReader(); + /// the reader owns cached track vectors, so it must not be copied + MCKinematicsReader(const MCKinematicsReader&) = delete; + MCKinematicsReader& operator=(const MCKinematicsReader&) = delete; + /// constructor taking a name and mode (either kDigiContext or kMCKine) /// In case of "context", the name is the filename of the digitization context. /// In case of MCKine mode, the name is the "prefix" referencing a single simulation production. diff --git a/Steer/src/MCKinematicsReader.cxx b/Steer/src/MCKinematicsReader.cxx index 42cd40c90c1ae..d7d273f5ee831 100644 --- a/Steer/src/MCKinematicsReader.cxx +++ b/Steer/src/MCKinematicsReader.cxx @@ -43,6 +43,13 @@ void MCKinematicsReader::ensureTracksForSourceAndEvent(int source, int event) co MCKinematicsReader::~MCKinematicsReader() { + for (auto& perSource : mTracks) { + for (auto tracks : perSource) { + delete tracks; + } + } + mTracks.clear(); + for (auto chain : mInputChains) { delete chain; }