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