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  }
64  // note that the default values should be identical betwen all folds
65  m_folds.at(0)->decorateWithDefaults(jet);
66  }
67 
68  // Dependencies
69  std::set<std::string> MultifoldGNN::getDecoratorKeys() const {
70  return merged([](const auto& f){ return f.getDecoratorKeys(); }, m_folds);
71  }
72  std::set<std::string> MultifoldGNN::getAuxInputKeys() const {
73  return merged([](const auto& f){ return f.getAuxInputKeys(); }, m_folds);
74  }
75  std::set<std::string> MultifoldGNN::getConstituentAuxInputKeys() const {
76  return merged([](const auto& f){ return f.getConstituentAuxInputKeys(); }, m_folds);
77  }
78 
79  const GNN& MultifoldGNN::getFold(const SG::AuxElement& element) const {
80  return *m_folds.at(m_fold_hash(element) % m_folds.size());
81  }
82 
83 
84 }
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
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:446
DMTest::C
C_v1 C
Definition: C.h:26
BTaggingConfigFlags.getNNs
def getNNs(flags)
Definition: BTaggingConfigFlags.py:76
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:43
FlavorTagDiscriminants::MultifoldGNN::m_folds
std::vector< std::shared_ptr< const GNN > > m_folds
Definition: MultifoldGNN.h:41
FlavorTagDiscriminants::MultifoldGNN::getDecoratorKeys
std::set< std::string > getDecoratorKeys() const
Definition: MultifoldGNN.cxx:69
FlavorTagDiscriminants::MultifoldGNN::getConstituentAuxInputKeys
std::set< std::string > getConstituentAuxInputKeys() const
Definition: MultifoldGNN.cxx:75
xAOD::BTagging_v1
Definition: BTagging_v1.h:39
FlavorTagDiscriminants::MultifoldGNN::m_fold_hash
SG::AuxElement::ConstAccessor< uint32_t > m_fold_hash
Definition: MultifoldGNN.h:42
MultifoldGNN.h
GNN.h
FlavorTagDiscriminants::MultifoldGNN::getFold
const GNN & getFold(const SG::AuxElement &element) const
Definition: MultifoldGNN.cxx:79
FlavorTagDiscriminants::MultifoldGNN::~MultifoldGNN
~MultifoldGNN()
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
FlavorTagDiscriminants::GNN
Definition: GNN.h:40
JetContainer.h
FlavorTagDiscriminants::MultifoldGNN::decorateWithDefaults
void decorateWithDefaults(const SG::AuxElement &jet) const
Definition: MultifoldGNN.cxx:63
DeMoScan.first
bool first
Definition: DeMoScan.py:534
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
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:72
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: GNN.cxx:94