From 5a204e465829a06872656ef92a49aaf1f46bfc13 Mon Sep 17 00:00:00 2001
From: Chris Jones <jonesc@hep.phy.cam.ac.uk>
Date: Thu, 12 Oct 2023 15:53:25 +0100
Subject: [PATCH] RichFutureMCUtils: Small clean up in MC associations

---
 .../src/component/DecodedDataAddMCInfo.cpp    |  2 +-
 .../src/lib/RichRecMCHelper.cpp               | 64 +++++++++++--------
 .../src/lib/RichSmartIDMCUtils.cpp            |  7 +-
 3 files changed, 39 insertions(+), 34 deletions(-)

diff --git a/Rich/RichFutureMCUtils/src/component/DecodedDataAddMCInfo.cpp b/Rich/RichFutureMCUtils/src/component/DecodedDataAddMCInfo.cpp
index 7a9b9d1b3ab..54a8bcb99e0 100644
--- a/Rich/RichFutureMCUtils/src/component/DecodedDataAddMCInfo.cpp
+++ b/Rich/RichFutureMCUtils/src/component/DecodedDataAddMCInfo.cpp
@@ -95,7 +95,7 @@ namespace Rich::Future::MC {
                 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
+                  // just the first in the container.
                   const auto* mch = pix_mchits.front();
                   for ( const auto* h : pix_mchits ) {
                     if ( h->isSignal() ) {
diff --git a/Rich/RichFutureMCUtils/src/lib/RichRecMCHelper.cpp b/Rich/RichFutureMCUtils/src/lib/RichRecMCHelper.cpp
index 3a5a10f1b6a..959a755e12b 100644
--- a/Rich/RichFutureMCUtils/src/lib/RichRecMCHelper.cpp
+++ b/Rich/RichFutureMCUtils/src/lib/RichRecMCHelper.cpp
@@ -28,8 +28,8 @@ LHCb::MCParticle::ConstVector Helper::trueRecPhoton( const LHCb::Track&
 
   // loop over all the MCPs to see if any match the cluster
   for ( const auto tkMCP : tkMCPs ) {
-    const LHCb::MCParticle* tMCP = tkMCP.to();
-    const auto              MCP  = ( tMCP ? trueRecPhoton( *tMCP, cluster ) : nullptr );
+    const auto* tMCP = tkMCP.to();
+    const auto  MCP  = ( tMCP ? trueRecPhoton( *tMCP, cluster ) : nullptr );
     // if found, and not already present, add to vector
     if ( MCP && std::find( mcPs.begin(), mcPs.end(), MCP ) == mcPs.end() ) { mcPs.push_back( MCP ); }
   }
@@ -46,7 +46,7 @@ const LHCb::MCParticle* Helper::trueRecPhoton( const LHCb::MCParticle&     mcPar
     // now try secondary IDs
     for ( const auto S : cluster.secondaryIDs() ) {
       mcP = trueRecPhoton( mcPart, S );
-      if ( mcP ) break;
+      if ( mcP ) { break; }
     }
   }
   // return found pointer
@@ -72,38 +72,46 @@ LHCb::MCParticle::ConstVector Helper::trueCherenkovPhoton( const LHCb::Track&
                                                            const Rich::RadiatorType    rad,   //
                                                            const Rich::PDPixelCluster& cluster ) const {
 
+  // true MCPs to return
+  LHCb::MCParticle::ConstVector trueMCPs;
+
   // get the MCPs for the track
   const auto tkMCPs = mcParticles( track );
 
-  // true MCPs to return
-  LHCb::MCParticle::ConstVector trueMCPs;
-  trueMCPs.reserve( tkMCPs.size() );
-
-  // save to vector functor
-  auto saveMCP = [&]( const auto tkMCP, const auto id ) {
-    // Is this true Cherenkov radiation ?
-    if ( trueCherenkovRadiation( id, rad ) ) {
-      // get the MCPs for this smartID
-      const auto clMCPs = mcParticles( id );
-      // loop over the cluster MCPs
-      for ( const auto clMCP : clMCPs ) {
-        // Do the hit and track have the same MCP ?
-        if ( clMCP == tkMCP ) {
-          // if not already in the selected list, add it
-          if ( std::find( trueMCPs.begin(), trueMCPs.end(), clMCP ) == trueMCPs.end() ) { trueMCPs.push_back( clMCP ); }
+  if ( !tkMCPs.empty() ) {
+
+    // reserve same size in output
+    trueMCPs.reserve( tkMCPs.size() );
+
+    // save to vector functor
+    auto saveMCP = [&]( const auto tkMCP, const auto id ) {
+      // Is this true Cherenkov radiation ?
+      if ( trueCherenkovRadiation( id, rad ) ) {
+        // get the MCPs for this smartID
+        const auto clMCPs = mcParticles( id );
+        // loop over the cluster MCPs
+        for ( const auto clMCP : clMCPs ) {
+          // Do the hit and track have the same MCP ?
+          if ( clMCP == tkMCP ) {
+            // if not already in the selected list, add it
+            if ( std::find( trueMCPs.begin(), trueMCPs.end(), clMCP ) == trueMCPs.end() ) {
+              trueMCPs.push_back( clMCP );
+            }
+          }
         }
       }
+    };
+
+    // loop over the track MCPs
+    for ( const auto tkMCP : tkMCPs ) {
+      if ( !tkMCP ) { continue; }
+      // save primary ID
+      saveMCP( tkMCP, cluster.primaryID().channelDataOnly() );
+      // loop over secondary IDs
+      for ( const auto S : cluster.secondaryIDs() ) { saveMCP( tkMCP, S.channelDataOnly() ); }
     }
-  };
 
-  // loop over the track MCPs
-  for ( const auto tkMCP : tkMCPs ) {
-    if ( !tkMCP ) { continue; }
-    // save primary ID
-    saveMCP( tkMCP, cluster.primaryID().channelDataOnly() );
-    // loop over secondary IDs
-    for ( const auto S : cluster.secondaryIDs() ) { saveMCP( tkMCP, S.channelDataOnly() ); }
-  }
+  } // tk MCPs not empty
 
   return trueMCPs;
 }
diff --git a/Rich/RichFutureMCUtils/src/lib/RichSmartIDMCUtils.cpp b/Rich/RichFutureMCUtils/src/lib/RichSmartIDMCUtils.cpp
index 37e3e386241..b24b8e2d000 100644
--- a/Rich/RichFutureMCUtils/src/lib/RichSmartIDMCUtils.cpp
+++ b/Rich/RichFutureMCUtils/src/lib/RichSmartIDMCUtils.cpp
@@ -64,11 +64,8 @@ std::vector<LHCb::MCRichDigitHistoryCode> SmartIDUtils::mcDigitHistoryCodes( con
   if ( iEn != m_sumMap.end() ) {
     // reserve size
     codes.reserve( ( *iEn ).second.size() );
-    // Loop over the associated summaries
-    for ( const auto* sum : ( *iEn ).second ) {
-      // add to the vector
-      codes.push_back( sum->history() );
-    }
+    // Loop over the associated summaries and add
+    for ( const auto* sum : ( *iEn ).second ) { codes.push_back( sum->history() ); }
   }
   return codes;
 }
-- 
GitLab