ATLAS Offline Software
Loading...
Searching...
No Matches
CaloClusterLoader.cxx
Go to the documentation of this file.
1/*
2Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
9#include <unordered_set>
10#include <vector>
11
12namespace FlavorTagInference {
13
14 // factory for functions which return the sort variable we
15 // use to order calo clusters
18 {
19 typedef xAOD::CaloCluster CC;
20 typedef xAOD::IParticle Jet;
21 switch(config) {
23 return [](const CC* p, const Jet&) {return p->pt();};
24 default: {
25 throw std::logic_error("Unknown sort function");
26 }
27 }
28 } // end of CaloCluster sort getter
29
31 const ConstituentsInputConfig& cfg,
32 const FTagOptions& options
33 ):
37 cfg.inputs, options))
38 {
39 m_used_remap = m_seqGetter.getUsedRemap();
40 m_name = cfg.name;
41 m_skipInvalidLinks = options.skip_invalid_links;
42 }
43
45 const xAOD::IParticle& jet
46 ) const
47 {
48 // Three-hop navigation for UFO jets:
49 // jet -> constituentLinks -> FlowElement (UFO)
50 // -> otherObjects() -> FlowElement (intermediate CSSK PFO)
51 // -> otherObjects() -> CaloCluster
52 // Two-hop navigation for PFlow jets (small-R):
53 // jet -> constituentLinks -> FlowElement (PFO)
54 // -> otherObjects() -> CaloCluster
55 // Dedup via unordered_set because UFO->cluster is many-to-many.
56 static const SG::AuxElement::ConstAccessor<PartLinks> acc("constituentLinks");
57
58 std::vector<std::pair<double, const xAOD::CaloCluster*>> clusters;
59 std::unordered_set<const xAOD::CaloCluster*> seen;
60
61 for (const ElementLink<IPC>& link : acc(jet)) {
62 if (!link.isValid()) {
63 if (m_skipInvalidLinks) { continue; }
64 throw std::logic_error("invalid constituentLink in CaloClusterLoader");
65 }
66 const auto* flow = dynamic_cast<const xAOD::FlowElement*>(*link);
67 if (!flow) {
68 continue;
69 }
70 // Second hop: FlowElement -> otherObjects()
71 for (const auto* other : flow->otherObjects()) {
72 if (!other) {
73 continue;
74 }
75 // PFlow path: `other` is already a CaloCluster.
76 if (const auto* cluster = dynamic_cast<const xAOD::CaloCluster*>(other)) {
77 if (seen.insert(cluster).second) {
78 clusters.push_back({m_caloClusterSortVar(cluster, jet), cluster});
79 }
80 continue;
81 }
82 // UFO path: `other` is an intermediate FlowElement
83 // (e.g. CSSKGParticleFlowObject). Recurse one more hop.
84 if (const auto* intermediate = dynamic_cast<const xAOD::FlowElement*>(other)) {
85 for (const auto* grandOther : intermediate->otherObjects()) {
86 if (!grandOther) { continue; }
87 const auto* cluster = dynamic_cast<const xAOD::CaloCluster*>(grandOther);
88 if (cluster && seen.insert(cluster).second) {
89 clusters.push_back({m_caloClusterSortVar(cluster, jet), cluster});
90 }
91 }
92 }
93 }
94 }
95
96 // Sort by pt descending
97 std::sort(clusters.begin(), clusters.end(), std::greater<>());
98
99 CaloClusters sorted_clusters;
100 sorted_clusters.reserve(clusters.size());
101 for (const auto& cl : clusters) {
102 sorted_clusters.push_back(cl.second);
103 }
104 return sorted_clusters;
105 }
106
108 CaloClusters sorted_clusters = getCaloClustersFromJet(jet);
109 return m_seqGetter.getFeats(jet, sorted_clusters);
110 }
111
115 const std::set<std::string>& CaloClusterLoader::getUsedRemap() const {
116 return m_used_remap;
117 }
118 const std::string& CaloClusterLoader::getName() const {
119 return m_name;
120 }
122 return m_config.type;
123 }
124
125}
Principal data class for CaloCell clusters.
CaloClusters getCaloClustersFromJet(const xAOD::IParticle &jet) const
Inputs getData(const xAOD::IParticle &jet) const override
getter_utils::SeqGetter< xAOD::CaloCluster > m_seqGetter
const std::string & getName() const override
CaloClusterSortVar caloClusterSortVar(ConstituentsSortOrder)
const FTagDataDependencyNames & getDependencies() const override
std::function< double(const xAOD::CaloCluster *, const Jet &)> CaloClusterSortVar
std::vector< const xAOD::CaloCluster * > CaloClusters
CaloClusterLoader(const ConstituentsInputConfig &cfg, const FTagOptions &options)
const ConstituentsType & getType() const override
const std::set< std::string > & getUsedRemap() const override
Class providing the definition of the 4-vector interface.
This file contains "getter" functions used for accessing tagger inputs from the EDM.
std::pair< std::vector< float >, std::vector< int64_t > > Inputs
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
FlowElement_v1 FlowElement
Definition of the current "pfo version".
Definition FlowElement.h:16