ATLAS Offline Software
Loading...
Searching...
No Matches
JetReclusteringAlg.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
8
9namespace CP {
10
12
15
18
20
21 ANA_CHECK(m_systematicsList.initialize());
22
23 // reclustering properties
25 ANA_MSG_ERROR("reclusteredJetsRadius is negative, please fix");
26 return StatusCode::FAILURE;
27 }
28
29 fastjet::JetAlgorithm algorithm;
30 static const std::unordered_map<std::string, fastjet::JetAlgorithm> algorithmMap = {
31 {"AntiKt", fastjet::antikt_algorithm},
32 {"Kt", fastjet::kt_algorithm},
33 {"CamKt", fastjet::cambridge_algorithm}
34 };
35 auto it = algorithmMap.find(m_clusteringAlgorithm.value());
36 if (it != algorithmMap.end()) {
37 algorithm = it->second;
38 } else {
39 ATH_MSG_ERROR("Jet reclustering algorithm " << m_clusteringAlgorithm.value()
40 << " is not supported by CP::JetReclusteringAlg! Choose amongst: AntiKt, Kt, CamKt.");
41 return StatusCode::FAILURE;
42 }
43
44 m_fastjetClustering = std::make_unique<fastjet::JetDefinition>(algorithm, m_reclusteredJetsRadius, fastjet::E_scheme, fastjet::Best);
45
46 return StatusCode::SUCCESS;
47 }
48
49 StatusCode JetReclusteringAlg::execute(const EventContext& ctx) {
50
51 for (const auto &sys : m_systematicsList.systematicsVector()) {
52
53 const xAOD::JetContainer *jets = nullptr;
54 ANA_CHECK(m_jetsHandle.retrieve(jets, sys, ctx));
55
56 auto rcJetAuxContainer = std::make_unique<xAOD::JetAuxContainer>();
57 auto rcJetContainer = std::make_unique<xAOD::JetContainer>();
58 rcJetContainer->setStore(rcJetAuxContainer.get());
59
60 // only take selected jets, remembering their index in the input
61 // container via the fastjet user index
62 std::vector<fastjet::PseudoJet> clusters;
63 clusters.reserve(jets->size());
64 for (std::size_t i = 0; i < jets->size(); ++i) {
65 const xAOD::Jet *jet = (*jets)[i];
66 if (m_jetSelection.getBool(*jet, sys)) {
67 fastjet::PseudoJet pseudoJet(jet->px(), jet->py(), jet->pz(), jet->e());
68 pseudoJet.set_user_index(static_cast<int>(i));
69 clusters.emplace_back(std::move(pseudoJet));
70 }
71 }
72
73 // no jets (clusters) - nothing to do
74 if (clusters.empty()) {
75 ANA_CHECK(m_outHandle.record(std::move(rcJetContainer), std::move(rcJetAuxContainer), sys, ctx));
76 continue;
77 }
78
79 fastjet::ClusterSequence cluster_sequence(clusters, *m_fastjetClustering);
80 std::vector<fastjet::PseudoJet> rcJets = cluster_sequence.inclusive_jets(0.0);
81
82 for (const auto& irc : rcJets) {
83 xAOD::Jet *rcJet = rcJetContainer->push_back(std::make_unique<xAOD::Jet>());
84
85 const xAOD::JetFourMom_t p4(irc.pt(), irc.eta(), irc.phi_std(), irc.m());
86 rcJet->setJetP4(p4);
87
88 const auto constituents = irc.constituents();
89
90 std::vector<int> indices;
91 indices.reserve(constituents.size());
92 for (const auto& iconst : constituents) {
93 indices.push_back(iconst.user_index());
94 }
95
96 m_smallRjetIndicesDecor.set(*rcJet, indices, sys);
97
98 // Write energy to the RC jet, since default 4-vector form is (pt, eta, phi, m)
99 m_rcEnergyDecor.set(*rcJet, irc.e(), sys);
100 }
101
102 ANA_CHECK(m_outHandle.record(std::move(rcJetContainer), std::move(rcJetAuxContainer), sys, ctx));
103
104 }
105 return StatusCode::SUCCESS;
106 }
107
108} // namespace
#define ATH_MSG_ERROR(x,...)
#define ANA_MSG_ERROR(xmsg,...)
Macro printing error messages.
#define ANA_CHECK(EXP)
check whether the given expression was successful
std::vector< std::vector< int64_t > > indices
Gaudi::Property< float > m_reclusteredJetsRadius
CP::SysWriteDecorHandle< float > m_rcEnergyDecor
std::unique_ptr< fastjet::JetDefinition > m_fastjetClustering
CP::SysReadSelectionHandle m_jetSelection
CP::SysWriteDecorHandle< std::vector< int > > m_smallRjetIndicesDecor
CP::SysListHandle m_systematicsList
CP::SysWriteHandle< xAOD::JetContainer, xAOD::JetAuxContainer > m_outHandle
Gaudi::Property< std::string > m_clusteringAlgorithm
CP::SysReadHandle< xAOD::JetContainer > m_jetsHandle
virtual StatusCode initialize() override
virtual::StatusCode execute()
execute this algorithm
void setJetP4(const JetFourMom_t &p4)
Definition Jet_v1.cxx:182
virtual double e() const
The total energy of the particle.
Definition Jet_v1.cxx:63
std::string algorithm
Definition hcg.cxx:87
Select isolated Photons, Electrons and Muons.
Jet_v1 Jet
Definition of the current "jet version".
JetContainer_v1 JetContainer
Definition of the current "jet container version".
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition JetTypes.h:17