23 const IInterface*
p ) :
54 ATH_MSG_FATAL(
"Both usePixelSpacePoints and useSctSpacePoints set to False. At least one needs to be True");
55 return StatusCode::FAILURE;
69 if (conn_fileName.empty()) {
70 ATH_MSG_FATAL(
"Cannot find layer connections file " << conn_fileName);
71 return StatusCode::FAILURE;
75 std::ifstream ifs(conn_fileName.c_str());
79 ATH_MSG_INFO(
"Layer connections are initialized from file " << conn_fileName);
110 float shift_x =
vertex.x() - beamSpotHandle->beamTilt(0)*
vertex.z();
111 float shift_y =
vertex.y() - beamSpotHandle->beamTilt(1)*
vertex.z();
113 std::unique_ptr<TrigFTF_GNN_DataStorage> storage = std::make_unique<TrigFTF_GNN_DataStorage>(*
m_geo);
118 std::vector<std::vector<TrigFTF_GNN_Node> > trigSpStorage[2];
131 std::vector<IdentifierHash> listOfSctIds;
133 m_regsel_sct->lookup(ctx)->HashIDList( internalRoI, listOfSctIds );
137 trigSpStorage[1].resize(h2l->size());
139 for(
const auto&
idx : listOfSctIds) {
141 short layerIndex = h2l->at(
static_cast<int>(
idx));
143 std::vector<TrigFTF_GNN_Node>& tmpColl = trigSpStorage[1].at(
static_cast<int>(
idx));
147 if(input_coll ==
nullptr)
continue;
165 pixelSpacePointsContainer = pixHandle.
ptr();
167 std::vector<IdentifierHash> listOfPixIds;
169 m_regsel_pix->lookup(ctx)->HashIDList( internalRoI, listOfPixIds );
173 trigSpStorage[0].resize(h2l->size());
175 for(
const auto&
idx : listOfPixIds) {
177 short layerIndex = h2l->at(
static_cast<int>(
idx));
179 std::vector<TrigFTF_GNN_Node>& tmpColl = trigSpStorage[0].at(
static_cast<int>(
idx));
183 if(input_coll ==
nullptr)
continue;
203 std::vector<TrigFTF_GNN_Edge> edgeStorage;
205 std::pair<int, int> graphStats =
buildTheGraph(internalRoI, storage, edgeStorage);
207 ATH_MSG_DEBUG(
"Created graph with "<<graphStats.first<<
" edges and "<<graphStats.second<<
" edge links");
212 if(graphStats.second == 0)
return seedStats;
214 int maxLevel =
runCCA(graphStats.first, edgeStorage);
216 ATH_MSG_DEBUG(
"Reached Level "<<maxLevel<<
" after GNN iterations");
224 if(maxLevel < minLevel)
return seedStats;
226 std::vector<TrigFTF_GNN_Edge*> vSeeds;
228 vSeeds.reserve(graphStats.first/2);
230 for(
int edgeIndex=0;edgeIndex<graphStats.first;edgeIndex++) {
233 if(pS->
m_level < minLevel)
continue;
235 vSeeds.push_back(pS);
238 if(vSeeds.empty())
return seedStats;
246 output.reserve(vSeeds.size());
248 for(
auto pS : vSeeds) {
250 if(pS->m_level == -1)
continue;
254 tFilter.followTrack(pS, rs);
260 if(
static_cast<int>(rs.
m_vs.size()) < minLevel)
continue;
262 std::vector<const TrigFTF_GNN_Node*> vN;
264 for(std::vector<TrigFTF_GNN_Edge*>::reverse_iterator sIt=rs.
m_vs.rbegin();sIt!=rs.
m_vs.rend();++sIt) {
266 (*sIt)->m_level = -1;
268 if(sIt == rs.
m_vs.rbegin()) {
269 vN.push_back((*sIt)->m_n1);
271 vN.push_back((*sIt)->m_n2);
274 if(vN.size()<3)
continue;
276 unsigned int lastIdx =
output.size();
279 for(
const auto&
n : vN) {
280 output[lastIdx].addSpacePoint(
n->m_pSP);
293 for(
const auto& sp : *spColl) {
294 const auto&
pos = sp->globalPosition();
295 float xs =
pos.x() - shift_x;
296 float ys =
pos.y() - shift_y;
298 tmpColl[
idx].m_x = xs;
299 tmpColl[
idx].m_y = ys;
300 tmpColl[
idx].m_z = zs;
301 tmpColl[
idx].m_r = std::sqrt(xs*xs + ys*ys);
302 tmpColl[
idx].m_phi = std::atan2(ys,xs);
303 tmpColl[
idx].m_pSP = sp;
312 const float cut_dphi_max =
m_LRTmode ? 0.07 : 0.012;
313 const float cut_dcurv_max =
m_LRTmode ? 0.015 : 0.001;
314 const float cut_tau_ratio_max =
m_LRTmode ? 0.015 : 0.007;
317 const float min_deltaPhi =
m_LRTmode ? 0.01f : 0.001f;
319 const float maxOuterRadius =
m_LRTmode ? 1050.0 : 550.0;
321 const float cut_zMinU = min_z0 + maxOuterRadius*roi.
dzdrMinus();
322 const float cut_zMaxU = max_z0 + maxOuterRadius*roi.
dzdrPlus();
324 const float ptCoeff = 0.29997*1.9972/2.0;
326 float tripletPtMin = 0.8*
m_minPt;
328 float maxCurv = ptCoeff/tripletPtMin;
330 const float maxKappa_high_eta =
m_LRTmode ? 1.0*maxCurv : std::sqrt(0.8)*maxCurv;
331 const float maxKappa_low_eta =
m_LRTmode ? 1.0*maxCurv : std::sqrt(0.6)*maxCurv;
332 const float dphi_coeff =
m_LRTmode ? 1.0*maxCurv : 0.68*maxCurv;
334 const float minDeltaRadius = 2.0;
338 unsigned int nConnections = 0;
344 for(
const auto&
bg :
m_geo->bin_groups()) {
348 if(B1.
empty())
continue;
352 for(
const auto& b2_idx :
bg.second) {
356 if(B2.
empty())
continue;
361 deltaPhi = min_deltaPhi + dphi_coeff*std::fabs(rb2-rb1);
364 unsigned int first_it = 0;
366 for(
unsigned int n1Idx = 0;n1Idx<B1.
m_vn.size();n1Idx++) {
368 std::vector<unsigned int>& v1In = B1.
m_in[n1Idx];
372 const std::array<float, 5>& n1pars = B1.
m_params[n1Idx];
374 float phi1 = n1pars[2];
375 float r1 = n1pars[3];
376 float z1 = n1pars[4];
383 for(
unsigned int n2PhiIdx = first_it; n2PhiIdx<B2.
m_vPhiNodes.size();n2PhiIdx++) {
391 if(phi2 > maxPhi)
break;
393 unsigned int n2Idx = B2.
m_vPhiNodes[n2PhiIdx].second;
395 const std::vector<unsigned int>& v2In = B2.
m_in[n2Idx];
399 const std::array<float, 5>& n2pars = B2.
m_params[n2Idx];
401 float r2 = n2pars[3];
405 if(
dr < minDeltaRadius) {
409 float z2 = n2pars[4];
413 float ftau = std::fabs(tau);
418 if(ftau < n1pars[0])
continue;
419 if(ftau > n1pars[1])
continue;
421 if(ftau < n2pars[0])
continue;
422 if(ftau > n2pars[1])
continue;
426 float z0 = z1 - r1*tau;
428 if(z0 < min_z0 || z0 > max_z0)
continue;
430 float zouter =
z0 + maxOuterRadius*tau;
432 if(zouter < cut_zMinU || zouter > cut_zMaxU)
continue;
435 float curv = (phi2-phi1)/
dr;
436 float abs_curv = std::abs(curv);
439 if(abs_curv > maxKappa_low_eta) {
444 if(abs_curv > maxKappa_high_eta) {
451 float exp_eta = std::sqrt(1+tau*tau)-tau;
453 bool isGood = v2In.size() <= 2;
457 float uat_1 = 1.0f/exp_eta;
459 for(
const auto& n2_in_idx : v2In) {
461 float tau2 = edgeStorage.at(n2_in_idx).m_p[0];
462 float tau_ratio = tau2*uat_1 - 1.0f;
464 if(std::fabs(tau_ratio) > cut_tau_ratio_max){
476 float dPhi2 = curv*r2;
477 float dPhi1 = curv*r1;
481 edgeStorage.emplace_back(B1.
m_vn[n1Idx], B2.
m_vn[n2Idx], exp_eta, curv, phi1 + dPhi1);
485 int outEdgeIdx = nEdges;
487 float uat_2 = 1/exp_eta;
488 float Phi2 = phi2 + dPhi2;
491 for(
const auto& inEdgeIdx : v2In) {
497 float tau_ratio = pS->
m_p[0]*uat_2 - 1.0f;
499 if(std::abs(tau_ratio) > cut_tau_ratio_max){
503 float dPhi = Phi2 - pS->
m_p[2];
508 if(dPhi < -cut_dphi_max || dPhi > cut_dphi_max) {
512 float dcurv = curv2 - pS->
m_p[1];
514 if(dcurv < -cut_dcurv_max || dcurv > cut_dcurv_max) {
530 return std::make_pair(nEdges, nConnections);
535 const int maxIter = 15;
541 std::vector<TrigFTF_GNN_Edge*> v_old;
543 for(
int edgeIndex=0;edgeIndex<nEdges;edgeIndex++) {
546 if(pS->
m_nNei == 0)
continue;
551 for(;iter<maxIter;iter++) {
554 std::vector<TrigFTF_GNN_Edge*> v_new;
556 v_new.reserve(v_old.size());
558 for(
auto pS : v_old) {
560 int next_level = pS->m_level;
562 for(
int nIdx=0;nIdx<pS->m_nNei;nIdx++) {
564 unsigned int nextEdgeIdx = pS->m_vNei[nIdx];
568 if(pS->m_level == pN->
m_level) {
575 pS->m_next = next_level;
582 for(
auto pS : v_new) {
583 if(pS->m_next != pS->m_level) {
585 pS->m_level = pS->m_next;
586 if(maxLevel < pS->m_level) maxLevel = pS->m_level;
590 if(nChanges == 0)
break;
593 v_old = std::move(v_new);