From 641263db439a766aaf2b3ffb98a4f355058f84f6 Mon Sep 17 00:00:00 2001 From: Dmitry Kalinkin Date: Mon, 5 Feb 2024 14:41:41 -0500 Subject: [PATCH 1/2] add algorithms_test/calorimetry_CalorimeterClusterRecoCoG.cc --- src/tests/algorithms_test/CMakeLists.txt | 1 + .../calorimetry_CalorimeterClusterRecoCoG.cc | 107 ++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 src/tests/algorithms_test/calorimetry_CalorimeterClusterRecoCoG.cc diff --git a/src/tests/algorithms_test/CMakeLists.txt b/src/tests/algorithms_test/CMakeLists.txt index 64b82d29e7..9e5c22f364 100644 --- a/src/tests/algorithms_test/CMakeLists.txt +++ b/src/tests/algorithms_test/CMakeLists.txt @@ -3,6 +3,7 @@ get_filename_component(TEST_NAME ${CMAKE_CURRENT_LIST_DIR} NAME) # These tests can use the Catch2-provided main add_executable(${TEST_NAME} + calorimetry_CalorimeterClusterRecoCoG.cc calorimetry_CalorimeterIslandCluster.cc calorimetry_CalorimeterHitDigi.cc calorimetry_HEXPLIT.cc diff --git a/src/tests/algorithms_test/calorimetry_CalorimeterClusterRecoCoG.cc b/src/tests/algorithms_test/calorimetry_CalorimeterClusterRecoCoG.cc new file mode 100644 index 0000000000..1061af753f --- /dev/null +++ b/src/tests/algorithms_test/calorimetry_CalorimeterClusterRecoCoG.cc @@ -0,0 +1,107 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (C) 2024, Dmitry Kalinkin + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "algorithms/calorimetry/CalorimeterClusterRecoCoG.h" +#include "algorithms/calorimetry/CalorimeterClusterRecoCoGConfig.h" + +using eicrecon::CalorimeterClusterRecoCoG; +using eicrecon::CalorimeterClusterRecoCoGConfig; + +TEST_CASE( "the cluster assembly algorithm runs", "[CalorimeterClusterCoG]" ) { + CalorimeterClusterRecoCoG algo("CalorimeterClusterRecoCoG"); + + std::shared_ptr logger = spdlog::default_logger()->clone("CalorimeterClusterRecoCoG"); + logger->set_level(spdlog::level::trace); + + CalorimeterClusterRecoCoGConfig cfg; + + cfg.energyWeight = "none"; + cfg.sampFrac = 1.; + cfg.logWeightBase = 3.6; + cfg.logWeightBaseCoeffs = {}; + cfg.logWeightBase_Eref = 50 * dd4hep::MeV; + cfg.enableEtaBounds = false; + + algo.applyConfig(cfg); + algo.init(logger); + + SECTION( "on a single cell" ) { + // Inputs + edm4eic::CalorimeterHitCollection hits_coll; + edm4eic::ProtoClusterCollection proto_coll; + hits_coll.create( + 0xBEEF, // std::uint64_t cellID, + 5.0 * edm4eic::unit::MeV, // float energy, + 0.0 * edm4eic::unit::MeV, // float energyError, + 0.0 * edm4eic::unit::ns, // float time, + 0.0 * edm4eic::unit::ns, // float timeError, + edm4hep::Vector3f(1.0 * edm4eic::unit::mm, 2.0 * edm4eic::unit::mm, 3.0 * edm4eic::unit::mm), // edm4hep::Vector3f position, + edm4hep::Vector3f(0.0 * edm4eic::unit::mm, 0.0 * edm4eic::unit::mm, 0.0 * edm4eic::unit::mm), // edm4hep::Vector3f dimension, + 0, // std::int32_t sector, + 0, // std::int32_t layer, + edm4hep::Vector3f(0.0 * edm4eic::unit::mm, 0.0 * edm4eic::unit::mm, 0.0 * edm4eic::unit::mm) // edm4hep::Vector3f local + ); + auto proto = proto_coll.create(); + proto.addToHits(hits_coll[0]); + proto.addToWeights(123.0); + + edm4hep::SimCalorimeterHitCollection mchit_coll; + bool with_matching_mc_hit; + edm4hep::MCParticle part; + SECTION( "with matching MC hit" ) { + with_matching_mc_hit = true; + auto mchit = mchit_coll.create( + 0xBEEF, // std::uint64_t cellID, + 6.0 * edm4eic::unit::MeV, // float energy, + edm4hep::Vector3f(0.0 * edm4eic::unit::mm, 0.0 * edm4eic::unit::mm, 0.0 * edm4eic::unit::mm) // edm4hep::Vector3f position + ); + edm4hep::MutableCaloHitContribution contrib = { + 0, // std::int32_t PDG, + 0 * edm4eic::unit::MeV, // float energy, + 0 * edm4eic::unit::ns, // float time, + edm4hep::Vector3f(0.0 * edm4eic::unit::mm, 0.0 * edm4eic::unit::mm, 0.0 * edm4eic::unit::mm) // edm4hep::Vector3f stepPosition + }; + contrib.setParticle(part); + mchit.addToContributions(contrib); + } + + SECTION( "without matching MC hit" ) { + with_matching_mc_hit = false; + } + + // Outputs + auto clust_coll = std::make_unique(); + auto assoc_coll = std::make_unique(); + + algo.process({&proto_coll, &mchit_coll}, {clust_coll.get(), assoc_coll.get()}); + + REQUIRE( (*clust_coll).size() == 1 ); + REQUIRE( (*clust_coll)[0].hits_size() == 1 ); + REQUIRE( (*clust_coll)[0].getHits(0).getEnergy() == hits_coll[0].getEnergy() ); + REQUIRE( (*clust_coll)[0].getHits(0).getEnergyError() == hits_coll[0].getEnergyError() ); + REQUIRE( (*clust_coll)[0].getHits(0).getTime() == hits_coll[0].getTime() ); + REQUIRE( (*clust_coll)[0].getHits(0).getTimeError() == hits_coll[0].getTimeError() ); + REQUIRE( (*clust_coll)[0].getHits(0).getPosition() == hits_coll[0].getPosition() ); + + if (with_matching_mc_hit) { + REQUIRE( (*assoc_coll).size() == 1 ); + REQUIRE( (*assoc_coll)[0].getSim() == part ); + REQUIRE( (*assoc_coll)[0].getSim().id() == part.id() ); + REQUIRE( (*assoc_coll)[0].getRec() == (*clust_coll)[0] ); + REQUIRE( (*assoc_coll)[0].getRec().id() == (*clust_coll)[0].id() ); + } else { + REQUIRE( (*assoc_coll).size() == 0 ); + } + } +} From 4eb3753d6499f6ab1005b42f56d460c6f5835978 Mon Sep 17 00:00:00 2001 From: Dmitry Kalinkin Date: Mon, 5 Feb 2024 17:19:26 -0500 Subject: [PATCH 2/2] workaround PODIO memory leaks --- .../calorimetry_CalorimeterClusterRecoCoG.cc | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/tests/algorithms_test/calorimetry_CalorimeterClusterRecoCoG.cc b/src/tests/algorithms_test/calorimetry_CalorimeterClusterRecoCoG.cc index 1061af753f..ffdb6c960a 100644 --- a/src/tests/algorithms_test/calorimetry_CalorimeterClusterRecoCoG.cc +++ b/src/tests/algorithms_test/calorimetry_CalorimeterClusterRecoCoG.cc @@ -8,7 +8,8 @@ #include #include #include -#include +#include +#include #include #include @@ -58,22 +59,24 @@ TEST_CASE( "the cluster assembly algorithm runs", "[CalorimeterClusterCoG]" ) { edm4hep::SimCalorimeterHitCollection mchit_coll; bool with_matching_mc_hit; - edm4hep::MCParticle part; + edm4hep::MCParticleCollection part_coll; + edm4hep::CaloHitContributionCollection contrib_coll; SECTION( "with matching MC hit" ) { with_matching_mc_hit = true; + part_coll.create(); auto mchit = mchit_coll.create( 0xBEEF, // std::uint64_t cellID, 6.0 * edm4eic::unit::MeV, // float energy, edm4hep::Vector3f(0.0 * edm4eic::unit::mm, 0.0 * edm4eic::unit::mm, 0.0 * edm4eic::unit::mm) // edm4hep::Vector3f position ); - edm4hep::MutableCaloHitContribution contrib = { + contrib_coll.create( 0, // std::int32_t PDG, 0 * edm4eic::unit::MeV, // float energy, 0 * edm4eic::unit::ns, // float time, edm4hep::Vector3f(0.0 * edm4eic::unit::mm, 0.0 * edm4eic::unit::mm, 0.0 * edm4eic::unit::mm) // edm4hep::Vector3f stepPosition - }; - contrib.setParticle(part); - mchit.addToContributions(contrib); + ); + contrib_coll[0].setParticle(part_coll[0]); + mchit.addToContributions(contrib_coll[0]); } SECTION( "without matching MC hit" ) { @@ -96,8 +99,8 @@ TEST_CASE( "the cluster assembly algorithm runs", "[CalorimeterClusterCoG]" ) { if (with_matching_mc_hit) { REQUIRE( (*assoc_coll).size() == 1 ); - REQUIRE( (*assoc_coll)[0].getSim() == part ); - REQUIRE( (*assoc_coll)[0].getSim().id() == part.id() ); + REQUIRE( (*assoc_coll)[0].getSim() == part_coll[0] ); + REQUIRE( (*assoc_coll)[0].getSim().id() == part_coll[0].id() ); REQUIRE( (*assoc_coll)[0].getRec() == (*clust_coll)[0] ); REQUIRE( (*assoc_coll)[0].getRec().id() == (*clust_coll)[0].id() ); } else {