From f5ade07fd4d86ad9ebc62263380d796f2116b373 Mon Sep 17 00:00:00 2001 From: Chris Jones <jonesc@hep.phy.cam.ac.uk> Date: Fri, 13 Oct 2023 10:58:44 +0100 Subject: [PATCH] RICH DecodedDataAddMCInfo: Remove redundant option, avoid map insertion when missing --- .../src/component/DecodedDataAddMCInfo.cpp | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/Rich/RichFutureMCUtils/src/component/DecodedDataAddMCInfo.cpp b/Rich/RichFutureMCUtils/src/component/DecodedDataAddMCInfo.cpp index 54a8bcb99e0..339485b8156 100644 --- a/Rich/RichFutureMCUtils/src/component/DecodedDataAddMCInfo.cpp +++ b/Rich/RichFutureMCUtils/src/component/DecodedDataAddMCInfo.cpp @@ -22,6 +22,7 @@ // Event Model #include "Event/MCRichHit.h" +#include <algorithm> #include <map> #include <memory> #include <tuple> @@ -91,24 +92,29 @@ namespace Rich::Future::MC { for ( auto& pd : mD ) { // IDs per PD for ( auto& id : pd.smartIDs() ) { - // Do we have any MChits for this ID - const auto& pix_mchits = hitsPerPix[id]; - if ( !pix_mchits.empty() ) { - // Find best MCHit to use. Either first labelled as single, otherwise - // just the first in the container. - const auto* mch = pix_mchits.front(); - for ( const auto* h : pix_mchits ) { - if ( h->isSignal() ) { - mch = h; - break; + + // Find MC hit, if available, for this ID + const LHCb::MCRichHit* mch = nullptr; + const auto id_in_map = hitsPerPix.find( id ); + if ( id_in_map != hitsPerPix.end() ) { + const auto& pix_mchits = id_in_map->second; + if ( !pix_mchits.empty() ) { + // Find best MCHit to use. + // Either first labelled as signal, otherwise just the first in the container. + mch = pix_mchits.front(); + for ( const auto* h : pix_mchits ) { + if ( h->isSignal() ) { + mch = h; + break; + } } } - if ( m_useMCTime ) { - // Set time in ID - id.setTime( mch->timeOfFlight() ); - _ri_verbo << id << endmsg; - } } + + // Set time in ID + // If no MC hit found, set 0 (so will be out of time) + id.setTime( mch ? mch->timeOfFlight() : 0.0 ); + _ri_verbo << id << endmsg; } } } @@ -126,9 +132,6 @@ namespace Rich::Future::MC { * When active, applies corrections to the data to make compatible * with the dd4hep builds. */ Gaudi::Property<bool> m_detdescMCinput{this, "IsDetDescMC", true}; - - /// Enable use of MC time info - Gaudi::Property<bool> m_useMCTime{this, "UseMCTime", true}; }; // Declaration of the Algorithm Factory -- GitLab