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 #include "GNN_TrackingFilter.h"
11 
12 #include <optional>
13 
15  const std::string& n,
16  const IInterface* p ) : SeedingToolBase(t,n,p)
17 {
18 }
19 
23  m_sct_h2l = m_layerNumberTool->sctLayers();
24  m_pix_h2l = m_layerNumberTool->pixelLayers();
25  m_are_pixels.resize(m_layerNumberTool->maxNumberOfUniqueLayers(), true);
26  for(const auto& l : *m_sct_h2l) m_are_pixels[l] = false;
27 
28  return StatusCode::SUCCESS;
29 }
30 
33 }
34 
35 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 {
36 
37  std::unique_ptr<GNN_DataStorage> storage = std::make_unique<GNN_DataStorage>(*m_geo);
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  const std::vector<xAOD::DetectorIDHashType>& elementlist = extSP.elementIdList() ;
58 
59  bool isPixel(elementlist.size() == 1);
60 
61  short layer = (isPixel ? m_pix_h2l : m_sct_h2l)->at(static_cast<int>(elementlist[0]));
62 
63  //convert incoming xaod spacepoints into GNN nodes
64 
65  GNN_Node& node = node_storage[layer].emplace_back(layer);
66 
67  const auto& pos = extSP.globalPosition();
68 
69  node.m_x = pos.x() - shift_x;
70  node.m_y = pos.y() - shift_y;
71  node.m_z = pos.z();
72  node.m_r = std::sqrt(std::pow(node.m_x, 2) + std::pow(node.m_y, 2));
73  node.m_phi = std::atan2(node.m_y, node.m_x);
74  node.m_idx = idx;
75 
76  if(isPixel && m_useML){
77  const xAOD::PixelCluster* pCL = dynamic_cast<const xAOD::PixelCluster*>(extSP.measurements().front());
78  if(pCL != nullptr){
79  node.m_pcw = pCL->widthInEta();
80  }
81  }
82  }
83 
84  for(size_t l = 0; l < node_storage.size(); l++) {
85 
86  const std::vector<GNN_Node>& nodes = node_storage[l];
87 
88  if(nodes.size() == 0) continue;
89 
90  if(m_are_pixels[l])
91  nPixelLoaded += storage->loadPixelGraphNodes(l, nodes, m_useML);
92  else
93  nStripLoaded += storage->loadStripGraphNodes(l, nodes);
94  }
95 
96  ATH_MSG_DEBUG("Loaded "<<nPixelLoaded<<" pixel spacepoints and "<<nStripLoaded<<" strip spacepoints");
97 
98  storage->sortByPhi();
99 
100  storage->initializeNodes(m_useML);
101 
102  storage->generatePhiIndexing(1.5*m_phiSliceWidth);
103 
104  std::vector<GNN_Edge> edgeStorage;
105 
106  const TrigRoiDescriptor fakeRoi = TrigRoiDescriptor(0, -4.5, 4.5, 0, -M_PI, M_PI, 0, -150.0, 150.0);
107 
108  std::pair<int, int> graphStats = buildTheGraph(fakeRoi, storage, edgeStorage);
109 
110  ATH_MSG_DEBUG("Created graph with "<<graphStats.first<<" edges and "<<graphStats.second<< " edge links");
111 
112  int maxLevel = runCCA(graphStats.first, edgeStorage);
113 
114  ATH_MSG_DEBUG("Reached Level "<<maxLevel<<" after GNN iterations");
115 
116  int minLevel = 3;//a triplet + 2 confirmation
117 
118  if(m_LRTmode) {
119  minLevel = 2;//a triplet + 1 confirmation
120  }
121 
122  if(maxLevel < minLevel) return StatusCode::SUCCESS;
123 
124  std::vector<GNN_Edge*> vSeeds;
125 
126  vSeeds.reserve(graphStats.first/2);
127 
128  for(int edgeIndex = 0; edgeIndex < graphStats.first; edgeIndex++) {
129 
130  GNN_Edge* pS = &(edgeStorage.at(edgeIndex));
131 
132  if(pS->m_level < minLevel) continue;
133 
134  vSeeds.push_back(pS);
135  }
136 
137  if(vSeeds.empty()) return StatusCode::SUCCESS;
138 
139  std::sort(vSeeds.begin(), vSeeds.end(), GNN_Edge::CompareLevel());
140 
141  //backtracking
142 
143  TrigFTF_GNN_TrackingFilter tFilter(m_layerGeometry, edgeStorage);
144 
145  for(auto pS : vSeeds) {
146  if(pS->m_level == -1) continue;
147 
148  TrigFTF_GNN_EdgeState rs(false);
149 
150  tFilter.followTrack(pS, rs);
151 
152  if(!rs.m_initialized) {
153  continue;
154  }
155 
156  if(static_cast<int>(rs.m_vs.size()) < minLevel) continue;
157 
158  std::vector<const GNN_Node*> vN;
159 
160  for(std::vector<GNN_Edge*>::reverse_iterator sIt=rs.m_vs.rbegin();sIt!=rs.m_vs.rend();++sIt) {
161  (*sIt)->m_level = -1;//mark as collected
162 
163  if(sIt == rs.m_vs.rbegin()) {
164  vN.push_back((*sIt)->m_n1);
165  }
166 
167  vN.push_back((*sIt)->m_n2);
168 
169  }
170 
171  if(vN.size()<3) continue;
172 
173  std::vector<const xAOD::SpacePoint*> sps;
174  sps.reserve(vN.size());
175  for (const auto* vNptr : vN) {
176  sps.push_back(&spContainer.at(vNptr->sp_idx()).externalSpacePoint());
177  }
178 
179  //add seed to output
180 
181  std::unique_ptr<ActsTrk::Seed> to_add = std::make_unique<ActsTrk::Seed>(std::move(sps));
182 
183  seedContainer.push_back(std::move(to_add));
184  }
185 
186  ATH_MSG_DEBUG("GBTS created "<<seedContainer.size()<<" seeds");
187 
188  return StatusCode::SUCCESS;
189 }
190 
SeedingToolBase::m_layerGeometry
std::vector< TrigInDetSiLayer > m_layerGeometry
Definition: TrigInDetPattRecoTools/src/SeedingToolBase.h:72
Gbts2ActsSeedingTool::Gbts2ActsSeedingTool
Gbts2ActsSeedingTool(const std::string &, const std::string &, const IInterface *)
Definition: Gbts2ActsSeedingTool.cxx:14
SeedingToolBase::initialize
virtual StatusCode initialize()
Definition: TrigInDetPattRecoTools/src/SeedingToolBase.cxx:19
xAOD::PixelCluster_v1::widthInEta
float widthInEta() const
Returns the width of the cluster in phi (x) and eta (y) directions, respectively.
TrigFTF_GNN_Edge::CompareLevel
Definition: GNN_DataStorage.h:109
SeedingToolBase
Definition: TrigInDetPattRecoTools/src/SeedingToolBase.h:26
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
TrigFTF_GNN_DataStorage::sortByPhi
void sortByPhi()
Definition: GNN_DataStorage.cxx:177
Gbts2ActsSeedingTool::m_beamSpotKey
SG::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey
Definition: Gbts2ActsSeedingTool.h:34
TrigFTF_GNN_EdgeState
Definition: GNN_TrackingFilter.h:11
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:71
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
Gbts2ActsSeedingTool::finalize
virtual StatusCode finalize() override
Definition: Gbts2ActsSeedingTool.cxx:31
Gbts2ActsSeedingTool::m_pix_h2l
const std::vector< short > * m_pix_h2l
Definition: Gbts2ActsSeedingTool.h:37
TrigFTF_GNN_EdgeState::m_vs
std::vector< TrigFTF_GNN_Edge * > m_vs
Definition: GNN_TrackingFilter.h:33
TrigFTF_GNN_EdgeState::m_initialized
bool m_initialized
Definition: GNN_TrackingFilter.h:38
Gbts2ActsSeedingTool.h
Gbts2ActsSeedingTool::initialize
virtual StatusCode initialize() override
Definition: Gbts2ActsSeedingTool.cxx:20
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
SeedingToolBase::m_LRTmode
BooleanProperty m_LRTmode
Definition: TrigInDetPattRecoTools/src/SeedingToolBase.h:51
TrigFTF_GNN_Edge
Definition: GNN_DataStorage.h:106
TrigFTF_GNN_DataStorage::generatePhiIndexing
void generatePhiIndexing(float)
Definition: GNN_DataStorage.cxx:226
TrigFTF_GNN_Edge::m_level
signed char m_level
Definition: GNN_DataStorage.h:128
beamspotman.n
n
Definition: beamspotman.py:729
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:35
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:66
PixelCluster.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
GNN_TrackingFilter.h
TrigFTF_GNN_DataStorage::loadPixelGraphNodes
int loadPixelGraphNodes(short, const std::vector< TrigFTF_GNN_Node > &, bool)
Definition: GNN_DataStorage.cxx:104
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
Gbts2ActsSeedingTool::m_sct_h2l
const std::vector< short > * m_sct_h2l
Definition: Gbts2ActsSeedingTool.h:36
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:43
TrigFTF_GNN_DataStorage::initializeNodes
void initializeNodes(bool)
Definition: GNN_DataStorage.cxx:182
SeedingToolBase::m_geo
std::unique_ptr< const TrigFTF_GNN_Geometry > m_geo
Definition: TrigInDetPattRecoTools/src/SeedingToolBase.h:73
SeedingToolBase::m_phiSliceWidth
float m_phiSliceWidth
Definition: TrigInDetPattRecoTools/src/SeedingToolBase.h:69
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
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
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:142
TrigFTF_GNN_TrackingFilter::followTrack
void followTrack(TrigFTF_GNN_Edge *, TrigFTF_GNN_EdgeState &)
Definition: GNN_TrackingFilter.cxx:82
SeedingToolBase::m_useML
BooleanProperty m_useML
Definition: TrigInDetPattRecoTools/src/SeedingToolBase.h:52
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
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
SeedingToolBase::runCCA
int runCCA(int, std::vector< GNN_Edge > &) const
Definition: TrigInDetPattRecoTools/src/SeedingToolBase.cxx:318
node
Definition: node.h:21
TrigFTF_GNN_TrackingFilter
Definition: GNN_TrackingFilter.h:44