16 #include "Gaudi/Property.h"
31 using std::ostringstream;
41 std::string
chamber(
int istation,
int zsec,
int phi) {
45 else if (istation == 2)
60 std::string setaphi(
bool measphi) {
61 if (measphi)
return "phi";
70 const IInterface*
parent) :
72 declareInterface<ICscClusterBuilder>(
this);
96 ATH_MSG_DEBUG(
" noiseOption is not among rms/sigma/f001. rms is used for default!!");
125 ATH_MSG_DEBUG(
"Retrieved CSC precision cluster fitting tool");
135 return StatusCode::SUCCESS;
144 if (!givenIDs.empty()) {
145 for (
unsigned int i = 0;
i < givenIDs.size(); ++
i) {
146 if (
getClusters(givenIDs[
i], decodedIds,
object).isFailure()) {
147 ATH_MSG_ERROR(
"Unable to decode CSC RDO " <<
i <<
"th into CSC PrepRawData");
148 return StatusCode::RECOVERABLE;
154 ATH_MSG_ERROR(
"Unable to decode CSC RDO into CSC PrepRawData");
155 return StatusCode::RECOVERABLE;
159 return StatusCode::SUCCESS;
168 decodedIds.push_back(givenHashId);
169 ATH_MSG_DEBUG(
"A collection already exists in the container for offline id hash. " << (
int)givenHashId);
170 return StatusCode::SUCCESS;
179 return StatusCode::SUCCESS;
185 if (
nullptr ==
col) {
186 unsigned int coll_hash = givenHashId;
187 ATH_MSG_WARNING(
"Specific CSC Strip PrepData collection retrieving failed for collection hash = " << coll_hash);
188 return StatusCode::SUCCESS;
194 int istation =
m_idHelperSvc->cscIdHelper().stationName(colid) - 49;
201 vector<const CscStripPrepData*> strips[8];
202 int maxstrip[8] = {0, 0, 0, 0, 0, 0, 0, 0};
207 if (MuonDetMgr ==
nullptr) {
208 ATH_MSG_ERROR(
"Null pointer to the MuonDetectorManager conditions object");
209 return StatusCode::FAILURE;
214 for (CscStripPrepDataCollection::const_iterator idig =
col->begin(); idig !=
col->end(); ++idig) {
221 int idx = 2 * (wlay - 1) + measphi;
223 if (maxstrip[
idx] == 0) {
225 for (
int istrip = 0; istrip < maxstrip[
idx]; ++istrip) strips[
idx].push_back(
nullptr);
228 if (istrip < 0 || istrip >= maxstrip[
idx]) {
232 strips[
idx][istrip] = &dig;
237 for (
int measphi = 0; measphi < 2; ++measphi) {
238 for (
int wlay = 1; wlay < 5; ++wlay) {
239 int idx = 2 * (wlay - 1) + measphi;
248 ATH_MSG_ERROR(
"Couldn't add CscPrepdataCollection to container!");
249 return StatusCode::RECOVERABLE;
251 decodedIds.push_back(
hash);
254 return StatusCode::SUCCESS;
266 return StatusCode::SUCCESS;
272 for (CscStripPrepDataContainer::const_iterator
icol = con.begin();
icol != con.end(); ++
icol) {
277 decodedIds.push_back(
col.identifyHash());
281 int istation =
m_idHelperSvc->cscIdHelper().stationName(colid) - 49;
285 <<
" has " <<
col.size() <<
" strips");
288 vector<const CscStripPrepData*> strips[8];
289 int maxstrip[8] = {0, 0, 0, 0, 0, 0, 0, 0};
294 if (MuonDetMgr ==
nullptr) {
295 ATH_MSG_ERROR(
"Null pointer to the MuonDetectorManager conditions object");
296 return StatusCode::FAILURE;
301 for (CscStripPrepDataCollection::const_iterator idig =
col.begin(); idig !=
col.end(); ++idig) {
308 int idx = 2 * (wlay - 1) + measphi;
310 if (maxstrip[
idx] == 0) {
312 for (
int istrip = 0; istrip < maxstrip[
idx]; ++istrip) strips[
idx].push_back(
nullptr);
315 if (istrip < 0 || istrip >= maxstrip[
idx]) {
319 strips[
idx][istrip] = &dig;
324 for (
int measphi = 0; measphi < 2; ++measphi) {
325 for (
int wlay = 1; wlay < 5; ++wlay) {
326 int idx = 2 * (wlay - 1) + measphi;
329 <<
" " << wlay <<
"th layer ");
336 ATH_MSG_ERROR(
"Couldn't add CscPrepdataCollection to container!");
337 return StatusCode::FAILURE;
339 decodedIds.push_back(
hash);
343 return StatusCode::SUCCESS;
349 return StatusCode::SUCCESS;
367 unsigned int maxstrip = strips.size();
369 ATH_MSG_DEBUG(
" Clustering for " << setaphi(measphi) <<
" plane with " << maxstrip <<
" strips");
378 std::vector<bool> astrip;
379 std::vector<bool> bstrip;
383 for (
unsigned int istrip = 0; istrip < strips.size(); ++istrip) {
387 bool isBadChannel =
false;
389 if (!newCollection) {
393 newCollection->setIdentifier(elementId);
399 if (
m_idHelperSvc->cscIdHelper().get_channel_hash(stripId, stripHash)) {
401 <<
" the identifier is ");
407 float stripNoise = 0;
418 if (isBadChannel)
active =
false;
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);
428 strlog <<
" time=OVERFLOW";
431 else if (isBadChannel)
439 strlog <<
" :" <<
res.status;
443 allStripfits.push_back(
res);
445 bstrip.push_back(isBadChannel);
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;
464 rstrip.push_back(adjacentActive);
468 if (IsAnyStripRecovered) {
471 ostringstream checklog1;
472 ostringstream checklog2;
474 for (
unsigned int istrip = 0; istrip < strips.size(); ++istrip) {
475 if (istrip % 24 == 0) checklog1 <<
"\n";
476 checklog1 <<
int(astrip[istrip]) <<
" ";
478 if (!astrip[istrip] && rstrip[istrip]) {
481 if (istrip % 24 == 0) checklog2 <<
"\n";
482 checklog2 <<
int(astrip[istrip]) <<
" ";
489 for (
unsigned int istrip = 0; istrip < strips.size(); ++istrip) {
490 if (!astrip[istrip] && rstrip[istrip]) {
491 astrip[istrip] = rstrip[istrip];
500 vector<unsigned int> strip0s;
501 vector<unsigned int> nstrips;
506 bool incluster =
false;
507 for (
unsigned int istrip = 0; istrip < strips.size(); ++istrip) {
509 if (!astrip[istrip])
continue;
510 assert(strips[istrip] != 0);
515 first_strip = istrip;
521 if (istrip != maxstrip - 1 && astrip[istrip + 1])
continue;
524 if (!measphi && nstrip < 3) {
525 bool collectLeftStrip =
false;
526 bool collectRightStrip =
false;
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;
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;
543 if (istrip + 1 < maxstrip &&
544 allStripfits[istrip + 1].
charge > 0.1
545 && strips[istrip + 1])
546 collectRightStrip =
true;
550 if (collectLeftStrip) {
551 first_strip = first_strip - 1;
554 if (collectRightStrip) { nstrip += 1; }
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]; }
567 strip0s.push_back(first_strip);
568 nstrips.push_back(nstrip);
580 vector<unsigned int> newStrip0s;
581 vector<unsigned int> newNstrips;
584 for (
unsigned int icl = 0; icl < nstrips.size(); ++icl) {
585 unsigned int nstrip = nstrips[icl];
586 unsigned int strip0 = strip0s[icl];
588 ATH_MSG_VERBOSE(
" " << icl <<
"th cluster merger " << strip0 <<
" " << nstrip);
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;
598 ATH_MSG_DEBUG(
" " << icl <<
" ** narrow Cluster merger Type I" << newStrip0 <<
" " << newNstrip);
600 newStrip0s[icl - 1 - nMerged] = newStrip0;
601 newNstrips[icl - 1 - nMerged] = newNstrip;
606 if (icl + 1 < nstrips.size() && (strip0 + nstrip == strip0s[icl + 1])) {
607 unsigned int newStrip0 = strip0;
608 unsigned int newNstrip = nstrip + nstrips[icl + 1];
610 ATH_MSG_DEBUG(
" " << icl <<
" ** narrow Cluster merger Type II" << newStrip0 <<
" " << newNstrip);
612 newStrip0s.push_back(newStrip0);
613 newNstrips.push_back(newNstrip);
623 newStrip0s.push_back(strip0);
624 newNstrips.push_back(nstrip);
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 <<
"] "
644 std::vector<const CscStripPrepData*> clusterStrips;
645 clusterStrips.reserve(50);
646 std::vector<Identifier> prd_digit_ids;
647 prd_digit_ids.reserve(50);
649 for (
unsigned int icl = 0; icl < newNstrips.size(); ++icl) {
653 unsigned int nstrip = newNstrips[icl];
654 unsigned int strip0 = newStrip0s[icl];
657 clusterStrips.clear();
658 prd_digit_ids.clear();
660 for (
unsigned int ist = strip0; ist < strip0 + nstrip; ++ist) {
664 sfits.push_back(sfit);
665 clusterStrips.push_back(pstrip);
666 prd_digit_ids.push_back(pstrip->
identify());
676 bool leftToFill =
false;
677 bool rightToFill =
false;
689 if (strips[strip0 - 1]) {
691 }
else if (strips[strip0 + 2]) {
694 }
else if (strips[strip0 + 2]) {
700 ATH_MSG_VERBOSE(
" strip0 nstrip filling left or right " << strip0 <<
" " << nstrip <<
" " << leftToFill <<
" "
709 bool fillTheOtherSide =
false;
711 fillTheOtherSide =
true;
713 if (strips[strip0 - 1] ==
nullptr) fillTheOtherSide =
true;
716 if (strip0 + nstrip >= allStripfits.size()) { fillTheOtherSide =
false; }
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());
724 nstrip = prd_digit_ids.size();
727 if (strips[strip0 + nstrip]) {
728 sfits.push_back(allStripfits[strip0 + nstrip]);
730 clusterStrips.push_back(strips[strip0 + nstrip]);
731 prd_digit_ids.push_back(strips[strip0 + nstrip]->
identify());
732 nstrip = prd_digit_ids.size();
738 bool fillTheOtherSide =
false;
739 if (strip0 + nstrip >= allStripfits.size()) {
740 fillTheOtherSide =
true;
742 if (strips[strip0 + nstrip] ==
nullptr) fillTheOtherSide =
true;
745 if (strip0 == 0) { fillTheOtherSide =
false; }
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();
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());
760 nstrip = prd_digit_ids.size();
768 std::vector<ICscClusterFitter::Result>
results;
780 for (
unsigned int i = 0;
i <
results.size(); ++
i)
787 if (measphi || precisionFitFailed) {
792 oldclustatus =
res.clusterStatus;
801 ostringstream deflog;
804 deflog <<
" failed: return=" <<
fitresult;
806 deflog <<
" succeeded";
812 res.clusterStatus = oldclustatus;
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;
835 if (id_strip >= sfits.size()) {
841 if (id_strip < clusterStrips.size()) pstrip_id = clusterStrips[id_strip];
850 int zsec =
m_idHelperSvc->cscIdHelper().stationEta(cluster_id);
851 int wlay =
m_idHelperSvc->cscIdHelper().wireLayer(cluster_id);
856 if (MuonDetMgr ==
nullptr) {
857 ATH_MSG_ERROR(
"Null pointer to the MuonDetectorManager conditions object");
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 <<
")");
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());
883 prd_digit_ids_submit.push_back(prd_digit_ids[ids_index]);
885 unsigned int nstrip = prd_digit_ids_submit.size();
887 ATH_MSG_DEBUG(
" all size: " << strips.size() <<
" " << allStripfits.size());
894 prd_digit_ids_submit,
897 int(cluster_charge + 0.5),
902 newCollection->size());
904 newCollection->push_back(pclus);