File indexing completed on 2025-07-11 07:53:43
0001
0002
0003
0004 #include <catch2/catch_test_macros.hpp>
0005 #include <catch2/matchers/catch_matchers.hpp>
0006 #include <catch2/matchers/catch_matchers_floating_point.hpp>
0007 #include <cmath>
0008 #include <edm4eic/CalorimeterHitCollection.h>
0009 #include <edm4eic/ClusterCollection.h>
0010 #include <edm4eic/MCRecoClusterParticleAssociationCollection.h>
0011 #include <edm4eic/unit_system.h>
0012 #include <edm4hep/Vector3f.h>
0013 #include <edm4hep/utils/vector_utils.h>
0014 #include <memory>
0015 #include <spdlog/common.h>
0016 #include <spdlog/logger.h>
0017 #include <spdlog/spdlog.h>
0018 #include <tuple>
0019
0020 #include "algorithms/calorimetry/CalorimeterClusterShape.h"
0021 #include "algorithms/calorimetry/CalorimeterClusterShapeConfig.h"
0022
0023 using eicrecon::CalorimeterClusterShape;
0024 using eicrecon::CalorimeterClusterShapeConfig;
0025
0026 TEST_CASE("the calorimeter CoG algorithm runs", "[CalorimeterClusterShape]") {
0027 const float EPSILON = 1e-5;
0028
0029 CalorimeterClusterShape algo("CalorimeterClusterShape");
0030
0031 std::shared_ptr<spdlog::logger> logger =
0032 spdlog::default_logger()->clone("CalorimeterClusterShape");
0033 logger->set_level(spdlog::level::trace);
0034
0035 CalorimeterClusterShapeConfig cfg;
0036 cfg.longitudinalShowerInfoAvailable = true;
0037
0038 algo.applyConfig(cfg);
0039 algo.init();
0040
0041 edm4eic::CalorimeterHitCollection hits_coll;
0042 edm4eic::MCRecoClusterParticleAssociationCollection assoc_in_coll;
0043 edm4eic::ClusterCollection clust_in_coll;
0044 auto assoc_out_coll = std::make_unique<edm4eic::MCRecoClusterParticleAssociationCollection>();
0045 auto clust_out_coll = std::make_unique<edm4eic::ClusterCollection>();
0046
0047 auto hit1 = hits_coll.create();
0048 hit1.setCellID(0);
0049 hit1.setEnergy(0.1 * edm4eic::unit::GeV);
0050 hit1.setEnergyError(0);
0051 hit1.setTime(0);
0052 hit1.setTimeError(0);
0053 hit1.setPosition(edm4hep::Vector3f{0, 0, 1 * edm4eic::unit::mm});
0054 hit1.setDimension({0, 0, 0});
0055 hit1.setLocal(edm4hep::Vector3f{0, 0, 1 * edm4eic::unit::mm});
0056
0057 auto hit2 = hits_coll.create();
0058 hit2.setCellID(1);
0059 hit2.setEnergy(0.1 * edm4eic::unit::GeV);
0060 hit2.setEnergyError(0);
0061 hit2.setTime(0);
0062 hit2.setTimeError(0);
0063 hit2.setPosition(edm4hep::Vector3f{-1 * edm4eic::unit::mm, 0, 2 * edm4eic::unit::mm});
0064 hit2.setDimension({0, 0, 0});
0065 hit2.setLocal(edm4hep::Vector3f{-1 * edm4eic::unit::mm, 0, 2 * edm4eic::unit::mm});
0066
0067
0068 auto clust_in = clust_in_coll.create();
0069 clust_in.addToHits(hit1);
0070 clust_in.addToHitContributions(hit1.getEnergy());
0071 clust_in.addToHits(hit2);
0072 clust_in.addToHitContributions(hit2.getEnergy());
0073 clust_in.setNhits(clust_in.hits_size());
0074 clust_in.setEnergy(hit1.getEnergy() + hit2.getEnergy());
0075 clust_in.setPosition((hit1.getPosition() + hit2.getPosition()) / 2);
0076
0077 auto assoc_in = assoc_in_coll.create();
0078 assoc_in.setWeight(0.123);
0079 assoc_in.setRec(clust_in);
0080
0081
0082
0083 auto input = std::make_tuple(&clust_in_coll, &assoc_in_coll);
0084 auto output = std::make_tuple(clust_out_coll.get(), assoc_out_coll.get());
0085
0086 algo.process(input, output);
0087
0088 REQUIRE(clust_out_coll->size() == 1);
0089 auto clust_out = (*clust_out_coll)[0];
0090 REQUIRE(clust_in.getNhits() == clust_out.getNhits());
0091
0092 REQUIRE_THAT(clust_out.getIntrinsicTheta(), Catch::Matchers::WithinAbs(M_PI / 4, EPSILON));
0093
0094 REQUIRE_THAT(std::abs(clust_out.getIntrinsicPhi()), Catch::Matchers::WithinAbs(M_PI, EPSILON));
0095
0096 REQUIRE(assoc_out_coll->size() == 1);
0097 REQUIRE((*assoc_out_coll)[0].getRec() == clust_out);
0098 REQUIRE((*assoc_out_coll)[0].getWeight() == assoc_in.getWeight());
0099 }