ATLAS Offline Software
Gbts2ActsSeedingTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 
9 #include "Gbts2ActsSeedingTool.h"
10 
11 #include <optional>
12 
14  const std::string& n,
15  const IInterface* p ) : SeedingToolBase(t,n,p)
16 {
17 }
18 
22  m_sct_h2l = m_layerNumberTool->sctLayers();
23  m_pix_h2l = m_layerNumberTool->pixelLayers();
24  m_are_pixels.resize(m_layerNumberTool->maxNumberOfUniqueLayers(), true);
25  for(const auto& l : *m_sct_h2l) m_are_pixels[l] = false;
26 
27  return StatusCode::SUCCESS;
28 }
29 
32 }
33 
34 StatusCode Gbts2ActsSeedingTool::createSeeds(const EventContext& ctx, const Acts::SpacePointContainer<ActsTrk::SpacePointCollector, Acts::detail::RefHolder>& spContainer, const Acts::Vector3&, const Acts::Vector3&, ActsTrk::SeedContainer& seedContainer) const {
35 
36  seedContainer.spacePoints().reserve(spContainer.size());
37  std::unique_ptr<GNN_DataStorage> storage = std::make_unique<GNN_DataStorage>(*m_geo, m_mlLUT);
38 
40 
41  const Amg::Vector3D &vertex = beamSpotHandle->beamPos();
42 
43  float shift_x = vertex.x() - beamSpotHandle->beamTilt(0)*vertex.z();
44  float shift_y = vertex.y() - beamSpotHandle->beamTilt(1)*vertex.z();
45 
46  std::vector<std::vector<GNN_Node> > node_storage;//layer-based collections
47  node_storage.resize(m_are_pixels.size());
48 
49  for(auto& v : node_storage) v.reserve(100000);
50 
51  unsigned int nPixelLoaded = 0;
52  unsigned int nStripLoaded = 0;
53 
54  for(size_t idx=0; idx<spContainer.size(); idx++){
55  const auto & sp = spContainer.at(idx);
56  const auto & extSP = sp.externalSpacePoint();
57  seedContainer.spacePoints().push_back(&extSP);
58  const std::vector<xAOD::DetectorIDHashType>& elementlist = extSP.elementIdList() ;
59 
60  bool isPixel(elementlist.size() == 1);
61 
62  short layer = (isPixel ? m_pix_h2l : m_sct_h2l)->at(static_cast<int>(elementlist[0]));
63 
64  //convert incoming xaod spacepoints into GNN nodes
65 
66  GNN_Node& node = node_storage[layer].emplace_back(layer);
67 
68  const auto& pos = extSP.globalPosition();
69 
70  node.m_x = pos.x() - shift_x;
71  node.m_y = pos.y() - shift_y;
72  node.m_z = pos.z();
73  node.m_r = std::sqrt(std::pow(node.m_x, 2) + std::pow(node.m_y, 2));
74  node.m_phi = std::atan2(node.m_y, node.m_x);
75  node.m_idx = idx;
76 
77  if(isPixel && m_useML){
78  //Check type in debug build otherwise assume it is correct
79  assert(dynamic_cast<const xAOD::PixelCluster*>(extSP.measurements().front())!=nullptr);
80  const xAOD::PixelCluster* pCL = static_cast<const xAOD::PixelCluster*>(extSP.measurements().front());
81  node.m_pcw = pCL->widthInEta();
82  node.m_locPosY = pCL->localPosition<2>().y();
83  }
84  }
85 
86  for(size_t l = 0; l < node_storage.size(); l++) {
87 
88  const std::vector<GNN_Node>& nodes = node_storage[l];
89 
90  if(nodes.size() == 0) continue;
91 
92  if(m_are_pixels[l])
93  nPixelLoaded += storage->loadPixelGraphNodes(l, nodes, m_useML);
94  else
95  nStripLoaded += storage->loadStripGraphNodes(l, nodes);
96  }
97 
98  ATH_MSG_DEBUG("Loaded "<<nPixelLoaded<<" pixel spacepoints and "<<nStripLoaded<<" strip spacepoints");
99 
100  storage->sortByPhi();
101 
102  storage->initializeNodes(m_useML);
103 
105 
106  std::vector<GNN_Edge> edgeStorage;
107 
108  const TrigRoiDescriptor fakeRoi = TrigRoiDescriptor(0, -4.5, 4.5, 0, -M_PI, M_PI, 0, -150.0, 150.0);
109 
110  std::pair<int, int> graphStats = buildTheGraph(fakeRoi, storage, edgeStorage);
111 
112  ATH_MSG_DEBUG("Created graph with "<<graphStats.first<<" edges and "<<graphStats.second<< " edge links");
113 
114  if (graphStats.first == 0 || graphStats.second == 0) return StatusCode::SUCCESS;
115 
116  int maxLevel = runCCA(graphStats.first, edgeStorage);
117 
118  ATH_MSG_DEBUG("Reached Level "<<maxLevel<<" after GNN iterations");
119 
120  std::vector<std::tuple<float, int, std::vector<unsigned int> > > vSeedCandidates;
121 
122  extractSeedsFromTheGraph(maxLevel, graphStats.first, spContainer.size(), edgeStorage, vSeedCandidates);
123 
124  if (vSeedCandidates.empty()) return StatusCode::SUCCESS;
125 
126  seedContainer.reserve(vSeedCandidates.size(), 7.0f); // 7 SP/seed to optimise allocations (average is 6.1 SP/seed)
127 
128  for (const auto& seed : vSeedCandidates) {
129 
130  if (std::get<1>(seed) != 0) continue;//identified as a clone of a better candidate
131 
132  //add seed to output
133 
134  seedContainer.push_back(std::get<2>(seed));
135 
136  }
137 
138  ATH_MSG_DEBUG("GBTS created "<<seedContainer.size()<<" seeds");
139 
140  return StatusCode::SUCCESS;
141 }
142 
Gbts2ActsSeedingTool::Gbts2ActsSeedingTool
Gbts2ActsSeedingTool(const std::string &, const std::string &, const IInterface *)
Definition: Gbts2ActsSeedingTool.cxx:13
ActsTrk::SeedContainer
Definition: SeedContainer.h:19
SeedingToolBase::initialize
virtual StatusCode initialize()
Definition: TrigInDetPattRecoTools/src/SeedingToolBase.cxx:24
xAOD::PixelCluster_v1::widthInEta
float widthInEta() const
Returns the width of the cluster in phi (x) and eta (y) directions, respectively.
SeedingToolBase
Definition: TrigInDetPattRecoTools/src/SeedingToolBase.h:29
SG::ReadCondHandle
Definition: ReadCondHandle.h:40
TrigFTF_GNN_DataStorage::sortByPhi
void sortByPhi()
Definition: GNN_DataStorage.cxx:178
Gbts2ActsSeedingTool::m_beamSpotKey
SG::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey
Definition: Gbts2ActsSeedingTool.h:34
SeedingToolBase::buildTheGraph
std::pair< int, int > buildTheGraph(const IRoiDescriptor &, const std::unique_ptr< GNN_DataStorage > &, std::vector< GNN_Edge > &) const
Definition: TrigInDetPattRecoTools/src/SeedingToolBase.cxx:98
M_PI
#define M_PI
Definition: ActiveFraction.h:11
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:157
TrigRoiDescriptor
nope - should be used for standalone also, perhaps need to protect the class def bits #ifndef XAOD_AN...
Definition: TrigRoiDescriptor.h:56
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
TrigFTF_GNN_Node
Definition: GNN_DataStorage.h:18
SeedingToolBase::m_mlLUT
std::vector< std::array< float, 5 > > m_mlLUT
Definition: TrigInDetPattRecoTools/src/SeedingToolBase.h:80
Gbts2ActsSeedingTool::finalize
virtual StatusCode finalize() override
Definition: Gbts2ActsSeedingTool.cxx:30
Gbts2ActsSeedingTool::m_pix_h2l
const std::vector< short > * m_pix_h2l
Definition: Gbts2ActsSeedingTool.h:37
SeedingToolBase::extractSeedsFromTheGraph
void extractSeedsFromTheGraph(int, int, int, std::vector< GNN_Edge > &, std::vector< std::tuple< float, int, std::vector< unsigned int > > > &) const
Definition: TrigInDetPattRecoTools/src/SeedingToolBase.cxx:416
Gbts2ActsSeedingTool.h
Gbts2ActsSeedingTool::initialize
virtual StatusCode initialize() override
Definition: Gbts2ActsSeedingTool.cxx:19
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
TrigFTF_GNN_DataStorage::generatePhiIndexing
void generatePhiIndexing(float)
Definition: GNN_DataStorage.cxx:257
beamspotman.n
n
Definition: beamspotman.py:727
Gbts2ActsSeedingTool::createSeeds
virtual StatusCode createSeeds(const EventContext &ctx, const Acts::SpacePointContainer< ActsTrk::SpacePointCollector, Acts::detail::RefHolder > &spContainer, const Acts::Vector3 &beamSpotPos, const Acts::Vector3 &bField, ActsTrk::SeedContainer &seedContainer) const override
Definition: Gbts2ActsSeedingTool.cxx:34
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
SeedingToolBase::finalize
virtual StatusCode finalize()
Definition: TrigInDetPattRecoTools/src/SeedingToolBase.cxx:93
PixelCluster.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
hist_file_dump.f
f
Definition: hist_file_dump.py:140
ActsTrk::SeedContainer::spacePoints
const SpacePointContainer & spacePoints() const noexcept
Definition: SeedContainer.h:41
TrigFTF_GNN_DataStorage::loadPixelGraphNodes
int loadPixelGraphNodes(short, const std::vector< TrigFTF_GNN_Node > &, bool)
Definition: GNN_DataStorage.cxx:105
xAOD::UncalibratedMeasurement_v1::localPosition
ConstVectorMap< N > localPosition() const
Returns the local position of the measurement.
Gbts2ActsSeedingTool::m_sct_h2l
const std::vector< short > * m_sct_h2l
Definition: Gbts2ActsSeedingTool.h:36
ActsTrk::SeedContainer::push_back
Acts::MutableSeedProxy2 push_back(Acts::MutableSeedProxy2 seed)
Definition: SeedContainer.h:89
Gbts2ActsSeedingTool::m_are_pixels
std::vector< bool > m_are_pixels
Definition: Gbts2ActsSeedingTool.h:38
SeedingToolBase::m_layerNumberTool
ToolHandle< ITrigL2LayerNumberTool > m_layerNumberTool
Definition: TrigInDetPattRecoTools/src/SeedingToolBase.h:48
TrigFTF_GNN_DataStorage::initializeNodes
void initializeNodes(bool)
Definition: GNN_DataStorage.cxx:183
SeedingToolBase::m_geo
std::unique_ptr< const TrigFTF_GNN_Geometry > m_geo
Definition: TrigInDetPattRecoTools/src/SeedingToolBase.h:79
SeedingToolBase::m_phiSliceWidth
float m_phiSliceWidth
Definition: TrigInDetPattRecoTools/src/SeedingToolBase.h:75
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:16
python.PyAthena.v
v
Definition: PyAthena.py:154
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
ContainerAccessor.h
xAOD::PixelCluster_v1
Definition: PixelCluster_v1.h:17
y
#define y
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
TrigFTF_GNN_DataStorage::loadStripGraphNodes
int loadStripGraphNodes(short, const std::vector< TrigFTF_GNN_Node > &)
Definition: GNN_DataStorage.cxx:143
SeedingToolBase::m_useML
BooleanProperty m_useML
Definition: TrigInDetPattRecoTools/src/SeedingToolBase.h:57
TrigRoiDescriptor
Athena::TPCnvVers::Current TrigRoiDescriptor
Definition: TrigSteeringEventTPCnv.cxx:68
TrigRoiDescriptor.h
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15
SeedingToolBase::runCCA
int runCCA(int, std::vector< GNN_Edge > &) const
Definition: TrigInDetPattRecoTools/src/SeedingToolBase.cxx:348
node
Definition: node.h:21