From 6aad101c7c82bcb7be629eabf293afd8110f38b7 Mon Sep 17 00:00:00 2001 From: Matteo Rama Date: Fri, 5 Dec 2025 09:37:13 +0100 Subject: [PATCH] Added protection against null MCParticle pointer, plus fix another issue --- Calo/CaloAssociators/src/CaloDigitLinker.cpp | 32 +++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/Calo/CaloAssociators/src/CaloDigitLinker.cpp b/Calo/CaloAssociators/src/CaloDigitLinker.cpp index dc27dc1ac..f8466d185 100644 --- a/Calo/CaloAssociators/src/CaloDigitLinker.cpp +++ b/Calo/CaloAssociators/src/CaloDigitLinker.cpp @@ -116,27 +116,29 @@ namespace LHCb::Calo::Algorithm { // Make a map of the MC hits/particles and weights. std::map hitMap; std::map particleMap; - + for ( auto hit : hits ) { - if ( hit.data() == static_cast( nullptr ) ) continue; // spillover MCHit contributed to this digit - + hitMap[hit] += hit.data()->activeE(); - particleMap[hit.data()->particle()] += hit.data()->activeE(); - - const LHCb::MCParticle* particle = hit.data()->particle(); - + auto* mcp = hit.data()->particle(); + if ( !mcp ) continue; + particleMap[mcp] += hit.data()->activeE(); + // Add the energy deposition from the given particle to ALL parents - while ( 0 != particle ) { - const LHCb::MCVertex* vertex = particle->originVertex(); - if ( !vertex ) continue; - particle = vertex->mother(); - if ( !particle ) continue; - particleMap[particle] += hit.data()->activeE(); - } + const LHCb::MCParticle* particle = mcp; + while (true) { + const auto* vtx = particle->originVertex(); + if (!vtx) break; + particle = vtx->mother(); + if (!particle) break; + + particleMap[particle] += hit.data()->activeE(); + } + } - + // Make the associations hitLinks.link( digit.cellID().index(), hitMap ); -- GitLab