diff --git a/src/algorithms/reco/CalorimeterTotalFourMomentum.cc b/src/algorithms/reco/CalorimeterTotalFourMomentum.cc new file mode 100644 index 0000000000..2b68ffcace --- /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..e9470809ca 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 diff --git a/src/services/io/podio/JEventProcessorPODIO.cc b/src/services/io/podio/JEventProcessorPODIO.cc index 7b36d2f66f..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", // Track projections "CalorimeterTrackProjections",