From e17c0f956ef70552034655a07c35ae16ce028c81 Mon Sep 17 00:00:00 2001 From: Bardh Quni <107641136+qunib@users.noreply.github.com> Date: Mon, 27 Oct 2025 19:29:34 -0500 Subject: [PATCH 1/2] Update MatchClusters.cc Previously, some photons that overlapped with charged tracks were being incorrectly discarded, leading to reduced reconstruction efficiency. This change adjusts the matching logic to retain valid photons without affecting charged particle suppression. --- src/algorithms/reco/MatchClusters.cc | 45 +++++++++++++++++++--------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/src/algorithms/reco/MatchClusters.cc b/src/algorithms/reco/MatchClusters.cc index 20960e08bd..0c4a47c943 100644 --- a/src/algorithms/reco/MatchClusters.cc +++ b/src/algorithms/reco/MatchClusters.cc @@ -124,38 +124,55 @@ std::map MatchClusters::indexedClusters( const edm4eic::ClusterCollection* clusters, const edm4eic::MCRecoClusterParticleAssociationCollection* associations) const { - std::map matched = {}; + // temporary map: mcID -> (cluster, weight) so we can choose the cluster with highest weight per mcID + std::map> bestForMc; + // loop over clusters for (const auto cluster : *clusters) { - int mcID = -1; + int bestMcID = -1; + float bestWeight = -1.f; - // find associated particle + // find best associated MC particle for this cluster (largest association weight) for (const auto assoc : *associations) { if (assoc.getRec() == cluster) { - mcID = assoc.getSim().getObjectID().index; - break; + const int candMcID = assoc.getSim().getObjectID().index; + const float w = assoc.getWeight(); + if (w > bestWeight) { + bestWeight = w; + bestMcID = candMcID; + } } } - trace(" --> Found cluster with mcID {} and energy {}", mcID, cluster.getEnergy()); + trace(" --> Found cluster with best mcID {} weight {} and energy {}", bestMcID, bestWeight, + cluster.getEnergy()); - if (mcID < 0) { + if (bestMcID < 0) { trace(" --> WARNING: no valid MC truth link found, skipping cluster..."); continue; } - const bool duplicate = matched.contains(mcID); - if (duplicate) { - trace(" --> WARNING: this is a duplicate mcID, keeping the higher energy cluster"); - - if (cluster.getEnergy() < matched[mcID].getEnergy()) { - continue; + // For this mcID, keep the cluster with the highest association weight (tie-break by energy). + auto it = bestForMc.find(bestMcID); + if (it == bestForMc.end()) { + bestForMc.emplace(bestMcID, std::make_pair(cluster, bestWeight)); + } else { + const float existingWeight = it->second.second; + if (bestWeight > existingWeight || + (bestWeight == existingWeight && cluster.getEnergy() > it->second.first.getEnergy())) { + it->second = std::make_pair(cluster, bestWeight); } } - matched[mcID] = cluster; } + + // Convert to the old API: map + std::map matched; + for (const auto& kv : bestForMc) { + matched.emplace(kv.first, kv.second.first); + } + return matched; } From 83fd77a40db12f35e204156055f556edc03cad70 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 28 Oct 2025 00:40:57 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/algorithms/reco/MatchClusters.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/algorithms/reco/MatchClusters.cc b/src/algorithms/reco/MatchClusters.cc index 0c4a47c943..5756051228 100644 --- a/src/algorithms/reco/MatchClusters.cc +++ b/src/algorithms/reco/MatchClusters.cc @@ -126,22 +126,21 @@ std::map MatchClusters::indexedClusters( // temporary map: mcID -> (cluster, weight) so we can choose the cluster with highest weight per mcID std::map> bestForMc; - // loop over clusters for (const auto cluster : *clusters) { - int bestMcID = -1; + int bestMcID = -1; float bestWeight = -1.f; // find best associated MC particle for this cluster (largest association weight) for (const auto assoc : *associations) { if (assoc.getRec() == cluster) { const int candMcID = assoc.getSim().getObjectID().index; - const float w = assoc.getWeight(); + const float w = assoc.getWeight(); if (w > bestWeight) { bestWeight = w; - bestMcID = candMcID; + bestMcID = candMcID; } } }