ATLAS Offline Software
Loading...
Searching...
No Matches
HyPERTtbarDiLeptonParser.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 float* classification_out = hyperModel.getOutputs<float>(outputNames[2]);
111
117}
118
120 using namespace asg::msgUserCode;
121 setMsgLevel(MSG::INFO);
122 ANA_MSG_INFO("HYPEREDGE OUT:");
123 std::string row = "[";
124 for (const auto& i : m_hyperedge_out) {
125 for (const auto j : i) {
126 row += std::to_string(j) + ", ";
127 }
128 }
129 row += "],";
130 ANA_MSG_INFO(row);
131
132 ANA_MSG_INFO("EDGE OUT:");
133 row = "[";
134 for (const auto& i : m_edge_out) {
135 for (const auto j : i) {
136 row += std::to_string(j) + ", ";
137 }
138 }
139 row += "],";
140 ANA_MSG_INFO(row);
141
142 ANA_MSG_INFO("CLASSIFICATION OUT:");
144}
145
146// Parser outputs
153
154// Clear the parser
156 m_edge_out_shape.clear();
157 m_hyperedge_out_shape.clear();
158 m_edge_out.clear();
159 m_hyperedge_out.clear();
160 m_reco_indices_out.clear();
161 m_reco_scores_out.clear();
162 m_reco_labels_out.clear();
163 m_reco_ids_out.clear();
164 m_classification_out.clear();
166
167 m_l_edge_index_.clear();
168 m_l_edge_index_shape.clear();
169 m_l_edge_attr_s_.clear();
170 m_l_edge_attr_s_shape.clear();
171 m_l_x_s_.clear();
172 m_l_x_s_shape.clear();
173 m_l_batch_.clear();
174 m_l_batch_shape.clear();
175 m_l_edge_index_h_.clear();
179 m_l_u_s_.clear();
180 m_l_u_s_shape.clear();
181}
182
183} // 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
virtual void printOutputsForValidation() const override
std::vector< std::vector< int64_t > > m_reco_ids_out
std::vector< std::vector< int64_t > > m_reco_indices_out
void clear() override
This method clears the parser object.
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 reconstructOutputs(const HyPERGraph &hyperGraph) override
This method implements the reconstruction of the outputs from the parser object into physcally meanin...
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_classification_out
std::vector< std::vector< float > > m_hyperedge_out
std::vector< std::vector< float > > m_edge_out
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
void RecoTtbarDiLepton(const HyPERGraph &hyperGraph, const scores &edge_scores, const scores &hyperedge_scores, const scores &classification_score, indices &reco_indices, std::vector< float > &reco_scores, std::vector< std::string > &reco_labels, std::vector< std::vector< int64_t > > &reco_ids, float &reco_classification_score)
Reconstruct the ttbar single lepton topology.