Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-06-29 07:06:48

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