49 ATH_MSG_FATAL(
"Both usePixelSpacePoints and useSctSpacePoints set to False. At least one needs to be True");
50 return StatusCode::FAILURE;
65 return StatusCode::SUCCESS;
81 float shift_x =
vertex.x() - beamSpotHandle->beamTilt(0)*
vertex.z();
82 float shift_y =
vertex.y() - beamSpotHandle->beamTilt(1)*
vertex.z();
84 std::unique_ptr<GNN_DataStorage> storage = std::make_unique<GNN_DataStorage>(*
m_geo);
92 std::map<short, std::vector<IdentifierHash> > detIdMap;
104 sctSpacePointsContainer = sctHandle.
ptr();
106 std::vector<IdentifierHash> listOfSctIds;
107 m_regsel_sct->lookup(ctx)->HashIDList( internalRoI, listOfSctIds );
111 for(
const auto& hashId : listOfSctIds) {
113 short layerIndex = h2l->at(
static_cast<int>(hashId));
115 auto it = detIdMap.find(layerIndex);
116 if(
it != detIdMap.end()) (*it).second.push_back(hashId);
118 std::vector<IdentifierHash>
v = {hashId};
119 detIdMap.insert(std::make_pair(layerIndex,
v));
133 pixelSpacePointsContainer = pixHandle.
ptr();
135 std::vector<IdentifierHash> listOfPixIds;
137 m_regsel_pix->lookup(ctx)->HashIDList( internalRoI, listOfPixIds );
141 for(
const auto& hashId : listOfPixIds) {
143 short layerIndex = h2l->at(
static_cast<int>(hashId));
145 auto it = detIdMap.find(layerIndex);
146 if(
it != detIdMap.end()) (*it).second.push_back(hashId);
148 std::vector<IdentifierHash>
v = {hashId};
149 detIdMap.insert(std::make_pair(layerIndex,
v));
156 std::unique_ptr<GNN_DataStorage> storage = std::make_unique<GNN_DataStorage>(*
m_geo);
158 std::vector<const Trk::SpacePoint*> vSP;
162 std::vector<std::vector<GNN_Node> > trigSpStorage[2];
168 for(
const auto& lColl : detIdMap) {
170 short layerIndex = lColl.first;
172 int layerKey =
m_geo->getTrigFTF_GNN_LayerByIndex(layerIndex)->m_layer.m_subdet;
174 bool isPixel = layerKey > 20000;
176 auto pCont = isPixel ? pixelSpacePointsContainer : sctSpacePointsContainer;
178 int contIdx= isPixel ? 0 : 1;
182 for(
const auto&
idx : lColl.second) {
184 std::vector<GNN_Node>& tmpColl = trigSpStorage[contIdx].at(
static_cast<int>(
idx));
186 auto input_coll = pCont->indexFindPtr(
idx);
188 if(input_coll ==
nullptr)
continue;
195 if(isPixel) nPixels += nNewNodes;
206 std::vector<GNN_Edge> edgeStorage;
208 std::pair<int, int> graphStats =
buildTheGraph(internalRoI, storage, edgeStorage);
210 ATH_MSG_DEBUG(
"Created graph with "<<graphStats.first<<
" edges and "<<graphStats.second<<
" edge links");
215 if(graphStats.second == 0)
return seedStats;
217 int maxLevel =
runCCA(graphStats.first, edgeStorage);
219 ATH_MSG_DEBUG(
"Reached Level "<<maxLevel<<
" after GNN iterations");
227 if(maxLevel < minLevel)
return seedStats;
229 std::vector<GNN_Edge*> vSeeds;
231 vSeeds.reserve(graphStats.first/2);
233 for(
int edgeIndex=0;edgeIndex<graphStats.first;edgeIndex++) {
234 GNN_Edge* pS = &(edgeStorage.at(edgeIndex));
236 if(pS->
m_level < minLevel)
continue;
238 vSeeds.push_back(pS);
241 if(vSeeds.empty())
return seedStats;
249 output.reserve(vSeeds.size());
251 for(
auto pS : vSeeds) {
253 if(pS->m_level == -1)
continue;
263 if(
static_cast<int>(rs.
m_vs.size()) < minLevel)
continue;
265 std::vector<const GNN_Node*> vN;
267 for(std::vector<GNN_Edge*>::reverse_iterator sIt=rs.
m_vs.rbegin();sIt!=rs.
m_vs.rend();++sIt) {
269 (*sIt)->m_level = -1;
271 if(sIt == rs.
m_vs.rbegin()) {
272 vN.push_back((*sIt)->m_n1);
274 vN.push_back((*sIt)->m_n2);
277 if(vN.size()<3)
continue;
279 unsigned int lastIdx =
output.size();
282 for(
const auto&
n : vN) {
283 output[lastIdx].addSpacePoint(vSP[
n->m_idx]);
292 std::vector<const Trk::SpacePoint*> vSP;
293 std::vector<short> vL;
295 vSP.reserve(TrigAccel::ITk::GBTS_MAX_NUMBER_SPACEPOINTS);
296 vL.reserve(TrigAccel::ITk::GBTS_MAX_NUMBER_SPACEPOINTS);
298 std::unique_ptr<TrigAccel::DATA_EXPORT_BUFFER> dataBuffer = std::unique_ptr<TrigAccel::DATA_EXPORT_BUFFER>(
new TrigAccel::DATA_EXPORT_BUFFER(5000));
301 const size_t bufferOffset = 256;
302 size_t totalSize = bufferOffset+dataTypeSize;
307 unsigned int spIdx = 0;
313 for(
const auto& lColl : detIdMap) {
315 short layerIndex = lColl.first;
321 bool isPixel = layerKey > 20000;
324 auto pCont = isPixel ? pixelSpacePointsContainer : sctSpacePointsContainer;
338 if(
b > MaxEtaBin) MaxEtaBin =
b;
341 for(
const auto&
idx : lColl.second) {
343 auto input_coll = pCont->indexFindPtr(
idx);
345 if(input_coll ==
nullptr)
continue;
347 for(
const auto sp : *input_coll) {
355 if(cw > 0.2)
continue;
360 vSP.emplace_back(sp);
361 vL.emplace_back(layerIndex);
363 const auto&
p = sp->globalPosition();
365 float params[4] = {(
float)(
p.x() - shift_x),
float(
p.y() - shift_y), (
float)(
p.z()), cw};
371 if(spIdx >= TrigAccel::ITk::GBTS_MAX_NUMBER_SPACEPOINTS)
break;
373 if(spIdx >= TrigAccel::ITk::GBTS_MAX_NUMBER_SPACEPOINTS)
break;
378 if (isPixel) nPixels += spIdx - pJobData->
m_layerInfo[4*nLayers];
384 if(spIdx == 0)
return seedStats;
390 pJobData->
m_nMaxEdges =
static_cast<unsigned int>(7*spIdx);
396 for(
const auto&
bg :
m_geo->bin_groups()) {
398 int bin1_idx =
bg.first;
400 for(
const auto& bin2_idx :
bg.second) {
411 const float ptCoeff = 0.29997*1.9972/2.0;
413 float tripletPtMin = 0.8*
m_minPt;
415 float maxCurv = ptCoeff/tripletPtMin;
417 const float pt_scale = 900/
m_minPt;
419 const float min_deltaPhi_low_dr = 0.002*pt_scale;
420 const float dphi_coeff_low_dr = 4.33e-4*pt_scale;
421 const float min_deltaPhi = 0.015*pt_scale;
422 const float dphi_coeff = 2.2e-4*pt_scale;
424 const float cut_dphi_max =
m_LRTmode ? 0.07 : 0.012;
425 const float cut_dcurv_max =
m_LRTmode ? 0.015 : 0.001;
426 const float cut_tau_ratio_max =
m_LRTmode ? 0.015f : 0.01;
430 const float maxOuterRadius =
m_LRTmode ? 1050.0 : 550.0;
431 const float minDeltaRadius = 2.0;
433 const float cut_zMinU = min_z0 + maxOuterRadius*internalRoI.
dzdrMinus();
434 const float cut_zMaxU = max_z0 + maxOuterRadius*internalRoI.
dzdrPlus();
436 const float maxKappa =
m_LRTmode ? 1.0*maxCurv : 0.9*maxCurv;
468 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();
490 if(pSeeds->
m_nSeeds == 0)
return seedStats;
492 for(
unsigned int seed=0; seed<pSeeds->
m_nSeeds; seed++) {
494 unsigned int lastIdx =
output.size();
503 unsigned int nEdges = pGraph->
m_nEdges;
508 std::vector<GNN_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);
530 std::vector<GNN_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<GNN_Edge*> vSeeds;
569 vSeeds.reserve(graphStats.first/2);
571 for(
int edgeIndex=0;edgeIndex<graphStats.first;edgeIndex++) {
572 GNN_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;
601 if(
static_cast<int>(rs.
m_vs.size()) < minLevel)
continue;
603 std::vector<const GNN_Node*> vN;
605 for(std::vector<GNN_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();
620 for(
const auto&
n : vN) {
621 output[lastIdx].addSpacePoint(vSP[
n->m_idx]);
635 int init_size = vSP.size();
636 for(
const auto sp : *spColl) {
637 const auto&
pos = sp->globalPosition();
638 vSP.emplace_back(sp);
639 float xs =
pos.x() - shift_x;
640 float ys =
pos.y() - shift_y;
642 tmpColl[
idx].m_x = xs;
643 tmpColl[
idx].m_y = ys;
644 tmpColl[
idx].m_z = zs;
645 tmpColl[
idx].m_r = std::sqrt(xs*xs + ys*ys);
646 tmpColl[
idx].m_phi = std::atan2(ys,xs);
647 tmpColl[
idx].m_idx = init_size +
idx;