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, 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  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  //Check type in debug build otherwise assume it is correct
78  assert(dynamic_cast<const xAOD::PixelCluster*>(extSP.measurements().front())!=nullptr);
79  const xAOD::PixelCluster* pCL = static_cast<const xAOD::PixelCluster*>(extSP.measurements().front());
80  node.m_pcw = pCL->widthInEta();
81  node.m_locPosY = pCL->localPosition<2>().y();
82  }
83  }
84 
85  for(size_t l = 0; l < node_storage.size(); l++) {
86 
87  const std::vector<GNN_Node>& nodes = node_storage[l];
88 
89  if(nodes.size() == 0) continue;
90 
91  if(m_are_pixels[l])
92  nPixelLoaded += storage->loadPixelGraphNodes(l, nodes, m_useML);
93  else
94  nStripLoaded += storage->loadStripGraphNodes(l, nodes);
95  }
96 
97  ATH_MSG_DEBUG("Loaded "<<nPixelLoaded<<" pixel spacepoints and "<<nStripLoaded<<" strip spacepoints");
98 
99  storage->sortByPhi();
100 
101  storage->initializeNodes(m_useML);
102 
104 
105  std::vector<GNN_Edge> edgeStorage;
106 
107  const TrigRoiDescriptor fakeRoi = TrigRoiDescriptor(0, -4.5, 4.5, 0, -M_PI, M_PI, 0, -150.0, 150.0);
108 
109  std::pair<int, int> graphStats = buildTheGraph(fakeRoi, storage, edgeStorage);
110 
111  ATH_MSG_DEBUG("Created graph with "<<graphStats.first<<" edges and "<<graphStats.second<< " edge links");
112 
113  int maxLevel = runCCA(graphStats.first, edgeStorage);
114 
115  ATH_MSG_DEBUG("Reached Level "<<maxLevel<<" after GNN iterations");
116 
117  int minLevel = 3;//a triplet + 2 confirmation
118 
119  if(m_LRTmode) {
120  minLevel = 2;//a triplet + 1 confirmation
121  }
122 
123  if(maxLevel < minLevel) return StatusCode::SUCCESS;
124 
125  std::vector<GNN_Edge*> vSeeds;
126 
127  vSeeds.reserve(graphStats.first/2);
128 
129  for(int edgeIndex = 0; edgeIndex < graphStats.first; edgeIndex++) {
130 
131  GNN_Edge* pS = &(edgeStorage.at(edgeIndex));
132 
133  if(pS->m_level < minLevel) continue;
134 
135  vSeeds.push_back(pS);
136  }
137 
138  if(vSeeds.empty()) return StatusCode::SUCCESS;
139 
140  std::sort(vSeeds.begin(), vSeeds.end(), GNN_Edge::CompareLevel());
141 
142  //backtracking
143 
144  TrigFTF_GNN_TrackingFilter tFilter(m_layerGeometry, edgeStorage);
145 
146  for(auto pS : vSeeds) {
147  if(pS->m_level == -1) continue;
148 
149  TrigFTF_GNN_EdgeState rs(false);
150 
151  tFilter.followTrack(pS, rs);
152 
153  if(!rs.m_initialized) {
154  continue;
155  }
156 
157  if(static_cast<int>(rs.m_vs.size()) < minLevel) continue;
158 
159  std::vector<const GNN_Node*> vN;
160 
161  for(std::vector<GNN_Edge*>::reverse_iterator sIt=rs.m_vs.rbegin();sIt!=rs.m_vs.rend();++sIt) {
162  (*sIt)->m_level = -1;//mark as collected
163 
164  if(sIt == rs.m_vs.rbegin()) {
165  vN.push_back((*sIt)->m_n1);
166  }
167 
168  vN.push_back((*sIt)->m_n2);
169 
170  }
171 
172  if(vN.size()<3) continue;
173 
174  std::vector<const xAOD::SpacePoint*> sps;
175  sps.reserve(vN.size());
176  for (const auto* vNptr : vN) {
177  sps.push_back(&spContainer.at(vNptr->sp_idx()).externalSpacePoint());
178  }
179 
180  //add seed to output
181 
182  std::unique_ptr<ActsTrk::Seed> to_add = std::make_unique<ActsTrk::Seed>(std::move(sps));
183 
184  seedContainer.push_back(std::move(to_add));
185  }
186 
187  ATH_MSG_DEBUG("GBTS created "<<seedContainer.size()<<" seeds");
188 
189  return StatusCode::SUCCESS;
190 }
191 
SeedingToolBase::m_layerGeometry
std::vector< TrigInDetSiLayer > m_layerGeometry
Definition: TrigInDetPattRecoTools/src/SeedingToolBase.h:73
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:111
SeedingToolBase
Definition: TrigInDetPattRecoTools/src/SeedingToolBase.h:26
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
TrigFTF_GNN_DataStorage::sortByPhi
void sortByPhi()
Definition: GNN_DataStorage.cxx:178
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:93
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:75
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:108
TrigFTF_GNN_DataStorage::generatePhiIndexing
void generatePhiIndexing(float)
Definition: GNN_DataStorage.cxx:254
TrigFTF_GNN_Edge::m_level
signed char m_level
Definition: GNN_DataStorage.h:130
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: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:88
PixelCluster.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
hist_file_dump.f
f
Definition: hist_file_dump.py:140
GNN_TrackingFilter.h
TrigFTF_GNN_DataStorage::loadPixelGraphNodes
int loadPixelGraphNodes(short, const std::vector< TrigFTF_GNN_Node > &, bool)
Definition: GNN_DataStorage.cxx:105
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
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
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:183
SeedingToolBase::m_geo
std::unique_ptr< const TrigFTF_GNN_Geometry > m_geo
Definition: TrigInDetPattRecoTools/src/SeedingToolBase.h:74
SeedingToolBase::m_phiSliceWidth
float m_phiSliceWidth
Definition: TrigInDetPattRecoTools/src/SeedingToolBase.h:70
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
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
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:340
node
Definition: node.h:21
TrigFTF_GNN_TrackingFilter
Definition: GNN_TrackingFilter.h:44