ATLAS Offline Software
Loading...
Searching...
No Matches
FPGATrackSimGNNEdgeClassifierTool Class Reference

#include <FPGATrackSimGNNEdgeClassifierTool.h>

Inheritance diagram for FPGATrackSimGNNEdgeClassifierTool:
Collaboration diagram for FPGATrackSimGNNEdgeClassifierTool:

Public Member Functions

 FPGATrackSimGNNEdgeClassifierTool (const std::string &, const std::string &, const IInterface *)
virtual StatusCode initialize () override
virtual StatusCode scoreEdges (const std::vector< std::shared_ptr< FPGATrackSimGNNHit > > &hits, std::vector< std::shared_ptr< FPGATrackSimGNNEdge > > &edges)
int regionNum () const
ServiceHandle< StoreGateSvc > & evtStore ()
 The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
const ServiceHandle< StoreGateSvc > & detStore () const
 The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
virtual StatusCode sysInitialize () override
 Perform system initialization for an algorithm.
virtual StatusCode sysStart () override
 Handle START transition.
virtual std::vector< Gaudi::DataHandle * > inputHandles () const override
 Return this algorithm's input handles.
virtual std::vector< Gaudi::DataHandle * > outputHandles () const override
 Return this algorithm's output handles.
Gaudi::Details::PropertyBase & declareProperty (Gaudi::Property< T, V, H > &t)
void updateVHKA (Gaudi::Details::PropertyBase &)
MsgStream & msg () const
bool msgLvl (const MSG::Level lvl) const

Protected Member Functions

void renounceArray (SG::VarHandleKeyArray &handlesArray)
 remove all handles from I/O resolution
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce (T &h)
void extraDeps_update_handler (Gaudi::Details::PropertyBase &ExtraDeps)
 Add StoreName to extra input/output deps as needed.

Private Types

typedef ServiceHandle< StoreGateSvcStoreGateSvc_t

Private Member Functions

std::vector< float > getNodeFeatures (const std::vector< std::shared_ptr< FPGATrackSimGNNHit > > &hits)
std::vector< int64_t > getEdgeList (const std::vector< std::shared_ptr< FPGATrackSimGNNEdge > > &edges)
std::vector< float > getEdgeFeatures (std::vector< std::shared_ptr< FPGATrackSimGNNEdge > > &edges, const std::vector< float > &gNodeFeatures)
void computeEdgeFeatures (std::shared_ptr< FPGATrackSimGNNEdge > &edge, const int &hit1_index, const int &hit2_index, const std::vector< float > &gNodeFeatures)
Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
 specialization for handling Gaudi::Property<SG::VarHandleKey>

Private Attributes

ToolHandle< AthOnnx::IOnnxRuntimeInferenceToolm_GNNInferenceTool {this, "GNNInferenceTool", "AthOnnx::OnnxRuntimeInferenceTool"}
Gaudi::Property< int > m_regionNum {this, "regionNum", -1, "Region number for this GNNEdgeClassifierTool"}
StringArrayProperty m_gnnFeatureNamesVec
FloatArrayProperty m_gnnFeatureScalesVec
StoreGateSvc_t m_evtStore
 Pointer to StoreGate (event store by default)
StoreGateSvc_t m_detStore
 Pointer to StoreGate (detector store by default)
std::vector< SG::VarHandleKeyArray * > m_vhka
bool m_varHandleArraysDeclared

Detailed Description

Definition at line 25 of file FPGATrackSimGNNEdgeClassifierTool.h.

Member Typedef Documentation

◆ StoreGateSvc_t

typedef ServiceHandle<StoreGateSvc> AthCommonDataStore< AthCommonMsg< AlgTool > >::StoreGateSvc_t
privateinherited

Definition at line 388 of file AthCommonDataStore.h.

Constructor & Destructor Documentation

◆ FPGATrackSimGNNEdgeClassifierTool()

FPGATrackSimGNNEdgeClassifierTool::FPGATrackSimGNNEdgeClassifierTool ( const std::string & algname,
const std::string & name,
const IInterface * ifc )

