Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-07 08:04:19

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2026, ePIC Collaboration
0003 
0004 #include <algorithms/logger.h>
0005 #include <catch2/catch_test_macros.hpp>
0006 #include <edm4eic/ClusterCollection.h>
0007 #include <edm4eic/ReconstructedParticleCollection.h>
0008 #include <edm4eic/TrackClusterMatchCollection.h>
0009 #include <edm4eic/TrackCollection.h>
0010 #include <cstddef>
0011 #include <memory>
0012 
0013 #include "algorithms/particle_flow/ChargedCandidateMaker.h"
0014 
0015 TEST_CASE("the ChargedCandidateMaker algorithm runs", "[ChargedCandidateMaker]") {
0016   eicrecon::ChargedCandidateMaker algo("test");
0017 
0018   // initialize algorithm
0019   algo.level(algorithms::LogLevel::kDebug);
0020   algo.init();
0021 
0022   SECTION("empty input produces empty output") {
0023     auto matches   = std::make_unique<edm4eic::TrackClusterMatchCollection>();
0024     auto particles = std::make_unique<edm4eic::ReconstructedParticleCollection>();
0025 
0026     algo.process({matches.get()}, {particles.get()});
0027 
0028     REQUIRE(particles->size() == 0);
0029   }
0030 
0031   SECTION("single match produces one particle with one track and one cluster") {
0032     // Create backing collections that own the objects
0033     auto tracks   = std::make_unique<edm4eic::TrackCollection>();
0034     auto clusters = std::make_unique<edm4eic::ClusterCollection>();
0035     auto matches  = std::make_unique<edm4eic::TrackClusterMatchCollection>();
0036 
0037     auto track   = tracks->create();
0038     auto cluster = clusters->create();
0039 
0040     auto match = matches->create();
0041     match.setTrack(track);
0042     match.setCluster(cluster);
0043     match.setWeight(1.0f);
0044 
0045     auto particles = std::make_unique<edm4eic::ReconstructedParticleCollection>();
0046     algo.process({matches.get()}, {particles.get()});
0047 
0048     REQUIRE(particles->size() == 1);
0049 
0050     auto particle = particles->at(0);
0051     REQUIRE(particle.tracks_size() == 1);
0052     REQUIRE(particle.clusters_size() == 1);
0053     REQUIRE(particle.getTracks(0) == track);
0054     REQUIRE(particle.getClusters(0) == cluster);
0055   }
0056 
0057   SECTION("two matches with the same track produce one particle with two clusters") {
0058     auto tracks   = std::make_unique<edm4eic::TrackCollection>();
0059     auto clusters = std::make_unique<edm4eic::ClusterCollection>();
0060     auto matches  = std::make_unique<edm4eic::TrackClusterMatchCollection>();
0061 
0062     auto track    = tracks->create();
0063     auto clusterA = clusters->create();
0064     auto clusterB = clusters->create();
0065 
0066     auto matchA = matches->create();
0067     matchA.setTrack(track);
0068     matchA.setCluster(clusterA);
0069     matchA.setWeight(1.0f);
0070 
0071     auto matchB = matches->create();
0072     matchB.setTrack(track);
0073     matchB.setCluster(clusterB);
0074     matchB.setWeight(0.5f);
0075 
0076     auto particles = std::make_unique<edm4eic::ReconstructedParticleCollection>();
0077     algo.process({matches.get()}, {particles.get()});
0078 
0079     REQUIRE(particles->size() == 1);
0080 
0081     auto particle = particles->at(0);
0082     REQUIRE(particle.tracks_size() == 1);
0083     REQUIRE(particle.clusters_size() == 2);
0084     REQUIRE(particle.getTracks(0) == track);
0085   }
0086 
0087   SECTION("two matches with different tracks produce two particles") {
0088     auto tracks   = std::make_unique<edm4eic::TrackCollection>();
0089     auto clusters = std::make_unique<edm4eic::ClusterCollection>();
0090     auto matches  = std::make_unique<edm4eic::TrackClusterMatchCollection>();
0091 
0092     auto trackA   = tracks->create();
0093     auto trackB   = tracks->create();
0094     auto clusterA = clusters->create();
0095     auto clusterB = clusters->create();
0096 
0097     auto matchA = matches->create();
0098     matchA.setTrack(trackA);
0099     matchA.setCluster(clusterA);
0100     matchA.setWeight(1.0f);
0101 
0102     auto matchB = matches->create();
0103     matchB.setTrack(trackB);
0104     matchB.setCluster(clusterB);
0105     matchB.setWeight(1.0f);
0106 
0107     auto particles = std::make_unique<edm4eic::ReconstructedParticleCollection>();
0108     algo.process({matches.get()}, {particles.get()});
0109 
0110     REQUIRE(particles->size() == 2);
0111 
0112     // Each particle should have exactly one track and one cluster
0113     for (std::size_t i = 0; i < particles->size(); ++i) {
0114       auto particle = particles->at(i);
0115       REQUIRE(particle.tracks_size() == 1);
0116       REQUIRE(particle.clusters_size() == 1);
0117     }
0118   }
0119 }