Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:00:01

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2024, Dmitry Kalinkin, Simon Gardner
0003 
0004 #include <DD4hep/Detector.h>
0005 #include <DD4hep/IDDescriptor.h>
0006 #include <DD4hep/Readout.h>
0007 #include <algorithms/geo.h>
0008 #include <algorithms/logger.h>
0009 #include <catch2/catch_test_macros.hpp>
0010 #include <catch2/generators/catch_generators.hpp>
0011 #include <edm4eic/RawTrackerHitCollection.h>
0012 #include <edm4eic/unit_system.h>
0013 #include <gsl/pointers>
0014 #include <podio/ObjectID.h>
0015 #include <utility>
0016 #include <vector>
0017 
0018 #include "algorithms/fardetectors/FarDetectorTrackerCluster.h"
0019 #include "algorithms/fardetectors/FarDetectorTrackerClusterConfig.h"
0020 
0021 TEST_CASE("the clustering algorithm runs", "[FarDetectorTrackerCluster]") {
0022   eicrecon::FarDetectorTrackerCluster algo("FarDetectorTrackerCluster");
0023 
0024   eicrecon::FarDetectorTrackerClusterConfig cfg;
0025   cfg.hit_time_limit = 10.0 * edm4eic::unit::ns;
0026   cfg.readout        = "MockTrackerHits";
0027   cfg.x_field        = "x";
0028   cfg.y_field        = "y";
0029 
0030   auto detector = algorithms::GeoSvc::instance().detector();
0031   auto id_desc  = detector->readout(cfg.readout).idSpec();
0032 
0033   algo.applyConfig(cfg);
0034   algo.level(algorithms::LogLevel::kTrace);
0035   algo.init();
0036 
0037   SECTION("on a single pixel") {
0038     edm4eic::RawTrackerHitCollection hits_coll;
0039     hits_coll.create(id_desc.encode({{"system", 255}, {"x", 0}, {"y", 0}}), // std::uint64_t cellID,
0040                      5.0,                                                   // int32 charge,
0041                      0.0                                                    // int32 timeStamp
0042     );
0043 
0044     std::vector<FDTrackerCluster> clusterPositions = algo.ClusterHits(hits_coll);
0045 
0046     REQUIRE(clusterPositions.size() == 1);
0047     REQUIRE(clusterPositions[0].rawHits.size() == 1);
0048     REQUIRE(clusterPositions[0].x == 0.0);
0049     REQUIRE(clusterPositions[0].y == 0.0);
0050     REQUIRE(clusterPositions[0].energy == 5.0);
0051     REQUIRE(clusterPositions[0].time == 0.0);
0052   }
0053 
0054   SECTION("on two separated pixels") {
0055     edm4eic::RawTrackerHitCollection hits_coll;
0056     hits_coll.create(
0057         id_desc.encode({{"system", 255}, {"x", 0}, {"y", 10}}), // std::uint64_t cellID,
0058         5.0,                                                    // int32 charge,
0059         5.0                                                     // int32 timeStamp
0060     );
0061     hits_coll.create(
0062         id_desc.encode({{"system", 255}, {"x", 10}, {"y", 0}}), // std::uint64_t cellID,
0063         5.0,                                                    // int32 charge,
0064         5.0                                                     // int32 timeStamp
0065     );
0066 
0067     std::vector<FDTrackerCluster> clusterPositions = algo.ClusterHits(hits_coll);
0068 
0069     REQUIRE(clusterPositions.size() == 2);
0070     REQUIRE(clusterPositions[0].rawHits.size() == 1);
0071     REQUIRE(clusterPositions[1].rawHits.size() == 1);
0072   }
0073 
0074   SECTION("on two adjacent pixels") {
0075     edm4eic::RawTrackerHitCollection hits_coll;
0076     hits_coll.create(id_desc.encode({{"system", 255}, {"x", 0}, {"y", 0}}), // std::uint64_t cellID,
0077                      5.0,                                                   // int32 charge,
0078                      5.0                                                    // int32 timeStamp
0079     );
0080     hits_coll.create(id_desc.encode({{"system", 255}, {"x", 1}, {"y", 0}}), // std::uint64_t cellID,
0081                      5.0,                                                   // int32 charge,
0082                      5.0                                                    // int32 timeStamp
0083     );
0084 
0085     std::vector<FDTrackerCluster> clusterPositions = algo.ClusterHits(hits_coll);
0086 
0087     REQUIRE(clusterPositions.size() == 1);
0088     REQUIRE(clusterPositions[0].rawHits.size() == 2);
0089     REQUIRE(clusterPositions[0].x == 0.5);
0090   }
0091 
0092   SECTION("on two adjacent pixels outwith the time separation") {
0093     edm4eic::RawTrackerHitCollection hits_coll;
0094     hits_coll.create(id_desc.encode({{"system", 255}, {"x", 0}, {"y", 0}}), // std::uint64_t cellID,
0095                      5.0,                                                   // int32 charge,
0096                      0.0                                                    // int32 timeStamp
0097     );
0098     hits_coll.create(id_desc.encode({{"system", 255}, {"x", 1}, {"y", 0}}), // std::uint64_t cellID,
0099                      5.0,                                                   // int32 charge,
0100                      1.1 * cfg.hit_time_limit                               // int32 timeStamp
0101     );
0102 
0103     std::vector<FDTrackerCluster> clusterPositions = algo.ClusterHits(hits_coll);
0104 
0105     REQUIRE(clusterPositions.size() == 2);
0106     REQUIRE(clusterPositions[0].rawHits.size() == 1);
0107     REQUIRE(clusterPositions[1].rawHits.size() == 1);
0108   }
0109 
0110   SECTION("run on three adjacent pixels") {
0111 
0112     // Check I and L shape clusters
0113     auto pixel3       = GENERATE(std::vector<int>{2, 0}, std::vector<int>{1, 1});
0114     auto pixelCharges = GENERATE(std::vector<int>{5, 10, 5}, std::vector<int>{10, 5, 5});
0115     float pixel2Time  = GENERATE_COPY(0, 1.1 * cfg.hit_time_limit);
0116 
0117     edm4eic::RawTrackerHitCollection hits_coll;
0118     hits_coll.create(id_desc.encode({{"system", 255}, {"x", 0}, {"y", 0}}), // std::uint64_t cellID,
0119                      pixelCharges[0],                                       // int32 charge,
0120                      0.0                                                    // int32 timeStamp
0121     );
0122     hits_coll.create(id_desc.encode({{"system", 255}, {"x", 1}, {"y", 0}}), // std::uint64_t cellID,
0123                      pixelCharges[1],                                       // int32 charge,
0124                      pixel2Time                                             // int32 timeStamp
0125     );
0126     hits_coll.create(
0127         id_desc.encode(
0128             {{"system", 255}, {"x", pixel3[0]}, {"y", pixel3[1]}}), // std::uint64_t cellID,
0129         pixelCharges[2],                                            // int32 charge,
0130         0.0                                                         // int32 timeStamp
0131     );
0132 
0133     std::vector<FDTrackerCluster> clusterPositions = algo.ClusterHits(hits_coll);
0134 
0135     if (pixel2Time < cfg.hit_time_limit) {
0136       REQUIRE(clusterPositions.size() == 1);
0137       REQUIRE(clusterPositions[0].rawHits.size() == 3);
0138     } else if (pixel3[0] == 2) {
0139       REQUIRE(clusterPositions.size() == 3);
0140       REQUIRE(clusterPositions[0].rawHits.size() == 1);
0141       REQUIRE(clusterPositions[1].rawHits.size() == 1);
0142       REQUIRE(clusterPositions[2].rawHits.size() == 1);
0143     } else {
0144       REQUIRE(clusterPositions.size() == 2);
0145     }
0146   }
0147 }