Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-14 08:14:45

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2024, Sebouh Paul
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}; //mm
0038   cfg.layerDistXY          = {1.0 * dd4hep::mm, 1.0 * dd4hep::mm}; //mm
0039   cfg.minClusterEdep       = 9 * dd4hep::MeV;
0040   // minimum number of hits (to save this cluster)
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(
0053               {{"system", 255}, {"x", 0}, {"y", 0}, {"layer", 0}}), // std::uint64_t cellID,
0054           5.0,                                                      // float energy,
0055           0.0,                                                      // float energyError,
0056           0.0,                                                      // float time,
0057           0.0,                                                      // float timeError,
0058           edm4hep::Vector3f(0.0, 0.0, 0.0),                         // edm4hep::Vector3f position,
0059           edm4hep::Vector3f(0.0, 0.0, 0.0),                         // edm4hep::Vector3f dimension,
0060           0,                                                        // std::int32_t sector,
0061           0,                                                        // std::int32_t layer,
0062           edm4hep::Vector3f(0.0, 0.0, 0.0)                          // edm4hep::Vector3f local
0063       );
0064       auto protoclust_coll = std::make_unique<edm4eic::ProtoClusterCollection>();
0065       algo.process({&hits_coll}, {protoclust_coll.get()});
0066 
0067       REQUIRE((*protoclust_coll).size() == 1);
0068       REQUIRE((*protoclust_coll)[0].hits_size() == 1);
0069       REQUIRE((*protoclust_coll)[0].weights_size() == 1);
0070     }
0071 
0072     SECTION("on two separated cells") {
0073       edm4eic::CalorimeterHitCollection hits_coll;
0074       hits_coll.create(
0075           id_desc.encode(
0076               {{"system", 255}, {"x", 0}, {"y", 0}, {"layer", 0}}), // std::uint64_t cellID,
0077           5.0,                                                      // float energy,
0078           0.0,                                                      // float energyError,
0079           0.0,                                                      // float time,
0080           0.0,                                                      // float timeError,
0081           edm4hep::Vector3f(0.0, 0.0, 0.0),                         // edm4hep::Vector3f position,
0082           edm4hep::Vector3f(1.0, 1.0, 0.0),                         // edm4hep::Vector3f dimension,
0083           0,                                                        // std::int32_t sector,
0084           0,                                                        // std::int32_t layer,
0085           edm4hep::Vector3f(0.0, 0.0, 0.0)                          // edm4hep::Vector3f local
0086       );
0087       hits_coll.create(
0088           id_desc.encode(
0089               {{"system", 255}, {"x", 2}, {"y", 2}, {"layer", 0}}), // std::uint64_t cellID,
0090           6.0,                                                      // float energy,
0091           0.0,                                                      // float energyError,
0092           0.0,                                                      // float time,
0093           0.0,                                                      // float timeError,
0094           edm4hep::Vector3f(1.1, 1.1, 0.0),                         // edm4hep::Vector3f position,
0095           edm4hep::Vector3f(1.0, 1.0, 0.0),                         // edm4hep::Vector3f dimension,
0096           0,                                                        // std::int32_t sector,
0097           0,                                                        // std::int32_t layer,
0098           edm4hep::Vector3f(1.1 /* mm */, 1.1 /* mm */, 0.0)        // edm4hep::Vector3f local
0099       );
0100       auto protoclust_coll = std::make_unique<edm4eic::ProtoClusterCollection>();
0101       algo.process({&hits_coll}, {protoclust_coll.get()});
0102 
0103       REQUIRE((*protoclust_coll).size() == 2);
0104       REQUIRE((*protoclust_coll)[0].hits_size() == 1);
0105       REQUIRE((*protoclust_coll)[0].weights_size() == 1);
0106       REQUIRE((*protoclust_coll)[1].hits_size() == 1);
0107       REQUIRE((*protoclust_coll)[1].weights_size() == 1);
0108     }
0109 
0110     SECTION("on two adjacent cells (same layer)") {
0111       edm4eic::CalorimeterHitCollection hits_coll;
0112       hits_coll.create(
0113           id_desc.encode({{"system", 255}, {"x", 0}, {"y", 0}}), // std::uint64_t cellID,
0114           5.0,                                                   // float energy,
0115           0.0,                                                   // float energyError,
0116           0.0,                                                   // float time,
0117           0.0,                                                   // float timeError,
0118           edm4hep::Vector3f(0.0, 0.0, 0.0),                      // edm4hep::Vector3f position,
0119           edm4hep::Vector3f(1.0, 1.0, 0.0),                      // edm4hep::Vector3f dimension,
0120           0,                                                     // std::int32_t sector,
0121           0,                                                     // std::int32_t layer,
0122           edm4hep::Vector3f(0.0, 0.0, 0.0)                       // edm4hep::Vector3f local
0123       );
0124       hits_coll.create(
0125           id_desc.encode({{"system", 255}, {"x", 1}, {"y", 0}}), // std::uint64_t cellID,
0126           6.0,                                                   // float energy,
0127           0.0,                                                   // float energyError,
0128           0.0,                                                   // float time,
0129           0.0,                                                   // float timeError,
0130           edm4hep::Vector3f(0.9, 0.9, 0.0),                      // edm4hep::Vector3f position,
0131           edm4hep::Vector3f(1.0, 1.0, 0.0),                      // edm4hep::Vector3f dimension,
0132           0,                                                     // std::int32_t sector,
0133           0,                                                     // std::int32_t layer,
0134           edm4hep::Vector3f(0.9 /* mm */, 0.9 /* mm */, 0.0)     // edm4hep::Vector3f local
0135       );
0136       auto protoclust_coll = std::make_unique<edm4eic::ProtoClusterCollection>();
0137       algo.process({&hits_coll}, {protoclust_coll.get()});
0138 
0139       REQUIRE((*protoclust_coll).size() == 1);
0140       REQUIRE((*protoclust_coll)[0].hits_size() == 2);
0141       REQUIRE((*protoclust_coll)[0].weights_size() == 2);
0142     }
0143   }
0144 
0145   SECTION("run on three cells, two of which are on the same layer, and there is a third one on "
0146           "another layer acting as a bridge between them") {
0147 
0148     cfg.localDistXY = {1 * dd4hep::mm, 1 * dd4hep::mm};
0149     algo.applyConfig(cfg);
0150     algo.init();
0151 
0152     edm4eic::CalorimeterHitCollection hits_coll;
0153     hits_coll.create(
0154         id_desc.encode(
0155             {{"system", 255}, {"x", 0}, {"y", 0}, {"layer", 0}}), // std::uint64_t cellID,
0156         5.0,                                                      // float energy,
0157         0.0,                                                      // float energyError,
0158         0.0,                                                      // float time,
0159         0.0,                                                      // float timeError,
0160         edm4hep::Vector3f(0.0, 0.0, 0.0),                         // edm4hep::Vector3f position,
0161         edm4hep::Vector3f(1.0, 1.0, 0.0),                         // edm4hep::Vector3f dimension,
0162         0,                                                        // std::int32_t sector,
0163         0,                                                        // std::int32_t layer,
0164         edm4hep::Vector3f(0.0, 0.0, 0.0)                          // edm4hep::Vector3f local
0165     );
0166     hits_coll.create(
0167         id_desc.encode(
0168             {{"system", 255}, {"x", 1}, {"y", 0}, {"layer", 1}}), // std::uint64_t cellID,
0169         1.0,                                                      // float energy,
0170         0.0,                                                      // float energyError,
0171         0.0,                                                      // float time,
0172         0.0,                                                      // float timeError,
0173         edm4hep::Vector3f(0.9, 0.9, 0.0),                         // edm4hep::Vector3f position,
0174         edm4hep::Vector3f(1.0, 1.0, 0.0),                         // edm4hep::Vector3f dimension,
0175         0,                                                        // std::int32_t sector,
0176         1,                                                        // std::int32_t layer,
0177         edm4hep::Vector3f(0.9 /* mm */, 0.9 /* mm */, 0.0)        // edm4hep::Vector3f local
0178     );
0179     hits_coll.create(
0180         id_desc.encode(
0181             {{"system", 255}, {"x", 2}, {"y", 0}, {"layer", 0}}), // std::uint64_t cellID,
0182         6.0,                                                      // float energy,
0183         0.0,                                                      // float energyError,
0184         0.0,                                                      // float time,
0185         0.0,                                                      // float timeError,
0186         edm4hep::Vector3f(1.8, 1.8, 0.0),                         // edm4hep::Vector3f position,
0187         edm4hep::Vector3f(1.0, 1.0, 0.0),                         // edm4hep::Vector3f dimension,
0188         0,                                                        // std::int32_t sector,
0189         0,                                                        // std::int32_t layer,
0190         edm4hep::Vector3f(1.8 /* mm */, 1.8 /* mm */, 0.0)        // edm4hep::Vector3f local
0191     );
0192     auto protoclust_coll = std::make_unique<edm4eic::ProtoClusterCollection>();
0193     algo.process({&hits_coll}, {protoclust_coll.get()});
0194 
0195     REQUIRE((*protoclust_coll).size() == 1);
0196     REQUIRE((*protoclust_coll)[0].hits_size() == 3);
0197     REQUIRE((*protoclust_coll)[0].weights_size() == 3);
0198   }
0199 }