87 LogDebug(
"MuonPathAssociator") <<
"starting correlation";
89 for (
int wh = -2; wh <= 2; wh++) {
90 for (
int st = 1; st <= 4; st++) {
91 for (
int se = 1; se <= 14; se++) {
92 if (se >= 13 && st != 4)
100 std::vector<metaPrimitive> SL1metaPrimitives;
101 for (
const auto &metaprimitiveIt : inMPaths) {
102 if (metaprimitiveIt.rawId == sl1Id.rawId())
103 SL1metaPrimitives.push_back(metaprimitiveIt);
107 std::vector<metaPrimitive> SL3metaPrimitives;
108 for (
const auto &metaprimitiveIt : inMPaths) {
109 if (metaprimitiveIt.rawId == sl3Id.rawId())
110 SL3metaPrimitives.push_back(metaprimitiveIt);
113 if (SL1metaPrimitives.empty() and SL3metaPrimitives.empty())
117 LogDebug(
"MuonPathAssociator") <<
"correlating " << SL1metaPrimitives.size() <<
" metaPrim in SL1 and "
118 << SL3metaPrimitives.size() <<
" in SL3 for " << sl3Id;
120 bool at_least_one_correlation =
false;
121 bool at_least_one_SL1_confirmation =
false;
122 bool at_least_one_SL3_confirmation =
false;
124 bool useFitSL1[SL1metaPrimitives.size()];
125 for (
unsigned int i = 0;
i < SL1metaPrimitives.size();
i++)
126 useFitSL1[
i] =
false;
127 bool useFitSL3[SL3metaPrimitives.size()];
128 for (
unsigned int i = 0;
i < SL3metaPrimitives.size();
i++)
129 useFitSL3[
i] =
false;
132 vector<metaPrimitive> chamberMetaPrimitives;
133 vector<metaPrimitive> confirmedMetaPrimitives;
134 vector<metaPrimitive> normalMetaPrimitives;
137 for (
auto SL1metaPrimitive = SL1metaPrimitives.begin(); SL1metaPrimitive != SL1metaPrimitives.end();
138 ++SL1metaPrimitive, sl1++, sl3 = -1) {
140 at_least_one_correlation =
false;
141 for (
auto SL3metaPrimitive = SL3metaPrimitives.begin(); SL3metaPrimitive != SL3metaPrimitives.end();
142 ++SL3metaPrimitive, sl3++) {
155 double NewSlope = -999.;
157 long int pos = (PosSL3 + PosSL1) / 2;
160 if (((PosSL3 + PosSL1) % 2 != 0) && (
pos < 0)) {
164 long int difPos_mm_x4 = PosSL3 - PosSL1;
170 double MeanT0 = (SL1metaPrimitive->t0 + SL3metaPrimitive->t0) / 2;
180 if (shift_sl1 < shift_sl3) {
185 int wi[8], tdc[8], lat[8];
186 wi[0] = SL1metaPrimitive->wi1;
187 tdc[0] = SL1metaPrimitive->tdc1;
188 lat[0] = SL1metaPrimitive->lat1;
189 wi[1] = SL1metaPrimitive->wi2;
190 tdc[1] = SL1metaPrimitive->tdc2;
191 lat[1] = SL1metaPrimitive->lat2;
192 wi[2] = SL1metaPrimitive->wi3;
193 tdc[2] = SL1metaPrimitive->tdc3;
194 lat[2] = SL1metaPrimitive->lat3;
195 wi[3] = SL1metaPrimitive->wi4;
196 tdc[3] = SL1metaPrimitive->tdc4;
197 lat[3] = SL1metaPrimitive->lat4;
198 wi[4] = SL3metaPrimitive->wi1;
199 tdc[4] = SL3metaPrimitive->tdc1;
200 lat[4] = SL3metaPrimitive->lat1;
201 wi[5] = SL3metaPrimitive->wi2;
202 tdc[5] = SL3metaPrimitive->tdc2;
203 lat[5] = SL3metaPrimitive->lat2;
204 wi[6] = SL3metaPrimitive->wi3;
205 tdc[6] = SL3metaPrimitive->tdc3;
206 lat[6] = SL3metaPrimitive->lat3;
207 wi[7] = SL3metaPrimitive->wi4;
208 tdc[7] = SL3metaPrimitive->tdc4;
209 lat[7] = SL3metaPrimitive->lat4;
213 long int Z_FACTOR_CORR[8] = {-6, -2, 2, 6, -6, -2, 2, 6};
215 for (
int i = 0;
i < 8;
i++) {
216 int sign = 2 * (
i / 4) - 1;
219 long int sum_A, sum_B;
221 long int shift, slTime;
224 slTime = SL1metaPrimitive->t0;
227 slTime = SL3metaPrimitive->t0;
231 long int wireHorizPos_x4 =
236 pos_mm_x4 = wireHorizPos_x4 - (drift_dist_um_x4 >> 10);
238 pos_mm_x4 = wireHorizPos_x4 + (drift_dist_um_x4 >> 10);
243 chi2 += ((sum_A - sum_B) * (sum_A - sum_B)) >> 2;
253 useFitSL1[sl1] =
true;
254 useFitSL3[sl3] =
true;
257 if (SL3metaPrimitive->quality ==
LOWQ and SL1metaPrimitive->quality ==
LOWQ)
260 if ((SL3metaPrimitive->quality ==
HIGHQ && SL1metaPrimitive->quality ==
LOWQ)
or
261 (SL1metaPrimitive->quality ==
HIGHQ && SL3metaPrimitive->quality ==
LOWQ))
264 if (SL3metaPrimitive->quality ==
HIGHQ && SL1metaPrimitive->quality ==
HIGHQ)
269 double phi_cmssw = -999.;
270 double phiB_cmssw = -999.;
272 if (
ChId.station() >= 3)
276 int thisec =
ChId.sector();
281 phi_cmssw = jm_x_cmssw_global.
phi() -
PHI_CONV * (thisec - 1);
282 double psi = atan(NewSlope);
286 phi = global_coords[0];
287 phiB = global_coords[1];
290 outMPaths.emplace_back(
ChId.rawId(),
300 SL1metaPrimitive->wi1,
301 SL1metaPrimitive->tdc1,
302 SL1metaPrimitive->lat1,
303 SL1metaPrimitive->wi2,
304 SL1metaPrimitive->tdc2,
305 SL1metaPrimitive->lat2,
306 SL1metaPrimitive->wi3,
307 SL1metaPrimitive->tdc3,
308 SL1metaPrimitive->lat3,
309 SL1metaPrimitive->wi4,
310 SL1metaPrimitive->tdc4,
311 SL1metaPrimitive->lat4,
312 SL3metaPrimitive->wi1,
313 SL3metaPrimitive->tdc1,
314 SL3metaPrimitive->lat1,
315 SL3metaPrimitive->wi2,
316 SL3metaPrimitive->tdc2,
317 SL3metaPrimitive->lat2,
318 SL3metaPrimitive->wi3,
319 SL3metaPrimitive->tdc3,
320 SL3metaPrimitive->lat3,
321 SL3metaPrimitive->wi4,
322 SL3metaPrimitive->tdc4,
323 SL3metaPrimitive->lat4);
325 chamberMetaPrimitives.emplace_back(
ChId.rawId(),
335 SL1metaPrimitive->wi1,
336 SL1metaPrimitive->tdc1,
337 SL1metaPrimitive->lat1,
338 SL1metaPrimitive->wi2,
339 SL1metaPrimitive->tdc2,
340 SL1metaPrimitive->lat2,
341 SL1metaPrimitive->wi3,
342 SL1metaPrimitive->tdc3,
343 SL1metaPrimitive->lat3,
344 SL1metaPrimitive->wi4,
345 SL1metaPrimitive->tdc4,
346 SL1metaPrimitive->lat4,
347 SL3metaPrimitive->wi1,
348 SL3metaPrimitive->tdc1,
349 SL3metaPrimitive->lat1,
350 SL3metaPrimitive->wi2,
351 SL3metaPrimitive->tdc2,
352 SL3metaPrimitive->lat2,
353 SL3metaPrimitive->wi3,
354 SL3metaPrimitive->tdc3,
355 SL3metaPrimitive->lat3,
356 SL3metaPrimitive->wi4,
357 SL3metaPrimitive->tdc4,
358 SL3metaPrimitive->lat4);
360 at_least_one_correlation =
true;
363 if (at_least_one_correlation ==
false &&
365 int matched_digis = 0;
377 for (
const auto &dtLayerId_It : *dtdigis) {
378 const DTLayerId dtLId = dtLayerId_It.first;
381 if (dtSLId.rawId() != sl3Id.rawId())
384 if (dtLId.
layer() == 4)
386 else if (dtLId.
layer() == 3)
388 else if (dtLId.
layer() == 2)
390 else if (dtLId.
layer() == 1)
392 double x_inSL3 = SL1metaPrimitive->x - SL1metaPrimitive->tanPhi * (
VERT_PHI1_PHI3 + l_shift);
393 for (
auto digiIt = (dtLayerId_It.second).first; digiIt != (dtLayerId_It.second).
second; ++digiIt) {
394 DTWireId wireId(dtLId, (*digiIt).wire());
401 x_wire = x_wire_left;
404 if (
std::abs(x_inSL3 - x_wire) < minx) {
407 next_wire = best_wire;
409 next_layer = best_layer;
412 best_wire = (*digiIt).wire();
413 best_tdc = (*digiIt).time();
414 best_layer = dtLId.
layer();
417 }
else if ((
std::abs(x_inSL3 - x_wire) >= minx) && (
std::abs(x_inSL3 - x_wire) < min2x)) {
419 next_wire = (*digiIt).wire();
420 next_tdc = (*digiIt).time();
421 next_layer = dtLId.
layer();
427 if (matched_digis >= 2 and best_layer != -1 and next_layer != -1) {
429 if (SL1metaPrimitive->quality ==
LOWQ)
445 if (next_layer == 1) {
450 if (next_layer == 2) {
455 if (next_layer == 3) {
460 if (next_layer == 4) {
466 if (best_layer == 1) {
471 if (best_layer == 2) {
476 if (best_layer == 3) {
481 if (best_layer == 4) {
489 SL1metaPrimitive->t0,
491 SL1metaPrimitive->tanPhi,
492 SL1metaPrimitive->phi,
493 SL1metaPrimitive->phiB,
494 SL1metaPrimitive->phi_cmssw,
495 SL1metaPrimitive->phiB_cmssw,
496 SL1metaPrimitive->chi2,
498 SL1metaPrimitive->wi1,
499 SL1metaPrimitive->tdc1,
500 SL1metaPrimitive->lat1,
501 SL1metaPrimitive->wi2,
502 SL1metaPrimitive->tdc2,
503 SL1metaPrimitive->lat2,
504 SL1metaPrimitive->wi3,
505 SL1metaPrimitive->tdc3,
506 SL1metaPrimitive->lat3,
507 SL1metaPrimitive->wi4,
508 SL1metaPrimitive->tdc4,
509 SL1metaPrimitive->lat4,
525 SL1metaPrimitive->t0,
527 SL1metaPrimitive->tanPhi,
528 SL1metaPrimitive->phi,
529 SL1metaPrimitive->phiB,
530 SL1metaPrimitive->phi_cmssw,
531 SL1metaPrimitive->phiB_cmssw,
532 SL1metaPrimitive->chi2,
534 SL1metaPrimitive->wi1,
535 SL1metaPrimitive->tdc1,
536 SL1metaPrimitive->lat1,
537 SL1metaPrimitive->wi2,
538 SL1metaPrimitive->tdc2,
539 SL1metaPrimitive->lat2,
540 SL1metaPrimitive->wi3,
541 SL1metaPrimitive->tdc3,
542 SL1metaPrimitive->lat3,
543 SL1metaPrimitive->wi4,
544 SL1metaPrimitive->tdc4,
545 SL1metaPrimitive->lat4,
559 useFitSL1[sl1] =
true;
560 at_least_one_SL1_confirmation =
true;
569 for (
auto SL3metaPrimitive = SL3metaPrimitives.begin(); SL3metaPrimitive != SL3metaPrimitives.end();
570 ++SL3metaPrimitive, sl3++) {
576 int matched_digis = 0;
589 for (
const auto &dtLayerId_It : *dtdigis) {
590 const DTLayerId dtLId = dtLayerId_It.first;
593 if (dtSLId.rawId() != sl1Id.rawId())
596 if (dtLId.
layer() == 4)
598 if (dtLId.
layer() == 3)
600 if (dtLId.
layer() == 2)
602 if (dtLId.
layer() == 1)
604 double x_inSL1 = SL3metaPrimitive->x + SL3metaPrimitive->tanPhi * (
VERT_PHI1_PHI3 - l_shift);
605 for (
auto digiIt = (dtLayerId_It.second).first; digiIt != (dtLayerId_It.second).
second; ++digiIt) {
606 DTWireId wireId(dtLId, (*digiIt).wire());
613 x_wire = x_wire_left;
616 if (
std::abs(x_inSL1 - x_wire) < minx) {
618 next_wire = best_wire;
620 next_layer = best_layer;
623 best_wire = (*digiIt).wire();
624 best_tdc = (*digiIt).time();
625 best_layer = dtLId.
layer();
628 }
else if ((
std::abs(x_inSL1 - x_wire) >= minx) && (
std::abs(x_inSL1 - x_wire) < min2x)) {
630 next_wire = (*digiIt).wire();
631 next_tdc = (*digiIt).time();
632 next_layer = dtLId.
layer();
638 if (matched_digis >= 2 and best_layer != -1 and next_layer != -1) {
640 if (SL3metaPrimitive->quality ==
LOWQ)
656 if (next_layer == 1) {
661 if (next_layer == 2) {
666 if (next_layer == 3) {
671 if (next_layer == 4) {
677 if (best_layer == 1) {
682 if (best_layer == 2) {
687 if (best_layer == 3) {
692 if (best_layer == 4) {
700 SL3metaPrimitive->t0,
702 SL3metaPrimitive->tanPhi,
703 SL3metaPrimitive->phi,
704 SL3metaPrimitive->phiB,
705 SL3metaPrimitive->phi_cmssw,
706 SL3metaPrimitive->phiB_cmssw,
707 SL3metaPrimitive->chi2,
721 SL3metaPrimitive->wi1,
722 SL3metaPrimitive->tdc1,
723 SL3metaPrimitive->lat1,
724 SL3metaPrimitive->wi2,
725 SL3metaPrimitive->tdc2,
726 SL3metaPrimitive->lat2,
727 SL3metaPrimitive->wi3,
728 SL3metaPrimitive->tdc3,
729 SL3metaPrimitive->lat3,
730 SL3metaPrimitive->wi4,
731 SL3metaPrimitive->tdc4,
732 SL3metaPrimitive->lat4,
736 SL3metaPrimitive->t0,
738 SL3metaPrimitive->tanPhi,
739 SL3metaPrimitive->phi,
740 SL3metaPrimitive->phiB,
741 SL3metaPrimitive->phi_cmssw,
742 SL3metaPrimitive->phiB_cmssw,
743 SL3metaPrimitive->chi2,
757 SL3metaPrimitive->wi1,
758 SL3metaPrimitive->tdc1,
759 SL3metaPrimitive->lat1,
760 SL3metaPrimitive->wi2,
761 SL3metaPrimitive->tdc2,
762 SL3metaPrimitive->lat2,
763 SL3metaPrimitive->wi3,
764 SL3metaPrimitive->tdc3,
765 SL3metaPrimitive->lat3,
766 SL3metaPrimitive->wi4,
767 SL3metaPrimitive->tdc4,
768 SL3metaPrimitive->lat4,
770 useFitSL3[sl3] =
true;
771 at_least_one_SL3_confirmation =
true;
778 LogDebug(
"MuonPathAssociator") <<
"Pushing back correlated MPs to the MPs collection";
783 LogDebug(
"MuonPathAssociator") <<
"Pushing back confirmed MPs to the complete vector";
789 if (
debug_ && !at_least_one_correlation)
791 <<
"correlation we found zero correlations, adding both collections as they are to the outMPaths";
794 <<
"correlation sizes:" << SL1metaPrimitives.size() <<
" " << SL3metaPrimitives.size();
797 for (
auto SL1metaPrimitive = SL1metaPrimitives.begin(); SL1metaPrimitive != SL1metaPrimitives.end();
798 ++SL1metaPrimitive, sl1++) {
803 DTChamberId(SLId.wheel(), SLId.station(), SLId.sector());
805 SL1metaPrimitive->t0,
807 SL1metaPrimitive->tanPhi,
808 SL1metaPrimitive->phi,
809 SL1metaPrimitive->phiB,
810 SL1metaPrimitive->phi_cmssw,
811 SL1metaPrimitive->phiB_cmssw,
812 SL1metaPrimitive->chi2,
813 SL1metaPrimitive->quality,
814 SL1metaPrimitive->wi1,
815 SL1metaPrimitive->tdc1,
816 SL1metaPrimitive->lat1,
817 SL1metaPrimitive->wi2,
818 SL1metaPrimitive->tdc2,
819 SL1metaPrimitive->lat2,
820 SL1metaPrimitive->wi3,
821 SL1metaPrimitive->tdc3,
822 SL1metaPrimitive->lat3,
823 SL1metaPrimitive->wi4,
824 SL1metaPrimitive->tdc4,
825 SL1metaPrimitive->lat4,
851 outMPaths.push_back(newSL1metaPrimitive);
853 normalMetaPrimitives.push_back(newSL1metaPrimitive);
858 for (
auto SL3metaPrimitive = SL3metaPrimitives.begin(); SL3metaPrimitive != SL3metaPrimitives.end();
859 ++SL3metaPrimitive, sl3++) {
863 DTChamberId(SLId.wheel(), SLId.station(), SLId.sector());
865 SL3metaPrimitive->t0,
867 SL3metaPrimitive->tanPhi,
868 SL3metaPrimitive->phi,
869 SL3metaPrimitive->phiB,
870 SL3metaPrimitive->phi_cmssw,
871 SL3metaPrimitive->phiB_cmssw,
872 SL3metaPrimitive->chi2,
873 SL3metaPrimitive->quality,
886 SL3metaPrimitive->wi1,
887 SL3metaPrimitive->tdc1,
888 SL3metaPrimitive->lat1,
889 SL3metaPrimitive->wi2,
890 SL3metaPrimitive->tdc2,
891 SL3metaPrimitive->lat2,
892 SL3metaPrimitive->wi3,
893 SL3metaPrimitive->tdc3,
894 SL3metaPrimitive->lat3,
895 SL3metaPrimitive->wi4,
896 SL3metaPrimitive->tdc4,
897 SL3metaPrimitive->lat4,
901 outMPaths.push_back(newSL3metaPrimitive);
903 normalMetaPrimitives.push_back(newSL3metaPrimitive);
908 SL1metaPrimitives.clear();
909 SL1metaPrimitives.erase(SL1metaPrimitives.begin(), SL1metaPrimitives.end());
910 SL3metaPrimitives.clear();
911 SL3metaPrimitives.erase(SL3metaPrimitives.begin(), SL3metaPrimitives.end());
913 vector<metaPrimitive> auxMetaPrimitives;
916 LogDebug(
"MuonPathAssociator") <<
"Pushing back normal MPs to the auxiliar vector";
917 removeSharingHits(normalMetaPrimitives, confirmedMetaPrimitives, auxMetaPrimitives);
921 LogDebug(
"MuonPathAssociator") <<
"Pushing back normal MPs to the MPs collection";
929 std::vector<metaPrimitive> SL2metaPrimitives;
931 for (
int wh = -2; wh <= 2; wh++) {
932 for (
int st = 1; st <= 4; st++) {
933 for (
int se = 1; se <= 14; se++) {
934 if (se >= 13 && st != 4)
941 for (
auto metaprimitiveIt = inMPaths.begin(); metaprimitiveIt != inMPaths.end(); ++metaprimitiveIt)
942 if (metaprimitiveIt->rawId == sl2Id.rawId()) {
943 SL2metaPrimitives.push_back(*metaprimitiveIt);
946 outMPaths.push_back(*metaprimitiveIt);
952 LogDebug(
"MuonPathAssociator") <<
"\t etaTP: added " << SL2metaPrimitives.size() <<
"to outMPaths" << std::endl;
954 SL2metaPrimitives.clear();
955 SL2metaPrimitives.erase(SL2metaPrimitives.begin(), SL2metaPrimitives.end());