ATLAS Offline Software
FPGATrackSimGNNGraphConstructionTool.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2 
3 #ifndef FPGATRACKSIMGNNGRAPHCONSTRUCTIONTOOL_H
4 #define FPGATRACKSIMGNNGRAPHCONSTRUCTIONTOOL_H
5 
19 
22 
24 #include "AthOnnxUtils/OnnxUtils.h"
25 #include <onnxruntime_cxx_api.h>
26 
28 {
29  public:
30 
32  // AthAlgTool
33 
34  FPGATrackSimGNNGraphConstructionTool(const std::string&, const std::string&, const IInterface*);
35 
36  virtual StatusCode initialize() override;
37 
39  // Functions
40 
41  virtual StatusCode getEdges(const std::vector<std::shared_ptr<FPGATrackSimGNNHit>> & hits,
42  std::vector<std::shared_ptr<FPGATrackSimGNNEdge>> & edges);
43 
44  private:
45 
47  // Handles
48 
49  ToolHandle<AthOnnx::IOnnxRuntimeInferenceTool> m_MLInferenceTool {this, "MLInferenceTool", "AthOnnx::OnnxRuntimeInferenceTool"};
50 
52  // Properties
53 
54  Gaudi::Property<std::string> m_graphTool { this, "graphTool", "", "Tool for graph construction" };
55  Gaudi::Property<std::string> m_moduleMapType { this, "moduleMapType", "", "Type for Module Map for graph construction" };
56  Gaudi::Property<std::string> m_moduleMapFunc { this, "moduleMapFunc", "", "Function for Module Map for graph construction" };
57  Gaudi::Property<float> m_moduleMapTol { this, "moduleMapTol", 0.0, "Tolerance value for Module Map cut calculations" };
58  Gaudi::Property<std::string> m_moduleMapPath { this, "moduleMapPath", "", "Location of Module Map ROOT file" };
59  Gaudi::Property<float> m_metricLearningR { this, "metricLearningR", 0.0, "Clustering radius for Metric Learning"};
60  Gaudi::Property<int> m_metricLearningMaxN { this, "metricLearningMaxN", 1, "Max number of neighbours for Metric Learning"};
61 
63  // Convenience
64 
65  // Module Map Information
66  std::vector<unsigned int> m_mid1{};
67  std::vector<unsigned int> m_mid2{};
68  std::vector<float> m_z0min_12{};
69  std::vector<float> m_dphimin_12{};
70  std::vector<float> m_phislopemin_12{};
71  std::vector<float> m_detamin_12{};
72  std::vector<float> m_z0max_12{};
73  std::vector<float> m_dphimax_12{};
74  std::vector<float> m_phislopemax_12{};
75  std::vector<float> m_detamax_12{};
76 
78  // Helpers
79 
80  void loadDoubletModuleMap();
81  void doModuleMap(const std::vector<std::shared_ptr<FPGATrackSimGNNHit>> & hits,
82  std::vector<std::shared_ptr<FPGATrackSimGNNEdge>> & edges);
83  void getDoubletEdges(const std::vector<std::shared_ptr<FPGATrackSimGNNHit>> & hits,
84  std::vector<std::shared_ptr<FPGATrackSimGNNEdge>> & edges);
85  void applyDoubletCuts(const std::shared_ptr<FPGATrackSimGNNHit> & hit1, const std::shared_ptr<FPGATrackSimGNNHit> & hit2,
86  std::vector<std::shared_ptr<FPGATrackSimGNNEdge>> & edges,
87  int hit1_index, int hit2_index, unsigned int modulemap_id);
88  bool doMask(float val, float min, float max);
89  bool doMinMaxMask(float val, float min, float max);
90  float featureSign(float feature);
91  void doMetricLearning(const std::vector<std::shared_ptr<FPGATrackSimGNNHit>> & hits, std::vector<std::shared_ptr<FPGATrackSimGNNEdge>> & edges);
92  std::vector<float> getNodeFeatures(const std::vector<std::shared_ptr<FPGATrackSimGNNHit>> & hits);
93  std::vector<float> embed(const std::vector<std::shared_ptr<FPGATrackSimGNNHit>> & hits);
94  void doClustering(const std::vector<std::shared_ptr<FPGATrackSimGNNHit>> & hits, std::vector<std::shared_ptr<FPGATrackSimGNNEdge>> & edges, std::vector<float> & gEmbedded);
95  // Metric Learning Properties
96  StringArrayProperty m_MLFeatureNamesVec{
97  this, "MLFeatureNames",
98  {"r", "phi", "z"},
99  "Feature names for the Metric Learning model"};
100  FloatArrayProperty m_MLFeatureScalesVec{
101  this, "MLFeatureScales",
102  {1000.0, 3.14159265359, 1000.0},
103  "Feature scales for the Metric Learning model"};
104 };
105 
106 #endif // FPGATRACKSIMGNNGRAPHCONSTRUCTIONTOOL_H
FPGATrackSimGNNGraphConstructionTool::getNodeFeatures
std::vector< float > getNodeFeatures(const std::vector< std::shared_ptr< FPGATrackSimGNNHit >> &hits)
Definition: FPGATrackSimGNNGraphConstructionTool.cxx:204
TRTCalib_Extractor.hits
hits
Definition: TRTCalib_Extractor.py:35
FPGATrackSimGNNGraphConstructionTool::m_MLFeatureScalesVec
FloatArrayProperty m_MLFeatureScalesVec
Definition: FPGATrackSimGNNGraphConstructionTool.h:100
FPGATrackSimGNNGraphConstructionTool::m_metricLearningMaxN
Gaudi::Property< int > m_metricLearningMaxN
Definition: FPGATrackSimGNNGraphConstructionTool.h:60
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
IOnnxRuntimeInferenceTool.h
FPGATrackSimGNNGraphConstructionTool::embed
std::vector< float > embed(const std::vector< std::shared_ptr< FPGATrackSimGNNHit >> &hits)
Definition: FPGATrackSimGNNGraphConstructionTool.cxx:222
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
FPGATrackSimGNNGraphConstructionTool::m_dphimin_12
std::vector< float > m_dphimin_12
Definition: FPGATrackSimGNNGraphConstructionTool.h:69
FPGATrackSimGNNGraphConstructionTool::m_moduleMapFunc
Gaudi::Property< std::string > m_moduleMapFunc
Definition: FPGATrackSimGNNGraphConstructionTool.h:56
FPGATrackSimGNNGraphConstructionTool::m_moduleMapTol
Gaudi::Property< float > m_moduleMapTol
Definition: FPGATrackSimGNNGraphConstructionTool.h:57
FPGATrackSimGNNGraphConstructionTool
Definition: FPGATrackSimGNNGraphConstructionTool.h:28
FPGATrackSimGNNGraphConstructionTool::FPGATrackSimGNNGraphConstructionTool
FPGATrackSimGNNGraphConstructionTool(const std::string &, const std::string &, const IInterface *)
Definition: FPGATrackSimGNNGraphConstructionTool.cxx:12
FPGATrackSimGNNEdge.h
FPGATrackSim-specific class to represent an edge as a connection between two hits in the detector use...
FPGATrackSimGNNGraphConstructionTool::m_MLFeatureNamesVec
StringArrayProperty m_MLFeatureNamesVec
Definition: FPGATrackSimGNNGraphConstructionTool.h:96
FPGATrackSimGNNGraphConstructionTool::applyDoubletCuts
void applyDoubletCuts(const std::shared_ptr< FPGATrackSimGNNHit > &hit1, const std::shared_ptr< FPGATrackSimGNNHit > &hit2, std::vector< std::shared_ptr< FPGATrackSimGNNEdge >> &edges, int hit1_index, int hit2_index, unsigned int modulemap_id)
Definition: FPGATrackSimGNNGraphConstructionTool.cxx:136
FPGATrackSimGNNGraphConstructionTool::m_z0min_12
std::vector< float > m_z0min_12
Definition: FPGATrackSimGNNGraphConstructionTool.h:68
FPGATrackSimGNNGraphConstructionTool::doMetricLearning
void doMetricLearning(const std::vector< std::shared_ptr< FPGATrackSimGNNHit >> &hits, std::vector< std::shared_ptr< FPGATrackSimGNNEdge >> &edges)
Definition: FPGATrackSimGNNGraphConstructionTool.cxx:195
FPGATrackSimGNNGraphConstructionTool::doMinMaxMask
bool doMinMaxMask(float val, float min, float max)
Definition: FPGATrackSimGNNGraphConstructionTool.cxx:176
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
FPGATrackSimGNNGraphConstructionTool::initialize
virtual StatusCode initialize() override
Definition: FPGATrackSimGNNGraphConstructionTool.cxx:15
FPGATrackSimGNNGraphConstructionTool::m_phislopemin_12
std::vector< float > m_phislopemin_12
Definition: FPGATrackSimGNNGraphConstructionTool.h:70
FPGATrackSimGNNGraphConstructionTool::m_MLInferenceTool
ToolHandle< AthOnnx::IOnnxRuntimeInferenceTool > m_MLInferenceTool
Definition: FPGATrackSimGNNGraphConstructionTool.h:49
AthAlgTool.h
FPGATrackSimGNNGraphConstructionTool::m_detamin_12
std::vector< float > m_detamin_12
Definition: FPGATrackSimGNNGraphConstructionTool.h:71
FPGATrackSimGNNGraphConstructionTool::getDoubletEdges
void getDoubletEdges(const std::vector< std::shared_ptr< FPGATrackSimGNNHit >> &hits, std::vector< std::shared_ptr< FPGATrackSimGNNEdge >> &edges)
Definition: FPGATrackSimGNNGraphConstructionTool.cxx:106
FPGATrackSimGNNGraphConstructionTool::m_phislopemax_12
std::vector< float > m_phislopemax_12
Definition: FPGATrackSimGNNGraphConstructionTool.h:74
FPGATrackSimGNNGraphConstructionTool::m_moduleMapType
Gaudi::Property< std::string > m_moduleMapType
Definition: FPGATrackSimGNNGraphConstructionTool.h:55
FPGATrackSimGNNGraphConstructionTool::m_z0max_12
std::vector< float > m_z0max_12
Definition: FPGATrackSimGNNGraphConstructionTool.h:72
FPGATrackSimGNNGraphConstructionTool::m_mid2
std::vector< unsigned int > m_mid2
Definition: FPGATrackSimGNNGraphConstructionTool.h:67
FPGATrackSimGNNHit.h
FPGATrackSim-specific class to represent an hit in the detector used for GNN pattern recognition.
FPGATrackSimGNNGraphConstructionTool::doModuleMap
void doModuleMap(const std::vector< std::shared_ptr< FPGATrackSimGNNHit >> &hits, std::vector< std::shared_ptr< FPGATrackSimGNNEdge >> &edges)
Definition: FPGATrackSimGNNGraphConstructionTool.cxx:93
FPGATrackSimGNNGraphConstructionTool::m_detamax_12
std::vector< float > m_detamax_12
Definition: FPGATrackSimGNNGraphConstructionTool.h:75
FPGATrackSimGNNGraphConstructionTool::getEdges
virtual StatusCode getEdges(const std::vector< std::shared_ptr< FPGATrackSimGNNHit >> &hits, std::vector< std::shared_ptr< FPGATrackSimGNNEdge >> &edges)
Definition: FPGATrackSimGNNGraphConstructionTool.cxx:38
FPGATrackSimGNNGraphConstructionTool::m_mid1
std::vector< unsigned int > m_mid1
Definition: FPGATrackSimGNNGraphConstructionTool.h:66
FPGATrackSimGNNGraphConstructionTool::doClustering
void doClustering(const std::vector< std::shared_ptr< FPGATrackSimGNNHit >> &hits, std::vector< std::shared_ptr< FPGATrackSimGNNEdge >> &edges, std::vector< float > &gEmbedded)
Definition: FPGATrackSimGNNGraphConstructionTool.cxx:237
FPGATrackSimGNNGraphConstructionTool::doMask
bool doMask(float val, float min, float max)
Definition: FPGATrackSimGNNGraphConstructionTool.cxx:166
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
FPGATrackSimGNNGraphConstructionTool::m_metricLearningR
Gaudi::Property< float > m_metricLearningR
Definition: FPGATrackSimGNNGraphConstructionTool.h:59
OnnxUtils.h
FPGATrackSimGNNGraphConstructionTool::m_moduleMapPath
Gaudi::Property< std::string > m_moduleMapPath
Definition: FPGATrackSimGNNGraphConstructionTool.h:58
FPGATrackSimGNNGraphConstructionTool::featureSign
float featureSign(float feature)
Definition: FPGATrackSimGNNGraphConstructionTool.cxx:188
AthAlgTool
Definition: AthAlgTool.h:26
FPGATrackSimGNNGraphConstructionTool::m_graphTool
Gaudi::Property< std::string > m_graphTool
Definition: FPGATrackSimGNNGraphConstructionTool.h:54
FPGATrackSimGNNGraphConstructionTool::loadDoubletModuleMap
void loadDoubletModuleMap()
Definition: FPGATrackSimGNNGraphConstructionTool.cxx:50
FPGATrackSimGNNGraphConstructionTool::m_dphimax_12
std::vector< float > m_dphimax_12
Definition: FPGATrackSimGNNGraphConstructionTool.h:73