Definition at line 10 of file FPGATrackSimGNNEdgeClassifierTool.cxx.

11 : AthAlgTool(algname, name, ifc) {}
AthAlgTool()
Default constructor:

Member Function Documentation

◆ computeEdgeFeatures()

void FPGATrackSimGNNEdgeClassifierTool::computeEdgeFeatures ( std::shared_ptr< FPGATrackSimGNNEdge > & edge,
const int & hit1_index,
const int & hit2_index,
const std::vector< float > & gNodeFeatures )
private

Definition at line 118 of file FPGATrackSimGNNEdgeClassifierTool.cxx.

119{
120 size_t num_features = m_gnnFeatureNamesVec.size();
121
122 std::map<std::string, float> hit1_features;
123 std::map<std::string, float> hit2_features;
124
125 for(size_t i = 0; i < num_features; i++){
126 hit1_features[m_gnnFeatureNamesVec[i]] = gNodeFeatures[hit1_index * num_features + i];
127 hit2_features[m_gnnFeatureNamesVec[i]] = gNodeFeatures[hit2_index * num_features + i];
128 }
129
130 float deta = hit2_features["eta"] - hit1_features["eta"];
131 float dz = hit2_features["z"] - hit1_features["z"];
132 float dr = hit2_features["r"] - hit1_features["r"];
133 float dphi = P4Helpers::deltaPhi(hit2_features["phi"],hit1_features["phi"]);
134 float phislope = dr==0. ? 0. : dphi / dr;
135 float rphislope = 0.5 * (hit2_features["r"] + hit1_features["r"]) * phislope;
136
137 edge->setEdgeDR(dr);
138 edge->setEdgeDPhi(dphi);
139 edge->setEdgeDZ(dz);
140 edge->setEdgeDEta(deta);
141 edge->setEdgePhiSlope(phislope);
142 edge->setEdgeRPhiSlope(rphislope);
143}
double deltaPhi(double phiA, double phiB)
delta Phi in range [-pi,pi[
Definition P4Helpers.h:34

◆ declareGaudiProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareGaudiProperty ( Gaudi::Property< T, V, H > & hndl,
const SG::VarHandleKeyType &  )
inlineprivateinherited

specialization for handling Gaudi::Property<SG::VarHandleKey>

Definition at line 156 of file AthCommonDataStore.h.

158 {
160 hndl.value(),
161 hndl.documentation());
162
163 }
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)

◆ declareProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty ( Gaudi::Property< T, V, H > & t)
inlineinherited

Definition at line 145 of file AthCommonDataStore.h.

145 {
146 typedef typename SG::HandleClassifier<T>::type htype;
148 }
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
specialization for handling Gaudi::Property<SG::VarHandleKey>

◆ detStore()

const ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore ( ) const
inlineinherited

The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 95 of file AthCommonDataStore.h.

◆ evtStore()

ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore ( )
inlineinherited

The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 85 of file AthCommonDataStore.h.

◆ extraDeps_update_handler()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::extraDeps_update_handler ( Gaudi::Details::PropertyBase & ExtraDeps)
protectedinherited

Add StoreName to extra input/output deps as needed.

use the logic of the VarHandleKey to parse the DataObjID keys supplied via the ExtraInputs and ExtraOuputs Properties to add the StoreName if it's not explicitly given

◆ getEdgeFeatures()

std::vector< float > FPGATrackSimGNNEdgeClassifierTool::getEdgeFeatures ( std::vector< std::shared_ptr< FPGATrackSimGNNEdge > > & edges,
const std::vector< float > & gNodeFeatures )
private

Definition at line 100 of file FPGATrackSimGNNEdgeClassifierTool.cxx.

