diff --git a/Calo/CaloAssociators/src/CaloDigitLinker.cpp b/Calo/CaloAssociators/src/CaloDigitLinker.cpp index dc27dc1acc56ffa1666db29bda8bc438a3581968..f8466d1852b38c8e63a92637aef2d7bdd80a50d8 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 );