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 std::unique_ptr<GNN_DataStorage> storage = std::make_unique<GNN_DataStorage>(*
m_geo,
m_mlLUT);
85
86 int nPixels = 0;
88
91
92 std::map<short, std::vector<IdentifierHash> > detIdMap;
93
95
97
98 if(!sctHandle.isValid()) {
100 return seedStats;
101
102 }
103
104 sctSpacePointsContainer = sctHandle.ptr();
105
106 std::vector<IdentifierHash> listOfSctIds;
107 m_regsel_sct->lookup(ctx)->HashIDList( internalRoI, listOfSctIds );
108
110
111 for(const auto& hashId : listOfSctIds) {
112
113 short layerIndex = h2l->at(static_cast<int>(hashId));
114
115 auto it = detIdMap.find(layerIndex);
116 if(it != detIdMap.end()) (*it).second.push_back(hashId);
117 else {
118 std::vector<IdentifierHash>
v = {hashId};
119 detIdMap.insert(std::make_pair(layerIndex,v));
120 }
121 }
122 }
123
125
127
128 if(!pixHandle.isValid()) {
130 return seedStats;
131 }
132
133 pixelSpacePointsContainer = pixHandle.ptr();
134
135 std::vector<IdentifierHash> listOfPixIds;
136
137 m_regsel_pix->lookup(ctx)->HashIDList( internalRoI, listOfPixIds );
138
140
141 for(const auto& hashId : listOfPixIds) {
142
143 short layerIndex = h2l->at(static_cast<int>(hashId));
144
145 auto it = detIdMap.find(layerIndex);
146 if(it != detIdMap.end()) (*it).second.push_back(hashId);
147 else {
148 std::vector<IdentifierHash>
v = {hashId};
149 detIdMap.insert(std::make_pair(layerIndex,v));
150 }
151 }
152 }
153
155
156 std::unique_ptr<GNN_DataStorage> storage = std::make_unique<GNN_DataStorage>(*
m_geo,
m_mlLUT);
157
158 std::vector<const Trk::SpacePoint*> vSP;
159
161
162 std::vector<std::vector<GNN_Node> > trigSpStorage[2];
163
165
167
168 for(const auto& lColl : detIdMap) {
169
170 short layerIndex = lColl.first;
171
172 int layerKey =
m_geo->getTrigFTF_GNN_LayerByIndex(layerIndex)->m_layer.m_subdet;
173
174 bool isPixel = layerKey > 20000;
175
176 auto pCont = isPixel ? pixelSpacePointsContainer : sctSpacePointsContainer;
177
178 int contIdx= isPixel ? 0 : 1;
179
180 int nNewNodes = 0;
181
182 for(const auto& idx : lColl.second) {
183
184 std::vector<GNN_Node>& tmpColl = trigSpStorage[contIdx].at(static_cast<int>(idx));
185
186 auto input_coll = pCont->indexFindPtr(idx);
187
188 if(input_coll == nullptr) continue;
189
191
192 nNewNodes += (isPixel) ? storage->loadPixelGraphNodes(layerIndex, tmpColl,
m_useML) : storage->loadStripGraphNodes(layerIndex, tmpColl);
193 }
194
195 if(isPixel) nPixels += nNewNodes;
197 }
198
201
202 storage->sortByPhi();
203 storage->initializeNodes(
m_useML);
205
206 std::vector<GNN_Edge> edgeStorage;
207
208 std::pair<int, int> graphStats =
buildTheGraph(internalRoI, storage, edgeStorage);
209
210 ATH_MSG_DEBUG(
"Created graph with "<<graphStats.first<<
" edges and "<<graphStats.second<<
" edge links");
211
214
215 if (graphStats.second == 0) return seedStats;
216
217 int maxLevel =
runCCA(graphStats.first, edgeStorage);
218
219 ATH_MSG_DEBUG(
"Reached Level "<<maxLevel<<
" after GNN iterations");
220
221 std::vector<std::tuple<float, int, std::vector<unsigned int> > > vSeedCandidates;
222
224
225 if (vSeedCandidates.empty()) return seedStats;
226
227 for(const auto& seed : vSeedCandidates) {
228
229 if (std::get<1>(seed) != 0) continue;
230
231 unsigned int lastIdx =
output.size();
232 output.emplace_back(std::get<0>(seed));
233
234 for(const auto& sp_idx : std::get<2>(seed)) {
235 output[lastIdx].addSpacePoint(vSP[sp_idx]);
236 }
237 }
238
240 }
241 else {
242
243
244 std::vector<const Trk::SpacePoint*> vSP;
245 std::vector<short> vL;
246
249
250 std::unique_ptr<TrigAccel::DATA_EXPORT_BUFFER> dataBuffer = std::unique_ptr<TrigAccel::DATA_EXPORT_BUFFER>(
new TrigAccel::DATA_EXPORT_BUFFER(5000));
251
253 const size_t bufferOffset = 256;
254 size_t totalSize = bufferOffset+dataTypeSize;
256
258
259 unsigned int spIdx = 0;
260 int sp_offset = 0;
261 int nLayers = 0;
262 int MaxEtaBin = 0;
264
265 for(const auto& lColl : detIdMap) {
266
267 short layerIndex = lColl.first;
268
269 const TrigFTF_GNN_Layer* pL =
m_geo->getTrigFTF_GNN_LayerByIndex(layerIndex);
270
272
273 bool isPixel = layerKey > 20000;
275
276 auto pCont = isPixel ? pixelSpacePointsContainer : sctSpacePointsContainer;
277
279
283
286
288
289 for(
auto b : pL->
m_bins) {
290 if(b > MaxEtaBin) MaxEtaBin =
b;
291 }
292
293 for(const auto& idx : lColl.second) {
294
295 auto input_coll = pCont->indexFindPtr(idx);
296
297 if(input_coll == nullptr) continue;
298
299 for(
const auto sp : *input_coll) {
300
301 float cw = -1.0;
302
303 const InDet::PixelCluster* pCL =
dynamic_cast<const InDet::PixelCluster*
>(
sp->clusterList().first);
304 if(pCL != nullptr) {
307 if(cw > 0.2) continue;
308 cw = -1.0;
309 }
310 }
311
312 vSP.emplace_back(
sp);
313 vL.emplace_back(layerIndex);
314
315 const auto&
p =
sp->globalPosition();
316
318
319 memcpy(&pJobData->
m_params[sp_offset], ¶ms[0],
sizeof(params));
320
321 sp_offset += 4;
322 spIdx++;
324 }
326 }
327
329
330 if (isPixel) nPixels += spIdx - pJobData->
m_layerInfo[4*nLayers];
332
333 nLayers++;
334 }
335
336 if(spIdx == 0) return seedStats;
337
342 pJobData->
m_nMaxEdges =
static_cast<unsigned int>(7*spIdx);
343
344
345
346 int pairIdx = 0;
347
348 for(
const auto& bg :
m_geo->bin_groups()) {
349
350 int bin1_idx =
bg.first;
351
352 for(
const auto& bin2_idx :
bg.second) {
355 pairIdx++;
356 }
357 }
358
360
361
362
363 const float ptCoeff = 0.29997*1.9972/2.0;
364
365 float tripletPtMin = 0.8*
m_minPt;
366
367 float maxCurv = ptCoeff/tripletPtMin;
368
369 const float pt_scale = 900/
m_minPt;
370
371 const float min_deltaPhi_low_dr = 0.002*pt_scale;
372 const float dphi_coeff_low_dr = 4.33e-4*pt_scale;
373 const float min_deltaPhi = 0.015*pt_scale;
374 const float dphi_coeff = 2.2e-4*pt_scale;
375
376 const float cut_dphi_max =
m_LRTmode ? 0.07 : 0.012;
377 const float cut_dcurv_max =
m_LRTmode ? 0.015 : 0.001;
378 const float cut_tau_ratio_max =
m_LRTmode ? 0.015f : 0.01;
381
382 const float maxOuterRadius =
m_LRTmode ? 1050.0 : 550.0;
383 const float minDeltaRadius = 2.0;
384
385 const float cut_zMinU = min_z0 + maxOuterRadius*internalRoI.
dzdrMinus();
386 const float cut_zMaxU = max_z0 + maxOuterRadius*internalRoI.
dzdrPlus();
387
388 const float maxKappa =
m_LRTmode ? 1.0*maxCurv : 0.9*maxCurv;
389
404
405 int minLevel = 3;
406
408 minLevel = 2;
409 }
410
412
414
417
418 ATH_MSG_DEBUG(
"Loaded "<<nPixels<<
" Pixel Spacepoints and "<<nStrips<<
" Strip SpacePoints");
419
420 std::shared_ptr<TrigAccel::OffloadBuffer> pBuff = std::make_shared<TrigAccel::OffloadBuffer>(dataBuffer.get());
421
423
424 if(!pWork) {
426 return seedStats;
427 }
428
429 bool workSuccess = pWork->run();
430 if(!workSuccess) {
432 return seedStats;
433 }
434
435 std::shared_ptr<TrigAccel::OffloadBuffer> pOutput = pWork->getOutput();
436
440
442 if(pSeeds->
m_nSeeds == 0)
return seedStats;
443
445
446 unsigned int lastIdx =
output.size();
450 }
451 }
452 }
453 else {
454
455 unsigned int nEdges = pGraph->
m_nEdges;
457
458
459
460 std::vector<GNN_Node> nodes;
461
462 nodes.reserve(vSP.size());
463
464 for(
unsigned int idx = 0;
idx < vSP.size();
idx++) {
465
466 nodes.emplace_back(vL[idx]);
467
468 const auto&
pos = vSP[
idx]->globalPosition();
469 float xs =
pos.x() - shift_x;
470 float ys =
pos.y() - shift_y;
472
476 nodes[
idx].m_r = std::sqrt(xs*xs + ys*ys);
477
479
480 }
481
482 std::vector<GNN_Edge> edgeStorage;
483
484 std::pair<int, int> graphStats(0,0);
485
486 edgeStorage.resize(nEdges);
487
488 unsigned int edgeSize = nMaxNei + 1 + 2;
489
490 for(
unsigned int idx=0;
idx<nEdges;
idx++) {
491 unsigned int pos =
idx*edgeSize;
492
496
498
499 edgeStorage[
idx].m_n1 = &nodes[node1Idx];
500 edgeStorage[
idx].m_n2 = &nodes[node2Idx];
501 edgeStorage[
idx].m_level = 1;
502 edgeStorage[
idx].m_nNei = nNei;
503 for(
int k=0;
k<nNei;
k++) {
505 }
506 }
507
508 graphStats.first = nEdges;
509 graphStats.second = pGraph->
m_nLinks;
510
511
512
513 int maxLevel =
runCCA(graphStats.first, edgeStorage);
514
515 ATH_MSG_DEBUG(
"Reached Level "<<maxLevel<<
" after GNN iterations");
516
517 if(maxLevel < minLevel) return seedStats;
518
519 std::vector<GNN_Edge*> vSeeds;
520
521 vSeeds.reserve(graphStats.first/2);
522
523 for(int edgeIndex=0;edgeIndex<graphStats.first;edgeIndex++) {
524 GNN_Edge* pS = &(edgeStorage.at(edgeIndex));
525
526 if(pS->m_level < minLevel) continue;
527
528 vSeeds.push_back(pS);
529 }
530
531 if(vSeeds.empty()) return seedStats;
532
534
535
536
538
539 output.reserve(vSeeds.size());
540
541 for(auto pS : vSeeds) {
542
543 if(pS->m_level == -1) continue;
544
545 TrigFTF_GNN_EdgeState
rs(
false);
546
547 tFilter.followTrack(pS,
rs);
548
549 if(!
rs.m_initialized) {
550 continue;
551 }
552
553 if(
static_cast<int>(
rs.m_vs.size()) < minLevel)
continue;
554
555 std::vector<const GNN_Node*> vN;
556
557 for(std::vector<GNN_Edge*>::reverse_iterator sIt=
rs.m_vs.rbegin();sIt!=
rs.m_vs.rend();++sIt) {
558
559 (*sIt)->m_level = -1;
560
561 if(sIt ==
rs.m_vs.rbegin()) {
562 vN.push_back((*sIt)->m_n1);
563 }
564 vN.push_back((*sIt)->m_n2);
565 }
566
567 if(vN.size()<3) continue;
568
569 unsigned int lastIdx =
output.size();
571
572 for(const auto& n : vN) {
573 output[lastIdx].addSpacePoint(vSP[
n->m_idx]);
574 }
575 }
576 }
578 }
579 return seedStats;
580}
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