101{
102 std::vector<float> gEdgeFeatures;
103
104 for (auto& edge : edges) {
105 computeEdgeFeatures(edge, edge->getEdgeIndex1(), edge->getEdgeIndex2(), gNodeFeatures);
106
107 gEdgeFeatures.push_back(edge->getEdgeDR());
108 gEdgeFeatures.push_back(edge->getEdgeDPhi());
109 gEdgeFeatures.push_back(edge->getEdgeDZ());
110 gEdgeFeatures.push_back(edge->getEdgeDEta());
111 gEdgeFeatures.push_back(edge->getEdgePhiSlope());
112 gEdgeFeatures.push_back(edge->getEdgeRPhiSlope());
113 }
114
115 return gEdgeFeatures;
116}
void computeEdgeFeatures(std::shared_ptr< FPGATrackSimGNNEdge > &edge, const int &hit1_index, const int &hit2_index, const std::vector< float > &gNodeFeatures)

◆ getEdgeList()

std::vector< int64_t > FPGATrackSimGNNEdgeClassifierTool::getEdgeList ( const std::vector< std::shared_ptr< FPGATrackSimGNNEdge > > & edges)
private

Definition at line 83 of file FPGATrackSimGNNEdgeClassifierTool.cxx.

84{
85 std::vector<int64_t> rowIndices;
86 std::vector<int64_t> colIndices;
87 std::vector<int64_t> edgesList(edges.size() * 2);
88
89 for(const auto& edge : edges) {
90 rowIndices.push_back(edge->getEdgeIndex1());
91 colIndices.push_back(edge->getEdgeIndex2());
92 }
93
94 std::copy(rowIndices.begin(), rowIndices.end(), edgesList.begin());
95 std::copy(colIndices.begin(), colIndices.end(), edgesList.begin() + edges.size());
96
97 return edgesList;
98}

◆ getNodeFeatures()

std::vector< float > FPGATrackSimGNNEdgeClassifierTool::getNodeFeatures ( const std::vector< std::shared_ptr< FPGATrackSimGNNHit > > & hits)
private

Definition at line 55 of file FPGATrackSimGNNEdgeClassifierTool.cxx.

56{
57 std::vector<float> gNodeFeatures;
58
59 for(const auto& hit : hits) {
60 std::map<std::string, float> features;
61 features["r"] = hit->getR();
62 features["phi"] = hit->getPhi();
63 features["z"] = hit->getZ();
64 features["eta"] = hit->getEta();
65 features["cluster_r_1"] = hit->getCluster1R();
66 features["cluster_phi_1"] = hit->getCluster1Phi();
67 features["cluster_z_1"] = hit->getCluster1Z();
68 features["cluster_eta_1"] = hit->getCluster1Eta();
69 features["cluster_r_2"] = hit->getCluster2R();
70 features["cluster_phi_2"] = hit->getCluster2Phi();
71 features["cluster_z_2"] = hit->getCluster2Z();
72 features["cluster_eta_2"] = hit->getCluster2Eta();
73
74 for(size_t i = 0; i < m_gnnFeatureNamesVec.size(); i++){
75 gNodeFeatures.push_back(
77 }
78 }
79
80 return gNodeFeatures;
81}

◆ initialize()

StatusCode FPGATrackSimGNNEdgeClassifierTool::initialize ( )
overridevirtual

Definition at line 13 of file FPGATrackSimGNNEdgeClassifierTool.cxx.

14{
15 ATH_CHECK( m_GNNInferenceTool.retrieve() );
16 m_GNNInferenceTool->printModelInfo();
17 assert(m_gnnFeatureNamesVec.size() == m_gnnFeatureScalesVec.size());
18
19 return StatusCode::SUCCESS;
20}
#define ATH_CHECK
Evaluate an expression and check for errors.
ToolHandle< AthOnnx::IOnnxRuntimeInferenceTool > m_GNNInferenceTool

◆ inputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::inputHandles ( ) const
overridevirtualinherited

Return this algorithm's input handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ msg()

MsgStream & AthCommonMsg< AlgTool >::msg ( ) const
inlineinherited

Definition at line 24 of file AthCommonMsg.h.

24 {
25 return this->msgStream();
26 }

◆ msgLvl()

bool AthCommonMsg< AlgTool >::msgLvl ( const MSG::Level lvl) const
inlineinherited

Definition at line 30 of file AthCommonMsg.h.

30 {
31 return this->msgLevel(lvl);
32 }

◆ outputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::outputHandles ( ) const
overridevirtualinherited

Return this algorithm's output handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ regionNum()

int FPGATrackSimGNNEdgeClassifierTool::regionNum ( ) const
inline

Definition at line 40 of file FPGATrackSimGNNEdgeClassifierTool.h.

◆ renounce()

std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > AthCommonDataStore< AthCommonMsg< AlgTool > >::renounce ( T & h)
inlineprotectedinherited

Definition at line 380 of file AthCommonDataStore.h.

381 {
382 h.renounce();
384 }
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)

