From bc83bd6b9f335d785c95641d6fd27d65f95f22d0 Mon Sep 17 00:00:00 2001 From: Sebouh Paul Date: Mon, 10 Jun 2024 12:13:59 -0400 Subject: [PATCH 1/3] added calorimeter four momentum algorithm --- .../reco/CalorimeterTotalFourMomentum.cc | 46 +++++++++++++++++++ .../reco/CalorimeterTotalFourMomentum.h | 42 +++++++++++++++++ src/detectors/FHCAL/FHCAL.cc | 13 ++++++ .../CalorimeterTotalFourMomentum_factory.h | 39 ++++++++++++++++ 4 files changed, 140 insertions(+) create mode 100644 src/algorithms/reco/CalorimeterTotalFourMomentum.cc create mode 100644 src/algorithms/reco/CalorimeterTotalFourMomentum.h create mode 100644 src/factories/reco/CalorimeterTotalFourMomentum_factory.h diff --git a/src/algorithms/reco/CalorimeterTotalFourMomentum.cc b/src/algorithms/reco/CalorimeterTotalFourMomentum.cc new file mode 100644 index 0000000000..c0e8cefb6f --- /dev/null +++ b/src/algorithms/reco/CalorimeterTotalFourMomentum.cc @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (C) 2024 Sebouh Pual +#include "CalorimeterTotalFourMomentum.h" +#include +#include +#include +#include + +/** + Creates a pseudo particle containing the momenta and energies from all clusters in a given ClusterCollection. + The 3-momentum for each cluster is the energy of that cluster, in the direction from the origin to the + cluster position. These 3-momenta, along with the energies of the clusters, are added together to form + the total four-momentum in the calorimeter system. + + */ + +namespace eicrecon { + + void CalorimeterTotalFourMomentum::init() { } + + void CalorimeterTotalFourMomentum::process(const CalorimeterTotalFourMomentum::Input& input, + const CalorimeterTotalFourMomentum::Output& output) const { + + const auto [clusters] = input; + auto [hadronic_final_state] = output; + + double Etot=0; + double pxtot=0; + double pytot=0; + double pztot=0; + for (const auto& cluster : *clusters) { + double E = cluster.getEnergy(); + Etot+=E; + double x= cluster.getPosition().x; + double y= cluster.getPosition().y; + double z= cluster.getPosition().z; + double r=sqrt(x*x+y*y+z*z); + pxtot+=E*x/r; + pytot+=E*y/r; + pztot+=E*z/r; + } + auto hfs = hadronic_final_state->create(); + hfs.setMomentum({(float)pxtot, (float)pytot, (float)pztot}); + hfs.setEnergy((float)Etot); + } +} diff --git a/src/algorithms/reco/CalorimeterTotalFourMomentum.h b/src/algorithms/reco/CalorimeterTotalFourMomentum.h new file mode 100644 index 0000000000..689da2c878 --- /dev/null +++ b/src/algorithms/reco/CalorimeterTotalFourMomentum.h @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (C) 2024 Sebouh Paul + +#pragma once + +#include +#include +#include +#include +#include +#include // for basic_string +#include // for string_view +#include +#include "algorithms/interfaces/WithPodConfig.h" + + +namespace eicrecon { + +using CalorimeterTotalFourMomentumAlgorithm = algorithms::Algorithm< + algorithms::Input< + const edm4eic::ClusterCollection + >, + algorithms::Output< + edm4eic::ReconstructedParticleCollection + > + >; + class CalorimeterTotalFourMomentum : + public CalorimeterTotalFourMomentumAlgorithm, + public WithPodConfig { + public: + CalorimeterTotalFourMomentum(std::string_view name) + : CalorimeterTotalFourMomentumAlgorithm{name, + {"inputClusters"}, + {"totalFourMomentum"}, + "Merges all clusters in a collection into a total 4-vector of momentum and energy"} {} + + void init() final; + void process(const Input&, const Output&) const final; + private: + std::shared_ptr m_log; + }; +} // namespace eicrecon diff --git a/src/detectors/FHCAL/FHCAL.cc b/src/detectors/FHCAL/FHCAL.cc index 2d796d1bdf..4ba5276912 100644 --- a/src/detectors/FHCAL/FHCAL.cc +++ b/src/detectors/FHCAL/FHCAL.cc @@ -17,6 +17,7 @@ #include "factories/calorimetry/CalorimeterTruthClustering_factory.h" #include "factories/calorimetry/HEXPLIT_factory.h" #include "factories/calorimetry/ImagingTopoCluster_factory.h" +#include "factories/reco/CalorimeterTotalFourMomentum_factory.h" extern "C" { void InitPlugin(JApplication *app) { @@ -138,6 +139,18 @@ extern "C" { ) ); + app->Add( + new JOmniFactoryGeneratorT( + "HcalEndcapPInsertTotalFourMomentum", + {"HcalEndcapPInsertClusters"}, // edm4eic::Cluster + {"HcalEndcapPInsertTotalFourMomentum"}, // edm4eic::ReconstructedParticle + { + + }, + app // TODO: Remove me once fixed + ) + ); + // Make sure digi and reco use the same value decltype(CalorimeterHitDigiConfig::capADC) LFHCAL_capADC = 65536; decltype(CalorimeterHitDigiConfig::dyRangeADC) LFHCAL_dyRangeADC = 1 * dd4hep::GeV; diff --git a/src/factories/reco/CalorimeterTotalFourMomentum_factory.h b/src/factories/reco/CalorimeterTotalFourMomentum_factory.h new file mode 100644 index 0000000000..0474267494 --- /dev/null +++ b/src/factories/reco/CalorimeterTotalFourMomentum_factory.h @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (C) 2024 Sebouh Paul + +#pragma once + +#include "algorithms/reco/CalorimeterTotalFourMomentum.h" +#include "services/algorithms_init/AlgorithmsInit_service.h" +#include "extensions/jana/JOmniFactory.h" + + +namespace eicrecon { + +class CalorimeterTotalFourMomentum_factory : public JOmniFactory { + + using AlgoT = eicrecon::CalorimeterTotalFourMomentum; + private: + std::unique_ptr m_algo; + PodioInput m_clusters_input {this}; + PodioOutput m_four_momentum_output {this}; + + Service m_algorithmsInit {this}; + +public: + void Configure() { + m_algo = std::make_unique(GetPrefix()); + m_algo->level((algorithms::LogLevel)logger()->level()); + m_algo->applyConfig(config()); + m_algo->init(); + } + + void ChangeRun(int64_t run_number) { + } + + void Process(int64_t run_number, uint64_t event_number) { + m_algo->process({m_clusters_input()},{m_four_momentum_output().get()}); + } +}; + +} // eicrecon From dc77759b879b918043e88aef20e5b72aa8beb102 Mon Sep 17 00:00:00 2001 From: Sebouh Paul Date: Mon, 10 Jun 2024 12:34:51 -0400 Subject: [PATCH 2/3] added HcalEndcapPInsertTotalFourMomentum to list of banks --- src/services/io/podio/JEventProcessorPODIO.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/io/podio/JEventProcessorPODIO.cc b/src/services/io/podio/JEventProcessorPODIO.cc index 7b36d2f66f..9f90f7bd9a 100644 --- a/src/services/io/podio/JEventProcessorPODIO.cc +++ b/src/services/io/podio/JEventProcessorPODIO.cc @@ -212,7 +212,7 @@ JEventProcessorPODIO::JEventProcessorPODIO() { #if EDM4EIC_VERSION_MAJOR >= 6 "HadronicFinalState", #endif - + "HcalEndcapPInsertTotalFourMomentum", // Track projections "CalorimeterTrackProjections", From 9c911f2a08a16d1abddd32e8948d1f7c3d33fdff Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 10 Jun 2024 16:43:28 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../reco/CalorimeterTotalFourMomentum.cc | 14 +++++++------- src/detectors/FHCAL/FHCAL.cc | 10 +++++----- src/services/io/podio/JEventProcessorPODIO.cc | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/algorithms/reco/CalorimeterTotalFourMomentum.cc b/src/algorithms/reco/CalorimeterTotalFourMomentum.cc index c0e8cefb6f..2b68ffcace 100644 --- a/src/algorithms/reco/CalorimeterTotalFourMomentum.cc +++ b/src/algorithms/reco/CalorimeterTotalFourMomentum.cc @@ -10,7 +10,7 @@ Creates a pseudo particle containing the momenta and energies from all clusters in a given ClusterCollection. The 3-momentum for each cluster is the energy of that cluster, in the direction from the origin to the cluster position. These 3-momenta, along with the energies of the clusters, are added together to form - the total four-momentum in the calorimeter system. + the total four-momentum in the calorimeter system. */ @@ -32,12 +32,12 @@ namespace eicrecon { double E = cluster.getEnergy(); Etot+=E; double x= cluster.getPosition().x; - double y= cluster.getPosition().y; - double z= cluster.getPosition().z; - double r=sqrt(x*x+y*y+z*z); - pxtot+=E*x/r; - pytot+=E*y/r; - pztot+=E*z/r; + double y= cluster.getPosition().y; + double z= cluster.getPosition().z; + double r=sqrt(x*x+y*y+z*z); + pxtot+=E*x/r; + pytot+=E*y/r; + pztot+=E*z/r; } auto hfs = hadronic_final_state->create(); hfs.setMomentum({(float)pxtot, (float)pytot, (float)pztot}); diff --git a/src/detectors/FHCAL/FHCAL.cc b/src/detectors/FHCAL/FHCAL.cc index 4ba5276912..e9470809ca 100644 --- a/src/detectors/FHCAL/FHCAL.cc +++ b/src/detectors/FHCAL/FHCAL.cc @@ -139,18 +139,18 @@ extern "C" { ) ); - app->Add( + app->Add( new JOmniFactoryGeneratorT( "HcalEndcapPInsertTotalFourMomentum", - {"HcalEndcapPInsertClusters"}, // edm4eic::Cluster - {"HcalEndcapPInsertTotalFourMomentum"}, // edm4eic::ReconstructedParticle + {"HcalEndcapPInsertClusters"}, // edm4eic::Cluster + {"HcalEndcapPInsertTotalFourMomentum"}, // edm4eic::ReconstructedParticle { }, - app // TODO: Remove me once fixed + app // TODO: Remove me once fixed ) ); - + // Make sure digi and reco use the same value decltype(CalorimeterHitDigiConfig::capADC) LFHCAL_capADC = 65536; decltype(CalorimeterHitDigiConfig::dyRangeADC) LFHCAL_dyRangeADC = 1 * dd4hep::GeV; diff --git a/src/services/io/podio/JEventProcessorPODIO.cc b/src/services/io/podio/JEventProcessorPODIO.cc index 9f90f7bd9a..8d073282c1 100644 --- a/src/services/io/podio/JEventProcessorPODIO.cc +++ b/src/services/io/podio/JEventProcessorPODIO.cc @@ -212,7 +212,7 @@ JEventProcessorPODIO::JEventProcessorPODIO() { #if EDM4EIC_VERSION_MAJOR >= 6 "HadronicFinalState", #endif - "HcalEndcapPInsertTotalFourMomentum", + "HcalEndcapPInsertTotalFourMomentum", // Track projections "CalorimeterTrackProjections",