From af604a179e1a2bc4d7e8197c743453cc999d7f05 Mon Sep 17 00:00:00 2001 From: Gerhard Raven Date: Sun, 21 Jun 2020 14:14:16 +0200 Subject: [PATCH 1/5] migrate CaloHypo matching to v2 CaloHypotheses --- .../src/CaloFutureClusterMCTruth.cpp | 12 +-- .../src/CaloFutureHypoMCTruth.cpp | 87 +++++++++---------- Calo/CaloAssociators/src/CaloHypoMCTruth.cpp | 2 +- 3 files changed, 48 insertions(+), 53 deletions(-) diff --git a/Calo/CaloAssociators/src/CaloFutureClusterMCTruth.cpp b/Calo/CaloAssociators/src/CaloFutureClusterMCTruth.cpp index 267410376..777cc246c 100644 --- a/Calo/CaloAssociators/src/CaloFutureClusterMCTruth.cpp +++ b/Calo/CaloAssociators/src/CaloFutureClusterMCTruth.cpp @@ -46,7 +46,7 @@ */ namespace LHCb::Calo::Associators { class Cluster2MCParticle : public Gaudi::Functional::Transformer { + const LHCb::CaloFuture2MC::DigitTable&, const LHCb::Event::Calo::Clusters& )> { // ========================================================================== // set the appropriate default values for input data Gaudi::Property m_sFilter{this, "StatusFilter", static_cast( LHCb::CaloDigitStatus::Mask::UseForEnergy )}; @@ -72,7 +72,7 @@ namespace LHCb::Calo::Associators { /// algorithm execution LHCb::CaloFuture2MC::ClusterTable operator()( const LHCb::CaloFuture2MC::DigitTable& digTable, - const LHCb::CaloClusters& clusters ) const override { + const LHCb::Event::Calo::Clusters& clusters ) const override { using namespace LHCb::CaloDataFunctor; using namespace CaloMCTools; @@ -87,13 +87,13 @@ namespace LHCb::Calo::Associators { // loop over all digits in the cluster and collect // the links from individual digits - for ( const auto& entry : cluster->entries() ) { + for ( const auto& entry : cluster.entries() ) { if ( m_sFilter >= 0 && entry.status().noneOf( LHCb::CaloDigitStatus::Status( m_sFilter ) ) ) continue; // get all MC relations from this entry / digit // loop over all MC entries and collect the enegy - for ( const auto& [_, particle, energy] : digTable.relations( entry.digit()->cellID() ) ) { + for ( const auto& [_, particle, energy] : digTable.relations( entry.cellID() ) ) { // accumulate the energy from the same particle mcMap[particle] += energy; } @@ -107,10 +107,10 @@ namespace LHCb::Calo::Associators { // MC particle & its cumulative energy deposition to the cluster for ( const auto& [particle, energy] : mcMap ) { if ( !particle ) { continue; } - if ( cluster->e() > 0 && energy < m_wFilter * cluster->e() ) { continue; } + if ( cluster.e() > 0 && energy < m_wFilter * cluster.e() ) { continue; } // fill the relation table: ATTENTION "i_push" is used! - table.i_push( cluster->seed(), particle, energy ); // NB: "i_push" + table.i_push( cluster.cellID(), particle, energy ); // NB: "i_push" } } // end of loop over clusters diff --git a/Calo/CaloAssociators/src/CaloFutureHypoMCTruth.cpp b/Calo/CaloAssociators/src/CaloFutureHypoMCTruth.cpp index d1a0a38d4..e7da54b8e 100644 --- a/Calo/CaloAssociators/src/CaloFutureHypoMCTruth.cpp +++ b/Calo/CaloAssociators/src/CaloFutureHypoMCTruth.cpp @@ -10,9 +10,9 @@ \*****************************************************************************/ #include "CaloFutureUtils/CaloFuture2MC.h" #include "CaloUtils/CaloAlgUtils.h" -#include "Event/CaloHypo.h" +#include "Event/CaloHypos_v2.h" #include "Event/MCParticle.h" -#include "GaudiAlg/GaudiAlgorithm.h" +#include "GaudiAlg/Transformer.h" #include "Linker/LinkerWithKey.h" #include "Relations/RelationWeighted1D.h" @@ -26,63 +26,58 @@ */ namespace LHCb::Calo::Associators { - class Hypo2MCParticle : public GaudiAlgorithm { + using namespace LHCb::CaloFuture2MC; + + class Hypo2MCParticle + : public Gaudi::Functional::Transformer { public: - /// Standard constructor Hypo2MCParticle( const std::string& name, ISvcLocator* pSvcLocator ); - - StatusCode execute() override; ///< Algorithm execution + HypoTable operator()( const LHCb::Event::Calo::Hypotheses&, + const ClusterTable& ) const override; private: - Gaudi::Property m_cluster2MCLoc{this, "Cluster2MCTable", - "Relations/" + LHCb::CaloClusterLocation::Default}; - Gaudi::Property> m_inputs{this, "CaloHypos", {}}; ///< input data + mutable Gaudi::Accumulators::AveragingCounter m_links_per_hypo { this, "#links/hypo" }; + mutable Gaudi::Accumulators::AveragingCounter m_links { this, "#links" }; }; - Hypo2MCParticle::Hypo2MCParticle( const std::string& name, ISvcLocator* pSvc ) : GaudiAlgorithm( name, pSvc ) { - using namespace LHCb::CaloHypoLocation; - m_inputs.value() = {LHCb::CaloAlgUtils::PathFromContext( context(), Photons ), - LHCb::CaloAlgUtils::PathFromContext( context(), Electrons ), - LHCb::CaloAlgUtils::PathFromContext( context(), MergedPi0s ), - LHCb::CaloAlgUtils::PathFromContext( context(), SplitPhotons )}; - } - // ============================================================================ - - // ============================================================================ - // declare algorithm factory - // ============================================================================ DECLARE_COMPONENT_WITH_ID( Hypo2MCParticle, "CaloFutureHypoMCTruth" ) - // ============================================================================ // ============================================================================ - /// algorithm execution + + Hypo2MCParticle::Hypo2MCParticle( const std::string& name, ISvcLocator* pSvc ) + : Transformer{name, + pSvc, + {KeyValue{"InputHypos", ""}, + KeyValue{"InputClusterTable", "Relations/" + LHCb::CaloClusterLocation::Default}}, + KeyValue{"OutputTable",""}} {} + // ============================================================================ - StatusCode Hypo2MCParticle::execute() { - //--- load cluster->MC - const auto* cluster2MC = getIfExists( m_cluster2MCLoc ); - if ( !cluster2MC ) - return Warning( " Cluster <-> MC relation table not found at " + m_cluster2MCLoc, StatusCode::FAILURE ); - for ( const auto& container : m_inputs ) { - LHCb::CaloFuture2MC::HypoLink linker( eventSvc(), msgSvc(), container ); - const LHCb::CaloHypos* hypos = getIfExists( container ); - if ( !hypos ) { - counter( "No container " + container ) += 1; - continue; - } - int links = 0; - for ( const auto* hypo : *hypos ) { - const LHCb::CaloCluster* cluster = LHCb::CaloAlgUtils::ClusterFromHypo( hypo ); - int hlinks = 0; - for ( const auto& ir : cluster2MC->relations( cluster->seed() ) ) { - linker.link( hypo, ir.to(), ir.weight() ); - hlinks++; - links++; + HypoTable Hypo2MCParticle::operator()( const LHCb::Event::Calo::Hypotheses& hypos, + const ClusterTable& cluster2MC ) const { + + HypoTable out; + int links = 0; + for ( const auto& hypo : hypos ) { + + std::map map; + + for ( const auto& cluster : hypo.clusters() ) { + for ( const auto& ir : cluster2MC.relations( cluster.cellID() ) ) { + auto [it, ok] = map.try_emplace( ir.to(), ir.weight() ); + if ( !ok ) it->second += ir.weight(); } - counter( "#links/hypo " + container ) += hlinks; } - counter( "#links " + container ) += links; + int hlinks = 0; + for ( const auto& [ particle, weight] : map ) { + out.i_push( hypo.cellID(), particle, weight ); + ++hlinks; + ++links; + } + m_links_per_hypo += hlinks; } - return StatusCode::SUCCESS; + m_links += links; // counter( "#links " + container ) += links; + out.i_sort(); + return out; } } // namespace LHCb::Calo::Associators // ============================================================================ diff --git a/Calo/CaloAssociators/src/CaloHypoMCTruth.cpp b/Calo/CaloAssociators/src/CaloHypoMCTruth.cpp index 2729f4833..b70870a67 100644 --- a/Calo/CaloAssociators/src/CaloHypoMCTruth.cpp +++ b/Calo/CaloAssociators/src/CaloHypoMCTruth.cpp @@ -61,7 +61,7 @@ std::tuple CaloHypoMCTruth:: LHCb::LinksByKey linksByKey; linksByKey.setSourceClassID( LHCb::CaloHypo::classID() ); linksByKey.setTargetClassID( LHCb::MCParticle::classID() ); - for ( const LHCb::CaloHypo* hypo : hypos ) { + for ( const auto hypo : hypos ) { int hlinks = 0; for ( const auto& ir : cluster2MC.relations( LHCb::CaloAlgUtils::ClusterFromHypo( hypo ) ) ) { if ( hypo && ir.to() ) { -- GitLab From 73a6fcbbd6c8ba7291c63a30b8e8495bc9305cd5 Mon Sep 17 00:00:00 2001 From: Gerhard Raven Date: Tue, 7 Jul 2020 09:26:14 +0200 Subject: [PATCH 2/5] fix memory leak in CaloHypo2Tracks --- Calo/CaloAssociators/src/CaloHypo2Tracks.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Calo/CaloAssociators/src/CaloHypo2Tracks.cpp b/Calo/CaloAssociators/src/CaloHypo2Tracks.cpp index 3d60ca685..a0c0ac808 100644 --- a/Calo/CaloAssociators/src/CaloHypo2Tracks.cpp +++ b/Calo/CaloAssociators/src/CaloHypo2Tracks.cpp @@ -39,7 +39,7 @@ namespace LHCb::Calo::Asssociators { CaloHypo2Tracks( const std::string& name, ISvcLocator* pSvc ) : Transformer( name, pSvc, - {KeyValue( "InputHypos", "" ), KeyValue( "InputTable", {CaloFutureIdLocation::ClusterMatch} )}, + {KeyValue( "InputHypos", "" ), KeyValue( "InputTable", CaloFutureIdLocation::ClusterMatch )}, {KeyValue( "OutputTracks", "" )} ) {} LHCb::Tracks operator()( const CaloHypos& hypos, const TrackMatchTable& table ) const override { @@ -47,14 +47,13 @@ namespace LHCb::Calo::Asssociators { for ( auto* hypo : hypos ) { for ( auto& cluster : hypo->clusters() ) { for ( auto& entry : table.relations( cluster, m_electrChi2Cut, false ) ) { - auto track = std::make_unique( *entry.to() ); - tracks.insert( track.release() ); + tracks.insert(entry.to()); } } } return tracks; } }; + DECLARE_COMPONENT( CaloHypo2Tracks ) } // namespace LHCb::Calo::Asssociators -DECLARE_COMPONENT( LHCb::Calo::Asssociators::CaloHypo2Tracks ) -- GitLab From fbd57cc8efcf563598b72fddc965a9179bf172be Mon Sep 17 00:00:00 2001 From: Gerhard Raven Date: Thu, 23 Jul 2020 13:43:30 +0200 Subject: [PATCH 3/5] modernize --- .../src/CaloClusterEfficiency.cpp | 14 ++++---- .../src/CaloDigit2MCLinks2Table.cpp | 2 +- Calo/CaloAssociators/src/CaloDigitMCTruth.cpp | 36 ++++++++----------- .../src/CaloFutureClusterMCTruth.cpp | 7 ++-- .../src/CaloFutureDigit2MCLinks2Table.cpp | 15 +++----- .../src/CaloFutureHypoMCTruth.cpp | 16 ++++----- Calo/CaloAssociators/src/CaloHypo2Tracks.cpp | 5 +-- 7 files changed, 40 insertions(+), 55 deletions(-) diff --git a/Calo/CaloAssociators/src/CaloClusterEfficiency.cpp b/Calo/CaloAssociators/src/CaloClusterEfficiency.cpp index ab10ab810..de147a773 100644 --- a/Calo/CaloAssociators/src/CaloClusterEfficiency.cpp +++ b/Calo/CaloAssociators/src/CaloClusterEfficiency.cpp @@ -69,7 +69,9 @@ namespace LHCb::Calo::Algorithms { const LHCb::Event::Calo::v2::Clusters& clusters ) const override { const auto cluster_index = clusters.index(); - if ( !cluster_index ) { /* OOPS */ + if ( !cluster_index ) { + ++m_canNotIndexClusters; + return; } // tuple @@ -128,9 +130,8 @@ namespace LHCb::Calo::Algorithms { m_eff += is_reconstructed; continue; } - auto cl = *it; // get cluster from Iterator using operator* - auto cl_pos = cl.position(); - auto cl_e = cl.e(); + auto cl_pos = it->position(); + auto cl_e = it->e(); // fraction of cluster energy from this MCParticle float f_cl = ( cl_e > 0. ) ? weight / cl_e : 0.; @@ -177,6 +178,8 @@ namespace LHCb::Calo::Algorithms { mutable Gaudi::Accumulators::MsgCounter m_multVtx{this, "More than 1 endVertex found for signal"}; mutable Gaudi::Accumulators::MsgCounter m_clNotFound{ this, "CellID from relations table not found in clusters"}; + mutable Gaudi::Accumulators::MsgCounter m_canNotIndexClusters{this, + "Failed to index cluster container"}; bool check_endVtx( LHCb::MCParticle* mcp, Tuple tuple ) const { // get endVertices @@ -223,10 +226,9 @@ namespace LHCb::Calo::Algorithms { // ========================================================================== }; + DECLARE_COMPONENT_WITH_ID( ClusterEfficiency, "CaloClusterEfficiency" ) } // namespace LHCb::Calo::Algorithms -DECLARE_COMPONENT_WITH_ID( LHCb::Calo::Algorithms::ClusterEfficiency, "CaloClusterEfficiency" ) - // ============================================================================ // The END // ============================================================================ diff --git a/Calo/CaloAssociators/src/CaloDigit2MCLinks2Table.cpp b/Calo/CaloAssociators/src/CaloDigit2MCLinks2Table.cpp index 5b17b6859..1e96fd3ea 100644 --- a/Calo/CaloAssociators/src/CaloDigit2MCLinks2Table.cpp +++ b/Calo/CaloAssociators/src/CaloDigit2MCLinks2Table.cpp @@ -57,7 +57,7 @@ LHCb::Calo2MC::DigitTable CaloDigit2MCLinks2Table::operator()( const LHCb::CaloD // loop over all digits for ( const auto* digit : digits ) { - if ( 0 == digit ) { continue; } + if ( !digit ) continue; // use the auxillary container to be immune agains // potential bugs (if any..), like duplicated entries, etc diff --git a/Calo/CaloAssociators/src/CaloDigitMCTruth.cpp b/Calo/CaloAssociators/src/CaloDigitMCTruth.cpp index 9df93ba03..129a2f103 100644 --- a/Calo/CaloAssociators/src/CaloDigitMCTruth.cpp +++ b/Calo/CaloAssociators/src/CaloDigitMCTruth.cpp @@ -18,7 +18,6 @@ #include "GaudiAlg/GaudiAlgorithm.h" #include "Kernel/CaloCellIDKeyTraits.h" #include "Linker/LinkerWithKey.h" -// // ============================================================================ /** @class CaloDigitMCTruth CaloDigitMCTruth.cpp @@ -152,8 +151,6 @@ StatusCode CaloDigitMCTruth::execute() { typedef Over_Et_Threshold OverET; /// helper class to build MC history tree typedef MCCaloHistory MCHistory; - /// auxillary structure for conversion "CaloCellID" -> "int" - // typedef Containers::key_traits Key ; // get digits from TES Digits* digits = getIfExists( m_input ); @@ -165,10 +162,8 @@ StatusCode CaloDigitMCTruth::execute() { // scale factor for recalculation of eActive into eTotal const double activeToTotal = detector->activeToTotal(); - { // check the availability of the global MC truth - LHCb::MCCaloDigits* _mc = mcTruth( digits ); - if ( 0 == _mc ) { Error( "MCCaloDigits* point to NULL" ).ignore(); } - } + // check the availability of the global MC truth + if ( !mcTruth( digits ) ) { Error( "MCCaloDigits* point to NULL" ).ignore(); } // create the Linker object LHCb::Calo2MC::DigitLink linker( eventSvc(), msgSvc(), m_input ); @@ -182,9 +177,8 @@ StatusCode CaloDigitMCTruth::execute() { unsigned long nLinks = 0; // loop over all digits - for ( Digits::const_iterator idigit = digits->begin(); digits->end() != idigit; ++idigit ) { - Digit* digit = *idigit; - if ( 0 == digit ) { continue; } // skip invalid + for ( const Digit* digit : *digits ) { + if ( !digit ) { continue; } // skip invalid // skip extra small energy depositions if ( !overE( digit ) && !overET( digit ) ) { continue; } @@ -205,28 +199,26 @@ StatusCode CaloDigitMCTruth::execute() { // copy history map into the separate container CaloMCMap map2( map1 ); - { // update the copy of history map - for ( CaloMCMap::iterator entry = map1.begin(); map1.end() != entry; ++entry ) { - const LHCb::MCParticle* particle = entry->first; - const double energy = entry->second; - StatusCode up = updateCaloMCMap( particle, energy, map2 ); - if ( up.isFailure() ) warning() << "updateCaloMCMap FAILED " << endmsg; - } + // update the copy of history map + for ( const auto& [particle, energy] : map1 ) { + updateCaloMCMap( particle, energy, map2 ) + .orElse( [&] { warning() << "updateCaloMCMap FAILED " << endmsg; } ) + .ignore(); } // threshold value const double threshold = m_minFr * digit->e(); // fill the relation table - for ( CaloMCMap::iterator entry = map2.begin(); map2.end() != entry; ++entry ) { - const LHCb::MCParticle* particle = entry->first; - if ( 0 == particle ) { continue; } + for ( auto [particle, energy] : map2 ) { + if ( !particle ) { continue; } + + // cumulative energy deposition from this particle + energy *= activeToTotal; // use only more or less "energetic" particles if ( particle->momentum().e() < m_minPE ) { continue; } - // cumulative energy deposition from this particle - const double energy = activeToTotal * entry->second; // skip very small energy depositions if ( energy < m_minE && energy * sinTheta < m_minET && energy < threshold ) { continue; } diff --git a/Calo/CaloAssociators/src/CaloFutureClusterMCTruth.cpp b/Calo/CaloAssociators/src/CaloFutureClusterMCTruth.cpp index 777cc246c..cc72a372a 100644 --- a/Calo/CaloAssociators/src/CaloFutureClusterMCTruth.cpp +++ b/Calo/CaloAssociators/src/CaloFutureClusterMCTruth.cpp @@ -72,7 +72,7 @@ namespace LHCb::Calo::Associators { /// algorithm execution LHCb::CaloFuture2MC::ClusterTable operator()( const LHCb::CaloFuture2MC::DigitTable& digTable, - const LHCb::Event::Calo::Clusters& clusters ) const override { + const LHCb::Event::Calo::Clusters& clusters ) const override { using namespace LHCb::CaloDataFunctor; using namespace CaloMCTools; @@ -83,7 +83,7 @@ namespace LHCb::Calo::Associators { for ( const auto& cluster : clusters ) { // auxillary container to collect all links from individual digits - CaloMCMap mcMap; + std::map mcMap; // loop over all digits in the cluster and collect // the links from individual digits @@ -95,7 +95,8 @@ namespace LHCb::Calo::Associators { // loop over all MC entries and collect the enegy for ( const auto& [_, particle, energy] : digTable.relations( entry.cellID() ) ) { // accumulate the energy from the same particle - mcMap[particle] += energy; + auto [it, ok] = mcMap.try_emplace( particle, energy ); + if ( !ok ) it->second += energy; } } // end of loop over all entries in Cluster diff --git a/Calo/CaloAssociators/src/CaloFutureDigit2MCLinks2Table.cpp b/Calo/CaloAssociators/src/CaloFutureDigit2MCLinks2Table.cpp index 1e9ad0055..48fde345e 100644 --- a/Calo/CaloAssociators/src/CaloFutureDigit2MCLinks2Table.cpp +++ b/Calo/CaloAssociators/src/CaloFutureDigit2MCLinks2Table.cpp @@ -50,36 +50,31 @@ namespace LHCb::Calo::Associators { // create the relation table LHCb::CaloFuture2MC::DigitTable table{3000}; - // loop over all digits for ( const auto& digit : digits ) { - // use the auxillary container to be immune agains // potential bugs (if any..), like duplicated entries, etc // in the Linkers - CaloMCTools::CaloMCMap mcMap; + std::map mcMap; links.applyToLinks( Containers::key_traits::identifier( digit.cellID() ), [&mcMap, &mcParticles]( unsigned int, unsigned int tgtIndex, float weight ) { - // use Linker const LHCb::MCParticle* particle = static_cast( mcParticles.containedObject( tgtIndex ) ); - if ( particle ) mcMap[particle] += weight; // update the auxillary container + auto [it, ok] = mcMap.try_emplace( particle, weight ); + if ( !ok ) it->second += weight; } ); - // convert the auxillary container into Relation Table + // copy contents of the auxillary container into Relation Table for ( auto [particle, energy] : mcMap ) { // use fast i_push method! table.i_push( digit.cellID(), particle, energy ); // NB !! } - - } // end of the loop over digits in the container + } // mandatory operation after "i_push"! table.i_sort(); // NB !! m_emptyTable += table.relations().empty(); - m_cd2mcLinkscounter += table.relations().size(); - return table; } }; diff --git a/Calo/CaloAssociators/src/CaloFutureHypoMCTruth.cpp b/Calo/CaloAssociators/src/CaloFutureHypoMCTruth.cpp index e7da54b8e..91398bcc6 100644 --- a/Calo/CaloAssociators/src/CaloFutureHypoMCTruth.cpp +++ b/Calo/CaloAssociators/src/CaloFutureHypoMCTruth.cpp @@ -32,11 +32,11 @@ namespace LHCb::Calo::Associators { : public Gaudi::Functional::Transformer { public: Hypo2MCParticle( const std::string& name, ISvcLocator* pSvcLocator ); - HypoTable operator()( const LHCb::Event::Calo::Hypotheses&, - const ClusterTable& ) const override; + HypoTable operator()( const LHCb::Event::Calo::Hypotheses&, const ClusterTable& ) const override; + private: - mutable Gaudi::Accumulators::AveragingCounter m_links_per_hypo { this, "#links/hypo" }; - mutable Gaudi::Accumulators::AveragingCounter m_links { this, "#links" }; + mutable Gaudi::Accumulators::AveragingCounter m_links_per_hypo{this, "#links/hypo"}; + mutable Gaudi::Accumulators::AveragingCounter m_links{this, "#links"}; }; DECLARE_COMPONENT_WITH_ID( Hypo2MCParticle, "CaloFutureHypoMCTruth" ) @@ -48,7 +48,7 @@ namespace LHCb::Calo::Associators { pSvc, {KeyValue{"InputHypos", ""}, KeyValue{"InputClusterTable", "Relations/" + LHCb::CaloClusterLocation::Default}}, - KeyValue{"OutputTable",""}} {} + KeyValue{"OutputTable", ""}} {} // ============================================================================ @@ -58,9 +58,7 @@ namespace LHCb::Calo::Associators { HypoTable out; int links = 0; for ( const auto& hypo : hypos ) { - std::map map; - for ( const auto& cluster : hypo.clusters() ) { for ( const auto& ir : cluster2MC.relations( cluster.cellID() ) ) { auto [it, ok] = map.try_emplace( ir.to(), ir.weight() ); @@ -68,14 +66,14 @@ namespace LHCb::Calo::Associators { } } int hlinks = 0; - for ( const auto& [ particle, weight] : map ) { + for ( const auto& [particle, weight] : map ) { out.i_push( hypo.cellID(), particle, weight ); ++hlinks; ++links; } m_links_per_hypo += hlinks; } - m_links += links; // counter( "#links " + container ) += links; + m_links += links; out.i_sort(); return out; } diff --git a/Calo/CaloAssociators/src/CaloHypo2Tracks.cpp b/Calo/CaloAssociators/src/CaloHypo2Tracks.cpp index a0c0ac808..50ecab0ff 100644 --- a/Calo/CaloAssociators/src/CaloHypo2Tracks.cpp +++ b/Calo/CaloAssociators/src/CaloHypo2Tracks.cpp @@ -46,9 +46,7 @@ namespace LHCb::Calo::Asssociators { LHCb::Tracks tracks; for ( auto* hypo : hypos ) { for ( auto& cluster : hypo->clusters() ) { - for ( auto& entry : table.relations( cluster, m_electrChi2Cut, false ) ) { - tracks.insert(entry.to()); - } + for ( auto& entry : table.relations( cluster, m_electrChi2Cut, false ) ) { tracks.insert( entry.to() ); } } } return tracks; @@ -56,4 +54,3 @@ namespace LHCb::Calo::Asssociators { }; DECLARE_COMPONENT( CaloHypo2Tracks ) } // namespace LHCb::Calo::Asssociators - -- GitLab From b158e08589bc5476b23dd4cb0e64d0af5a906352 Mon Sep 17 00:00:00 2001 From: Gerhard Raven Date: Mon, 31 Aug 2020 00:41:53 +0200 Subject: [PATCH 4/5] add support for Hypo v2 in CaloClusterResolution --- Calo/CaloAssociators/src/CaloClusterResolution.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Calo/CaloAssociators/src/CaloClusterResolution.cpp b/Calo/CaloAssociators/src/CaloClusterResolution.cpp index 47c5d0350..49aba72e9 100644 --- a/Calo/CaloAssociators/src/CaloClusterResolution.cpp +++ b/Calo/CaloAssociators/src/CaloClusterResolution.cpp @@ -14,6 +14,7 @@ #include "CaloUtils/CaloAlgUtils.h" #include "Event/CaloCluster.h" #include "Event/CaloClusters_v2.h" +#include "Event/CaloHypos_v2.h" #include "Event/CaloDataFunctor.h" #include "Event/MCParticle.h" #include "GaudiAlg/Consumer.h" @@ -92,6 +93,10 @@ namespace { return in.position().z(); } + std::optional RetrieveZPosition( LHCb::Event::Calo::Hypotheses::const_reference in ) { + return RetrieveZPosition( in.clusters().front() ); + } + std::optional RetrieveZPosition( const LHCb::CaloHypo* in ) { const auto* pos = in->position(); // pi0->gamma gamma special treatment: return hypo of first gamma @@ -110,6 +115,10 @@ namespace { return {in.position().x(), in.position().y(), in.e()}; } + LHCb::CaloPosition::Parameters RetrieveParameters( LHCb::Event::Calo::Hypotheses::const_reference in ) { + return RetrieveParameters( in.clusters().front() ); + } + LHCb::CaloPosition::Parameters RetrieveParameters( const LHCb::CaloHypo* in ) { const auto* pos = in->position(); if ( !pos ) { @@ -239,6 +248,7 @@ namespace LHCb::Calo { DECLARE_COMPONENT_WITH_ID( ClusterResolution, "CaloClusterResolution" ) DECLARE_COMPONENT_WITH_ID( ClusterResolution, "CaloFutureClusterResolution" ) DECLARE_COMPONENT_WITH_ID( ClusterResolution, "CaloHypoResolution" ) + DECLARE_COMPONENT_WITH_ID( ClusterResolution, "CaloFutureHypoResolution" ) } // namespace LHCb::Calo // ============================================================================ // The END -- GitLab From 7d11f67257f0b7cb5d84ab0a3a0dce347accf3b7 Mon Sep 17 00:00:00 2001 From: Gerhard Raven Date: Mon, 31 Aug 2020 10:07:15 +0200 Subject: [PATCH 5/5] port CaloHypo2Tracks to v2 hypos --- .../src/CaloClusterResolution.cpp | 2 +- Calo/CaloAssociators/src/CaloHypo2Tracks.cpp | 25 +++++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Calo/CaloAssociators/src/CaloClusterResolution.cpp b/Calo/CaloAssociators/src/CaloClusterResolution.cpp index 49aba72e9..e351eea34 100644 --- a/Calo/CaloAssociators/src/CaloClusterResolution.cpp +++ b/Calo/CaloAssociators/src/CaloClusterResolution.cpp @@ -14,8 +14,8 @@ #include "CaloUtils/CaloAlgUtils.h" #include "Event/CaloCluster.h" #include "Event/CaloClusters_v2.h" -#include "Event/CaloHypos_v2.h" #include "Event/CaloDataFunctor.h" +#include "Event/CaloHypos_v2.h" #include "Event/MCParticle.h" #include "GaudiAlg/Consumer.h" #include "GaudiAlg/GaudiTupleAlg.h" diff --git a/Calo/CaloAssociators/src/CaloHypo2Tracks.cpp b/Calo/CaloAssociators/src/CaloHypo2Tracks.cpp index 50ecab0ff..8d9b9a7cb 100644 --- a/Calo/CaloAssociators/src/CaloHypo2Tracks.cpp +++ b/Calo/CaloAssociators/src/CaloHypo2Tracks.cpp @@ -13,8 +13,8 @@ #include "Relations/RelationWeighted2D.h" -#include "Event/CaloCluster.h" -#include "Event/CaloHypo.h" +#include "Event/CaloClusters_v2.h" +#include "Event/CaloHypos_v2.h" #include "Event/Track.h" #include "GaudiAlg/Transformer.h" @@ -30,27 +30,30 @@ namespace LHCb::Calo::Asssociators { - using TrackMatchTable = RelationWeighted2D; + using TrackMatchTable = RelationWeighted2D; - struct CaloHypo2Tracks : Gaudi::Functional::Transformer { + struct Hypo2Tracks + : Gaudi::Functional::Transformer { Gaudi::Property m_electrChi2Cut{this, "ElectrMaxChi2", 0., "Threshold on maximum electron cluster track match chi2"}; - CaloHypo2Tracks( const std::string& name, ISvcLocator* pSvc ) + Hypo2Tracks( const std::string& name, ISvcLocator* pSvc ) : Transformer( name, pSvc, {KeyValue( "InputHypos", "" ), KeyValue( "InputTable", CaloFutureIdLocation::ClusterMatch )}, {KeyValue( "OutputTracks", "" )} ) {} - LHCb::Tracks operator()( const CaloHypos& hypos, const TrackMatchTable& table ) const override { - LHCb::Tracks tracks; - for ( auto* hypo : hypos ) { - for ( auto& cluster : hypo->clusters() ) { - for ( auto& entry : table.relations( cluster, m_electrChi2Cut, false ) ) { tracks.insert( entry.to() ); } + Tracks operator()( const Event::Calo::Hypotheses& hypos, const TrackMatchTable& table ) const override { + Tracks tracks; + for ( const auto& hypo : hypos ) { + for ( const auto& cluster : hypo.clusters() ) { + for ( auto& entry : table.relations( cluster.cellID(), m_electrChi2Cut, false ) ) { + if ( !tracks.object( entry.to()->key() ) ) tracks.insert( entry.to() ); + } } } return tracks; } }; - DECLARE_COMPONENT( CaloHypo2Tracks ) + DECLARE_COMPONENT( Hypo2Tracks ) } // namespace LHCb::Calo::Asssociators -- GitLab