File indexing completed on 2024-09-27 07:03:08
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 <catch2/catch_test_macros.hpp>
0010 #include <edm4eic/CalorimeterHitCollection.h>
0011 #include <edm4eic/ProtoClusterCollection.h>
0012 #include <edm4hep/Vector3f.h>
0013 #include <spdlog/common.h>
0014 #include <spdlog/logger.h>
0015 #include <spdlog/spdlog.h>
0016 #include <gsl/pointers>
0017 #include <memory>
0018 #include <utility>
0019 #include <vector>
0020
0021 #include "algorithms/calorimetry/ImagingTopoCluster.h"
0022 #include "algorithms/calorimetry/ImagingTopoClusterConfig.h"
0023
0024 using eicrecon::ImagingTopoCluster;
0025 using eicrecon::ImagingTopoClusterConfig;
0026
0027 TEST_CASE( "the clustering algorithm runs", "[ImagingTopoCluster]" ) {
0028 ImagingTopoCluster algo("ImagingTopoCluster");
0029
0030 std::shared_ptr<spdlog::logger> logger = spdlog::default_logger()->clone("ImagingTopoCluster");
0031 logger->set_level(spdlog::level::trace);
0032
0033 ImagingTopoClusterConfig cfg;
0034 cfg.layerMode =eicrecon::ImagingTopoClusterConfig::ELayerMode::xy;
0035 cfg.minClusterHitEdep = 0. * dd4hep::GeV;
0036 cfg.minClusterCenterEdep = 0. * dd4hep::GeV;
0037 cfg.localDistXY = {1.0* dd4hep::mm, 1.0* dd4hep::mm};
0038 cfg.layerDistXY = {1.0* dd4hep::mm, 1.0* dd4hep::mm};
0039 cfg.minClusterEdep = 9 * dd4hep::MeV;
0040
0041 cfg.minClusterNhits = 1;
0042 auto detector = algorithms::GeoSvc::instance().detector();
0043 auto id_desc = detector->readout("MockCalorimeterHits").idSpec();
0044
0045 SECTION( "without splitting" ) {
0046 algo.applyConfig(cfg);
0047 algo.init();
0048
0049 SECTION( "on a single cell" ) {
0050 edm4eic::CalorimeterHitCollection hits_coll;
0051 hits_coll.create(
0052 id_desc.encode({{"system", 255}, {"x", 0}, {"y", 0}, {"layer", 0}}),
0053 5.0,
0054 0.0,
0055 0.0,
0056 0.0,
0057 edm4hep::Vector3f(0.0, 0.0, 0.0),
0058 edm4hep::Vector3f(0.0, 0.0, 0.0),
0059 0,
0060 0,
0061 edm4hep::Vector3f(0.0, 0.0, 0.0)
0062 );
0063 auto protoclust_coll = std::make_unique<edm4eic::ProtoClusterCollection>();
0064 algo.process({&hits_coll}, {protoclust_coll.get()});
0065
0066 REQUIRE( (*protoclust_coll).size() == 1 );
0067 REQUIRE( (*protoclust_coll)[0].hits_size() == 1 );
0068 REQUIRE( (*protoclust_coll)[0].weights_size() == 1 );
0069 }
0070
0071 SECTION( "on two separated cells" ) {
0072 edm4eic::CalorimeterHitCollection hits_coll;
0073 hits_coll.create(
0074 id_desc.encode({{"system", 255}, {"x", 0}, {"y", 0}, {"layer", 0}}),
0075 5.0,
0076 0.0,
0077 0.0,
0078 0.0,
0079 edm4hep::Vector3f(0.0, 0.0, 0.0),
0080 edm4hep::Vector3f(1.0, 1.0, 0.0),
0081 0,
0082 0,
0083 edm4hep::Vector3f(0.0, 0.0, 0.0)
0084 );
0085 hits_coll.create(
0086 id_desc.encode({{"system", 255}, {"x", 2}, {"y", 2}, {"layer", 0}}),
0087 6.0,
0088 0.0,
0089 0.0,
0090 0.0,
0091 edm4hep::Vector3f(1.1, 1.1, 0.0),
0092 edm4hep::Vector3f(1.0, 1.0, 0.0),
0093 0,
0094 0,
0095 edm4hep::Vector3f(1.1 , 1.1 , 0.0)
0096 );
0097 auto protoclust_coll = std::make_unique<edm4eic::ProtoClusterCollection>();
0098 algo.process({&hits_coll}, {protoclust_coll.get()});
0099
0100 REQUIRE( (*protoclust_coll).size() == 2 );
0101 REQUIRE( (*protoclust_coll)[0].hits_size() == 1 );
0102 REQUIRE( (*protoclust_coll)[0].weights_size() == 1 );
0103 REQUIRE( (*protoclust_coll)[1].hits_size() == 1 );
0104 REQUIRE( (*protoclust_coll)[1].weights_size() == 1 );
0105 }
0106
0107 SECTION( "on two adjacent cells (same layer)" ) {
0108 edm4eic::CalorimeterHitCollection hits_coll;
0109 hits_coll.create(
0110 id_desc.encode({{"system", 255}, {"x", 0}, {"y", 0}}),
0111 5.0,
0112 0.0,
0113 0.0,
0114 0.0,
0115 edm4hep::Vector3f(0.0, 0.0, 0.0),
0116 edm4hep::Vector3f(1.0, 1.0, 0.0),
0117 0,
0118 0,
0119 edm4hep::Vector3f(0.0, 0.0, 0.0)
0120 );
0121 hits_coll.create(
0122 id_desc.encode({{"system", 255}, {"x", 1}, {"y", 0}}),
0123 6.0,
0124 0.0,
0125 0.0,
0126 0.0,
0127 edm4hep::Vector3f(0.9, 0.9, 0.0),
0128 edm4hep::Vector3f(1.0, 1.0, 0.0),
0129 0,
0130 0,
0131 edm4hep::Vector3f(0.9 , 0.9 , 0.0)
0132 );
0133 auto protoclust_coll = std::make_unique<edm4eic::ProtoClusterCollection>();
0134 algo.process({&hits_coll}, {protoclust_coll.get()});
0135
0136 REQUIRE( (*protoclust_coll).size() == 1 );
0137 REQUIRE( (*protoclust_coll)[0].hits_size() == 2 );
0138 REQUIRE( (*protoclust_coll)[0].weights_size() == 2 );
0139 }
0140 }
0141
0142 SECTION( "run on three cells, two of which are on the same layer, and there is a third one on another layer acting as a bridge between them" ) {
0143
0144 cfg.localDistXY = {1 * dd4hep::mm, 1 * dd4hep::mm};
0145 algo.applyConfig(cfg);
0146 algo.init();
0147
0148 edm4eic::CalorimeterHitCollection hits_coll;
0149 hits_coll.create(
0150 id_desc.encode({{"system", 255}, {"x", 0}, {"y", 0}, {"layer", 0}}),
0151 5.0,
0152 0.0,
0153 0.0,
0154 0.0,
0155 edm4hep::Vector3f(0.0, 0.0, 0.0),
0156 edm4hep::Vector3f(1.0, 1.0, 0.0),
0157 0,
0158 0,
0159 edm4hep::Vector3f(0.0, 0.0, 0.0)
0160 );
0161 hits_coll.create(
0162 id_desc.encode({{"system", 255}, {"x", 1}, {"y", 0}, {"layer",1}}),
0163 1.0,
0164 0.0,
0165 0.0,
0166 0.0,
0167 edm4hep::Vector3f(0.9, 0.9, 0.0),
0168 edm4hep::Vector3f(1.0, 1.0, 0.0),
0169 0,
0170 1,
0171 edm4hep::Vector3f(0.9 , 0.9 , 0.0)
0172 );
0173 hits_coll.create(
0174 id_desc.encode({{"system", 255}, {"x", 2}, {"y", 0},{"layer",0}}),
0175 6.0,
0176 0.0,
0177 0.0,
0178 0.0,
0179 edm4hep::Vector3f(1.8, 1.8, 0.0),
0180 edm4hep::Vector3f(1.0, 1.0, 0.0),
0181 0,
0182 0,
0183 edm4hep::Vector3f(1.8 , 1.8 , 0.0)
0184 );
0185 auto protoclust_coll = std::make_unique<edm4eic::ProtoClusterCollection>();
0186 algo.process({&hits_coll}, {protoclust_coll.get()});
0187
0188
0189 REQUIRE( (*protoclust_coll).size() == 1 );
0190 REQUIRE( (*protoclust_coll)[0].hits_size() == 3 );
0191 REQUIRE( (*protoclust_coll)[0].weights_size() == 3 );
0192
0193 }
0194 }