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