ATLAS Offline Software
Classes | Public Member Functions | Public Attributes | Private Types | Private Member Functions | Private Attributes | List of all members
InDetGNNHardScatterSelection::GNN Class Reference

#include <GNN.h>

Collaboration diagram for InDetGNNHardScatterSelection::GNN:

Classes

struct  Decorators
 

Public Member Functions

 GNN (const std::string &nnFile)
 
 GNN (GNN &&)
 
 GNN (const GNN &)
 
virtual ~GNN ()
 
virtual void decorate (const xAOD::Vertex &verrtex) const
 

Public Attributes

std::shared_ptr< const FlavorTagDiscriminants::OnnxUtil > m_onnxUtil
 

Private Types

using TPC = xAOD::TrackParticleContainer
 
using TrackLinks = std::vector< ElementLink< TPC > >
 
template<typename T >
using Dec = SG::AuxElement::Decorator< T >
 
template<typename T >
using Decs = std::vector< std::pair< std::string, Dec< T > >>
 

Private Member Functions

std::set< std::string > createDecorators (const FlavorTagDiscriminants::OnnxUtil::OutputConfig &outConfig)
 

Private Attributes

std::string m_input_node_name
 
std::vector< internal::VarFromVertexm_varsFromVertex
 
std::vector< std::shared_ptr< IConstituentsLoader > > m_constituentsLoaders
 
Decorators m_decorators
 
float m_defaultValue
 

Detailed Description

Implementation of the GNN used by the InDetGNNHardScatterSelection::GNNTool

NOTE: The GNN relies on decorations added in InDetGNNHardScatterSelection::VertexDecoratorAlg and as such should only be called from within that algorithm

Author
Jackson Burzynski jacks.nosp@m.on.c.nosp@m.arl.b.nosp@m.urzy.nosp@m.nski@.nosp@m.cern.nosp@m..ch

Definition at line 42 of file InnerDetector/InDetRecTools/InDetGNNHardScatterSelection/InDetGNNHardScatterSelection/GNN.h.

Member Typedef Documentation

◆ Dec

template<typename T >
using InDetGNNHardScatterSelection::GNN::Dec = SG::AuxElement::Decorator<T>
private

◆ Decs

template<typename T >
using InDetGNNHardScatterSelection::GNN::Decs = std::vector<std::pair<std::string, Dec<T> >>
private

◆ TPC

◆ TrackLinks

Constructor & Destructor Documentation

◆ GNN() [1/3]

InDetGNNHardScatterSelection::GNN::GNN ( const std::string &  nnFile)

Definition at line 21 of file InnerDetector/InDetRecTools/InDetGNNHardScatterSelection/Root/GNN.cxx.

21  :
22  m_onnxUtil(nullptr)
23  {
24 
25  // Load and initialize the neural network model from the given file path.
26  std::string fullPathToOnnxFile = PathResolverFindCalibFile(nn_file);
27  m_onnxUtil = std::make_shared<FlavorTagDiscriminants::OnnxUtil>(fullPathToOnnxFile);
28 
29  // Extract metadata from the ONNX file, primarily about the model's inputs.
30  auto lwt_config = m_onnxUtil->getLwtConfig();
31 
32  // Create configuration objects for data preprocessing.
33  auto [inputs, constituents_configs] = dataprep::createGetterConfig(lwt_config);
34 
35  for (auto config : constituents_configs){
36  switch (config.type){
38  m_constituentsLoaders.push_back(std::make_shared<TracksLoader>(config));
39  break;
41  m_constituentsLoaders.push_back(std::make_shared<ElectronsLoader>(config));
42  break;
44  m_constituentsLoaders.push_back(std::make_shared<MuonsLoader>(config));
45  break;
47  m_constituentsLoaders.push_back(std::make_shared<JetsLoader>(config));
48  break;
50  m_constituentsLoaders.push_back(std::make_shared<PhotonsLoader>(config));
51  break;
53  m_constituentsLoaders.push_back(std::make_shared<IParticlesLoader>(config));
54  break;
55  }
56  }
57 
59 
60  // Retrieve the configuration for the model outputs.
61  FlavorTagDiscriminants::OnnxUtil::OutputConfig gnn_output_config = m_onnxUtil->getOutputConfig();
62 
63  for (const auto& outNode : gnn_output_config) {
64  // the node's output name will be used to define the decoration name
65  std::string dec_name = outNode.name;
66  m_decorators.vertexFloat.emplace_back(outNode.name, Dec<float>(dec_name));
67  }
68  }

◆ GNN() [2/3]

InDetGNNHardScatterSelection::GNN::GNN ( GNN &&  )
default

◆ GNN() [3/3]

InDetGNNHardScatterSelection::GNN::GNN ( const GNN )
default

◆ ~GNN()

InDetGNNHardScatterSelection::GNN::~GNN ( )
virtualdefault

Member Function Documentation

◆ createDecorators()

std::set<std::string> InDetGNNHardScatterSelection::GNN::createDecorators ( const FlavorTagDiscriminants::OnnxUtil::OutputConfig &  outConfig)
private

◆ decorate()

void InDetGNNHardScatterSelection::GNN::decorate ( const xAOD::Vertex verrtex) const
virtual

