73 {
74
75 TrigInDetTrackSeedingResult seedStats;
76
78
79 SG::ReadCondHandle<InDet::BeamSpotData> beamSpotHandle {
m_beamSpotKey, ctx };
81 float shift_x =
vertex.x() - beamSpotHandle->beamTilt(0)*
vertex.z();
82 float shift_y =
vertex.y() - beamSpotHandle->beamTilt(1)*
vertex.z();
83
84
85 int nPixels = 0;
87
90
91 std::map<short, std::vector<IdentifierHash> > detIdMap;
92
94
96
97 if(!sctHandle.isValid()) {
99 return seedStats;
100
101 }
102
103 sctSpacePointsContainer = sctHandle.ptr();
104
105 std::vector<IdentifierHash> listOfSctIds;
106 m_regsel_sct->lookup(ctx)->HashIDList( internalRoI, listOfSctIds );
107
109
110 for(const auto& hashId : listOfSctIds) {
111
112 short layerIndex = h2l->at(static_cast<int>(hashId));
113
114 auto it = detIdMap.find(layerIndex);
115 if(it != detIdMap.end()) (*it).second.push_back(hashId);
116 else {
117 std::vector<IdentifierHash>
v = {hashId};
118 detIdMap.insert(std::make_pair(layerIndex,v));
119 }
120 }
121 }
122
124
126
127 if(!pixHandle.isValid()) {
129 return seedStats;
130 }
131
132 pixelSpacePointsContainer = pixHandle.ptr();
133
134 std::vector<IdentifierHash> listOfPixIds;
135
136 m_regsel_pix->lookup(ctx)->HashIDList( internalRoI, listOfPixIds );
137
139
140 for(const auto& hashId : listOfPixIds) {
141
142 short layerIndex = h2l->at(static_cast<int>(hashId));
143
144 auto it = detIdMap.find(layerIndex);
145 if(it != detIdMap.end()) (*it).second.push_back(hashId);
146 else {
147 std::vector<IdentifierHash>
v = {hashId};
148 detIdMap.insert(std::make_pair(layerIndex,v));
149 }
150 }
151 }
152
154
155 std::unique_ptr<GNN_DataStorage> storage = std::make_unique<GNN_DataStorage>(*
m_geo,
m_mlLUT);
156
157 std::vector<const Trk::SpacePoint*> vSP;
158
160
161 std::vector<std::vector<GNN_Node> > trigSpStorage[2];
162
164
166
167 for(const auto& lColl : detIdMap) {
168
169 short layerIndex = lColl.first;
170
171 int layerKey =
m_geo->getTrigFTF_GNN_LayerByIndex(layerIndex)->m_layer.m_subdet;
172
173 bool isPixel = layerKey > 20000;
174
175 auto pCont = isPixel ? pixelSpacePointsContainer : sctSpacePointsContainer;
176
177 int contIdx= isPixel ? 0 : 1;
178
179 int nNewNodes = 0;
180
181 for(const auto& idx : lColl.second) {
182
183 std::vector<GNN_Node>& tmpColl = trigSpStorage[contIdx].at(static_cast<int>(idx));
184
185 auto input_coll = pCont->indexFindPtr(idx);
186
187 if(input_coll == nullptr) continue;
188
190
191 nNewNodes += (isPixel) ? storage->loadPixelGraphNodes(layerIndex, tmpColl,
m_useML) : storage->loadStripGraphNodes(layerIndex, tmpColl);
192 }
193
194 if(isPixel) nPixels += nNewNodes;
196 }
197
200
201 storage->sortByPhi();
202 storage->initializeNodes(
m_useML);
204
205 std::vector<GNN_Edge> edgeStorage;
206
207 std::pair<int, int> graphStats =
buildTheGraph(internalRoI, storage, edgeStorage);
208
209 ATH_MSG_DEBUG(
"Created graph with "<<graphStats.first<<
" edges and "<<graphStats.second<<
" edge links");
210
213
214 if (graphStats.second == 0) return seedStats;
215
216 int maxLevel =
runCCA(graphStats.first, edgeStorage);
217
218 ATH_MSG_DEBUG(
"Reached Level "<<maxLevel<<
" after GNN iterations");
219
220 std::vector<std::pair<float, std::vector<unsigned int> > > vSeedCandidates;
221
223
224 if (vSeedCandidates.empty()) return seedStats;
225
226 for(const auto& seed : vSeedCandidates) {
227
228 unsigned int lastIdx =
output.size();
230
231 for(
const auto& sp_idx :
seed.second) {
232 output[lastIdx].addSpacePoint(vSP[sp_idx]);
233 }
234 }
235
237 }
238 else {
239
240
241 std::vector<const Trk::SpacePoint*> vSP;
242 std::vector<short> vL;
243
246
247 std::unique_ptr<TrigAccel::DATA_EXPORT_BUFFER> dataBuffer = std::unique_ptr<TrigAccel::DATA_EXPORT_BUFFER>(
new TrigAccel::DATA_EXPORT_BUFFER(5000));
248
250 const size_t bufferOffset = 256;
251 size_t totalSize = bufferOffset+dataTypeSize;
253
255
256 unsigned int spIdx = 0;
257 int sp_offset = 0;
258 int nLayers = 0;
259 int MaxEtaBin = 0;
261
262 for(const auto& lColl : detIdMap) {
263
264 short layerIndex = lColl.first;
265
266 const TrigFTF_GNN_Layer* pL =
m_geo->getTrigFTF_GNN_LayerByIndex(layerIndex);
267
269
270 bool isPixel = layerKey > 20000;
272
273 auto pCont = isPixel ? pixelSpacePointsContainer : sctSpacePointsContainer;
274
276
280
283
285
286 for(
auto b : pL->
m_bins) {
287 if(b > MaxEtaBin) MaxEtaBin =
b;
288 }
289
290 for(const auto& idx : lColl.second) {
291
292 auto input_coll = pCont->indexFindPtr(idx);
293
294 if(input_coll == nullptr) continue;
295
296 for(
const auto sp : *input_coll) {
297
298 float cw = -1.0;
299
300 const InDet::PixelCluster* pCL =
dynamic_cast<const InDet::PixelCluster*
>(
sp->clusterList().first);
301 if(pCL != nullptr) {
304 if(cw > 0.2) continue;
305 cw = -1.0;
306 }
307 }
308
309 vSP.emplace_back(
sp);
310 vL.emplace_back(layerIndex);
311
312 const auto&
p =
sp->globalPosition();
313
315
316 memcpy(&pJobData->
m_params[sp_offset], ¶ms[0],
sizeof(params));
317
318 sp_offset += 4;
319 spIdx++;
321 }
323 }
324
326
327 if (isPixel) nPixels += spIdx - pJobData->
m_layerInfo[4*nLayers];
329
330 nLayers++;
331 }
332
333 if(spIdx == 0) return seedStats;
334
339 pJobData->
m_nMaxEdges =
static_cast<unsigned int>(7*spIdx);
340
341
342
343 int pairIdx = 0;
344
345 for(
const auto& bg :
m_geo->bin_groups()) {
346
347 int bin1_idx =
bg.first;
348
349 for(
const auto& bin2_idx :
bg.second) {
352 pairIdx++;
353 }
354 }
355
357
358
359
360 const float ptCoeff = 0.29997*1.9972/2.0;
361
362 float tripletPtMin = 0.8*
m_minPt;
363
364 float maxCurv = ptCoeff/tripletPtMin;
365
366 const float pt_scale = 900/
m_minPt;
367
368 const float min_deltaPhi_low_dr = 0.002*pt_scale;
369 const float dphi_coeff_low_dr = 4.33e-4*pt_scale;
370 const float min_deltaPhi = 0.015*pt_scale;
371 const float dphi_coeff = 2.2e-4*pt_scale;
372
373 const float cut_dphi_max =
m_LRTmode ? 0.07 : 0.012;
374 const float cut_dcurv_max =
m_LRTmode ? 0.015 : 0.001;
375 const float cut_tau_ratio_max =
m_LRTmode ? 0.015f : 0.01;
378
379 const float maxOuterRadius =
m_LRTmode ? 1050.0 : 550.0;
380 const float minDeltaRadius = 2.0;
381
382 const float cut_zMinU = min_z0 + maxOuterRadius*internalRoI.
dzdrMinus();
383 const float cut_zMaxU = max_z0 + maxOuterRadius*internalRoI.
dzdrPlus();
384
385 const float maxKappa =
m_LRTmode ? 1.0*maxCurv : 0.9*maxCurv;
386
401
402 int minLevel = 3;
403
405 minLevel = 2;
406 }
407
409
411
414
415 ATH_MSG_DEBUG(
"Loaded "<<nPixels<<
" Pixel Spacepoints and "<<nStrips<<
" Strip SpacePoints");
416
417 std::shared_ptr<TrigAccel::OffloadBuffer> pBuff = std::make_shared<TrigAccel::OffloadBuffer>(dataBuffer.get());
418
420
421 if(!pWork) {
423 return seedStats;
424 }
425
426 bool workSuccess = pWork->run();
427 if(!workSuccess) {
429 return seedStats;
430 }
431
432 std::shared_ptr<TrigAccel::OffloadBuffer> pOutput = pWork->getOutput();
433
437
439 if(pSeeds->
m_nSeeds == 0)
return seedStats;
440
442
443 unsigned int lastIdx =
output.size();
447 }
448 }
449 }
450 else {
451
452 unsigned int nEdges = pGraph->
m_nEdges;
454
455
456
457 std::vector<GNN_Node> nodes;
458 nodes.reserve(vSP.size());
459
460 for(
unsigned int idx = 0;
idx < vSP.size();
idx++) {
461 nodes.emplace_back(static_cast<unsigned short>(vL[idx]));
462 auto &node = nodes.back();
463
464 const auto&
pos = vSP[
idx]->globalPosition();
465 float xs =
pos.x() - shift_x;
466 float ys =
pos.y() - shift_y;
467
468 node.m_x = xs;
469 node.m_y = ys;
471 node.m_r = std::sqrt(xs*xs + ys*ys);
473
474 }
475
476 std::vector<GNN_Edge> edgeStorage;
477
478 std::pair<int, int> graphStats(0,0);
479
480 edgeStorage.resize(nEdges);
481
482 unsigned int edgeSize = nMaxNei + 1 + 2;
483
484 for(
unsigned int idx=0;
idx<nEdges;
idx++) {
485 unsigned int pos =
idx*edgeSize;
486
490 if (node1Idx < 0 || std::cmp_greater_equal(node1Idx, nodes.size()) ||
491 node2Idx < 0 || std::cmp_greater_equal(node2Idx, nodes.size())) {
492
493 continue;
494 }
496
497
498 edgeStorage[
idx].m_n1 = &nodes[node1Idx];
499
500
501 edgeStorage[
idx].m_n2 = &nodes[node2Idx];
502
503 edgeStorage[
idx].m_level = 1;
504 edgeStorage[
idx].m_nNei = nNei;
505 for(
int k=0;
k<nNei;
k++) {
507 }
508 }
509
510 graphStats.first = nEdges;
511 graphStats.second = pGraph->
m_nLinks;
512
513
514
515 int maxLevel =
runCCA(graphStats.first, edgeStorage);
516
517 ATH_MSG_DEBUG(
"Reached Level "<<maxLevel<<
" after GNN iterations");
518
519 if(maxLevel < minLevel) return seedStats;
520
521 std::vector<GNN_Edge*> vSeeds;
522
523 vSeeds.reserve(graphStats.first/2);
524
525 for(int edgeIndex=0;edgeIndex<graphStats.first;edgeIndex++) {
526 GNN_Edge* pS = &(edgeStorage.at(edgeIndex));
527
528 if(pS->m_level < minLevel) continue;
529
530 vSeeds.push_back(pS);
531 }
532
533 if(vSeeds.empty()) return seedStats;
534
536
537
538
539
540
542
543 output.reserve(vSeeds.size());
544
545 for(auto pS : vSeeds) {
546
547 if(pS->m_level == -1) continue;
548
549 TrigFTF_GNN_EdgeState
rs(
false);
550
551 tFilter.followTrack(pS,
rs);
552
553 if(!
rs.m_initialized) {
554 continue;
555 }
556
557 if(
static_cast<int>(
rs.m_vs.size()) < minLevel)
continue;
558
559 std::vector<const GNN_Node*> vN;
560
561 for(std::vector<GNN_Edge*>::reverse_iterator sIt=
rs.m_vs.rbegin();sIt!=
rs.m_vs.rend();++sIt) {
562
563 (*sIt)->m_level = -1;
564
565 if(sIt ==
rs.m_vs.rbegin()) {
566 vN.push_back((*sIt)->m_n1);
567 }
568 vN.push_back((*sIt)->m_n2);
569 }
570
571 if(vN.size()<3) continue;
572
573 unsigned int lastIdx =
output.size();
575
576 for(const auto& n : vN) {
577 output[lastIdx].addSpacePoint(vSP[
n->m_idx]);
578 }
579 }
580 }
582 }
583 return seedStats;
584}
#define ATH_MSG_DEBUG(x,...)
static unsigned int totalSize(const MultiDimArray< T, N > &ht)
const Amg::Vector2D & widthPhiRZ() const
const TrigInDetSiLayer & m_layer
std::vector< int > m_bins
Eigen::Matrix< double, 3, 1 > Vector3D
int nStrips(const MuonGM::TgcReadoutElement &readoutEle, int layer)
constexpr unsigned nEtaBins
struct TrigAccel::ITk::GraphMakingInputData GRAPH_MAKING_INPUT_DATA
static constexpr unsigned int GBTS_MAX_NUMBER_SPACEPOINTS
static constexpr unsigned char nNei
static constexpr unsigned char node1
static constexpr unsigned char node2
struct TrigAccel::ITk::OutputSeeds OUTPUT_SEEDS
struct TrigAccel::ITk::GraphAndSeedsOutput GRAPH_AND_SEEDS_OUTPUT
static constexpr unsigned char nei_idx_start
struct TrigAccel::ITk::CompressedGraph COMPRESSED_GRAPH
struct TrigAccel::DataExportBuffer DATA_EXPORT_BUFFER
SpacePointContainer_v1 SpacePointContainer
Define the version of the space point container.
std::unique_ptr< int[]> m_graphArray
unsigned int m_nMaxNeighbours
OUTPUT_SEEDS m_OutputSeeds
COMPRESSED_GRAPH m_CompressedGraph
std::unique_ptr< Tracklet[]> m_seedsArray