From 20b4767a15185671dd1281cbb546b9d5de13ef24 Mon Sep 17 00:00:00 2001 From: Kenneth Long Date: Wed, 30 Sep 2020 11:35:07 +0200 Subject: [PATCH] Match clusters/tracks in a common bin by pt Update misleading comment --- .../GraphReco/plugins/HGCClusterTrackLinker.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/RecoHGCal/GraphReco/plugins/HGCClusterTrackLinker.cc b/RecoHGCal/GraphReco/plugins/HGCClusterTrackLinker.cc index 6dd55a5a82650..525ca57965cd9 100644 --- a/RecoHGCal/GraphReco/plugins/HGCClusterTrackLinker.cc +++ b/RecoHGCal/GraphReco/plugins/HGCClusterTrackLinker.cc @@ -78,9 +78,16 @@ void HGCClusterTrackLinker::produce(edm::Event& iEvent, const edm::EventSetup& i for (auto& cand : *out) { if (trackIndices.size()) { - // Find best match (just set to the first one for now) - // Can do closest in pt or mix of closest in pt and eta/phi - int tidx = 0; + // Find best match. Current just closest in pt, can do + // a smarter mix of closest in pt and eta/phi or something else + std::vector ptdiffs; + ptdiffs.reserve(trackIndices.size()); + for (size_t entry : trackIndices) { + edm::RefToBase t(tracks, entry); + ptdiffs.push_back(std::abs(t->pt()-cand.pt())); + } + + size_t tidx = std::distance(ptdiffs.begin(), std::min_element(ptdiffs.begin(), ptdiffs.end())); edm::RefToBase matchingTrack(tracks, trackIndices.at(tidx)); trackIndices.erase(trackIndices.begin()+tidx);