83 float shift_x = vertex.x() - beamSpotHandle->beamTilt(0)*vertex.z();
84 float shift_y = vertex.y() - beamSpotHandle->beamTilt(1)*vertex.z();
86 std::unique_ptr<GNNR3_DataStorage> storage = std::make_unique<GNNR3_DataStorage>(*
m_geo);
94 std::map<short, std::vector<IdentifierHash> > detIdMap;
106 sctSpacePointsContainer = sctHandle.
ptr();
108 std::vector<IdentifierHash> listOfSctIds;
109 m_regsel_sct->lookup(ctx)->HashIDList( internalRoI, listOfSctIds );
113 for(
const auto& hashId : listOfSctIds) {
115 short layerIndex = h2l->at(
static_cast<int>(hashId));
117 auto it = detIdMap.find(layerIndex);
118 if(it != detIdMap.end()) (*it).second.push_back(hashId);
120 std::vector<IdentifierHash> v = {hashId};
121 detIdMap.insert(std::make_pair(layerIndex,v));
135 pixelSpacePointsContainer = pixHandle.
ptr();
137 std::vector<IdentifierHash> listOfPixIds;
139 m_regsel_pix->lookup(ctx)->HashIDList( internalRoI, listOfPixIds );
143 for(
const auto& hashId : listOfPixIds) {
145 short layerIndex = h2l->at(
static_cast<int>(hashId));
147 auto it = detIdMap.find(layerIndex);
148 if(it != detIdMap.end()) (*it).second.push_back(hashId);
150 std::vector<IdentifierHash> v = {hashId};
151 detIdMap.insert(std::make_pair(layerIndex,v));
158 std::unique_ptr<GNNR3_DataStorage> storage = std::make_unique<GNNR3_DataStorage>(*
m_geo);
160 std::vector<const Trk::SpacePoint*> vSP;
164 std::vector<std::vector<GNNR3_Node> > trigSpStorage[2];
170 for(
const auto& lColl : detIdMap) {
172 short layerIndex = lColl.first;
174 int layerKey =
m_geo->getTrigFTF_GNNR3_LayerByIndex(layerIndex)->m_layer.m_subdet;
176 bool isPixel = layerKey > 20000;
178 auto pCont = isPixel ? pixelSpacePointsContainer : sctSpacePointsContainer;
180 int contIdx= isPixel ? 0 : 1;
184 for(
const auto& idx : lColl.second) {
186 std::vector<GNNR3_Node>& tmpColl = trigSpStorage[contIdx].at(
static_cast<int>(idx));
188 auto input_coll = pCont->indexFindPtr(idx);
190 if(input_coll ==
nullptr)
continue;
194 nNewNodes += (isPixel) ? storage->loadPixelGraphNodes(layerIndex, tmpColl,
m_useML) : storage->loadStripGraphNodes(layerIndex, tmpColl);
197 if(isPixel) nPixels += nNewNodes;
198 else nStrips += nNewNodes;
204 storage->sortByPhi();
205 storage->initializeNodes(
m_useML);
208 std::vector<GNNR3_Edge> edgeStorage;
210 std::pair<int, int> graphStats =
buildTheGraph(internalRoI, storage, edgeStorage);
212 ATH_MSG_DEBUG(
"Created graph with "<<graphStats.first<<
" edges and "<<graphStats.second<<
" edge links");
217 if(graphStats.second == 0)
return seedStats;
219 int maxLevel =
runCCA(graphStats.first, edgeStorage);
221 ATH_MSG_DEBUG(
"Reached Level "<<maxLevel<<
" after GNN iterations");
229 if(maxLevel < minLevel)
return seedStats;
231 std::vector<GNNR3_Edge*> vSeeds;
233 vSeeds.reserve(graphStats.first/2);
235 for(
int edgeIndex=0;edgeIndex<graphStats.first;edgeIndex++) {
236 GNNR3_Edge* pS = &(edgeStorage.at(edgeIndex));
238 if(pS->
m_level < minLevel)
continue;
240 vSeeds.push_back(pS);
243 if(vSeeds.empty())
return seedStats;
251 output.reserve(vSeeds.size());
253 for(
auto pS : vSeeds) {
255 if(pS->m_level == -1)
continue;
261 if(!
rs.m_initialized) {
265 if(
static_cast<int>(
rs.m_vs.size()) < minLevel)
continue;
267 std::vector<const GNNR3_Node*> vN;
269 for(std::vector<GNNR3_Edge*>::reverse_iterator sIt=
rs.m_vs.rbegin();sIt!=
rs.m_vs.rend();++sIt) {
271 (*sIt)->m_level = -1;
273 if(sIt ==
rs.m_vs.rbegin()) {
274 vN.push_back((*sIt)->m_n1);
276 vN.push_back((*sIt)->m_n2);
279 if(vN.size()<3)
continue;
281 unsigned int lastIdx = output.size();
282 output.emplace_back(
rs.m_J);
284 for(
const auto& n : vN) {
285 output[lastIdx].addSpacePoint(vSP[n->m_idx]);
297 std::vector<const Trk::SpacePoint*> vSP;
298 std::vector<short> vL;
303 std::unique_ptr<TrigAccel::DATA_EXPORT_BUFFER> dataBuffer = std::unique_ptr<TrigAccel::DATA_EXPORT_BUFFER>(
new TrigAccel::DATA_EXPORT_BUFFER(5000));
306 const size_t bufferOffset = 256;
307 size_t totalSize = bufferOffset+dataTypeSize;
312 unsigned int spIdx = 0;
318 for(
const auto& lColl : detIdMap) {
320 short layerIndex = lColl.first;
326 bool isPixel = layerKey > 20000;
329 auto pCont = isPixel ? pixelSpacePointsContainer : sctSpacePointsContainer;
340 nEtaBins += pL->
m_bins.size();
342 for(
auto b : pL->
m_bins) {
343 if(b > MaxEtaBin) MaxEtaBin = b;
346 for(
const auto& idx : lColl.second) {
348 auto input_coll = pCont->indexFindPtr(idx);
350 if(input_coll ==
nullptr)
continue;
352 for(
const auto sp : *input_coll) {
360 if(cw > 0.2)
continue;
365 vSP.emplace_back(
sp);
366 vL.emplace_back(layerIndex);
368 const auto& p =
sp->globalPosition();
370 float params[4] = {(float)(p.x() - shift_x), float(p.y() - shift_y), (float)(p.z()), cw};
372 memcpy(&pJobData->
m_params[sp_offset], ¶ms[0],
sizeof(params));
383 if (isPixel) nPixels += spIdx - pJobData->
m_layerInfo[4*nLayers];
384 else nStrips += spIdx - pJobData->
m_layerInfo[4*nLayers];
399 for(
const auto& bg :
m_geo->bin_groups()) {
401 int bin1_idx = bg.first;
403 for(
const auto& bin2_idx : bg.second) {
414 const float ptCoeff = 0.29997*1.9972/2.0;
416 float tripletPtMin = 0.8*
m_minPt;
418 float maxCurv = ptCoeff/tripletPtMin;
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;
428 const float maxOuterRadius =
m_LRTmode ? 1050.0 : 550.0;
429 const float minDeltaRadius = 2.0;
431 const float cut_zMinU = min_z0 + maxOuterRadius*internalRoI.
dzdrMinus();
432 const float cut_zMaxU = max_z0 + maxOuterRadius*internalRoI.
dzdrPlus();
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;
464 ATH_MSG_DEBUG(
"Loaded "<<nPixels<<
" Pixel Spacepoints and "<<nStrips<<
" Strip SpacePoints");
466 std::shared_ptr<TrigAccel::OffloadBuffer> pBuff = std::make_shared<TrigAccel::OffloadBuffer>(dataBuffer.get());
477 bool workSuccess = pWork->run();
483 std::shared_ptr<TrigAccel::OffloadBuffer> pOutput = pWork->getOutput();
491 for(
unsigned int seed=0; seed<pSeeds->
m_nSeeds; seed++) {
493 unsigned int lastIdx = output.size();
496 output[lastIdx].addSpacePoint(vSP[pSeeds->
m_seedsArray[seed].m_nodes[
node]]);
502 unsigned int nEdges = pGraph->
m_nEdges;
507 std::vector<GNNR3_Node> nodes;
509 nodes.reserve(vSP.size());
511 for(
unsigned int idx = 0;idx < vSP.size(); idx++) {
513 nodes.emplace_back(vL[idx]);
515 const auto& pos = vSP[idx]->globalPosition();
516 float xs = pos.x() - shift_x;
517 float ys = pos.y() - shift_y;
523 nodes[idx].m_r = std::sqrt(xs*xs + ys*ys);
525 nodes[idx].m_idx = idx;
529 std::vector<GNNR3_Edge> edgeStorage;
531 std::pair<int, int> graphStats(0,0);
533 edgeStorage.resize(nEdges);
535 unsigned int edgeSize = nMaxNei + 1 + 2;
537 for(
unsigned int idx=0;idx<nEdges;idx++) {
538 unsigned int pos = idx*edgeSize;
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++) {
555 graphStats.first = nEdges;
556 graphStats.second = pGraph->
m_nLinks;
560 int maxLevel =
runCCA(graphStats.first, edgeStorage);
562 ATH_MSG_DEBUG(
"Reached Level "<<maxLevel<<
" after GNN iterations");
564 if(maxLevel < minLevel)
return seedStats;
566 std::vector<GNNR3_Edge*> vSeeds;
568 vSeeds.reserve(graphStats.first/2);
570 for(
int edgeIndex=0;edgeIndex<graphStats.first;edgeIndex++) {
571 GNNR3_Edge* pS = &(edgeStorage.at(edgeIndex));
573 if(pS->
m_level < minLevel)
continue;
575 vSeeds.push_back(pS);
578 if(vSeeds.empty())
return seedStats;
586 output.reserve(vSeeds.size());
588 for(
auto pS : vSeeds) {
590 if(pS->m_level == -1)
continue;
596 if(!
rs.m_initialized) {
600 if(
static_cast<int>(
rs.m_vs.size()) < minLevel)
continue;
602 std::vector<const GNNR3_Node*> vN;
604 for(std::vector<GNNR3_Edge*>::reverse_iterator sIt=
rs.m_vs.rbegin();sIt!=
rs.m_vs.rend();++sIt) {
606 (*sIt)->m_level = -1;
608 if(sIt ==
rs.m_vs.rbegin()) {
609 vN.push_back((*sIt)->m_n1);
611 vN.push_back((*sIt)->m_n2);
614 if(vN.size()<3)
continue;
616 unsigned int lastIdx = output.size();
617 output.emplace_back(
rs.m_J);
619 for(
const auto& n : vN) {
620 output[lastIdx].addSpacePoint(vSP[n->m_idx]);