ATLAS Offline Software
Loading...
Searching...
No Matches
TauSeedJetLabelCopyAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
9
10#include <algorithm>
11#include <limits>
12
13namespace {
14
15std::vector<std::size_t> sortedIndices(const std::vector<ElementLink<xAOD::IParticleContainer>>& links) {
16 std::vector<std::size_t> indices;
17 indices.reserve(links.size());
18 for (const ElementLink<xAOD::IParticleContainer>& link : links) indices.push_back(link.index());
19 std::sort(indices.begin(), indices.end());
20 return indices;
21}
22
23}
24
25namespace ParticleJetTools {
26
27TauSeedJetLabelCopyAlg::TauSeedJetLabelCopyAlg(const std::string& name, ISvcLocator* loc)
28 : AthReentrantAlgorithm(name, loc) {}
29
31 ATH_CHECK(m_tauKey.initialize());
32 ATH_CHECK(m_jetKey.initialize());
33
34 const std::string tauPrefix = m_tauKey.key() + ".";
35 for (const std::string& name : m_intNames) {
36 m_intAccs.emplace_back(name);
37 m_intDecorKeys.emplace_back(tauPrefix + name);
38 }
39 for (const std::string& name : m_floatNames) {
40 m_floatAccs.emplace_back(name);
41 m_floatDecorKeys.emplace_back(tauPrefix + name);
42 }
43 ATH_CHECK(m_intDecorKeys.initialize());
44 ATH_CHECK(m_floatDecorKeys.initialize());
45 return StatusCode::SUCCESS;
46}
47
48StatusCode TauSeedJetLabelCopyAlg::execute(const EventContext& ctx) const {
51 ATH_CHECK(taus.isValid());
52 ATH_CHECK(seedJets.isValid());
53 if (!m_matchConstituents && seedJets->size() != taus->size()) {
54 ATH_MSG_ERROR(taus->size() << " taus but " << seedJets->size() << " seed jets to match by index");
55 return StatusCode::FAILURE;
56 }
57
58 std::vector<std::vector<std::size_t>> jetConstituents;
60 jetConstituents.reserve(seedJets->size());
61 for (const xAOD::Jet* jet : *seedJets) jetConstituents.push_back(sortedIndices(jet->constituentLinks()));
62 }
63
64 auto intHandles = m_intDecorKeys.makeHandles(ctx);
65 auto floatHandles = m_floatDecorKeys.makeHandles(ctx);
66
67 for (std::size_t index = 0; index < taus->size(); ++index) {
68 const xAOD::TauJet* tau = taus->at(index);
69 const xAOD::Jet* jet = nullptr;
71 const auto match = std::find(jetConstituents.begin(), jetConstituents.end(), sortedIndices(tau->clusterLinks()));
72 if (match != jetConstituents.end()) jet = seedJets->at(match - jetConstituents.begin());
73 } else {
74 jet = seedJets->at(index);
75 }
76 for (std::size_t i = 0; i < intHandles.size(); ++i) {
77 intHandles.at(i)(*tau) = jet ? m_intAccs.at(i)(*jet) : -1;
78 }
79 for (std::size_t i = 0; i < floatHandles.size(); ++i) {
80 floatHandles.at(i)(*tau) = jet ? m_floatAccs.at(i)(*jet) : std::numeric_limits<float>::quiet_NaN();
81 }
82 }
83
84 return StatusCode::SUCCESS;
85}
86
87}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x,...)
std::vector< std::vector< int64_t > > indices
static Double_t taus
Handle class for reading from StoreGate.
Handle class for adding a decoration to an object.
An algorithm that can be simultaneously executed in multiple threads.
SG::WriteDecorHandleKeyArray< xAOD::TauJetContainer, int > m_intDecorKeys
virtual StatusCode execute(const EventContext &ctx) const override
SG::ReadHandleKey< xAOD::TauJetContainer > m_tauKey
std::vector< SG::ConstAccessor< float > > m_floatAccs
SG::ReadHandleKey< xAOD::JetContainer > m_jetKey
std::vector< SG::ConstAccessor< int > > m_intAccs
TauSeedJetLabelCopyAlg(const std::string &name, ISvcLocator *loc)
Gaudi::Property< std::vector< std::string > > m_floatNames
Gaudi::Property< std::vector< std::string > > m_intNames
SG::WriteDecorHandleKeyArray< xAOD::TauJetContainer, float > m_floatDecorKeys
virtual bool isValid() override final
Can the handle be successfully dereferenced?
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition hcg.cxx:359
pointer & link(pointer p) const
Return a reference to the link for an element.
Definition index.py:1
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Jet_v1 Jet
Definition of the current "jet version".
TauJet_v3 TauJet
Definition of the current "tau version".
Definition TauJet.h:17