ATLAS Offline Software
Loading...
Searching...
No Matches
JetLinkMatcherAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "JetLinkMatcherAlg.h"
8#include <vector>
9#include <memory>
10
11namespace ftag {
12
13 JetLinkMatcherAlg::JetLinkMatcherAlg(const std::string& name,
14 ISvcLocator* pSvcLocator):
15 AthReentrantAlgorithm(name, pSvcLocator)
16 {
17 declareProperty("floatsToCopy", m_floats.toCopy);
18 declareProperty("doublesToCopy", m_doubles.toCopy);
19 declareProperty("intsToCopy", m_ints.toCopy);
20 declareProperty("uintsToCopy", m_uints.toCopy);
21 declareProperty("ulongsToCopy", m_ulongs.toCopy);
22 declareProperty("charsToCopy", m_chars.toCopy);
23 declareProperty("iparticlesToCopy", m_iparticles.toCopy);
24 }
25
27 std::vector<std::string> sources;
28 for (const auto& key: m_sourceJets) {
29 sources.emplace_back(key.key());
30 }
31 std::string target = m_targetJet.key();
32 ATH_CHECK(m_floats.initialize(this, sources, target));
33 ATH_CHECK(m_doubles.initialize(this, sources, target));
34 ATH_CHECK(m_ints.initialize(this, sources, target));
35 ATH_CHECK(m_uints.initialize(this, sources, target));
36 ATH_CHECK(m_ulongs.initialize(this, sources, target));
37 ATH_CHECK(m_chars.initialize(this, sources, target));
38 ATH_CHECK(m_iparticles.initialize(this, sources, target));
39 ATH_CHECK(m_targetJet.initialize());
40 ATH_CHECK(m_sourceJets.initialize());
41 ATH_CHECK(m_link.initialize());
42 if (!m_matchDecorator.empty()) {
43 ATH_CHECK(m_matchDecorator.initialize());
44 }
45 return StatusCode::SUCCESS;
46 }
47
48 StatusCode JetLinkMatcherAlg::execute(const EventContext& cxt) const {
49 using JC = xAOD::JetContainer;
50 SG::ReadHandle<IPC> targetJetGet(m_targetJet, cxt);
52 std::optional<SG::WriteDecorHandle<IPC,char>> matchDecorator;
53 if (!m_matchDecorator.empty()) {
54 matchDecorator.emplace(m_matchDecorator, cxt);
55 }
56 std::vector<MatchedPair<IPC>> matches;
57 for (const xAOD::IParticle* target: *targetJetGet) {
58 const ElementLink<IPC>& sourceLink = link(*target);
59 const xAOD::IParticle* source = sourceLink.isValid() ?
60 *sourceLink : nullptr;
61 if (!matchDecorator && !source) {
62 throw std::runtime_error("invalid link to source");
63 }
64 if (source) {
65 if (matchDecorator) matchDecorator.value()(*target) = 1;
66 matches.push_back({source, target});
67 } else {
68 matchDecorator.value()(*target) = 0;
69 matches.push_back({nullptr, target});
70 }
71 }
72 m_floats.copy(matches, cxt);
73 m_doubles.copy(matches, cxt);
74 m_ints.copy(matches, cxt);
75 m_uints.copy(matches, cxt);
76 m_ulongs.copy(matches, cxt);
77 m_chars.copy(matches, cxt);
78 m_iparticles.copy(matches, cxt);
79
80 return StatusCode::SUCCESS;
81 }
83 return StatusCode::SUCCESS;
84 }
85
86}// end namespace ftag
#define ATH_CHECK
Evaluate an expression and check for errors.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
An algorithm that can be simultaneously executed in multiple threads.
Handle class for reading a decoration on an object.
virtual StatusCode execute(const EventContext &) const override
virtual StatusCode initialize() override
VariableMule< IPLV, IPC > m_iparticles
VariableMule< uint, IPC > m_uints
VariableMule< int, IPC > m_ints
SG::ReadHandleKeyArray< IPC > m_sourceJets
VariableMule< float, IPC > m_floats
VariableMule< ulong, IPC > m_ulongs
SG::ReadDecorHandleKey< IPC > m_link
SG::ReadHandleKey< IPC > m_targetJet
VariableMule< double, IPC > m_doubles
SG::WriteDecorHandleKey< IPC > m_matchDecorator
VariableMule< char, IPC > m_chars
virtual StatusCode finalize() override
JetLinkMatcherAlg(const std::string &name, ISvcLocator *pSvcLocator)
Class providing the definition of the 4-vector interface.
JetContainer_v1 JetContainer
Definition of the current "jet container version".