From c9d0fdf47d609d6ffa8887fe2dca4e91ac048207 Mon Sep 17 00:00:00 2001 From: ruse-traveler Date: Tue, 8 Oct 2024 00:24:37 -0400 Subject: [PATCH 01/46] Add skeletons of algorithm and factory --- .../calorimetry/TrackClusterSubtraction.cc | 50 ++++++++ .../calorimetry/TrackClusterSubtraction.h | 119 ++++++++++++++++++ .../TrackClusterSubtractionConfig.h | 22 ++++ .../TrackClusterSubtraction_factory.h | 66 ++++++++++ 4 files changed, 257 insertions(+) create mode 100644 src/algorithms/calorimetry/TrackClusterSubtraction.cc create mode 100644 src/algorithms/calorimetry/TrackClusterSubtraction.h create mode 100644 src/algorithms/calorimetry/TrackClusterSubtractionConfig.h create mode 100644 src/factories/calorimetry/TrackClusterSubtraction_factory.h diff --git a/src/algorithms/calorimetry/TrackClusterSubtraction.cc b/src/algorithms/calorimetry/TrackClusterSubtraction.cc new file mode 100644 index 0000000000..4939f1d66a --- /dev/null +++ b/src/algorithms/calorimetry/TrackClusterSubtraction.cc @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (C) 2024 Derek Anderson + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// algorithm definition +#include "TrackClusterSubtraction.h" +#include "algorithms/calorimetry/TrackClusterSubtractionConfig.h" + + + +namespace eicrecon { + + // -------------------------------------------------------------------------- + //! Initialize algorithm + // -------------------------------------------------------------------------- + void TrackClusterSubtraction::init(const dd4hep::Detector* detector) { + + // grab detector id + m_idCalo = detector -> constant(m_cfg.idCalo); + debug("Collecting projections to detector with system id {}", m_idCalo); + + } // end 'init(dd4hep::Detector*)' + + + + // -------------------------------------------------------------------------- + //! Process inputs + // -------------------------------------------------------------------------- + /*! TODO fill in + */ + void TrackClusterSubtraction::process( + const TrackClusterSubtraction::Input& input, + const TrackClusterSubtraction::Output& output + ) const { + + /* TODO fill in */ + + } // end 'get_projections(edm4eic::CalorimeterHit&, edm4eic::TrackSegmentCollection&, VecTrkPoint&)' + +} // end eicrecon namespace diff --git a/src/algorithms/calorimetry/TrackClusterSubtraction.h b/src/algorithms/calorimetry/TrackClusterSubtraction.h new file mode 100644 index 0000000000..42e00dde27 --- /dev/null +++ b/src/algorithms/calorimetry/TrackClusterSubtraction.h @@ -0,0 +1,119 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (C) 2024 Derek Anderson + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// for algorithm configuration +#include "TrackClusterSubtractionConfig.h" +#include "algorithms/interfaces/WithPodConfig.h" + + + +namespace eicrecon { + + // -------------------------------------------------------------------------- + //! Comparator struct for clusters + // -------------------------------------------------------------------------- + /*! Organizes protoclusters by their ObjectID's in decreasing collection + * ID first, and second by decreasing index second. + * + * TODO order by energy first,then by objectID + */ + struct CompareCluster { + + bool operator() (const edm4eic::Cluster& lhs, const edm4eic::Cluster& rhs) const { + if (lhs.getObjectID().collectionID == rhs.getObjectID().collectionID) { + return (lhs.getObjectID().index < rhs.getObjectID().index); + } else { + return (lhs.getObjectID().collectionID < rhs.getObjectID().collectionID); + } + } + + }; // end CompareCluster + + + + // -------------------------------------------------------------------------- + //! Convenience types + // -------------------------------------------------------------------------- + using VecProj = std::vector; + using VecClust = std::vector; + using SetClust = std::set; + using MapToVecProj = std::map; + using MapToVecClust = std::map; + + + + // -------------------------------------------------------------------------- + //! Algorithm input/output + // -------------------------------------------------------------------------- + using TrackClusterSubtractionAlgorithm = algorithms::Algorithm< + algorithms::Input< + edm4eic::ClusterCollection, + edm4eic::ClusterCollection, + edm4eic::TrackSegmentCollection + >, + algorithms::Output< + edm4eic::ClusterCollection, + edm4eic::ClusterCollection + > + >; + + + + // -------------------------------------------------------------------------- + //! Track-Cluster Subtraction + // -------------------------------------------------------------------------- + /*! An algorithm which takes collections of EM and HCal clusters, matches + * track projections, subtracts the sum of the energy the projections + * to the clusters, and returns the remnants of the subtracted clusters. + */ + class TrackClusterSubtraction : + public TrackClusterSubtractionAlgorithm, + public WithPodConfig + { + + public: + + // ctor + TrackClusterSubtraction(std::string_view name) : + TrackClusterSubtractionAlgorithm { + name, + { + "InputEMCalClusterCollection", + "InputHCalClusterCollection", + "InputTrackProjections" + }, + {"OutputClusterCollection"}, + "Subtracts energy of tracks pointing to clusters." + } {} + + // public methods + void init(const dd4hep::Detector* detector); + void process (const Input&, const Output&) const final; + + private: + + // private methods + /* TODO fill in */ + + // calorimeter id + int m_idCalo {0}; + + }; // end TrackClusterSubtraction + +} // end eicrecon namespace diff --git a/src/algorithms/calorimetry/TrackClusterSubtractionConfig.h b/src/algorithms/calorimetry/TrackClusterSubtractionConfig.h new file mode 100644 index 0000000000..47573840ec --- /dev/null +++ b/src/algorithms/calorimetry/TrackClusterSubtractionConfig.h @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (C) 2024 Derek Anderson + +#pragma once + +#include + +namespace eicrecon { + + struct TrackClusterSubtractionConfig { + + std::string idCalo = "HcalBarrel_ID"; // id of calorimeter to match projections to + + /* TODO parameters will go here */ + + // scale for hit-track distance + double transverseEnergyProfileScale = 1.0; + + }; // end TrackClusterSubtractionConfig + +} // end eicrecon namespace + diff --git a/src/factories/calorimetry/TrackClusterSubtraction_factory.h b/src/factories/calorimetry/TrackClusterSubtraction_factory.h new file mode 100644 index 0000000000..f38cc77898 --- /dev/null +++ b/src/factories/calorimetry/TrackClusterSubtraction_factory.h @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (C) 2024 Derek Anderson + +#pragma once + +// c++ utilities +#include +// dd4hep utilities +#include +// eicrecon components +#include "extensions/jana/JOmniFactory.h" +#include "services/geometry/dd4hep/DD4hep_service.h" +#include "services/algorithms_init/AlgorithmsInit_service.h" +#include "algorithms/calorimetry/TrackClusterSubtraction.h" + +namespace eicrecon { + + class TrackClusterSubtraction_factory : public JOmniFactory { + + public: + + using AlgoT = eicrecon::TrackClusterSubtraction; + + private: + + // algorithm to run + std::unique_ptr m_algo; + + // input collections + PodioInput m_emclusters_input {this}; + PodioInput m_hclusters_input {this}; + PodioInput m_track_projections_input {this}; + + // output collections + PodioOutput m_emclusters_output {this}; + PodioOutput m_hclusters_output {this}; + + // parameter bindings + /* TODO fill in */ + + // services + Service m_geoSvc {this}; + Service m_algoInitSvc {this}; + + public: + + void Configure() { + m_algo = std::make_unique(GetPrefix()); + m_algo->applyConfig( config() ); + m_algo->init(m_geoSvc().detector()); + } + + void ChangeRun(int64_t run_number) { + /* nothing to do here */ + } + + void Process(int64_t run_number, uint64_t event_number) { + m_algo->process( + {m_emclusters_input(), m_hclusters_input(), m_track_projections_input()}, + {m_emclusters_output().get(), m_hclusters_output().get()} + ); + } + + }; // end TrackClusterSubtraction_factory + +} // end eicrecon namespace From 7236ad977848690dd2f99fcf4b92f936e69e88b9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 8 Oct 2024 04:37:26 +0000 Subject: [PATCH 02/46] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/algorithms/calorimetry/TrackClusterSubtractionConfig.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/algorithms/calorimetry/TrackClusterSubtractionConfig.h b/src/algorithms/calorimetry/TrackClusterSubtractionConfig.h index 47573840ec..b906e0bccd 100644 --- a/src/algorithms/calorimetry/TrackClusterSubtractionConfig.h +++ b/src/algorithms/calorimetry/TrackClusterSubtractionConfig.h @@ -19,4 +19,3 @@ namespace eicrecon { }; // end TrackClusterSubtractionConfig } // end eicrecon namespace - From 4728ac12beb5280af7964eb7ff43f87a593ab2e2 Mon Sep 17 00:00:00 2001 From: ruse-traveler Date: Sat, 22 Feb 2025 03:56:47 -0500 Subject: [PATCH 03/46] Propagate upstream changes from development fork --- src/algorithms/CMakeLists.txt | 1 + .../calorimetry/TrackClusterSubtraction.cc | 50 ------- .../calorimetry/TrackClusterSubtraction.h | 119 --------------- .../TrackClusterSubtractionConfig.h | 22 --- src/algorithms/particle/CMakeLists.txt | 18 +++ src/algorithms/particle/PFTools.h | 61 ++++++++ .../particle/TrackClusterSubtractor.cc | 136 ++++++++++++++++++ .../particle/TrackClusterSubtractor.h | 79 ++++++++++ .../particle/TrackClusterSubtractorConfig.h | 17 +++ src/factories/CMakeLists.txt | 1 + src/factories/particle/CMakeLists.txt | 2 + .../TrackClusterSubtractor_factory.h} | 29 ++-- 12 files changed, 330 insertions(+), 205 deletions(-) delete mode 100644 src/algorithms/calorimetry/TrackClusterSubtraction.cc delete mode 100644 src/algorithms/calorimetry/TrackClusterSubtraction.h delete mode 100644 src/algorithms/calorimetry/TrackClusterSubtractionConfig.h create mode 100644 src/algorithms/particle/CMakeLists.txt create mode 100644 src/algorithms/particle/PFTools.h create mode 100644 src/algorithms/particle/TrackClusterSubtractor.cc create mode 100644 src/algorithms/particle/TrackClusterSubtractor.h create mode 100644 src/algorithms/particle/TrackClusterSubtractorConfig.h create mode 100644 src/factories/particle/CMakeLists.txt rename src/factories/{calorimetry/TrackClusterSubtraction_factory.h => particle/TrackClusterSubtractor_factory.h} (53%) diff --git a/src/algorithms/CMakeLists.txt b/src/algorithms/CMakeLists.txt index 9adcb8fb49..ebebfd4699 100644 --- a/src/algorithms/CMakeLists.txt +++ b/src/algorithms/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.16) add_subdirectory(interfaces) add_subdirectory(calorimetry) add_subdirectory(tracking) +add_subdirectory(particle) add_subdirectory(pid) add_subdirectory(pid_lut) add_subdirectory(digi) diff --git a/src/algorithms/calorimetry/TrackClusterSubtraction.cc b/src/algorithms/calorimetry/TrackClusterSubtraction.cc deleted file mode 100644 index 4939f1d66a..0000000000 --- a/src/algorithms/calorimetry/TrackClusterSubtraction.cc +++ /dev/null @@ -1,50 +0,0 @@ -// SPDX-License-Identifier: LGPL-3.0-or-later -// Copyright (C) 2024 Derek Anderson - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// algorithm definition -#include "TrackClusterSubtraction.h" -#include "algorithms/calorimetry/TrackClusterSubtractionConfig.h" - - - -namespace eicrecon { - - // -------------------------------------------------------------------------- - //! Initialize algorithm - // -------------------------------------------------------------------------- - void TrackClusterSubtraction::init(const dd4hep::Detector* detector) { - - // grab detector id - m_idCalo = detector -> constant(m_cfg.idCalo); - debug("Collecting projections to detector with system id {}", m_idCalo); - - } // end 'init(dd4hep::Detector*)' - - - - // -------------------------------------------------------------------------- - //! Process inputs - // -------------------------------------------------------------------------- - /*! TODO fill in - */ - void TrackClusterSubtraction::process( - const TrackClusterSubtraction::Input& input, - const TrackClusterSubtraction::Output& output - ) const { - - /* TODO fill in */ - - } // end 'get_projections(edm4eic::CalorimeterHit&, edm4eic::TrackSegmentCollection&, VecTrkPoint&)' - -} // end eicrecon namespace diff --git a/src/algorithms/calorimetry/TrackClusterSubtraction.h b/src/algorithms/calorimetry/TrackClusterSubtraction.h deleted file mode 100644 index 42e00dde27..0000000000 --- a/src/algorithms/calorimetry/TrackClusterSubtraction.h +++ /dev/null @@ -1,119 +0,0 @@ -// SPDX-License-Identifier: LGPL-3.0-or-later -// Copyright (C) 2024 Derek Anderson - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// for algorithm configuration -#include "TrackClusterSubtractionConfig.h" -#include "algorithms/interfaces/WithPodConfig.h" - - - -namespace eicrecon { - - // -------------------------------------------------------------------------- - //! Comparator struct for clusters - // -------------------------------------------------------------------------- - /*! Organizes protoclusters by their ObjectID's in decreasing collection - * ID first, and second by decreasing index second. - * - * TODO order by energy first,then by objectID - */ - struct CompareCluster { - - bool operator() (const edm4eic::Cluster& lhs, const edm4eic::Cluster& rhs) const { - if (lhs.getObjectID().collectionID == rhs.getObjectID().collectionID) { - return (lhs.getObjectID().index < rhs.getObjectID().index); - } else { - return (lhs.getObjectID().collectionID < rhs.getObjectID().collectionID); - } - } - - }; // end CompareCluster - - - - // -------------------------------------------------------------------------- - //! Convenience types - // -------------------------------------------------------------------------- - using VecProj = std::vector; - using VecClust = std::vector; - using SetClust = std::set; - using MapToVecProj = std::map; - using MapToVecClust = std::map; - - - - // -------------------------------------------------------------------------- - //! Algorithm input/output - // -------------------------------------------------------------------------- - using TrackClusterSubtractionAlgorithm = algorithms::Algorithm< - algorithms::Input< - edm4eic::ClusterCollection, - edm4eic::ClusterCollection, - edm4eic::TrackSegmentCollection - >, - algorithms::Output< - edm4eic::ClusterCollection, - edm4eic::ClusterCollection - > - >; - - - - // -------------------------------------------------------------------------- - //! Track-Cluster Subtraction - // -------------------------------------------------------------------------- - /*! An algorithm which takes collections of EM and HCal clusters, matches - * track projections, subtracts the sum of the energy the projections - * to the clusters, and returns the remnants of the subtracted clusters. - */ - class TrackClusterSubtraction : - public TrackClusterSubtractionAlgorithm, - public WithPodConfig - { - - public: - - // ctor - TrackClusterSubtraction(std::string_view name) : - TrackClusterSubtractionAlgorithm { - name, - { - "InputEMCalClusterCollection", - "InputHCalClusterCollection", - "InputTrackProjections" - }, - {"OutputClusterCollection"}, - "Subtracts energy of tracks pointing to clusters." - } {} - - // public methods - void init(const dd4hep::Detector* detector); - void process (const Input&, const Output&) const final; - - private: - - // private methods - /* TODO fill in */ - - // calorimeter id - int m_idCalo {0}; - - }; // end TrackClusterSubtraction - -} // end eicrecon namespace diff --git a/src/algorithms/calorimetry/TrackClusterSubtractionConfig.h b/src/algorithms/calorimetry/TrackClusterSubtractionConfig.h deleted file mode 100644 index 47573840ec..0000000000 --- a/src/algorithms/calorimetry/TrackClusterSubtractionConfig.h +++ /dev/null @@ -1,22 +0,0 @@ -// SPDX-License-Identifier: LGPL-3.0-or-later -// Copyright (C) 2024 Derek Anderson - -#pragma once - -#include - -namespace eicrecon { - - struct TrackClusterSubtractionConfig { - - std::string idCalo = "HcalBarrel_ID"; // id of calorimeter to match projections to - - /* TODO parameters will go here */ - - // scale for hit-track distance - double transverseEnergyProfileScale = 1.0; - - }; // end TrackClusterSubtractionConfig - -} // end eicrecon namespace - diff --git a/src/algorithms/particle/CMakeLists.txt b/src/algorithms/particle/CMakeLists.txt new file mode 100644 index 0000000000..9075ac6dac --- /dev/null +++ b/src/algorithms/particle/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 3.16) + +set(PLUGIN_NAME "algorithms_particle") + +# Function creates ${PLUGIN_NAME}_plugin and ${PLUGIN_NAME}_library targets +# Setting default includes, libraries and installation paths +plugin_add(${PLUGIN_NAME} WITH_SHARED_LIBRARY WITHOUT_PLUGIN) + +# The macro grabs sources as *.cc *.cpp *.c and headers as *.h *.hh *.hpp Then +# correctly sets sources for ${_name}_plugin and ${_name}_library targets Adds +# headers to the correct installation directory +plugin_glob_all(${PLUGIN_NAME}) + +# Find dependencies +plugin_add_algorithms(${PLUGIN_NAME}) +plugin_add_dd4hep(${PLUGIN_NAME}) +plugin_add_event_model(${PLUGIN_NAME}) +plugin_add_eigen3(${PLUGIN_NAME}) diff --git a/src/algorithms/particle/PFTools.h b/src/algorithms/particle/PFTools.h new file mode 100644 index 0000000000..8eebff75d2 --- /dev/null +++ b/src/algorithms/particle/PFTools.h @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (C) 2025 Derek Anderson + +#pragma once + +#include +#include +#include +#include +#include +#include + + + +namespace eicrecon { + + // -------------------------------------------------------------------------- + //! Particle Flow tools namespace + // -------------------------------------------------------------------------- + /*! This namespace collects a variety of useful types and methods + * used throughout particle flow algorithms. + */ + namespace PFTools { + + // ------------------------------------------------------------------------ + //! Comparator struct for clusters + // ------------------------------------------------------------------------ + /*! Organizes protoclusters by their ObjectID's in decreasing collection + * ID first, and second by decreasing index second. + * + * TODO should also order by energy... + */ + struct CompareClust { + + bool operator() (const edm4eic::Cluster& lhs, const edm4eic::Cluster& rhs) const { + if (lhs.getObjectID().collectionID == rhs.getObjectID().collectionID) { + return (lhs.getObjectID().index < rhs.getObjectID().index); + } else { + return (lhs.getObjectID().collectionID < rhs.getObjectID().collectionID); + } + } + + }; // end CompareCluster + + + + // ------------------------------------------------------------------------ + //! Convenience types + // ------------------------------------------------------------------------ + typedef std::vector> MatrixF; + typedef std::vector VecMatrixF; + typedef std::vector VecTrk; + typedef std::vector VecProj; + typedef std::vector VecClust; + typedef std::set SetClust; + typedef std::map MapToVecTrk; + typedef std::map MapToVecProj; + typedef std::map MapToVecClust; + + } // end PFTools namespace +} // end eicrecon namespace diff --git a/src/algorithms/particle/TrackClusterSubtractor.cc b/src/algorithms/particle/TrackClusterSubtractor.cc new file mode 100644 index 0000000000..1ad1c90fdb --- /dev/null +++ b/src/algorithms/particle/TrackClusterSubtractor.cc @@ -0,0 +1,136 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (C) 2024 Derek Anderson + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "TrackClusterSubtractor.h" +#include "algorithms/particle/TrackClusterSubtractorConfig.h" + + + +namespace eicrecon { + + // -------------------------------------------------------------------------- + //! Initialize algorithm + // -------------------------------------------------------------------------- + void TrackClusterSubtractor::init() { + + //... nothing to do ...// + + } // end 'init(dd4hep::Detector*)' + + + + // -------------------------------------------------------------------------- + //! Process inputs + // -------------------------------------------------------------------------- + /*! Subtract energy of matched tracks via the following algorithm. + * 1. Build a map of each cluster onto a list of matched + * track projections. + * 2. For each cluster, subtract the sum of momenta of + * all matched tracks scaled by the specified fraction + * from the cluster's energy. + * 3. If subtracted energy is greater than 0, copy cluster + * into output with new subtracted energy. + */ + void TrackClusterSubtractor::process( + const TrackClusterSubtractor::Input& input, + const TrackClusterSubtractor::Output& output + ) const { + + // grab inputs/outputs + const auto [in_matches, in_projections] = input; + auto [out_clusters, out_matches] = output; + + // exit if no matched tracks in collection + if (in_matches->size() == 0) { + debug("No matched tracks in collection."); + return; + } + + // ------------------------------------------------------------------------ + // 1. Build map of clusters onto projections + // ------------------------------------------------------------------------ + PFTools::MapToVecProj mapClustToProj; + for (const auto& match : *in_matches) { + for (const auto& project : *in_projections) { + + // pick out corresponding projection from track + if (match.getTrack() != project.getTrack()) { + continue; + } + + // locate relevant point to measure momentum + bool foundPoint = false; + for (const auto& point : project.getPoints()) { + + // pick out surface specified in configuration + if (point.surface != m_cfg.surfaceToUse) { + continue; + } + + // add to map and break + mapClustToProj[ match.getCluster() ].push_back(point); + break; + } + + // break if needed + if (foundPoint) { + break; + } + } // end projection loop + } // end track-cluster match loop + debug("Built map of clusters-onto-tracks, size = {}", mapClustToProj.size()); + + // lambda to sum momenta of matched tracks + // - FIXME should account for mass somehow... + auto sumMomenta = [](const PFTools::VecProj& projects) { + double sum = 0.; + for (const auto& project : projects) { + sum += edm4hep::utils::magnitude( project.momentum ); + } + return sum; + }; + + // ------------------------------------------------------------------------ + // 2. Subtract energy for tracks + // ------------------------------------------------------------------------ + // FIXME need to think: for charged particles, energy reconstruction + // should use only the portion of energy relevant to the charged + // track if there is something leftover after subtraction... + for (const auto& [cluster, projects] : mapClustToProj) { + + // do subtraction + const double eTrk = sumMomenta(projects); + const double eToSub = m_cfg.fracEnergyToSub * eTrk; + const double eSub = cluster.getEnergy() - eSub; + trace("Subtracted {} GeV from cluster with {} GeV", eToSub, cluster.getEnergy()); + + // if greater than 0, scale energy accordingly and + // write out remnant cluster + if (eSub <= 0.0) { + continue; + } + const double scale = eSub / cluster.getEnergy(); + + // update cluster energy + edm4eic::MutableCluster remnant_clust = cluster.clone(); + remnant_clust.setEnergy( scale * cluster.getEnergy() ); + out_clusters->push_back(remnant_clust); + trace("Create remnant cluster with {} GeV", remnant_clust.getEnergy()); + + } // end cluster-to-projections loop + debug("Finished subtraction, {} clusters leftover", out_clusters->size()); + + } // end 'get_projections(edm4eic::CalorimeterHit&, edm4eic::TrackSegmentCollection&, VecTrkPoint&)' + +} // end eicrecon namespace diff --git a/src/algorithms/particle/TrackClusterSubtractor.h b/src/algorithms/particle/TrackClusterSubtractor.h new file mode 100644 index 0000000000..a4f968e7b9 --- /dev/null +++ b/src/algorithms/particle/TrackClusterSubtractor.h @@ -0,0 +1,79 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (C) 2025 Derek Anderson + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "PFTools.h" +#include "TrackClusterSubtractorConfig.h" +#include "algorithms/interfaces/WithPodConfig.h" + + + +namespace eicrecon { + + // -------------------------------------------------------------------------- + //! Algorithm input/output + // -------------------------------------------------------------------------- + using TrackClusterSubtractorAlgorithm = algorithms::Algorithm< + algorithms::Input< + edm4eic::TrackClusterMatchCollection, + edm4eic::TrackSegmentCollection + >, + algorithms::Output< + edm4eic::ClusterCollection, + edm4eic::TrackClusterMatchCollection + > + >; + + + + // -------------------------------------------------------------------------- + //! Track-Cluster Subtraction + // -------------------------------------------------------------------------- + /*! An algorithm which takes a collection of clusters and their matched + * tracks, subtracts the sum of all tracks pointing to the cluster, + * and outputs the remnant cluster and their matched tracks. + */ + class TrackClusterSubtractor + : public TrackClusterSubtractorAlgorithm + , public WithPodConfig + { + + public: + + // ctor + TrackClusterSubtractor(std::string_view name) : + TrackClusterSubtractorAlgorithm { + name, + {"InputTrackClusterMatches", "InputTrackProjections"}, + {"OutputClusterCollection", "OutputTrackClusterMatches"}, + "Subtracts energy of tracks pointing to clusters." + } {} + + // public methods + void init(); + void process (const Input&, const Output&) const final; + + private: + + // private methods + /* TODO fill in */ + + }; // end TrackClusterSubtractor + +} // end eicrecon namespace diff --git a/src/algorithms/particle/TrackClusterSubtractorConfig.h b/src/algorithms/particle/TrackClusterSubtractorConfig.h new file mode 100644 index 0000000000..3d31ef54fa --- /dev/null +++ b/src/algorithms/particle/TrackClusterSubtractorConfig.h @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (C) 2025 Derek Anderson + +#pragma once + +#include + +namespace eicrecon { + + struct TrackClusterSubtractorConfig { + + uint64_t surfaceToUse = 1; // index of surface to use for projections + double fracEnergyToSub = 1.0; // fraction of energy to subtract + + }; // end TrackClusterSubtractorConfig + +} // end eicrecon namespace diff --git a/src/factories/CMakeLists.txt b/src/factories/CMakeLists.txt index c4934b6e50..13e01c1a22 100644 --- a/src/factories/CMakeLists.txt +++ b/src/factories/CMakeLists.txt @@ -1,5 +1,6 @@ add_subdirectory(calorimetry) add_subdirectory(digi) add_subdirectory(fardetectors) +add_subdirectory(particle) add_subdirectory(tracking) add_subdirectory(meta) diff --git a/src/factories/particle/CMakeLists.txt b/src/factories/particle/CMakeLists.txt new file mode 100644 index 0000000000..591839f6df --- /dev/null +++ b/src/factories/particle/CMakeLists.txt @@ -0,0 +1,2 @@ +set(PLUGIN_NAME "factories_particle") +plugin_headers_only(${PLUGIN_NAME}) diff --git a/src/factories/calorimetry/TrackClusterSubtraction_factory.h b/src/factories/particle/TrackClusterSubtractor_factory.h similarity index 53% rename from src/factories/calorimetry/TrackClusterSubtraction_factory.h rename to src/factories/particle/TrackClusterSubtractor_factory.h index f38cc77898..73713de3c4 100644 --- a/src/factories/calorimetry/TrackClusterSubtraction_factory.h +++ b/src/factories/particle/TrackClusterSubtractor_factory.h @@ -11,15 +11,17 @@ #include "extensions/jana/JOmniFactory.h" #include "services/geometry/dd4hep/DD4hep_service.h" #include "services/algorithms_init/AlgorithmsInit_service.h" -#include "algorithms/calorimetry/TrackClusterSubtraction.h" +#include "algorithms/particle/TrackClusterSubtractor.h" namespace eicrecon { - class TrackClusterSubtraction_factory : public JOmniFactory { + class TrackClusterSubtractor_factory + : public JOmniFactory + { public: - using AlgoT = eicrecon::TrackClusterSubtraction; + using AlgoT = eicrecon::TrackClusterSubtractor; private: @@ -27,19 +29,18 @@ namespace eicrecon { std::unique_ptr m_algo; // input collections - PodioInput m_emclusters_input {this}; - PodioInput m_hclusters_input {this}; + PodioInput m_track_cluster_match_input {this}; PodioInput m_track_projections_input {this}; // output collections - PodioOutput m_emclusters_output {this}; - PodioOutput m_hclusters_output {this}; + PodioOutput m_clusters_output {this}; + PodioOutput m_track_cluster_match_output {this}; // parameter bindings - /* TODO fill in */ + ParameterRef m_surfaceToUse {this, "surfaceToUse", config().surfaceToUse}; + ParameterRef m_fracEnergyToSub {this, "fracEnergyToSub", config().fracEnergyToSub}; // services - Service m_geoSvc {this}; Service m_algoInitSvc {this}; public: @@ -47,20 +48,20 @@ namespace eicrecon { void Configure() { m_algo = std::make_unique(GetPrefix()); m_algo->applyConfig( config() ); - m_algo->init(m_geoSvc().detector()); + m_algo->init(); } void ChangeRun(int64_t run_number) { - /* nothing to do here */ + //... nothing to do ...// } void Process(int64_t run_number, uint64_t event_number) { m_algo->process( - {m_emclusters_input(), m_hclusters_input(), m_track_projections_input()}, - {m_emclusters_output().get(), m_hclusters_output().get()} + {m_track_cluster_match_input(), m_track_projections_input()}, + {m_clusters_output().get(), m_track_cluster_match_output().get()} ); } - }; // end TrackClusterSubtraction_factory + }; // end TrackClusterSubtractor_factory } // end eicrecon namespace From fb5a20256601853d350bd741e1b48e7e6c2fe97e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 22 Feb 2025 08:58:35 +0000 Subject: [PATCH 04/46] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/algorithms/particle/PFTools.h | 4 ++-- src/algorithms/particle/TrackClusterSubtractor.cc | 6 +++--- src/algorithms/particle/TrackClusterSubtractor.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/algorithms/particle/PFTools.h b/src/algorithms/particle/PFTools.h index 8eebff75d2..65ef99e093 100644 --- a/src/algorithms/particle/PFTools.h +++ b/src/algorithms/particle/PFTools.h @@ -18,8 +18,8 @@ namespace eicrecon { //! Particle Flow tools namespace // -------------------------------------------------------------------------- /*! This namespace collects a variety of useful types and methods - * used throughout particle flow algorithms. - */ + * used throughout particle flow algorithms. + */ namespace PFTools { // ------------------------------------------------------------------------ diff --git a/src/algorithms/particle/TrackClusterSubtractor.cc b/src/algorithms/particle/TrackClusterSubtractor.cc index 1ad1c90fdb..78090a7a63 100644 --- a/src/algorithms/particle/TrackClusterSubtractor.cc +++ b/src/algorithms/particle/TrackClusterSubtractor.cc @@ -76,9 +76,9 @@ namespace eicrecon { // pick out surface specified in configuration if (point.surface != m_cfg.surfaceToUse) { continue; - } + } - // add to map and break + // add to map and break mapClustToProj[ match.getCluster() ].push_back(point); break; } @@ -103,7 +103,7 @@ namespace eicrecon { // ------------------------------------------------------------------------ // 2. Subtract energy for tracks - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ // FIXME need to think: for charged particles, energy reconstruction // should use only the portion of energy relevant to the charged // track if there is something leftover after subtraction... diff --git a/src/algorithms/particle/TrackClusterSubtractor.h b/src/algorithms/particle/TrackClusterSubtractor.h index a4f968e7b9..3f028f05b6 100644 --- a/src/algorithms/particle/TrackClusterSubtractor.h +++ b/src/algorithms/particle/TrackClusterSubtractor.h @@ -47,7 +47,7 @@ namespace eicrecon { // -------------------------------------------------------------------------- /*! An algorithm which takes a collection of clusters and their matched * tracks, subtracts the sum of all tracks pointing to the cluster, - * and outputs the remnant cluster and their matched tracks. + * and outputs the remnant cluster and their matched tracks. */ class TrackClusterSubtractor : public TrackClusterSubtractorAlgorithm From d611fe69c383bf1ab95513c8816e64a79b850a4f Mon Sep 17 00:00:00 2001 From: ruse-traveler Date: Sun, 23 Feb 2025 02:41:43 -0500 Subject: [PATCH 05/46] Load particle plugin --- src/utilities/eicrecon/eicrecon.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utilities/eicrecon/eicrecon.cc b/src/utilities/eicrecon/eicrecon.cc index e8c75c6948..bcf52b58ac 100644 --- a/src/utilities/eicrecon/eicrecon.cc +++ b/src/utilities/eicrecon/eicrecon.cc @@ -24,6 +24,7 @@ std::vector EICRECON_DEFAULT_PLUGINS = { "beam", "reco", "tracking", + "particle", "pid", "EEMC", "BEMC", From 21186d678387867829ab2127f5f44e516e62ecb3 Mon Sep 17 00:00:00 2001 From: ruse-traveler Date: Sun, 23 Feb 2025 04:15:54 -0500 Subject: [PATCH 06/46] Use track PDGs for masses --- src/algorithms/particle/PFTools.h | 2 + .../particle/TrackClusterSubtractor.cc | 80 +++++++++++-------- .../particle/TrackClusterSubtractor.h | 9 ++- .../particle/TrackClusterSubtractorConfig.h | 5 +- .../particle/TrackClusterSubtractor_factory.h | 3 +- 5 files changed, 61 insertions(+), 38 deletions(-) diff --git a/src/algorithms/particle/PFTools.h b/src/algorithms/particle/PFTools.h index 8eebff75d2..fcc8f94d78 100644 --- a/src/algorithms/particle/PFTools.h +++ b/src/algorithms/particle/PFTools.h @@ -51,9 +51,11 @@ namespace eicrecon { typedef std::vector VecMatrixF; typedef std::vector VecTrk; typedef std::vector VecProj; + typedef std::vector VecSeg; typedef std::vector VecClust; typedef std::set SetClust; typedef std::map MapToVecTrk; + typedef std::map MapToVecSeg; typedef std::map MapToVecProj; typedef std::map MapToVecClust; diff --git a/src/algorithms/particle/TrackClusterSubtractor.cc b/src/algorithms/particle/TrackClusterSubtractor.cc index 1ad1c90fdb..9007d6a1d5 100644 --- a/src/algorithms/particle/TrackClusterSubtractor.cc +++ b/src/algorithms/particle/TrackClusterSubtractor.cc @@ -60,47 +60,21 @@ namespace eicrecon { // ------------------------------------------------------------------------ // 1. Build map of clusters onto projections // ------------------------------------------------------------------------ - PFTools::MapToVecProj mapClustToProj; + PFTools::MapToVecSeg mapClustToProj; for (const auto& match : *in_matches) { for (const auto& project : *in_projections) { // pick out corresponding projection from track if (match.getTrack() != project.getTrack()) { continue; + } else { + mapClustToProj[ match.getCluster() ].push_back( project ); } - // locate relevant point to measure momentum - bool foundPoint = false; - for (const auto& point : project.getPoints()) { - - // pick out surface specified in configuration - if (point.surface != m_cfg.surfaceToUse) { - continue; - } - - // add to map and break - mapClustToProj[ match.getCluster() ].push_back(point); - break; - } - - // break if needed - if (foundPoint) { - break; - } } // end projection loop } // end track-cluster match loop debug("Built map of clusters-onto-tracks, size = {}", mapClustToProj.size()); - // lambda to sum momenta of matched tracks - // - FIXME should account for mass somehow... - auto sumMomenta = [](const PFTools::VecProj& projects) { - double sum = 0.; - for (const auto& project : projects) { - sum += edm4hep::utils::magnitude( project.momentum ); - } - return sum; - }; - // ------------------------------------------------------------------------ // 2. Subtract energy for tracks // ------------------------------------------------------------------------ @@ -110,9 +84,9 @@ namespace eicrecon { for (const auto& [cluster, projects] : mapClustToProj) { // do subtraction - const double eTrk = sumMomenta(projects); - const double eToSub = m_cfg.fracEnergyToSub * eTrk; - const double eSub = cluster.getEnergy() - eSub; + const double eTrkSum = sum_track_energy(projects); + const double eToSub = m_cfg.fracEnergyToSub * eTrkSum; + const double eSub = cluster.getEnergy() - eToSub; trace("Subtracted {} GeV from cluster with {} GeV", eToSub, cluster.getEnergy()); // if greater than 0, scale energy accordingly and @@ -133,4 +107,46 @@ namespace eicrecon { } // end 'get_projections(edm4eic::CalorimeterHit&, edm4eic::TrackSegmentCollection&, VecTrkPoint&)' + + + // -------------------------------------------------------------------------- + //! Sum energy of tracks + // -------------------------------------------------------------------------- + /*! Sums energy of tracks projected to the surface in the + * calorimeter specified by `surfaceToUse`. Uses PDG of + * track to select mass for energy; if not available, + * uses mass set by `defaultMassPdg`. + */ + double TrackClusterSubtractor::sum_track_energy(const PFTools::VecSeg& projects) const { + + double eSum = 0.; + for (const auto& project : projects) { + + // measure momentum at specified surface + double momentum = 0.; + for (const auto& point : project.getPoints()) { + if (point.surface != m_cfg.surfaceToUse) { + continue; + } else { + momentum = edm4hep::utils::magnitude( point.momentum ); + break; + } + } + + // get mass based on track pdg + double mass = m_parSvc.particle(m_cfg.defaultMassPdg).mass; + if (project.getTrack().getPdg() != 0) { + mass = m_parSvc.particle(project.getTrack().getPdg()).mass; + } + + // increment sum + eSum += sqrt((momentum*momentum) + (mass*mass)); + } + + // output debugging and exit + trace("Sum of track energy = {} GeV", eSum); + return eSum; + + } // end 'Sum_track_energy(PFTools::VecSeg&)' + } // end eicrecon namespace diff --git a/src/algorithms/particle/TrackClusterSubtractor.h b/src/algorithms/particle/TrackClusterSubtractor.h index a4f968e7b9..e06031702c 100644 --- a/src/algorithms/particle/TrackClusterSubtractor.h +++ b/src/algorithms/particle/TrackClusterSubtractor.h @@ -20,10 +20,10 @@ #include "PFTools.h" #include "TrackClusterSubtractorConfig.h" +#include "algorithms/interfaces/ParticleSvc.h" #include "algorithms/interfaces/WithPodConfig.h" - namespace eicrecon { // -------------------------------------------------------------------------- @@ -67,12 +67,15 @@ namespace eicrecon { // public methods void init(); - void process (const Input&, const Output&) const final; + void process(const Input&, const Output&) const final; private: // private methods - /* TODO fill in */ + double sum_track_energy(const PFTools::VecSeg& projects) const; + + // services + const algorithms::ParticleSvc& m_parSvc = algorithms::ParticleSvc::instance(); }; // end TrackClusterSubtractor diff --git a/src/algorithms/particle/TrackClusterSubtractorConfig.h b/src/algorithms/particle/TrackClusterSubtractorConfig.h index 3d31ef54fa..b9531311d1 100644 --- a/src/algorithms/particle/TrackClusterSubtractorConfig.h +++ b/src/algorithms/particle/TrackClusterSubtractorConfig.h @@ -9,8 +9,9 @@ namespace eicrecon { struct TrackClusterSubtractorConfig { - uint64_t surfaceToUse = 1; // index of surface to use for projections - double fracEnergyToSub = 1.0; // fraction of energy to subtract + double fracEnergyToSub = 1.0; ///< fraction of track energy to subtract + int32_t defaultMassPdg = 211; ///< default mass to use for track energy + uint64_t surfaceToUse = 1; ///< index of surface to use for measuring momentum }; // end TrackClusterSubtractorConfig diff --git a/src/factories/particle/TrackClusterSubtractor_factory.h b/src/factories/particle/TrackClusterSubtractor_factory.h index 73713de3c4..b75a3c8730 100644 --- a/src/factories/particle/TrackClusterSubtractor_factory.h +++ b/src/factories/particle/TrackClusterSubtractor_factory.h @@ -37,8 +37,9 @@ namespace eicrecon { PodioOutput m_track_cluster_match_output {this}; // parameter bindings - ParameterRef m_surfaceToUse {this, "surfaceToUse", config().surfaceToUse}; ParameterRef m_fracEnergyToSub {this, "fracEnergyToSub", config().fracEnergyToSub}; + ParameterRef m_defaultMassPdg {this, "defaultMassPdg", config().defaultMassPdg}; + ParameterRef m_surfaceToUse {this, "surfaceToUse", config().surfaceToUse}; // services Service m_algoInitSvc {this}; From 0a4203a981765d2af11cdf2ec8c0eb408db851f0 Mon Sep 17 00:00:00 2001 From: ruse-traveler Date: Sun, 23 Feb 2025 05:01:24 -0500 Subject: [PATCH 07/46] Allow for checking zero against resolutions --- .../particle/TrackClusterSubtractor.cc | 52 +++++++++++++++++-- .../particle/TrackClusterSubtractor.h | 3 +- .../particle/TrackClusterSubtractorConfig.h | 8 +++ .../particle/TrackClusterSubtractor_factory.h | 4 ++ 4 files changed, 62 insertions(+), 5 deletions(-) diff --git a/src/algorithms/particle/TrackClusterSubtractor.cc b/src/algorithms/particle/TrackClusterSubtractor.cc index 16482e81c3..234c07c9b4 100644 --- a/src/algorithms/particle/TrackClusterSubtractor.cc +++ b/src/algorithms/particle/TrackClusterSubtractor.cc @@ -11,6 +11,7 @@ #include #include #include +#include #include "TrackClusterSubtractor.h" #include "algorithms/particle/TrackClusterSubtractorConfig.h" @@ -77,7 +78,7 @@ namespace eicrecon { // ------------------------------------------------------------------------ // 2. Subtract energy for tracks - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ // FIXME need to think: for charged particles, energy reconstruction // should use only the portion of energy relevant to the charged // track if there is something leftover after subtraction... @@ -91,7 +92,7 @@ namespace eicrecon { // if greater than 0, scale energy accordingly and // write out remnant cluster - if (eSub <= 0.0) { + if (is_zero(eSub)) { continue; } const double scale = eSub / cluster.getEnergy(); @@ -140,13 +141,56 @@ namespace eicrecon { } // increment sum - eSum += sqrt((momentum*momentum) + (mass*mass)); + eSum += std::sqrt((momentum*momentum) + (mass*mass)); } // output debugging and exit trace("Sum of track energy = {} GeV", eSum); return eSum; - } // end 'Sum_track_energy(PFTools::VecSeg&)' + } // end 'sum_track_energy(PFTools::VecSeg&)' + + + + // -------------------------------------------------------------------------- + //! Is difference consistent with zero? + // -------------------------------------------------------------------------- + /*! Checks if provided difference is consistent with zero, + * either checking if difference is within an epsilon + * (if `doNSigmaCut` is false), or if difference is within + * `nSigmaMax` of zero (if `doNSigmaCut` is true) based on + * the provided tracker and calorimeter resolutions. + */ + bool TrackClusterSubtractor::is_zero(const double difference) const { + + // if < 0, automatically return true + if (difference < 0) { + return true; + } + + // calculate nSigma + const double totReso = std::sqrt((m_cfg.trkReso*m_cfg.trkReso) + (m_cfg.calReso*m_cfg.calReso)); + const double nSigma = difference / totReso; + + // do appropriate comparison + bool isZero = false; + if (m_cfg.doNSigmaCut) { + isZero = (nSigma < m_cfg.nSigmaMax); + trace( + "Difference of {} GeV consistent with zero: nSigma = {} < {}", + difference, + nSigma, + m_cfg.nSigmaMax + ); + } else { + isZero = std::abs(difference) < std::numeric_limits::epsilon(); + trace( + "Difference of {} GeV consistent with zero within an epsilon", + difference + ); + } + return isZero; + + } // end 'is_zero(double)' } // end eicrecon namespace diff --git a/src/algorithms/particle/TrackClusterSubtractor.h b/src/algorithms/particle/TrackClusterSubtractor.h index 7c84951cbd..2764d215ce 100644 --- a/src/algorithms/particle/TrackClusterSubtractor.h +++ b/src/algorithms/particle/TrackClusterSubtractor.h @@ -47,7 +47,7 @@ namespace eicrecon { // -------------------------------------------------------------------------- /*! An algorithm which takes a collection of clusters and their matched * tracks, subtracts the sum of all tracks pointing to the cluster, - * and outputs the remnant cluster and their matched tracks. + * and outputs the remnant cluster and their matched tracks. */ class TrackClusterSubtractor : public TrackClusterSubtractorAlgorithm @@ -73,6 +73,7 @@ namespace eicrecon { // private methods double sum_track_energy(const PFTools::VecSeg& projects) const; + bool is_zero(const double difference) const; // services const algorithms::ParticleSvc& m_parSvc = algorithms::ParticleSvc::instance(); diff --git a/src/algorithms/particle/TrackClusterSubtractorConfig.h b/src/algorithms/particle/TrackClusterSubtractorConfig.h index b9531311d1..96d2092534 100644 --- a/src/algorithms/particle/TrackClusterSubtractorConfig.h +++ b/src/algorithms/particle/TrackClusterSubtractorConfig.h @@ -9,10 +9,18 @@ namespace eicrecon { struct TrackClusterSubtractorConfig { + // general parameters double fracEnergyToSub = 1.0; ///< fraction of track energy to subtract int32_t defaultMassPdg = 211; ///< default mass to use for track energy uint64_t surfaceToUse = 1; ///< index of surface to use for measuring momentum + // parameters for resolution-based + // comparison + bool doNSigmaCut = false; ///< turn on/off checking against resolutions + uint32_t nSigmaMax = 1; ///< max no. of sigma to be consistent w/ zero + double trkReso = 1.0; ///< tracking momentum resolution to use + double calReso = 1.0; ///< calorimeter energy resolution to use + }; // end TrackClusterSubtractorConfig } // end eicrecon namespace diff --git a/src/factories/particle/TrackClusterSubtractor_factory.h b/src/factories/particle/TrackClusterSubtractor_factory.h index b75a3c8730..639abc0bdd 100644 --- a/src/factories/particle/TrackClusterSubtractor_factory.h +++ b/src/factories/particle/TrackClusterSubtractor_factory.h @@ -40,6 +40,10 @@ namespace eicrecon { ParameterRef m_fracEnergyToSub {this, "fracEnergyToSub", config().fracEnergyToSub}; ParameterRef m_defaultMassPdg {this, "defaultMassPdg", config().defaultMassPdg}; ParameterRef m_surfaceToUse {this, "surfaceToUse", config().surfaceToUse}; + ParameterRef m_doNSigmaCut {this, "doNSigmaCut", config().doNSigmaCut}; + ParameterRef m_nSigmaMax {this, "nSigmaMax", config().nSigmaMax}; + ParameterRef m_trkReso {this, "trkReso", config().trkReso}; + ParameterRef m_calReso {this, "calReso", config().calReso}; // services Service m_algoInitSvc {this}; From df5646d7dec890bdafd3f92f1ccbc241245ad0eb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 23 Feb 2025 10:01:37 +0000 Subject: [PATCH 08/46] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/algorithms/particle/TrackClusterSubtractor.cc | 2 +- src/algorithms/particle/TrackClusterSubtractor.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/algorithms/particle/TrackClusterSubtractor.cc b/src/algorithms/particle/TrackClusterSubtractor.cc index 234c07c9b4..b526c2e809 100644 --- a/src/algorithms/particle/TrackClusterSubtractor.cc +++ b/src/algorithms/particle/TrackClusterSubtractor.cc @@ -78,7 +78,7 @@ namespace eicrecon { // ------------------------------------------------------------------------ // 2. Subtract energy for tracks - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ // FIXME need to think: for charged particles, energy reconstruction // should use only the portion of energy relevant to the charged // track if there is something leftover after subtraction... diff --git a/src/algorithms/particle/TrackClusterSubtractor.h b/src/algorithms/particle/TrackClusterSubtractor.h index 2764d215ce..0a9c9ad873 100644 --- a/src/algorithms/particle/TrackClusterSubtractor.h +++ b/src/algorithms/particle/TrackClusterSubtractor.h @@ -47,7 +47,7 @@ namespace eicrecon { // -------------------------------------------------------------------------- /*! An algorithm which takes a collection of clusters and their matched * tracks, subtracts the sum of all tracks pointing to the cluster, - * and outputs the remnant cluster and their matched tracks. + * and outputs the remnant cluster and their matched tracks. */ class TrackClusterSubtractor : public TrackClusterSubtractorAlgorithm From dcaed63133694b877248522e785f81e116ed4350 Mon Sep 17 00:00:00 2001 From: ruse-traveler Date: Sun, 23 Feb 2025 05:40:25 -0500 Subject: [PATCH 09/46] Write out all relevant collections --- .../particle/TrackClusterSubtractor.cc | 58 ++++++++++++++----- .../particle/TrackClusterSubtractor.h | 7 ++- .../particle/TrackClusterSubtractor_factory.h | 9 ++- 3 files changed, 54 insertions(+), 20 deletions(-) diff --git a/src/algorithms/particle/TrackClusterSubtractor.cc b/src/algorithms/particle/TrackClusterSubtractor.cc index 234c07c9b4..6a4018722d 100644 --- a/src/algorithms/particle/TrackClusterSubtractor.cc +++ b/src/algorithms/particle/TrackClusterSubtractor.cc @@ -50,7 +50,7 @@ namespace eicrecon { // grab inputs/outputs const auto [in_matches, in_projections] = input; - auto [out_clusters, out_matches] = output; + auto [out_sub_clusters, out_remain_clusters, out_sub_matches] = output; // exit if no matched tracks in collection if (in_matches->size() == 0) { @@ -79,9 +79,6 @@ namespace eicrecon { // ------------------------------------------------------------------------ // 2. Subtract energy for tracks // ------------------------------------------------------------------------ - // FIXME need to think: for charged particles, energy reconstruction - // should use only the portion of energy relevant to the charged - // track if there is something leftover after subtraction... for (const auto& [cluster, projects] : mapClustToProj) { // do subtraction @@ -90,21 +87,52 @@ namespace eicrecon { const double eSub = cluster.getEnergy() - eToSub; trace("Subtracted {} GeV from cluster with {} GeV", eToSub, cluster.getEnergy()); - // if greater than 0, scale energy accordingly and - // write out remnant cluster - if (is_zero(eSub)) { - continue; + // check if consistent with zero, + // set eSub accordingly + const bool isZero = is_zero(eSub); + const double eSubToUse = isZero ? 0. : eSub; + + // calculate energy fractions + const double remainFrac = eSubToUse / cluster.getEnergy(); + const double subtractFrac = 1. - remainFrac; + + // scale subtracted cluster energy + edm4eic::MutableCluster sub_clust = cluster.clone(); + sub_clust.setEnergy( subtractFrac * cluster.getEnergy() ); + out_sub_clusters->push_back(sub_clust); + trace( + "Created subtracted cluster with {} GeV (originally {} GeV)", + sub_clust.getEnergy(), + cluster.getEnergy() + ); + + // create track cluster matches + for (const auto& project : projects) { + edm4eic::MutableTrackClusterMatch match = out_sub_matches->create(); + match.setCluster( sub_clust ); + match.setTrack( project.getTrack() ); + match.setWeight( 1.0 ); // FIXME placeholder + trace( + "Matched subtracted cluster {} to track {}", + sub_clust.getObjectID().index, + project.getTrack().getObjectID().index + ); } - const double scale = eSub / cluster.getEnergy(); - // update cluster energy - edm4eic::MutableCluster remnant_clust = cluster.clone(); - remnant_clust.setEnergy( scale * cluster.getEnergy() ); - out_clusters->push_back(remnant_clust); - trace("Create remnant cluster with {} GeV", remnant_clust.getEnergy()); + // if NOT consistent with zero, write + // out remnant cluster + if (!isZero) { + edm4eic::MutableCluster remain_clust = cluster.clone(); + remain_clust.setEnergy( remainFrac * cluster.getEnergy() ); + out_remain_clusters->push_back(remain_clust); + trace( + "Created remnant cluster with {} GeV", + remain_clust.getEnergy() + ); + } } // end cluster-to-projections loop - debug("Finished subtraction, {} clusters leftover", out_clusters->size()); + debug("Finished subtraction, {} remnant clusters", out_remain_clusters->size()); } // end 'get_projections(edm4eic::CalorimeterHit&, edm4eic::TrackSegmentCollection&, VecTrkPoint&)' diff --git a/src/algorithms/particle/TrackClusterSubtractor.h b/src/algorithms/particle/TrackClusterSubtractor.h index 2764d215ce..7e32a65e49 100644 --- a/src/algorithms/particle/TrackClusterSubtractor.h +++ b/src/algorithms/particle/TrackClusterSubtractor.h @@ -35,6 +35,7 @@ namespace eicrecon { edm4eic::TrackSegmentCollection >, algorithms::Output< + edm4eic::ClusterCollection, edm4eic::ClusterCollection, edm4eic::TrackClusterMatchCollection > @@ -60,8 +61,10 @@ namespace eicrecon { TrackClusterSubtractor(std::string_view name) : TrackClusterSubtractorAlgorithm { name, - {"InputTrackClusterMatches", "InputTrackProjections"}, - {"OutputClusterCollection", "OutputTrackClusterMatches"}, + {"inputTrackClusterMatches", "inputTrackProjections"}, + {"outputSubtractedClusterCollection", + "outputRemnantClusterCollection", + "outputTrackSubtractedClusterMatches"}, "Subtracts energy of tracks pointing to clusters." } {} diff --git a/src/factories/particle/TrackClusterSubtractor_factory.h b/src/factories/particle/TrackClusterSubtractor_factory.h index 639abc0bdd..1369718efe 100644 --- a/src/factories/particle/TrackClusterSubtractor_factory.h +++ b/src/factories/particle/TrackClusterSubtractor_factory.h @@ -33,8 +33,9 @@ namespace eicrecon { PodioInput m_track_projections_input {this}; // output collections - PodioOutput m_clusters_output {this}; - PodioOutput m_track_cluster_match_output {this}; + PodioOutput m_subtract_clusters_output {this}; + PodioOutput m_remnant_clusters_output {this}; + PodioOutput m_track_sub_cluster_match_output {this}; // parameter bindings ParameterRef m_fracEnergyToSub {this, "fracEnergyToSub", config().fracEnergyToSub}; @@ -63,7 +64,9 @@ namespace eicrecon { void Process(int64_t run_number, uint64_t event_number) { m_algo->process( {m_track_cluster_match_input(), m_track_projections_input()}, - {m_clusters_output().get(), m_track_cluster_match_output().get()} + {m_subtract_clusters_output().get(), + m_remnant_clusters_output().get(), + m_track_sub_cluster_match_output().get()} ); } From 7bf428cee8dcb929a51c3de26a29f92b28b17404 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 23 Feb 2025 10:42:55 +0000 Subject: [PATCH 10/46] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/algorithms/particle/TrackClusterSubtractor.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/algorithms/particle/TrackClusterSubtractor.cc b/src/algorithms/particle/TrackClusterSubtractor.cc index 6a4018722d..fc0e9f7853 100644 --- a/src/algorithms/particle/TrackClusterSubtractor.cc +++ b/src/algorithms/particle/TrackClusterSubtractor.cc @@ -78,7 +78,7 @@ namespace eicrecon { // ------------------------------------------------------------------------ // 2. Subtract energy for tracks - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ for (const auto& [cluster, projects] : mapClustToProj) { // do subtraction From 5fc4ac4b0158dd5b0794a80f3ca667d65f4eb1c2 Mon Sep 17 00:00:00 2001 From: ruse-traveler Date: Tue, 11 Mar 2025 17:02:56 -0400 Subject: [PATCH 11/46] Add particle category to global reconstruction --- src/global/particle/CMakeLists.txt | 23 +++++ src/global/particle/particle.cc | 145 +++++++++++++++++++++++++++++ 2 files changed, 168 insertions(+) create mode 100644 src/global/particle/CMakeLists.txt create mode 100644 src/global/particle/particle.cc diff --git a/src/global/particle/CMakeLists.txt b/src/global/particle/CMakeLists.txt new file mode 100644 index 0000000000..e5c5509550 --- /dev/null +++ b/src/global/particle/CMakeLists.txt @@ -0,0 +1,23 @@ +# Automatically set plugin name the same as the directory name Don't forget +# string(REPLACE " " "_" PLUGIN_NAME ${PLUGIN_NAME}) if this dir has spaces in +# its name +get_filename_component(PLUGIN_NAME ${CMAKE_CURRENT_LIST_DIR} NAME) + +# Function creates ${PLUGIN_NAME}_plugin and ${PLUGIN_NAME}_library targets +# Setting default includes, libraries and installation paths +plugin_add(${PLUGIN_NAME}) + +# The macro grabs sources as *.cc *.cpp *.c and headers as *.h *.hh *.hpp Then +# correctly sets sources for ${_name}_plugin and ${_name}_library targets Adds +# headers to the correct installation directory +plugin_glob_all(${PLUGIN_NAME}) + +# Find dependencies +plugin_add_event_model(${PLUGIN_NAME}) +plugin_add_dd4hep(${PLUGIN_NAME}) + +# Add include directories (works same as target_include_directories) +# plugin_include_directories(${PLUGIN_NAME} SYSTEM PUBLIC ...) + +# Add libraries (works same as target_include_directories) +plugin_link_libraries(${PLUGIN_NAME} algorithms_particle_library) diff --git a/src/global/particle/particle.cc b/src/global/particle/particle.cc new file mode 100644 index 0000000000..32100ca16e --- /dev/null +++ b/src/global/particle/particle.cc @@ -0,0 +1,145 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (C) 2024 Derek Anderson + +#include +#include +#include +#include + +#include "extensions/jana/JOmniFactoryGeneratorT.h" +#include "factories/particle/TrackClusterMergeSplitter_factory.h" +#include "factories/particle/TrackClusterSubtractor_factory.h" + +extern "C" { + + void InitPlugin(JApplication *app) { + + using namespace eicrecon; + + InitJANAPlugin(app); + + // ==================================================================== + // PFAlpha: baseline PF implementation + // ==================================================================== + + // -------------------------------------------------------------------- + // PFA (0) connection: split/merge clusters accordingly + // -------------------------------------------------------------------- + + /* TODO move here when ready */ + + // -------------------------------------------------------------------- + // PFA (1a) arbitration: apply track correction to clusters + // -------------------------------------------------------------------- + + // backward ----------------------------------------------------------- + + app->Add( + new JOmniFactoryGeneratorT( + "EcalEndcapNSubtractedClusters", + {"EcalEndcapNTrackSplitMergeClusterMatches", + "CalorimeterTrackProjections"}, + {"EcalEndcapNSubtractedClusters", + "EcalEndcapNRemnantClusters", + "EcalEndcapNTrackSubtractedClusterMatches"}, + { + .fracEnergyToSub = 1.0, + .defaultMassPdg = 211, + .surfaceToUse = 1, + }, + app // TODO: remove me once fixed + ) + ); + + app->Add( + new JOmniFactoryGeneratorT( + "HcalEndcapNSubtractedClusters", + {"HcalEndcapNTrackSplitMergeClusterMatches", + "CalorimeterTrackProjections"}, + {"HcalEndcapNSubtractedClusters", + "HcalEndcapNRemnantClusters", + "HcalEndcapNTrackSubtractedClusterMatches"}, + { + .fracEnergyToSub = 1.0, + .defaultMassPdg = 211, + .surfaceToUse = 1 + }, + app // TODO: remove me once fixed + ) + ); + + // central ------------------------------------------------------------ + + app->Add( + new JOmniFactoryGeneratorT( + "HcalBarrelSubtractedClusters", + {"HcalBarrelTrackSplitMergeClusterMatches", + "CalorimeterTrackProjections"}, + {"HcalBarrelSubtractedClusters", + "HcalBarrelRemnantClusters", + "HcalBarrelTrackSubtractedClusterMatches"}, + { + .fracEnergyToSub = 1.0, + .defaultMassPdg = 211, + .surfaceToUse = 1 + }, + app // TODO: remove me once fixed + ) + ); + + // forward ------------------------------------------------------------ + + app->Add( + new JOmniFactoryGeneratorT( + "EcalEndcapPSubtractedClusters", + {"EcalEndcapPTrackSplitMergeClusterMatches", + "CalorimeterTrackProjections"}, + {"EcalEndcapPSubtractedClusters", + "EcalEndcapPRemnantClusters", + "EcalEndcapPTrackSubtractedClusterMatches"}, + { + .fracEnergyToSub = 1.0, + .defaultMassPdg = 211, + .surfaceToUse = 1 + }, + app // TODO: remove me once fixed + ) + ); + + app->Add( + new JOmniFactoryGeneratorT( + "LFHCALSubtractedClusters", + {"LFHCALTrackSplitMergeClusterMatches", + "CalorimeterTrackProjections"}, + {"LFHCALSubtractedClusters", + "LFHCALRemnantClusters", + "LFHCALTrackSubtractedClusterMatches"}, + { + .fracEnergyToSub = 1.0, + .defaultMassPdg = 211, + .surfaceToUse = 1 + }, + app // TODO: remove me once fixed + ) + ); + + // -------------------------------------------------------------------- + // PFA (1b) arbitration: form charged candidates + // -------------------------------------------------------------------- + + /* TODO add here */ + + // -------------------------------------------------------------------- + // PFA (2) arbitration: combine remnants, form neutral candidates + // -------------------------------------------------------------------- + + /* TODO add here */ + + // -------------------------------------------------------------------- + // PFA (3) regression: convert candidates to reco particles + // -------------------------------------------------------------------- + + /* TODO add here */ + + } +} From 87204cbe56bc3c90e300557a046387c72385b49d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 26 Aug 2025 18:36:43 +0000 Subject: [PATCH 12/46] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/algorithms/particle/PFTools.h | 78 ++--- .../particle/TrackClusterSubtractor.cc | 317 ++++++++---------- .../particle/TrackClusterSubtractor.h | 96 +++--- .../particle/TrackClusterSubtractorConfig.h | 26 +- .../particle/TrackClusterSubtractor_factory.h | 109 +++--- src/global/particle/particle.cc | 222 +++++------- 6 files changed, 379 insertions(+), 469 deletions(-) diff --git a/src/algorithms/particle/PFTools.h b/src/algorithms/particle/PFTools.h index f46cd7d47e..ce852cc2f6 100644 --- a/src/algorithms/particle/PFTools.h +++ b/src/algorithms/particle/PFTools.h @@ -10,54 +10,50 @@ #include #include - - namespace eicrecon { - // -------------------------------------------------------------------------- - //! Particle Flow tools namespace - // -------------------------------------------------------------------------- - /*! This namespace collects a variety of useful types and methods +// -------------------------------------------------------------------------- +//! Particle Flow tools namespace +// -------------------------------------------------------------------------- +/*! This namespace collects a variety of useful types and methods * used throughout particle flow algorithms. */ - namespace PFTools { +namespace PFTools { - // ------------------------------------------------------------------------ - //! Comparator struct for clusters - // ------------------------------------------------------------------------ - /*! Organizes protoclusters by their ObjectID's in decreasing collection + // ------------------------------------------------------------------------ + //! Comparator struct for clusters + // ------------------------------------------------------------------------ + /*! Organizes protoclusters by their ObjectID's in decreasing collection * ID first, and second by decreasing index second. * * TODO should also order by energy... */ - struct CompareClust { - - bool operator() (const edm4eic::Cluster& lhs, const edm4eic::Cluster& rhs) const { - if (lhs.getObjectID().collectionID == rhs.getObjectID().collectionID) { - return (lhs.getObjectID().index < rhs.getObjectID().index); - } else { - return (lhs.getObjectID().collectionID < rhs.getObjectID().collectionID); - } - } - - }; // end CompareCluster + struct CompareClust { - - - // ------------------------------------------------------------------------ - //! Convenience types - // ------------------------------------------------------------------------ - typedef std::vector> MatrixF; - typedef std::vector VecMatrixF; - typedef std::vector VecTrk; - typedef std::vector VecProj; - typedef std::vector VecSeg; - typedef std::vector VecClust; - typedef std::set SetClust; - typedef std::map MapToVecTrk; - typedef std::map MapToVecSeg; - typedef std::map MapToVecProj; - typedef std::map MapToVecClust; - - } // end PFTools namespace -} // end eicrecon namespace + bool operator()(const edm4eic::Cluster& lhs, const edm4eic::Cluster& rhs) const { + if (lhs.getObjectID().collectionID == rhs.getObjectID().collectionID) { + return (lhs.getObjectID().index < rhs.getObjectID().index); + } else { + return (lhs.getObjectID().collectionID < rhs.getObjectID().collectionID); + } + } + + }; // end CompareCluster + + // ------------------------------------------------------------------------ + //! Convenience types + // ------------------------------------------------------------------------ + typedef std::vector> MatrixF; + typedef std::vector VecMatrixF; + typedef std::vector VecTrk; + typedef std::vector VecProj; + typedef std::vector VecSeg; + typedef std::vector VecClust; + typedef std::set SetClust; + typedef std::map MapToVecTrk; + typedef std::map MapToVecSeg; + typedef std::map MapToVecProj; + typedef std::map MapToVecClust; + +} // namespace PFTools +} // namespace eicrecon diff --git a/src/algorithms/particle/TrackClusterSubtractor.cc b/src/algorithms/particle/TrackClusterSubtractor.cc index fc0e9f7853..d48fab9fa8 100644 --- a/src/algorithms/particle/TrackClusterSubtractor.cc +++ b/src/algorithms/particle/TrackClusterSubtractor.cc @@ -16,25 +16,21 @@ #include "TrackClusterSubtractor.h" #include "algorithms/particle/TrackClusterSubtractorConfig.h" - - namespace eicrecon { - // -------------------------------------------------------------------------- - //! Initialize algorithm - // -------------------------------------------------------------------------- - void TrackClusterSubtractor::init() { - - //... nothing to do ...// +// -------------------------------------------------------------------------- +//! Initialize algorithm +// -------------------------------------------------------------------------- +void TrackClusterSubtractor::init() { - } // end 'init(dd4hep::Detector*)' + //... nothing to do ...// +} // end 'init(dd4hep::Detector*)' - - // -------------------------------------------------------------------------- - //! Process inputs - // -------------------------------------------------------------------------- - /*! Subtract energy of matched tracks via the following algorithm. +// -------------------------------------------------------------------------- +//! Process inputs +// -------------------------------------------------------------------------- +/*! Subtract energy of matched tracks via the following algorithm. * 1. Build a map of each cluster onto a list of matched * track projections. * 2. For each cluster, subtract the sum of momenta of @@ -43,182 +39,161 @@ namespace eicrecon { * 3. If subtracted energy is greater than 0, copy cluster * into output with new subtracted energy. */ - void TrackClusterSubtractor::process( - const TrackClusterSubtractor::Input& input, - const TrackClusterSubtractor::Output& output - ) const { - - // grab inputs/outputs - const auto [in_matches, in_projections] = input; - auto [out_sub_clusters, out_remain_clusters, out_sub_matches] = output; - - // exit if no matched tracks in collection - if (in_matches->size() == 0) { - debug("No matched tracks in collection."); - return; - } - - // ------------------------------------------------------------------------ - // 1. Build map of clusters onto projections - // ------------------------------------------------------------------------ - PFTools::MapToVecSeg mapClustToProj; - for (const auto& match : *in_matches) { - for (const auto& project : *in_projections) { - - // pick out corresponding projection from track - if (match.getTrack() != project.getTrack()) { - continue; - } else { - mapClustToProj[ match.getCluster() ].push_back( project ); - } - - } // end projection loop - } // end track-cluster match loop - debug("Built map of clusters-onto-tracks, size = {}", mapClustToProj.size()); - - // ------------------------------------------------------------------------ - // 2. Subtract energy for tracks - // ------------------------------------------------------------------------ - for (const auto& [cluster, projects] : mapClustToProj) { - - // do subtraction - const double eTrkSum = sum_track_energy(projects); - const double eToSub = m_cfg.fracEnergyToSub * eTrkSum; - const double eSub = cluster.getEnergy() - eToSub; - trace("Subtracted {} GeV from cluster with {} GeV", eToSub, cluster.getEnergy()); - - // check if consistent with zero, - // set eSub accordingly - const bool isZero = is_zero(eSub); - const double eSubToUse = isZero ? 0. : eSub; - - // calculate energy fractions - const double remainFrac = eSubToUse / cluster.getEnergy(); - const double subtractFrac = 1. - remainFrac; - - // scale subtracted cluster energy - edm4eic::MutableCluster sub_clust = cluster.clone(); - sub_clust.setEnergy( subtractFrac * cluster.getEnergy() ); - out_sub_clusters->push_back(sub_clust); - trace( - "Created subtracted cluster with {} GeV (originally {} GeV)", - sub_clust.getEnergy(), - cluster.getEnergy() - ); - - // create track cluster matches - for (const auto& project : projects) { - edm4eic::MutableTrackClusterMatch match = out_sub_matches->create(); - match.setCluster( sub_clust ); - match.setTrack( project.getTrack() ); - match.setWeight( 1.0 ); // FIXME placeholder - trace( - "Matched subtracted cluster {} to track {}", - sub_clust.getObjectID().index, - project.getTrack().getObjectID().index - ); +void TrackClusterSubtractor::process(const TrackClusterSubtractor::Input& input, + const TrackClusterSubtractor::Output& output) const { + + // grab inputs/outputs + const auto [in_matches, in_projections] = input; + auto [out_sub_clusters, out_remain_clusters, out_sub_matches] = output; + + // exit if no matched tracks in collection + if (in_matches->size() == 0) { + debug("No matched tracks in collection."); + return; + } + + // ------------------------------------------------------------------------ + // 1. Build map of clusters onto projections + // ------------------------------------------------------------------------ + PFTools::MapToVecSeg mapClustToProj; + for (const auto& match : *in_matches) { + for (const auto& project : *in_projections) { + + // pick out corresponding projection from track + if (match.getTrack() != project.getTrack()) { + continue; + } else { + mapClustToProj[match.getCluster()].push_back(project); } - // if NOT consistent with zero, write - // out remnant cluster - if (!isZero) { - edm4eic::MutableCluster remain_clust = cluster.clone(); - remain_clust.setEnergy( remainFrac * cluster.getEnergy() ); - out_remain_clusters->push_back(remain_clust); - trace( - "Created remnant cluster with {} GeV", - remain_clust.getEnergy() - ); - } - - } // end cluster-to-projections loop - debug("Finished subtraction, {} remnant clusters", out_remain_clusters->size()); + } // end projection loop + } // end track-cluster match loop + debug("Built map of clusters-onto-tracks, size = {}", mapClustToProj.size()); + + // ------------------------------------------------------------------------ + // 2. Subtract energy for tracks + // ------------------------------------------------------------------------ + for (const auto& [cluster, projects] : mapClustToProj) { + + // do subtraction + const double eTrkSum = sum_track_energy(projects); + const double eToSub = m_cfg.fracEnergyToSub * eTrkSum; + const double eSub = cluster.getEnergy() - eToSub; + trace("Subtracted {} GeV from cluster with {} GeV", eToSub, cluster.getEnergy()); + + // check if consistent with zero, + // set eSub accordingly + const bool isZero = is_zero(eSub); + const double eSubToUse = isZero ? 0. : eSub; + + // calculate energy fractions + const double remainFrac = eSubToUse / cluster.getEnergy(); + const double subtractFrac = 1. - remainFrac; + + // scale subtracted cluster energy + edm4eic::MutableCluster sub_clust = cluster.clone(); + sub_clust.setEnergy(subtractFrac * cluster.getEnergy()); + out_sub_clusters->push_back(sub_clust); + trace("Created subtracted cluster with {} GeV (originally {} GeV)", sub_clust.getEnergy(), + cluster.getEnergy()); + + // create track cluster matches + for (const auto& project : projects) { + edm4eic::MutableTrackClusterMatch match = out_sub_matches->create(); + match.setCluster(sub_clust); + match.setTrack(project.getTrack()); + match.setWeight(1.0); // FIXME placeholder + trace("Matched subtracted cluster {} to track {}", sub_clust.getObjectID().index, + project.getTrack().getObjectID().index); + } - } // end 'get_projections(edm4eic::CalorimeterHit&, edm4eic::TrackSegmentCollection&, VecTrkPoint&)' + // if NOT consistent with zero, write + // out remnant cluster + if (!isZero) { + edm4eic::MutableCluster remain_clust = cluster.clone(); + remain_clust.setEnergy(remainFrac * cluster.getEnergy()); + out_remain_clusters->push_back(remain_clust); + trace("Created remnant cluster with {} GeV", remain_clust.getEnergy()); + } + } // end cluster-to-projections loop + debug("Finished subtraction, {} remnant clusters", out_remain_clusters->size()); +} // end 'get_projections(edm4eic::CalorimeterHit&, edm4eic::TrackSegmentCollection&, VecTrkPoint&)' - // -------------------------------------------------------------------------- - //! Sum energy of tracks - // -------------------------------------------------------------------------- - /*! Sums energy of tracks projected to the surface in the +// -------------------------------------------------------------------------- +//! Sum energy of tracks +// -------------------------------------------------------------------------- +/*! Sums energy of tracks projected to the surface in the * calorimeter specified by `surfaceToUse`. Uses PDG of * track to select mass for energy; if not available, * uses mass set by `defaultMassPdg`. */ - double TrackClusterSubtractor::sum_track_energy(const PFTools::VecSeg& projects) const { - - double eSum = 0.; - for (const auto& project : projects) { - - // measure momentum at specified surface - double momentum = 0.; - for (const auto& point : project.getPoints()) { - if (point.surface != m_cfg.surfaceToUse) { - continue; - } else { - momentum = edm4hep::utils::magnitude( point.momentum ); - break; - } - } - - // get mass based on track pdg - double mass = m_parSvc.particle(m_cfg.defaultMassPdg).mass; - if (project.getTrack().getPdg() != 0) { - mass = m_parSvc.particle(project.getTrack().getPdg()).mass; +double TrackClusterSubtractor::sum_track_energy(const PFTools::VecSeg& projects) const { + + double eSum = 0.; + for (const auto& project : projects) { + + // measure momentum at specified surface + double momentum = 0.; + for (const auto& point : project.getPoints()) { + if (point.surface != m_cfg.surfaceToUse) { + continue; + } else { + momentum = edm4hep::utils::magnitude(point.momentum); + break; } - - // increment sum - eSum += std::sqrt((momentum*momentum) + (mass*mass)); } - // output debugging and exit - trace("Sum of track energy = {} GeV", eSum); - return eSum; + // get mass based on track pdg + double mass = m_parSvc.particle(m_cfg.defaultMassPdg).mass; + if (project.getTrack().getPdg() != 0) { + mass = m_parSvc.particle(project.getTrack().getPdg()).mass; + } - } // end 'sum_track_energy(PFTools::VecSeg&)' + // increment sum + eSum += std::sqrt((momentum * momentum) + (mass * mass)); + } + // output debugging and exit + trace("Sum of track energy = {} GeV", eSum); + return eSum; +} // end 'sum_track_energy(PFTools::VecSeg&)' - // -------------------------------------------------------------------------- - //! Is difference consistent with zero? - // -------------------------------------------------------------------------- - /*! Checks if provided difference is consistent with zero, +// -------------------------------------------------------------------------- +//! Is difference consistent with zero? +// -------------------------------------------------------------------------- +/*! Checks if provided difference is consistent with zero, * either checking if difference is within an epsilon * (if `doNSigmaCut` is false), or if difference is within * `nSigmaMax` of zero (if `doNSigmaCut` is true) based on * the provided tracker and calorimeter resolutions. */ - bool TrackClusterSubtractor::is_zero(const double difference) const { - - // if < 0, automatically return true - if (difference < 0) { - return true; - } - - // calculate nSigma - const double totReso = std::sqrt((m_cfg.trkReso*m_cfg.trkReso) + (m_cfg.calReso*m_cfg.calReso)); - const double nSigma = difference / totReso; - - // do appropriate comparison - bool isZero = false; - if (m_cfg.doNSigmaCut) { - isZero = (nSigma < m_cfg.nSigmaMax); - trace( - "Difference of {} GeV consistent with zero: nSigma = {} < {}", - difference, - nSigma, - m_cfg.nSigmaMax - ); - } else { - isZero = std::abs(difference) < std::numeric_limits::epsilon(); - trace( - "Difference of {} GeV consistent with zero within an epsilon", - difference - ); - } - return isZero; - - } // end 'is_zero(double)' - -} // end eicrecon namespace +bool TrackClusterSubtractor::is_zero(const double difference) const { + + // if < 0, automatically return true + if (difference < 0) { + return true; + } + + // calculate nSigma + const double totReso = + std::sqrt((m_cfg.trkReso * m_cfg.trkReso) + (m_cfg.calReso * m_cfg.calReso)); + const double nSigma = difference / totReso; + + // do appropriate comparison + bool isZero = false; + if (m_cfg.doNSigmaCut) { + isZero = (nSigma < m_cfg.nSigmaMax); + trace("Difference of {} GeV consistent with zero: nSigma = {} < {}", difference, nSigma, + m_cfg.nSigmaMax); + } else { + isZero = std::abs(difference) < std::numeric_limits::epsilon(); + trace("Difference of {} GeV consistent with zero within an epsilon", difference); + } + return isZero; + +} // end 'is_zero(double)' + +} // namespace eicrecon diff --git a/src/algorithms/particle/TrackClusterSubtractor.h b/src/algorithms/particle/TrackClusterSubtractor.h index 210c470df0..fe39d02597 100644 --- a/src/algorithms/particle/TrackClusterSubtractor.h +++ b/src/algorithms/particle/TrackClusterSubtractor.h @@ -23,64 +23,48 @@ #include "algorithms/interfaces/ParticleSvc.h" #include "algorithms/interfaces/WithPodConfig.h" - namespace eicrecon { - // -------------------------------------------------------------------------- - //! Algorithm input/output - // -------------------------------------------------------------------------- - using TrackClusterSubtractorAlgorithm = algorithms::Algorithm< - algorithms::Input< - edm4eic::TrackClusterMatchCollection, - edm4eic::TrackSegmentCollection - >, - algorithms::Output< - edm4eic::ClusterCollection, - edm4eic::ClusterCollection, - edm4eic::TrackClusterMatchCollection - > - >; - - - - // -------------------------------------------------------------------------- - //! Track-Cluster Subtraction - // -------------------------------------------------------------------------- - /*! An algorithm which takes a collection of clusters and their matched +// -------------------------------------------------------------------------- +//! Algorithm input/output +// -------------------------------------------------------------------------- +using TrackClusterSubtractorAlgorithm = algorithms::Algorithm< + algorithms::Input, + algorithms::Output>; + +// -------------------------------------------------------------------------- +//! Track-Cluster Subtraction +// -------------------------------------------------------------------------- +/*! An algorithm which takes a collection of clusters and their matched * tracks, subtracts the sum of all tracks pointing to the cluster, * and outputs the remnant cluster and their matched tracks. */ - class TrackClusterSubtractor - : public TrackClusterSubtractorAlgorithm - , public WithPodConfig - { - - public: - - // ctor - TrackClusterSubtractor(std::string_view name) : - TrackClusterSubtractorAlgorithm { - name, - {"inputTrackClusterMatches", "inputTrackProjections"}, - {"outputSubtractedClusterCollection", - "outputRemnantClusterCollection", - "outputTrackSubtractedClusterMatches"}, - "Subtracts energy of tracks pointing to clusters." - } {} - - // public methods - void init(); - void process(const Input&, const Output&) const final; - - private: - - // private methods - double sum_track_energy(const PFTools::VecSeg& projects) const; - bool is_zero(const double difference) const; - - // services - const algorithms::ParticleSvc& m_parSvc = algorithms::ParticleSvc::instance(); - - }; // end TrackClusterSubtractor - -} // end eicrecon namespace +class TrackClusterSubtractor : public TrackClusterSubtractorAlgorithm, + public WithPodConfig { + +public: + // ctor + TrackClusterSubtractor(std::string_view name) + : TrackClusterSubtractorAlgorithm{name, + {"inputTrackClusterMatches", "inputTrackProjections"}, + {"outputSubtractedClusterCollection", + "outputRemnantClusterCollection", + "outputTrackSubtractedClusterMatches"}, + "Subtracts energy of tracks pointing to clusters."} {} + + // public methods + void init(); + void process(const Input&, const Output&) const final; + +private: + // private methods + double sum_track_energy(const PFTools::VecSeg& projects) const; + bool is_zero(const double difference) const; + + // services + const algorithms::ParticleSvc& m_parSvc = algorithms::ParticleSvc::instance(); + +}; // end TrackClusterSubtractor + +} // namespace eicrecon diff --git a/src/algorithms/particle/TrackClusterSubtractorConfig.h b/src/algorithms/particle/TrackClusterSubtractorConfig.h index 96d2092534..5225a6dd54 100644 --- a/src/algorithms/particle/TrackClusterSubtractorConfig.h +++ b/src/algorithms/particle/TrackClusterSubtractorConfig.h @@ -7,20 +7,20 @@ namespace eicrecon { - struct TrackClusterSubtractorConfig { +struct TrackClusterSubtractorConfig { - // general parameters - double fracEnergyToSub = 1.0; ///< fraction of track energy to subtract - int32_t defaultMassPdg = 211; ///< default mass to use for track energy - uint64_t surfaceToUse = 1; ///< index of surface to use for measuring momentum + // general parameters + double fracEnergyToSub = 1.0; ///< fraction of track energy to subtract + int32_t defaultMassPdg = 211; ///< default mass to use for track energy + uint64_t surfaceToUse = 1; ///< index of surface to use for measuring momentum - // parameters for resolution-based - // comparison - bool doNSigmaCut = false; ///< turn on/off checking against resolutions - uint32_t nSigmaMax = 1; ///< max no. of sigma to be consistent w/ zero - double trkReso = 1.0; ///< tracking momentum resolution to use - double calReso = 1.0; ///< calorimeter energy resolution to use + // parameters for resolution-based + // comparison + bool doNSigmaCut = false; ///< turn on/off checking against resolutions + uint32_t nSigmaMax = 1; ///< max no. of sigma to be consistent w/ zero + double trkReso = 1.0; ///< tracking momentum resolution to use + double calReso = 1.0; ///< calorimeter energy resolution to use - }; // end TrackClusterSubtractorConfig +}; // end TrackClusterSubtractorConfig -} // end eicrecon namespace +} // namespace eicrecon diff --git a/src/factories/particle/TrackClusterSubtractor_factory.h b/src/factories/particle/TrackClusterSubtractor_factory.h index 1369718efe..cbe7ebfa7c 100644 --- a/src/factories/particle/TrackClusterSubtractor_factory.h +++ b/src/factories/particle/TrackClusterSubtractor_factory.h @@ -15,61 +15,54 @@ namespace eicrecon { - class TrackClusterSubtractor_factory - : public JOmniFactory - { - - public: - - using AlgoT = eicrecon::TrackClusterSubtractor; - - private: - - // algorithm to run - std::unique_ptr m_algo; - - // input collections - PodioInput m_track_cluster_match_input {this}; - PodioInput m_track_projections_input {this}; - - // output collections - PodioOutput m_subtract_clusters_output {this}; - PodioOutput m_remnant_clusters_output {this}; - PodioOutput m_track_sub_cluster_match_output {this}; - - // parameter bindings - ParameterRef m_fracEnergyToSub {this, "fracEnergyToSub", config().fracEnergyToSub}; - ParameterRef m_defaultMassPdg {this, "defaultMassPdg", config().defaultMassPdg}; - ParameterRef m_surfaceToUse {this, "surfaceToUse", config().surfaceToUse}; - ParameterRef m_doNSigmaCut {this, "doNSigmaCut", config().doNSigmaCut}; - ParameterRef m_nSigmaMax {this, "nSigmaMax", config().nSigmaMax}; - ParameterRef m_trkReso {this, "trkReso", config().trkReso}; - ParameterRef m_calReso {this, "calReso", config().calReso}; - - // services - Service m_algoInitSvc {this}; - - public: - - void Configure() { - m_algo = std::make_unique(GetPrefix()); - m_algo->applyConfig( config() ); - m_algo->init(); - } - - void ChangeRun(int64_t run_number) { - //... nothing to do ...// - } - - void Process(int64_t run_number, uint64_t event_number) { - m_algo->process( - {m_track_cluster_match_input(), m_track_projections_input()}, - {m_subtract_clusters_output().get(), - m_remnant_clusters_output().get(), - m_track_sub_cluster_match_output().get()} - ); - } - - }; // end TrackClusterSubtractor_factory - -} // end eicrecon namespace +class TrackClusterSubtractor_factory + : public JOmniFactory { + +public: + using AlgoT = eicrecon::TrackClusterSubtractor; + +private: + // algorithm to run + std::unique_ptr m_algo; + + // input collections + PodioInput m_track_cluster_match_input{this}; + PodioInput m_track_projections_input{this}; + + // output collections + PodioOutput m_subtract_clusters_output{this}; + PodioOutput m_remnant_clusters_output{this}; + PodioOutput m_track_sub_cluster_match_output{this}; + + // parameter bindings + ParameterRef m_fracEnergyToSub{this, "fracEnergyToSub", config().fracEnergyToSub}; + ParameterRef m_defaultMassPdg{this, "defaultMassPdg", config().defaultMassPdg}; + ParameterRef m_surfaceToUse{this, "surfaceToUse", config().surfaceToUse}; + ParameterRef m_doNSigmaCut{this, "doNSigmaCut", config().doNSigmaCut}; + ParameterRef m_nSigmaMax{this, "nSigmaMax", config().nSigmaMax}; + ParameterRef m_trkReso{this, "trkReso", config().trkReso}; + ParameterRef m_calReso{this, "calReso", config().calReso}; + + // services + Service m_algoInitSvc{this}; + +public: + void Configure() { + m_algo = std::make_unique(GetPrefix()); + m_algo->applyConfig(config()); + m_algo->init(); + } + + void ChangeRun(int64_t run_number) { + //... nothing to do ...// + } + + void Process(int64_t run_number, uint64_t event_number) { + m_algo->process({m_track_cluster_match_input(), m_track_projections_input()}, + {m_subtract_clusters_output().get(), m_remnant_clusters_output().get(), + m_track_sub_cluster_match_output().get()}); + } + +}; // end TrackClusterSubtractor_factory + +} // namespace eicrecon diff --git a/src/global/particle/particle.cc b/src/global/particle/particle.cc index 32100ca16e..8f68360e9f 100644 --- a/src/global/particle/particle.cc +++ b/src/global/particle/particle.cc @@ -12,134 +12,96 @@ extern "C" { - void InitPlugin(JApplication *app) { - - using namespace eicrecon; - - InitJANAPlugin(app); - - // ==================================================================== - // PFAlpha: baseline PF implementation - // ==================================================================== - - // -------------------------------------------------------------------- - // PFA (0) connection: split/merge clusters accordingly - // -------------------------------------------------------------------- - - /* TODO move here when ready */ - - // -------------------------------------------------------------------- - // PFA (1a) arbitration: apply track correction to clusters - // -------------------------------------------------------------------- - - // backward ----------------------------------------------------------- - - app->Add( - new JOmniFactoryGeneratorT( - "EcalEndcapNSubtractedClusters", - {"EcalEndcapNTrackSplitMergeClusterMatches", - "CalorimeterTrackProjections"}, - {"EcalEndcapNSubtractedClusters", - "EcalEndcapNRemnantClusters", - "EcalEndcapNTrackSubtractedClusterMatches"}, - { - .fracEnergyToSub = 1.0, - .defaultMassPdg = 211, - .surfaceToUse = 1, - }, - app // TODO: remove me once fixed - ) - ); - - app->Add( - new JOmniFactoryGeneratorT( - "HcalEndcapNSubtractedClusters", - {"HcalEndcapNTrackSplitMergeClusterMatches", - "CalorimeterTrackProjections"}, - {"HcalEndcapNSubtractedClusters", - "HcalEndcapNRemnantClusters", - "HcalEndcapNTrackSubtractedClusterMatches"}, - { - .fracEnergyToSub = 1.0, - .defaultMassPdg = 211, - .surfaceToUse = 1 - }, - app // TODO: remove me once fixed - ) - ); - - // central ------------------------------------------------------------ - - app->Add( - new JOmniFactoryGeneratorT( - "HcalBarrelSubtractedClusters", - {"HcalBarrelTrackSplitMergeClusterMatches", - "CalorimeterTrackProjections"}, - {"HcalBarrelSubtractedClusters", - "HcalBarrelRemnantClusters", - "HcalBarrelTrackSubtractedClusterMatches"}, - { - .fracEnergyToSub = 1.0, - .defaultMassPdg = 211, - .surfaceToUse = 1 - }, - app // TODO: remove me once fixed - ) - ); - - // forward ------------------------------------------------------------ - - app->Add( - new JOmniFactoryGeneratorT( - "EcalEndcapPSubtractedClusters", - {"EcalEndcapPTrackSplitMergeClusterMatches", - "CalorimeterTrackProjections"}, - {"EcalEndcapPSubtractedClusters", - "EcalEndcapPRemnantClusters", - "EcalEndcapPTrackSubtractedClusterMatches"}, - { - .fracEnergyToSub = 1.0, - .defaultMassPdg = 211, - .surfaceToUse = 1 - }, - app // TODO: remove me once fixed - ) - ); - - app->Add( - new JOmniFactoryGeneratorT( - "LFHCALSubtractedClusters", - {"LFHCALTrackSplitMergeClusterMatches", - "CalorimeterTrackProjections"}, - {"LFHCALSubtractedClusters", - "LFHCALRemnantClusters", - "LFHCALTrackSubtractedClusterMatches"}, - { - .fracEnergyToSub = 1.0, - .defaultMassPdg = 211, - .surfaceToUse = 1 - }, - app // TODO: remove me once fixed - ) - ); - - // -------------------------------------------------------------------- - // PFA (1b) arbitration: form charged candidates - // -------------------------------------------------------------------- - - /* TODO add here */ - - // -------------------------------------------------------------------- - // PFA (2) arbitration: combine remnants, form neutral candidates - // -------------------------------------------------------------------- - - /* TODO add here */ - - // -------------------------------------------------------------------- - // PFA (3) regression: convert candidates to reco particles - // -------------------------------------------------------------------- - - /* TODO add here */ - - } +void InitPlugin(JApplication* app) { + + using namespace eicrecon; + + InitJANAPlugin(app); + + // ==================================================================== + // PFAlpha: baseline PF implementation + // ==================================================================== + + // -------------------------------------------------------------------- + // PFA (0) connection: split/merge clusters accordingly + // -------------------------------------------------------------------- + + /* TODO move here when ready */ + + // -------------------------------------------------------------------- + // PFA (1a) arbitration: apply track correction to clusters + // -------------------------------------------------------------------- + + // backward ----------------------------------------------------------- + + app->Add(new JOmniFactoryGeneratorT( + "EcalEndcapNSubtractedClusters", + {"EcalEndcapNTrackSplitMergeClusterMatches", "CalorimeterTrackProjections"}, + {"EcalEndcapNSubtractedClusters", "EcalEndcapNRemnantClusters", + "EcalEndcapNTrackSubtractedClusterMatches"}, + { + .fracEnergyToSub = 1.0, + .defaultMassPdg = 211, + .surfaceToUse = 1, + }, + app // TODO: remove me once fixed + )); + + app->Add(new JOmniFactoryGeneratorT( + "HcalEndcapNSubtractedClusters", + {"HcalEndcapNTrackSplitMergeClusterMatches", "CalorimeterTrackProjections"}, + {"HcalEndcapNSubtractedClusters", "HcalEndcapNRemnantClusters", + "HcalEndcapNTrackSubtractedClusterMatches"}, + {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, + app // TODO: remove me once fixed + )); + + // central ------------------------------------------------------------ + + app->Add(new JOmniFactoryGeneratorT( + "HcalBarrelSubtractedClusters", + {"HcalBarrelTrackSplitMergeClusterMatches", "CalorimeterTrackProjections"}, + {"HcalBarrelSubtractedClusters", "HcalBarrelRemnantClusters", + "HcalBarrelTrackSubtractedClusterMatches"}, + {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, + app // TODO: remove me once fixed + )); + + // forward ------------------------------------------------------------ + + app->Add(new JOmniFactoryGeneratorT( + "EcalEndcapPSubtractedClusters", + {"EcalEndcapPTrackSplitMergeClusterMatches", "CalorimeterTrackProjections"}, + {"EcalEndcapPSubtractedClusters", "EcalEndcapPRemnantClusters", + "EcalEndcapPTrackSubtractedClusterMatches"}, + {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, + app // TODO: remove me once fixed + )); + + app->Add(new JOmniFactoryGeneratorT( + "LFHCALSubtractedClusters", + {"LFHCALTrackSplitMergeClusterMatches", "CalorimeterTrackProjections"}, + {"LFHCALSubtractedClusters", "LFHCALRemnantClusters", "LFHCALTrackSubtractedClusterMatches"}, + {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, + app // TODO: remove me once fixed + )); + + // -------------------------------------------------------------------- + // PFA (1b) arbitration: form charged candidates + // -------------------------------------------------------------------- + + /* TODO add here */ + + // -------------------------------------------------------------------- + // PFA (2) arbitration: combine remnants, form neutral candidates + // -------------------------------------------------------------------- + + /* TODO add here */ + + // -------------------------------------------------------------------- + // PFA (3) regression: convert candidates to reco particles + // -------------------------------------------------------------------- + + /* TODO add here */ +} } From 10867a32f896bf9915a78014c52d72cf5760db32 Mon Sep 17 00:00:00 2001 From: Wouter Deconinck Date: Tue, 26 Aug 2025 14:37:33 -0500 Subject: [PATCH 13/46] Implement Track-Cluster Subtraction (PFA1) (fix: iwyu) (#2051) This PR applies the include-what-you-use fixes as suggested by https://github.com/eic/EICrecon/actions/runs/17247257038. Please merge this PR into the branch `add-track-cluster-subtraction-pfa-one` to resolve failures in PR #1627. Auto-generated by [create-pull-request][1] [1]: https://github.com/peter-evans/create-pull-request Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/algorithms/particle/TrackClusterSubtractor.cc | 9 +++++---- src/algorithms/particle/TrackClusterSubtractor.h | 8 -------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/algorithms/particle/TrackClusterSubtractor.cc b/src/algorithms/particle/TrackClusterSubtractor.cc index d48fab9fa8..f5452c1db5 100644 --- a/src/algorithms/particle/TrackClusterSubtractor.cc +++ b/src/algorithms/particle/TrackClusterSubtractor.cc @@ -1,19 +1,20 @@ // SPDX-License-Identifier: LGPL-3.0-or-later // Copyright (C) 2024 Derek Anderson -#include -#include +#include +#include #include #include #include #include -#include #include -#include #include #include +#include +#include #include "TrackClusterSubtractor.h" +#include "algorithms/particle/PFTools.h" #include "algorithms/particle/TrackClusterSubtractorConfig.h" namespace eicrecon { diff --git a/src/algorithms/particle/TrackClusterSubtractor.h b/src/algorithms/particle/TrackClusterSubtractor.h index fe39d02597..02024c1b6d 100644 --- a/src/algorithms/particle/TrackClusterSubtractor.h +++ b/src/algorithms/particle/TrackClusterSubtractor.h @@ -3,20 +3,12 @@ #pragma once -#include #include #include #include -#include #include -#include -#include -#include -#include -#include #include #include -#include #include "PFTools.h" #include "TrackClusterSubtractorConfig.h" From 3bbe27a1fdb971d4d3239686c2bb9e83e0736e37 Mon Sep 17 00:00:00 2001 From: ruse-traveler Date: Tue, 26 Aug 2025 16:39:10 -0400 Subject: [PATCH 14/46] Remove PFTools --- src/algorithms/particle/PFTools.h | 59 ------------------- .../particle/TrackClusterSubtractor.cc | 34 ++++++----- .../particle/TrackClusterSubtractor.h | 53 ++++++++++++----- .../particle/TrackClusterSubtractorConfig.h | 31 ++++++---- 4 files changed, 77 insertions(+), 100 deletions(-) delete mode 100644 src/algorithms/particle/PFTools.h diff --git a/src/algorithms/particle/PFTools.h b/src/algorithms/particle/PFTools.h deleted file mode 100644 index ce852cc2f6..0000000000 --- a/src/algorithms/particle/PFTools.h +++ /dev/null @@ -1,59 +0,0 @@ -// SPDX-License-Identifier: LGPL-3.0-or-later -// Copyright (C) 2025 Derek Anderson - -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace eicrecon { - -// -------------------------------------------------------------------------- -//! Particle Flow tools namespace -// -------------------------------------------------------------------------- -/*! This namespace collects a variety of useful types and methods - * used throughout particle flow algorithms. - */ -namespace PFTools { - - // ------------------------------------------------------------------------ - //! Comparator struct for clusters - // ------------------------------------------------------------------------ - /*! Organizes protoclusters by their ObjectID's in decreasing collection - * ID first, and second by decreasing index second. - * - * TODO should also order by energy... - */ - struct CompareClust { - - bool operator()(const edm4eic::Cluster& lhs, const edm4eic::Cluster& rhs) const { - if (lhs.getObjectID().collectionID == rhs.getObjectID().collectionID) { - return (lhs.getObjectID().index < rhs.getObjectID().index); - } else { - return (lhs.getObjectID().collectionID < rhs.getObjectID().collectionID); - } - } - - }; // end CompareCluster - - // ------------------------------------------------------------------------ - //! Convenience types - // ------------------------------------------------------------------------ - typedef std::vector> MatrixF; - typedef std::vector VecMatrixF; - typedef std::vector VecTrk; - typedef std::vector VecProj; - typedef std::vector VecSeg; - typedef std::vector VecClust; - typedef std::set SetClust; - typedef std::map MapToVecTrk; - typedef std::map MapToVecSeg; - typedef std::map MapToVecProj; - typedef std::map MapToVecClust; - -} // namespace PFTools -} // namespace eicrecon diff --git a/src/algorithms/particle/TrackClusterSubtractor.cc b/src/algorithms/particle/TrackClusterSubtractor.cc index f5452c1db5..f9e8cf55ce 100644 --- a/src/algorithms/particle/TrackClusterSubtractor.cc +++ b/src/algorithms/particle/TrackClusterSubtractor.cc @@ -1,5 +1,5 @@ // SPDX-License-Identifier: LGPL-3.0-or-later -// Copyright (C) 2024 Derek Anderson +// Copyright (C) 2025 Derek Anderson #include #include @@ -14,7 +14,6 @@ #include #include "TrackClusterSubtractor.h" -#include "algorithms/particle/PFTools.h" #include "algorithms/particle/TrackClusterSubtractorConfig.h" namespace eicrecon { @@ -56,7 +55,7 @@ void TrackClusterSubtractor::process(const TrackClusterSubtractor::Input& input, // ------------------------------------------------------------------------ // 1. Build map of clusters onto projections // ------------------------------------------------------------------------ - PFTools::MapToVecSeg mapClustToProj; + MapToVecSeg mapClustToProj; for (const auto& match : *in_matches) { for (const auto& project : *in_projections) { @@ -95,7 +94,8 @@ void TrackClusterSubtractor::process(const TrackClusterSubtractor::Input& input, edm4eic::MutableCluster sub_clust = cluster.clone(); sub_clust.setEnergy(subtractFrac * cluster.getEnergy()); out_sub_clusters->push_back(sub_clust); - trace("Created subtracted cluster with {} GeV (originally {} GeV)", sub_clust.getEnergy(), + trace("Created subtracted cluster with {} GeV (originally {} GeV)", + sub_clust.getEnergy(), cluster.getEnergy()); // create track cluster matches @@ -126,11 +126,11 @@ void TrackClusterSubtractor::process(const TrackClusterSubtractor::Input& input, //! Sum energy of tracks // -------------------------------------------------------------------------- /*! Sums energy of tracks projected to the surface in the - * calorimeter specified by `surfaceToUse`. Uses PDG of - * track to select mass for energy; if not available, - * uses mass set by `defaultMassPdg`. - */ -double TrackClusterSubtractor::sum_track_energy(const PFTools::VecSeg& projects) const { + * calorimeter specified by `surfaceToUse`. Uses PDG of + * track to select mass for energy; if not available, + * uses mass set by `defaultMassPdg`. + */ +double TrackClusterSubtractor::sum_track_energy(const VecSeg& projects) const { double eSum = 0.; for (const auto& project : projects) { @@ -160,17 +160,17 @@ double TrackClusterSubtractor::sum_track_energy(const PFTools::VecSeg& projects) trace("Sum of track energy = {} GeV", eSum); return eSum; -} // end 'sum_track_energy(PFTools::VecSeg&)' +} // end 'sum_track_energy(VecSeg&)' // -------------------------------------------------------------------------- //! Is difference consistent with zero? // -------------------------------------------------------------------------- /*! Checks if provided difference is consistent with zero, - * either checking if difference is within an epsilon - * (if `doNSigmaCut` is false), or if difference is within - * `nSigmaMax` of zero (if `doNSigmaCut` is true) based on - * the provided tracker and calorimeter resolutions. - */ + * either checking if difference is within an epsilon + * (if `doNSigmaCut` is false), or if difference is within + * `nSigmaMax` of zero (if `doNSigmaCut` is true) based on + * the provided tracker and calorimeter resolutions. + */ bool TrackClusterSubtractor::is_zero(const double difference) const { // if < 0, automatically return true @@ -187,7 +187,9 @@ bool TrackClusterSubtractor::is_zero(const double difference) const { bool isZero = false; if (m_cfg.doNSigmaCut) { isZero = (nSigma < m_cfg.nSigmaMax); - trace("Difference of {} GeV consistent with zero: nSigma = {} < {}", difference, nSigma, + trace("Difference of {} GeV consistent with zero: nSigma = {} < {}", + difference, + nSigma, m_cfg.nSigmaMax); } else { isZero = std::abs(difference) < std::numeric_limits::epsilon(); diff --git a/src/algorithms/particle/TrackClusterSubtractor.h b/src/algorithms/particle/TrackClusterSubtractor.h index 02024c1b6d..20e23a91a2 100644 --- a/src/algorithms/particle/TrackClusterSubtractor.h +++ b/src/algorithms/particle/TrackClusterSubtractor.h @@ -10,7 +10,6 @@ #include #include -#include "PFTools.h" #include "TrackClusterSubtractorConfig.h" #include "algorithms/interfaces/ParticleSvc.h" #include "algorithms/interfaces/WithPodConfig.h" @@ -21,40 +20,66 @@ namespace eicrecon { //! Algorithm input/output // -------------------------------------------------------------------------- using TrackClusterSubtractorAlgorithm = algorithms::Algorithm< - algorithms::Input, - algorithms::Output, + algorithms::Output>; -// -------------------------------------------------------------------------- +// ========================================================================== //! Track-Cluster Subtraction -// -------------------------------------------------------------------------- +// ========================================================================== /*! An algorithm which takes a collection of clusters and their matched - * tracks, subtracts the sum of all tracks pointing to the cluster, - * and outputs the remnant cluster and their matched tracks. - */ + * tracks, subtracts the sum of all tracks pointing to the cluster, + * and outputs the remnant cluster and their matched tracks. + */ class TrackClusterSubtractor : public TrackClusterSubtractorAlgorithm, public WithPodConfig { public: - // ctor + + // ------------------------------------------------------------------------ + //! Comparator struct for clusters + // ------------------------------------------------------------------------ + /*! Organizes clusters by their ObjectIDs in decreasing collection + * ID first, and second by decreasing index second. + */ + struct CompareClust { + bool operator()(const edm4eic::Cluster& lhs, const edm4eic::Cluster& rhs) const { + if (lhs.getObjectID().collectionID == rhs.getObjectID().collectionID) { + return (lhs.getObjectID().index < rhs.getObjectID().index); + } else { + return (lhs.getObjectID().collectionID < rhs.getObjectID().collectionID); + } + } + }; + + ///! Alias for vectors of track segments + using VecSeg = std::vector; + + ///! Alias for a map from a cluster to the segments of matched tracks + using MapToVecSeg = std::map; + + ///! CTOR DESCRIPTION WILL GO HERE TrackClusterSubtractor(std::string_view name) : TrackClusterSubtractorAlgorithm{name, - {"inputTrackClusterMatches", "inputTrackProjections"}, + {"inputTrackClusterMatches", + "inputTrackProjections"}, {"outputSubtractedClusterCollection", "outputRemnantClusterCollection", "outputTrackSubtractedClusterMatches"}, "Subtracts energy of tracks pointing to clusters."} {} - // public methods void init(); void process(const Input&, const Output&) const final; private: - // private methods - double sum_track_energy(const PFTools::VecSeg& projects) const; + + ///! private methods + double sum_track_energy(const VecSeg& projects) const; bool is_zero(const double difference) const; - // services + ///! Particle service instance for retrieving specified mass hypothesis const algorithms::ParticleSvc& m_parSvc = algorithms::ParticleSvc::instance(); }; // end TrackClusterSubtractor diff --git a/src/algorithms/particle/TrackClusterSubtractorConfig.h b/src/algorithms/particle/TrackClusterSubtractorConfig.h index 5225a6dd54..843f155d1b 100644 --- a/src/algorithms/particle/TrackClusterSubtractorConfig.h +++ b/src/algorithms/particle/TrackClusterSubtractorConfig.h @@ -9,17 +9,26 @@ namespace eicrecon { struct TrackClusterSubtractorConfig { - // general parameters - double fracEnergyToSub = 1.0; ///< fraction of track energy to subtract - int32_t defaultMassPdg = 211; ///< default mass to use for track energy - uint64_t surfaceToUse = 1; ///< index of surface to use for measuring momentum - - // parameters for resolution-based - // comparison - bool doNSigmaCut = false; ///< turn on/off checking against resolutions - uint32_t nSigmaMax = 1; ///< max no. of sigma to be consistent w/ zero - double trkReso = 1.0; ///< tracking momentum resolution to use - double calReso = 1.0; ///< calorimeter energy resolution to use + ///! fraction of track energy to subtract + double fracEnergyToSub = 1.0; + + ///! default mass to use for track energy + int32_t defaultMassPdg = 211; + + ///! index of surface to use for measuring momentum + uint64_t surfaceToUse = 1; + + ///! turn on/off checking against resolutions + bool doNSigmaCut = false; + + ///! max no. of sigma to be consistent w/ zero + uint32_t nSigmaMax = 1; + + ///! tracking momentum resolution to use + double trkReso = 1.0; + + ///! calorimeter energy resolution to use + double calReso = 1.0; }; // end TrackClusterSubtractorConfig From 0ec864d5ae03f08d7d0f91dadeb06907af13addf Mon Sep 17 00:00:00 2001 From: ruse-traveler Date: Tue, 26 Aug 2025 18:08:24 -0400 Subject: [PATCH 15/46] Make sure cmake finds plugin --- src/global/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/global/CMakeLists.txt b/src/global/CMakeLists.txt index 4d12e01fc8..bbff676663 100644 --- a/src/global/CMakeLists.txt +++ b/src/global/CMakeLists.txt @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.16) add_subdirectory(tracking) add_subdirectory(reco) +add_subdirectory(particle) add_subdirectory(pid) add_subdirectory(pid_lut) add_subdirectory(beam) From fa3fcb065fc67ba3d9a82e2e32159bc9804124af Mon Sep 17 00:00:00 2001 From: ruse-traveler Date: Tue, 26 Aug 2025 18:09:46 -0400 Subject: [PATCH 16/46] Use track-cluster matches until merge/splitter is updated --- src/global/particle/particle.cc | 81 +++++++++++++++++++++++++-------- 1 file changed, 61 insertions(+), 20 deletions(-) diff --git a/src/global/particle/particle.cc b/src/global/particle/particle.cc index 8f68360e9f..20b92ac516 100644 --- a/src/global/particle/particle.cc +++ b/src/global/particle/particle.cc @@ -1,5 +1,5 @@ // SPDX-License-Identifier: LGPL-3.0-or-later -// Copyright (C) 2024 Derek Anderson +// Copyright (C) 2025 Derek Anderson #include #include @@ -7,7 +7,6 @@ #include #include "extensions/jana/JOmniFactoryGeneratorT.h" -#include "factories/particle/TrackClusterMergeSplitter_factory.h" #include "factories/particle/TrackClusterSubtractor_factory.h" extern "C" { @@ -36,34 +35,63 @@ void InitPlugin(JApplication* app) { app->Add(new JOmniFactoryGeneratorT( "EcalEndcapNSubtractedClusters", - {"EcalEndcapNTrackSplitMergeClusterMatches", "CalorimeterTrackProjections"}, - {"EcalEndcapNSubtractedClusters", "EcalEndcapNRemnantClusters", + {"EcalEndcapNTrackClusterMatches", + "CalorimeterTrackProjections"}, + {"EcalEndcapNSubtractedClusters", + "EcalEndcapNRemnantClusters", "EcalEndcapNTrackSubtractedClusterMatches"}, { - .fracEnergyToSub = 1.0, - .defaultMassPdg = 211, - .surfaceToUse = 1, + .fracEnergyToSub = 1.0, + .defaultMassPdg = 211, + .surfaceToUse = 1, }, app // TODO: remove me once fixed )); app->Add(new JOmniFactoryGeneratorT( "HcalEndcapNSubtractedClusters", - {"HcalEndcapNTrackSplitMergeClusterMatches", "CalorimeterTrackProjections"}, - {"HcalEndcapNSubtractedClusters", "HcalEndcapNRemnantClusters", + {"HcalEndcapNTrackClusterMatches", + "CalorimeterTrackProjections"}, + {"HcalEndcapNSubtractedClusters", + "HcalEndcapNRemnantClusters", "HcalEndcapNTrackSubtractedClusterMatches"}, - {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, + { + .fracEnergyToSub = 1.0, + .defaultMassPdg = 211, + .surfaceToUse = 1 + }, app // TODO: remove me once fixed )); // central ------------------------------------------------------------ + app->Add(new JOmniFactoryGeneratorT( + "EcalBarrelSubtractedClusters", + {"EcalBarrelTrackClusterMatches", + "CalorimeterTrackProjections"}, + {"EcalBarrelSubtractedClusters", + "EcalBarrelRemnantClusters", + "EcalBarrelTrackSubtractedClusterMatches"}, + { + .fracEnergyToSub = 1.0, + .defaultMassPdg = 211, + .surfaceToUse = 1 + }, + app // TODO: remove me once fixed + )); + app->Add(new JOmniFactoryGeneratorT( "HcalBarrelSubtractedClusters", - {"HcalBarrelTrackSplitMergeClusterMatches", "CalorimeterTrackProjections"}, - {"HcalBarrelSubtractedClusters", "HcalBarrelRemnantClusters", + {"HcalBarrelTrackClusterMatches", + "CalorimeterTrackProjections"}, + {"HcalBarrelSubtractedClusters", + "HcalBarrelRemnantClusters", "HcalBarrelTrackSubtractedClusterMatches"}, - {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, + { + .fracEnergyToSub = 1.0, + .defaultMassPdg = 211, + .surfaceToUse = 1 + }, app // TODO: remove me once fixed )); @@ -71,18 +99,31 @@ void InitPlugin(JApplication* app) { app->Add(new JOmniFactoryGeneratorT( "EcalEndcapPSubtractedClusters", - {"EcalEndcapPTrackSplitMergeClusterMatches", "CalorimeterTrackProjections"}, - {"EcalEndcapPSubtractedClusters", "EcalEndcapPRemnantClusters", + {"EcalEndcapPTrackClusterMatches", + "CalorimeterTrackProjections"}, + {"EcalEndcapPSubtractedClusters", + "EcalEndcapPRemnantClusters", "EcalEndcapPTrackSubtractedClusterMatches"}, - {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, + { + .fracEnergyToSub = 1.0, + .defaultMassPdg = 211, + .surfaceToUse = 1 + }, app // TODO: remove me once fixed )); app->Add(new JOmniFactoryGeneratorT( "LFHCALSubtractedClusters", - {"LFHCALTrackSplitMergeClusterMatches", "CalorimeterTrackProjections"}, - {"LFHCALSubtractedClusters", "LFHCALRemnantClusters", "LFHCALTrackSubtractedClusterMatches"}, - {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, + {"LFHCALTrackSplitMergeClusterMatches", + "CalorimeterTrackProjections"}, + {"LFHCALSubtractedClusters", + "LFHCALRemnantClusters", + "LFHCALTrackSubtractedClusterMatches"}, + { + .fracEnergyToSub = 1.0, + .defaultMassPdg = 211, + .surfaceToUse = 1 + }, app // TODO: remove me once fixed )); @@ -104,4 +145,4 @@ void InitPlugin(JApplication* app) { /* TODO add here */ } -} +} // extern "C" From 9c045ea542558d6343187e49ef9990c72dd225e3 Mon Sep 17 00:00:00 2001 From: ruse-traveler Date: Tue, 26 Aug 2025 18:10:09 -0400 Subject: [PATCH 17/46] Make consistent with reco CMakeLists --- src/global/particle/CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/global/particle/CMakeLists.txt b/src/global/particle/CMakeLists.txt index e5c5509550..fe74cf15d4 100644 --- a/src/global/particle/CMakeLists.txt +++ b/src/global/particle/CMakeLists.txt @@ -1,3 +1,5 @@ +cmake_minimum_required(VERSION 3.16) + # Automatically set plugin name the same as the directory name Don't forget # string(REPLACE " " "_" PLUGIN_NAME ${PLUGIN_NAME}) if this dir has spaces in # its name @@ -5,7 +7,7 @@ get_filename_component(PLUGIN_NAME ${CMAKE_CURRENT_LIST_DIR} NAME) # Function creates ${PLUGIN_NAME}_plugin and ${PLUGIN_NAME}_library targets # Setting default includes, libraries and installation paths -plugin_add(${PLUGIN_NAME}) +plugin_add(${PLUGIN_NAME} PLUGIN_USE_CC_ONLY) # The macro grabs sources as *.cc *.cpp *.c and headers as *.h *.hh *.hpp Then # correctly sets sources for ${_name}_plugin and ${_name}_library targets Adds @@ -13,8 +15,8 @@ plugin_add(${PLUGIN_NAME}) plugin_glob_all(${PLUGIN_NAME}) # Find dependencies -plugin_add_event_model(${PLUGIN_NAME}) plugin_add_dd4hep(${PLUGIN_NAME}) +plugin_add_event_model(${PLUGIN_NAME}) # Add include directories (works same as target_include_directories) # plugin_include_directories(${PLUGIN_NAME} SYSTEM PUBLIC ...) From da828bbb1aa340d7c9bb7d95906dd9158f71014b Mon Sep 17 00:00:00 2001 From: ruse-traveler Date: Tue, 26 Aug 2025 18:10:21 -0400 Subject: [PATCH 18/46] Do light reformatting --- .../particle/TrackClusterSubtractor.cc | 22 ++++++----------- .../particle/TrackClusterSubtractor.h | 6 ++--- .../particle/TrackClusterSubtractor_factory.h | 24 ++++++++++++------- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/algorithms/particle/TrackClusterSubtractor.cc b/src/algorithms/particle/TrackClusterSubtractor.cc index f9e8cf55ce..ce99f40fc1 100644 --- a/src/algorithms/particle/TrackClusterSubtractor.cc +++ b/src/algorithms/particle/TrackClusterSubtractor.cc @@ -18,15 +18,6 @@ namespace eicrecon { -// -------------------------------------------------------------------------- -//! Initialize algorithm -// -------------------------------------------------------------------------- -void TrackClusterSubtractor::init() { - - //... nothing to do ...// - -} // end 'init(dd4hep::Detector*)' - // -------------------------------------------------------------------------- //! Process inputs // -------------------------------------------------------------------------- @@ -43,7 +34,7 @@ void TrackClusterSubtractor::process(const TrackClusterSubtractor::Input& input, const TrackClusterSubtractor::Output& output) const { // grab inputs/outputs - const auto [in_matches, in_projections] = input; + const auto [in_matches, in_projections] = input; auto [out_sub_clusters, out_remain_clusters, out_sub_matches] = output; // exit if no matched tracks in collection @@ -77,17 +68,17 @@ void TrackClusterSubtractor::process(const TrackClusterSubtractor::Input& input, // do subtraction const double eTrkSum = sum_track_energy(projects); - const double eToSub = m_cfg.fracEnergyToSub * eTrkSum; - const double eSub = cluster.getEnergy() - eToSub; + const double eToSub = m_cfg.fracEnergyToSub * eTrkSum; + const double eSub = cluster.getEnergy() - eToSub; trace("Subtracted {} GeV from cluster with {} GeV", eToSub, cluster.getEnergy()); // check if consistent with zero, // set eSub accordingly - const bool isZero = is_zero(eSub); + const bool isZero = is_zero(eSub); const double eSubToUse = isZero ? 0. : eSub; // calculate energy fractions - const double remainFrac = eSubToUse / cluster.getEnergy(); + const double remainFrac = eSubToUse / cluster.getEnergy(); const double subtractFrac = 1. - remainFrac; // scale subtracted cluster energy @@ -104,7 +95,8 @@ void TrackClusterSubtractor::process(const TrackClusterSubtractor::Input& input, match.setCluster(sub_clust); match.setTrack(project.getTrack()); match.setWeight(1.0); // FIXME placeholder - trace("Matched subtracted cluster {} to track {}", sub_clust.getObjectID().index, + trace("Matched subtracted cluster {} to track {}", + sub_clust.getObjectID().index, project.getTrack().getObjectID().index); } diff --git a/src/algorithms/particle/TrackClusterSubtractor.h b/src/algorithms/particle/TrackClusterSubtractor.h index 20e23a91a2..251dba556e 100644 --- a/src/algorithms/particle/TrackClusterSubtractor.h +++ b/src/algorithms/particle/TrackClusterSubtractor.h @@ -60,7 +60,7 @@ class TrackClusterSubtractor : public TrackClusterSubtractorAlgorithm, ///! Alias for a map from a cluster to the segments of matched tracks using MapToVecSeg = std::map; - ///! CTOR DESCRIPTION WILL GO HERE + ///! Algorithm constructor TrackClusterSubtractor(std::string_view name) : TrackClusterSubtractorAlgorithm{name, {"inputTrackClusterMatches", @@ -70,12 +70,12 @@ class TrackClusterSubtractor : public TrackClusterSubtractorAlgorithm, "outputTrackSubtractedClusterMatches"}, "Subtracts energy of tracks pointing to clusters."} {} - void init(); + // public method void process(const Input&, const Output&) const final; private: - ///! private methods + // private methods double sum_track_energy(const VecSeg& projects) const; bool is_zero(const double difference) const; diff --git a/src/factories/particle/TrackClusterSubtractor_factory.h b/src/factories/particle/TrackClusterSubtractor_factory.h index cbe7ebfa7c..c8fa0ac42a 100644 --- a/src/factories/particle/TrackClusterSubtractor_factory.h +++ b/src/factories/particle/TrackClusterSubtractor_factory.h @@ -1,13 +1,11 @@ // SPDX-License-Identifier: LGPL-3.0-or-later -// Copyright (C) 2024 Derek Anderson +// Copyright (C) 2025 Derek Anderson #pragma once -// c++ utilities -#include -// dd4hep utilities #include -// eicrecon components +#include + #include "extensions/jana/JOmniFactory.h" #include "services/geometry/dd4hep/DD4hep_service.h" #include "services/algorithms_init/AlgorithmsInit_service.h" @@ -19,10 +17,13 @@ class TrackClusterSubtractor_factory : public JOmniFactory { public: + + ///! alias for algorithm name using AlgoT = eicrecon::TrackClusterSubtractor; private: - // algorithm to run + + // pointer to algorithm std::unique_ptr m_algo; // input collections @@ -47,22 +48,27 @@ class TrackClusterSubtractor_factory Service m_algoInitSvc{this}; public: + + ///! Configures algorithm void Configure() { m_algo = std::make_unique(GetPrefix()); m_algo->applyConfig(config()); m_algo->init(); } + ///! Applies any updates between changes in runs void ChangeRun(int64_t run_number) { //... nothing to do ...// } + ///! Primary algorithm call void Process(int64_t run_number, uint64_t event_number) { - m_algo->process({m_track_cluster_match_input(), m_track_projections_input()}, - {m_subtract_clusters_output().get(), m_remnant_clusters_output().get(), + m_algo->process({m_track_cluster_match_input(), + m_track_projections_input()}, + {m_subtract_clusters_output().get(), + m_remnant_clusters_output().get(), m_track_sub_cluster_match_output().get()}); } - }; // end TrackClusterSubtractor_factory } // namespace eicrecon From 298815fd74662d1da77aa881d894a1b02a01c4da Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 26 Aug 2025 22:10:39 +0000 Subject: [PATCH 19/46] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../particle/TrackClusterSubtractor.cc | 20 ++--- .../particle/TrackClusterSubtractor.h | 11 +-- .../particle/TrackClusterSubtractor_factory.h | 9 +-- src/global/particle/particle.cc | 75 ++++++------------- 4 files changed, 34 insertions(+), 81 deletions(-) diff --git a/src/algorithms/particle/TrackClusterSubtractor.cc b/src/algorithms/particle/TrackClusterSubtractor.cc index ce99f40fc1..9242ace31c 100644 --- a/src/algorithms/particle/TrackClusterSubtractor.cc +++ b/src/algorithms/particle/TrackClusterSubtractor.cc @@ -34,7 +34,7 @@ void TrackClusterSubtractor::process(const TrackClusterSubtractor::Input& input, const TrackClusterSubtractor::Output& output) const { // grab inputs/outputs - const auto [in_matches, in_projections] = input; + const auto [in_matches, in_projections] = input; auto [out_sub_clusters, out_remain_clusters, out_sub_matches] = output; // exit if no matched tracks in collection @@ -68,25 +68,24 @@ void TrackClusterSubtractor::process(const TrackClusterSubtractor::Input& input, // do subtraction const double eTrkSum = sum_track_energy(projects); - const double eToSub = m_cfg.fracEnergyToSub * eTrkSum; - const double eSub = cluster.getEnergy() - eToSub; + const double eToSub = m_cfg.fracEnergyToSub * eTrkSum; + const double eSub = cluster.getEnergy() - eToSub; trace("Subtracted {} GeV from cluster with {} GeV", eToSub, cluster.getEnergy()); // check if consistent with zero, // set eSub accordingly - const bool isZero = is_zero(eSub); + const bool isZero = is_zero(eSub); const double eSubToUse = isZero ? 0. : eSub; // calculate energy fractions - const double remainFrac = eSubToUse / cluster.getEnergy(); + const double remainFrac = eSubToUse / cluster.getEnergy(); const double subtractFrac = 1. - remainFrac; // scale subtracted cluster energy edm4eic::MutableCluster sub_clust = cluster.clone(); sub_clust.setEnergy(subtractFrac * cluster.getEnergy()); out_sub_clusters->push_back(sub_clust); - trace("Created subtracted cluster with {} GeV (originally {} GeV)", - sub_clust.getEnergy(), + trace("Created subtracted cluster with {} GeV (originally {} GeV)", sub_clust.getEnergy(), cluster.getEnergy()); // create track cluster matches @@ -95,8 +94,7 @@ void TrackClusterSubtractor::process(const TrackClusterSubtractor::Input& input, match.setCluster(sub_clust); match.setTrack(project.getTrack()); match.setWeight(1.0); // FIXME placeholder - trace("Matched subtracted cluster {} to track {}", - sub_clust.getObjectID().index, + trace("Matched subtracted cluster {} to track {}", sub_clust.getObjectID().index, project.getTrack().getObjectID().index); } @@ -179,9 +177,7 @@ bool TrackClusterSubtractor::is_zero(const double difference) const { bool isZero = false; if (m_cfg.doNSigmaCut) { isZero = (nSigma < m_cfg.nSigmaMax); - trace("Difference of {} GeV consistent with zero: nSigma = {} < {}", - difference, - nSigma, + trace("Difference of {} GeV consistent with zero: nSigma = {} < {}", difference, nSigma, m_cfg.nSigmaMax); } else { isZero = std::abs(difference) < std::numeric_limits::epsilon(); diff --git a/src/algorithms/particle/TrackClusterSubtractor.h b/src/algorithms/particle/TrackClusterSubtractor.h index 251dba556e..6f684543ab 100644 --- a/src/algorithms/particle/TrackClusterSubtractor.h +++ b/src/algorithms/particle/TrackClusterSubtractor.h @@ -20,10 +20,8 @@ namespace eicrecon { //! Algorithm input/output // -------------------------------------------------------------------------- using TrackClusterSubtractorAlgorithm = algorithms::Algorithm< - algorithms::Input, - algorithms::Output, + algorithms::Output>; // ========================================================================== @@ -37,7 +35,6 @@ class TrackClusterSubtractor : public TrackClusterSubtractorAlgorithm, public WithPodConfig { public: - // ------------------------------------------------------------------------ //! Comparator struct for clusters // ------------------------------------------------------------------------ @@ -63,8 +60,7 @@ class TrackClusterSubtractor : public TrackClusterSubtractorAlgorithm, ///! Algorithm constructor TrackClusterSubtractor(std::string_view name) : TrackClusterSubtractorAlgorithm{name, - {"inputTrackClusterMatches", - "inputTrackProjections"}, + {"inputTrackClusterMatches", "inputTrackProjections"}, {"outputSubtractedClusterCollection", "outputRemnantClusterCollection", "outputTrackSubtractedClusterMatches"}, @@ -74,7 +70,6 @@ class TrackClusterSubtractor : public TrackClusterSubtractorAlgorithm, void process(const Input&, const Output&) const final; private: - // private methods double sum_track_energy(const VecSeg& projects) const; bool is_zero(const double difference) const; diff --git a/src/factories/particle/TrackClusterSubtractor_factory.h b/src/factories/particle/TrackClusterSubtractor_factory.h index c8fa0ac42a..f75761237f 100644 --- a/src/factories/particle/TrackClusterSubtractor_factory.h +++ b/src/factories/particle/TrackClusterSubtractor_factory.h @@ -17,12 +17,10 @@ class TrackClusterSubtractor_factory : public JOmniFactory { public: - ///! alias for algorithm name using AlgoT = eicrecon::TrackClusterSubtractor; private: - // pointer to algorithm std::unique_ptr m_algo; @@ -48,7 +46,6 @@ class TrackClusterSubtractor_factory Service m_algoInitSvc{this}; public: - ///! Configures algorithm void Configure() { m_algo = std::make_unique(GetPrefix()); @@ -63,10 +60,8 @@ class TrackClusterSubtractor_factory ///! Primary algorithm call void Process(int64_t run_number, uint64_t event_number) { - m_algo->process({m_track_cluster_match_input(), - m_track_projections_input()}, - {m_subtract_clusters_output().get(), - m_remnant_clusters_output().get(), + m_algo->process({m_track_cluster_match_input(), m_track_projections_input()}, + {m_subtract_clusters_output().get(), m_remnant_clusters_output().get(), m_track_sub_cluster_match_output().get()}); } }; // end TrackClusterSubtractor_factory diff --git a/src/global/particle/particle.cc b/src/global/particle/particle.cc index 20b92ac516..36fc53ec74 100644 --- a/src/global/particle/particle.cc +++ b/src/global/particle/particle.cc @@ -35,31 +35,23 @@ void InitPlugin(JApplication* app) { app->Add(new JOmniFactoryGeneratorT( "EcalEndcapNSubtractedClusters", - {"EcalEndcapNTrackClusterMatches", - "CalorimeterTrackProjections"}, - {"EcalEndcapNSubtractedClusters", - "EcalEndcapNRemnantClusters", + {"EcalEndcapNTrackClusterMatches", "CalorimeterTrackProjections"}, + {"EcalEndcapNSubtractedClusters", "EcalEndcapNRemnantClusters", "EcalEndcapNTrackSubtractedClusterMatches"}, { - .fracEnergyToSub = 1.0, - .defaultMassPdg = 211, - .surfaceToUse = 1, + .fracEnergyToSub = 1.0, + .defaultMassPdg = 211, + .surfaceToUse = 1, }, app // TODO: remove me once fixed )); app->Add(new JOmniFactoryGeneratorT( "HcalEndcapNSubtractedClusters", - {"HcalEndcapNTrackClusterMatches", - "CalorimeterTrackProjections"}, - {"HcalEndcapNSubtractedClusters", - "HcalEndcapNRemnantClusters", + {"HcalEndcapNTrackClusterMatches", "CalorimeterTrackProjections"}, + {"HcalEndcapNSubtractedClusters", "HcalEndcapNRemnantClusters", "HcalEndcapNTrackSubtractedClusterMatches"}, - { - .fracEnergyToSub = 1.0, - .defaultMassPdg = 211, - .surfaceToUse = 1 - }, + {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, app // TODO: remove me once fixed )); @@ -67,31 +59,19 @@ void InitPlugin(JApplication* app) { app->Add(new JOmniFactoryGeneratorT( "EcalBarrelSubtractedClusters", - {"EcalBarrelTrackClusterMatches", - "CalorimeterTrackProjections"}, - {"EcalBarrelSubtractedClusters", - "EcalBarrelRemnantClusters", + {"EcalBarrelTrackClusterMatches", "CalorimeterTrackProjections"}, + {"EcalBarrelSubtractedClusters", "EcalBarrelRemnantClusters", "EcalBarrelTrackSubtractedClusterMatches"}, - { - .fracEnergyToSub = 1.0, - .defaultMassPdg = 211, - .surfaceToUse = 1 - }, + {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, app // TODO: remove me once fixed )); app->Add(new JOmniFactoryGeneratorT( "HcalBarrelSubtractedClusters", - {"HcalBarrelTrackClusterMatches", - "CalorimeterTrackProjections"}, - {"HcalBarrelSubtractedClusters", - "HcalBarrelRemnantClusters", + {"HcalBarrelTrackClusterMatches", "CalorimeterTrackProjections"}, + {"HcalBarrelSubtractedClusters", "HcalBarrelRemnantClusters", "HcalBarrelTrackSubtractedClusterMatches"}, - { - .fracEnergyToSub = 1.0, - .defaultMassPdg = 211, - .surfaceToUse = 1 - }, + {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, app // TODO: remove me once fixed )); @@ -99,31 +79,18 @@ void InitPlugin(JApplication* app) { app->Add(new JOmniFactoryGeneratorT( "EcalEndcapPSubtractedClusters", - {"EcalEndcapPTrackClusterMatches", - "CalorimeterTrackProjections"}, - {"EcalEndcapPSubtractedClusters", - "EcalEndcapPRemnantClusters", + {"EcalEndcapPTrackClusterMatches", "CalorimeterTrackProjections"}, + {"EcalEndcapPSubtractedClusters", "EcalEndcapPRemnantClusters", "EcalEndcapPTrackSubtractedClusterMatches"}, - { - .fracEnergyToSub = 1.0, - .defaultMassPdg = 211, - .surfaceToUse = 1 - }, + {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, app // TODO: remove me once fixed )); app->Add(new JOmniFactoryGeneratorT( "LFHCALSubtractedClusters", - {"LFHCALTrackSplitMergeClusterMatches", - "CalorimeterTrackProjections"}, - {"LFHCALSubtractedClusters", - "LFHCALRemnantClusters", - "LFHCALTrackSubtractedClusterMatches"}, - { - .fracEnergyToSub = 1.0, - .defaultMassPdg = 211, - .surfaceToUse = 1 - }, + {"LFHCALTrackSplitMergeClusterMatches", "CalorimeterTrackProjections"}, + {"LFHCALSubtractedClusters", "LFHCALRemnantClusters", "LFHCALTrackSubtractedClusterMatches"}, + {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, app // TODO: remove me once fixed )); @@ -145,4 +112,4 @@ void InitPlugin(JApplication* app) { /* TODO add here */ } -} // extern "C" +} // extern "C" From 88539e174e22311f5ae9fa848b34cc446479859d Mon Sep 17 00:00:00 2001 From: ruse-traveler Date: Thu, 28 Aug 2025 15:18:24 -0400 Subject: [PATCH 20/46] Fix merge conflicts --- .../particle/TrackClusterSubtractor.cc | 127 +++++++++++------- .../particle/TrackClusterSubtractor.h | 23 +++- .../particle/TrackClusterSubtractor_factory.h | 14 +- src/global/particle/particle.cc | 83 +++++++++--- 4 files changed, 164 insertions(+), 83 deletions(-) diff --git a/src/algorithms/particle/TrackClusterSubtractor.cc b/src/algorithms/particle/TrackClusterSubtractor.cc index 9242ace31c..969d771745 100644 --- a/src/algorithms/particle/TrackClusterSubtractor.cc +++ b/src/algorithms/particle/TrackClusterSubtractor.cc @@ -18,37 +18,46 @@ namespace eicrecon { -// -------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- //! Process inputs -// -------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- /*! Subtract energy of matched tracks via the following algorithm. - * 1. Build a map of each cluster onto a list of matched - * track projections. - * 2. For each cluster, subtract the sum of momenta of - * all matched tracks scaled by the specified fraction - * from the cluster's energy. - * 3. If subtracted energy is greater than 0, copy cluster - * into output with new subtracted energy. - */ + * 1. Build a map of each cluster onto a list of matched + * track projections. + * 2. For each cluster, subtract the sum of momenta of + * all matched tracks scaled by the specified fraction + * from the cluster's energy. + * 3. For each matched cluster: + * a. If subtracted energy is greater than zero, create + * a remnant cluster with the subtracted energy + * b. And create an expected cluster with energy equal + * to the difference between the total and the remnant. + * 4. Flag any un-matched clusters as remnants. + */ void TrackClusterSubtractor::process(const TrackClusterSubtractor::Input& input, const TrackClusterSubtractor::Output& output) const { // grab inputs/outputs - const auto [in_matches, in_projections] = input; - auto [out_sub_clusters, out_remain_clusters, out_sub_matches] = output; + const auto [in_match, in_cluster, in_project] = input; + auto [out_remnant, out_expect, out_match] = output; - // exit if no matched tracks in collection - if (in_matches->size() == 0) { - debug("No matched tracks in collection."); + // exit if no clusters in collection + if (in_cluster->size() == 0) { + debug("No clusters in collection"); return; } - // ------------------------------------------------------------------------ + // emit debugging message if no matched tracks in collection + if (in_match->size() == 0) { + debug("No matched tracks in collection."); + } + + // -------------------------------------------------------------------------- // 1. Build map of clusters onto projections - // ------------------------------------------------------------------------ + // -------------------------------------------------------------------------- MapToVecSeg mapClustToProj; - for (const auto& match : *in_matches) { - for (const auto& project : *in_projections) { + for (const auto& match : *in_match) { + for (const auto& project : *in_project) { // pick out corresponding projection from track if (match.getTrack() != project.getTrack()) { @@ -61,15 +70,23 @@ void TrackClusterSubtractor::process(const TrackClusterSubtractor::Input& input, } // end track-cluster match loop debug("Built map of clusters-onto-tracks, size = {}", mapClustToProj.size()); - // ------------------------------------------------------------------------ + // now identify any clusters without matching tracks + VecClust vecNoMatchClust; + for (const auto& cluster : *in_cluster) { + if (mapClustToProj.count(cluster) == 0) { + vecNoMatchClust.push_back(cluster); + } + } + debug("Built vector of unmatched clusters, size = {}", vecNoMatchClust.size()); + + // -------------------------------------------------------------------------- // 2. Subtract energy for tracks - // ------------------------------------------------------------------------ + // -------------------------------------------------------------------------- for (const auto& [cluster, projects] : mapClustToProj) { // do subtraction - const double eTrkSum = sum_track_energy(projects); - const double eToSub = m_cfg.fracEnergyToSub * eTrkSum; - const double eSub = cluster.getEnergy() - eToSub; + const double eToSub = m_cfg.fracEnergyToSub * sum_track_energy(projects); + const double eSub = cluster.getEnergy() - eToSub; trace("Subtracted {} GeV from cluster with {} GeV", eToSub, cluster.getEnergy()); // check if consistent with zero, @@ -77,44 +94,56 @@ void TrackClusterSubtractor::process(const TrackClusterSubtractor::Input& input, const bool isZero = is_zero(eSub); const double eSubToUse = isZero ? 0. : eSub; - // calculate energy fractions - const double remainFrac = eSubToUse / cluster.getEnergy(); - const double subtractFrac = 1. - remainFrac; + // ------------------------------------------------------------------------ + // 3(a). If difference not consistent with zero, create output remnant + // ------------------------------------------------------------------------ + if (!isZero) { + auto remain_clust = cluster.clone(); + remain_clust.setEnergy(eSubToUse); + out_remnant->push_back(remain_clust); + trace("Created remnant cluster with {} GeV", remain_clust.getEnergy()); + } - // scale subtracted cluster energy - edm4eic::MutableCluster sub_clust = cluster.clone(); - sub_clust.setEnergy(subtractFrac * cluster.getEnergy()); - out_sub_clusters->push_back(sub_clust); - trace("Created subtracted cluster with {} GeV (originally {} GeV)", sub_clust.getEnergy(), + // ------------------------------------------------------------------------ + // 3(b). Create cluster with energy equal to eTotal - eRemnant and match + // ------------------------------------------------------------------------ + auto expect_clust = cluster.clone(); + expect_clust.setEnergy(cluster.getEnergy() - eSubToUse); + out_expect->push_back(expect_clust); + trace("Created subtracted cluster with {} GeV (originally {} GeV)", + expect_clust.getEnergy(), cluster.getEnergy()); - // create track cluster matches + // create a track-cluster match for expected clusters for (const auto& project : projects) { - edm4eic::MutableTrackClusterMatch match = out_sub_matches->create(); - match.setCluster(sub_clust); + edm4eic::MutableTrackClusterMatch match = out_match->create(); + match.setCluster(expect_clust); match.setTrack(project.getTrack()); match.setWeight(1.0); // FIXME placeholder - trace("Matched subtracted cluster {} to track {}", sub_clust.getObjectID().index, + trace("Matched expected cluster {} to track {}", + expect_clust.getObjectID().index, project.getTrack().getObjectID().index); } - // if NOT consistent with zero, write - // out remnant cluster - if (!isZero) { - edm4eic::MutableCluster remain_clust = cluster.clone(); - remain_clust.setEnergy(remainFrac * cluster.getEnergy()); - out_remain_clusters->push_back(remain_clust); - trace("Created remnant cluster with {} GeV", remain_clust.getEnergy()); - } - } // end cluster-to-projections loop - debug("Finished subtraction, {} remnant clusters", out_remain_clusters->size()); + debug("Finished subtraction, {} remnant clusters and {} expected clusters", + out_remnant->size(), + out_expect->size()); + + // -------------------------------------------------------------------------- + // 4. Any unmatched clusters are remnants by definition + // -------------------------------------------------------------------------- + for (const auto& cluster : vecNoMatchClust) { + auto remain_clust = cluster.clone(); + out_remnant->push_back(remain_clust); + } + debug("Finished copying unmatched clusters to remnants, {} remnant clusters", out_remnant->size()); -} // end 'get_projections(edm4eic::CalorimeterHit&, edm4eic::TrackSegmentCollection&, VecTrkPoint&)' +} // end 'process(Input&, Output&)' -// -------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- //! Sum energy of tracks -// -------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- /*! Sums energy of tracks projected to the surface in the * calorimeter specified by `surfaceToUse`. Uses PDG of * track to select mass for energy; if not available, diff --git a/src/algorithms/particle/TrackClusterSubtractor.h b/src/algorithms/particle/TrackClusterSubtractor.h index 6f684543ab..65094444fa 100644 --- a/src/algorithms/particle/TrackClusterSubtractor.h +++ b/src/algorithms/particle/TrackClusterSubtractor.h @@ -20,8 +20,11 @@ namespace eicrecon { //! Algorithm input/output // -------------------------------------------------------------------------- using TrackClusterSubtractorAlgorithm = algorithms::Algorithm< - algorithms::Input, - algorithms::Output, + algorithms::Output>; // ========================================================================== @@ -29,7 +32,8 @@ using TrackClusterSubtractorAlgorithm = algorithms::Algorithm< // ========================================================================== /*! An algorithm which takes a collection of clusters and their matched * tracks, subtracts the sum of all tracks pointing to the cluster, - * and outputs the remnant cluster and their matched tracks. + * and outputs the remnant clusters, expected clusters, and their matched + * tracks. */ class TrackClusterSubtractor : public TrackClusterSubtractorAlgorithm, public WithPodConfig { @@ -51,6 +55,9 @@ class TrackClusterSubtractor : public TrackClusterSubtractorAlgorithm, } }; + ///! Alias for vectors of clusters + using VecClust = std::vector; + ///! Alias for vectors of track segments using VecSeg = std::vector; @@ -60,10 +67,12 @@ class TrackClusterSubtractor : public TrackClusterSubtractorAlgorithm, ///! Algorithm constructor TrackClusterSubtractor(std::string_view name) : TrackClusterSubtractorAlgorithm{name, - {"inputTrackClusterMatches", "inputTrackProjections"}, - {"outputSubtractedClusterCollection", - "outputRemnantClusterCollection", - "outputTrackSubtractedClusterMatches"}, + {"inputTrackClusterMatches", + "inputClusters", + "inputTrackProjections"}, + {"outputRemnantClusterCollection", + "outputExpectedClusterCollection", + "outputTrackExpectedClusterMatches"}, "Subtracts energy of tracks pointing to clusters."} {} // public method diff --git a/src/factories/particle/TrackClusterSubtractor_factory.h b/src/factories/particle/TrackClusterSubtractor_factory.h index f75761237f..41339e78e6 100644 --- a/src/factories/particle/TrackClusterSubtractor_factory.h +++ b/src/factories/particle/TrackClusterSubtractor_factory.h @@ -26,12 +26,13 @@ class TrackClusterSubtractor_factory // input collections PodioInput m_track_cluster_match_input{this}; + PodioInput m_clusters_input{this}; PodioInput m_track_projections_input{this}; // output collections - PodioOutput m_subtract_clusters_output{this}; PodioOutput m_remnant_clusters_output{this}; - PodioOutput m_track_sub_cluster_match_output{this}; + PodioOutput m_expected_clusters_output{this}; + PodioOutput m_track_expected_match_output{this}; // parameter bindings ParameterRef m_fracEnergyToSub{this, "fracEnergyToSub", config().fracEnergyToSub}; @@ -60,9 +61,12 @@ class TrackClusterSubtractor_factory ///! Primary algorithm call void Process(int64_t run_number, uint64_t event_number) { - m_algo->process({m_track_cluster_match_input(), m_track_projections_input()}, - {m_subtract_clusters_output().get(), m_remnant_clusters_output().get(), - m_track_sub_cluster_match_output().get()}); + m_algo->process({m_track_cluster_match_input(), + m_clusters_input(), + m_track_projections_input()}, + {m_remnant_clusters_output().get(), + m_expected_clusters_output().get(), + m_track_expected_match_output().get()}); } }; // end TrackClusterSubtractor_factory diff --git a/src/global/particle/particle.cc b/src/global/particle/particle.cc index 36fc53ec74..e4605188eb 100644 --- a/src/global/particle/particle.cc +++ b/src/global/particle/particle.cc @@ -35,9 +35,12 @@ void InitPlugin(JApplication* app) { app->Add(new JOmniFactoryGeneratorT( "EcalEndcapNSubtractedClusters", - {"EcalEndcapNTrackClusterMatches", "CalorimeterTrackProjections"}, - {"EcalEndcapNSubtractedClusters", "EcalEndcapNRemnantClusters", - "EcalEndcapNTrackSubtractedClusterMatches"}, + {"EcalEndcapNTrackClusterMatches", + "EcalEndcapNClusters", + "CalorimeterTrackProjections"}, + {"EcalEndcapNRemnantClusters", + "EcalEndcapNExpectedClusters", + "EcalEndcapNTrackExpectedClusterMatches"}, { .fracEnergyToSub = 1.0, .defaultMassPdg = 211, @@ -48,10 +51,17 @@ void InitPlugin(JApplication* app) { app->Add(new JOmniFactoryGeneratorT( "HcalEndcapNSubtractedClusters", - {"HcalEndcapNTrackClusterMatches", "CalorimeterTrackProjections"}, - {"HcalEndcapNSubtractedClusters", "HcalEndcapNRemnantClusters", - "HcalEndcapNTrackSubtractedClusterMatches"}, - {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, + {"HcalEndcapNTrackClusterMatches", + "HcalEndcapNClusters", + "CalorimeterTrackProjections"}, + {"HcalEndcapNRemnantClusters", + "HcalEndcapNExpectedClusters", + "HcalEndcapNTrackExpectedClusterMatches"}, + { + .fracEnergyToSub = 1.0, + .defaultMassPdg = 211, + .surfaceToUse = 1 + }, app // TODO: remove me once fixed )); @@ -59,19 +69,33 @@ void InitPlugin(JApplication* app) { app->Add(new JOmniFactoryGeneratorT( "EcalBarrelSubtractedClusters", - {"EcalBarrelTrackClusterMatches", "CalorimeterTrackProjections"}, - {"EcalBarrelSubtractedClusters", "EcalBarrelRemnantClusters", - "EcalBarrelTrackSubtractedClusterMatches"}, - {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, + {"EcalBarrelTrackClusterMatches", + "EcalBarrelClusters", + "CalorimeterTrackProjections"}, + {"EcalBarrelRemnantClusters", + "EcalBarrelExpectedClusters", + "EcalBarrelTrackExpectedClusterMatches"}, + { + .fracEnergyToSub = 1.0, + .defaultMassPdg = 211, + .surfaceToUse = 1 + }, app // TODO: remove me once fixed )); app->Add(new JOmniFactoryGeneratorT( "HcalBarrelSubtractedClusters", - {"HcalBarrelTrackClusterMatches", "CalorimeterTrackProjections"}, - {"HcalBarrelSubtractedClusters", "HcalBarrelRemnantClusters", - "HcalBarrelTrackSubtractedClusterMatches"}, - {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, + {"HcalBarrelTrackClusterMatches", + "HcalBarrelClusters", + "CalorimeterTrackProjections"}, + {"HcalBarrelRemnantClusters", + "HcalBarrelExpectedClusters", + "HcalBarrelTrackExpectedClusterMatches"}, + { + .fracEnergyToSub = 1.0, + .defaultMassPdg = 211, + .surfaceToUse = 1 + }, app // TODO: remove me once fixed )); @@ -79,18 +103,33 @@ void InitPlugin(JApplication* app) { app->Add(new JOmniFactoryGeneratorT( "EcalEndcapPSubtractedClusters", - {"EcalEndcapPTrackClusterMatches", "CalorimeterTrackProjections"}, - {"EcalEndcapPSubtractedClusters", "EcalEndcapPRemnantClusters", - "EcalEndcapPTrackSubtractedClusterMatches"}, - {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, + {"EcalEndcapPTrackClusterMatches", + "EcalEndcapPClusters", + "CalorimeterTrackProjections"}, + {"EcalEndcapPRemnantClusters", + "EcalEndcapPExpectedClusters", + "EcalEndcapPTrackExpectedClusterMatches"}, + { + .fracEnergyToSub = 1.0, + .defaultMassPdg = 211, + .surfaceToUse = 1 + }, app // TODO: remove me once fixed )); app->Add(new JOmniFactoryGeneratorT( "LFHCALSubtractedClusters", - {"LFHCALTrackSplitMergeClusterMatches", "CalorimeterTrackProjections"}, - {"LFHCALSubtractedClusters", "LFHCALRemnantClusters", "LFHCALTrackSubtractedClusterMatches"}, - {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, + {"LFHCALTrackSplitMergeClusterMatches", + "LFHCALClusters", + "CalorimeterTrackProjections"}, + {"LFHCALRemnantClusters", + "LFHCALExpectedClusters", + "LFHCALTrackExpectedClusterMatches"}, + { + .fracEnergyToSub = 1.0, + .defaultMassPdg = 211, + .surfaceToUse = 1 + }, app // TODO: remove me once fixed )); From 7df36f30b736783812750a575d88b0ddfc53b96b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 28 Aug 2025 19:19:35 +0000 Subject: [PATCH 21/46] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../particle/TrackClusterSubtractor.cc | 16 ++-- .../particle/TrackClusterSubtractor.h | 20 ++--- .../particle/TrackClusterSubtractor_factory.h | 10 +-- src/global/particle/particle.cc | 73 +++++-------------- 4 files changed, 36 insertions(+), 83 deletions(-) diff --git a/src/algorithms/particle/TrackClusterSubtractor.cc b/src/algorithms/particle/TrackClusterSubtractor.cc index 969d771745..f68d7696c8 100644 --- a/src/algorithms/particle/TrackClusterSubtractor.cc +++ b/src/algorithms/particle/TrackClusterSubtractor.cc @@ -39,7 +39,7 @@ void TrackClusterSubtractor::process(const TrackClusterSubtractor::Input& input, // grab inputs/outputs const auto [in_match, in_cluster, in_project] = input; - auto [out_remnant, out_expect, out_match] = output; + auto [out_remnant, out_expect, out_match] = output; // exit if no clusters in collection if (in_cluster->size() == 0) { @@ -86,7 +86,7 @@ void TrackClusterSubtractor::process(const TrackClusterSubtractor::Input& input, // do subtraction const double eToSub = m_cfg.fracEnergyToSub * sum_track_energy(projects); - const double eSub = cluster.getEnergy() - eToSub; + const double eSub = cluster.getEnergy() - eToSub; trace("Subtracted {} GeV from cluster with {} GeV", eToSub, cluster.getEnergy()); // check if consistent with zero, @@ -110,8 +110,7 @@ void TrackClusterSubtractor::process(const TrackClusterSubtractor::Input& input, auto expect_clust = cluster.clone(); expect_clust.setEnergy(cluster.getEnergy() - eSubToUse); out_expect->push_back(expect_clust); - trace("Created subtracted cluster with {} GeV (originally {} GeV)", - expect_clust.getEnergy(), + trace("Created subtracted cluster with {} GeV (originally {} GeV)", expect_clust.getEnergy(), cluster.getEnergy()); // create a track-cluster match for expected clusters @@ -120,14 +119,12 @@ void TrackClusterSubtractor::process(const TrackClusterSubtractor::Input& input, match.setCluster(expect_clust); match.setTrack(project.getTrack()); match.setWeight(1.0); // FIXME placeholder - trace("Matched expected cluster {} to track {}", - expect_clust.getObjectID().index, + trace("Matched expected cluster {} to track {}", expect_clust.getObjectID().index, project.getTrack().getObjectID().index); } } // end cluster-to-projections loop - debug("Finished subtraction, {} remnant clusters and {} expected clusters", - out_remnant->size(), + debug("Finished subtraction, {} remnant clusters and {} expected clusters", out_remnant->size(), out_expect->size()); // -------------------------------------------------------------------------- @@ -137,7 +134,8 @@ void TrackClusterSubtractor::process(const TrackClusterSubtractor::Input& input, auto remain_clust = cluster.clone(); out_remnant->push_back(remain_clust); } - debug("Finished copying unmatched clusters to remnants, {} remnant clusters", out_remnant->size()); + debug("Finished copying unmatched clusters to remnants, {} remnant clusters", + out_remnant->size()); } // end 'process(Input&, Output&)' diff --git a/src/algorithms/particle/TrackClusterSubtractor.h b/src/algorithms/particle/TrackClusterSubtractor.h index 65094444fa..fb42c1c5ab 100644 --- a/src/algorithms/particle/TrackClusterSubtractor.h +++ b/src/algorithms/particle/TrackClusterSubtractor.h @@ -20,11 +20,9 @@ namespace eicrecon { //! Algorithm input/output // -------------------------------------------------------------------------- using TrackClusterSubtractorAlgorithm = algorithms::Algorithm< - algorithms::Input, - algorithms::Output>; // ========================================================================== @@ -66,14 +64,12 @@ class TrackClusterSubtractor : public TrackClusterSubtractorAlgorithm, ///! Algorithm constructor TrackClusterSubtractor(std::string_view name) - : TrackClusterSubtractorAlgorithm{name, - {"inputTrackClusterMatches", - "inputClusters", - "inputTrackProjections"}, - {"outputRemnantClusterCollection", - "outputExpectedClusterCollection", - "outputTrackExpectedClusterMatches"}, - "Subtracts energy of tracks pointing to clusters."} {} + : TrackClusterSubtractorAlgorithm{ + name, + {"inputTrackClusterMatches", "inputClusters", "inputTrackProjections"}, + {"outputRemnantClusterCollection", "outputExpectedClusterCollection", + "outputTrackExpectedClusterMatches"}, + "Subtracts energy of tracks pointing to clusters."} {} // public method void process(const Input&, const Output&) const final; diff --git a/src/factories/particle/TrackClusterSubtractor_factory.h b/src/factories/particle/TrackClusterSubtractor_factory.h index 41339e78e6..1534034b0a 100644 --- a/src/factories/particle/TrackClusterSubtractor_factory.h +++ b/src/factories/particle/TrackClusterSubtractor_factory.h @@ -61,12 +61,10 @@ class TrackClusterSubtractor_factory ///! Primary algorithm call void Process(int64_t run_number, uint64_t event_number) { - m_algo->process({m_track_cluster_match_input(), - m_clusters_input(), - m_track_projections_input()}, - {m_remnant_clusters_output().get(), - m_expected_clusters_output().get(), - m_track_expected_match_output().get()}); + m_algo->process( + {m_track_cluster_match_input(), m_clusters_input(), m_track_projections_input()}, + {m_remnant_clusters_output().get(), m_expected_clusters_output().get(), + m_track_expected_match_output().get()}); } }; // end TrackClusterSubtractor_factory diff --git a/src/global/particle/particle.cc b/src/global/particle/particle.cc index e4605188eb..14b2924f92 100644 --- a/src/global/particle/particle.cc +++ b/src/global/particle/particle.cc @@ -35,11 +35,8 @@ void InitPlugin(JApplication* app) { app->Add(new JOmniFactoryGeneratorT( "EcalEndcapNSubtractedClusters", - {"EcalEndcapNTrackClusterMatches", - "EcalEndcapNClusters", - "CalorimeterTrackProjections"}, - {"EcalEndcapNRemnantClusters", - "EcalEndcapNExpectedClusters", + {"EcalEndcapNTrackClusterMatches", "EcalEndcapNClusters", "CalorimeterTrackProjections"}, + {"EcalEndcapNRemnantClusters", "EcalEndcapNExpectedClusters", "EcalEndcapNTrackExpectedClusterMatches"}, { .fracEnergyToSub = 1.0, @@ -51,17 +48,10 @@ void InitPlugin(JApplication* app) { app->Add(new JOmniFactoryGeneratorT( "HcalEndcapNSubtractedClusters", - {"HcalEndcapNTrackClusterMatches", - "HcalEndcapNClusters", - "CalorimeterTrackProjections"}, - {"HcalEndcapNRemnantClusters", - "HcalEndcapNExpectedClusters", + {"HcalEndcapNTrackClusterMatches", "HcalEndcapNClusters", "CalorimeterTrackProjections"}, + {"HcalEndcapNRemnantClusters", "HcalEndcapNExpectedClusters", "HcalEndcapNTrackExpectedClusterMatches"}, - { - .fracEnergyToSub = 1.0, - .defaultMassPdg = 211, - .surfaceToUse = 1 - }, + {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, app // TODO: remove me once fixed )); @@ -69,33 +59,19 @@ void InitPlugin(JApplication* app) { app->Add(new JOmniFactoryGeneratorT( "EcalBarrelSubtractedClusters", - {"EcalBarrelTrackClusterMatches", - "EcalBarrelClusters", - "CalorimeterTrackProjections"}, - {"EcalBarrelRemnantClusters", - "EcalBarrelExpectedClusters", + {"EcalBarrelTrackClusterMatches", "EcalBarrelClusters", "CalorimeterTrackProjections"}, + {"EcalBarrelRemnantClusters", "EcalBarrelExpectedClusters", "EcalBarrelTrackExpectedClusterMatches"}, - { - .fracEnergyToSub = 1.0, - .defaultMassPdg = 211, - .surfaceToUse = 1 - }, + {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, app // TODO: remove me once fixed )); app->Add(new JOmniFactoryGeneratorT( "HcalBarrelSubtractedClusters", - {"HcalBarrelTrackClusterMatches", - "HcalBarrelClusters", - "CalorimeterTrackProjections"}, - {"HcalBarrelRemnantClusters", - "HcalBarrelExpectedClusters", + {"HcalBarrelTrackClusterMatches", "HcalBarrelClusters", "CalorimeterTrackProjections"}, + {"HcalBarrelRemnantClusters", "HcalBarrelExpectedClusters", "HcalBarrelTrackExpectedClusterMatches"}, - { - .fracEnergyToSub = 1.0, - .defaultMassPdg = 211, - .surfaceToUse = 1 - }, + {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, app // TODO: remove me once fixed )); @@ -103,33 +79,18 @@ void InitPlugin(JApplication* app) { app->Add(new JOmniFactoryGeneratorT( "EcalEndcapPSubtractedClusters", - {"EcalEndcapPTrackClusterMatches", - "EcalEndcapPClusters", - "CalorimeterTrackProjections"}, - {"EcalEndcapPRemnantClusters", - "EcalEndcapPExpectedClusters", + {"EcalEndcapPTrackClusterMatches", "EcalEndcapPClusters", "CalorimeterTrackProjections"}, + {"EcalEndcapPRemnantClusters", "EcalEndcapPExpectedClusters", "EcalEndcapPTrackExpectedClusterMatches"}, - { - .fracEnergyToSub = 1.0, - .defaultMassPdg = 211, - .surfaceToUse = 1 - }, + {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, app // TODO: remove me once fixed )); app->Add(new JOmniFactoryGeneratorT( "LFHCALSubtractedClusters", - {"LFHCALTrackSplitMergeClusterMatches", - "LFHCALClusters", - "CalorimeterTrackProjections"}, - {"LFHCALRemnantClusters", - "LFHCALExpectedClusters", - "LFHCALTrackExpectedClusterMatches"}, - { - .fracEnergyToSub = 1.0, - .defaultMassPdg = 211, - .surfaceToUse = 1 - }, + {"LFHCALTrackSplitMergeClusterMatches", "LFHCALClusters", "CalorimeterTrackProjections"}, + {"LFHCALRemnantClusters", "LFHCALExpectedClusters", "LFHCALTrackExpectedClusterMatches"}, + {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, app // TODO: remove me once fixed )); From ff0a01b67b4bdb028ff7cf59951e5a0da6bb6117 Mon Sep 17 00:00:00 2001 From: ruse-traveler Date: Thu, 18 Sep 2025 14:04:34 -0400 Subject: [PATCH 22/46] Remove unused ChangeRun, make Process consistent with base class --- src/factories/particle/TrackClusterSubtractor_factory.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/factories/particle/TrackClusterSubtractor_factory.h b/src/factories/particle/TrackClusterSubtractor_factory.h index 1534034b0a..0037c77fe6 100644 --- a/src/factories/particle/TrackClusterSubtractor_factory.h +++ b/src/factories/particle/TrackClusterSubtractor_factory.h @@ -54,13 +54,8 @@ class TrackClusterSubtractor_factory m_algo->init(); } - ///! Applies any updates between changes in runs - void ChangeRun(int64_t run_number) { - //... nothing to do ...// - } - ///! Primary algorithm call - void Process(int64_t run_number, uint64_t event_number) { + void Process(int32_t /*run_number*/, uint64_t /*event_number*/) { m_algo->process( {m_track_cluster_match_input(), m_clusters_input(), m_track_projections_input()}, {m_remnant_clusters_output().get(), m_expected_clusters_output().get(), From 9cdd2dce20c7f9dc868d01802b0ce20869056239 Mon Sep 17 00:00:00 2001 From: ruse-traveler Date: Thu, 18 Sep 2025 14:31:48 -0400 Subject: [PATCH 23/46] Add outputs to defaults --- src/services/io/podio/JEventProcessorPODIO.cc | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/services/io/podio/JEventProcessorPODIO.cc b/src/services/io/podio/JEventProcessorPODIO.cc index 01d6af2102..da3e2c7374 100644 --- a/src/services/io/podio/JEventProcessorPODIO.cc +++ b/src/services/io/podio/JEventProcessorPODIO.cc @@ -370,6 +370,26 @@ JEventProcessorPODIO::JEventProcessorPODIO() { "DIRCTruthSeededParticleIDs", "DIRCParticleIDs", + // particle flow + "EcalBarrelRemnantClusters", + "EcalBarrelExpectedClusters", + "EcalBarrelTrackExpectedClusterMatches", + "EcalEndcapNRemnantClusters", + "EcalEndcapNExpectedClusters", + "EcalEndcapNTrackExpectedClusterMatches", + "EcalEndcapPRemnantClusters", + "EcalEndcapPExpectedClusters", + "EcalEndcapPTrackExpectedClusterMatches", + "HcalBarrelRemnantClusters", + "HcalBarrelExpectedClusters", + "HcalBarrelTrackExpectedClusterMatches", + "HcalEndcapNRemnantClusters", + "HcalEndcapNExpectedClusters", + "HcalEndcapNTrackExpectedClusterMatches", + "LFHCALRemnantClusters", + "LFHCALExpectedClusters", + "LFHCALTrackExpectedClusterMatches", + "B0ECalRawHitAssociations", "EcalBarrelScFiRawHitAssociations", "EcalBarrelImagingRawHitAssociations", From b9f43005f215e0de80662e48613d486c05e88cb0 Mon Sep 17 00:00:00 2001 From: ruse-traveler Date: Thu, 18 Sep 2025 15:24:36 -0400 Subject: [PATCH 24/46] Clean up, add header guards --- .../particle/TrackClusterSubtractor.cc | 23 ++++++----- .../particle/TrackClusterSubtractor.h | 7 ++++ src/global/particle/particle.cc | 11 ++--- src/services/io/podio/JEventProcessorPODIO.cc | 40 +++++++++---------- 4 files changed, 47 insertions(+), 34 deletions(-) diff --git a/src/algorithms/particle/TrackClusterSubtractor.cc b/src/algorithms/particle/TrackClusterSubtractor.cc index f68d7696c8..bd967d9600 100644 --- a/src/algorithms/particle/TrackClusterSubtractor.cc +++ b/src/algorithms/particle/TrackClusterSubtractor.cc @@ -1,6 +1,7 @@ // SPDX-License-Identifier: LGPL-3.0-or-later // Copyright (C) 2025 Derek Anderson +#include #include #include #include @@ -12,6 +13,7 @@ #include #include #include +#if EDM4EIC_VERSION_MAJOR >= 8 #include "TrackClusterSubtractor.h" #include "algorithms/particle/TrackClusterSubtractorConfig.h" @@ -86,12 +88,12 @@ void TrackClusterSubtractor::process(const TrackClusterSubtractor::Input& input, // do subtraction const double eToSub = m_cfg.fracEnergyToSub * sum_track_energy(projects); - const double eSub = cluster.getEnergy() - eToSub; + const double eSub = cluster.getEnergy() - eToSub; trace("Subtracted {} GeV from cluster with {} GeV", eToSub, cluster.getEnergy()); // check if consistent with zero, // set eSub accordingly - const bool isZero = is_zero(eSub); + const bool isZero = is_zero(eSub); const double eSubToUse = isZero ? 0. : eSub; // ------------------------------------------------------------------------ @@ -110,7 +112,8 @@ void TrackClusterSubtractor::process(const TrackClusterSubtractor::Input& input, auto expect_clust = cluster.clone(); expect_clust.setEnergy(cluster.getEnergy() - eSubToUse); out_expect->push_back(expect_clust); - trace("Created subtracted cluster with {} GeV (originally {} GeV)", expect_clust.getEnergy(), + trace("Created subtracted cluster with {} GeV (originally {} GeV)", + expect_clust.getEnergy(), cluster.getEnergy()); // create a track-cluster match for expected clusters @@ -122,9 +125,9 @@ void TrackClusterSubtractor::process(const TrackClusterSubtractor::Input& input, trace("Matched expected cluster {} to track {}", expect_clust.getObjectID().index, project.getTrack().getObjectID().index); } - } // end cluster-to-projections loop - debug("Finished subtraction, {} remnant clusters and {} expected clusters", out_remnant->size(), + debug("Finished subtraction, {} remnant clusters and {} expected clusters", + out_remnant->size(), out_expect->size()); // -------------------------------------------------------------------------- @@ -204,14 +207,16 @@ bool TrackClusterSubtractor::is_zero(const double difference) const { bool isZero = false; if (m_cfg.doNSigmaCut) { isZero = (nSigma < m_cfg.nSigmaMax); - trace("Difference of {} GeV consistent with zero: nSigma = {} < {}", difference, nSigma, + trace("Difference of {} GeV consistent with zero: nSigma = {} < {}", + difference, + nSigma, m_cfg.nSigmaMax); } else { - isZero = std::abs(difference) < std::numeric_limits::epsilon(); - trace("Difference of {} GeV consistent with zero within an epsilon", difference); + isZero = std::abs(difference) < std::numeric_limits::epsilon(); trace("Difference of {} GeV consistent with zero within an epsilon", difference); } return isZero; } // end 'is_zero(double)' - } // namespace eicrecon + +#endif // EDM4EIC_VERSION_MAJOR >= 8 diff --git a/src/algorithms/particle/TrackClusterSubtractor.h b/src/algorithms/particle/TrackClusterSubtractor.h index fb42c1c5ab..4cf824acef 100644 --- a/src/algorithms/particle/TrackClusterSubtractor.h +++ b/src/algorithms/particle/TrackClusterSubtractor.h @@ -3,9 +3,12 @@ #pragma once +#include #include #include +#if EDM4EIC_VERSION_MAJOR >= 8 #include +#endif #include #include #include @@ -14,6 +17,8 @@ #include "algorithms/interfaces/ParticleSvc.h" #include "algorithms/interfaces/WithPodConfig.h" +#if EDM4EIC_VERSION_MAJOR >= 8 + namespace eicrecon { // -------------------------------------------------------------------------- @@ -85,3 +90,5 @@ class TrackClusterSubtractor : public TrackClusterSubtractorAlgorithm, }; // end TrackClusterSubtractor } // namespace eicrecon + +#endif // EDM4EIC_VERSION_MAJOR >= 8 diff --git a/src/global/particle/particle.cc b/src/global/particle/particle.cc index 14b2924f92..211e6737af 100644 --- a/src/global/particle/particle.cc +++ b/src/global/particle/particle.cc @@ -7,7 +7,10 @@ #include #include "extensions/jana/JOmniFactoryGeneratorT.h" + +#if EDM4EIC_VERSION_MAJOR >= 8 #include "factories/particle/TrackClusterSubtractor_factory.h" +#endif extern "C" { @@ -33,16 +36,13 @@ void InitPlugin(JApplication* app) { // backward ----------------------------------------------------------- +#if EDM4EIC_VERSION_MAJOR >= 8 app->Add(new JOmniFactoryGeneratorT( "EcalEndcapNSubtractedClusters", {"EcalEndcapNTrackClusterMatches", "EcalEndcapNClusters", "CalorimeterTrackProjections"}, {"EcalEndcapNRemnantClusters", "EcalEndcapNExpectedClusters", "EcalEndcapNTrackExpectedClusterMatches"}, - { - .fracEnergyToSub = 1.0, - .defaultMassPdg = 211, - .surfaceToUse = 1, - }, + {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, app // TODO: remove me once fixed )); @@ -93,6 +93,7 @@ void InitPlugin(JApplication* app) { {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, app // TODO: remove me once fixed )); +#endif // -------------------------------------------------------------------- // PFA (1b) arbitration: form charged candidates diff --git a/src/services/io/podio/JEventProcessorPODIO.cc b/src/services/io/podio/JEventProcessorPODIO.cc index da3e2c7374..214575b674 100644 --- a/src/services/io/podio/JEventProcessorPODIO.cc +++ b/src/services/io/podio/JEventProcessorPODIO.cc @@ -370,26 +370,6 @@ JEventProcessorPODIO::JEventProcessorPODIO() { "DIRCTruthSeededParticleIDs", "DIRCParticleIDs", - // particle flow - "EcalBarrelRemnantClusters", - "EcalBarrelExpectedClusters", - "EcalBarrelTrackExpectedClusterMatches", - "EcalEndcapNRemnantClusters", - "EcalEndcapNExpectedClusters", - "EcalEndcapNTrackExpectedClusterMatches", - "EcalEndcapPRemnantClusters", - "EcalEndcapPExpectedClusters", - "EcalEndcapPTrackExpectedClusterMatches", - "HcalBarrelRemnantClusters", - "HcalBarrelExpectedClusters", - "HcalBarrelTrackExpectedClusterMatches", - "HcalEndcapNRemnantClusters", - "HcalEndcapNExpectedClusters", - "HcalEndcapNTrackExpectedClusterMatches", - "LFHCALRemnantClusters", - "LFHCALExpectedClusters", - "LFHCALTrackExpectedClusterMatches", - "B0ECalRawHitAssociations", "EcalBarrelScFiRawHitAssociations", "EcalBarrelImagingRawHitAssociations", @@ -410,6 +390,26 @@ JEventProcessorPODIO::JEventProcessorPODIO() { "HcalBarrelTrackClusterMatches", "EcalEndcapNTrackClusterMatches", "HcalEndcapNTrackClusterMatches", + + // particle flow + "EcalBarrelRemnantClusters", + "EcalBarrelExpectedClusters", + "EcalBarrelTrackExpectedClusterMatches", + "EcalEndcapNRemnantClusters", + "EcalEndcapNExpectedClusters", + "EcalEndcapNTrackExpectedClusterMatches", + "EcalEndcapPRemnantClusters", + "EcalEndcapPExpectedClusters", + "EcalEndcapPTrackExpectedClusterMatches", + "HcalBarrelRemnantClusters", + "HcalBarrelExpectedClusters", + "HcalBarrelTrackExpectedClusterMatches", + "HcalEndcapNRemnantClusters", + "HcalEndcapNExpectedClusters", + "HcalEndcapNTrackExpectedClusterMatches", + "LFHCALRemnantClusters", + "LFHCALExpectedClusters", + "LFHCALTrackExpectedClusterMatches", #endif }; From f0cc6506d70759849aebb254921d86e159c45f15 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 18 Sep 2025 19:26:06 +0000 Subject: [PATCH 25/46] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../particle/TrackClusterSubtractor.cc | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/algorithms/particle/TrackClusterSubtractor.cc b/src/algorithms/particle/TrackClusterSubtractor.cc index bd967d9600..c529cb8408 100644 --- a/src/algorithms/particle/TrackClusterSubtractor.cc +++ b/src/algorithms/particle/TrackClusterSubtractor.cc @@ -88,12 +88,12 @@ void TrackClusterSubtractor::process(const TrackClusterSubtractor::Input& input, // do subtraction const double eToSub = m_cfg.fracEnergyToSub * sum_track_energy(projects); - const double eSub = cluster.getEnergy() - eToSub; + const double eSub = cluster.getEnergy() - eToSub; trace("Subtracted {} GeV from cluster with {} GeV", eToSub, cluster.getEnergy()); // check if consistent with zero, // set eSub accordingly - const bool isZero = is_zero(eSub); + const bool isZero = is_zero(eSub); const double eSubToUse = isZero ? 0. : eSub; // ------------------------------------------------------------------------ @@ -112,8 +112,7 @@ void TrackClusterSubtractor::process(const TrackClusterSubtractor::Input& input, auto expect_clust = cluster.clone(); expect_clust.setEnergy(cluster.getEnergy() - eSubToUse); out_expect->push_back(expect_clust); - trace("Created subtracted cluster with {} GeV (originally {} GeV)", - expect_clust.getEnergy(), + trace("Created subtracted cluster with {} GeV (originally {} GeV)", expect_clust.getEnergy(), cluster.getEnergy()); // create a track-cluster match for expected clusters @@ -126,8 +125,7 @@ void TrackClusterSubtractor::process(const TrackClusterSubtractor::Input& input, project.getTrack().getObjectID().index); } } // end cluster-to-projections loop - debug("Finished subtraction, {} remnant clusters and {} expected clusters", - out_remnant->size(), + debug("Finished subtraction, {} remnant clusters and {} expected clusters", out_remnant->size(), out_expect->size()); // -------------------------------------------------------------------------- @@ -207,12 +205,11 @@ bool TrackClusterSubtractor::is_zero(const double difference) const { bool isZero = false; if (m_cfg.doNSigmaCut) { isZero = (nSigma < m_cfg.nSigmaMax); - trace("Difference of {} GeV consistent with zero: nSigma = {} < {}", - difference, - nSigma, + trace("Difference of {} GeV consistent with zero: nSigma = {} < {}", difference, nSigma, m_cfg.nSigmaMax); } else { - isZero = std::abs(difference) < std::numeric_limits::epsilon(); trace("Difference of {} GeV consistent with zero within an epsilon", difference); + isZero = std::abs(difference) < std::numeric_limits::epsilon(); + trace("Difference of {} GeV consistent with zero within an epsilon", difference); } return isZero; From b1172a2554de6bdf7f54359fe14dbfc6e9c42c8e Mon Sep 17 00:00:00 2001 From: Wouter Deconinck Date: Thu, 18 Sep 2025 15:00:14 -0500 Subject: [PATCH 26/46] Implement Track-Cluster Subtraction (PFA1) (fix: iwyu) (#2087) This PR applies the include-what-you-use fixes as suggested by https://github.com/eic/EICrecon/actions/runs/17839250702. Please merge this PR into the branch `add-track-cluster-subtraction-pfa-one` to resolve failures in PR #1627. Auto-generated by [create-pull-request][1] [1]: https://github.com/peter-evans/create-pull-request Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/algorithms/particle/TrackClusterSubtractor.h | 7 +++++-- src/global/particle/particle.cc | 7 ++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/algorithms/particle/TrackClusterSubtractor.h b/src/algorithms/particle/TrackClusterSubtractor.h index 4cf824acef..bbcf6ba409 100644 --- a/src/algorithms/particle/TrackClusterSubtractor.h +++ b/src/algorithms/particle/TrackClusterSubtractor.h @@ -3,19 +3,22 @@ #pragma once -#include #include #include +#include +#include #if EDM4EIC_VERSION_MAJOR >= 8 #include #endif #include +#include #include #include +#include #include "TrackClusterSubtractorConfig.h" -#include "algorithms/interfaces/ParticleSvc.h" #include "algorithms/interfaces/WithPodConfig.h" +#include "services/particle/ParticleSvc.h" #if EDM4EIC_VERSION_MAJOR >= 8 diff --git a/src/global/particle/particle.cc b/src/global/particle/particle.cc index 211e6737af..a0baa147fd 100644 --- a/src/global/particle/particle.cc +++ b/src/global/particle/particle.cc @@ -1,10 +1,11 @@ // SPDX-License-Identifier: LGPL-3.0-or-later // Copyright (C) 2025 Derek Anderson +#include +#include #include -#include -#include -#include +#include +#include #include "extensions/jana/JOmniFactoryGeneratorT.h" From 7147e152b8b58461369a213e959e35225ce7718c Mon Sep 17 00:00:00 2001 From: ruse-traveler Date: Wed, 8 Oct 2025 11:03:42 -0400 Subject: [PATCH 27/46] Add FHCal insert --- src/global/particle/particle.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/global/particle/particle.cc b/src/global/particle/particle.cc index a0baa147fd..02d144d567 100644 --- a/src/global/particle/particle.cc +++ b/src/global/particle/particle.cc @@ -94,6 +94,15 @@ void InitPlugin(JApplication* app) { {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, app // TODO: remove me once fixed )); + + app->Add(new JOmniFactoryGeneratorT( + "HcalEndcapPInsertSubtractedClusters", + {"HcalEndcapPInsertTrackSplitMergeClusterMatches", "HcalEndcapPInsertClusters", "CalorimeterTrackProjections"}, + {"HcalEndcapPInsertRemnantClusters", "HcalEndcapPInsertExpectedClusters", "HcalEndcapPInsertTrackExpectedClusterMatches"}, + {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, + app // TODO: remove me once fixed + )); + #endif // -------------------------------------------------------------------- From 7e71e75c04e94af35d98c514940b4b55d47d7afb Mon Sep 17 00:00:00 2001 From: ruse-traveler Date: Wed, 8 Oct 2025 11:05:08 -0400 Subject: [PATCH 28/46] Make sure FHCal insert collections are in default output --- src/services/io/podio/JEventProcessorPODIO.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/services/io/podio/JEventProcessorPODIO.cc b/src/services/io/podio/JEventProcessorPODIO.cc index a9a7ff09da..d6ee7970c4 100644 --- a/src/services/io/podio/JEventProcessorPODIO.cc +++ b/src/services/io/podio/JEventProcessorPODIO.cc @@ -404,6 +404,9 @@ JEventProcessorPODIO::JEventProcessorPODIO() { "LFHCALRemnantClusters", "LFHCALExpectedClusters", "LFHCALTrackExpectedClusterMatches", + "HcalEndcapPInsertRemnantClusters", + "HcalEndcapPInsertExpectedClusters", + "HcalEndcapPInsertTrackExpectedClusterMatches", #endif }; From 6b0429da262c4122e4623be0c7a923bb7a45c396 Mon Sep 17 00:00:00 2001 From: ruse-traveler Date: Wed, 8 Oct 2025 11:05:37 -0400 Subject: [PATCH 29/46] Rename factories after primary output --- src/global/particle/particle.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/global/particle/particle.cc b/src/global/particle/particle.cc index 02d144d567..9adc8678cb 100644 --- a/src/global/particle/particle.cc +++ b/src/global/particle/particle.cc @@ -39,7 +39,7 @@ void InitPlugin(JApplication* app) { #if EDM4EIC_VERSION_MAJOR >= 8 app->Add(new JOmniFactoryGeneratorT( - "EcalEndcapNSubtractedClusters", + "EcalEndcapNRemnantClusters", {"EcalEndcapNTrackClusterMatches", "EcalEndcapNClusters", "CalorimeterTrackProjections"}, {"EcalEndcapNRemnantClusters", "EcalEndcapNExpectedClusters", "EcalEndcapNTrackExpectedClusterMatches"}, @@ -48,7 +48,7 @@ void InitPlugin(JApplication* app) { )); app->Add(new JOmniFactoryGeneratorT( - "HcalEndcapNSubtractedClusters", + "HcalEndcapNRemnantClusters", {"HcalEndcapNTrackClusterMatches", "HcalEndcapNClusters", "CalorimeterTrackProjections"}, {"HcalEndcapNRemnantClusters", "HcalEndcapNExpectedClusters", "HcalEndcapNTrackExpectedClusterMatches"}, @@ -59,7 +59,7 @@ void InitPlugin(JApplication* app) { // central ------------------------------------------------------------ app->Add(new JOmniFactoryGeneratorT( - "EcalBarrelSubtractedClusters", + "EcalBarrelRemnantClusters", {"EcalBarrelTrackClusterMatches", "EcalBarrelClusters", "CalorimeterTrackProjections"}, {"EcalBarrelRemnantClusters", "EcalBarrelExpectedClusters", "EcalBarrelTrackExpectedClusterMatches"}, @@ -68,7 +68,7 @@ void InitPlugin(JApplication* app) { )); app->Add(new JOmniFactoryGeneratorT( - "HcalBarrelSubtractedClusters", + "HcalBarrelRemnantClusters", {"HcalBarrelTrackClusterMatches", "HcalBarrelClusters", "CalorimeterTrackProjections"}, {"HcalBarrelRemnantClusters", "HcalBarrelExpectedClusters", "HcalBarrelTrackExpectedClusterMatches"}, @@ -79,7 +79,7 @@ void InitPlugin(JApplication* app) { // forward ------------------------------------------------------------ app->Add(new JOmniFactoryGeneratorT( - "EcalEndcapPSubtractedClusters", + "EcalEndcapPRemnantClusters", {"EcalEndcapPTrackClusterMatches", "EcalEndcapPClusters", "CalorimeterTrackProjections"}, {"EcalEndcapPRemnantClusters", "EcalEndcapPExpectedClusters", "EcalEndcapPTrackExpectedClusterMatches"}, @@ -88,7 +88,7 @@ void InitPlugin(JApplication* app) { )); app->Add(new JOmniFactoryGeneratorT( - "LFHCALSubtractedClusters", + "LFHCALRemnantClusters", {"LFHCALTrackSplitMergeClusterMatches", "LFHCALClusters", "CalorimeterTrackProjections"}, {"LFHCALRemnantClusters", "LFHCALExpectedClusters", "LFHCALTrackExpectedClusterMatches"}, {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, @@ -96,7 +96,7 @@ void InitPlugin(JApplication* app) { )); app->Add(new JOmniFactoryGeneratorT( - "HcalEndcapPInsertSubtractedClusters", + "HcalEndcapPInsertRemnantClusters", {"HcalEndcapPInsertTrackSplitMergeClusterMatches", "HcalEndcapPInsertClusters", "CalorimeterTrackProjections"}, {"HcalEndcapPInsertRemnantClusters", "HcalEndcapPInsertExpectedClusters", "HcalEndcapPInsertTrackExpectedClusterMatches"}, {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, From 429dd294af2932b0b43e1f333feecd03f7035bf1 Mon Sep 17 00:00:00 2001 From: ruse-traveler Date: Wed, 8 Oct 2025 11:06:26 -0400 Subject: [PATCH 30/46] Remove WIP notes --- src/global/particle/particle.cc | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/src/global/particle/particle.cc b/src/global/particle/particle.cc index 9adc8678cb..8abf0205f7 100644 --- a/src/global/particle/particle.cc +++ b/src/global/particle/particle.cc @@ -25,16 +25,6 @@ void InitPlugin(JApplication* app) { // PFAlpha: baseline PF implementation // ==================================================================== - // -------------------------------------------------------------------- - // PFA (0) connection: split/merge clusters accordingly - // -------------------------------------------------------------------- - - /* TODO move here when ready */ - - // -------------------------------------------------------------------- - // PFA (1a) arbitration: apply track correction to clusters - // -------------------------------------------------------------------- - // backward ----------------------------------------------------------- #if EDM4EIC_VERSION_MAJOR >= 8 @@ -105,22 +95,5 @@ void InitPlugin(JApplication* app) { #endif - // -------------------------------------------------------------------- - // PFA (1b) arbitration: form charged candidates - // -------------------------------------------------------------------- - - /* TODO add here */ - - // -------------------------------------------------------------------- - // PFA (2) arbitration: combine remnants, form neutral candidates - // -------------------------------------------------------------------- - - /* TODO add here */ - - // -------------------------------------------------------------------- - // PFA (3) regression: convert candidates to reco particles - // -------------------------------------------------------------------- - - /* TODO add here */ } } // extern "C" From 05251ce5d27b25f9e52ec8bc57147ac8471029a1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 8 Oct 2025 15:06:51 +0000 Subject: [PATCH 31/46] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/global/particle/particle.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/global/particle/particle.cc b/src/global/particle/particle.cc index 8abf0205f7..09abd061cf 100644 --- a/src/global/particle/particle.cc +++ b/src/global/particle/particle.cc @@ -87,13 +87,14 @@ void InitPlugin(JApplication* app) { app->Add(new JOmniFactoryGeneratorT( "HcalEndcapPInsertRemnantClusters", - {"HcalEndcapPInsertTrackSplitMergeClusterMatches", "HcalEndcapPInsertClusters", "CalorimeterTrackProjections"}, - {"HcalEndcapPInsertRemnantClusters", "HcalEndcapPInsertExpectedClusters", "HcalEndcapPInsertTrackExpectedClusterMatches"}, + {"HcalEndcapPInsertTrackSplitMergeClusterMatches", "HcalEndcapPInsertClusters", + "CalorimeterTrackProjections"}, + {"HcalEndcapPInsertRemnantClusters", "HcalEndcapPInsertExpectedClusters", + "HcalEndcapPInsertTrackExpectedClusterMatches"}, {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, app // TODO: remove me once fixed )); #endif - } } // extern "C" From e2c59e895b3508699aec524211f194de4380f591 Mon Sep 17 00:00:00 2001 From: ruse-traveler Date: Thu, 9 Oct 2025 14:33:59 -0400 Subject: [PATCH 32/46] Add algorithm, factory, and generators --- .../particle/ChargedCandidateMaker.cc | 64 +++++++++++++++ .../particle/ChargedCandidateMaker.h | 80 +++++++++++++++++++ .../particle/ChargedCandidateMaker_factory.h | 45 +++++++++++ src/global/particle/particle.cc | 59 ++++++++++++++ 4 files changed, 248 insertions(+) create mode 100644 src/algorithms/particle/ChargedCandidateMaker.cc create mode 100644 src/algorithms/particle/ChargedCandidateMaker.h create mode 100644 src/algorithms/particle/ChargedCandidateMaker_factory.h diff --git a/src/algorithms/particle/ChargedCandidateMaker.cc b/src/algorithms/particle/ChargedCandidateMaker.cc new file mode 100644 index 0000000000..da8e25e388 --- /dev/null +++ b/src/algorithms/particle/ChargedCandidateMaker.cc @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (C) 2025 Derek Anderson + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#if EDM4EIC_VERSION_MAJOR >= 8 + +#include "ChargedCandidateMaker.h" + +namespace eicrecon { + +// ---------------------------------------------------------------------------- +//! Process inputs +// ---------------------------------------------------------------------------- +/*! Construct a candidate charged particle via the + * following algorithm. + * 1. Build map of tracks onto vectors of their + * matched tracks + * 2. For each track, create a Reconstructed + * Particle with track and cluster relations + * filled + */ +void ChargedCandidateMaker::process(const ChargedCandidateMaker::Input& input, + const ChargedCandidateMaker::Output& output) const { + + // grab inputs/outputs + const auto [in_match] = input; + auto [out_particle] = output; + + // exit if no matches in collection + if (in_match->size() == 0) { + debug("No track-cluster matches in collection"); + return; + } + + // -------------------------------------------------------------------------- + // 1. Build map of tracks onto matched clusters + // -------------------------------------------------------------------------- + MapToVecClust mapTrkToClust; + for (const auto& match : *in_match) { + mapTrkToClust[match.getTrack()].push_back(match.getCluster()); + } + + // -------------------------------------------------------------------------- + // 2. Create a reconstructed particle for each track + // -------------------------------------------------------------------------- + for (const auto& [track, clusters] : mapTrkToClust) { + edm4eic::MutableReconstructedParticle particle = out_particle->create(); + particle.addToTracks(track); + for (const edm4eic::Cluster& cluster : clusters) { + particle.addToClusters(cluster); + } + } +} // end 'process(Input&, Output&)' +} // namespace eicrecon + +#endif // EDM4EIC_VERSION_MAJOR >= 8 diff --git a/src/algorithms/particle/ChargedCandidateMaker.h b/src/algorithms/particle/ChargedCandidateMaker.h new file mode 100644 index 0000000000..84997c97c5 --- /dev/null +++ b/src/algorithms/particle/ChargedCandidateMaker.h @@ -0,0 +1,80 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (C) 2025 Derek Anderson + +#pragma once + +#include +#include +#include +#include +#include +#if EDM4EIC_VERSION_MAJOR >= 8 +#include +#endif +#include +#include +#include +#include + +#include "algorithms/interfaces/WithPodConfig.h" + +#if EDM4EIC_VERSION_MAJOR >= 8 + +namespace eicrecon { + +// -------------------------------------------------------------------------- +//! Algorithm input/output +// -------------------------------------------------------------------------- +using ChargedCandidateMakerAlgorithm = algorithms::Algorithm< + algorithms::Input, + algorithms::Output>; + +// ========================================================================== +//! Candidate Charged Particle Maker +// ========================================================================== +/*! An algorithm which takes a collection of clusters and their matched + * tracks, subtracts the sum of all tracks pointing to the cluster, + * and outputs the remnant clusters, expected clusters, and their matched + * tracks. + */ +class ChargedCandidateMaker : public ChargedCandidateMakerAlgorithm, + public WithPodConfig { + +public: + // ------------------------------------------------------------------------ + //! Comparator struct for tracks + // ------------------------------------------------------------------------ + /*! Organizes tracks by their ObjectIDs in decreasing collection + * ID first, and second by decreasing index second. + */ + struct CompareTrack { + bool operator()(const edm4eic::Track& lhs, const edm4eic::Track& rhs) const { + if (lhs.getObjectID().collectionID == rhs.getObjectID().collectionID) { + return (lhs.getObjectID().index < rhs.getObjectID().index); + } else { + return (lhs.getObjectID().collectionID < rhs.getObjectID().collectionID); + } + } + }; + + ///! Alias for a map from a track to matched clusters + using MapToVecClust = std::map, + CompareTrack>; + + ///! Algorithm constructor + ChargedCandidateMaker(std::string_view name) + : ChargedCandidateMakerAlgorithm{ + name, + {"inputTrackClusterMatches"}, + {"outputChargedCandidateParticles"}, + "Forms candidate charged particles."} {} + + // public method + void process(const Input&, const Output&) const final; + +}; // end ChargedCandidateMaker + +} // namespace eicrecon + +#endif // EDM4EIC_VERSION_MAJOR >= 8 diff --git a/src/algorithms/particle/ChargedCandidateMaker_factory.h b/src/algorithms/particle/ChargedCandidateMaker_factory.h new file mode 100644 index 0000000000..d3214a1b0a --- /dev/null +++ b/src/algorithms/particle/ChargedCandidateMaker_factory.h @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (C) 2025 Derek Anderson + +#pragma once + +#include + +#include "extensions/jana/JOmniFactory.h" +#include "algorithms/particle/ChargedCandidateMaker.h" + +namespace eicrecon { + +class ChargedCandidateMaker_factory + : public JOmniFactory { + +public: + ///! alias for algorithm name + using AlgoT = eicrecon::ChargedCandidateMaker; + +private: + // pointer to algorithm + std::unique_ptr m_algo; + + // input collection + PodioInput m_track_cluster_match_input{this}; + + // output collection + PodioOutput m_charged_candidate_output{this}; + +public: + ///! Configures algorithm + void Configure() { + m_algo = std::make_unique(GetPrefix()); + m_algo->init(); + } + + ///! Primary algorithm call + void Process(int32_t /*run_number*/, uint64_t /*event_number*/) { + m_algo->process( + {m_track_cluster_match_input()}, + {m_charged_candidate_output().get()}); + } +}; // end ChargedCandidateMaker_factory + +} // namespace eicrecon diff --git a/src/global/particle/particle.cc b/src/global/particle/particle.cc index 8abf0205f7..f24fccc6a5 100644 --- a/src/global/particle/particle.cc +++ b/src/global/particle/particle.cc @@ -8,8 +8,10 @@ #include #include "extensions/jana/JOmniFactoryGeneratorT.h" +#include "factories/meta/CollectionCollector_factory.h" #if EDM4EIC_VERSION_MAJOR >= 8 +#include "factories/particle/ChargedCandidateMaker_factory.h" #include "factories/particle/TrackClusterSubtractor_factory.h" #endif @@ -25,6 +27,10 @@ void InitPlugin(JApplication* app) { // PFAlpha: baseline PF implementation // ==================================================================== + // -------------------------------------------------------------------- + // PFA (1a) arbitration: apply track correction to clusters + // -------------------------------------------------------------------- + // backward ----------------------------------------------------------- #if EDM4EIC_VERSION_MAJOR >= 8 @@ -93,6 +99,59 @@ void InitPlugin(JApplication* app) { app // TODO: remove me once fixed )); + // -------------------------------------------------------------------- + // PFA (1b) arbitration: form charged candidates + // -------------------------------------------------------------------- + + // backward ----------------------------------------------------------- + + app->Add(new JOmniFactoryGeneratorT>( + "EndcapNTrackExpectedClusterMatches", + {"EcalEndcapNTrackExpectedClusterMatches", "HcalEndcapNTrackExpectedClusterMatches"}, + {"EndcapNTrackExpectedClusterMatches"}, app)); + + app->Add(new JOmniFactoryGeneratorT( + "EndcapNChargedCandidateParticlesAlpha", + {"EndcapNTrackExpectedClusterMatches"}, + {"EndcapNChargedCandidateParticlesAlpha"}, + {}, app)); + + // central ------------------------------------------------------------ + + app->Add(new JOmniFactoryGeneratorT>( + "BarrelTrackExpectedClusterMatches", + {"EcalBarrelTrackExpectedClusterMatches", "HcalBarrelTrackExpectedClusterMatches"}, + {"BarrelTrackExpectedClusterMatches"}, app)); + + app->Add(new JOmniFactoryGeneratorT( + "BarrelChargedCandidateParticlesAlpha", + {"BarrelTrackExpectedClusterMatches"}, + {"BarrelChargedCandidateParticlesAlpha"}, + {}, app)); + + // forward ------------------------------------------------------------ + + app->Add(new JOmniFactoryGeneratorT>( + "EndcapPTrackExpectedClusterMatches", + {"EcalEndcapPTrackExpectedClusterMatches", "LFHCALTrackExpectedClusterMatches"}, + {"EndcapPTrackExpectedClusterMatches"}, app)); + + app->Add(new JOmniFactoryGeneratorT( + "EndcapPChargedCandidateParticlesAlpha", + {"EndcapPTrackExpectedClusterMatches"}, + {"EndcapPChargedCandidateParticlesAlpha"}, + {}, app)); + + app->Add(new JOmniFactoryGeneratorT>( + "EndcapPInsertTrackExpectedClusterMatches", + {"EcalEndcapPTrackExpectedClusterMatches", "HcalEndcapPInsertTrackExpectedClusterMatches"}, + {"EndcapPInsertTrackExpectedClusterMatches"}, app)); + + app->Add(new JOmniFactoryGeneratorT( + "EndcapPInsertChargedCandidateParticlesAlpha", + {"EndcapPInsertTrackExpectedClusterMatches"}, + {"EndcapPInsertChargedCandidateParticlesAlpha"}, + {}, app)); #endif } From a8040d90f1a07d9e1ae0d010471d0370a5f8e799 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 9 Oct 2025 18:43:14 +0000 Subject: [PATCH 33/46] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../particle/ChargedCandidateMaker.cc | 2 +- .../particle/ChargedCandidateMaker.h | 21 +++---- .../particle/ChargedCandidateMaker_factory.h | 7 +-- src/global/particle/particle.cc | 61 +++++++++---------- 4 files changed, 41 insertions(+), 50 deletions(-) diff --git a/src/algorithms/particle/ChargedCandidateMaker.cc b/src/algorithms/particle/ChargedCandidateMaker.cc index da8e25e388..f16f4eab39 100644 --- a/src/algorithms/particle/ChargedCandidateMaker.cc +++ b/src/algorithms/particle/ChargedCandidateMaker.cc @@ -32,7 +32,7 @@ void ChargedCandidateMaker::process(const ChargedCandidateMaker::Input& input, // grab inputs/outputs const auto [in_match] = input; - auto [out_particle] = output; + auto [out_particle] = output; // exit if no matches in collection if (in_match->size() == 0) { diff --git a/src/algorithms/particle/ChargedCandidateMaker.h b/src/algorithms/particle/ChargedCandidateMaker.h index 84997c97c5..75c67735eb 100644 --- a/src/algorithms/particle/ChargedCandidateMaker.h +++ b/src/algorithms/particle/ChargedCandidateMaker.h @@ -25,12 +25,12 @@ namespace eicrecon { // -------------------------------------------------------------------------- //! Algorithm input/output // -------------------------------------------------------------------------- -using ChargedCandidateMakerAlgorithm = algorithms::Algorithm< - algorithms::Input, - algorithms::Output>; +using ChargedCandidateMakerAlgorithm = + algorithms::Algorithm, + algorithms::Output>; // ========================================================================== -//! Candidate Charged Particle Maker +//! Candidate Charged Particle Maker // ========================================================================== /*! An algorithm which takes a collection of clusters and their matched * tracks, subtracts the sum of all tracks pointing to the cluster, @@ -58,17 +58,14 @@ class ChargedCandidateMaker : public ChargedCandidateMakerAlgorithm, }; ///! Alias for a map from a track to matched clusters - using MapToVecClust = std::map, - CompareTrack>; + using MapToVecClust = std::map, CompareTrack>; ///! Algorithm constructor ChargedCandidateMaker(std::string_view name) - : ChargedCandidateMakerAlgorithm{ - name, - {"inputTrackClusterMatches"}, - {"outputChargedCandidateParticles"}, - "Forms candidate charged particles."} {} + : ChargedCandidateMakerAlgorithm{name, + {"inputTrackClusterMatches"}, + {"outputChargedCandidateParticles"}, + "Forms candidate charged particles."} {} // public method void process(const Input&, const Output&) const final; diff --git a/src/algorithms/particle/ChargedCandidateMaker_factory.h b/src/algorithms/particle/ChargedCandidateMaker_factory.h index d3214a1b0a..992a3ad7f8 100644 --- a/src/algorithms/particle/ChargedCandidateMaker_factory.h +++ b/src/algorithms/particle/ChargedCandidateMaker_factory.h @@ -10,8 +10,7 @@ namespace eicrecon { -class ChargedCandidateMaker_factory - : public JOmniFactory { +class ChargedCandidateMaker_factory : public JOmniFactory { public: ///! alias for algorithm name @@ -36,9 +35,7 @@ class ChargedCandidateMaker_factory ///! Primary algorithm call void Process(int32_t /*run_number*/, uint64_t /*event_number*/) { - m_algo->process( - {m_track_cluster_match_input()}, - {m_charged_candidate_output().get()}); + m_algo->process({m_track_cluster_match_input()}, {m_charged_candidate_output().get()}); } }; // end ChargedCandidateMaker_factory diff --git a/src/global/particle/particle.cc b/src/global/particle/particle.cc index f24fccc6a5..d7c2b62d78 100644 --- a/src/global/particle/particle.cc +++ b/src/global/particle/particle.cc @@ -105,53 +105,50 @@ void InitPlugin(JApplication* app) { // backward ----------------------------------------------------------- - app->Add(new JOmniFactoryGeneratorT>( - "EndcapNTrackExpectedClusterMatches", - {"EcalEndcapNTrackExpectedClusterMatches", "HcalEndcapNTrackExpectedClusterMatches"}, - {"EndcapNTrackExpectedClusterMatches"}, app)); + app->Add( + new JOmniFactoryGeneratorT>( + "EndcapNTrackExpectedClusterMatches", + {"EcalEndcapNTrackExpectedClusterMatches", "HcalEndcapNTrackExpectedClusterMatches"}, + {"EndcapNTrackExpectedClusterMatches"}, app)); app->Add(new JOmniFactoryGeneratorT( - "EndcapNChargedCandidateParticlesAlpha", - {"EndcapNTrackExpectedClusterMatches"}, - {"EndcapNChargedCandidateParticlesAlpha"}, - {}, app)); + "EndcapNChargedCandidateParticlesAlpha", {"EndcapNTrackExpectedClusterMatches"}, + {"EndcapNChargedCandidateParticlesAlpha"}, {}, app)); // central ------------------------------------------------------------ - app->Add(new JOmniFactoryGeneratorT>( - "BarrelTrackExpectedClusterMatches", - {"EcalBarrelTrackExpectedClusterMatches", "HcalBarrelTrackExpectedClusterMatches"}, - {"BarrelTrackExpectedClusterMatches"}, app)); + app->Add( + new JOmniFactoryGeneratorT>( + "BarrelTrackExpectedClusterMatches", + {"EcalBarrelTrackExpectedClusterMatches", "HcalBarrelTrackExpectedClusterMatches"}, + {"BarrelTrackExpectedClusterMatches"}, app)); app->Add(new JOmniFactoryGeneratorT( - "BarrelChargedCandidateParticlesAlpha", - {"BarrelTrackExpectedClusterMatches"}, - {"BarrelChargedCandidateParticlesAlpha"}, - {}, app)); + "BarrelChargedCandidateParticlesAlpha", {"BarrelTrackExpectedClusterMatches"}, + {"BarrelChargedCandidateParticlesAlpha"}, {}, app)); // forward ------------------------------------------------------------ - app->Add(new JOmniFactoryGeneratorT>( - "EndcapPTrackExpectedClusterMatches", - {"EcalEndcapPTrackExpectedClusterMatches", "LFHCALTrackExpectedClusterMatches"}, - {"EndcapPTrackExpectedClusterMatches"}, app)); + app->Add( + new JOmniFactoryGeneratorT>( + "EndcapPTrackExpectedClusterMatches", + {"EcalEndcapPTrackExpectedClusterMatches", "LFHCALTrackExpectedClusterMatches"}, + {"EndcapPTrackExpectedClusterMatches"}, app)); app->Add(new JOmniFactoryGeneratorT( - "EndcapPChargedCandidateParticlesAlpha", - {"EndcapPTrackExpectedClusterMatches"}, - {"EndcapPChargedCandidateParticlesAlpha"}, - {}, app)); + "EndcapPChargedCandidateParticlesAlpha", {"EndcapPTrackExpectedClusterMatches"}, + {"EndcapPChargedCandidateParticlesAlpha"}, {}, app)); - app->Add(new JOmniFactoryGeneratorT>( - "EndcapPInsertTrackExpectedClusterMatches", - {"EcalEndcapPTrackExpectedClusterMatches", "HcalEndcapPInsertTrackExpectedClusterMatches"}, - {"EndcapPInsertTrackExpectedClusterMatches"}, app)); + app->Add( + new JOmniFactoryGeneratorT>( + "EndcapPInsertTrackExpectedClusterMatches", + {"EcalEndcapPTrackExpectedClusterMatches", + "HcalEndcapPInsertTrackExpectedClusterMatches"}, + {"EndcapPInsertTrackExpectedClusterMatches"}, app)); app->Add(new JOmniFactoryGeneratorT( - "EndcapPInsertChargedCandidateParticlesAlpha", - {"EndcapPInsertTrackExpectedClusterMatches"}, - {"EndcapPInsertChargedCandidateParticlesAlpha"}, - {}, app)); + "EndcapPInsertChargedCandidateParticlesAlpha", {"EndcapPInsertTrackExpectedClusterMatches"}, + {"EndcapPInsertChargedCandidateParticlesAlpha"}, {}, app)); #endif } From e2fa5d2f9c9d2b5778d7ddcc93dd91311cdd79d5 Mon Sep 17 00:00:00 2001 From: ruse-traveler Date: Mon, 13 Oct 2025 16:22:04 -0400 Subject: [PATCH 34/46] Remove edm4eic 8.X guards --- src/algorithms/particle/ChargedCandidateMaker.cc | 3 --- src/algorithms/particle/ChargedCandidateMaker.h | 6 ------ 2 files changed, 9 deletions(-) diff --git a/src/algorithms/particle/ChargedCandidateMaker.cc b/src/algorithms/particle/ChargedCandidateMaker.cc index f16f4eab39..c5f66ca491 100644 --- a/src/algorithms/particle/ChargedCandidateMaker.cc +++ b/src/algorithms/particle/ChargedCandidateMaker.cc @@ -10,7 +10,6 @@ #include #include #include -#if EDM4EIC_VERSION_MAJOR >= 8 #include "ChargedCandidateMaker.h" @@ -60,5 +59,3 @@ void ChargedCandidateMaker::process(const ChargedCandidateMaker::Input& input, } } // end 'process(Input&, Output&)' } // namespace eicrecon - -#endif // EDM4EIC_VERSION_MAJOR >= 8 diff --git a/src/algorithms/particle/ChargedCandidateMaker.h b/src/algorithms/particle/ChargedCandidateMaker.h index 75c67735eb..f95a99d3a7 100644 --- a/src/algorithms/particle/ChargedCandidateMaker.h +++ b/src/algorithms/particle/ChargedCandidateMaker.h @@ -8,9 +8,7 @@ #include #include #include -#if EDM4EIC_VERSION_MAJOR >= 8 #include -#endif #include #include #include @@ -18,8 +16,6 @@ #include "algorithms/interfaces/WithPodConfig.h" -#if EDM4EIC_VERSION_MAJOR >= 8 - namespace eicrecon { // -------------------------------------------------------------------------- @@ -73,5 +69,3 @@ class ChargedCandidateMaker : public ChargedCandidateMakerAlgorithm, }; // end ChargedCandidateMaker } // namespace eicrecon - -#endif // EDM4EIC_VERSION_MAJOR >= 8 From 99325a799c0245868041b270b1fc9b630c41e3e4 Mon Sep 17 00:00:00 2001 From: ruse-traveler Date: Mon, 13 Oct 2025 16:22:55 -0400 Subject: [PATCH 35/46] Remove unnecessary comments --- src/algorithms/particle/ChargedCandidateMaker.cc | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/algorithms/particle/ChargedCandidateMaker.cc b/src/algorithms/particle/ChargedCandidateMaker.cc index c5f66ca491..4ee02c8208 100644 --- a/src/algorithms/particle/ChargedCandidateMaker.cc +++ b/src/algorithms/particle/ChargedCandidateMaker.cc @@ -39,17 +39,11 @@ void ChargedCandidateMaker::process(const ChargedCandidateMaker::Input& input, return; } - // -------------------------------------------------------------------------- - // 1. Build map of tracks onto matched clusters - // -------------------------------------------------------------------------- MapToVecClust mapTrkToClust; for (const auto& match : *in_match) { mapTrkToClust[match.getTrack()].push_back(match.getCluster()); } - // -------------------------------------------------------------------------- - // 2. Create a reconstructed particle for each track - // -------------------------------------------------------------------------- for (const auto& [track, clusters] : mapTrkToClust) { edm4eic::MutableReconstructedParticle particle = out_particle->create(); particle.addToTracks(track); From 84649901d4db675549b99b938754d08e98b0592f Mon Sep 17 00:00:00 2001 From: ruse-traveler Date: Mon, 13 Oct 2025 16:24:27 -0400 Subject: [PATCH 36/46] Add missing factory --- .../particle/ChargedCandidateMaker_factory.h | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/factories/particle/ChargedCandidateMaker_factory.h diff --git a/src/factories/particle/ChargedCandidateMaker_factory.h b/src/factories/particle/ChargedCandidateMaker_factory.h new file mode 100644 index 0000000000..d3214a1b0a --- /dev/null +++ b/src/factories/particle/ChargedCandidateMaker_factory.h @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (C) 2025 Derek Anderson + +#pragma once + +#include + +#include "extensions/jana/JOmniFactory.h" +#include "algorithms/particle/ChargedCandidateMaker.h" + +namespace eicrecon { + +class ChargedCandidateMaker_factory + : public JOmniFactory { + +public: + ///! alias for algorithm name + using AlgoT = eicrecon::ChargedCandidateMaker; + +private: + // pointer to algorithm + std::unique_ptr m_algo; + + // input collection + PodioInput m_track_cluster_match_input{this}; + + // output collection + PodioOutput m_charged_candidate_output{this}; + +public: + ///! Configures algorithm + void Configure() { + m_algo = std::make_unique(GetPrefix()); + m_algo->init(); + } + + ///! Primary algorithm call + void Process(int32_t /*run_number*/, uint64_t /*event_number*/) { + m_algo->process( + {m_track_cluster_match_input()}, + {m_charged_candidate_output().get()}); + } +}; // end ChargedCandidateMaker_factory + +} // namespace eicrecon From dbb370aa24c78499be416456bcb523eceb11a4aa Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 13 Oct 2025 20:24:56 +0000 Subject: [PATCH 37/46] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/factories/particle/ChargedCandidateMaker_factory.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/factories/particle/ChargedCandidateMaker_factory.h b/src/factories/particle/ChargedCandidateMaker_factory.h index d3214a1b0a..992a3ad7f8 100644 --- a/src/factories/particle/ChargedCandidateMaker_factory.h +++ b/src/factories/particle/ChargedCandidateMaker_factory.h @@ -10,8 +10,7 @@ namespace eicrecon { -class ChargedCandidateMaker_factory - : public JOmniFactory { +class ChargedCandidateMaker_factory : public JOmniFactory { public: ///! alias for algorithm name @@ -36,9 +35,7 @@ class ChargedCandidateMaker_factory ///! Primary algorithm call void Process(int32_t /*run_number*/, uint64_t /*event_number*/) { - m_algo->process( - {m_track_cluster_match_input()}, - {m_charged_candidate_output().get()}); + m_algo->process({m_track_cluster_match_input()}, {m_charged_candidate_output().get()}); } }; // end ChargedCandidateMaker_factory From 06a25367f01f33f6c487bbb1a29592eaa7b53051 Mon Sep 17 00:00:00 2001 From: ruse-traveler Date: Mon, 13 Oct 2025 16:26:38 -0400 Subject: [PATCH 38/46] Fix typo in docstring --- src/algorithms/particle/ChargedCandidateMaker.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/algorithms/particle/ChargedCandidateMaker.h b/src/algorithms/particle/ChargedCandidateMaker.h index f95a99d3a7..89dba553ae 100644 --- a/src/algorithms/particle/ChargedCandidateMaker.h +++ b/src/algorithms/particle/ChargedCandidateMaker.h @@ -41,7 +41,7 @@ class ChargedCandidateMaker : public ChargedCandidateMakerAlgorithm, //! Comparator struct for tracks // ------------------------------------------------------------------------ /*! Organizes tracks by their ObjectIDs in decreasing collection - * ID first, and second by decreasing index second. + * ID first, and by decreasing index second. */ struct CompareTrack { bool operator()(const edm4eic::Track& lhs, const edm4eic::Track& rhs) const { From cb56a9624c8bd60fde76d5f108d44c09a0836fdc Mon Sep 17 00:00:00 2001 From: ruse-traveler Date: Mon, 13 Oct 2025 16:28:18 -0400 Subject: [PATCH 39/46] Fix typo in docstring --- src/algorithms/particle/TrackClusterSubtractor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/algorithms/particle/TrackClusterSubtractor.h b/src/algorithms/particle/TrackClusterSubtractor.h index b0d867e549..dffff63522 100644 --- a/src/algorithms/particle/TrackClusterSubtractor.h +++ b/src/algorithms/particle/TrackClusterSubtractor.h @@ -45,7 +45,7 @@ class TrackClusterSubtractor : public TrackClusterSubtractorAlgorithm, //! Comparator struct for clusters // ------------------------------------------------------------------------ /*! Organizes clusters by their ObjectIDs in decreasing collection - * ID first, and second by decreasing index second. + * ID first, and by decreasing index second. */ struct CompareClust { bool operator()(const edm4eic::Cluster& lhs, const edm4eic::Cluster& rhs) const { From 82451e7dab7f2c14aa0f3c5b65912c3d185e856a Mon Sep 17 00:00:00 2001 From: Wouter Deconinck Date: Mon, 13 Oct 2025 16:17:55 -0500 Subject: [PATCH 40/46] Implement Track-Cluster Subtraction (PFA1a) (fix: iwyu) (#2133) This PR applies the include-what-you-use fixes as suggested by https://github.com/eic/EICrecon/actions/runs/18477471601. Please merge this PR into the branch `add-track-cluster-subtraction-pfa-one` to resolve failures in PR #1627. Auto-generated by [create-pull-request][1] [1]: https://github.com/peter-evans/create-pull-request Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/algorithms/particle/TrackClusterSubtractor.cc | 1 - src/algorithms/particle/TrackClusterSubtractor.h | 3 +-- src/global/particle/particle.cc | 1 - 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/algorithms/particle/TrackClusterSubtractor.cc b/src/algorithms/particle/TrackClusterSubtractor.cc index f25fff8062..768b5a6452 100644 --- a/src/algorithms/particle/TrackClusterSubtractor.cc +++ b/src/algorithms/particle/TrackClusterSubtractor.cc @@ -1,7 +1,6 @@ // SPDX-License-Identifier: LGPL-3.0-or-later // Copyright (C) 2025 Derek Anderson -#include #include #include #include diff --git a/src/algorithms/particle/TrackClusterSubtractor.h b/src/algorithms/particle/TrackClusterSubtractor.h index dffff63522..91ddb4dd67 100644 --- a/src/algorithms/particle/TrackClusterSubtractor.h +++ b/src/algorithms/particle/TrackClusterSubtractor.h @@ -5,10 +5,9 @@ #include #include -#include -#include #include #include +#include #include #include #include diff --git a/src/global/particle/particle.cc b/src/global/particle/particle.cc index 0581c3c2a2..1cb4650699 100644 --- a/src/global/particle/particle.cc +++ b/src/global/particle/particle.cc @@ -3,7 +3,6 @@ #include #include -#include #include #include From ed2fae1f11c64ad486f71dc7dd1cdfca10330094 Mon Sep 17 00:00:00 2001 From: Wouter Deconinck Date: Mon, 13 Oct 2025 16:21:05 -0500 Subject: [PATCH 41/46] Implement Charged Candidate Maker (PFA1b) (fix: iwyu) (#2134) This PR applies the include-what-you-use fixes as suggested by https://github.com/eic/EICrecon/actions/runs/18477497612. Please merge this PR into the branch `add-charged-candidate-maker-pfa-one` to resolve failures in PR #2124. Auto-generated by [create-pull-request][1] [1]: https://github.com/peter-evans/create-pull-request Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/algorithms/particle/ChargedCandidateMaker.cc | 5 ----- src/algorithms/particle/ChargedCandidateMaker.h | 4 ++-- src/global/particle/particle.cc | 5 ++++- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/algorithms/particle/ChargedCandidateMaker.cc b/src/algorithms/particle/ChargedCandidateMaker.cc index 4ee02c8208..53c3f4e40a 100644 --- a/src/algorithms/particle/ChargedCandidateMaker.cc +++ b/src/algorithms/particle/ChargedCandidateMaker.cc @@ -1,12 +1,7 @@ // SPDX-License-Identifier: LGPL-3.0-or-later // Copyright (C) 2025 Derek Anderson -#include #include -#include -#include -#include -#include #include #include #include diff --git a/src/algorithms/particle/ChargedCandidateMaker.h b/src/algorithms/particle/ChargedCandidateMaker.h index 89dba553ae..006dac6147 100644 --- a/src/algorithms/particle/ChargedCandidateMaker.h +++ b/src/algorithms/particle/ChargedCandidateMaker.h @@ -5,10 +5,10 @@ #include #include -#include -#include #include +#include #include +#include #include #include #include diff --git a/src/global/particle/particle.cc b/src/global/particle/particle.cc index f3d568a7c6..c81d8adcf7 100644 --- a/src/global/particle/particle.cc +++ b/src/global/particle/particle.cc @@ -3,7 +3,10 @@ #include #include -#include +#include +#include +#include +#include #include #include From eb4e239d4da32a0af891505919fb5c1e2eb177b5 Mon Sep 17 00:00:00 2001 From: ruse-traveler Date: Thu, 23 Oct 2025 17:34:57 -0400 Subject: [PATCH 42/46] Remove misplaced factory --- .../particle/ChargedCandidateMaker_factory.h | 42 ------------------- 1 file changed, 42 deletions(-) delete mode 100644 src/algorithms/particle/ChargedCandidateMaker_factory.h diff --git a/src/algorithms/particle/ChargedCandidateMaker_factory.h b/src/algorithms/particle/ChargedCandidateMaker_factory.h deleted file mode 100644 index 992a3ad7f8..0000000000 --- a/src/algorithms/particle/ChargedCandidateMaker_factory.h +++ /dev/null @@ -1,42 +0,0 @@ -// SPDX-License-Identifier: LGPL-3.0-or-later -// Copyright (C) 2025 Derek Anderson - -#pragma once - -#include - -#include "extensions/jana/JOmniFactory.h" -#include "algorithms/particle/ChargedCandidateMaker.h" - -namespace eicrecon { - -class ChargedCandidateMaker_factory : public JOmniFactory { - -public: - ///! alias for algorithm name - using AlgoT = eicrecon::ChargedCandidateMaker; - -private: - // pointer to algorithm - std::unique_ptr m_algo; - - // input collection - PodioInput m_track_cluster_match_input{this}; - - // output collection - PodioOutput m_charged_candidate_output{this}; - -public: - ///! Configures algorithm - void Configure() { - m_algo = std::make_unique(GetPrefix()); - m_algo->init(); - } - - ///! Primary algorithm call - void Process(int32_t /*run_number*/, uint64_t /*event_number*/) { - m_algo->process({m_track_cluster_match_input()}, {m_charged_candidate_output().get()}); - } -}; // end ChargedCandidateMaker_factory - -} // namespace eicrecon From 4c8a98a0e9c41d648a42b97cd4c791ab4e975424 Mon Sep 17 00:00:00 2001 From: ruse-traveler Date: Thu, 23 Oct 2025 17:38:10 -0400 Subject: [PATCH 43/46] Temporarily add charged candidates to default output --- src/services/io/podio/JEventProcessorPODIO.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/services/io/podio/JEventProcessorPODIO.cc b/src/services/io/podio/JEventProcessorPODIO.cc index 436d201dc6..9a7b260f6c 100644 --- a/src/services/io/podio/JEventProcessorPODIO.cc +++ b/src/services/io/podio/JEventProcessorPODIO.cc @@ -408,6 +408,11 @@ JEventProcessorPODIO::JEventProcessorPODIO() { "HcalEndcapPInsertRemnantClusters", "HcalEndcapPInsertExpectedClusters", "HcalEndcapPInsertTrackExpectedClusterMatches", + + "EndcapNChargedCandidateParticlesAlpha", + "BarrelChargedCandidateParticlesAlpha", + "EndcapPChargedCandidateParticlesAlpha", + "EndcapPInsertChargedCandidateParticlesAlpha", }; std::vector output_exclude_collections; // need to get as vector, then convert to set std::string output_include_collections = "DEPRECATED"; From f208a5182c75e1fb461899310d51d1a88cc3e93f Mon Sep 17 00:00:00 2001 From: ruse-traveler Date: Thu, 30 Oct 2025 12:30:06 -0400 Subject: [PATCH 44/46] Use track-cluster matches as PFA1b input --- src/global/particle/particle.cc | 107 +++++--------------------------- 1 file changed, 17 insertions(+), 90 deletions(-) diff --git a/src/global/particle/particle.cc b/src/global/particle/particle.cc index c81d8adcf7..0497fa2192 100644 --- a/src/global/particle/particle.cc +++ b/src/global/particle/particle.cc @@ -27,79 +27,6 @@ void InitPlugin(JApplication* app) { // PFAlpha: baseline PF implementation // ==================================================================== - // -------------------------------------------------------------------- - // PFA (1a) arbitration: apply track correction to clusters - // -------------------------------------------------------------------- - - // backward ----------------------------------------------------------- - - app->Add(new JOmniFactoryGeneratorT( - "EcalEndcapNRemnantClusters", - {"EcalEndcapNTrackClusterMatches", "EcalEndcapNClusters", "CalorimeterTrackProjections"}, - {"EcalEndcapNRemnantClusters", "EcalEndcapNExpectedClusters", - "EcalEndcapNTrackExpectedClusterMatches"}, - {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, - app // TODO: remove me once fixed - )); - - app->Add(new JOmniFactoryGeneratorT( - "HcalEndcapNRemnantClusters", - {"HcalEndcapNTrackClusterMatches", "HcalEndcapNClusters", "CalorimeterTrackProjections"}, - {"HcalEndcapNRemnantClusters", "HcalEndcapNExpectedClusters", - "HcalEndcapNTrackExpectedClusterMatches"}, - {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, - app // TODO: remove me once fixed - )); - - // central ------------------------------------------------------------ - - app->Add(new JOmniFactoryGeneratorT( - "EcalBarrelRemnantClusters", - {"EcalBarrelTrackClusterMatches", "EcalBarrelClusters", "CalorimeterTrackProjections"}, - {"EcalBarrelRemnantClusters", "EcalBarrelExpectedClusters", - "EcalBarrelTrackExpectedClusterMatches"}, - {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, - app // TODO: remove me once fixed - )); - - app->Add(new JOmniFactoryGeneratorT( - "HcalBarrelRemnantClusters", - {"HcalBarrelTrackClusterMatches", "HcalBarrelClusters", "CalorimeterTrackProjections"}, - {"HcalBarrelRemnantClusters", "HcalBarrelExpectedClusters", - "HcalBarrelTrackExpectedClusterMatches"}, - {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, - app // TODO: remove me once fixed - )); - - // forward ------------------------------------------------------------ - - app->Add(new JOmniFactoryGeneratorT( - "EcalEndcapPRemnantClusters", - {"EcalEndcapPTrackClusterMatches", "EcalEndcapPClusters", "CalorimeterTrackProjections"}, - {"EcalEndcapPRemnantClusters", "EcalEndcapPExpectedClusters", - "EcalEndcapPTrackExpectedClusterMatches"}, - {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, - app // TODO: remove me once fixed - )); - - app->Add(new JOmniFactoryGeneratorT( - "LFHCALRemnantClusters", - {"LFHCALTrackSplitMergeClusterMatches", "LFHCALClusters", "CalorimeterTrackProjections"}, - {"LFHCALRemnantClusters", "LFHCALExpectedClusters", "LFHCALTrackExpectedClusterMatches"}, - {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, - app // TODO: remove me once fixed - )); - - app->Add(new JOmniFactoryGeneratorT( - "HcalEndcapPInsertRemnantClusters", - {"HcalEndcapPInsertTrackSplitMergeClusterMatches", "HcalEndcapPInsertClusters", - "CalorimeterTrackProjections"}, - {"HcalEndcapPInsertRemnantClusters", "HcalEndcapPInsertExpectedClusters", - "HcalEndcapPInsertTrackExpectedClusterMatches"}, - {.fracEnergyToSub = 1.0, .defaultMassPdg = 211, .surfaceToUse = 1}, - app // TODO: remove me once fixed - )); - // -------------------------------------------------------------------- // PFA (1b) arbitration: form charged candidates // -------------------------------------------------------------------- @@ -108,47 +35,47 @@ void InitPlugin(JApplication* app) { app->Add( new JOmniFactoryGeneratorT>( - "EndcapNTrackExpectedClusterMatches", - {"EcalEndcapNTrackExpectedClusterMatches", "HcalEndcapNTrackExpectedClusterMatches"}, - {"EndcapNTrackExpectedClusterMatches"}, app)); + "EndcapNTrackClusterMatches", + {"EcalEndcapNTrackClusterMatches", "HcalEndcapNTrackClusterMatches"}, + {"EndcapNTrackClusterMatches"}, app)); app->Add(new JOmniFactoryGeneratorT( - "EndcapNChargedCandidateParticlesAlpha", {"EndcapNTrackExpectedClusterMatches"}, + "EndcapNChargedCandidateParticlesAlpha", {"EndcapNTrackClusterMatches"}, {"EndcapNChargedCandidateParticlesAlpha"}, {}, app)); // central ------------------------------------------------------------ app->Add( new JOmniFactoryGeneratorT>( - "BarrelTrackExpectedClusterMatches", - {"EcalBarrelTrackExpectedClusterMatches", "HcalBarrelTrackExpectedClusterMatches"}, - {"BarrelTrackExpectedClusterMatches"}, app)); + "BarrelTrackClusterMatches", + {"EcalBarrelTrackClusterMatches", "HcalBarrelTrackClusterMatches"}, + {"BarrelTrackClusterMatches"}, app)); app->Add(new JOmniFactoryGeneratorT( - "BarrelChargedCandidateParticlesAlpha", {"BarrelTrackExpectedClusterMatches"}, + "BarrelChargedCandidateParticlesAlpha", {"BarrelTrackClusterMatches"}, {"BarrelChargedCandidateParticlesAlpha"}, {}, app)); // forward ------------------------------------------------------------ app->Add( new JOmniFactoryGeneratorT>( - "EndcapPTrackExpectedClusterMatches", - {"EcalEndcapPTrackExpectedClusterMatches", "LFHCALTrackExpectedClusterMatches"}, - {"EndcapPTrackExpectedClusterMatches"}, app)); + "EndcapPTrackClusterMatches", + {"EcalEndcapPTrackClusterMatches", "LFHCALTrackClusterMatches"}, + {"EndcapPTrackClusterMatches"}, app)); app->Add(new JOmniFactoryGeneratorT( - "EndcapPChargedCandidateParticlesAlpha", {"EndcapPTrackExpectedClusterMatches"}, + "EndcapPChargedCandidateParticlesAlpha", {"EndcapPTrackClusterMatches"}, {"EndcapPChargedCandidateParticlesAlpha"}, {}, app)); app->Add( new JOmniFactoryGeneratorT>( - "EndcapPInsertTrackExpectedClusterMatches", - {"EcalEndcapPTrackExpectedClusterMatches", - "HcalEndcapPInsertTrackExpectedClusterMatches"}, - {"EndcapPInsertTrackExpectedClusterMatches"}, app)); + "EndcapPInsertTrackClusterMatches", + {"EcalEndcapPTrackClusterMatches", + "HcalEndcapPInsertTrackClusterMatches"}, + {"EndcapPInsertTrackClusterMatches"}, app)); app->Add(new JOmniFactoryGeneratorT( - "EndcapPInsertChargedCandidateParticlesAlpha", {"EndcapPInsertTrackExpectedClusterMatches"}, + "EndcapPInsertChargedCandidateParticlesAlpha", {"EndcapPInsertTrackClusterMatches"}, {"EndcapPInsertChargedCandidateParticlesAlpha"}, {}, app)); } } // extern "C" From 7deef73f96470372f763880f44a7aa37c74074f1 Mon Sep 17 00:00:00 2001 From: ruse-traveler Date: Thu, 30 Oct 2025 12:35:08 -0400 Subject: [PATCH 45/46] Remove PFA1a code --- .../particle/TrackClusterSubtractor.cc | 215 ------------------ .../particle/TrackClusterSubtractor.h | 90 -------- .../particle/TrackClusterSubtractorConfig.h | 35 --- .../particle/TrackClusterSubtractor_factory.h | 66 ------ src/global/particle/particle.cc | 1 - src/services/io/podio/JEventProcessorPODIO.cc | 22 -- 6 files changed, 429 deletions(-) delete mode 100644 src/algorithms/particle/TrackClusterSubtractor.cc delete mode 100644 src/algorithms/particle/TrackClusterSubtractor.h delete mode 100644 src/algorithms/particle/TrackClusterSubtractorConfig.h delete mode 100644 src/factories/particle/TrackClusterSubtractor_factory.h diff --git a/src/algorithms/particle/TrackClusterSubtractor.cc b/src/algorithms/particle/TrackClusterSubtractor.cc deleted file mode 100644 index 768b5a6452..0000000000 --- a/src/algorithms/particle/TrackClusterSubtractor.cc +++ /dev/null @@ -1,215 +0,0 @@ -// SPDX-License-Identifier: LGPL-3.0-or-later -// Copyright (C) 2025 Derek Anderson - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "TrackClusterSubtractor.h" -#include "algorithms/particle/TrackClusterSubtractorConfig.h" - -namespace eicrecon { - -// ---------------------------------------------------------------------------- -//! Process inputs -// ---------------------------------------------------------------------------- -/*! Subtract energy of matched tracks via the following algorithm. - * 1. Build a map of each cluster onto a list of matched - * track projections. - * 2. For each cluster, subtract the sum of momenta of - * all matched tracks scaled by the specified fraction - * from the cluster's energy. - * 3. For each matched cluster: - * a. If subtracted energy is greater than zero, create - * a remnant cluster with the subtracted energy - * b. And create an expected cluster with energy equal - * to the difference between the total and the remnant. - * 4. Flag any un-matched clusters as remnants. - */ -void TrackClusterSubtractor::process(const TrackClusterSubtractor::Input& input, - const TrackClusterSubtractor::Output& output) const { - - // grab inputs/outputs - const auto [in_match, in_cluster, in_project] = input; - auto [out_remnant, out_expect, out_match] = output; - - // exit if no clusters in collection - if (in_cluster->size() == 0) { - debug("No clusters in collection"); - return; - } - - // emit debugging message if no matched tracks in collection - if (in_match->size() == 0) { - debug("No matched tracks in collection."); - } - - // -------------------------------------------------------------------------- - // 1. Build map of clusters onto projections - // -------------------------------------------------------------------------- - MapToVecSeg mapClustToProj; - for (const auto& match : *in_match) { - for (const auto& project : *in_project) { - - // pick out corresponding projection from track - if (match.getTrack() != project.getTrack()) { - continue; - } else { - mapClustToProj[match.getCluster()].push_back(project); - } - - } // end projection loop - } // end track-cluster match loop - debug("Built map of clusters-onto-tracks, size = {}", mapClustToProj.size()); - - // now identify any clusters without matching tracks - VecClust vecNoMatchClust; - for (const auto& cluster : *in_cluster) { - if (mapClustToProj.count(cluster) == 0) { - vecNoMatchClust.push_back(cluster); - } - } - debug("Built vector of unmatched clusters, size = {}", vecNoMatchClust.size()); - - // -------------------------------------------------------------------------- - // 2. Subtract energy for tracks - // -------------------------------------------------------------------------- - for (const auto& [cluster, projects] : mapClustToProj) { - - // do subtraction - const double eToSub = m_cfg.fracEnergyToSub * sum_track_energy(projects); - const double eSub = cluster.getEnergy() - eToSub; - trace("Subtracted {} GeV from cluster with {} GeV", eToSub, cluster.getEnergy()); - - // check if consistent with zero, - // set eSub accordingly - const bool isZero = is_zero(eSub); - const double eSubToUse = isZero ? 0. : eSub; - - // ------------------------------------------------------------------------ - // 3(a). If difference not consistent with zero, create output remnant - // ------------------------------------------------------------------------ - if (!isZero) { - auto remain_clust = cluster.clone(); - remain_clust.setEnergy(eSubToUse); - out_remnant->push_back(remain_clust); - trace("Created remnant cluster with {} GeV", remain_clust.getEnergy()); - } - - // ------------------------------------------------------------------------ - // 3(b). Create cluster with energy equal to eTotal - eRemnant and match - // ------------------------------------------------------------------------ - auto expect_clust = cluster.clone(); - expect_clust.setEnergy(cluster.getEnergy() - eSubToUse); - out_expect->push_back(expect_clust); - trace("Created subtracted cluster with {} GeV (originally {} GeV)", expect_clust.getEnergy(), - cluster.getEnergy()); - - // create a track-cluster match for expected clusters - for (const auto& project : projects) { - edm4eic::MutableTrackClusterMatch match = out_match->create(); - match.setCluster(expect_clust); - match.setTrack(project.getTrack()); - match.setWeight(1.0); // FIXME placeholder - trace("Matched expected cluster {} to track {}", expect_clust.getObjectID().index, - project.getTrack().getObjectID().index); - } - } // end cluster-to-projections loop - debug("Finished subtraction, {} remnant clusters and {} expected clusters", out_remnant->size(), - out_expect->size()); - - // -------------------------------------------------------------------------- - // 4. Any unmatched clusters are remnants by definition - // -------------------------------------------------------------------------- - for (const auto& cluster : vecNoMatchClust) { - auto remain_clust = cluster.clone(); - out_remnant->push_back(remain_clust); - } - debug("Finished copying unmatched clusters to remnants, {} remnant clusters", - out_remnant->size()); - -} // end 'process(Input&, Output&)' - -// ---------------------------------------------------------------------------- -//! Sum energy of tracks -// ---------------------------------------------------------------------------- -/*! Sums energy of tracks projected to the surface in the - * calorimeter specified by `surfaceToUse`. Uses PDG of - * track to select mass for energy; if not available, - * uses mass set by `defaultMassPdg`. - */ -double TrackClusterSubtractor::sum_track_energy(const VecSeg& projects) const { - - double eSum = 0.; - for (const auto& project : projects) { - - // measure momentum at specified surface - double momentum = 0.; - for (const auto& point : project.getPoints()) { - if (point.surface != m_cfg.surfaceToUse) { - continue; - } else { - momentum = edm4hep::utils::magnitude(point.momentum); - break; - } - } - - // get mass based on track pdg - double mass = m_parSvc.particle(m_cfg.defaultMassPdg).mass; - if (project.getTrack().getPdg() != 0) { - mass = m_parSvc.particle(project.getTrack().getPdg()).mass; - } - - // increment sum - eSum += std::sqrt((momentum * momentum) + (mass * mass)); - } - - // output debugging and exit - trace("Sum of track energy = {} GeV", eSum); - return eSum; - -} // end 'sum_track_energy(VecSeg&)' - -// -------------------------------------------------------------------------- -//! Is difference consistent with zero? -// -------------------------------------------------------------------------- -/*! Checks if provided difference is consistent with zero, - * either checking if difference is within an epsilon - * (if `doNSigmaCut` is false), or if difference is within - * `nSigmaMax` of zero (if `doNSigmaCut` is true) based on - * the provided tracker and calorimeter resolutions. - */ -bool TrackClusterSubtractor::is_zero(const double difference) const { - - // if < 0, automatically return true - if (difference < 0) { - return true; - } - - // calculate nSigma - const double totReso = - std::sqrt((m_cfg.trkReso * m_cfg.trkReso) + (m_cfg.calReso * m_cfg.calReso)); - const double nSigma = difference / totReso; - - // do appropriate comparison - bool isZero = false; - if (m_cfg.doNSigmaCut) { - isZero = (nSigma < m_cfg.nSigmaMax); - trace("Difference of {} GeV consistent with zero: nSigma = {} < {}", difference, nSigma, - m_cfg.nSigmaMax); - } else { - isZero = std::abs(difference) < std::numeric_limits::epsilon(); - trace("Difference of {} GeV consistent with zero within an epsilon", difference); - } - return isZero; - -} // end 'is_zero(double)' -} // namespace eicrecon diff --git a/src/algorithms/particle/TrackClusterSubtractor.h b/src/algorithms/particle/TrackClusterSubtractor.h deleted file mode 100644 index 91ddb4dd67..0000000000 --- a/src/algorithms/particle/TrackClusterSubtractor.h +++ /dev/null @@ -1,90 +0,0 @@ -// SPDX-License-Identifier: LGPL-3.0-or-later -// Copyright (C) 2025 Derek Anderson - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "TrackClusterSubtractorConfig.h" -#include "algorithms/interfaces/WithPodConfig.h" -#include "services/particle/ParticleSvc.h" - -namespace eicrecon { - -// -------------------------------------------------------------------------- -//! Algorithm input/output -// -------------------------------------------------------------------------- -using TrackClusterSubtractorAlgorithm = algorithms::Algorithm< - algorithms::Input, - algorithms::Output>; - -// ========================================================================== -//! Track-Cluster Subtraction -// ========================================================================== -/*! An algorithm which takes a collection of clusters and their matched - * tracks, subtracts the sum of all tracks pointing to the cluster, - * and outputs the remnant clusters, expected clusters, and their matched - * tracks. - */ -class TrackClusterSubtractor : public TrackClusterSubtractorAlgorithm, - public WithPodConfig { - -public: - // ------------------------------------------------------------------------ - //! Comparator struct for clusters - // ------------------------------------------------------------------------ - /*! Organizes clusters by their ObjectIDs in decreasing collection - * ID first, and by decreasing index second. - */ - struct CompareClust { - bool operator()(const edm4eic::Cluster& lhs, const edm4eic::Cluster& rhs) const { - if (lhs.getObjectID().collectionID == rhs.getObjectID().collectionID) { - return (lhs.getObjectID().index < rhs.getObjectID().index); - } else { - return (lhs.getObjectID().collectionID < rhs.getObjectID().collectionID); - } - } - }; - - ///! Alias for vectors of clusters - using VecClust = std::vector; - - ///! Alias for vectors of track segments - using VecSeg = std::vector; - - ///! Alias for a map from a cluster to the segments of matched tracks - using MapToVecSeg = std::map; - - ///! Algorithm constructor - TrackClusterSubtractor(std::string_view name) - : TrackClusterSubtractorAlgorithm{ - name, - {"inputTrackClusterMatches", "inputClusters", "inputTrackProjections"}, - {"outputRemnantClusterCollection", "outputExpectedClusterCollection", - "outputTrackExpectedClusterMatches"}, - "Subtracts energy of tracks pointing to clusters."} {} - - // public method - void process(const Input&, const Output&) const final; - -private: - // private methods - double sum_track_energy(const VecSeg& projects) const; - bool is_zero(const double difference) const; - - ///! Particle service instance for retrieving specified mass hypothesis - const algorithms::ParticleSvc& m_parSvc = algorithms::ParticleSvc::instance(); - -}; // end TrackClusterSubtractor - -} // namespace eicrecon diff --git a/src/algorithms/particle/TrackClusterSubtractorConfig.h b/src/algorithms/particle/TrackClusterSubtractorConfig.h deleted file mode 100644 index 843f155d1b..0000000000 --- a/src/algorithms/particle/TrackClusterSubtractorConfig.h +++ /dev/null @@ -1,35 +0,0 @@ -// SPDX-License-Identifier: LGPL-3.0-or-later -// Copyright (C) 2025 Derek Anderson - -#pragma once - -#include - -namespace eicrecon { - -struct TrackClusterSubtractorConfig { - - ///! fraction of track energy to subtract - double fracEnergyToSub = 1.0; - - ///! default mass to use for track energy - int32_t defaultMassPdg = 211; - - ///! index of surface to use for measuring momentum - uint64_t surfaceToUse = 1; - - ///! turn on/off checking against resolutions - bool doNSigmaCut = false; - - ///! max no. of sigma to be consistent w/ zero - uint32_t nSigmaMax = 1; - - ///! tracking momentum resolution to use - double trkReso = 1.0; - - ///! calorimeter energy resolution to use - double calReso = 1.0; - -}; // end TrackClusterSubtractorConfig - -} // namespace eicrecon diff --git a/src/factories/particle/TrackClusterSubtractor_factory.h b/src/factories/particle/TrackClusterSubtractor_factory.h deleted file mode 100644 index 0037c77fe6..0000000000 --- a/src/factories/particle/TrackClusterSubtractor_factory.h +++ /dev/null @@ -1,66 +0,0 @@ -// SPDX-License-Identifier: LGPL-3.0-or-later -// Copyright (C) 2025 Derek Anderson - -#pragma once - -#include -#include - -#include "extensions/jana/JOmniFactory.h" -#include "services/geometry/dd4hep/DD4hep_service.h" -#include "services/algorithms_init/AlgorithmsInit_service.h" -#include "algorithms/particle/TrackClusterSubtractor.h" - -namespace eicrecon { - -class TrackClusterSubtractor_factory - : public JOmniFactory { - -public: - ///! alias for algorithm name - using AlgoT = eicrecon::TrackClusterSubtractor; - -private: - // pointer to algorithm - std::unique_ptr m_algo; - - // input collections - PodioInput m_track_cluster_match_input{this}; - PodioInput m_clusters_input{this}; - PodioInput m_track_projections_input{this}; - - // output collections - PodioOutput m_remnant_clusters_output{this}; - PodioOutput m_expected_clusters_output{this}; - PodioOutput m_track_expected_match_output{this}; - - // parameter bindings - ParameterRef m_fracEnergyToSub{this, "fracEnergyToSub", config().fracEnergyToSub}; - ParameterRef m_defaultMassPdg{this, "defaultMassPdg", config().defaultMassPdg}; - ParameterRef m_surfaceToUse{this, "surfaceToUse", config().surfaceToUse}; - ParameterRef m_doNSigmaCut{this, "doNSigmaCut", config().doNSigmaCut}; - ParameterRef m_nSigmaMax{this, "nSigmaMax", config().nSigmaMax}; - ParameterRef m_trkReso{this, "trkReso", config().trkReso}; - ParameterRef m_calReso{this, "calReso", config().calReso}; - - // services - Service m_algoInitSvc{this}; - -public: - ///! Configures algorithm - void Configure() { - m_algo = std::make_unique(GetPrefix()); - m_algo->applyConfig(config()); - m_algo->init(); - } - - ///! Primary algorithm call - void Process(int32_t /*run_number*/, uint64_t /*event_number*/) { - m_algo->process( - {m_track_cluster_match_input(), m_clusters_input(), m_track_projections_input()}, - {m_remnant_clusters_output().get(), m_expected_clusters_output().get(), - m_track_expected_match_output().get()}); - } -}; // end TrackClusterSubtractor_factory - -} // namespace eicrecon diff --git a/src/global/particle/particle.cc b/src/global/particle/particle.cc index 0497fa2192..6ec9ce5dbd 100644 --- a/src/global/particle/particle.cc +++ b/src/global/particle/particle.cc @@ -13,7 +13,6 @@ #include "extensions/jana/JOmniFactoryGeneratorT.h" #include "factories/meta/CollectionCollector_factory.h" #include "factories/particle/ChargedCandidateMaker_factory.h" -#include "factories/particle/TrackClusterSubtractor_factory.h" extern "C" { diff --git a/src/services/io/podio/JEventProcessorPODIO.cc b/src/services/io/podio/JEventProcessorPODIO.cc index 24761cbf3d..2fd3bbca9f 100644 --- a/src/services/io/podio/JEventProcessorPODIO.cc +++ b/src/services/io/podio/JEventProcessorPODIO.cc @@ -395,28 +395,6 @@ JEventProcessorPODIO::JEventProcessorPODIO() { "HcalEndcapNTrackClusterMatches", // particle flow - "EcalBarrelRemnantClusters", - "EcalBarrelExpectedClusters", - "EcalBarrelTrackExpectedClusterMatches", - "EcalEndcapNRemnantClusters", - "EcalEndcapNExpectedClusters", - "EcalEndcapNTrackExpectedClusterMatches", - "EcalEndcapPRemnantClusters", - "EcalEndcapPExpectedClusters", - "EcalEndcapPTrackExpectedClusterMatches", - "HcalBarrelRemnantClusters", - "HcalBarrelExpectedClusters", - "HcalBarrelTrackExpectedClusterMatches", - "HcalEndcapNRemnantClusters", - "HcalEndcapNExpectedClusters", - "HcalEndcapNTrackExpectedClusterMatches", - "LFHCALRemnantClusters", - "LFHCALExpectedClusters", - "LFHCALTrackExpectedClusterMatches", - "HcalEndcapPInsertRemnantClusters", - "HcalEndcapPInsertExpectedClusters", - "HcalEndcapPInsertTrackExpectedClusterMatches", - "EndcapNChargedCandidateParticlesAlpha", "BarrelChargedCandidateParticlesAlpha", "EndcapPChargedCandidateParticlesAlpha", From d517eb9705362f16e2c4026b648332485f0416fd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 30 Oct 2025 16:35:31 +0000 Subject: [PATCH 46/46] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/global/particle/particle.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/global/particle/particle.cc b/src/global/particle/particle.cc index 6ec9ce5dbd..47f392a439 100644 --- a/src/global/particle/particle.cc +++ b/src/global/particle/particle.cc @@ -69,8 +69,7 @@ void InitPlugin(JApplication* app) { app->Add( new JOmniFactoryGeneratorT>( "EndcapPInsertTrackClusterMatches", - {"EcalEndcapPTrackClusterMatches", - "HcalEndcapPInsertTrackClusterMatches"}, + {"EcalEndcapPTrackClusterMatches", "HcalEndcapPInsertTrackClusterMatches"}, {"EndcapPInsertTrackClusterMatches"}, app)); app->Add(new JOmniFactoryGeneratorT(