Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-09-27 07:03:08

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({{"system", 255}, {"x", 0}, {"y", 0}, {"layer", 0}}), // std::uint64_t cellID,
0053         5.0, // float energy,
0054         0.0, // float energyError,
0055         0.0, // float time,
0056         0.0, // float timeError,
0057         edm4hep::Vector3f(0.0, 0.0, 0.0), // edm4hep::Vector3f position,
0058         edm4hep::Vector3f(0.0, 0.0, 0.0), // edm4hep::Vector3f dimension,
0059         0, // std::int32_t sector,
0060         0, // std::int32_t layer,
0061         edm4hep::Vector3f(0.0, 0.0, 0.0) // edm4hep::Vector3f local
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}}), // std::uint64_t cellID,
0075         5.0, // float energy,
0076         0.0, // float energyError,
0077         0.0, // float time,
0078         0.0, // float timeError,
0079         edm4hep::Vector3f(0.0, 0.0, 0.0), // edm4hep::Vector3f position,
0080         edm4hep::Vector3f(1.0, 1.0, 0.0), // edm4hep::Vector3f dimension,
0081         0, // std::int32_t sector,
0082         0, // std::int32_t layer,
0083         edm4hep::Vector3f(0.0, 0.0, 0.0) // edm4hep::Vector3f local
0084       );
0085       hits_coll.create(
0086         id_desc.encode({{"system", 255}, {"x", 2}, {"y", 2}, {"layer", 0}}), // std::uint64_t cellID,
0087         6.0, // float energy,
0088         0.0, // float energyError,
0089         0.0, // float time,
0090         0.0, // float timeError,
0091         edm4hep::Vector3f(1.1, 1.1, 0.0), // edm4hep::Vector3f position,
0092         edm4hep::Vector3f(1.0, 1.0, 0.0), // edm4hep::Vector3f dimension,
0093         0, // std::int32_t sector,
0094         0, // std::int32_t layer,
0095         edm4hep::Vector3f(1.1 /* mm */, 1.1 /* mm */, 0.0) // edm4hep::Vector3f local
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}}), // std::uint64_t cellID,
0111         5.0, // float energy,
0112         0.0, // float energyError,
0113         0.0, // float time,
0114         0.0, // float timeError,
0115         edm4hep::Vector3f(0.0, 0.0, 0.0), // edm4hep::Vector3f position,
0116         edm4hep::Vector3f(1.0, 1.0, 0.0), // edm4hep::Vector3f dimension,
0117         0, // std::int32_t sector,
0118         0, // std::int32_t layer,
0119         edm4hep::Vector3f(0.0, 0.0, 0.0) // edm4hep::Vector3f local
0120       );
0121       hits_coll.create(
0122         id_desc.encode({{"system", 255}, {"x", 1}, {"y", 0}}), // std::uint64_t cellID,
0123         6.0, // float energy,
0124         0.0, // float energyError,
0125         0.0, // float time,
0126         0.0, // float timeError,
0127         edm4hep::Vector3f(0.9, 0.9, 0.0), // edm4hep::Vector3f position,
0128         edm4hep::Vector3f(1.0, 1.0, 0.0), // edm4hep::Vector3f dimension,
0129         0, // std::int32_t sector,
0130         0, // std::int32_t layer,
0131         edm4hep::Vector3f(0.9 /* mm */, 0.9 /* mm */, 0.0) // edm4hep::Vector3f local
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}}), // std::uint64_t cellID,
0151       5.0, // float energy,
0152       0.0, // float energyError,
0153       0.0, // float time,
0154       0.0, // float timeError,
0155       edm4hep::Vector3f(0.0, 0.0, 0.0), // edm4hep::Vector3f position,
0156       edm4hep::Vector3f(1.0, 1.0, 0.0), // edm4hep::Vector3f dimension,
0157       0, // std::int32_t sector,
0158       0, // std::int32_t layer,
0159       edm4hep::Vector3f(0.0, 0.0, 0.0) // edm4hep::Vector3f local
0160     );
0161     hits_coll.create(
0162                      id_desc.encode({{"system", 255}, {"x", 1}, {"y", 0}, {"layer",1}}), // std::uint64_t cellID,
0163       1.0, // float energy,
0164       0.0, // float energyError,
0165       0.0, // float time,
0166       0.0, // float timeError,
0167       edm4hep::Vector3f(0.9, 0.9, 0.0), // edm4hep::Vector3f position,
0168       edm4hep::Vector3f(1.0, 1.0, 0.0), // edm4hep::Vector3f dimension,
0169       0, // std::int32_t sector,
0170       1, // std::int32_t layer,
0171       edm4hep::Vector3f(0.9 /* mm */, 0.9 /* mm */, 0.0) // edm4hep::Vector3f local
0172     );
0173     hits_coll.create(
0174       id_desc.encode({{"system", 255}, {"x", 2}, {"y", 0},{"layer",0}}), // std::uint64_t cellID,
0175       6.0, // float energy,
0176       0.0, // float energyError,
0177       0.0, // float time,
0178       0.0, // float timeError,
0179       edm4hep::Vector3f(1.8, 1.8, 0.0), // edm4hep::Vector3f position,
0180       edm4hep::Vector3f(1.0, 1.0, 0.0), // edm4hep::Vector3f dimension,
0181       0, // std::int32_t sector,
0182       0, // std::int32_t layer,
0183       edm4hep::Vector3f(1.8 /* mm */, 1.8 /* mm */, 0.0) // edm4hep::Vector3f local
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 }