Skip to content
23 changes: 15 additions & 8 deletions src/algorithms/reco/TrackClusterMatch.cc
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright (C) 2025 Tristan Protzman

#include <cstdint>
#include <edm4eic/EDM4eicVersion.h> // Needs edm4eic::TrackClusterMatch
#include <fmt/core.h>
#include <podio/RelationRange.h>
#include <cstdint>
#include <gsl/pointers>
#include <optional>
#include <podio/RelationRange.h>
#include <set>
#include <stdexcept>
#include <vector>
#if EDM4EIC_VERSION_MAJOR >= 8

Expand All @@ -27,6 +28,14 @@ void TrackClusterMatch::process(const TrackClusterMatch::Input& input,
auto [matched_particles] = output;
trace("We have {} tracks and {} clusters", tracks->size(), clusters->size());

// Validate the configuration
if (m_cfg.matching_distance <= 0) {
throw std::runtime_error(fmt::format("Invalid matching distance: {}", m_cfg.matching_distance));
}
if (m_cfg.calo_id.empty()) {
throw std::runtime_error("Calorimeter ID must be set in the configuration");
}

std::set<int> used_tracks;
// Loop across each cluster, and find the cloeset projected track
for (auto cluster : *clusters) {
Expand All @@ -47,13 +56,11 @@ void TrackClusterMatch::process(const TrackClusterMatch::Input& input,
for (auto point : track.getPoints()) {
// Check if the point is at the calorimeter
// int id = m_detector->volumeManager().lookupDetector(cluster.getHits()[0].getCellID()).id(); // TODO: Find programmatic way to get detector cluster is from
uint32_t ecal_barrel_id = m_geo.detector()->constant<int>("EcalBarrel_ID");
uint32_t hcal_barrel_id = m_geo.detector()->constant<int>("HcalBarrel_ID");
bool is_ecal = point.system == ecal_barrel_id;
bool is_hcal = point.system == hcal_barrel_id;
bool is_surface = point.surface == 1;
uint32_t calo_id = m_geo.detector()->constant<int>(m_cfg.calo_id);
bool is_calo = point.system == calo_id;
bool is_surface = point.surface == 1;

if (!(is_ecal || is_hcal) || !is_surface) {
if (!is_calo || !is_surface) {
trace("Skipping track point not at the calorimeter");
continue;
}
Expand Down
1 change: 1 addition & 0 deletions src/algorithms/reco/TrackClusterMatchConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
namespace eicrecon {
struct TrackClusterMatchConfig {
double matching_distance = 0.5;
std::string calo_id = "";
};
} // namespace eicrecon
48 changes: 38 additions & 10 deletions src/global/reco/reco.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,46 @@ void InitPlugin(JApplication* app) {
},
app));

app->Add(new JOmniFactoryGeneratorT<CollectionCollector_factory<edm4eic::Cluster, true>>(
"BarrelClusters",
{
"HcalBarrelClusters",
"EcalBarrelClusters",
},
{"BarrelClusters"}, app));

#if EDM4EIC_VERSION_MAJOR >= 8
// Forward
app->Add(new JOmniFactoryGeneratorT<TrackClusterMatch_factory>(
"EcalEndcapPTrackClusterMatcher", {"CalorimeterTrackProjections", "EcalEndcapPClusters"},
{"EcalEndcapPTrackClusterMatches"}, {.calo_id = "EcalEndcapP_ID"}, app));

app->Add(new JOmniFactoryGeneratorT<TrackClusterMatch_factory>(
"EcalEndcapPInsertTrackClusterMatcher",
{"CalorimeterTrackProjections", "EcalEndcapPInsertClusters"},
{"EcalEndcapPInsertTrackClusterMatches"}, {.calo_id = "EcalEndcapPInsert_ID"}, app));

app->Add(new JOmniFactoryGeneratorT<TrackClusterMatch_factory>(
"LFHCALTrackClusterMatcher", {"CalorimeterTrackProjections", "LFHCALClusters"},
{"LFHCALTrackClusterMatches"}, {.calo_id = "LFHCAL_ID"}, app));

app->Add(new JOmniFactoryGeneratorT<TrackClusterMatch_factory>(
"TrackClusterMatcher", {"CalorimeterTrackProjections", "BarrelClusters"},
{"TrackClusterMatches"}, {}, app));
"HcalEndcapPInsertClusterMatcher",
{"CalorimeterTrackProjections", "HcalEndcapPInsertClusters"},
{"HcalEndcapPInsertTrackClusterMatches"}, {.calo_id = "HcalEndcapPInsert_ID"}, app));

// Barrel
app->Add(new JOmniFactoryGeneratorT<TrackClusterMatch_factory>(
"EcalBarrelTrackClusterMatcher", {"CalorimeterTrackProjections", "EcalBarrelClusters"},
{"EcalBarrelTrackClusterMatches"}, {.calo_id = "EcalBarrel_ID"}, app));

app->Add(new JOmniFactoryGeneratorT<TrackClusterMatch_factory>(
"HcalBarrelTrackClusterMatcher", {"CalorimeterTrackProjections", "HcalBarrelClusters"},
{"HcalBarrelTrackClusterMatches"}, {.calo_id = "HcalBarrel_ID"}, app));

// Backward
app->Add(new JOmniFactoryGeneratorT<TrackClusterMatch_factory>(
"EcalEndcapNBarrelTrackClusterMatcher",
{"CalorimeterTrackProjections", "EcalEndcapNClusters"}, {"EcalEndcapNTrackClusterMatches"},
{.calo_id = "EcalEndcapN_ID"}, app));

app->Add(new JOmniFactoryGeneratorT<TrackClusterMatch_factory>(
"HcalEndcapNBarrelTrackClusterMatcher",
{"CalorimeterTrackProjections", "HcalEndcapNClusters"}, {"HcalEndcapNTrackClusterMatches"},
{.calo_id = "HcalEndcapN_ID"}, app));

#endif // EDM4EIC_VERSION_MAJOR >= 8

app->Add(new JOmniFactoryGeneratorT<TransformBreitFrame_factory>(
Expand Down
9 changes: 8 additions & 1 deletion src/services/io/podio/JEventProcessorPODIO.cc
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,14 @@ JEventProcessorPODIO::JEventProcessorPODIO() {
"HcalFarForwardZDCRawHitAssociations",
#endif
#if EDM4EIC_VERSION_MAJOR >= 8
"TrackClusterMatches",
"EcalEndcapPTrackClusterMatches",
"EcalEndcapPInsertTrackClusterMatches",
"LFHCALTrackClusterMatches",
"HcalEndcapPInsertClusterMatches",
"EcalBarrelTrackClusterMatches",
"HcalBarrelTrackClusterMatches",
"EcalEndcapNTrackClusterMatches",
"HcalEndcapNTrackClusterMatches",
#endif

};
Expand Down
Loading