File indexing completed on 2026-09-04 08:28:03
0001
0002
0003
0004 #include <DD4hep/Detector.h>
0005 #include <DD4hep/IDDescriptor.h>
0006 #include <DD4hep/Readout.h>
0007 #include <Evaluator/DD4hepUnits.h>
0008 #include <algorithms/geo.h>
0009 #include <algorithms/logger.h>
0010 #include <catch2/catch_test_macros.hpp>
0011 #include <catch2/matchers/catch_matchers.hpp>
0012 #include <catch2/matchers/catch_matchers_floating_point.hpp>
0013 #include <edm4eic/MCRecoCalorimeterHitAssociationCollection.h>
0014 #include <edm4eic/MCRecoCalorimeterHitLinkCollection.h>
0015 #include <edm4hep/CaloHitContributionCollection.h>
0016 #include <edm4hep/EventHeaderCollection.h>
0017 #include <edm4hep/RawCalorimeterHitCollection.h>
0018 #include <edm4hep/SimCalorimeterHitCollection.h>
0019 #include <edm4hep/Vector3f.h>
0020 #include <podio/detail/Link.h>
0021 #include <spdlog/common.h>
0022 #include <spdlog/logger.h>
0023 #include <spdlog/spdlog.h>
0024 #include <cmath>
0025 #include <deque>
0026 #include <gsl/pointers>
0027 #include <memory>
0028 #include <string>
0029 #include <utility>
0030 #include <vector>
0031
0032 #include "algorithms/calorimetry/CalorimeterHitDigi.h"
0033 #include "algorithms/calorimetry/CalorimeterHitDigiConfig.h"
0034
0035 using eicrecon::CalorimeterHitDigi;
0036 using eicrecon::CalorimeterHitDigiConfig;
0037
0038 TEST_CASE("the clustering algorithm runs", "[CalorimeterHitDigi]") {
0039 [[maybe_unused]] const float EPSILON = 1e-5;
0040
0041 std::shared_ptr<spdlog::logger> logger = spdlog::default_logger()->clone("CalorimeterHitDigi");
0042 logger->set_level(spdlog::level::trace);
0043
0044 auto detector = algorithms::GeoSvc::instance().detector();
0045 auto id_desc = detector->readout("MockCalorimeterHits").idSpec();
0046
0047 CalorimeterHitDigi algo("test");
0048
0049 CalorimeterHitDigiConfig cfg;
0050 cfg.threshold = 0. ;
0051 cfg.corrMeanScale = "1.";
0052
0053
0054 cfg.pedSigmaADC = 0;
0055 cfg.tRes = 0. * dd4hep::ns;
0056 cfg.eRes = {0. * sqrt(dd4hep::GeV), 0., 0. * dd4hep::GeV};
0057 cfg.readout = "MockCalorimeterHits";
0058
0059 SECTION("single hit with couple contributions") {
0060 cfg.capADC = 555;
0061 cfg.dyRangeADC = 5.0 ;
0062 cfg.pedMeanADC = 123;
0063 cfg.resolutionTDC = 1.0 * dd4hep::ns;
0064 algo.level(algorithms::LogLevel(spdlog::level::trace));
0065 algo.applyConfig(cfg);
0066 algo.init();
0067
0068 auto headers = std::make_unique<edm4hep::EventHeaderCollection>();
0069 auto header = headers->create(1, 1, 12345678, 1.0);
0070
0071 auto calohits = std::make_unique<edm4hep::CaloHitContributionCollection>();
0072 auto simhits = std::make_unique<edm4hep::SimCalorimeterHitCollection>();
0073 auto mhit = simhits->create(
0074 id_desc.encode({{"system", 255}, {"x", 0}, {"y", 0}}),
0075 1.0 ,
0076 edm4hep::Vector3f({0. , 0. , 0. })
0077 );
0078 mhit.addToContributions(calohits->create(
0079 0,
0080 0.5 ,
0081 7.0 ,
0082 edm4hep::Vector3f({0. , 0. , 0. })
0083 ));
0084 mhit.addToContributions(calohits->create(
0085 0,
0086 0.5 ,
0087 9.0 ,
0088 edm4hep::Vector3f({0. , 0. , 0. })
0089 ));
0090
0091 auto rawhits = std::make_unique<edm4hep::RawCalorimeterHitCollection>();
0092 auto rawassocs = std::make_unique<edm4eic::MCRecoCalorimeterHitAssociationCollection>();
0093 edm4eic::MCRecoCalorimeterHitLinkCollection rawlinks;
0094 algo.process({headers.get(), simhits.get()}, {rawhits.get(), &rawlinks, rawassocs.get()});
0095
0096 REQUIRE((*rawhits).size() == 1);
0097 REQUIRE((*rawhits)[0].getCellID() == id_desc.encode({{"system", 255}, {"x", 0}, {"y", 0}}));
0098 REQUIRE((*rawhits)[0].getAmplitude() == 123 + 111);
0099 REQUIRE((*rawhits)[0].getTimeStamp() == 7);
0100
0101 REQUIRE((*rawassocs).size() == 1);
0102 REQUIRE((*rawassocs)[0].getSimHit() == (*simhits)[0]);
0103 REQUIRE((*rawassocs)[0].getRawHit() == (*rawhits)[0]);
0104
0105
0106 REQUIRE(rawlinks.size() == 1);
0107 REQUIRE(rawlinks.size() == (*rawassocs).size());
0108
0109
0110 REQUIRE(rawlinks[0].getFrom() == (*rawhits)[0]);
0111 REQUIRE(rawlinks[0].getTo() == (*simhits)[0]);
0112
0113
0114 REQUIRE_THAT(rawlinks[0].getWeight(), Catch::Matchers::WithinAbs(1.0, EPSILON));
0115 }
0116 }