Definition at line 74 of file InnerDetector/InDetRecTools/InDetGNNHardScatterSelection/Root/GNN.cxx.

74  {
75  /* Main function for decorating a vertex with GNN outputs. */
76  using namespace internal;
77 
78  // prepare input
79  // -------------
80  std::map<std::string, FlavorTagDiscriminants::Inputs> gnn_input;
81 
82  std::vector<float> vertex_feat;
83  for (const auto& getter: m_varsFromVertex) {
84  vertex_feat.push_back(getter(vertex).second);
85  }
86  std::vector<int64_t> vertexfeat_dim = {1, static_cast<int64_t>(vertex_feat.size())};
87 
88  FlavorTagDiscriminants::Inputs vertex_info (vertex_feat, vertexfeat_dim);
89  gnn_input.insert({"vertex_features", vertex_info});
90 
91  for (auto loader : m_constituentsLoaders){
92  auto [sequence_name, sequence_data, sequence_constituents] = loader->getData(vertex);
93  gnn_input.insert({sequence_name, sequence_data});
94  }
95 
96  // run inference
97  // -------------
98  auto [out_f, out_vc, out_vf] = m_onnxUtil->runInference(gnn_input);
99 
100  // decorate outputs
101  // ----------------
102  for (const auto& dec: m_decorators.vertexFloat) {
103  dec.second(vertex) = out_f.at(dec.first);
104  }
105  } // end of decorate()

Member Data Documentation

◆ m_constituentsLoaders

std::vector<std::shared_ptr<IConstituentsLoader> > InDetGNNHardScatterSelection::GNN::m_constituentsLoaders
private

◆ m_decorators

Decorators InDetGNNHardScatterSelection::GNN::m_decorators
private

◆ m_defaultValue

float InDetGNNHardScatterSelection::GNN::m_defaultValue
private

◆ m_input_node_name

std::string InDetGNNHardScatterSelection::GNN::m_input_node_name
private

◆ m_onnxUtil

std::shared_ptr<const FlavorTagDiscriminants::OnnxUtil> InDetGNNHardScatterSelection::GNN::m_onnxUtil

◆ m_varsFromVertex

std::vector<internal::VarFromVertex> InDetGNNHardScatterSelection::GNN::m_varsFromVertex
private

The documentation for this class was generated from the following files:
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
InDetGNNHardScatterSelection::GNN::m_decorators
Decorators m_decorators
Definition: InnerDetector/InDetRecTools/InDetGNNHardScatterSelection/InDetGNNHardScatterSelection/GNN.h:75
FlavorTagDiscriminants::Inputs
std::pair< std::vector< float >, std::vector< int64_t > > Inputs
Definition: FlavorTagDiscriminants/FlavorTagDiscriminants/OnnxUtil.h:28
InDetGNNHardScatterSelection::dataprep::createGetterConfig
std::tuple< std::vector< HSGNNInputConfig >, std::vector< ConstituentsInputConfig > > createGetterConfig(lwt::GraphConfig &graph_config)
Definition: InnerDetector/InDetRecTools/InDetGNNHardScatterSelection/Root/DataPrepUtilities.cxx:118
postInclude.inputs
inputs
Definition: postInclude.SortInput.py:15
InDetGNNHardScatterSelection::ConstituentsType::PHOTON
@ PHOTON
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
InDetGNNHardScatterSelection::ConstituentsType::TRACK
@ TRACK
InDetGNNHardScatterSelection::dataprep::createVertexVarGetters
std::vector< internal::VarFromVertex > createVertexVarGetters(const std::vector< HSGNNInputConfig > &inputs)
Definition: InnerDetector/InDetRecTools/InDetGNNHardScatterSelection/Root/DataPrepUtilities.cxx:168
InDetGNNHardScatterSelection::ConstituentsType::ELECTRON
@ ELECTRON
InDetGNNHardScatterSelection::ConstituentsType::JET
@ JET
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
InDetGNNHardScatterSelection::ConstituentsType::MUON
@ MUON
InDetGNNHardScatterSelection::ConstituentsType::IPARTICLE
@ IPARTICLE
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
InDetGNNHardScatterSelection::GNN::m_onnxUtil
std::shared_ptr< const FlavorTagDiscriminants::OnnxUtil > m_onnxUtil
Definition: InnerDetector/InDetRecTools/InDetGNNHardScatterSelection/InDetGNNHardScatterSelection/GNN.h:52
InDetGNNHardScatterSelection::GNN::Decorators::vertexFloat
Decs< float > vertexFloat
Definition: InnerDetector/InDetRecTools/InDetGNNHardScatterSelection/InDetGNNHardScatterSelection/GNN.h:65
InDetGNNHardScatterSelection::GNN::m_constituentsLoaders
std::vector< std::shared_ptr< IConstituentsLoader > > m_constituentsLoaders
Definition: InnerDetector/InDetRecTools/InDetGNNHardScatterSelection/InDetGNNHardScatterSelection/GNN.h:73
InDetGNNHardScatterSelection::GNN::m_varsFromVertex
std::vector< internal::VarFromVertex > m_varsFromVertex
Definition: InnerDetector/InDetRecTools/InDetGNNHardScatterSelection/InDetGNNHardScatterSelection/GNN.h:72