◆ renounceArray()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::renounceArray ( SG::VarHandleKeyArray & handlesArray)
inlineprotectedinherited

remove all handles from I/O resolution

Definition at line 364 of file AthCommonDataStore.h.

364 {
366 }

◆ scoreEdges()

StatusCode FPGATrackSimGNNEdgeClassifierTool::scoreEdges ( const std::vector< std::shared_ptr< FPGATrackSimGNNHit > > & hits,
std::vector< std::shared_ptr< FPGATrackSimGNNEdge > > & edges )
virtual

Definition at line 25 of file FPGATrackSimGNNEdgeClassifierTool.cxx.

26{
27 std::vector<float> edge_scores;
28
29 std::vector<float> gNodeFeatures = getNodeFeatures(hits);
30 std::vector<int64_t> edgeList = getEdgeList(edges);
31 std::vector<float> gEdgeFeatures = getEdgeFeatures(edges, gNodeFeatures);
32
33 std::vector<Ort::Value> gInputTensor;
34 ATH_CHECK( m_GNNInferenceTool->addInput(gInputTensor, gNodeFeatures, 0, hits.size()) );
35 ATH_CHECK( m_GNNInferenceTool->addInput(gInputTensor, edgeList, 1, edges.size()) );
36 ATH_CHECK( m_GNNInferenceTool->addInput(gInputTensor, gEdgeFeatures, 2, edges.size()) );
37
38 std::vector<float> gOutputData;
39 std::vector<Ort::Value> gOutputTensor;
40 ATH_CHECK( m_GNNInferenceTool->addOutput(gOutputTensor, edge_scores, 0, edges.size()) );
41
42 ATH_CHECK( m_GNNInferenceTool->inference(gInputTensor, gOutputTensor) );
43 // apply sigmoid to the gnn output data
44 for(auto& v : edge_scores) {
45 v = 1.f / (1.f + std::exp(-v));
46 };
47
48 for (size_t i = 0; i < edges.size(); i++) {
49 edges[i]->setEdgeScore(edge_scores[i]);
50 }
51
52 return StatusCode::SUCCESS;
53}
std::vector< int64_t > getEdgeList(const std::vector< std::shared_ptr< FPGATrackSimGNNEdge > > &edges)
std::vector< float > getEdgeFeatures(std::vector< std::shared_ptr< FPGATrackSimGNNEdge > > &edges, const std::vector< float > &gNodeFeatures)
std::vector< float > getNodeFeatures(const std::vector< std::shared_ptr< FPGATrackSimGNNHit > > &hits)

◆ sysInitialize()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysInitialize ( )
overridevirtualinherited

Perform system initialization for an algorithm.

We override this to declare all the elements of handle key arrays at the end of initialization. See comments on updateVHKA.

Reimplemented in asg::AsgMetadataTool, AthCheckedComponent< AthAlgTool >, AthCheckedComponent<::AthAlgTool >, and DerivationFramework::CfAthAlgTool.

◆ sysStart()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysStart ( )
overridevirtualinherited

Handle START transition.

We override this in order to make sure that conditions handle keys can cache a pointer to the conditions container.

