File indexing completed on 2026-07-16 07:51:46
0001
0002
0003
0004 #include <algorithms/logger.h>
0005 #include <catch2/catch_test_macros.hpp>
0006 #include <edm4eic/Cov4f.h>
0007 #include <edm4eic/EDM4eicVersion.h>
0008 #include <edm4eic/MCRecoParticleAssociationCollection.h>
0009 #if EDM4EIC_BUILD_VERSION >= EDM4EIC_VERSION(8, 7, 0)
0010 #include <edm4eic/MCRecoParticleLinkCollection.h>
0011 #endif
0012 #include <edm4eic/ReconstructedParticleCollection.h>
0013 #include <edm4hep/EventHeaderCollection.h>
0014 #include <edm4hep/MCParticleCollection.h>
0015 #include <edm4hep/ParticleIDCollection.h>
0016 #include <edm4hep/Vector3d.h>
0017 #include <edm4hep/Vector3f.h>
0018 #include <podio/detail/Link.h>
0019 #include <spdlog/common.h>
0020 #include <cmath>
0021 #include <cstddef>
0022 #include <deque>
0023 #include <memory>
0024 #include <string>
0025 #include <vector>
0026
0027 #include "algorithms/pid_lut/PIDLookup.h"
0028 #include "algorithms/pid_lut/PIDLookupConfig.h"
0029
0030 using eicrecon::PIDLookup;
0031 using eicrecon::PIDLookupConfig;
0032
0033 TEST_CASE("particles acquire PID", "[PIDLookup]") {
0034 PIDLookup algo("test");
0035
0036 PIDLookupConfig cfg{
0037 .filename = "/dev/null",
0038 .system = "MockTracker_ID",
0039 .pdg_values = {11},
0040 .charge_values = {1},
0041 .momentum_edges = {0., 1., 2.},
0042 .polar_edges = {0., M_PI},
0043 .azimuthal_binning = {0., 2 * M_PI, 2 * M_PI},
0044 .momentum_bin_centers_in_lut = true,
0045 .polar_bin_centers_in_lut = true,
0046 .use_radians = true,
0047 };
0048
0049 SECTION("single hit with couple contributions") {
0050 algo.level(algorithms::LogLevel(spdlog::level::trace));
0051 algo.applyConfig(cfg);
0052 algo.init();
0053
0054 auto headers = std::make_unique<edm4hep::EventHeaderCollection>();
0055 auto header = headers->create(1, 1, 12345678, 1.0);
0056
0057 auto parts_in = std::make_unique<edm4eic::ReconstructedParticleCollection>();
0058 auto assocs_in = std::make_unique<edm4eic::MCRecoParticleAssociationCollection>();
0059 auto mcparts = std::make_unique<edm4hep::MCParticleCollection>();
0060
0061 parts_in->create(0,
0062 0.5,
0063 edm4hep::Vector3f({0.5, 0., 0.}),
0064 edm4hep::Vector3f({0., 0., 0.}),
0065 1.,
0066 0.,
0067 0.,
0068 edm4eic::Cov4f(),
0069 0
0070 );
0071 mcparts->create(11,
0072 0,
0073 0,
0074 0.,
0075 0.,
0076 0.,
0077 edm4hep::Vector3d(),
0078 edm4hep::Vector3d(),
0079 edm4hep::Vector3d(),
0080 edm4hep::Vector3d(),
0081 9
0082 );
0083
0084 auto assoc_in = assocs_in->create();
0085 assoc_in.setRec((*parts_in)[0]);
0086 assoc_in.setSim((*mcparts)[0]);
0087
0088 auto parts_out = std::make_unique<edm4eic::ReconstructedParticleCollection>();
0089 auto assocs_out = std::make_unique<edm4eic::MCRecoParticleAssociationCollection>();
0090 auto partids_out = std::make_unique<edm4hep::ParticleIDCollection>();
0091 #if EDM4EIC_BUILD_VERSION >= EDM4EIC_VERSION(8, 7, 0)
0092 edm4eic::MCRecoParticleLinkCollection links_out;
0093 algo.process({headers.get(), parts_in.get(), assocs_in.get()},
0094 {parts_out.get(), &links_out, assocs_out.get(), partids_out.get()});
0095 #else
0096 algo.process({headers.get(), parts_in.get(), assocs_in.get()},
0097 {parts_out.get(), assocs_out.get(), partids_out.get()});
0098 #endif
0099
0100 REQUIRE((*parts_in).size() == (*parts_out).size());
0101 REQUIRE((*assocs_in).size() == (*assocs_out).size());
0102 REQUIRE(
0103 0 ==
0104 (*partids_out).size());
0105
0106 #if EDM4EIC_BUILD_VERSION >= EDM4EIC_VERSION(8, 7, 0)
0107
0108 REQUIRE(links_out.size() == (*assocs_out).size());
0109 for (size_t i = 0; i < links_out.size(); ++i) {
0110 REQUIRE(links_out[i].getFrom() == (*assocs_out)[i].getRec());
0111 REQUIRE(links_out[i].getTo() == (*assocs_out)[i].getSim());
0112 REQUIRE(links_out[i].getWeight() == (*assocs_out)[i].getWeight());
0113 }
0114 #endif
0115 }
0116 }