File indexing completed on 2025-07-05 08:15:25
0001
0002
0003
0004 #include <DD4hep/Detector.h> // for Detector
0005 #include <DD4hep/IDDescriptor.h> // for IDDescriptor
0006 #include <DD4hep/Readout.h> // for Readout
0007 #include <Evaluator/DD4hepUnits.h> // for MeV, mm, keV, ns
0008 #include <algorithms/geo.h>
0009 #include <catch2/catch_test_macros.hpp> // for AssertionHandler, operator""_catch_sr, StringRef, REQUIRE, operator<, operator==, operator>, TEST_CASE
0010 #include <edm4eic/CalorimeterHitCollection.h> // for CalorimeterHitCollection, MutableCalorimeterHit, CalorimeterHitMutableCollectionIterator
0011 #include <edm4hep/Vector3f.h> // for Vector3f
0012 #include <spdlog/common.h> // for level_enum
0013 #include <spdlog/logger.h> // for logger
0014 #include <spdlog/spdlog.h> // for default_logger
0015 #include <array> // for array
0016 #include <cmath> // for sqrt, abs
0017 #include <cstddef>
0018 #include <gsl/pointers>
0019 #include <memory> // for allocator, unique_ptr, make_unique, shared_ptr, __shared_ptr_access
0020 #include <utility> // for pair
0021
0022 #include "algorithms/calorimetry/HEXPLIT.h" // for HEXPLIT
0023 #include "algorithms/calorimetry/HEXPLITConfig.h" // for HEXPLITConfig
0024
0025 using eicrecon::HEXPLIT;
0026 using eicrecon::HEXPLITConfig;
0027
0028 TEST_CASE("the subcell-splitting algorithm runs", "[HEXPLIT]") {
0029 HEXPLIT algo("HEXPLIT");
0030
0031 std::shared_ptr<spdlog::logger> logger = spdlog::default_logger()->clone("HEXPLIT");
0032 logger->set_level(spdlog::level::trace);
0033
0034 HEXPLITConfig cfg;
0035 cfg.MIP = 472. * dd4hep::keV;
0036 cfg.tmax = 1000. * dd4hep::ns;
0037
0038 auto detector = algorithms::GeoSvc::instance().detector();
0039 auto id_desc = detector->readout("MockCalorimeterHits").idSpec();
0040
0041
0042 double side_length = 31.3 * dd4hep::mm;
0043 double layer_spacing = 25.1 * dd4hep::mm;
0044 double thickness = 3 * dd4hep::mm;
0045
0046
0047 auto dimension = edm4hep::Vector3f(2 * side_length, sqrt(3) * side_length, thickness);
0048
0049 algo.applyConfig(cfg);
0050 algo.init();
0051
0052 edm4eic::CalorimeterHitCollection hits_coll;
0053
0054
0055
0056 std::array<double, 5> layer = {0, 1, 2, 3, 4};
0057 std::array<double, 5> x = {0, 0.75 * side_length, 0, 0.75 * side_length, 0};
0058 std::array<double, 5> y = {sqrt(3) / 2 * side_length, -0.25 * sqrt(3) * side_length, 0,
0059 0.25 * sqrt(3) * side_length, sqrt(3) / 2 * side_length};
0060 std::array<double, 5> E = {50 * dd4hep::MeV, 50 * dd4hep::MeV, 50 * dd4hep::MeV, 50 * dd4hep::MeV,
0061 50 * dd4hep::MeV};
0062 for (std::size_t i = 0; i < 5; i++) {
0063 hits_coll.create(
0064 id_desc.encode({{"system", 255}, {"x", 0}, {"y", 0}}),
0065 E[i],
0066 0.0,
0067 0.0,
0068 0.0,
0069 edm4hep::Vector3f(x[i], y[i], layer[i] * layer_spacing),
0070 dimension,
0071 0,
0072 layer[i],
0073 edm4hep::Vector3f(x[i], y[i], layer[i] * layer_spacing)
0074 );
0075 }
0076
0077 auto subcellhits_coll = std::make_unique<edm4eic::CalorimeterHitCollection>();
0078 algo.process({&hits_coll}, {subcellhits_coll.get()});
0079
0080
0081
0082 REQUIRE((*subcellhits_coll).size() == 60);
0083
0084
0085 double tol = 0.001;
0086 double Esum = 0;
0087 int i = 0;
0088 for (auto subcell : *subcellhits_coll) {
0089 Esum += subcell.getEnergy();
0090 i++;
0091 if (i % 12 == 0) {
0092 REQUIRE(std::abs(Esum - E[i / 12 - 1]) / E[i / 12 - 1] < tol);
0093 Esum = 0;
0094 }
0095 }
0096
0097
0098 REQUIRE((*subcellhits_coll)[35].getEnergy() / E[2] > 0.95);
0099 }