458 {
459 std::vector<Amg::Vector2D> vectorOfPositions;
460 int numberOfSubclusters = 1;
461 vectorOfPositions.push_back(pixelPrepCluster->
localPosition());
462
464 SG::ReadHandle<InDet::PixelGangedClusterAmbiguities> splitClusterMap(
m_splitClusterMapKey, ctx);
465 InDet::PixelGangedClusterAmbiguities::const_iterator mapBegin = splitClusterMap->begin();
466 InDet::PixelGangedClusterAmbiguities::const_iterator mapEnd = splitClusterMap->end();
467 for (InDet::PixelGangedClusterAmbiguities::const_iterator mapIter = mapBegin; mapIter != mapEnd; ++mapIter) {
468 const InDet::SiCluster *
first = (*mapIter).first;
469 const InDet::SiCluster *
second = (*mapIter).second;
470 if (first == pixelPrepCluster && second != pixelPrepCluster) {
471 ATH_MSG_DEBUG(
"Found additional split cluster in ambiguity map (+=1).");
472 numberOfSubclusters += 1;
473 const InDet::SiCluster *otherOne =
second;
474 const InDet::PixelCluster *pixelAddCluster = nullptr;
476 pixelAddCluster = static_cast<const InDet::PixelCluster *>(otherOne);
477 }
478 if (pixelAddCluster == nullptr) {
479 ATH_MSG_WARNING(
"Pixel ambiguity map has empty pixel cluster. Please DEBUG!");
480 continue;
481 }
482 vectorOfPositions.push_back(pixelAddCluster->
localPosition());
483
486 }
487 }
488 }
489
490
491
495 "Parameters are not at a plane ! Aborting cluster correction... ");
496 return false;
497 }
498
499 std::vector<Amg::Vector2D> allLocalPositions;
500 std::vector<Amg::MatrixX> allErrorMatrix;
501 allLocalPositions =
504 trackPar,
505 allErrorMatrix,
506 numberOfSubclusters);
507
508 if (allLocalPositions.empty()) {
509 ATH_MSG_DEBUG(
" Cluster cannot be treated by NN. Giving back to default clusterization " );
510
511 return false;
512 }
513
514 if (allLocalPositions.size() != size_t(numberOfSubclusters)) {
515 ATH_MSG_WARNING(
"Returned position vector size " << allLocalPositions.size() <<
516 " not according to expected number of subclusters: " << numberOfSubclusters << ". Abort cluster correction..." );
517 return false;
518 }
519
520
521
522
523
524 if (numberOfSubclusters == 1) {
525 finalposition = allLocalPositions[0];
526 finalerrormatrix = allErrorMatrix[0];
527 }
528
529 else if (numberOfSubclusters == 2) {
530 double distancesq1 =
531 square(vectorOfPositions[0][0] - allLocalPositions[0][0]) / allErrorMatrix[0](0, 0) +
532 square(vectorOfPositions[1][0] - allLocalPositions[1][0]) / allErrorMatrix[1](0, 0) +
533 square(vectorOfPositions[0][1] - allLocalPositions[0][1]) / allErrorMatrix[0](1, 1) +
534 square(vectorOfPositions[1][1] - allLocalPositions[1][1]) / allErrorMatrix[1](1, 1);
535
536 double distancesq2 =
537 square(vectorOfPositions[1][0] - allLocalPositions[0][0]) / allErrorMatrix[0](0, 0) +
538 square(vectorOfPositions[0][0] - allLocalPositions[1][0]) / allErrorMatrix[1](0, 0) +
539 square(vectorOfPositions[1][1] - allLocalPositions[0][1]) / allErrorMatrix[0](1, 1) +
540 square(vectorOfPositions[0][1] - allLocalPositions[1][1]) / allErrorMatrix[1](1, 1);
541
543 " Old pix (1) x: " << vectorOfPositions[0][0] << " y: " << vectorOfPositions[0][1] << "\n"
544 << " Old pix (2) x: " << vectorOfPositions[1][0] << " y: " << vectorOfPositions[1][1] << "\n"
545 << " Pix (1) x: " << allLocalPositions[0][0] << " +/- " << std::sqrt(allErrorMatrix[0](0, 0))
546 << " y: " << allLocalPositions[0][1] << " +/- " << std::sqrt(allErrorMatrix[0](1, 1)) <<"\n"
547 << " Pix (2) x: " << allLocalPositions[1][0] << " +/- " << std::sqrt(allErrorMatrix[1](0, 0))
548 << " y: " << allLocalPositions[1][1] << " +/- " << std::sqrt(allErrorMatrix[1](1, 1)) << "\n"
549 << " Old (1) new (1) dist: " << std::sqrt(distancesq1) << " Old (1) new (2) " << std::sqrt(distancesq2) );
550
551
552 if (distancesq1 < distancesq2) {
553 finalposition = allLocalPositions[0];
554 finalerrormatrix = allErrorMatrix[0];
555 }else {
556 finalposition = allLocalPositions[1];
557 finalerrormatrix = allErrorMatrix[1];
558 }
559 }
560
561
562 else if (numberOfSubclusters == 3) {
563 double distances[6];
564
565 distances[0] =
distance(vectorOfPositions, allLocalPositions, allErrorMatrix, 0, 1, 2);
566 distances[1] =
distance(vectorOfPositions, allLocalPositions, allErrorMatrix, 0, 2, 1);
567 distances[2] =
distance(vectorOfPositions, allLocalPositions, allErrorMatrix, 1, 0, 2);
568 distances[3] =
distance(vectorOfPositions, allLocalPositions, allErrorMatrix, 1, 2, 0);
569 distances[4] =
distance(vectorOfPositions, allLocalPositions, allErrorMatrix, 2, 0, 1);
570 distances[5] =
distance(vectorOfPositions, allLocalPositions, allErrorMatrix, 2, 1, 0);
571
572 int smallestDistanceIndex = -10;
573 double minDistance = 1e10;
574
575 for (
int i = 0;
i < 6;
i++) {
576 ATH_MSG_VERBOSE(
" distance n.: " << i <<
" distance is: " << distances[i]);
577
578 if (distances[i] < minDistance) {
579 minDistance = distances[
i];
580 smallestDistanceIndex =
i;
581 }
582 }
583
584 ATH_MSG_DEBUG(
" The minimum distance is : " << minDistance <<
" for index: " << smallestDistanceIndex);
585
586 if (smallestDistanceIndex == 0 || smallestDistanceIndex == 1) {
587 finalposition = allLocalPositions[0];
588 finalerrormatrix = allErrorMatrix[0];
589 }
590 if (smallestDistanceIndex == 2 || smallestDistanceIndex == 4) {
591 finalposition = allLocalPositions[1];
592 finalerrormatrix = allErrorMatrix[1];
593 }
594 if (smallestDistanceIndex == 3 || smallestDistanceIndex == 5) {
595 finalposition = allLocalPositions[2];
596 finalerrormatrix = allErrorMatrix[2];
597 }
598 }
599 return true;
600}
virtual const Surface & associatedSurface() const =0
Access to the Surface associated to the Parameters.
virtual constexpr SurfaceType surfaceType() const =0
Returns the Surface Type enum for the surface used to define the derived class.
virtual constexpr ParametersType type() const =0
Return the ParametersType enum.
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space