Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-11 08:51:52

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2022 Wouter Deconinck
0003 
0004 #include "Gaudi/Algorithm.h"
0005 #include "GaudiKernel/RndmGenerators.h"
0006 #include "GaudiKernel/PhysicalConstants.h"
0007 #include <algorithm>
0008 #include <cmath>
0009 
0010 #include "JugBase/IParticleSvc.h"
0011 #include <k4FWCore/DataHandle.h>
0012 
0013 #include "JugBase/Utilities/Beam.h"
0014 
0015 #include "Math/Vector4D.h"
0016 using ROOT::Math::PxPyPzEVector;
0017 
0018 // Event Model related classes
0019 #include "edm4hep/MCParticleCollection.h"
0020 
0021 namespace Jug::Fast {
0022 
0023 class ScatteredElectronFinder : public Gaudi::Algorithm {
0024 private:
0025   mutable DataHandle<edm4hep::MCParticleCollection> m_inputMCParticleCollection{
0026     "inputMCParticles",
0027     Gaudi::DataHandle::Reader,
0028     this};
0029   mutable DataHandle<edm4hep::MCParticleCollection> m_outputMCScatteredElectron{
0030     "outputMCScatteredElectron",
0031     Gaudi::DataHandle::Writer,
0032     this};
0033 
0034 public:
0035   ScatteredElectronFinder(const std::string& name, ISvcLocator* svcLoc)
0036       : Gaudi::Algorithm(name, svcLoc) {
0037     declareProperty("inputMCParticles", m_inputMCParticleCollection, "MCParticles");
0038     declareProperty("outputMCScatteredElectron", m_outputMCScatteredElectron, "MCScatteredElectron");
0039   }
0040 
0041   StatusCode initialize() override {
0042     return Gaudi::Algorithm::initialize();
0043   }
0044 
0045   StatusCode execute(const EventContext&) const override {
0046     // input collections
0047     const auto& mcparts = *(m_inputMCParticleCollection.get());
0048     // output collection
0049     auto& out_electron = *(m_outputMCScatteredElectron.createAndPut());
0050     out_electron.setSubsetCollection();
0051 
0052     // Determine scattered electron
0053     //
0054     // Currently taken as first status==1 electron in HEPMC record,
0055     // which seems to be correct based on a cursory glance at the
0056     // Pythia8 output. In the future, it may be better to trace back
0057     // each final-state electron and see which one originates from
0058     // the beam.
0059     const auto ef_coll = Jug::Base::Beam::find_first_scattered_electron(mcparts);
0060     out_electron.push_back(ef_coll.front());
0061 
0062     return StatusCode::SUCCESS;
0063   }
0064 };
0065 
0066 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
0067 DECLARE_COMPONENT(ScatteredElectronFinder)
0068 
0069 } // namespace Jug::Fast