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 
23 
25 #include "AthOnnxUtils/OnnxUtils.h"
26 #include <onnxruntime_cxx_api.h>
27 
29 {
30  public:
31 
33  // AthAlgTool
34 
35  FPGATrackSimGNNGraphConstructionTool(const std::string&, const std::string&, const IInterface*);
36 
37  virtual StatusCode initialize() override;
38 
40  // Functions
41 
42  virtual StatusCode getEdges(const std::vector<std::shared_ptr<FPGATrackSimGNNHit>> & hits,
43  std::vector<std::shared_ptr<FPGATrackSimGNNEdge>> & edges);
44 
45  private:
46 
48  // Handles
49 
50  ToolHandle<AthOnnx::IOnnxRuntimeInferenceTool> m_MLInferenceTool {this, "MLInferenceTool", "AthOnnx::OnnxRuntimeInferenceTool"};
52 
54  // Properties
55 
56  Gaudi::Property<std::string> m_graphTool { this, "graphTool", "", "Tool for graph construction" };
57  Gaudi::Property<std::string> m_moduleMapType { this, "moduleMapType", "", "Type for Module Map for graph construction" };
58  Gaudi::Property<std::string> m_moduleMapFunc { this, "moduleMapFunc", "", "Function for Module Map for graph construction" };
59  Gaudi::Property<float> m_moduleMapTol { this, "moduleMapTol", 0.0, "Tolerance value for Module Map cut calculations" };
60  Gaudi::Property<float> m_metricLearningR { this, "metricLearningR", 0.0, "Clustering radius for Metric Learning"};
61  Gaudi::Property<int> m_metricLearningMaxN { this, "metricLearningMaxN", 1, "Max number of neighbours for Metric Learning"};
62 
64  // Convenience
65 
66  // Module Map Information
67  std::string m_moduleMapPath;
68  std::vector<unsigned int> m_mid1{};
69  std::vector<unsigned int> m_mid2{};
70  std::vector<float> m_z0min_12{};
71  std::vector<float> m_dphimin_12{};
72  std::vector<float> m_phislopemin_12{};
73  std::vector<float> m_detamin_12{};
74  std::vector<float> m_z0max_12{};
75  std::vector<float> m_dphimax_12{};
76  std::vector<float> m_phislopemax_12{};
77  std::vector<float> m_detamax_12{};
78 
80  // Helpers
81 
82  void loadDoubletModuleMap();
83  void doModuleMap(const std::vector<std::shared_ptr<FPGATrackSimGNNHit>> & hits,
84  std::vector<std::shared_ptr<FPGATrackSimGNNEdge>> & edges);
85  void getDoubletEdges(const std::vector<std::shared_ptr<FPGATrackSimGNNHit>> & hits,
86  std::vector<std::shared_ptr<FPGATrackSimGNNEdge>> & edges);
87  void applyDoubletCuts(const std::shared_ptr<FPGATrackSimGNNHit> & hit1, const std::shared_ptr<FPGATrackSimGNNHit> & hit2,
88  std::vector<std::shared_ptr<FPGATrackSimGNNEdge>> & edges,
89  int hit1_index, int hit2_index, unsigned int modulemap_id);
90  bool doMask(float val, float min, float max);
91  bool doMinMaxMask(float val, float min, float max);
92  float featureSign(float feature);
93  void doMetricLearning(const std::vector<std::shared_ptr<FPGATrackSimGNNHit>> & hits, std::vector<std::shared_ptr<FPGATrackSimGNNEdge>> & edges);
94  std::vector<float> getNodeFeatures(const std::vector<std::shared_ptr<FPGATrackSimGNNHit>> & hits);
95  std::vector<float> embed(const std::vector<std::shared_ptr<FPGATrackSimGNNHit>> & hits);
96  void doClustering(const std::vector<std::shared_ptr<FPGATrackSimGNNHit>> & hits, std::vector<std::shared_ptr<FPGATrackSimGNNEdge>> & edges, std::vector<float> & gEmbedded);
97  // Metric Learning Properties
98  StringArrayProperty m_MLFeatureNamesVec{
99  this, "MLFeatureNames",
100  {"r", "phi", "z"},
101  "Feature names for the Metric Learning model"};
102  FloatArrayProperty m_MLFeatureScalesVec{
103  this, "MLFeatureScales",
104  {1000.0, 3.14159265359, 1000.0},
105  "Feature scales for the Metric Learning model"};
106 };
107 
108 #endif // FPGATRACKSIMGNNGRAPHCONSTRUCTIONTOOL_H
FPGATrackSimGNNGraphConstructionTool::getNodeFeatures
std::vector< float > getNodeFeatures(const std::vector< std::shared_ptr< FPGATrackSimGNNHit >> &hits)
Definition: FPGATrackSimGNNGraphConstructionTool.cxx:209
TRTCalib_Extractor.hits
hits
Definition: TRTCalib_Extractor.py:35
FPGATrackSimGNNGraphConstructionTool::m_MLFeatureScalesVec
FloatArrayProperty m_MLFeatureScalesVec
Definition: FPGATrackSimGNNGraphConstructionTool.h:102
FPGATrackSimGNNGraphConstructionTool::m_metricLearningMaxN
Gaudi::Property< int > m_metricLearningMaxN
Definition: FPGATrackSimGNNGraphConstructionTool.h:61
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:227
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
IFPGATrackSimMappingSvc.h
FPGATrackSimGNNGraphConstructionTool::m_dphimin_12
std::vector< float > m_dphimin_12
Definition: FPGATrackSimGNNGraphConstructionTool.h:71
FPGATrackSimGNNGraphConstructionTool::m_moduleMapFunc
Gaudi::Property< std::string > m_moduleMapFunc
Definition: FPGATrackSimGNNGraphConstructionTool.h:58
FPGATrackSimGNNGraphConstructionTool::m_moduleMapTol
Gaudi::Property< float > m_moduleMapTol
Definition: FPGATrackSimGNNGraphConstructionTool.h:59
FPGATrackSimGNNGraphConstructionTool
Definition: FPGATrackSimGNNGraphConstructionTool.h:29
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:98
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:141
FPGATrackSimGNNGraphConstructionTool::m_z0min_12
std::vector< float > m_z0min_12
Definition: FPGATrackSimGNNGraphConstructionTool.h:70
FPGATrackSimGNNGraphConstructionTool::doMetricLearning
void doMetricLearning(const std::vector< std::shared_ptr< FPGATrackSimGNNHit >> &hits, std::vector< std::shared_ptr< FPGATrackSimGNNEdge >> &edges)
Definition: FPGATrackSimGNNGraphConstructionTool.cxx:200
FPGATrackSimGNNGraphConstructionTool::doMinMaxMask
bool doMinMaxMask(float val, float min, float max)
Definition: FPGATrackSimGNNGraphConstructionTool.cxx:181
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:72
FPGATrackSimGNNGraphConstructionTool::m_MLInferenceTool
ToolHandle< AthOnnx::IOnnxRuntimeInferenceTool > m_MLInferenceTool
Definition: FPGATrackSimGNNGraphConstructionTool.h:50
FPGATrackSimGNNGraphConstructionTool::m_FPGATrackSimMapping
ServiceHandle< IFPGATrackSimMappingSvc > m_FPGATrackSimMapping
Definition: FPGATrackSimGNNGraphConstructionTool.h:51
AthAlgTool.h
FPGATrackSimGNNGraphConstructionTool::m_detamin_12
std::vector< float > m_detamin_12
Definition: FPGATrackSimGNNGraphConstructionTool.h:73
FPGATrackSimGNNGraphConstructionTool::getDoubletEdges
void getDoubletEdges(const std::vector< std::shared_ptr< FPGATrackSimGNNHit >> &hits, std::vector< std::shared_ptr< FPGATrackSimGNNEdge >> &edges)
Definition: FPGATrackSimGNNGraphConstructionTool.cxx:111
FPGATrackSimGNNGraphConstructionTool::m_phislopemax_12
std::vector< float > m_phislopemax_12
Definition: FPGATrackSimGNNGraphConstructionTool.h:76
FPGATrackSimGNNGraphConstructionTool::m_moduleMapType
Gaudi::Property< std::string > m_moduleMapType
Definition: FPGATrackSimGNNGraphConstructionTool.h:57
FPGATrackSimGNNGraphConstructionTool::m_z0max_12
std::vector< float > m_z0max_12
Definition: FPGATrackSimGNNGraphConstructionTool.h:74
FPGATrackSimGNNGraphConstructionTool::m_moduleMapPath
std::string m_moduleMapPath
Definition: FPGATrackSimGNNGraphConstructionTool.h:67
FPGATrackSimGNNGraphConstructionTool::m_mid2
std::vector< unsigned int > m_mid2
Definition: FPGATrackSimGNNGraphConstructionTool.h:69
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:98
FPGATrackSimGNNGraphConstructionTool::m_detamax_12
std::vector< float > m_detamax_12
Definition: FPGATrackSimGNNGraphConstructionTool.h:77
FPGATrackSimGNNGraphConstructionTool::getEdges
virtual StatusCode getEdges(const std::vector< std::shared_ptr< FPGATrackSimGNNHit >> &hits, std::vector< std::shared_ptr< FPGATrackSimGNNEdge >> &edges)
Definition: FPGATrackSimGNNGraphConstructionTool.cxx:43
FPGATrackSimGNNGraphConstructionTool::m_mid1
std::vector< unsigned int > m_mid1
Definition: FPGATrackSimGNNGraphConstructionTool.h:68
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:242
FPGATrackSimGNNGraphConstructionTool::doMask
bool doMask(float val, float min, float max)
Definition: FPGATrackSimGNNGraphConstructionTool.cxx:171
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
FPGATrackSimGNNGraphConstructionTool::m_metricLearningR
Gaudi::Property< float > m_metricLearningR
Definition: FPGATrackSimGNNGraphConstructionTool.h:60
OnnxUtils.h
FPGATrackSimGNNGraphConstructionTool::featureSign
float featureSign(float feature)
Definition: FPGATrackSimGNNGraphConstructionTool.cxx:193
AthAlgTool
Definition: AthAlgTool.h:26
FPGATrackSimGNNGraphConstructionTool::m_graphTool
Gaudi::Property< std::string > m_graphTool
Definition: FPGATrackSimGNNGraphConstructionTool.h:56
FPGATrackSimGNNGraphConstructionTool::loadDoubletModuleMap
void loadDoubletModuleMap()
Definition: FPGATrackSimGNNGraphConstructionTool.cxx:55
FPGATrackSimGNNGraphConstructionTool::m_dphimax_12
std::vector< float > m_dphimax_12
Definition: FPGATrackSimGNNGraphConstructionTool.h:75
ServiceHandle< IFPGATrackSimMappingSvc >