ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
Algorithms
EventReconstruction
HyPERAnalysisAlgorithms
src
HyPERGraph.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
6
#include <string>
7
8
#include "
HyPERAnalysisAlgorithms/GraphBase.h
"
9
10
#include "
HyPERAnalysisAlgorithms/HyPERGraph.h
"
11
#include "
HyPERAnalysisAlgorithms/HyPERUtils.h
"
12
13
namespace
EventReco
{
14
void
HyPERGraph::addNode
(
const
Features
& attributes) {
15
m_nodes
.emplace_back(attributes,
m_nNodes
);
16
m_nNodes
+= 1;
17
}
18
19
void
HyPERGraph::addEdge
(int64_t source, int64_t target,
20
const
Features
& attributes) {
21
m_edges
.emplace_back(source, target, attributes);
22
m_nEdges
+= 1;
23
}
24
25
void
HyPERGraph::addGlobal
(
const
Features
& attributes) {
26
m_global
=
EventReco::Global
(attributes);
27
}
28
29
void
HyPERGraph::buildEdgeIndices
() {
30
if
(
m_nNodes
< 2) {
31
return
;
// There are no edges when the number of nodes is less than 2.
32
}
33
std::vector<int64_t> edgeIndices =
range
(
m_nNodes
);
34
for
(
const
auto
& index1 : edgeIndices) {
35
for
(
const
auto
& index2 : edgeIndices) {
36
if
(index1 != index2)
37
m_edgeIndices
.push_back(std::make_pair(index1, index2));
38
}
39
}
40
}
41
42
void
HyPERGraph::buildHyperEdges
(int64_t order) {
43
m_hyperEdgeOrder
= order;
44
if
(
m_nNodes
< order) {
45
return
;
// There are no hyperedges when the number of nodes is less than
46
// the hyperedge order.
47
}
48
std::vector<int64_t> edgeIndices =
range
(
m_nNodes
);
49
m_hyperEdgeIndices
=
buildCombinations
(edgeIndices, order);
50
m_nHyperEdges
=
m_hyperEdgeIndices
.size();
51
}
52
53
void
HyPERGraph::printGraph
()
const
{
54
using namespace
asg::msgUserCode;
55
setMsgLevel(MSG::INFO);
56
ANA_MSG_INFO
(
"Printing graph..."
);
57
// Print the nodes
58
for
(
const
auto
&
node
:
m_nodes
) {
59
ANA_MSG_INFO
(
"Node Index: "
<<
node
.getNodeIndex());
60
for
(
const
auto
& feat :
node
.getFeatures()) {
61
ANA_MSG_INFO
(
"Feature: "
<< feat);
62
}
63
}
64
// Print the edges
65
for
(
const
auto
& edge :
m_edges
) {
66
ANA_MSG_INFO
(
"Edge Index: "
<< edge.getIndices().first <<
" -> "
67
<< edge.getIndices().second);
68
for
(
const
auto
& feat : edge.getFeatures()) {
69
ANA_MSG_INFO
(
"Feature: "
<< feat);
70
}
71
}
72
// Print the global
73
ANA_MSG_INFO
(
"Global Features: "
);
74
for
(
const
auto
& feat :
m_global
.getFeatures()) {
75
ANA_MSG_INFO
(
"Feature: "
<< feat);
76
}
77
// Print the hyperedges
78
for
(
const
auto
& hyperEdge :
m_hyperEdgeIndices
) {
79
std::string
indices
{
""
};
80
for
(
const
auto
&
index
: hyperEdge) {
81
indices
+= std::to_string(
index
) +
" "
;
82
}
83
ANA_MSG_INFO
(
"HyperEdge indices: "
<<
indices
);
84
}
85
ANA_MSG_INFO
(
"Finished graph printing..."
);
86
}
87
88
void
HyPERGraph::printGraphInputsForValidation
()
const
{
89
using namespace
asg::msgUserCode;
90
setMsgLevel(MSG::INFO);
91
ANA_MSG_INFO
(
"Printing graph inputs in validation mode..."
);
92
93
// Print the nodes
94
ANA_MSG_INFO
(
"NODES:"
);
95
for
(
const
auto
&
node
:
m_nodes
) {
96
std::string row =
"["
;
97
for
(
const
auto
& feat :
node
.getFeatures()) {
98
row += std::to_string(feat) +
", "
;
99
}
100
row +=
"],"
;
101
ANA_MSG_INFO
(row);
102
}
103
// Print the edges
104
ANA_MSG_INFO
(
"EDGES:"
);
105
for
(
const
auto
& edge :
m_edges
) {
106
std::string row =
"["
;
107
for
(
const
auto
& feat : edge.getFeatures()) {
108
row += std::to_string(feat) +
", "
;
109
}
110
row +=
"],"
;
111
ANA_MSG_INFO
(row);
112
}
113
// Print the edge indices
114
ANA_MSG_INFO
(
"EDGE INDICES:"
);
115
std::string row1 =
"["
;
116
std::string row2 =
"["
;
117
for
(
const
auto
& edge :
m_edges
) {
118
row1 += std::to_string(edge.getIndices().first) +
", "
;
119
row2 += std::to_string(edge.getIndices().second) +
", "
;
120
}
121
row1 +=
"],"
;
122
row2 +=
"],"
;
123
ANA_MSG_INFO
(row1);
124
ANA_MSG_INFO
(row2);
125
// Print the globals
126
ANA_MSG_INFO
(
"GLOBAL:"
);
127
std::string row =
"[["
;
128
for
(
const
auto
& feat :
m_global
.getFeatures()) {
129
row += std::to_string(feat) +
", "
;
130
}
131
row +=
"]],"
;
132
ANA_MSG_INFO
(row);
133
// Print batch
134
ANA_MSG_INFO
(
"BATCH:"
);
135
row =
"[["
;
136
for
(
auto
i{0}; i < this->
nNodes
(); i++) {
137
row +=
"0, "
;
138
}
139
row +=
"]],"
;
140
ANA_MSG_INFO
(row);
141
// Print the hyperedges
142
ANA_MSG_INFO
(
"HYPEREDGE INDICES:"
);
143
std::vector<std::string> rows(this->
hyperEdgeOrder
());
144
for
(
auto
i{0}; i < this->
hyperEdgeOrder
(); i++) {
145
rows[i] =
"["
;
146
}
147
for
(
const
auto
& hyperEdge :
m_hyperEdgeIndices
) {
148
for
(
auto
i{0}; i < this->
hyperEdgeOrder
(); i++) {
149
rows[i] += std::to_string(hyperEdge[i]) +
", "
;
150
}
151
}
152
for
(
auto
i{0}; i < this->
hyperEdgeOrder
(); i++) {
153
rows[i] +=
"],"
;
154
ANA_MSG_INFO
(rows[i]);
155
}
156
// Print batch hyperedges
157
ANA_MSG_INFO
(
"BATCH HYPEREDGES:"
);
158
row =
"[["
;
159
for
(
auto
i{0}; i < this->
nHyperEdges
(); i++) {
160
row +=
"0, "
;
161
}
162
row +=
"]],"
;
163
ANA_MSG_INFO
(row);
164
165
ANA_MSG_INFO
(
"Finished printing graph inputs for validation..."
);
166
}
167
168
void
HyPERGraph::clearGraph
() {
169
m_nNodes
= 0;
170
m_nEdges
= 0;
171
m_nodes
.clear();
172
m_edges
.clear();
173
m_global
= {};
174
m_edgeIndices
= {};
175
m_hyperEdgeIndices
= {};
176
m_hyperEdgeOrder
= 0;
177
m_nHyperEdges
= 0;
178
}
179
180
}
// namespace EventReco
MessageCheck.h
macros for messaging and checking status codes
ANA_MSG_INFO
#define ANA_MSG_INFO(xmsg,...)
Macro printing info messages.
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:291
GraphBase.h
HyPERGraph.h
indices
std::vector< std::vector< int64_t > > indices
Definition
HyPERTopoReco.h:16
HyPERUtils.h
EventReco::Global
Definition
GraphBase.h:50
EventReco::GraphBase::m_nEdges
int64_t m_nEdges
Definition
GraphBase.h:97
EventReco::GraphBase::m_nodes
std::vector< Node > m_nodes
Definition
GraphBase.h:94
EventReco::GraphBase::nNodes
int64_t nNodes() const
Definition
GraphBase.h:88
EventReco::GraphBase::m_edges
std::vector< Edge > m_edges
Definition
GraphBase.h:95
EventReco::GraphBase::m_nNodes
int64_t m_nNodes
Definition
GraphBase.h:96
EventReco::GraphBase::m_global
Global m_global
Definition
GraphBase.h:93
EventReco::HyPERGraph::m_edgeIndices
std::vector< EdgeIndex > m_edgeIndices
Definition
HyPERGraph.h:49
EventReco::HyPERGraph::m_nHyperEdges
int64_t m_nHyperEdges
Definition
HyPERGraph.h:51
EventReco::HyPERGraph::hyperEdgeOrder
int64_t hyperEdgeOrder() const
Definition
HyPERGraph.h:42
EventReco::HyPERGraph::m_hyperEdgeIndices
std::vector< HyperEdgeIndex > m_hyperEdgeIndices
Definition
HyPERGraph.h:50
EventReco::HyPERGraph::clearGraph
virtual void clearGraph()
Definition
HyPERGraph.cxx:168
EventReco::HyPERGraph::addNode
virtual void addNode(const Features &attributes) override
Definition
HyPERGraph.cxx:14
EventReco::HyPERGraph::m_hyperEdgeOrder
int64_t m_hyperEdgeOrder
Definition
HyPERGraph.h:52
EventReco::HyPERGraph::addEdge
virtual void addEdge(int64_t source, int64_t target, const Features &attributes) override
Definition
HyPERGraph.cxx:19
EventReco::HyPERGraph::nHyperEdges
int64_t nHyperEdges() const
Definition
HyPERGraph.h:41
EventReco::HyPERGraph::buildHyperEdges
void buildHyperEdges(int64_t order)
Definition
HyPERGraph.cxx:42
EventReco::HyPERGraph::printGraphInputsForValidation
virtual void printGraphInputsForValidation() const
Definition
HyPERGraph.cxx:88
EventReco::HyPERGraph::buildEdgeIndices
void buildEdgeIndices()
Definition
HyPERGraph.cxx:29
EventReco::HyPERGraph::printGraph
virtual void printGraph() const
Definition
HyPERGraph.cxx:53
EventReco::HyPERGraph::addGlobal
virtual void addGlobal(const Features &attributes) override
Definition
HyPERGraph.cxx:25
node
Definition
node.h:24
EventReco
Definition
GraphBase.h:14
EventReco::buildCombinations
std::vector< std::vector< T > > buildCombinations(const std::vector< T > &elements, int64_t hyperEdgeOrder)
Definition
HyPERUtils.h:48
EventReco::Features
std::vector< float > Features
Definition
GraphBase.h:16
EventReco::range
std::vector< int64_t > range(int64_t n)
Definition
HyPERUtils.cxx:29
index
Definition
index.py:1
Generated on
for ATLAS Offline Software by
1.17.0