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 ");
403 }
404
406
407 float stripNoise = 0;
414 stripNoise /= 3.251;
415 }
416
418 if (isBadChannel)
active =
false;
419
421
422 ostringstream strlog;
423 strlog <<
" Strip " << setw(3) << istrip + 1 <<
": charge= " << setw(7) <<
int(
res.charge) <<
" dcharge= " << setw(7)
425 if (std::fabs(
res.time) < 1e8)
426 strlog <<
" time=" << setw(3) <<
int(
res.time + 0.5);
427 else
428 strlog << " time=OVERFLOW";
429 if (active)
430 strlog << " *";
431 else if (isBadChannel)
432 strlog << " b";
433 else
434 strlog << " .";
436 strlog << " x";
437 else
438 strlog << " o";
439 strlog <<
" :" <<
res.status;
441 }
442 }
443 allStripfits.push_back(
res);
444 astrip.push_back(active);
445 bstrip.push_back(isBadChannel);
446 }
447
449
450
451
453
454
455 std::vector<bool> rstrip;
456 bool IsAnyStripRecovered = false;
457 for (unsigned int istrip = 0; istrip < strips.size(); ++istrip) {
458 bool adjacentActive = false;
459 if (bstrip[istrip]) {
460 if (istrip > 0 && astrip[istrip - 1]) adjacentActive = true;
461 if (istrip + 1 < strips.size() && astrip[istrip + 1]) adjacentActive = true;
462 if (adjacentActive) IsAnyStripRecovered = true;
463 }
464 rstrip.push_back(adjacentActive);
465 }
466
467
468 if (IsAnyStripRecovered) {
469
471 ostringstream checklog1;
472 ostringstream checklog2;
473
474 for (unsigned int istrip = 0; istrip < strips.size(); ++istrip) {
475 if (istrip % 24 == 0) checklog1 << "\n";
476 checklog1 <<
int(astrip[istrip]) <<
" ";
477
478 if (!astrip[istrip] && rstrip[istrip]) {
480 }
481 if (istrip % 24 == 0) checklog2 << "\n";
482 checklog2 <<
int(astrip[istrip]) <<
" ";
483 }
487 }
488
489 for (unsigned int istrip = 0; istrip < strips.size(); ++istrip) {
490 if (!astrip[istrip] && rstrip[istrip]) {
491 astrip[istrip] = rstrip[istrip];
492 }
493 }
494 }
496
497
498
500 vector<unsigned int> strip0s;
501 vector<unsigned int> nstrips;
502
503
504 int nstrip = 0;
505 int first_strip = 0;
506 bool incluster = false;
507 for (unsigned int istrip = 0; istrip < strips.size(); ++istrip) {
508
509 if (!astrip[istrip]) continue;
510 assert(strips[istrip] != 0);
511
512 if (!incluster) {
513 incluster = true;
514 nstrip = 0;
515 first_strip = istrip;
516 }
517 ++nstrip;
518
519
520
521 if (istrip != maxstrip - 1 && astrip[istrip + 1]) continue;
522
523
524 if (!measphi && nstrip < 3) {
525 bool collectLeftStrip = false;
526 bool collectRightStrip = false;
527
528 if (nstrip == 1) {
529 if (int(istrip) >= nstrip
530 && istrip + 1 < maxstrip
531 && (allStripfits[istrip - 1].
charge > 0.1 && allStripfits[istrip + 1].
charge > 0.1)
532 && strips[istrip - 1] && strips[istrip + 1]) {
533 collectLeftStrip = true;
534 collectRightStrip = true;
535 }
536 } else if (nstrip == 2) {
537 if (allStripfits[istrip - 1].
charge > allStripfits[istrip].
charge) {
538 if (int(istrip) >= nstrip
539 && allStripfits[istrip - 2].
charge > 0.1
540 && strips[istrip - 2])
541 collectLeftStrip = true;
542 } else {
543 if (istrip + 1 < maxstrip &&
544 allStripfits[istrip + 1].
charge > 0.1
545 && strips[istrip + 1])
546 collectRightStrip = true;
547 }
548 }
549
550 if (collectLeftStrip) {
551 first_strip = first_strip - 1;
552 nstrip += 1;
553 }
554 if (collectRightStrip) { nstrip += 1; }
555
557
558 ostringstream narrowlog;
559 narrowlog << " ** narrow Clusters " << first_strip + 1 << " " << nstrip << " L:R " << collectLeftStrip << " "
560 << collectRightStrip;
561 for (
int i = 0;
i < nstrip; ++
i) { narrowlog <<
" " << allStripfits[first_strip +
i].charge; }
562 for (
int i = 0;
i < nstrip; ++
i) { narrowlog <<
" " << strips[first_strip +
i]; }
564 }
565 }
566
567 strip0s.push_back(first_strip);
568 nstrips.push_back(nstrip);
569
570
571 incluster = false;
572 }
573
575
576
577
578
580 vector<unsigned int> newStrip0s;
581 vector<unsigned int> newNstrips;
582
583 int nMerged = 0;
584 for (unsigned int icl = 0; icl < nstrips.size(); ++icl) {
585 unsigned int nstrip = nstrips[icl];
586 unsigned int strip0 = strip0s[icl];
587
588 ATH_MSG_VERBOSE(
" " << icl <<
"th cluster merger " << strip0 <<
" " << nstrip);
589
590
591 if (!measphi) {
592 if (nstrip < 3) {
593
594 if (icl > 0 && (strip0 == strip0s[icl - 1] + nstrips[icl - 1])) {
595 unsigned int newStrip0 = strip0s[icl - 1];
596 unsigned int newNstrip = nstrips[icl - 1] + nstrip;
597
598 ATH_MSG_DEBUG(
" " << icl <<
" ** narrow Cluster merger Type I" << newStrip0 <<
" " << newNstrip);
599
600 newStrip0s[icl - 1 - nMerged] = newStrip0;
601 newNstrips[icl - 1 - nMerged] = newNstrip;
602 ++nMerged;
603 continue;
604 }
605
606 if (icl + 1 < nstrips.size() && (strip0 + nstrip == strip0s[icl + 1])) {
607 unsigned int newStrip0 = strip0;
608 unsigned int newNstrip = nstrip + nstrips[icl + 1];
609
610 ATH_MSG_DEBUG(
" " << icl <<
" ** narrow Cluster merger Type II" << newStrip0 <<
" " << newNstrip);
611
612 newStrip0s.push_back(newStrip0);
613 newNstrips.push_back(newNstrip);
614
615 icl += 1;
616 ++nMerged;
617 continue;
618 }
619 }
620 }
621
622
623 newStrip0s.push_back(strip0);
624 newNstrips.push_back(nstrip);
625 }
626
627 if (strip0s.size() != newStrip0s.size()) {
628 ATH_MSG_DEBUG(
" Phase II -> III Merged " << strip0s.size() <<
":" << nstrips.size() <<
" " << newStrip0s.size() <<
":"
629 << newNstrips.size());
630 for (unsigned int icl = 0; icl < nstrips.size(); ++icl)
631 ATH_MSG_DEBUG(
" *** " << icl <<
" [" << strip0s[icl] <<
"," << strip0s[icl] + nstrips[icl] - 1 <<
"] " << nstrips[icl]);
632 for (unsigned int icl = 0; icl < newNstrips.size(); ++icl)
633 ATH_MSG_DEBUG(
" ****** " << icl <<
" [" << newStrip0s[icl] <<
"," << newStrip0s[icl] + newNstrips[icl] - 1 <<
"] "
634 << newNstrips[icl]);
635 }
636
638
639
640
642
644 std::vector<const CscStripPrepData*> clusterStrips;
645 clusterStrips.reserve(50);
646 std::vector<Identifier> prd_digit_ids;
647 prd_digit_ids.reserve(50);
648
649 for (unsigned int icl = 0; icl < newNstrips.size(); ++icl) {
650
652
653 unsigned int nstrip = newNstrips[icl];
654 unsigned int strip0 = newStrip0s[icl];
655
656 sfits.clear();
657 clusterStrips.clear();
658 prd_digit_ids.clear();
659
660 for (unsigned int ist = strip0; ist < strip0 + nstrip; ++ist) {
663
664 sfits.push_back(sfit);
665 clusterStrips.push_back(pstrip);
666 prd_digit_ids.push_back(pstrip->
identify());
667 }
668
675
676 bool leftToFill = false;
677 bool rightToFill = false;
678 if (nstrip == 1) {
679 leftToFill = true;
680 rightToFill = true;
681 } else {
683 leftToFill = true;
685 rightToFill = true;
686 } else {
688 if (strip0 > 0) {
689 if (strips[strip0 - 1]) {
690 leftToFill = true;
691 } else if (strips[strip0 + 2]) {
692 rightToFill = true;
693 }
694 } else if (strips[strip0 + 2]) {
695 rightToFill = true;
696 }
697 }
698 }
699
700 ATH_MSG_VERBOSE(
" strip0 nstrip filling left or right " << strip0 <<
" " << nstrip <<
" " << leftToFill <<
" "
701 << rightToFill);
704
705 for (
unsigned int i = 0;
i < allStripfits.size(); ++
i) {
ATH_MSG_VERBOSE(
"index " << i <<
" " << allStripfits[i].
charge); }
706
707 if (leftToFill) {
708
709 bool fillTheOtherSide = false;
710 if (strip0 == 0) {
711 fillTheOtherSide = true;
712 } else {
713 if (strips[strip0 - 1] == nullptr) fillTheOtherSide = true;
714 }
715
716 if (strip0 + nstrip >= allStripfits.size()) { fillTheOtherSide = false; }
717
718 if (!fillTheOtherSide) {
719 if (strips[strip0 - 1]) {
720 sfits.insert(sfits.begin(), allStripfits[strip0 - 1]);
721 clusterStrips.insert(clusterStrips.begin(), strips[strip0 - 1]);
722 prd_digit_ids.insert(prd_digit_ids.begin(), strips[strip0 - 1]->identify());
723 strip0--;
724 nstrip = prd_digit_ids.size();
725 }
726 } else {
727 if (strips[strip0 + nstrip]) {
728 sfits.push_back(allStripfits[strip0 + nstrip]);
729
730 clusterStrips.push_back(strips[strip0 + nstrip]);
731 prd_digit_ids.push_back(strips[strip0 + nstrip]->
identify());
732 nstrip = prd_digit_ids.size();
733 }
734 }
735 }
736
737 if (rightToFill) {
738 bool fillTheOtherSide = false;
739 if (strip0 + nstrip >= allStripfits.size()) {
740 fillTheOtherSide = true;
741 } else {
742 if (strips[strip0 + nstrip] == nullptr) fillTheOtherSide = true;
743 }
744
745 if (strip0 == 0) { fillTheOtherSide = false; }
746
747 if (!fillTheOtherSide) {
748 if (strips[strip0 + nstrip]) {
749 sfits.push_back(allStripfits[strip0 + nstrip]);
750 clusterStrips.push_back(strips[strip0 + nstrip]);
751 prd_digit_ids.push_back(strips[strip0 + nstrip]->
identify());
752 nstrip = prd_digit_ids.size();
753 }
754 } else {
755 if (strips[strip0 - 1]) {
756 sfits.insert(sfits.begin(), allStripfits[strip0 - 1]);
757 clusterStrips.insert(clusterStrips.begin(), strips[strip0 - 1]);
758 prd_digit_ids.insert(prd_digit_ids.begin(), strips[strip0 - 1]->identify());
759 strip0--;
760 nstrip = prd_digit_ids.size();
761 }
762 }
763 }
764 }
766
768 std::vector<ICscClusterFitter::Result>
results;
769
770
771 if (!measphi) {
775
776
777 if (fitresult == 6) {
780 for (
unsigned int i = 0;
i <
results.size(); ++
i)
782 }
783 }
784
786
787 if (measphi || precisionFitFailed) {
788 ICscClusterFitter::Result
res;
790 if (!measphi) {
792 oldclustatus =
res.clusterStatus;
793 } else {
795 }
800 if (
msgLvl(MSG::VERBOSE)) {
801 ostringstream deflog;
803 if (fitresult) {
804 deflog <<
" failed: return=" <<
fitresult;
805 } else {
806 deflog << " succeeded";
807 }
809 }
810
812 res.clusterStatus = oldclustatus;
813
815 }
816 }
817 }
818
820
821
822
824 unsigned int nresults =
results.size();
825 for (unsigned int ire = 0; ire < nresults; ++ire) {
830 unsigned int id_strip =
results[ire].strip;
831 double cluster_charge =
results[ire].charge;
832 double cluster_time =
results[ire].time;
834
835 if (id_strip >= sfits.size()) {
837 continue;
838 }
839
841 if (id_strip < clusterStrips.size()) pstrip_id = clusterStrips[id_strip];
842 if (!pstrip_id) {
844 continue;
845 }
846
847
848 Identifier cluster_id = pstrip_id->
identify();
850 int zsec =
m_idHelperSvc->cscIdHelper().stationEta(cluster_id);
851 int wlay =
m_idHelperSvc->cscIdHelper().wireLayer(cluster_id);
852
853
855 const MuonGM::MuonDetectorManager* MuonDetMgr = DetectorManagerHandle.
cptr();
856 if (MuonDetMgr == nullptr) {
857 ATH_MSG_ERROR(
"Null pointer to the MuonDetectorManager conditions object");
858 return 0;
859 }
861
863
866 Amg::Vector2D plpos(measphi ? localTrk_pos.y() : localTrk_pos.z(), measphi ? localTrk_pos.z() : localTrk_pos.y());
869 ATH_MSG_DEBUG(
" ID strip: " << first_strip + id_strip <<
"(" << first_strip <<
":" << id_strip <<
")");
874 }
875 unsigned int fstrip =
results[ire].fstrip;
876 unsigned int lstrip =
results[ire].lstrip;
877 std::vector<Identifier> prd_digit_ids_submit;
878 for (unsigned int ids_index = fstrip; ids_index < lstrip + 1; ++ids_index) {
879 if (ids_index >= prd_digit_ids.size()) {
880 ATH_MSG_WARNING(
"index out of range " << ids_index <<
" size " << prd_digit_ids.size());
881 continue;
882 }
883 prd_digit_ids_submit.push_back(prd_digit_ids[ids_index]);
884 }
885 unsigned int nstrip = prd_digit_ids_submit.size();
887 ATH_MSG_DEBUG(
" all size: " << strips.size() <<
" " << allStripfits.size());
888
889
890
892 cluster_hash,
893 plpos,
894 prd_digit_ids_submit,
895 cov,
896 pro,
897 int(cluster_charge + 0.5),
898 cluster_time,
899 clustatus,
900 timeStatus);
902 newCollection->size());
903
904 newCollection->push_back(pclus);
905 }
906 }
907
908 return 0;
909}
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
void show() const
Print out in hex form.
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.