88 LogDebug(
"MuonPathAssociator") <<
"starting correlation";
90 for (
int wh = -2; wh <= 2; wh++) {
91 for (
int st = 1; st <= 4; st++) {
92 for (
int se = 1; se <= 14; se++) {
93 if (se >= 13 && st != 4)
101 std::vector<metaPrimitive> SL1metaPrimitives;
102 for (
const auto &metaprimitiveIt : inMPaths) {
103 if (metaprimitiveIt.rawId == sl1Id.rawId())
104 SL1metaPrimitives.push_back(metaprimitiveIt);
108 std::vector<metaPrimitive> SL3metaPrimitives;
109 for (
const auto &metaprimitiveIt : inMPaths) {
110 if (metaprimitiveIt.rawId == sl3Id.rawId())
111 SL3metaPrimitives.push_back(metaprimitiveIt);
114 if (SL1metaPrimitives.empty() and SL3metaPrimitives.empty())
118 LogDebug(
"MuonPathAssociator") <<
"correlating " << SL1metaPrimitives.size() <<
" metaPrim in SL1 and "
119 << SL3metaPrimitives.size() <<
" in SL3 for " << sl3Id;
121 bool at_least_one_correlation =
false;
122 bool at_least_one_SL1_confirmation =
false;
123 bool at_least_one_SL3_confirmation =
false;
125 bool useFitSL1[SL1metaPrimitives.size()];
126 for (
unsigned int i = 0;
i < SL1metaPrimitives.size();
i++)
127 useFitSL1[
i] =
false;
128 bool useFitSL3[SL3metaPrimitives.size()];
129 for (
unsigned int i = 0;
i < SL3metaPrimitives.size();
i++)
130 useFitSL3[
i] =
false;
133 vector<metaPrimitive> chamberMetaPrimitives;
134 vector<metaPrimitive> confirmedMetaPrimitives;
135 vector<metaPrimitive> normalMetaPrimitives;
138 for (
auto SL1metaPrimitive = SL1metaPrimitives.begin(); SL1metaPrimitive != SL1metaPrimitives.end();
139 ++SL1metaPrimitive, sl1++, sl3 = -1) {
141 at_least_one_correlation =
false;
142 for (
auto SL3metaPrimitive = SL3metaPrimitives.begin(); SL3metaPrimitive != SL3metaPrimitives.end();
143 ++SL3metaPrimitive, sl3++) {
156 double NewSlope = -999.;
158 long int pos = (PosSL3 + PosSL1) / 2;
161 if (((PosSL3 + PosSL1) % 2 != 0) && (
pos < 0)) {
165 long int difPos_mm_x4 = PosSL3 - PosSL1;
171 double MeanT0 = (SL1metaPrimitive->t0 + SL3metaPrimitive->t0) / 2;
181 if (shift_sl1 < shift_sl3) {
186 int wi[8], tdc[8], lat[8];
187 wi[0] = SL1metaPrimitive->wi1;
188 tdc[0] = SL1metaPrimitive->tdc1;
189 lat[0] = SL1metaPrimitive->lat1;
190 wi[1] = SL1metaPrimitive->wi2;
191 tdc[1] = SL1metaPrimitive->tdc2;
192 lat[1] = SL1metaPrimitive->lat2;
193 wi[2] = SL1metaPrimitive->wi3;
194 tdc[2] = SL1metaPrimitive->tdc3;
195 lat[2] = SL1metaPrimitive->lat3;
196 wi[3] = SL1metaPrimitive->wi4;
197 tdc[3] = SL1metaPrimitive->tdc4;
198 lat[3] = SL1metaPrimitive->lat4;
199 wi[4] = SL3metaPrimitive->wi1;
200 tdc[4] = SL3metaPrimitive->tdc1;
201 lat[4] = SL3metaPrimitive->lat1;
202 wi[5] = SL3metaPrimitive->wi2;
203 tdc[5] = SL3metaPrimitive->tdc2;
204 lat[5] = SL3metaPrimitive->lat2;
205 wi[6] = SL3metaPrimitive->wi3;
206 tdc[6] = SL3metaPrimitive->tdc3;
207 lat[6] = SL3metaPrimitive->lat3;
208 wi[7] = SL3metaPrimitive->wi4;
209 tdc[7] = SL3metaPrimitive->tdc4;
210 lat[7] = SL3metaPrimitive->lat4;
214 long int Z_FACTOR_CORR[8] = {-6, -2, 2, 6, -6, -2, 2, 6};
216 for (
int i = 0;
i < 8;
i++) {
217 int sign = 2 * (
i / 4) - 1;
220 long int sum_A, sum_B;
222 long int shift, slTime;
225 slTime = SL1metaPrimitive->t0;
228 slTime = SL3metaPrimitive->t0;
232 long int wireHorizPos_x4 =
237 pos_mm_x4 = wireHorizPos_x4 - (drift_dist_um_x4 >> 10);
239 pos_mm_x4 = wireHorizPos_x4 + (drift_dist_um_x4 >> 10);
244 chi2 += ((sum_A - sum_B) * (sum_A - sum_B)) >> 2;
254 useFitSL1[sl1] =
true;
255 useFitSL3[sl3] =
true;
258 if (SL3metaPrimitive->quality ==
LOWQ and SL1metaPrimitive->quality ==
LOWQ)
261 if ((SL3metaPrimitive->quality ==
HIGHQ && SL1metaPrimitive->quality ==
LOWQ)
or
262 (SL1metaPrimitive->quality ==
HIGHQ && SL3metaPrimitive->quality ==
LOWQ))
265 if (SL3metaPrimitive->quality ==
HIGHQ && SL1metaPrimitive->quality ==
HIGHQ)
272 if (
ChId.station() >= 3)
276 int thisec =
ChId.sector();
282 double psi = atan(NewSlope);
287 phi = global_coords[0];
288 phiB = global_coords[1];
292 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(),
333 SL1metaPrimitive->wi1,
334 SL1metaPrimitive->tdc1,
335 SL1metaPrimitive->lat1,
336 SL1metaPrimitive->wi2,
337 SL1metaPrimitive->tdc2,
338 SL1metaPrimitive->lat2,
339 SL1metaPrimitive->wi3,
340 SL1metaPrimitive->tdc3,
341 SL1metaPrimitive->lat3,
342 SL1metaPrimitive->wi4,
343 SL1metaPrimitive->tdc4,
344 SL1metaPrimitive->lat4,
345 SL3metaPrimitive->wi1,
346 SL3metaPrimitive->tdc1,
347 SL3metaPrimitive->lat1,
348 SL3metaPrimitive->wi2,
349 SL3metaPrimitive->tdc2,
350 SL3metaPrimitive->lat2,
351 SL3metaPrimitive->wi3,
352 SL3metaPrimitive->tdc3,
353 SL3metaPrimitive->lat3,
354 SL3metaPrimitive->wi4,
355 SL3metaPrimitive->tdc4,
356 SL3metaPrimitive->lat4);
358 at_least_one_correlation =
true;
361 if (at_least_one_correlation ==
false &&
363 int matched_digis = 0;
375 for (
const auto &dtLayerId_It : *dtdigis) {
376 const DTLayerId dtLId = dtLayerId_It.first;
379 if (dtSLId.rawId() != sl3Id.rawId())
382 if (dtLId.
layer() == 4)
384 else if (dtLId.
layer() == 3)
386 else if (dtLId.
layer() == 2)
388 else if (dtLId.
layer() == 1)
390 double x_inSL3 = SL1metaPrimitive->x - SL1metaPrimitive->tanPhi * (
VERT_PHI1_PHI3 + l_shift);
391 for (
auto digiIt = (dtLayerId_It.second).first; digiIt != (dtLayerId_It.second).
second; ++digiIt) {
392 DTWireId wireId(dtLId, (*digiIt).wire());
399 x_wire = x_wire_left;
402 if (
std::abs(x_inSL3 - x_wire) < minx) {
405 next_wire = best_wire;
407 next_layer = best_layer;
410 best_wire = (*digiIt).wire();
411 best_tdc = (*digiIt).time();
412 best_layer = dtLId.
layer();
415 }
else if ((
std::abs(x_inSL3 - x_wire) >= minx) && (
std::abs(x_inSL3 - x_wire) < min2x)) {
417 next_wire = (*digiIt).wire();
418 next_tdc = (*digiIt).time();
419 next_layer = dtLId.
layer();
425 if (matched_digis >= 2 and best_layer != -1 and next_layer != -1) {
427 if (SL1metaPrimitive->quality ==
LOWQ)
443 if (next_layer == 1) {
448 if (next_layer == 2) {
453 if (next_layer == 3) {
458 if (next_layer == 4) {
464 if (best_layer == 1) {
469 if (best_layer == 2) {
474 if (best_layer == 3) {
479 if (best_layer == 4) {
487 SL1metaPrimitive->t0,
489 SL1metaPrimitive->tanPhi,
490 SL1metaPrimitive->phi,
491 SL1metaPrimitive->phiB,
492 SL1metaPrimitive->chi2,
494 SL1metaPrimitive->wi1,
495 SL1metaPrimitive->tdc1,
496 SL1metaPrimitive->lat1,
497 SL1metaPrimitive->wi2,
498 SL1metaPrimitive->tdc2,
499 SL1metaPrimitive->lat2,
500 SL1metaPrimitive->wi3,
501 SL1metaPrimitive->tdc3,
502 SL1metaPrimitive->lat3,
503 SL1metaPrimitive->wi4,
504 SL1metaPrimitive->tdc4,
505 SL1metaPrimitive->lat4,
521 SL1metaPrimitive->t0,
523 SL1metaPrimitive->tanPhi,
524 SL1metaPrimitive->phi,
525 SL1metaPrimitive->phiB,
526 SL1metaPrimitive->chi2,
528 SL1metaPrimitive->wi1,
529 SL1metaPrimitive->tdc1,
530 SL1metaPrimitive->lat1,
531 SL1metaPrimitive->wi2,
532 SL1metaPrimitive->tdc2,
533 SL1metaPrimitive->lat2,
534 SL1metaPrimitive->wi3,
535 SL1metaPrimitive->tdc3,
536 SL1metaPrimitive->lat3,
537 SL1metaPrimitive->wi4,
538 SL1metaPrimitive->tdc4,
539 SL1metaPrimitive->lat4,
553 useFitSL1[sl1] =
true;
554 at_least_one_SL1_confirmation =
true;
563 for (
auto SL3metaPrimitive = SL3metaPrimitives.begin(); SL3metaPrimitive != SL3metaPrimitives.end();
564 ++SL3metaPrimitive, sl3++) {
570 int matched_digis = 0;
583 for (
const auto &dtLayerId_It : *dtdigis) {
584 const DTLayerId dtLId = dtLayerId_It.first;
587 if (dtSLId.rawId() != sl1Id.rawId())
590 if (dtLId.
layer() == 4)
592 if (dtLId.
layer() == 3)
594 if (dtLId.
layer() == 2)
596 if (dtLId.
layer() == 1)
598 double x_inSL1 = SL3metaPrimitive->x + SL3metaPrimitive->tanPhi * (
VERT_PHI1_PHI3 - l_shift);
599 for (
auto digiIt = (dtLayerId_It.second).first; digiIt != (dtLayerId_It.second).
second; ++digiIt) {
600 DTWireId wireId(dtLId, (*digiIt).wire());
607 x_wire = x_wire_left;
610 if (
std::abs(x_inSL1 - x_wire) < minx) {
612 next_wire = best_wire;
614 next_layer = best_layer;
617 best_wire = (*digiIt).wire();
618 best_tdc = (*digiIt).time();
619 best_layer = dtLId.
layer();
622 }
else if ((
std::abs(x_inSL1 - x_wire) >= minx) && (
std::abs(x_inSL1 - x_wire) < min2x)) {
624 next_wire = (*digiIt).wire();
625 next_tdc = (*digiIt).time();
626 next_layer = dtLId.
layer();
632 if (matched_digis >= 2 and best_layer != -1 and next_layer != -1) {
634 if (SL3metaPrimitive->quality ==
LOWQ)
650 if (next_layer == 1) {
655 if (next_layer == 2) {
660 if (next_layer == 3) {
665 if (next_layer == 4) {
671 if (best_layer == 1) {
676 if (best_layer == 2) {
681 if (best_layer == 3) {
686 if (best_layer == 4) {
694 SL3metaPrimitive->t0,
696 SL3metaPrimitive->tanPhi,
697 SL3metaPrimitive->phi,
698 SL3metaPrimitive->phiB,
699 SL3metaPrimitive->chi2,
713 SL3metaPrimitive->wi1,
714 SL3metaPrimitive->tdc1,
715 SL3metaPrimitive->lat1,
716 SL3metaPrimitive->wi2,
717 SL3metaPrimitive->tdc2,
718 SL3metaPrimitive->lat2,
719 SL3metaPrimitive->wi3,
720 SL3metaPrimitive->tdc3,
721 SL3metaPrimitive->lat3,
722 SL3metaPrimitive->wi4,
723 SL3metaPrimitive->tdc4,
724 SL3metaPrimitive->lat4,
728 SL3metaPrimitive->t0,
730 SL3metaPrimitive->tanPhi,
731 SL3metaPrimitive->phi,
732 SL3metaPrimitive->phiB,
733 SL3metaPrimitive->chi2,
747 SL3metaPrimitive->wi1,
748 SL3metaPrimitive->tdc1,
749 SL3metaPrimitive->lat1,
750 SL3metaPrimitive->wi2,
751 SL3metaPrimitive->tdc2,
752 SL3metaPrimitive->lat2,
753 SL3metaPrimitive->wi3,
754 SL3metaPrimitive->tdc3,
755 SL3metaPrimitive->lat3,
756 SL3metaPrimitive->wi4,
757 SL3metaPrimitive->tdc4,
758 SL3metaPrimitive->lat4,
760 useFitSL3[sl3] =
true;
761 at_least_one_SL3_confirmation =
true;
768 LogDebug(
"MuonPathAssociator") <<
"Pushing back correlated MPs to the MPs collection";
773 LogDebug(
"MuonPathAssociator") <<
"Pushing back confirmed MPs to the complete vector";
779 if (
debug_ && !at_least_one_correlation)
781 <<
"correlation we found zero correlations, adding both collections as they are to the outMPaths";
784 <<
"correlation sizes:" << SL1metaPrimitives.size() <<
" " << SL3metaPrimitives.size();
787 for (
auto SL1metaPrimitive = SL1metaPrimitives.begin(); SL1metaPrimitive != SL1metaPrimitives.end();
788 ++SL1metaPrimitive, sl1++) {
793 DTChamberId(SLId.wheel(), SLId.station(), SLId.sector());
795 SL1metaPrimitive->t0,
797 SL1metaPrimitive->tanPhi,
798 SL1metaPrimitive->phi,
799 SL1metaPrimitive->phiB,
800 SL1metaPrimitive->chi2,
801 SL1metaPrimitive->quality,
802 SL1metaPrimitive->wi1,
803 SL1metaPrimitive->tdc1,
804 SL1metaPrimitive->lat1,
805 SL1metaPrimitive->wi2,
806 SL1metaPrimitive->tdc2,
807 SL1metaPrimitive->lat2,
808 SL1metaPrimitive->wi3,
809 SL1metaPrimitive->tdc3,
810 SL1metaPrimitive->lat3,
811 SL1metaPrimitive->wi4,
812 SL1metaPrimitive->tdc4,
813 SL1metaPrimitive->lat4,
839 outMPaths.push_back(newSL1metaPrimitive);
841 normalMetaPrimitives.push_back(newSL1metaPrimitive);
846 for (
auto SL3metaPrimitive = SL3metaPrimitives.begin(); SL3metaPrimitive != SL3metaPrimitives.end();
847 ++SL3metaPrimitive, sl3++) {
851 DTChamberId(SLId.wheel(), SLId.station(), SLId.sector());
853 SL3metaPrimitive->t0,
855 SL3metaPrimitive->tanPhi,
856 SL3metaPrimitive->phi,
857 SL3metaPrimitive->phiB,
858 SL3metaPrimitive->chi2,
859 SL3metaPrimitive->quality,
872 SL3metaPrimitive->wi1,
873 SL3metaPrimitive->tdc1,
874 SL3metaPrimitive->lat1,
875 SL3metaPrimitive->wi2,
876 SL3metaPrimitive->tdc2,
877 SL3metaPrimitive->lat2,
878 SL3metaPrimitive->wi3,
879 SL3metaPrimitive->tdc3,
880 SL3metaPrimitive->lat3,
881 SL3metaPrimitive->wi4,
882 SL3metaPrimitive->tdc4,
883 SL3metaPrimitive->lat4,
887 outMPaths.push_back(newSL3metaPrimitive);
889 normalMetaPrimitives.push_back(newSL3metaPrimitive);
894 SL1metaPrimitives.clear();
895 SL1metaPrimitives.erase(SL1metaPrimitives.begin(), SL1metaPrimitives.end());
896 SL3metaPrimitives.clear();
897 SL3metaPrimitives.erase(SL3metaPrimitives.begin(), SL3metaPrimitives.end());
899 vector<metaPrimitive> auxMetaPrimitives;
902 LogDebug(
"MuonPathAssociator") <<
"Pushing back normal MPs to the auxiliar vector";
903 removeSharingHits(normalMetaPrimitives, confirmedMetaPrimitives, auxMetaPrimitives);
907 LogDebug(
"MuonPathAssociator") <<
"Pushing back normal MPs to the MPs collection";
915 std::vector<metaPrimitive> SL2metaPrimitives;
917 for (
int wh = -2; wh <= 2; wh++) {
918 for (
int st = 1; st <= 4; st++) {
919 for (
int se = 1; se <= 14; se++) {
920 if (se >= 13 && st != 4)
927 for (
auto metaprimitiveIt = inMPaths.begin(); metaprimitiveIt != inMPaths.end(); ++metaprimitiveIt)
928 if (metaprimitiveIt->rawId == sl2Id.rawId()) {
929 SL2metaPrimitives.push_back(*metaprimitiveIt);
932 outMPaths.push_back(*metaprimitiveIt);
938 LogDebug(
"MuonPathAssociator") <<
"\t etaTP: added " << SL2metaPrimitives.size() <<
"to outMPaths" << std::endl;
940 SL2metaPrimitives.clear();
941 SL2metaPrimitives.erase(SL2metaPrimitives.begin(), SL2metaPrimitives.end());