365 {
366
367 unsigned int maxstrip = strips.size();
368
369 ATH_MSG_DEBUG(
" Clustering for " << setaphi(measphi) <<
" plane with " << maxstrip <<
" strips");
370
372
373
374
375
378 std::vector<bool> astrip;
379 std::vector<bool> bstrip;
380 IdentifierHash cscHashId;
381
382
383 for (unsigned int istrip = 0; istrip < strips.size(); ++istrip) {
387 bool isBadChannel = false;
388 if (pstrip) {
389 if (!newCollection) {
393 newCollection->setIdentifier(elementId);
394 }
396
397 IdentifierHash stripHash;
398 Identifier stripId = pstrip->
identify();
399 if (
m_idHelperSvc->cscIdHelper().get_channel_hash(stripId, stripHash)) {
401 << " the identifier is \n" << stripId);
402 }
403
405
406 float stripNoise = 0;
413 stripNoise /= 3.251;
414 }
415
417 if (isBadChannel)
active =
false;
418
420
421 ostringstream strlog;
422 strlog <<
" Strip " << setw(3) << istrip + 1 <<
": charge= " << setw(7) <<
int(
res.charge) <<
" dcharge= " << setw(7)
424 if (std::fabs(
res.time) < 1e8)
425 strlog <<
" time=" << setw(3) <<
int(
res.time + 0.5);
426 else
427 strlog << " time=OVERFLOW";
428 if (active)
429 strlog << " *";
430 else if (isBadChannel)
431 strlog << " b";
432 else
433 strlog << " .";
435 strlog << " x";
436 else
437 strlog << " o";
438 strlog <<
" :" <<
res.status;
440 }
441 }
442 allStripfits.push_back(
res);
443 astrip.push_back(active);
444 bstrip.push_back(isBadChannel);
445 }
446
448
449
450
452
453
454 std::vector<bool> rstrip;
455 bool IsAnyStripRecovered = false;
456 for (unsigned int istrip = 0; istrip < strips.size(); ++istrip) {
457 bool adjacentActive = false;
458 if (bstrip[istrip]) {
459 if (istrip > 0 && astrip[istrip - 1]) adjacentActive = true;
460 if (istrip + 1 < strips.size() && astrip[istrip + 1]) adjacentActive = true;
461 if (adjacentActive) IsAnyStripRecovered = true;
462 }
463 rstrip.push_back(adjacentActive);
464 }
465
466
467 if (IsAnyStripRecovered) {
468
470 ostringstream checklog1;
471 ostringstream checklog2;
472
473 for (unsigned int istrip = 0; istrip < strips.size(); ++istrip) {
474 if (istrip % 24 == 0) checklog1 << "\n";
475 checklog1 <<
int(astrip[istrip]) <<
" ";
476
477 if (!astrip[istrip] && rstrip[istrip]) {
479 }
480 if (istrip % 24 == 0) checklog2 << "\n";
481 checklog2 <<
int(astrip[istrip]) <<
" ";
482 }
486 }
487
488 for (unsigned int istrip = 0; istrip < strips.size(); ++istrip) {
489 if (!astrip[istrip] && rstrip[istrip]) {
490 astrip[istrip] = rstrip[istrip];
491 }
492 }
493 }
495
496
497
499 vector<unsigned int> strip0s;
500 vector<unsigned int> nstrips;
501
502
503 int nstrip = 0;
504 int first_strip = 0;
505 bool incluster = false;
506 for (unsigned int istrip = 0; istrip < strips.size(); ++istrip) {
507
508 if (!astrip[istrip]) continue;
509 assert(strips[istrip] != 0);
510
511 if (!incluster) {
512 incluster = true;
513 nstrip = 0;
514 first_strip = istrip;
515 }
516 ++nstrip;
517
518
519
520 if (istrip != maxstrip - 1 && astrip[istrip + 1]) continue;
521
522
523 if (!measphi && nstrip < 3) {
524 bool collectLeftStrip = false;
525 bool collectRightStrip = false;
526
527 if (nstrip == 1) {
528 if (int(istrip) >= nstrip
529 && istrip + 1 < maxstrip
530 && (allStripfits[istrip - 1].
charge > 0.1 && allStripfits[istrip + 1].
charge > 0.1)
531 && strips[istrip - 1] && strips[istrip + 1]) {
532 collectLeftStrip = true;
533 collectRightStrip = true;
534 }
535 } else if (nstrip == 2) {
536 if (allStripfits[istrip - 1].
charge > allStripfits[istrip].
charge) {
537 if (int(istrip) >= nstrip
538 && allStripfits[istrip - 2].
charge > 0.1
539 && strips[istrip - 2])
540 collectLeftStrip = true;
541 } else {
542 if (istrip + 1 < maxstrip &&
543 allStripfits[istrip + 1].
charge > 0.1
544 && strips[istrip + 1])
545 collectRightStrip = true;
546 }
547 }
548
549 if (collectLeftStrip) {
550 first_strip = first_strip - 1;
551 nstrip += 1;
552 }
553 if (collectRightStrip) { nstrip += 1; }
554
556
557 ostringstream narrowlog;
558 narrowlog << " ** narrow Clusters " << first_strip + 1 << " " << nstrip << " L:R " << collectLeftStrip << " "
559 << collectRightStrip;
560 for (
int i = 0;
i < nstrip; ++
i) { narrowlog <<
" " << allStripfits[first_strip +
i].charge; }
561 for (
int i = 0;
i < nstrip; ++
i) { narrowlog <<
" " << strips[first_strip +
i]; }
563 }
564 }
565
566 strip0s.push_back(first_strip);
567 nstrips.push_back(nstrip);
568
569
570 incluster = false;
571 }
572
574
575
576
577
579 vector<unsigned int> newStrip0s;
580 vector<unsigned int> newNstrips;
581
582 int nMerged = 0;
583 for (unsigned int icl = 0; icl < nstrips.size(); ++icl) {
584 unsigned int nstrip = nstrips[icl];
585 unsigned int strip0 = strip0s[icl];
586
587 ATH_MSG_VERBOSE(
" " << icl <<
"th cluster merger " << strip0 <<
" " << nstrip);
588
589
590 if (!measphi) {
591 if (nstrip < 3) {
592
593 if (icl > 0 && (strip0 == strip0s[icl - 1] + nstrips[icl - 1])) {
594 unsigned int newStrip0 = strip0s[icl - 1];
595 unsigned int newNstrip = nstrips[icl - 1] + nstrip;
596
597 ATH_MSG_DEBUG(
" " << icl <<
" ** narrow Cluster merger Type I" << newStrip0 <<
" " << newNstrip);
598
599 newStrip0s[icl - 1 - nMerged] = newStrip0;
600 newNstrips[icl - 1 - nMerged] = newNstrip;
601 ++nMerged;
602 continue;
603 }
604
605 if (icl + 1 < nstrips.size() && (strip0 + nstrip == strip0s[icl + 1])) {
606 unsigned int newStrip0 = strip0;
607 unsigned int newNstrip = nstrip + nstrips[icl + 1];
608
609 ATH_MSG_DEBUG(
" " << icl <<
" ** narrow Cluster merger Type II" << newStrip0 <<
" " << newNstrip);
610
611 newStrip0s.push_back(newStrip0);
612 newNstrips.push_back(newNstrip);
613
614 icl += 1;
615 ++nMerged;
616 continue;
617 }
618 }
619 }
620
621
622 newStrip0s.push_back(strip0);
623 newNstrips.push_back(nstrip);
624 }
625
626 if (strip0s.size() != newStrip0s.size()) {
627 ATH_MSG_DEBUG(
" Phase II -> III Merged " << strip0s.size() <<
":" << nstrips.size() <<
" " << newStrip0s.size() <<
":"
628 << newNstrips.size());
629 for (unsigned int icl = 0; icl < nstrips.size(); ++icl)
630 ATH_MSG_DEBUG(
" *** " << icl <<
" [" << strip0s[icl] <<
"," << strip0s[icl] + nstrips[icl] - 1 <<
"] " << nstrips[icl]);
631 for (unsigned int icl = 0; icl < newNstrips.size(); ++icl)
632 ATH_MSG_DEBUG(
" ****** " << icl <<
" [" << newStrip0s[icl] <<
"," << newStrip0s[icl] + newNstrips[icl] - 1 <<
"] "
633 << newNstrips[icl]);
634 }
635
637
638
639
641
643 std::vector<const CscStripPrepData*> clusterStrips;
644 clusterStrips.reserve(50);
645 std::vector<Identifier> prd_digit_ids;
646 prd_digit_ids.reserve(50);
647
648 for (unsigned int icl = 0; icl < newNstrips.size(); ++icl) {
649
651
652 unsigned int nstrip = newNstrips[icl];
653 unsigned int strip0 = newStrip0s[icl];
654
655 sfits.clear();
656 clusterStrips.clear();
657 prd_digit_ids.clear();
658
659 for (unsigned int ist = strip0; ist < strip0 + nstrip; ++ist) {
662
663 sfits.push_back(sfit);
664 clusterStrips.push_back(pstrip);
665 prd_digit_ids.push_back(pstrip->
identify());
666 }
667
674
675 bool leftToFill = false;
676 bool rightToFill = false;
677 if (nstrip == 1) {
678 leftToFill = true;
679 rightToFill = true;
680 } else {
682 leftToFill = true;
684 rightToFill = true;
685 } else {
687 if (strip0 > 0) {
688 if (strips[strip0 - 1]) {
689 leftToFill = true;
690 } else if (strips[strip0 + 2]) {
691 rightToFill = true;
692 }
693 } else if (strips[strip0 + 2]) {
694 rightToFill = true;
695 }
696 }
697 }
698
699 ATH_MSG_VERBOSE(
" strip0 nstrip filling left or right " << strip0 <<
" " << nstrip <<
" " << leftToFill <<
" "
700 << rightToFill);
703
704 for (
unsigned int i = 0;
i < allStripfits.size(); ++
i) {
ATH_MSG_VERBOSE(
"index " << i <<
" " << allStripfits[i].
charge); }
705
706 if (leftToFill) {
707
708 bool fillTheOtherSide = false;
709 if (strip0 == 0) {
710 fillTheOtherSide = true;
711 } else {
712 if (strips[strip0 - 1] == nullptr) fillTheOtherSide = true;
713 }
714
715 if (strip0 + nstrip >= allStripfits.size()) { fillTheOtherSide = false; }
716
717 if (!fillTheOtherSide) {
718 if (strips[strip0 - 1]) {
719 sfits.insert(sfits.begin(), allStripfits[strip0 - 1]);
720 clusterStrips.insert(clusterStrips.begin(), strips[strip0 - 1]);
721 prd_digit_ids.insert(prd_digit_ids.begin(), strips[strip0 - 1]->identify());
722 strip0--;
723 nstrip = prd_digit_ids.size();
724 }
725 } else {
726 if (strips[strip0 + nstrip]) {
727 sfits.push_back(allStripfits[strip0 + nstrip]);
728
729 clusterStrips.push_back(strips[strip0 + nstrip]);
730 prd_digit_ids.push_back(strips[strip0 + nstrip]->
identify());
731 nstrip = prd_digit_ids.size();
732 }
733 }
734 }
735
736 if (rightToFill) {
737 bool fillTheOtherSide = false;
738 if (strip0 + nstrip >= allStripfits.size()) {
739 fillTheOtherSide = true;
740 } else {
741 if (strips[strip0 + nstrip] == nullptr) fillTheOtherSide = true;
742 }
743
744 if (strip0 == 0) { fillTheOtherSide = false; }
745
746 if (!fillTheOtherSide) {
747 if (strips[strip0 + nstrip]) {
748 sfits.push_back(allStripfits[strip0 + nstrip]);
749 clusterStrips.push_back(strips[strip0 + nstrip]);
750 prd_digit_ids.push_back(strips[strip0 + nstrip]->
identify());
751 nstrip = prd_digit_ids.size();
752 }
753 } else {
754 if (strips[strip0 - 1]) {
755 sfits.insert(sfits.begin(), allStripfits[strip0 - 1]);
756 clusterStrips.insert(clusterStrips.begin(), strips[strip0 - 1]);
757 prd_digit_ids.insert(prd_digit_ids.begin(), strips[strip0 - 1]->identify());
758 strip0--;
759 nstrip = prd_digit_ids.size();
760 }
761 }
762 }
763 }
765
767 std::vector<ICscClusterFitter::Result>
results;
768
769
770 if (!measphi) {
774
775
776 if (fitresult == 6) {
779 for (
unsigned int i = 0;
i <
results.size(); ++
i)
781 }
782 }
783
785
786 if (measphi || precisionFitFailed) {
787 ICscClusterFitter::Result
res;
789 if (!measphi) {
791 oldclustatus =
res.clusterStatus;
792 } else {
794 }
799 if (
msgLvl(MSG::VERBOSE)) {
800 ostringstream deflog;
802 if (fitresult) {
803 deflog <<
" failed: return=" <<
fitresult;
804 } else {
805 deflog << " succeeded";
806 }
808 }
809
811 res.clusterStatus = oldclustatus;
812
814 }
815 }
816 }
817
819
820
821
823 unsigned int nresults =
results.size();
824 for (unsigned int ire = 0; ire < nresults; ++ire) {
829 unsigned int id_strip =
results[ire].strip;
830 double cluster_charge =
results[ire].charge;
831 double cluster_time =
results[ire].time;
833
834 if (id_strip >= sfits.size()) {
836 continue;
837 }
838
840 if (id_strip < clusterStrips.size()) pstrip_id = clusterStrips[id_strip];
841 if (!pstrip_id) {
843 continue;
844 }
845
846
847 Identifier cluster_id = pstrip_id->
identify();
849 int zsec =
m_idHelperSvc->cscIdHelper().stationEta(cluster_id);
850 int wlay =
m_idHelperSvc->cscIdHelper().wireLayer(cluster_id);
851
852
854 const MuonGM::MuonDetectorManager* MuonDetMgr = DetectorManagerHandle.
cptr();
855 if (MuonDetMgr == nullptr) {
856 ATH_MSG_ERROR(
"Null pointer to the MuonDetectorManager conditions object");
857 return 0;
858 }
860
862
865 Amg::Vector2D plpos(measphi ? localTrk_pos.y() : localTrk_pos.z(), measphi ? localTrk_pos.z() : localTrk_pos.y());
868 ATH_MSG_DEBUG(
" ID strip: " << first_strip + id_strip <<
"(" << first_strip <<
":" << id_strip <<
")");
873 }
874 unsigned int fstrip =
results[ire].fstrip;
875 unsigned int lstrip =
results[ire].lstrip;
876 std::vector<Identifier> prd_digit_ids_submit;
877 for (unsigned int ids_index = fstrip; ids_index < lstrip + 1; ++ids_index) {
878 if (ids_index >= prd_digit_ids.size()) {
879 ATH_MSG_WARNING(
"index out of range " << ids_index <<
" size " << prd_digit_ids.size());
880 continue;
881 }
882 prd_digit_ids_submit.push_back(prd_digit_ids[ids_index]);
883 }
884 unsigned int nstrip = prd_digit_ids_submit.size();
886 ATH_MSG_DEBUG(
" all size: " << strips.size() <<
" " << allStripfits.size());
887
888
889
891 cluster_hash,
892 plpos,
893 prd_digit_ids_submit,
894 cov,
895 pro,
896 int(cluster_charge + 0.5),
897 cluster_time,
898 clustatus,
899 timeStatus);
901 newCollection->size());
902
903 newCollection->push_back(pclus);
904 }
905 }
906
907 return 0;
908}
double charge(const T &p)
std::pair< std::vector< unsigned int >, bool > res
bool msgLvl(const MSG::Level lvl) const
ICscStripFitter::Result StripFit
std::vector< StripFit > StripFitList
Amg::Vector3D nominalLocalClusterPos(int eta, int wireLayer, int measPhi, double x0) const
ignores internal alignment parameters, hence gives generally incorrect answer (local here is the stat...
void setHashAndIndex(unsigned short collHash, unsigned short objIndex)
TEMP for testing: might make some classes friends later ...
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Eigen::Matrix< double, 2, 1 > Vector2D
Eigen::Matrix< double, 3, 1 > Vector3D
std::string toString(CscStripStatus cstat)
Return a string description of a CSC cluster status flag.
CscClusterStatus
Enum to represent the cluster status - see the specific enum values for more details.
@ CscStatusSimple
Cluster with non-precision fit.
@ CscStatusUndefined
Undefined, should not happen, most likely indicates a problem.
CscTimeStatus
Enum to represent the cluster time measurement status - see the specific enum values for more details...
const Identifier & identify(const UncalibratedMeasurement *meas)
Returns the associated identifier from the muon measurement.