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("charVectorsToCopy", m_charVectors.toCopy);
24 declareProperty("iparticlesToCopy", m_iparticles.toCopy);
25 declareProperty("trackLinksToCopy", m_trackLinks.toCopy);
26 }
27
29 std::vector<std::string> sources;
30 for (const auto& key: m_sourceJets) {
31 sources.emplace_back(key.key());
32 }
33 std::string target = m_targetJet.key();
34 ATH_CHECK(m_floats.initialize(this, sources, target));
35 ATH_CHECK(m_doubles.initialize(this, sources, target));
36 ATH_CHECK(m_ints.initialize(this, sources, target));
37 ATH_CHECK(m_uints.initialize(this, sources, target));
38 ATH_CHECK(m_ulongs.initialize(this, sources, target));
39 ATH_CHECK(m_chars.initialize(this, sources, target));
40 ATH_CHECK(m_charVectors.initialize(this, sources, target));
41 ATH_CHECK(m_iparticles.initialize(this, sources, target));
42 ATH_CHECK(m_trackLinks.initialize(this, sources, target));
43 ATH_CHECK(m_targetJet.initialize());
44 ATH_CHECK(m_sourceJets.initialize());
45 ATH_CHECK(m_link.initialize());
46 if (!m_matchDecorator.empty()) {
47 ATH_CHECK(m_matchDecorator.initialize());
48 }
49 return StatusCode::SUCCESS;
50 }
51
52 StatusCode JetLinkMatcherAlg::execute(const EventContext& cxt) const {
53 SG::ReadHandle<JC> targetJetGet(m_targetJet, cxt);
55 std::optional<SG::WriteDecorHandle<JC,char>> matchDecorator;
56 if (!m_matchDecorator.empty()) {
57 matchDecorator.emplace(m_matchDecorator, cxt);
58 }
59 std::vector<MatchedPair<JC>> matches;
60 for (const xAOD::Jet* target: *targetJetGet) {
61 const ElementLink<JC>& sourceLink = link(*target);
62 const xAOD::Jet* source = sourceLink.isValid() ?
63 *sourceLink : nullptr;
64 if (!matchDecorator && !source) {
65 throw std::runtime_error("invalid link to source");
66 }
67 if (source) {
68 if (matchDecorator) matchDecorator.value()(*target) = 1;
69 matches.push_back({source, target});
70 } else {
71 matchDecorator.value()(*target) = 0;
72 matches.push_back({nullptr, target});
73 }
74 }
75 m_floats.copy(matches, cxt);
76 m_doubles.copy(matches, cxt);
77 m_ints.copy(matches, cxt);
78 m_uints.copy(matches, cxt);
79 m_ulongs.copy(matches, cxt);
80 m_chars.copy(matches, cxt);
81 m_charVectors.copy(matches, cxt);
82 m_iparticles.copy(matches, cxt);
83 m_trackLinks.copy(matches, cxt);
84
85 return StatusCode::SUCCESS;
86 }
88 return StatusCode::SUCCESS;
89 }
90
91}// 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.
SG::ReadHandleKeyArray< JC > m_sourceJets
virtual StatusCode execute(const EventContext &) const override
VariableMule< int, JC > m_ints
virtual StatusCode initialize() override
VariableMule< double, JC > m_doubles
VariableMule< float, JC > m_floats
SG::ReadDecorHandleKey< JC > m_link
VariableMule< char, JC > m_chars
SG::WriteDecorHandleKey< JC > m_matchDecorator
VariableMule< TPLV, JC > m_trackLinks
SG::ReadHandleKey< JC > m_targetJet
VariableMule< uint, JC > m_uints
VariableMule< ulong, JC > m_ulongs
virtual StatusCode finalize() override
VariableMule< std::vector< char >, JC > m_charVectors
VariableMule< IPLV, JC > m_iparticles
JetLinkMatcherAlg(const std::string &name, ISvcLocator *pSvcLocator)
Jet_v1 Jet
Definition of the current "jet version".