5#ifdef ACTS_GNN_WITH_MODULEMAP
11#include "ActsPlugins/Gnn/CudaTrackBuilding.hpp"
12#include "ActsPlugins/Gnn/DWalkTrackBuilding.hpp"
13#include "ActsPlugins/Gnn/EdgeLayerConnector.hpp"
14#include "ActsPlugins/Gnn/GnnPipeline.hpp"
15#include "ActsPlugins/Gnn/ModuleMapCuda.hpp"
16#include "ActsPlugins/Gnn/OnnxEdgeClassifier.hpp"
17#include "ActsPlugins/Gnn/TensorRTEdgeClassifier.hpp"
18#include "ActsPlugins/Gnn/TorchEdgeClassifier.hpp"
37 ActsPlugins::ModuleMapCuda::Config gcCfg;
42 gcCfg.gpuBlocks = 512;
43 auto gc = std::make_shared<ActsPlugins::ModuleMapCuda>(
44 gcCfg,
m_logger->cloneWithSuffix(
"ModuleMap"));
49 std::shared_ptr<ActsPlugins::EdgeClassificationBase> gnn;
50 if (
m_gnnPath.value().find(
".onnx") != std::string::npos) {
51#ifdef ACTS_GNN_ONNX_BACKEND
52 ActsPlugins::OnnxEdgeClassifier::Config gnnCfg;
55 gnn = std::make_shared<ActsPlugins::OnnxEdgeClassifier>(
56 gnnCfg,
m_logger->cloneWithSuffix(
"GNN"));
59 ATH_MSG_FATAL(
"Not compiled with ONNX, cannot interpret *.onnx files");
60 return StatusCode::FAILURE;
62 }
else if (
m_gnnPath.value().find(
".pt") != std::string::npos) {
63#ifdef ACTS_GNN_TORCH_BACKEND
64 ActsPlugins::TorchEdgeClassifier::Config gnnCfg;
67 gnn = std::make_shared<ActsPlugins::TorchEdgeClassifier>(
68 gnnCfg,
m_logger->cloneWithSuffix(
"GNN"));
71 ATH_MSG_FATAL(
"Not compiled with Torch, cannot interpret *.pt files");
72 return StatusCode::FAILURE;
74 }
else if (
m_gnnPath.value().find(
".engine") != std::string::npos) {
75#ifdef ACTS_GNN_WITH_TENSORRT
76 ActsPlugins::TensorRTEdgeClassifier::Config gnnCfg;
80 gnn = std::make_shared<ActsPlugins::TensorRTEdgeClassifier>(
81 gnnCfg,
m_logger->cloneWithSuffix(
"GNN"));
83 ATH_MSG_FATAL(
"Not compiled with TensorRT, cannot interpret *.engine files");
84 return StatusCode::FAILURE;
88 return StatusCode::FAILURE;
92 std::shared_ptr<ActsPlugins::TrackBuildingBase>
tb;
94 ATH_MSG_INFO(
"Configure CC&JunctionRemoval as graph segmentation algorithm");
95 ActsPlugins::CudaTrackBuilding::Config tbCfg;
96 tbCfg.doJunctionRemoval =
true;
97 tb = std::make_shared<ActsPlugins::CudaTrackBuilding>(
98 tbCfg,
m_logger->cloneWithSuffix(
"CC&JR"));
100 ATH_MSG_INFO(
"Configure EdgeLayerConnector as graph segmentation algorithm");
101 ActsPlugins::EdgeLayerConnector::Config tbCfg;
103 tbCfg.blockSize = 512;
105 tb = std::make_shared<ActsPlugins::EdgeLayerConnector>(
106 tbCfg,
m_logger->cloneWithSuffix(
"ELC"));
108 ATH_MSG_INFO(
"Configure D-WALK as graph segmentation algorithm");
109 ActsPlugins::DWalkTrackBuilding::Config tbCfg;
111 tb = std::make_shared<ActsPlugins::DWalkTrackBuilding>(
112 tbCfg,
m_logger->cloneWithSuffix(
"D-WALK"));
115 return StatusCode::FAILURE;
120 gc, std::vector{std::move(gnn)},
tb,
m_logger->cloneWithSuffix(
"Pipeline"));
122 return StatusCode::SUCCESS;
126 const std::vector<const Trk::SpacePoint*>& spacepoints,
127 std::vector<std::vector<uint32_t>>& tracks,
128 std::unordered_map<
int, std::unordered_map<int, float>>* edgeMap)
const {
130 const std::size_t nSP = spacepoints.size();
135 std::vector<std::size_t> sortIdx(nSP);
136 std::iota(sortIdx.begin(), sortIdx.end(), 0);
137 std::ranges::sort(sortIdx, std::less{}, [&](std::size_t
i) {
138 return spacepoints[
i]->clusterList().first->detectorElement()->identify().get_compact();
143 std::vector<std::uint64_t> moduleIds(nSP);
144 std::vector<int>
ids(nSP);
146 for (std::size_t k = 0;
k < nSP; ++
k) {
147 const std::size_t origIdx = sortIdx[
k];
150 moduleIds[
k] = spacepoints[origIdx]->clusterList().first->detectorElement()->identify().get_compact();
151 ids[
k] =
static_cast<int>(
k);
159 std::unique_lock<std::mutex>
lock;
160 if (m_runMutex)
lock = std::unique_lock<std::mutex>(*m_runMutex);
162 if (edgeMap !=
nullptr) {
163 ScoredGraphHook hook;
164 auto result =
m_gnnPipeline->run(features, moduleIds, ids, ActsPlugins::Device::Cuda(0), hook);
167 const std::vector<float>& edgeScores = hook.getEdgeScores();
168 const std::vector<std::int64_t>& edgeIndex = hook.getEdgeIndex();
169 const std::size_t nEdges = edgeScores.size();
172 for (std::size_t i = 0;
i < nEdges; ++
i) {
173 std::int64_t
src = edgeIndex[
i];
174 std::int64_t dst = edgeIndex[nEdges +
i];
175 (*edgeMap)[sortIdx[
src]][sortIdx[dst]] = edgeScores[
i];
180 return m_gnnPipeline->run(features, moduleIds, ids, ActsPlugins::Device::Cuda(0));;
189 for (
const auto& candidate : candidates) {
195 std::vector<uint32_t>
track;
196 track.reserve(candidate.size());
197 for (
int sortedIdx : candidate) {
200 tracks.push_back(std::move(track));
203 ATH_MSG_DEBUG(
"Returning " << tracks.size() <<
" track candidates after filtering (>= "
206 return StatusCode::SUCCESS;
211 out <<
"|---------------------------------------------------------------------|\n" ;
212 out <<
"| ActsGnnModuleMapFinderTool |\n" ;
213 out <<
"|---------------------------------------------------------------------|\n" ;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_INFO(x,...)
#define ATH_MSG_FATAL(x,...)
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
std::unique_ptr< const Acts::Logger > makeActsAthenaLogger(IMessageSvc *svc, const std::string &name, int level, std::optional< std::string > parent_name)
::StatusCode StatusCode
StatusCode definition for legacy code.
float j(const xAOD::IParticle &, const xAOD::TrackMeasurementValidation &hit, const Eigen::Matrix3d &jab_inv)