Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /EICrecon/src/tests/algorithms_test/calorimetry_ImagingTopoCluster.cc was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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