◆ updateVHKA()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::updateVHKA ( Gaudi::Details::PropertyBase & )
inlineinherited

Definition at line 308 of file AthCommonDataStore.h.

308 {
309 // debug() << "updateVHKA for property " << p.name() << " " << p.toString()
310 // << " size: " << m_vhka.size() << endmsg;
311 for (auto &a : m_vhka) {
313 for (auto k : keys) {
314 k->setOwner(this);
315 }
316 }
317 }
std::vector< SG::VarHandleKeyArray * > m_vhka

Member Data Documentation

◆ m_detStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_detStore
privateinherited

Pointer to StoreGate (detector store by default)

Definition at line 393 of file AthCommonDataStore.h.

◆ m_evtStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_evtStore
privateinherited

Pointer to StoreGate (event store by default)

Definition at line 390 of file AthCommonDataStore.h.

◆ m_gnnFeatureNamesVec

StringArrayProperty FPGATrackSimGNNEdgeClassifierTool::m_gnnFeatureNamesVec
private
Initial value:
{
this, "GNNFeatureNames",
{"r", "phi", "z", "eta", "cluster_r_1", "cluster_phi_1", "cluster_z_1", "cluster_eta_1", "cluster_r_2", "cluster_phi_2", "cluster_z_2", "cluster_eta_2"},
"Feature names for the GNN model"}

Definition at line 58 of file FPGATrackSimGNNEdgeClassifierTool.h.

58 {
59 this, "GNNFeatureNames",
60 {"r", "phi", "z", "eta", "cluster_r_1", "cluster_phi_1", "cluster_z_1", "cluster_eta_1", "cluster_r_2", "cluster_phi_2", "cluster_z_2", "cluster_eta_2"},
61 "Feature names for the GNN model"};

◆ m_gnnFeatureScalesVec

FloatArrayProperty FPGATrackSimGNNEdgeClassifierTool::m_gnnFeatureScalesVec
private
Initial value:
{
this, "GNNFeatureScales",
{1000.0, 3.14159265359, 1000.0, 1.0, 1000.0, 3.14159265359, 1000.0, 1.0, 1000.0, 3.14159265359, 1000.0, 1.0},
"Feature scales for the GNN model"}

Definition at line 62 of file FPGATrackSimGNNEdgeClassifierTool.h.

62 {
63 this, "GNNFeatureScales",
64 {1000.0, 3.14159265359, 1000.0, 1.0, 1000.0, 3.14159265359, 1000.0, 1.0, 1000.0, 3.14159265359, 1000.0, 1.0},
65 "Feature scales for the GNN model"};

◆ m_GNNInferenceTool

ToolHandle<AthOnnx::IOnnxRuntimeInferenceTool> FPGATrackSimGNNEdgeClassifierTool::m_GNNInferenceTool {this, "GNNInferenceTool", "AthOnnx::OnnxRuntimeInferenceTool"}
private

Definition at line 47 of file FPGATrackSimGNNEdgeClassifierTool.h.

47{this, "GNNInferenceTool", "AthOnnx::OnnxRuntimeInferenceTool"};

◆ m_regionNum

Gaudi::Property<int> FPGATrackSimGNNEdgeClassifierTool::m_regionNum {this, "regionNum", -1, "Region number for this GNNEdgeClassifierTool"}
private

Definition at line 48 of file FPGATrackSimGNNEdgeClassifierTool.h.

48{this, "regionNum", -1, "Region number for this GNNEdgeClassifierTool"};

◆ m_varHandleArraysDeclared

bool AthCommonDataStore< AthCommonMsg< AlgTool > >::m_varHandleArraysDeclared
privateinherited

Definition at line 399 of file AthCommonDataStore.h.

◆ m_vhka

std::vector<SG::VarHandleKeyArray*> AthCommonDataStore< AthCommonMsg< AlgTool > >::m_vhka
privateinherited

Definition at line 398 of file AthCommonDataStore.h.


The documentation for this class was generated from the following files: