File indexing completed on 2025-09-18 08:17:58
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 <edm4eic/MCRecoCalorimeterHitAssociationCollection.h>
0012 #include <edm4hep/CaloHitContributionCollection.h>
0013 #include <edm4hep/EventHeaderCollection.h>
0014 #include <edm4hep/RawCalorimeterHitCollection.h>
0015 #include <edm4hep/SimCalorimeterHitCollection.h>
0016 #include <edm4hep/Vector3f.h>
0017 #include <spdlog/common.h>
0018 #include <spdlog/logger.h>
0019 #include <spdlog/spdlog.h>
0020 #include <cmath>
0021 #include <gsl/pointers>
0022 #include <memory>
0023 #include <string>
0024 #include <utility>
0025 #include <vector>
0026
0027 #include "algorithms/calorimetry/CalorimeterHitDigi.h"
0028 #include "algorithms/calorimetry/CalorimeterHitDigiConfig.h"
0029
0030 using eicrecon::CalorimeterHitDigi;
0031 using eicrecon::CalorimeterHitDigiConfig;
0032
0033 TEST_CASE("the clustering algorithm runs", "[CalorimeterHitDigi]") {
0034 std::shared_ptr<spdlog::logger> logger = spdlog::default_logger()->clone("CalorimeterHitDigi");
0035 logger->set_level(spdlog::level::trace);
0036
0037 auto detector = algorithms::GeoSvc::instance().detector();
0038 auto id_desc = detector->readout("MockCalorimeterHits").idSpec();
0039
0040 CalorimeterHitDigi algo("test");
0041
0042 CalorimeterHitDigiConfig cfg;
0043 cfg.threshold = 0. ;
0044 cfg.corrMeanScale = "1.";
0045
0046
0047 cfg.pedSigmaADC = 0;
0048 cfg.tRes = 0. * dd4hep::ns;
0049 cfg.eRes = {0. * sqrt(dd4hep::GeV), 0., 0. * dd4hep::GeV};
0050 cfg.readout = "MockCalorimeterHits";
0051
0052 SECTION("single hit with couple contributions") {
0053 cfg.capADC = 555;
0054 cfg.dyRangeADC = 5.0 ;
0055 cfg.pedMeanADC = 123;
0056 cfg.resolutionTDC = 1.0 * dd4hep::ns;
0057 algo.level(algorithms::LogLevel(spdlog::level::trace));
0058 algo.applyConfig(cfg);
0059 algo.init();
0060
0061 auto headers = std::make_unique<edm4hep::EventHeaderCollection>();
0062 auto header = headers->create(1, 1, 12345678, 1.0);
0063
0064 auto calohits = std::make_unique<edm4hep::CaloHitContributionCollection>();
0065 auto simhits = std::make_unique<edm4hep::SimCalorimeterHitCollection>();
0066 auto mhit = simhits->create(
0067 id_desc.encode({{"system", 255}, {"x", 0}, {"y", 0}}),
0068 1.0 ,
0069 edm4hep::Vector3f({0. , 0. , 0. })
0070 );
0071 mhit.addToContributions(calohits->create(
0072 0,
0073 0.5 ,
0074 7.0 ,
0075 edm4hep::Vector3f({0. , 0. , 0. })
0076 ));
0077 mhit.addToContributions(calohits->create(
0078 0,
0079 0.5 ,
0080 9.0 ,
0081 edm4hep::Vector3f({0. , 0. , 0. })
0082 ));
0083
0084 auto rawhits = std::make_unique<edm4hep::RawCalorimeterHitCollection>();
0085 auto rawassocs = std::make_unique<edm4eic::MCRecoCalorimeterHitAssociationCollection>();
0086 algo.process({headers.get(), simhits.get()}, {rawhits.get(), rawassocs.get()});
0087
0088 REQUIRE((*rawhits).size() == 1);
0089 REQUIRE((*rawhits)[0].getCellID() == id_desc.encode({{"system", 255}, {"x", 0}, {"y", 0}}));
0090 REQUIRE((*rawhits)[0].getAmplitude() == 123 + 111);
0091 REQUIRE((*rawhits)[0].getTimeStamp() == 7);
0092
0093 REQUIRE((*rawassocs).size() == 1);
0094 REQUIRE((*rawassocs)[0].getSimHit() == (*simhits)[0]);
0095 REQUIRE((*rawassocs)[0].getRawHit() == (*rawhits)[0]);
0096 }
0097 }