75 {
76
77 TrigInDetTrackSeedingResult seedStats;
78
80
81 SG::ReadCondHandle<InDet::BeamSpotData> beamSpotHandle {
m_beamSpotKey, ctx };
83 float shift_x =
vertex.x() - beamSpotHandle->beamTilt(0)*
vertex.z();
84 float shift_y =
vertex.y() - beamSpotHandle->beamTilt(1)*
vertex.z();
85
86 std::unique_ptr<GNNR3_DataStorage> storage = std::make_unique<GNNR3_DataStorage>(*
m_geo);
87
88 int nPixels = 0;
90
93
94 std::map<short, std::vector<IdentifierHash> > detIdMap;
95
97
99
100 if(!sctHandle.isValid()) {
102 return seedStats;
103
104 }
105
106 sctSpacePointsContainer = sctHandle.ptr();
107
108 std::vector<IdentifierHash> listOfSctIds;
109 m_regsel_sct->lookup(ctx)->HashIDList( internalRoI, listOfSctIds );
110
112
113 for(const auto& hashId : listOfSctIds) {
114
115 short layerIndex = h2l->at(static_cast<int>(hashId));
116
117 auto it = detIdMap.find(layerIndex);
118 if(it != detIdMap.end()) (*it).second.push_back(hashId);
119 else {
120 std::vector<IdentifierHash>
v = {hashId};
121 detIdMap.insert(std::make_pair(layerIndex,v));
122 }
123 }
124 }
125
127
129
130 if(!pixHandle.isValid()) {
132 return seedStats;
133 }
134
135 pixelSpacePointsContainer = pixHandle.ptr();
136
137 std::vector<IdentifierHash> listOfPixIds;
138
139 m_regsel_pix->lookup(ctx)->HashIDList( internalRoI, listOfPixIds );
140
142
143 for(const auto& hashId : listOfPixIds) {
144
145 short layerIndex = h2l->at(static_cast<int>(hashId));
146
147 auto it = detIdMap.find(layerIndex);
148 if(it != detIdMap.end()) (*it).second.push_back(hashId);
149 else {
150 std::vector<IdentifierHash>
v = {hashId};
151 detIdMap.insert(std::make_pair(layerIndex,v));
152 }
153 }
154 }
155
157
158 std::unique_ptr<GNNR3_DataStorage> storage = std::make_unique<GNNR3_DataStorage>(*
m_geo);
159
160 std::vector<const Trk::SpacePoint*> vSP;
161
163
164 std::vector<std::vector<GNNR3_Node> > trigSpStorage[2];
165
167
169
170 for(const auto& lColl : detIdMap) {
171
172 short layerIndex = lColl.first;
173
174 int layerKey =
m_geo->getTrigFTF_GNNR3_LayerByIndex(layerIndex)->m_layer.m_subdet;
175
176 bool isPixel = layerKey > 20000;
177
178 auto pCont = isPixel ? pixelSpacePointsContainer : sctSpacePointsContainer;
179
180 int contIdx= isPixel ? 0 : 1;
181
182 int nNewNodes = 0;
183
184 for(const auto& idx : lColl.second) {
185
186 std::vector<GNNR3_Node>& tmpColl = trigSpStorage[contIdx].at(static_cast<int>(idx));
187
188 auto input_coll = pCont->indexFindPtr(idx);
189
190 if(input_coll == nullptr) continue;
191
193
194 nNewNodes += (isPixel) ? storage->loadPixelGraphNodes(layerIndex, tmpColl,
m_useML) : storage->loadStripGraphNodes(layerIndex, tmpColl);
195 }
196
197 if(isPixel) nPixels += nNewNodes;
199 }
200
203
204 storage->sortByPhi();
205 storage->initializeNodes(
m_useML);
207
208 std::vector<GNNR3_Edge> edgeStorage;
209
210 std::pair<int, int> graphStats =
buildTheGraph(internalRoI, storage, edgeStorage);
211
212 ATH_MSG_DEBUG(
"Created graph with "<<graphStats.first<<
" edges and "<<graphStats.second<<
" edge links");
213
216
217 if(graphStats.second == 0) return seedStats;
218
219 int maxLevel =
runCCA(graphStats.first, edgeStorage);
220
221 ATH_MSG_DEBUG(
"Reached Level "<<maxLevel<<
" after GNN iterations");
222
223 int minLevel = 3;
224
226 minLevel = 2;
227 }
228
229 if(maxLevel < minLevel) return seedStats;
230
231 std::vector<GNNR3_Edge*> vSeeds;
232
233 vSeeds.reserve(graphStats.first/2);
234
235 for(int edgeIndex=0;edgeIndex<graphStats.first;edgeIndex++) {
236 GNNR3_Edge* pS = &(edgeStorage.at(edgeIndex));
237
238 if(pS->m_level < minLevel) continue;
239
240 vSeeds.push_back(pS);
241 }
242
243 if(vSeeds.empty()) return seedStats;
244
246
247
248
250
251 output.reserve(vSeeds.size());
252
253 for(auto pS : vSeeds) {
254
255 if(pS->m_level == -1) continue;
256
257 TrigFTF_GNNR3_EdgeState
rs(
false);
258
259 tFilter.followTrack(pS,
rs);
260
261 if(!
rs.m_initialized) {
262 continue;
263 }
264
265 if(
static_cast<int>(
rs.m_vs.size()) < minLevel)
continue;
266
267 std::vector<const GNNR3_Node*> vN;
268
269 for(std::vector<GNNR3_Edge*>::reverse_iterator sIt=
rs.m_vs.rbegin();sIt!=
rs.m_vs.rend();++sIt) {
270
271 (*sIt)->m_level = -1;
272
273 if(sIt ==
rs.m_vs.rbegin()) {
274 vN.push_back((*sIt)->m_n1);
275 }
276 vN.push_back((*sIt)->m_n2);
277 }
278
279 if(vN.size()<3) continue;
280
281 unsigned int lastIdx =
output.size();
283
284 for(const auto& n : vN) {
285 output[lastIdx].addSpacePoint(vSP[
n->m_idx]);
286 }
287 }
288
290 }
291#if 0
292 else {
293
294
295
296
297 std::vector<const Trk::SpacePoint*> vSP;
298 std::vector<short> vL;
299
302
303 std::unique_ptr<TrigAccel::DATA_EXPORT_BUFFER> dataBuffer = std::unique_ptr<TrigAccel::DATA_EXPORT_BUFFER>(
new TrigAccel::DATA_EXPORT_BUFFER(5000));
304
306 const size_t bufferOffset = 256;
307 size_t totalSize = bufferOffset+dataTypeSize;
309
311
312 unsigned int spIdx = 0;
313 int sp_offset = 0;
314 int nLayers = 0;
315 int MaxEtaBin = 0;
317
318 for(const auto& lColl : detIdMap) {
319
320 short layerIndex = lColl.first;
321
322 const TrigFTF_GNNR3_Layer* pL =
m_geo->getTrigFTF_GNNR3_LayerByIndex(layerIndex);
323
325
326 bool isPixel = layerKey > 20000;
328
329 auto pCont = isPixel ? pixelSpacePointsContainer : sctSpacePointsContainer;
330
332
336
339
341
342 for(
auto b : pL->
m_bins) {
343 if(b > MaxEtaBin) MaxEtaBin =
b;
344 }
345
346 for(const auto& idx : lColl.second) {
347
348 auto input_coll = pCont->indexFindPtr(idx);
349
350 if(input_coll == nullptr) continue;
351
352 for(
const auto sp : *input_coll) {
353
354 float cw = -1.0;
355
356 const InDet::PixelCluster* pCL =
dynamic_cast<const InDet::PixelCluster*
>(
sp->clusterList().first);
357 if(pCL != nullptr) {
360 if(cw > 0.2) continue;
361 cw = -1.0;
362 }
363 }
364
365 vSP.emplace_back(
sp);
366 vL.emplace_back(layerIndex);
367
368 const auto&
p =
sp->globalPosition();
369
371
372 memcpy(&pJobData->
m_params[sp_offset], ¶ms[0],
sizeof(params));
373
374 sp_offset += 4;
375 spIdx++;
377 }
379 }
380
382
383 if (isPixel) nPixels += spIdx - pJobData->
m_layerInfo[4*nLayers];
385
386 nLayers++;
387 }
388
394
395
396
397 int pairIdx = 0;
398
399 for(
const auto& bg :
m_geo->bin_groups()) {
400
401 int bin1_idx =
bg.first;
402
403 for(
const auto& bin2_idx :
bg.second) {
406 pairIdx++;
407 }
408 }
409
411
412
413
414 const float ptCoeff = 0.29997*1.9972/2.0;
415
416 float tripletPtMin = 0.8*
m_minPt;
417
418 float maxCurv = ptCoeff/tripletPtMin;
419
420 const float min_deltaPhi = 0.001;
421 const float dphi_coeff = 0.68*maxCurv;
422 const float cut_dphi_max =
m_LRTmode ? 0.07 : 0.012;
423 const float cut_dcurv_max =
m_LRTmode ? 0.015 : 0.001;
424 const float cut_tau_ratio_max =
m_LRTmode ? 0.015 : 0.007;
427
428 const float maxOuterRadius =
m_LRTmode ? 1050.0 : 550.0;
429 const float minDeltaRadius = 2.0;
430
431 const float cut_zMinU = min_z0 + maxOuterRadius*internalRoI.
dzdrMinus();
432 const float cut_zMaxU = max_z0 + maxOuterRadius*internalRoI.
dzdrPlus();
433
434 const float maxKappa_high_eta =
m_LRTmode ? 1.0*maxCurv : std::sqrt(0.8)*maxCurv;
435 const float maxKappa_low_eta =
m_LRTmode ? 1.0*maxCurv : std::sqrt(0.6)*maxCurv;
436
450
451 int minLevel = 3;
452
454 minLevel = 2;
455 }
456
458
460
463
464 ATH_MSG_DEBUG(
"Loaded "<<nPixels<<
" Pixel Spacepoints and "<<nStrips<<
" Strip SpacePoints");
465
466 std::shared_ptr<TrigAccel::OffloadBuffer> pBuff = std::make_shared<TrigAccel::OffloadBuffer>(dataBuffer.get());
467
469
470 if(!pWork) {
472 return seedStats;
473 }
474
476
477 bool workSuccess = pWork->run();
478 if(!workSuccess) {
480 return seedStats;
481 }
482
483 std::shared_ptr<TrigAccel::OffloadBuffer> pOutput = pWork->getOutput();
484
488
490
492
493 unsigned int lastIdx =
output.size();
497 }
498 }
499 }
500 else {
501
502 unsigned int nEdges = pGraph->
m_nEdges;
504
505
506
507 std::vector<GNNR3_Node> nodes;
508
509 nodes.reserve(vSP.size());
510
511 for(
unsigned int idx = 0;
idx < vSP.size();
idx++) {
512
513 nodes.emplace_back(vL[idx]);
514
515 const auto&
pos = vSP[
idx]->globalPosition();
516 float xs =
pos.x() - shift_x;
517 float ys =
pos.y() - shift_y;
519
523 nodes[
idx].m_r = std::sqrt(xs*xs + ys*ys);
524
526
527 }
528
529 std::vector<GNNR3_Edge> edgeStorage;
530
531 std::pair<int, int> graphStats(0,0);
532
533 edgeStorage.resize(nEdges);
534
535 unsigned int edgeSize = nMaxNei + 1 + 2;
536
537 for(
unsigned int idx=0;
idx<nEdges;
idx++) {
538 unsigned int pos =
idx*edgeSize;
539
543
545
546 edgeStorage[
idx].m_n1 = &nodes[node1Idx];
547 edgeStorage[
idx].m_n2 = &nodes[node2Idx];
548 edgeStorage[
idx].m_level = 1;
549 edgeStorage[
idx].m_nNei = nNei;
550 for(
int k=0;
k<nNei;
k++) {
552 }
553 }
554
555 graphStats.first = nEdges;
556 graphStats.second = pGraph->
m_nLinks;
557
558
559
560 int maxLevel =
runCCA(graphStats.first, edgeStorage);
561
562 ATH_MSG_DEBUG(
"Reached Level "<<maxLevel<<
" after GNN iterations");
563
564 if(maxLevel < minLevel) return seedStats;
565
566 std::vector<GNNR3_Edge*> vSeeds;
567
568 vSeeds.reserve(graphStats.first/2);
569
570 for(int edgeIndex=0;edgeIndex<graphStats.first;edgeIndex++) {
571 GNNR3_Edge* pS = &(edgeStorage.at(edgeIndex));
572
573 if(pS->m_level < minLevel) continue;
574
575 vSeeds.push_back(pS);
576 }
577
578 if(vSeeds.empty()) return seedStats;
579
581
582
583
585
586 output.reserve(vSeeds.size());
587
588 for(auto pS : vSeeds) {
589
590 if(pS->m_level == -1) continue;
591
592 TrigFTF_GNNR3_EdgeState
rs(
false);
593
594 tFilter.followTrack(pS,
rs);
595
596 if(!
rs.m_initialized) {
597 continue;
598 }
599
600 if(
static_cast<int>(
rs.m_vs.size()) < minLevel)
continue;
601
602 std::vector<const GNNR3_Node*> vN;
603
604 for(std::vector<GNNR3_Edge*>::reverse_iterator sIt=
rs.m_vs.rbegin();sIt!=
rs.m_vs.rend();++sIt) {
605
606 (*sIt)->m_level = -1;
607
608 if(sIt ==
rs.m_vs.rbegin()) {
609 vN.push_back((*sIt)->m_n1);
610 }
611 vN.push_back((*sIt)->m_n2);
612 }
613
614 if(vN.size()<3) continue;
615
616 unsigned int lastIdx =
output.size();
618
619 for(const auto& n : vN) {
620 output[lastIdx].addSpacePoint(vSP[
n->m_idx]);
621 }
622 }
623 }
624
626 }
627
628#endif
629
630 return seedStats;
631
632}
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