ATLAS Offline Software
MultifoldGNN.cxx
Go to the documentation of this file.
1 /*
2 + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 
9 #include "xAODJet/JetContainer.h"
10 
11 namespace {
12  const std::string jetLinkName = "jetLink";
13  template<typename T, typename C>
14  std::set<std::string> merged(T get, const C& c) {
15  auto first = get(*c.at(0));
16  for (size_t idx = 1; idx < c.size(); idx++) {
17  if (get(*c.at(idx)) != first) {
18  throw std::runtime_error("inconsistent dependencies in folds");
19  }
20  }
21  return first;
22  }
23  auto getNNs(
24  const std::vector<std::string>& nn_files,
26  {
27  namespace ftd = FlavorTagDiscriminants;
28  std::vector<std::shared_ptr<const ftd::GNN>> nns;
29  for (const auto& nn_file: nn_files) {
30  nns.emplace_back(std::make_shared<const ftd::GNN>(nn_file, o));
31  }
32  return nns;
33  }
34 }
35 
36 namespace FlavorTagDiscriminants {
37 
39  const std::vector<std::string>& nn_files,
40  const std::string& fold_hash_name,
41  const GNNOptions& o):
42  MultifoldGNN(getNNs(nn_files, o), fold_hash_name)
43  {
44  }
46  const std::vector<std::shared_ptr<const GNN>>& nns,
47  const std::string& fold_hash_name):
48  m_folds(nns),
49  m_fold_hash(fold_hash_name),
50  m_jetLink(jetLinkName)
51  {
52  }
54  MultifoldGNN::MultifoldGNN(const MultifoldGNN&) = default;
55  MultifoldGNN::~MultifoldGNN() = default;
56 
57  void MultifoldGNN::decorate(const xAOD::BTagging& btag) const {
58  getFold(**m_jetLink(btag)).decorate(btag);
59  }
60  void MultifoldGNN::decorate(const xAOD::Jet& jet) const {
62  }
65  }
67  getFold(**m_jetLink(btag)).decorateWithDefaults(btag);
68  }
69 
70  // Dependencies
71  std::set<std::string> MultifoldGNN::getDecoratorKeys() const {
72  return merged([](const auto& f){ return f.getDecoratorKeys(); }, m_folds);
73  }
74  std::set<std::string> MultifoldGNN::getAuxInputKeys() const {
75  return merged([](const auto& f){ return f.getAuxInputKeys(); }, m_folds);
76  }
77  std::set<std::string> MultifoldGNN::getConstituentAuxInputKeys() const {
78  return merged([](const auto& f){ return f.getConstituentAuxInputKeys(); }, m_folds);
79  }
80 
81  const GNN& MultifoldGNN::getFold(const SG::AuxElement& element) const {
82  return *m_folds.at(m_fold_hash(element) % m_folds.size());
83  }
84 
85 
86 }
BTagging.h
FlavorTagDiscriminants
This file contains "getter" functions used for accessing tagger inputs from the EDM.
Definition: AssociationEnums.h:11
FlavorTagDiscriminants::GNNOptions
Definition: GNNOptions.h:16
SG::AuxElement
Base class for elements of a container that can have aux data.
Definition: AuxElement.h:472
DMTest::C
C_v1 C
Definition: C.h:26
BTaggingConfigFlags.getNNs
def getNNs(flags)
Definition: BTaggingConfigFlags.py:78
FlavorTagDiscriminants::MultifoldGNN::decorate
void decorate(const xAOD::BTagging &btag) const
Definition: MultifoldGNN.cxx:57
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
FlavorTagDiscriminants::MultifoldGNN::m_jetLink
SG::AuxElement::ConstAccessor< ElementLink< xAOD::JetContainer > > m_jetLink
Definition: MultifoldGNN.h:44
FlavorTagDiscriminants::MultifoldGNN::m_folds
std::vector< std::shared_ptr< const GNN > > m_folds
Definition: MultifoldGNN.h:42
FlavorTagDiscriminants::MultifoldGNN::getDecoratorKeys
std::set< std::string > getDecoratorKeys() const
Definition: MultifoldGNN.cxx:71
FlavorTagDiscriminants::MultifoldGNN::getConstituentAuxInputKeys
std::set< std::string > getConstituentAuxInputKeys() const
Definition: MultifoldGNN.cxx:77
hist_file_dump.f
f
Definition: hist_file_dump.py:135
xAOD::BTagging_v1
Definition: BTagging_v1.h:39
FlavorTagDiscriminants::MultifoldGNN::m_fold_hash
SG::AuxElement::ConstAccessor< uint32_t > m_fold_hash
Definition: MultifoldGNN.h:43
MultifoldGNN.h
FlavorTagDiscriminants::MultifoldGNN::getFold
const GNN & getFold(const SG::AuxElement &element) const
Definition: MultifoldGNN.cxx:81
FlavorTagDiscriminants::MultifoldGNN::~MultifoldGNN
~MultifoldGNN()
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
FlavorTagDiscriminants::GNN
Definition: PhysicsAnalysis/JetTagging/FlavorTagDiscriminants/FlavorTagDiscriminants/GNN.h:40
FlavorTagDiscriminants::GNN::decorateWithDefaults
virtual void decorateWithDefaults(const SG::AuxElement &jet) const
Definition: PhysicsAnalysis/JetTagging/FlavorTagDiscriminants/Root/GNN.cxx:136
JetContainer.h
FlavorTagDiscriminants::MultifoldGNN::decorateWithDefaults
void decorateWithDefaults(const SG::AuxElement &jet) const
Definition: MultifoldGNN.cxx:63
DeMoScan.first
bool first
Definition: DeMoScan.py:536
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
GNN.h
FlavorTagDiscriminants::MultifoldGNN
Definition: MultifoldGNN.h:22
FlavorTagDiscriminants::MultifoldGNN::MultifoldGNN
MultifoldGNN(const std::vector< std::string > &folds, const std::string &fold_hash_name, const GNNOptions &opts)
Definition: MultifoldGNN.cxx:38
FlavorTagDiscriminants::MultifoldGNN::getAuxInputKeys
std::set< std::string > getAuxInputKeys() const
Definition: MultifoldGNN.cxx:74
python.compressB64.c
def c
Definition: compressB64.py:93
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
FlavorTagDiscriminants::GNN::decorate
virtual void decorate(const xAOD::BTagging &btag) const
Definition: PhysicsAnalysis/JetTagging/FlavorTagDiscriminants/Root/GNN.cxx:121