diff --git a/src/algorithms/reco/ScatteredElectronsEMinusPz.cc b/src/algorithms/reco/ScatteredElectronsEMinusPz.cc index adecb6382a..0e0ec2bd30 100644 --- a/src/algorithms/reco/ScatteredElectronsEMinusPz.cc +++ b/src/algorithms/reco/ScatteredElectronsEMinusPz.cc @@ -1,5 +1,5 @@ // SPDX-License-Identifier: LGPL-3.0-or-later -// Copyright (C) 2024 Daniel Brandenburg +// Copyright (C) 2024 Daniel Brandenburg, Dmitry Kalinkin #include #include @@ -8,7 +8,8 @@ #include #include #include -#include +#include +#include #include #include @@ -22,12 +23,8 @@ namespace eicrecon { /** * @brief Initialize the ScatteredElectronsEMinusPz Algorithm - * - * @param logger */ - void ScatteredElectronsEMinusPz::init(std::shared_ptr& logger) { - m_log = logger; - } + void ScatteredElectronsEMinusPz::init() { } /** * @brief Produce a list of scattered electron candidates @@ -36,26 +33,24 @@ namespace eicrecon { * @param rcele - input collection of all electron candidates * @return std::unique_ptr */ - std::unique_ptr ScatteredElectronsEMinusPz::execute( - const edm4eic::ReconstructedParticleCollection *rcparts, - const edm4eic::ReconstructedParticleCollection *rcele - ){ + void ScatteredElectronsEMinusPz::process( + const ScatteredElectronsEMinusPz::Input& input, + const ScatteredElectronsEMinusPz::Output& output + ) const { + auto [rcparts, rcele] = input; + auto [out_electrons] = output; + + static const auto m_electron = m_particleSvc.particle(11).mass; + static const auto m_pion = m_particleSvc.particle(211).mass; // this map will store intermediate results // so that we can sort them before filling output // collection - std::map scatteredElectronsMap; + std::map> scatteredElectronsMap; - // our output collection of scattered electrons - // ordered by E-Pz - auto out_electrons = std::make_unique< - edm4eic::ReconstructedParticleCollection - >(); out_electrons->setSubsetCollection(); - m_log->trace( "We have {} candidate electrons", - rcele->size() - ); + trace("We have {} candidate electrons", rcele->size()); // Lorentz Vector for the scattered electron, // hadronic final state, and individual hadron @@ -95,7 +90,7 @@ namespace eicrecon { // Sum hadronic final state vHadronicFinalState += vHadron; } else { - m_log->trace( "Skipping electron in hadronic final state" ); + trace("Skipping electron in hadronic final state"); } } // hadron loop (reconstructed particles) @@ -105,22 +100,20 @@ namespace eicrecon { // candidates but we will rank them by their E-Pz double EPz=(vScatteredElectron+vHadronicFinalState).E() - (vScatteredElectron+vHadronicFinalState).Pz(); - m_log->trace( "\tE-Pz={}", EPz ); - m_log->trace( "\tScatteredElectron has Pxyz=( {}, {}, {} )", e.getMomentum().x, e.getMomentum().y, e.getMomentum().z ); + trace("\tE-Pz={}", EPz); + trace("\tScatteredElectron has Pxyz=( {}, {}, {} )", e.getMomentum().x, e.getMomentum().y, e.getMomentum().z); // Store the result of this calculation scatteredElectronsMap[ EPz ] = e; } // electron loop - m_log->trace( "Selecting candidates with {} < E-Pz < {}", m_cfg.minEMinusPz, m_cfg.maxEMinusPz ); + trace("Selecting candidates with {} < E-Pz < {}", m_cfg.minEMinusPz, m_cfg.maxEMinusPz); - // map sorts in descending order by default - // sort by descending bool first = true; - // for (auto kv : scatteredElectronsMap) { - for (auto kv = scatteredElectronsMap.rbegin(); kv != scatteredElectronsMap.rend(); ++kv) { + // map defined with std::greater<> will be iterated in descending order by the key + for (auto kv : scatteredElectronsMap) { - double EMinusPz = kv->first; + double EMinusPz = kv.first; // Do not save electron candidates that // are not within range if ( EMinusPz > m_cfg.maxEMinusPz @@ -131,18 +124,13 @@ namespace eicrecon { // For logging and development // report the highest E-Pz candidate chosen if ( first ){ - m_log->trace( "Max E-Pz Candidate:" ); - m_log->trace( "\tE-Pz={}", EMinusPz ); - m_log->trace( "\tScatteredElectron has Pxyz=( {}, {}, {} )", kv->second.getMomentum().x, kv->second.getMomentum().y, kv->second.getMomentum().z ); + trace("Max E-Pz Candidate:"); + trace("\tE-Pz={}", EMinusPz); + trace("\tScatteredElectron has Pxyz=( {}, {}, {} )", kv.second.getMomentum().x, kv.second.getMomentum().y, kv.second.getMomentum().z); first = false; } - out_electrons->push_back( kv->second ); + out_electrons->push_back( kv.second ); } // reverse loop on scatteredElectronsMap - - - // Return Electron candidates ranked - // in order from largest E-Pz to smallest - return out_electrons; } } // namespace eicrecon diff --git a/src/algorithms/reco/ScatteredElectronsEMinusPz.h b/src/algorithms/reco/ScatteredElectronsEMinusPz.h index 9bad30da7f..a7680b7d9f 100644 --- a/src/algorithms/reco/ScatteredElectronsEMinusPz.h +++ b/src/algorithms/reco/ScatteredElectronsEMinusPz.h @@ -1,31 +1,45 @@ // SPDX-License-Identifier: LGPL-3.0-or-later -// Copyright (C) 2024 Daniel Brandenburg +// Copyright (C) 2024 Daniel Brandenburg, Dmitry Kalinkin #pragma once +#include #include -#include -#include +#include +#include -#include "algorithms/reco/ScatteredElectronsEMinusPzConfig.h" +#include "algorithms/interfaces/ParticleSvc.h" #include "algorithms/interfaces/WithPodConfig.h" +#include "algorithms/reco/ScatteredElectronsEMinusPzConfig.h" namespace eicrecon { - class ScatteredElectronsEMinusPz : public WithPodConfig{ + using ScatteredElectronsEMinusPzAlgorithm = algorithms::Algorithm< + algorithms::Input< + edm4eic::ReconstructedParticleCollection, + edm4eic::ReconstructedParticleCollection + >, + algorithms::Output< + edm4eic::ReconstructedParticleCollection + > + >; + + class ScatteredElectronsEMinusPz : public ScatteredElectronsEMinusPzAlgorithm, WithPodConfig{ + + public: - public: + ScatteredElectronsEMinusPz(std::string_view name) + : ScatteredElectronsEMinusPzAlgorithm{name, + {"inputParticles", "inputElectronCandidates"}, + {"outputElectrons"}, + "Outputs DIS electrons ordered in decreasing E-pz"} {} + void init() final; + void process(const Input&, const Output&) const final; - void init(std::shared_ptr& logger); - std::unique_ptr execute( - const edm4eic::ReconstructedParticleCollection *rcparts, - const edm4eic::ReconstructedParticleCollection *rcele - ); + private: + const algorithms::ParticleSvc& m_particleSvc = algorithms::ParticleSvc::instance(); - private: - std::shared_ptr m_log; - double m_electron{0.000510998928}, m_pion{0.13957}; + }; - }; } // namespace eicrecon diff --git a/src/global/reco/ScatteredElectronsEMinusPz_factory.h b/src/global/reco/ScatteredElectronsEMinusPz_factory.h index 7a7d1e6cf5..87ae54f26d 100644 --- a/src/global/reco/ScatteredElectronsEMinusPz_factory.h +++ b/src/global/reco/ScatteredElectronsEMinusPz_factory.h @@ -29,19 +29,21 @@ class ScatteredElectronsEMinusPz_factory : // Declare outputs PodioOutput m_out_reco_particles {this}; + Service m_algorithmsInit {this}; + public: void Configure() { - m_algo = std::make_unique(); - m_algo->init(logger()); - m_algo->applyConfig(config()); + m_algo = std::make_unique(GetPrefix()); + m_algo->level(static_cast(logger()->level())); + m_algo->init(); } void ChangeRun(int64_t run_number) { } void Process(int64_t run_number, uint64_t event_number) { - auto output = m_algo->execute(m_rc_particles_input(), m_rc_electrons_input()); - m_out_reco_particles() = std::move(output); + m_algo->process({m_rc_particles_input(), m_rc_electrons_input()}, + {m_out_reco_particles().get()}); } };