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;
252 output.reserve(vSeeds.size());
254 for(
auto pS : vSeeds) {
256 if(pS->m_level == -1)
continue;
262 if(!
rs.m_initialized) {
266 if(
static_cast<int>(
rs.m_vs.size()) < minLevel)
continue;
268 std::vector<const GNNR3_Node*> vN;
270 for(std::vector<GNNR3_Edge*>::reverse_iterator sIt=
rs.m_vs.rbegin();sIt!=
rs.m_vs.rend();++sIt) {
272 (*sIt)->m_level = -1;
274 if(sIt ==
rs.m_vs.rbegin()) {
275 vN.push_back((*sIt)->m_n1);
277 vN.push_back((*sIt)->m_n2);
280 if(vN.size()<3)
continue;
282 unsigned int lastIdx = output.size();
283 output.emplace_back(
rs.m_J);
285 for(
const auto& n : vN) {
286 output[lastIdx].addSpacePoint(vSP[n->m_idx]);
298 std::vector<const Trk::SpacePoint*> vSP;
299 std::vector<short> vL;
304 std::unique_ptr<TrigAccel::DATA_EXPORT_BUFFER> dataBuffer = std::unique_ptr<TrigAccel::DATA_EXPORT_BUFFER>(
new TrigAccel::DATA_EXPORT_BUFFER(5000));
307 const size_t bufferOffset = 256;
308 size_t totalSize = bufferOffset+dataTypeSize;
313 unsigned int spIdx = 0;
319 for(
const auto& lColl : detIdMap) {
321 short layerIndex = lColl.first;
327 bool isPixel = layerKey > 20000;
330 auto pCont = isPixel ? pixelSpacePointsContainer : sctSpacePointsContainer;
341 nEtaBins += pL->
m_bins.size();
343 for(
auto b : pL->
m_bins) {
344 if(b > MaxEtaBin) MaxEtaBin = b;
347 for(
const auto& idx : lColl.second) {
349 auto input_coll = pCont->indexFindPtr(idx);
351 if(input_coll ==
nullptr)
continue;
353 for(
const auto sp : *input_coll) {
361 if(cw > 0.2)
continue;
366 vSP.emplace_back(
sp);
367 vL.emplace_back(layerIndex);
369 const auto& p =
sp->globalPosition();
371 float params[4] = {(float)(p.x() - shift_x), float(p.y() - shift_y), (float)(p.z()), cw};
373 memcpy(&pJobData->
m_params[sp_offset], ¶ms[0],
sizeof(params));
384 if (isPixel) nPixels += spIdx - pJobData->
m_layerInfo[4*nLayers];
385 else nStrips += spIdx - pJobData->
m_layerInfo[4*nLayers];
400 for(
const auto& bg :
m_geo->bin_groups()) {
402 int bin1_idx = bg.first;
404 for(
const auto& bin2_idx : bg.second) {
415 const float ptCoeff = 0.29997*1.9972/2.0;
417 float tripletPtMin = 0.8*
m_minPt;
419 float maxCurv = ptCoeff/tripletPtMin;
421 const float min_deltaPhi = 0.001;
422 const float dphi_coeff = 0.68*maxCurv;
423 const float cut_dphi_max =
m_LRTmode ? 0.07 : 0.012;
424 const float cut_dcurv_max =
m_LRTmode ? 0.015 : 0.001;
425 const float cut_tau_ratio_max =
m_LRTmode ? 0.015 : 0.007;
429 const float maxOuterRadius =
m_LRTmode ? 1050.0 : 550.0;
430 const float minDeltaRadius = 2.0;
432 const float cut_zMinU = min_z0 + maxOuterRadius*internalRoI.
dzdrMinus();
433 const float cut_zMaxU = max_z0 + maxOuterRadius*internalRoI.
dzdrPlus();
435 const float maxKappa_high_eta =
m_LRTmode ? 1.0*maxCurv : std::sqrt(0.8)*maxCurv;
436 const float maxKappa_low_eta =
m_LRTmode ? 1.0*maxCurv : std::sqrt(0.6)*maxCurv;
465 ATH_MSG_DEBUG(
"Loaded "<<nPixels<<
" Pixel Spacepoints and "<<nStrips<<
" Strip SpacePoints");
467 std::shared_ptr<TrigAccel::OffloadBuffer> pBuff = std::make_shared<TrigAccel::OffloadBuffer>(dataBuffer.get());
478 bool workSuccess = pWork->run();
484 std::shared_ptr<TrigAccel::OffloadBuffer> pOutput = pWork->getOutput();
492 for(
unsigned int seed=0; seed<pSeeds->
m_nSeeds; seed++) {
494 unsigned int lastIdx = output.size();
497 output[lastIdx].addSpacePoint(vSP[pSeeds->
m_seedsArray[seed].m_nodes[
node]]);
503 unsigned int nEdges = pGraph->
m_nEdges;
508 std::vector<GNNR3_Node> nodes;
510 nodes.reserve(vSP.size());
512 for(
unsigned int idx = 0;idx < vSP.size(); idx++) {
514 nodes.emplace_back(vL[idx]);
516 const auto& pos = vSP[idx]->globalPosition();
517 float xs = pos.x() - shift_x;
518 float ys = pos.y() - shift_y;
524 nodes[idx].m_r = std::sqrt(xs*xs + ys*ys);
526 nodes[idx].m_idx = idx;
530 std::vector<GNNR3_Edge> edgeStorage;
532 std::pair<int, int> graphStats(0,0);
534 edgeStorage.resize(nEdges);
536 unsigned int edgeSize = nMaxNei + 1 + 2;
538 for(
unsigned int idx=0;idx<nEdges;idx++) {
539 unsigned int pos = idx*edgeSize;
547 edgeStorage[idx].m_n1 = &nodes[node1Idx];
548 edgeStorage[idx].m_n2 = &nodes[node2Idx];
549 edgeStorage[idx].m_level = 1;
550 edgeStorage[idx].m_nNei = nNei;
551 for(
int k=0;k<nNei;k++) {
556 graphStats.first = nEdges;
557 graphStats.second = pGraph->
m_nLinks;
561 int maxLevel =
runCCA(graphStats.first, edgeStorage);
563 ATH_MSG_DEBUG(
"Reached Level "<<maxLevel<<
" after GNN iterations");
565 if(maxLevel < minLevel)
return seedStats;
567 std::vector<GNNR3_Edge*> vSeeds;
569 vSeeds.reserve(graphStats.first/2);
571 for(
int edgeIndex=0;edgeIndex<graphStats.first;edgeIndex++) {
572 GNNR3_Edge* pS = &(edgeStorage.at(edgeIndex));
574 if(pS->
m_level < minLevel)
continue;
576 vSeeds.push_back(pS);
579 if(vSeeds.empty())
return seedStats;
587 output.reserve(vSeeds.size());
589 for(
auto pS : vSeeds) {
591 if(pS->m_level == -1)
continue;
597 if(!
rs.m_initialized) {
601 if(
static_cast<int>(
rs.m_vs.size()) < minLevel)
continue;
603 std::vector<const GNNR3_Node*> vN;
605 for(std::vector<GNNR3_Edge*>::reverse_iterator sIt=
rs.m_vs.rbegin();sIt!=
rs.m_vs.rend();++sIt) {
607 (*sIt)->m_level = -1;
609 if(sIt ==
rs.m_vs.rbegin()) {
610 vN.push_back((*sIt)->m_n1);
612 vN.push_back((*sIt)->m_n2);
615 if(vN.size()<3)
continue;
617 unsigned int lastIdx = output.size();
618 output.emplace_back(
rs.m_J);
620 for(
const auto& n : vN) {
621 output[lastIdx].addSpacePoint(vSP[n->m_idx]);