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