ATLAS Offline Software
Loading...
Searching...
No Matches
HyPERTtbarAllHadronicParser.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4#include <AsgMessaging/MessageCheck.h> // To access ANA_MSG
5
10
11namespace EventReco {
12// Build and add all ONNX inputs
14 HyPERModel& hyperModel) {
15
16 // Build edge input tensors
17 std::vector<std::vector<int64_t>> l_edge_index_ = {{}, {}};
18 std::vector<std::vector<float>> l_edge_attr_s_ = {};
19 for (std::size_t i = 0; i < static_cast<std::size_t>(hyperGraph.nEdges());
20 i++) {
21 l_edge_index_[0].push_back(
22 static_cast<int64_t>(hyperGraph.getEdgeIndicesVector()[i].first));
23 l_edge_index_[1].push_back(
24 static_cast<int64_t>(hyperGraph.getEdgeIndicesVector()[i].second));
25 l_edge_attr_s_.push_back(hyperGraph.getEdgeFeats(i));
26 }
27
28 m_edge_out_shape = std::vector<int64_t>{
29 static_cast<int64_t>(l_edge_index_[0].size()),
30 static_cast<int64_t>(
31 1)}; // Currently only support binary classification for edges
32 // Edege attributes tensor
37 // Edge indices tensor
42
43 // Build node input tensor
44 std::vector<std::vector<float>> l_x_s_ = {};
45 std::vector<int64_t> l_batch_ = {};
46 for (std::size_t i = 0; i < static_cast<std::size_t>(hyperGraph.nNodes());
47 i++) {
48 l_x_s_.push_back(hyperGraph.getNodeFeats(i));
49 l_batch_.push_back(static_cast<int64_t>(0));
50 }
51
52 // Node features tensor
54 hyperModel.setInputs<float>(m_l_x_s_name, m_l_x_s_, m_l_x_s_shape);
55 // Batch tensor
56 m_l_batch_shape = std::vector<int64_t>{static_cast<int64_t>(l_batch_.size())};
57 m_l_batch_ = l_batch_;
59
60 // Build global input tensor
61 std::vector<std::vector<float>> l_u_s_ = {hyperGraph.getGlobalFeats()};
63 hyperModel.setInputs<float>(m_l_u_s_name, m_l_u_s_, m_l_u_s_shape);
64
65 // Build hyperedge input tensor
66 std::vector<std::vector<int64_t>> l_edge_index_h_ = {};
67 std::vector<int64_t> l_edge_index_h_batch_ = {};
68 bool h_batch_filled = false;
69 for (std::size_t i = 0;
70 i < static_cast<std::size_t>(hyperGraph.hyperEdgeOrder()); i++) {
71 std::vector<int64_t> e_m = {};
72 for (std::size_t j = 0;
73 j < static_cast<std::size_t>(hyperGraph.nHyperEdges()); j++) {
74 if (!h_batch_filled) {
75 l_edge_index_h_batch_.push_back(static_cast<int64_t>(0));
76 }
77 e_m.push_back(hyperGraph.getHyperEdgeIndices(j)[i]);
78 }
79 l_edge_index_h_.push_back(e_m);
80 h_batch_filled = true;
81 }
82
83 m_hyperedge_out_shape = std::vector<int64_t>{
84 static_cast<int64_t>(l_edge_index_h_[0].size()),
85 static_cast<int64_t>(
86 1)}; // Currently only support binary classification for hyperedges
87 // Hyperedge indices tensor
92 // Hyperedge batch tensor
94 std::vector<int64_t>{static_cast<int64_t>(l_edge_index_h_batch_.size())};
95 m_l_edge_index_h_batch_ = l_edge_index_h_batch_;
96 hyperModel.setInputs<int64_t>(m_l_edge_index_h_batch_name,
99}
100
101// Get HyPER outputs
103
104 // Get model-specific output names
105 std::vector<std::string> outputNames = hyperModel.getOutputNames();
106
107 // Get model outputs
108 float* hyperedge_out = hyperModel.getOutputs<float>(outputNames[0]);
109 float* edge_out = hyperModel.getOutputs<float>(outputNames[1]);
110
114}
115
117 using namespace asg::msgUserCode;
118 setMsgLevel(MSG::INFO);
119 ANA_MSG_INFO("HYPEREDGE OUT:");
120 std::string row = "[";
121 for (const auto& i : m_hyperedge_out) {
122 for (const auto j : i) {
123 row += std::to_string(j) + ", ";
124 }
125 }
126 row += "],";
127 ANA_MSG_INFO(row);
128
129 ANA_MSG_INFO("EDGE OUT:");
130 row = "[";
131 for (const auto& i : m_edge_out) {
132 for (const auto j : i) {
133 row += std::to_string(j) + ", ";
134 }
135 }
136 row += "],";
137 ANA_MSG_INFO(row);
138}
139
140// Parser outputs
147
148// Clear the parser
150 m_edge_out_shape.clear();
151 m_hyperedge_out_shape.clear();
152 m_edge_out.clear();
153 m_hyperedge_out.clear();
154 m_reco_indices_out.clear();
155 m_reco_scores_out.clear();
156 m_reco_labels_out.clear();
157
158 m_l_edge_index_.clear();
159 m_l_edge_index_shape.clear();
160 m_l_edge_attr_s_.clear();
161 m_l_edge_attr_s_shape.clear();
162 m_l_x_s_.clear();
163 m_l_x_s_shape.clear();
164 m_l_batch_.clear();
165 m_l_batch_shape.clear();
166 m_l_edge_index_h_.clear();
170 m_l_u_s_.clear();
171 m_l_u_s_shape.clear();
172}
173
174} // namespace EventReco
macros for messaging and checking status codes
#define ANA_MSG_INFO(xmsg,...)
Macro printing info messages.
int64_t nNodes() const
Definition GraphBase.h:88
Features getEdgeFeats(std::size_t index) const
Definition GraphBase.h:80
Features getNodeFeats(std::size_t index) const
Definition GraphBase.h:74
Features getGlobalFeats() const
Definition GraphBase.h:83
int64_t nEdges() const
Definition GraphBase.h:89
int64_t hyperEdgeOrder() const
Definition HyPERGraph.h:42
const std::vector< EdgeIndex > & getEdgeIndicesVector() const
Definition HyPERGraph.h:35
int64_t nHyperEdges() const
Definition HyPERGraph.h:41
HyperEdgeIndex getHyperEdgeIndices(std::size_t index) const
Definition HyPERGraph.h:38
T * getOutputs(const std::string &node)
Pointer to the buffer of the named output.
Definition HyPERModel.h:224
virtual std::vector< std::string > getOutputNames() const =0
Model-specific output names consumed by the parser.
void setInputs(const std::string &node, std::vector< T > &values, const std::vector< int64_t > &shape)
Bind an input by node name.
Definition HyPERModel.h:138
std::vector< std::vector< int64_t > > m_reco_indices_out
std::vector< std::vector< float > > m_hyperedge_out
void getONNXOutputs(HyPERModel &hyperModel) override
This method takes the information from the onnxruntime object and builds the outputs on the parser ob...
std::vector< std::vector< float > > m_edge_out
void buildONNXInputs(const HyPERGraph &hyperGraph, HyPERModel &hyperModel) override
This method takes the information from the graph object and builds the inputs for the onnxruntime obj...
void clear() override
This method clears the parser object.
void reconstructOutputs(const HyPERGraph &hyperGraph) override
This method implements the reconstruction of the outputs from the parser object into physcally meanin...
void RecoTtbarAllHadronic(const HyPERGraph &hyperGraph, const scores &edge_scores, const scores &hyperedge_scores, indices &reco_indices, std::vector< float > &reco_scores, std::vector< std::string > &reco_labels)
Reconstruct the ttbar all hadronic topology.
void flatTensorAndSetShape(const std::vector< std::vector< T > > &input, std::vector< T > &flatTensor, std::vector< int64_t > &shape)
Definition HyPERUtils.h:101
std::vector< std::vector< T > > convertONNXOutput(T *onnxOutput, const std::vector< int64_t > &shape)
Definition HyPERUtils.h:85