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::pair<float, std::vector<unsigned int> > > vSeedCandidates;
222
224
225 if (vSeedCandidates.empty()) return seedStats;
226
227 for(const auto& seed : vSeedCandidates) {
228
229 unsigned int lastIdx =
output.size();
231
232 for(
const auto& sp_idx :
seed.second) {
233 output[lastIdx].addSpacePoint(vSP[sp_idx]);
234 }
235 }
236
238 }
239 else {
240
241
242 std::vector<const Trk::SpacePoint*> vSP;
243 std::vector<short> vL;
244
247
248 std::unique_ptr<TrigAccel::DATA_EXPORT_BUFFER> dataBuffer = std::unique_ptr<TrigAccel::DATA_EXPORT_BUFFER>(
new TrigAccel::DATA_EXPORT_BUFFER(5000));
249
251 const size_t bufferOffset = 256;
252 size_t totalSize = bufferOffset+dataTypeSize;
254
256
257 unsigned int spIdx = 0;
258 int sp_offset = 0;
259 int nLayers = 0;
260 int MaxEtaBin = 0;
262
263 for(const auto& lColl : detIdMap) {
264
265 short layerIndex = lColl.first;
266
267 const TrigFTF_GNN_Layer* pL =
m_geo->getTrigFTF_GNN_LayerByIndex(layerIndex);
268
270
271 bool isPixel = layerKey > 20000;
273
274 auto pCont = isPixel ? pixelSpacePointsContainer : sctSpacePointsContainer;
275
277
281
284
286
287 for(
auto b : pL->
m_bins) {
288 if(b > MaxEtaBin) MaxEtaBin =
b;
289 }
290
291 for(const auto& idx : lColl.second) {
292
293 auto input_coll = pCont->indexFindPtr(idx);
294
295 if(input_coll == nullptr) continue;
296
297 for(
const auto sp : *input_coll) {
298
299 float cw = -1.0;
300
301 const InDet::PixelCluster* pCL =
dynamic_cast<const InDet::PixelCluster*
>(
sp->clusterList().first);
302 if(pCL != nullptr) {
305 if(cw > 0.2) continue;
306 cw = -1.0;
307 }
308 }
309
310 vSP.emplace_back(
sp);
311 vL.emplace_back(layerIndex);
312
313 const auto&
p =
sp->globalPosition();
314
316
317 memcpy(&pJobData->
m_params[sp_offset], ¶ms[0],
sizeof(params));
318
319 sp_offset += 4;
320 spIdx++;
322 }
324 }
325
327
328 if (isPixel) nPixels += spIdx - pJobData->
m_layerInfo[4*nLayers];
330
331 nLayers++;
332 }
333
334 if(spIdx == 0) return seedStats;
335
340 pJobData->
m_nMaxEdges =
static_cast<unsigned int>(7*spIdx);
341
342
343
344 int pairIdx = 0;
345
346 for(
const auto& bg :
m_geo->bin_groups()) {
347
348 int bin1_idx =
bg.first;
349
350 for(
const auto& bin2_idx :
bg.second) {
353 pairIdx++;
354 }
355 }
356
358
359
360
361 const float ptCoeff = 0.29997*1.9972/2.0;
362
363 float tripletPtMin = 0.8*
m_minPt;
364
365 float maxCurv = ptCoeff/tripletPtMin;
366
367 const float pt_scale = 900/
m_minPt;
368
369 const float min_deltaPhi_low_dr = 0.002*pt_scale;
370 const float dphi_coeff_low_dr = 4.33e-4*pt_scale;
371 const float min_deltaPhi = 0.015*pt_scale;
372 const float dphi_coeff = 2.2e-4*pt_scale;
373
374 const float cut_dphi_max =
m_LRTmode ? 0.07 : 0.012;
375 const float cut_dcurv_max =
m_LRTmode ? 0.015 : 0.001;
376 const float cut_tau_ratio_max =
m_LRTmode ? 0.015f : 0.01;
379
380 const float maxOuterRadius =
m_LRTmode ? 1050.0 : 550.0;
381 const float minDeltaRadius = 2.0;
382
383 const float cut_zMinU = min_z0 + maxOuterRadius*internalRoI.
dzdrMinus();
384 const float cut_zMaxU = max_z0 + maxOuterRadius*internalRoI.
dzdrPlus();
385
386 const float maxKappa =
m_LRTmode ? 1.0*maxCurv : 0.9*maxCurv;
387
402
403 int minLevel = 3;
404
406 minLevel = 2;
407 }
408
410
412
415
416 ATH_MSG_DEBUG(
"Loaded "<<nPixels<<
" Pixel Spacepoints and "<<nStrips<<
" Strip SpacePoints");
417
418 std::shared_ptr<TrigAccel::OffloadBuffer> pBuff = std::make_shared<TrigAccel::OffloadBuffer>(dataBuffer.get());
419
421
422 if(!pWork) {
424 return seedStats;
425 }
426
427 bool workSuccess = pWork->run();
428 if(!workSuccess) {
430 return seedStats;
431 }
432
433 std::shared_ptr<TrigAccel::OffloadBuffer> pOutput = pWork->getOutput();
434
438
440 if(pSeeds->
m_nSeeds == 0)
return seedStats;
441
443
444 unsigned int lastIdx =
output.size();
448 }
449 }
450 }
451 else {
452
453 unsigned int nEdges = pGraph->
m_nEdges;
455
456
457
458 std::vector<GNN_Node> nodes;
459
460 nodes.reserve(vSP.size());
461
462 for(
unsigned int idx = 0;
idx < vSP.size();
idx++) {
463
464 nodes.emplace_back(vL[idx]);
465
466 const auto&
pos = vSP[
idx]->globalPosition();
467 float xs =
pos.x() - shift_x;
468 float ys =
pos.y() - shift_y;
470
474 nodes[
idx].m_r = std::sqrt(xs*xs + ys*ys);
475
477
478 }
479
480 std::vector<GNN_Edge> edgeStorage;
481
482 std::pair<int, int> graphStats(0,0);
483
484 edgeStorage.resize(nEdges);
485
486 unsigned int edgeSize = nMaxNei + 1 + 2;
487
488 for(
unsigned int idx=0;
idx<nEdges;
idx++) {
489 unsigned int pos =
idx*edgeSize;
490
494
496
497 edgeStorage[
idx].m_n1 = &nodes[node1Idx];
498 edgeStorage[
idx].m_n2 = &nodes[node2Idx];
499 edgeStorage[
idx].m_level = 1;
500 edgeStorage[
idx].m_nNei = nNei;
501 for(
int k=0;
k<nNei;
k++) {
503 }
504 }
505
506 graphStats.first = nEdges;
507 graphStats.second = pGraph->
m_nLinks;
508
509
510
511 int maxLevel =
runCCA(graphStats.first, edgeStorage);
512
513 ATH_MSG_DEBUG(
"Reached Level "<<maxLevel<<
" after GNN iterations");
514
515 if(maxLevel < minLevel) return seedStats;
516
517 std::vector<GNN_Edge*> vSeeds;
518
519 vSeeds.reserve(graphStats.first/2);
520
521 for(int edgeIndex=0;edgeIndex<graphStats.first;edgeIndex++) {
522 GNN_Edge* pS = &(edgeStorage.at(edgeIndex));
523
524 if(pS->m_level < minLevel) continue;
525
526 vSeeds.push_back(pS);
527 }
528
529 if(vSeeds.empty()) return seedStats;
530
532
533
534
536
537 output.reserve(vSeeds.size());
538
539 for(auto pS : vSeeds) {
540
541 if(pS->m_level == -1) continue;
542
543 TrigFTF_GNN_EdgeState
rs(
false);
544
545 tFilter.followTrack(pS,
rs);
546
547 if(!
rs.m_initialized) {
548 continue;
549 }
550
551 if(
static_cast<int>(
rs.m_vs.size()) < minLevel)
continue;
552
553 std::vector<const GNN_Node*> vN;
554
555 for(std::vector<GNN_Edge*>::reverse_iterator sIt=
rs.m_vs.rbegin();sIt!=
rs.m_vs.rend();++sIt) {
556
557 (*sIt)->m_level = -1;
558
559 if(sIt ==
rs.m_vs.rbegin()) {
560 vN.push_back((*sIt)->m_n1);
561 }
562 vN.push_back((*sIt)->m_n2);
563 }
564
565 if(vN.size()<3) continue;
566
567 unsigned int lastIdx =
output.size();
569
570 for(const auto& n : vN) {
571 output[lastIdx].addSpacePoint(vSP[
n->m_idx]);
572 }
573 }
574 }
576 }
577 return seedStats;
578}
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