Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 27 additions & 20 deletions Detectors/GLOQC/src/MatchITSTPCQC.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
// or submit itself to any jurisdiction.

#include <algorithm>
#include <map>
#include <unordered_map>

#include "GLOQC/MatchITSTPCQC.h"
#include "ReconstructionDataFormats/TrackTPCITS.h"
Expand Down Expand Up @@ -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::pair<int, int>, std::unordered_map<int, bool>> 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<o2::MCTrack>& pcontainer = mcReader.getTracks(source, event);
for (auto& [trackID, flag] : flags) {
flag = static_cast<size_t>(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) {
Expand All @@ -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<o2::MCTrack>& 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}});
Expand All @@ -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<o2::MCTrack>& 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}});
Expand Down Expand Up @@ -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<o2::MCTrack>& 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}});
Expand Down Expand Up @@ -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<o2::MCTrack>& 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}});
Expand Down
4 changes: 4 additions & 0 deletions Steer/include/Steer/MCKinematicsReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions Steer/src/MCKinematicsReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading