90 LogDebug(
"MuonPathAssociator") <<
"starting correlation";
92 for (
int wh = -2; wh <= 2; wh++) {
93 for (
int st = 1; st <= 4; st++) {
94 for (
int se = 1; se <= 14; se++) {
95 if (se >= 13 && st != 4)
103 std::vector<metaPrimitive> SL1metaPrimitives;
104 for (
const auto &metaprimitiveIt : inMPaths) {
105 if (metaprimitiveIt.rawId == sl1Id.rawId())
106 SL1metaPrimitives.push_back(metaprimitiveIt);
110 std::vector<metaPrimitive> SL3metaPrimitives;
111 for (
const auto &metaprimitiveIt : inMPaths) {
112 if (metaprimitiveIt.rawId == sl3Id.rawId())
113 SL3metaPrimitives.push_back(metaprimitiveIt);
116 if (SL1metaPrimitives.empty() and SL3metaPrimitives.empty())
120 LogDebug(
"MuonPathAssociator") <<
"correlating " << SL1metaPrimitives.size() <<
" metaPrim in SL1 and "
121 << SL3metaPrimitives.size() <<
" in SL3 for " << sl3Id;
123 bool at_least_one_correlation =
false;
124 bool at_least_one_SL1_confirmation =
false;
125 bool at_least_one_SL3_confirmation =
false;
127 bool useFitSL1[SL1metaPrimitives.size()];
128 for (
unsigned int i = 0;
i < SL1metaPrimitives.size();
i++)
129 useFitSL1[
i] =
false;
130 bool useFitSL3[SL3metaPrimitives.size()];
131 for (
unsigned int i = 0;
i < SL3metaPrimitives.size();
i++)
132 useFitSL3[
i] =
false;
135 vector<metaPrimitive> chamberMetaPrimitives;
136 vector<metaPrimitive> confirmedMetaPrimitives;
137 vector<metaPrimitive> normalMetaPrimitives;
140 for (
auto SL1metaPrimitive = SL1metaPrimitives.begin(); SL1metaPrimitive != SL1metaPrimitives.end();
141 ++SL1metaPrimitive, sl1++, sl3 = -1) {
143 at_least_one_correlation =
false;
144 for (
auto SL3metaPrimitive = SL3metaPrimitives.begin(); SL3metaPrimitive != SL3metaPrimitives.end();
145 ++SL3metaPrimitive, sl3++) {
156 long int PosSL1 = (
int)round(10 * SL1metaPrimitive->x / (10 *
x_precision_));
157 long int PosSL3 = (
int)round(10 * SL3metaPrimitive->x / (10 *
x_precision_));
158 double NewSlope = -999.;
160 long int newConstant = (
int)(139.5 * 4);
161 long int difPos_mm_x4 = PosSL3 - PosSL1;
162 long int tanPsi_x4096_x128 = (difPos_mm_x4)*newConstant;
163 long int tanPsi_x4096 = tanPsi_x4096_x128 / ((
long int)
pow(2, 5 + numberOfBits));
164 if (tanPsi_x4096 < 0 && tanPsi_x4096_x128 % ((
long int)
pow(2, 5 + numberOfBits)) != 0)
168 double MeanT0 = (SL1metaPrimitive->t0 + SL3metaPrimitive->t0) / 2;
169 double MeanPos = (PosSL3 + PosSL1) / (2. / (
x_precision_));
179 int wi[8], tdc[8], lat[8];
180 wi[0] = SL1metaPrimitive->wi1;
181 tdc[0] = SL1metaPrimitive->tdc1;
182 lat[0] = SL1metaPrimitive->lat1;
183 wi[1] = SL1metaPrimitive->wi2;
184 tdc[1] = SL1metaPrimitive->tdc2;
185 lat[1] = SL1metaPrimitive->lat2;
186 wi[2] = SL1metaPrimitive->wi3;
187 tdc[2] = SL1metaPrimitive->tdc3;
188 lat[2] = SL1metaPrimitive->lat3;
189 wi[3] = SL1metaPrimitive->wi4;
190 tdc[3] = SL1metaPrimitive->tdc4;
191 lat[3] = SL1metaPrimitive->lat4;
192 wi[4] = SL3metaPrimitive->wi1;
193 tdc[4] = SL3metaPrimitive->tdc1;
194 lat[4] = SL3metaPrimitive->lat1;
195 wi[5] = SL3metaPrimitive->wi2;
196 tdc[5] = SL3metaPrimitive->tdc2;
197 lat[5] = SL3metaPrimitive->lat2;
198 wi[6] = SL3metaPrimitive->wi3;
199 tdc[6] = SL3metaPrimitive->tdc3;
200 lat[6] = SL3metaPrimitive->lat3;
201 wi[7] = SL3metaPrimitive->wi4;
202 tdc[7] = SL3metaPrimitive->tdc4;
203 lat[7] = SL3metaPrimitive->lat4;
207 long int CH_CENTER_TO_MID_SL_P = (
long int)(117.5 * 4);
208 long int Z_FACTOR_CORR[8] = {-6, -2, 2, 6, -6, -2, 2, 6};
210 for (
int i = 0;
i < 8;
i++) {
211 int sign = 2 * (
i / 4) - 1;
212 Z_FACTOR_CORR[
i] = Z_FACTOR_CORR[
i] *
CELL_HEIGHT + CH_CENTER_TO_MID_SL_P *
sign;
214 long int sum_A, sum_B;
215 for (
int i = 0;
i < 8;
i++) {
216 long int shift, slTime;
219 slTime = SL1metaPrimitive->t0;
222 slTime = SL3metaPrimitive->t0;
225 long int drift_speed_new = 889;
226 long int drift_dist_um_x4 = drift_speed_new * (((
long int)tdc[
i]) - slTime);
227 long int wireHorizPos_x4 = (42 * wi[
i] + ((
i + 1) % 2) * 21) / (10 *
x_precision_);
231 pos_mm_x4 = wireHorizPos_x4 - (drift_dist_um_x4 >> 10);
233 pos_mm_x4 = wireHorizPos_x4 + (drift_dist_um_x4 >> 10);
236 sum_A = sum_A << (14 - numberOfBits);
238 chi2 += ((sum_A - sum_B) * (sum_A - sum_B)) >> 2;
242 double newChi2 = (double)(
chi2 >> 16) / (1024. * 100.);
248 useFitSL1[sl1] =
true;
249 useFitSL3[sl3] =
true;
252 if (SL3metaPrimitive->quality <= 2 and SL1metaPrimitive->quality <= 2)
255 if ((SL3metaPrimitive->quality >= 3 && SL1metaPrimitive->quality <= 2)
or
256 (SL1metaPrimitive->quality >= 3 && SL3metaPrimitive->quality <= 2))
259 if (SL3metaPrimitive->quality >= 3 && SL1metaPrimitive->quality >= 3)
263 if (
ChId.station() >= 3)
267 int thisec =
ChId.sector();
272 double phi = jm_x_cmssw_global.
phi() - 0.5235988 * (thisec - 1);
273 double psi = atan(NewSlope);
277 outMPaths.emplace_back(
ChId.rawId(),
285 SL1metaPrimitive->wi1,
286 SL1metaPrimitive->tdc1,
287 SL1metaPrimitive->lat1,
288 SL1metaPrimitive->wi2,
289 SL1metaPrimitive->tdc2,
290 SL1metaPrimitive->lat2,
291 SL1metaPrimitive->wi3,
292 SL1metaPrimitive->tdc3,
293 SL1metaPrimitive->lat3,
294 SL1metaPrimitive->wi4,
295 SL1metaPrimitive->tdc4,
296 SL1metaPrimitive->lat4,
297 SL3metaPrimitive->wi1,
298 SL3metaPrimitive->tdc1,
299 SL3metaPrimitive->lat1,
300 SL3metaPrimitive->wi2,
301 SL3metaPrimitive->tdc2,
302 SL3metaPrimitive->lat2,
303 SL3metaPrimitive->wi3,
304 SL3metaPrimitive->tdc3,
305 SL3metaPrimitive->lat3,
306 SL3metaPrimitive->wi4,
307 SL3metaPrimitive->tdc4,
308 SL3metaPrimitive->lat4);
310 chamberMetaPrimitives.emplace_back(
ChId.rawId(),
318 SL1metaPrimitive->wi1,
319 SL1metaPrimitive->tdc1,
320 SL1metaPrimitive->lat1,
321 SL1metaPrimitive->wi2,
322 SL1metaPrimitive->tdc2,
323 SL1metaPrimitive->lat2,
324 SL1metaPrimitive->wi3,
325 SL1metaPrimitive->tdc3,
326 SL1metaPrimitive->lat3,
327 SL1metaPrimitive->wi4,
328 SL1metaPrimitive->tdc4,
329 SL1metaPrimitive->lat4,
330 SL3metaPrimitive->wi1,
331 SL3metaPrimitive->tdc1,
332 SL3metaPrimitive->lat1,
333 SL3metaPrimitive->wi2,
334 SL3metaPrimitive->tdc2,
335 SL3metaPrimitive->lat2,
336 SL3metaPrimitive->wi3,
337 SL3metaPrimitive->tdc3,
338 SL3metaPrimitive->lat3,
339 SL3metaPrimitive->wi4,
340 SL3metaPrimitive->tdc4,
341 SL3metaPrimitive->lat4);
343 at_least_one_correlation =
true;
346 if (at_least_one_correlation ==
false &&
348 int matched_digis = 0;
361 for (
const auto &dtLayerId_It : *dtdigis) {
362 const DTLayerId dtLId = dtLayerId_It.first;
364 if (dtSLId.rawId() != sl3Id.rawId())
367 if (dtLId.
layer() == 4)
369 else if (dtLId.
layer() == 3)
371 else if (dtLId.
layer() == 2)
373 else if (dtLId.
layer() == 1)
375 double x_inSL3 = SL1metaPrimitive->x - SL1metaPrimitive->tanPhi * (23.5 + l_shift);
376 for (
auto digiIt = (dtLayerId_It.second).first; digiIt != (dtLayerId_It.second).
second; ++digiIt) {
377 DTWireId wireId(dtLId, (*digiIt).wire());
378 int x_wire =
shiftinfo_[wireId.rawId()] + ((*digiIt).time() - SL1metaPrimitive->t0) * 0.00543;
379 int x_wire_left =
shiftinfo_[wireId.rawId()] - ((*digiIt).time() - SL1metaPrimitive->t0) * 0.00543;
382 x_wire = x_wire_left;
385 if (
std::abs(x_inSL3 - x_wire) < minx) {
387 next_wire = best_wire;
389 next_layer = best_layer;
392 best_wire = (*digiIt).wire();
393 best_tdc = (*digiIt).time();
394 best_layer = dtLId.
layer();
397 }
else if ((
std::abs(x_inSL3 - x_wire) >= minx) && (
std::abs(x_inSL3 - x_wire) < min2x)) {
399 next_wire = (*digiIt).wire();
400 next_tdc = (*digiIt).time();
401 next_layer = dtLId.
layer();
407 if (matched_digis >= 2 and best_layer != -1 and next_layer != -1) {
409 if (SL1metaPrimitive->quality <= 2)
425 if (next_layer == 1) {
430 if (next_layer == 2) {
435 if (next_layer == 3) {
440 if (next_layer == 4) {
446 if (best_layer == 1) {
451 if (best_layer == 2) {
456 if (best_layer == 3) {
461 if (best_layer == 4) {
469 SL1metaPrimitive->t0,
471 SL1metaPrimitive->tanPhi,
472 SL1metaPrimitive->phi,
473 SL1metaPrimitive->phiB,
474 SL1metaPrimitive->chi2,
476 SL1metaPrimitive->wi1,
477 SL1metaPrimitive->tdc1,
478 SL1metaPrimitive->lat1,
479 SL1metaPrimitive->wi2,
480 SL1metaPrimitive->tdc2,
481 SL1metaPrimitive->lat2,
482 SL1metaPrimitive->wi3,
483 SL1metaPrimitive->tdc3,
484 SL1metaPrimitive->lat3,
485 SL1metaPrimitive->wi4,
486 SL1metaPrimitive->tdc4,
487 SL1metaPrimitive->lat4,
503 SL1metaPrimitive->t0,
505 SL1metaPrimitive->tanPhi,
506 SL1metaPrimitive->phi,
507 SL1metaPrimitive->phiB,
508 SL1metaPrimitive->chi2,
510 SL1metaPrimitive->wi1,
511 SL1metaPrimitive->tdc1,
512 SL1metaPrimitive->lat1,
513 SL1metaPrimitive->wi2,
514 SL1metaPrimitive->tdc2,
515 SL1metaPrimitive->lat2,
516 SL1metaPrimitive->wi3,
517 SL1metaPrimitive->tdc3,
518 SL1metaPrimitive->lat3,
519 SL1metaPrimitive->wi4,
520 SL1metaPrimitive->tdc4,
521 SL1metaPrimitive->lat4,
535 useFitSL1[sl1] =
true;
536 at_least_one_SL1_confirmation =
true;
545 for (
auto SL3metaPrimitive = SL3metaPrimitives.begin(); SL3metaPrimitive != SL3metaPrimitives.end();
546 ++SL3metaPrimitive, sl3++) {
552 int matched_digis = 0;
565 for (
const auto &dtLayerId_It : *dtdigis) {
566 const DTLayerId dtLId = dtLayerId_It.first;
568 if (dtSLId.rawId() != sl1Id.rawId())
571 if (dtLId.
layer() == 4)
573 if (dtLId.
layer() == 3)
575 if (dtLId.
layer() == 2)
577 if (dtLId.
layer() == 1)
579 double x_inSL1 = SL3metaPrimitive->x + SL3metaPrimitive->tanPhi * (23.5 - l_shift);
580 for (
auto digiIt = (dtLayerId_It.second).first; digiIt != (dtLayerId_It.second).
second; ++digiIt) {
581 DTWireId wireId(dtLId, (*digiIt).wire());
582 int x_wire =
shiftinfo_[wireId.rawId()] + ((*digiIt).time() - SL3metaPrimitive->t0) * 0.00543;
583 int x_wire_left =
shiftinfo_[wireId.rawId()] - ((*digiIt).time() - SL3metaPrimitive->t0) * 0.00543;
586 x_wire = x_wire_left;
589 if (
std::abs(x_inSL1 - x_wire) < minx) {
591 next_wire = best_wire;
593 next_layer = best_layer;
596 best_wire = (*digiIt).wire();
597 best_tdc = (*digiIt).time();
598 best_layer = dtLId.
layer();
601 }
else if ((
std::abs(x_inSL1 - x_wire) >= minx) && (
std::abs(x_inSL1 - x_wire) < min2x)) {
603 next_wire = (*digiIt).wire();
604 next_tdc = (*digiIt).time();
605 next_layer = dtLId.
layer();
611 if (matched_digis >= 2 and best_layer != -1 and next_layer != -1) {
613 if (SL3metaPrimitive->quality <= 2)
629 if (next_layer == 1) {
634 if (next_layer == 2) {
639 if (next_layer == 3) {
644 if (next_layer == 4) {
650 if (best_layer == 1) {
655 if (best_layer == 2) {
660 if (best_layer == 3) {
665 if (best_layer == 4) {
673 SL3metaPrimitive->t0,
675 SL3metaPrimitive->tanPhi,
676 SL3metaPrimitive->phi,
677 SL3metaPrimitive->phiB,
678 SL3metaPrimitive->chi2,
692 SL3metaPrimitive->wi1,
693 SL3metaPrimitive->tdc1,
694 SL3metaPrimitive->lat1,
695 SL3metaPrimitive->wi2,
696 SL3metaPrimitive->tdc2,
697 SL3metaPrimitive->lat2,
698 SL3metaPrimitive->wi3,
699 SL3metaPrimitive->tdc3,
700 SL3metaPrimitive->lat3,
701 SL3metaPrimitive->wi4,
702 SL3metaPrimitive->tdc4,
703 SL3metaPrimitive->lat4,
707 SL3metaPrimitive->t0,
709 SL3metaPrimitive->tanPhi,
710 SL3metaPrimitive->phi,
711 SL3metaPrimitive->phiB,
712 SL3metaPrimitive->chi2,
726 SL3metaPrimitive->wi1,
727 SL3metaPrimitive->tdc1,
728 SL3metaPrimitive->lat1,
729 SL3metaPrimitive->wi2,
730 SL3metaPrimitive->tdc2,
731 SL3metaPrimitive->lat2,
732 SL3metaPrimitive->wi3,
733 SL3metaPrimitive->tdc3,
734 SL3metaPrimitive->lat3,
735 SL3metaPrimitive->wi4,
736 SL3metaPrimitive->tdc4,
737 SL3metaPrimitive->lat4,
739 useFitSL3[sl3] =
true;
740 at_least_one_SL3_confirmation =
true;
747 LogDebug(
"MuonPathAssociator") <<
"Pushing back correlated MPs to the MPs collection";
752 LogDebug(
"MuonPathAssociator") <<
"Pushing back confirmed MPs to the complete vector";
758 if (
debug_ && !at_least_one_correlation)
760 <<
"correlation we found zero correlations, adding both collections as they are to the outMPaths";
763 <<
"correlation sizes:" << SL1metaPrimitives.size() <<
" " << SL3metaPrimitives.size();
766 for (
auto SL1metaPrimitive = SL1metaPrimitives.begin(); SL1metaPrimitive != SL1metaPrimitives.end();
767 ++SL1metaPrimitive, sl1++) {
772 DTChamberId(SLId.wheel(), SLId.station(), SLId.sector());
774 SL1metaPrimitive->t0,
776 SL1metaPrimitive->tanPhi,
777 SL1metaPrimitive->phi,
778 SL1metaPrimitive->phiB,
779 SL1metaPrimitive->chi2,
780 SL1metaPrimitive->quality,
781 SL1metaPrimitive->wi1,
782 SL1metaPrimitive->tdc1,
783 SL1metaPrimitive->lat1,
784 SL1metaPrimitive->wi2,
785 SL1metaPrimitive->tdc2,
786 SL1metaPrimitive->lat2,
787 SL1metaPrimitive->wi3,
788 SL1metaPrimitive->tdc3,
789 SL1metaPrimitive->lat3,
790 SL1metaPrimitive->wi4,
791 SL1metaPrimitive->tdc4,
792 SL1metaPrimitive->lat4,
818 outMPaths.push_back(newSL1metaPrimitive);
820 normalMetaPrimitives.push_back(newSL1metaPrimitive);
825 for (
auto SL3metaPrimitive = SL3metaPrimitives.begin(); SL3metaPrimitive != SL3metaPrimitives.end();
826 ++SL3metaPrimitive, sl3++) {
830 DTChamberId(SLId.wheel(), SLId.station(), SLId.sector());
832 SL3metaPrimitive->t0,
834 SL3metaPrimitive->tanPhi,
835 SL3metaPrimitive->phi,
836 SL3metaPrimitive->phiB,
837 SL3metaPrimitive->chi2,
838 SL3metaPrimitive->quality,
851 SL3metaPrimitive->wi1,
852 SL3metaPrimitive->tdc1,
853 SL3metaPrimitive->lat1,
854 SL3metaPrimitive->wi2,
855 SL3metaPrimitive->tdc2,
856 SL3metaPrimitive->lat2,
857 SL3metaPrimitive->wi3,
858 SL3metaPrimitive->tdc3,
859 SL3metaPrimitive->lat3,
860 SL3metaPrimitive->wi4,
861 SL3metaPrimitive->tdc4,
862 SL3metaPrimitive->lat4,
866 outMPaths.push_back(newSL3metaPrimitive);
868 normalMetaPrimitives.push_back(newSL3metaPrimitive);
873 SL1metaPrimitives.clear();
874 SL1metaPrimitives.erase(SL1metaPrimitives.begin(), SL1metaPrimitives.end());
875 SL3metaPrimitives.clear();
876 SL3metaPrimitives.erase(SL3metaPrimitives.begin(), SL3metaPrimitives.end());
878 vector<metaPrimitive> auxMetaPrimitives;
881 LogDebug(
"MuonPathAssociator") <<
"Pushing back normal MPs to the auxiliar vector";
882 removeSharingHits(normalMetaPrimitives, confirmedMetaPrimitives, auxMetaPrimitives);
886 LogDebug(
"MuonPathAssociator") <<
"Pushing back normal MPs to the MPs collection";