From 8be97d9b384f31d389b0ecf6cf89c44d47eeebc5 Mon Sep 17 00:00:00 2001 From: Wouter Deconinck Date: Fri, 5 Aug 2022 19:03:32 +0000 Subject: [PATCH 1/2] feat: ScatteredElectronFinder, returns subset collection with first status==1 electron --- .../components/ScatteredElectronFinder.cpp | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 JugFast/src/components/ScatteredElectronFinder.cpp diff --git a/JugFast/src/components/ScatteredElectronFinder.cpp b/JugFast/src/components/ScatteredElectronFinder.cpp new file mode 100644 index 00000000..40f3054b --- /dev/null +++ b/JugFast/src/components/ScatteredElectronFinder.cpp @@ -0,0 +1,72 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright (C) 2022 Wouter Deconinck + +#include "Gaudi/Algorithm.h" +#include "GaudiAlg/GaudiTool.h" +#include "GaudiAlg/Producer.h" +#include "GaudiAlg/Transformer.h" +#include "GaudiKernel/RndmGenerators.h" +#include "GaudiKernel/PhysicalConstants.h" +#include +#include + +#include "JugBase/IParticleSvc.h" +#include "JugBase/DataHandle.h" + +#include "JugBase/Utilities/Beam.h" + +#include "Math/Vector4D.h" +using ROOT::Math::PxPyPzEVector; + +// Event Model related classes +#include "edm4hep/MCParticleCollection.h" + +namespace Jug::Fast { + +class ScatteredElectronFinder : public GaudiAlgorithm { +private: + DataHandle m_inputMCParticleCollection{ + "inputMCParticles", + Gaudi::DataHandle::Reader, + this}; + DataHandle m_outputMCScatteredElectron{ + "outputMCScatteredElectron", + Gaudi::DataHandle::Writer, + this}; + +public: + ScatteredElectronFinder(const std::string& name, ISvcLocator* svcLoc) + : GaudiAlgorithm(name, svcLoc) { + declareProperty("inputMCParticles", m_inputMCParticleCollection, "MCParticles"); + declareProperty("outputMCScatteredElectron", m_outputMCScatteredElectron, "MCScatteredElectron"); + } + + StatusCode initialize() override { + m_outputMCScatteredElectron->setSubsetCollection(); + return GaudiAlgorithm::initialize(); + } + + StatusCode execute() override { + // input collections + const auto& mcparts = *(m_inputMCParticleCollection.get()); + // output collection + auto& out_electron = *(m_outputMCScatteredElectron.createAndPut()); + + // Determine scattered electron + // + // Currently taken as first status==1 electron in HEPMC record, + // which seems to be correct based on a cursory glance at the + // Pythia8 output. In the future, it may be better to trace back + // each final-state electron and see which one originates from + // the beam. + const auto ef_coll = Jug::Base::Beam::find_first_scattered_electron(mcparts); + out_electron.push_back(ef_coll.front()); + + return StatusCode::SUCCESS; + } +}; + +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) +DECLARE_COMPONENT(ScatteredElectronFinder) + +} // namespace Jug::Fast -- GitLab From bda9466ddebb78a6e5e75efc17f1a37411c01e4f Mon Sep 17 00:00:00 2001 From: Wouter Deconinck Date: Wed, 10 Aug 2022 22:31:28 -0500 Subject: [PATCH 2/2] fix: setSubsetCollection after createAndPut --- JugFast/src/components/ScatteredElectronFinder.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/JugFast/src/components/ScatteredElectronFinder.cpp b/JugFast/src/components/ScatteredElectronFinder.cpp index 40f3054b..8ef2794e 100644 --- a/JugFast/src/components/ScatteredElectronFinder.cpp +++ b/JugFast/src/components/ScatteredElectronFinder.cpp @@ -42,7 +42,6 @@ public: } StatusCode initialize() override { - m_outputMCScatteredElectron->setSubsetCollection(); return GaudiAlgorithm::initialize(); } @@ -51,6 +50,7 @@ public: const auto& mcparts = *(m_inputMCParticleCollection.get()); // output collection auto& out_electron = *(m_outputMCScatteredElectron.createAndPut()); + out_electron.setSubsetCollection(); // Determine scattered electron // -- GitLab