Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-08 07:51:28

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2023, Dmitry Kalinkin
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/EDM4hepVersion.h>
0014 #include <edm4hep/EventHeaderCollection.h>
0015 #include <edm4hep/MCParticleCollection.h>
0016 #include <edm4hep/ParticleIDCollection.h>
0017 #if EDM4HEP_BUILD_VERSION < EDM4HEP_VERSION(0, 99, 2)
0018 #include <edm4hep/Vector2i.h>
0019 #endif
0020 #include <edm4hep/Vector3d.h>
0021 #include <edm4hep/Vector3f.h>
0022 #include <podio/detail/Link.h>
0023 #include <spdlog/common.h>
0024 #include <cmath>
0025 #include <cstddef>
0026 #include <deque>
0027 #include <memory>
0028 #include <string>
0029 #include <vector>
0030 
0031 #include "algorithms/pid_lut/PIDLookup.h"
0032 #include "algorithms/pid_lut/PIDLookupConfig.h"
0033 
0034 using eicrecon::PIDLookup;
0035 using eicrecon::PIDLookupConfig;
0036 
0037 TEST_CASE("particles acquire PID", "[PIDLookup]") {
0038   PIDLookup algo("test");
0039 
0040   PIDLookupConfig cfg{
0041       .filename                    = "/dev/null",
0042       .system                      = "MockTracker_ID",
0043       .pdg_values                  = {11},
0044       .charge_values               = {1},
0045       .momentum_edges              = {0., 1., 2.},
0046       .polar_edges                 = {0., M_PI},
0047       .azimuthal_binning           = {0., 2 * M_PI, 2 * M_PI}, // lower, upper, step
0048       .momentum_bin_centers_in_lut = true,
0049       .polar_bin_centers_in_lut    = true,
0050       .use_radians                 = true,
0051   };
0052 
0053   SECTION("single hit with couple contributions") {
0054     algo.level(algorithms::LogLevel(spdlog::level::trace));
0055     algo.applyConfig(cfg);
0056     algo.init();
0057 
0058     auto headers = std::make_unique<edm4hep::EventHeaderCollection>();
0059     auto header  = headers->create(1, 1, 12345678, 1.0);
0060 
0061     auto parts_in  = std::make_unique<edm4eic::ReconstructedParticleCollection>();
0062     auto assocs_in = std::make_unique<edm4eic::MCRecoParticleAssociationCollection>();
0063     auto mcparts   = std::make_unique<edm4hep::MCParticleCollection>();
0064 
0065     parts_in->create(0,                                // std::int32_t type
0066                      0.5,                              // float energy
0067                      edm4hep::Vector3f({0.5, 0., 0.}), // edm4hep::Vector3f momentum
0068                      edm4hep::Vector3f({0., 0., 0.}),  // edm4hep::Vector3f referencePoint
0069                      1.,                               // float charge
0070                      0.,                               // float mass
0071                      0.,                               // float goodnessOfPID
0072                      edm4eic::Cov4f(),                 // edm4eic::Cov4f covMatrix
0073                      0                                 // std::int32_t PDG
0074     );
0075     mcparts->create(11,                  // std::int32_t PDG
0076                     0,                   // std::int32_t generatorStatus
0077                     0,                   // std::int32_t simulatorStatus
0078                     0.,                  // float charge
0079                     0.,                  // float time
0080                     0.,                  // double mass
0081                     edm4hep::Vector3d(), // edm4hep::Vector3d vertex
0082                     edm4hep::Vector3d(), // edm4hep::Vector3d endpoint
0083 #if EDM4HEP_BUILD_VERSION < EDM4HEP_VERSION(0, 99, 1)
0084                     edm4hep::Vector3f(), // edm4hep::Vector3f momentum
0085                     edm4hep::Vector3f(), // edm4hep::Vector3f momentumAtEndpoint
0086 #else
0087                     edm4hep::Vector3d(), // edm4hep::Vector3d momentum
0088                     edm4hep::Vector3d(), // edm4hep::Vector3d momentumAtEndpoint
0089 #endif
0090 #if EDM4HEP_BUILD_VERSION < EDM4HEP_VERSION(0, 99, 3)
0091                     edm4hep::Vector3f() // edm4hep::Vector3f spin
0092 #else
0093                     9 // int32_t helicity (9 if unset)
0094 #endif
0095 #if EDM4HEP_BUILD_VERSION < EDM4HEP_VERSION(0, 99, 2)
0096                     ,
0097                     edm4hep::Vector2i() // edm4hep::Vector2i colorFlow
0098 #endif
0099     );
0100 
0101     auto assoc_in = assocs_in->create();
0102     assoc_in.setRec((*parts_in)[0]);
0103     assoc_in.setSim((*mcparts)[0]);
0104 
0105     auto parts_out   = std::make_unique<edm4eic::ReconstructedParticleCollection>();
0106     auto assocs_out  = std::make_unique<edm4eic::MCRecoParticleAssociationCollection>();
0107     auto partids_out = std::make_unique<edm4hep::ParticleIDCollection>();
0108 #if EDM4EIC_BUILD_VERSION >= EDM4EIC_VERSION(8, 7, 0)
0109     edm4eic::MCRecoParticleLinkCollection links_out;
0110     algo.process({headers.get(), parts_in.get(), assocs_in.get()},
0111                  {parts_out.get(), &links_out, assocs_out.get(), partids_out.get()});
0112 #else
0113     algo.process({headers.get(), parts_in.get(), assocs_in.get()},
0114                  {parts_out.get(), assocs_out.get(), partids_out.get()});
0115 #endif
0116 
0117     REQUIRE((*parts_in).size() == (*parts_out).size());
0118     REQUIRE((*assocs_in).size() == (*assocs_out).size());
0119     REQUIRE(
0120         0 ==
0121         (*partids_out).size()); // Since our table is empty, there will not be a successful lookup
0122 
0123 #if EDM4EIC_BUILD_VERSION >= EDM4EIC_VERSION(8, 7, 0)
0124     // Verify that links were created and match the associations
0125     REQUIRE(links_out.size() == (*assocs_out).size());
0126     for (size_t i = 0; i < links_out.size(); ++i) {
0127       REQUIRE(links_out[i].getFrom() == (*assocs_out)[i].getRec());
0128       REQUIRE(links_out[i].getTo() == (*assocs_out)[i].getSim());
0129       REQUIRE(links_out[i].getWeight() == (*assocs_out)[i].getWeight());
0130     }
0131 #endif
0132   }
0133 }