File indexing completed on 2024-04-06 12:19:41
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #include "L1Trigger/DTTrackFinder/src/L1MuDTAssignmentUnit.h"
0020
0021
0022
0023
0024
0025 #include <iostream>
0026 #include <cmath>
0027 #include <cassert>
0028
0029
0030
0031
0032
0033 #include "L1Trigger/DTTrackFinder/interface/L1MuDTTFConfig.h"
0034 #include "L1Trigger/DTTrackFinder/src/L1MuDTSectorProcessor.h"
0035 #include "L1Trigger/DTTrackFinder/src/L1MuDTDataBuffer.h"
0036 #include "L1Trigger/DTTrackFinder/interface/L1MuDTTrackSegPhi.h"
0037 #include "L1Trigger/DTTrackFinder/interface/L1MuDTTrackSegLoc.h"
0038 #include "L1Trigger/DTTrackFinder/src/L1MuDTTrackAssembler.h"
0039 #include "L1Trigger/DTTrackFinder/interface/L1MuDTTrackAssParam.h"
0040 #include "CondFormats/L1TObjects/interface/L1MuDTPhiLut.h"
0041 #include "CondFormats/DataRecord/interface/L1MuDTPhiLutRcd.h"
0042 #include "CondFormats/L1TObjects/interface/L1MuDTPtaLut.h"
0043 #include "CondFormats/DataRecord/interface/L1MuDTPtaLutRcd.h"
0044 #include "L1Trigger/DTTrackFinder/interface/L1MuDTTrack.h"
0045 #include "L1Trigger/DTTrackFinder/interface/L1MuDTTrackFinder.h"
0046 #include "L1Trigger/L1TCommon/interface/BitShift.h"
0047
0048 using namespace std;
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058 L1MuDTAssignmentUnit::L1MuDTAssignmentUnit(L1MuDTSectorProcessor& sp, int id, edm::ConsumesCollector iC)
0059 : m_sp(sp),
0060 m_id(id),
0061 m_addArray(),
0062 m_TSphi(),
0063 m_ptAssMethod(NODEF),
0064 thePhiToken(iC.esConsumes()),
0065 thePtaToken(iC.esConsumes()),
0066 nbit_phi(12),
0067 nbit_phib(10) {
0068 m_TSphi.reserve(4);
0069 reset();
0070
0071 setPrecision();
0072 }
0073
0074
0075
0076
0077
0078 L1MuDTAssignmentUnit::~L1MuDTAssignmentUnit() {}
0079
0080
0081
0082
0083
0084
0085
0086
0087 void L1MuDTAssignmentUnit::run(const edm::EventSetup& c) {
0088
0089 m_sp.track(m_id)->enable();
0090 m_sp.tracK(m_id)->enable();
0091
0092
0093 TrackClass tc = m_sp.TA()->trackClass(m_id);
0094 m_sp.track(m_id)->setTC(tc);
0095 m_sp.tracK(m_id)->setTC(tc);
0096
0097
0098 m_addArray = m_sp.TA()->address(m_id);
0099 m_sp.track(m_id)->setAddresses(m_addArray);
0100 m_sp.tracK(m_id)->setAddresses(m_addArray);
0101
0102
0103 TSR();
0104 m_sp.track(m_id)->setTSphi(m_TSphi);
0105 m_sp.tracK(m_id)->setTSphi(m_TSphi);
0106
0107
0108 vector<const L1MuDTTrackSegPhi*>::const_iterator iter = m_TSphi.begin();
0109 int bx = (*iter)->bx();
0110 m_sp.track(m_id)->setBx(bx);
0111 m_sp.tracK(m_id)->setBx(bx);
0112
0113
0114 PhiAU(c);
0115
0116
0117 PtAU(c);
0118
0119
0120 QuaAU();
0121
0122
0123
0124
0125
0126
0127
0128 }
0129
0130
0131
0132
0133 void L1MuDTAssignmentUnit::reset() {
0134 m_addArray.reset();
0135 m_TSphi.clear();
0136 m_ptAssMethod = NODEF;
0137 }
0138
0139
0140
0141
0142 void L1MuDTAssignmentUnit::PhiAU(const edm::EventSetup& c) {
0143
0144
0145 thePhiLUTs = c.getHandle(thePhiToken);
0146
0147 int sh_phi = 12 - m_sp.tf().config()->getNbitsPhiPhi();
0148 int sh_phib = 10 - m_sp.tf().config()->getNbitsPhiPhib();
0149
0150 const L1MuDTTrackSegPhi* second = getTSphi(2);
0151 const L1MuDTTrackSegPhi* first = getTSphi(1);
0152 const L1MuDTTrackSegPhi* forth = getTSphi(4);
0153
0154 int phi2 = 0;
0155 int sector = 0;
0156
0157 if (second) {
0158 phi2 = second->phi() >> sh_phi;
0159 sector = second->sector();
0160 } else if (second == nullptr && first) {
0161 phi2 = first->phi() >> sh_phi;
0162 sector = first->sector();
0163 } else if (second == nullptr && forth) {
0164 phi2 = forth->phi() >> sh_phi;
0165 sector = forth->sector();
0166 }
0167
0168 int sector0 = m_sp.id().sector();
0169
0170
0171
0172 int sectordiff = (sector - sector0) % 12;
0173 if (sectordiff >= 6)
0174 sectordiff -= 12;
0175 if (sectordiff < -6)
0176 sectordiff += 12;
0177
0178
0179
0180
0181 int sector_8 = convertSector(sector0);
0182
0183
0184 int phi_precision = 4096 >> sh_phi;
0185 const double k = 57.2958 / 2.5 / static_cast<float>(phi_precision);
0186 double phi_f = static_cast<double>(phi2);
0187 int phi_8 = static_cast<int>(floor(phi_f * k));
0188
0189 if (second == nullptr && first) {
0190 int bend_angle = l1t::bitShift((first->phib() >> sh_phib), sh_phib);
0191 phi_8 = phi_8 + thePhiLUTs->getDeltaPhi(0, bend_angle);
0192 } else if (second == nullptr && forth) {
0193 int bend_angle = l1t::bitShift((forth->phib() >> sh_phib), sh_phib);
0194 phi_8 = phi_8 + thePhiLUTs->getDeltaPhi(1, bend_angle);
0195 }
0196
0197 phi_8 += sectordiff * 12;
0198
0199 if (phi_8 > 15)
0200 phi_8 = 15;
0201 if (phi_8 < -16)
0202 phi_8 = -16;
0203
0204 int phi = (sector_8 + phi_8 + 144) % 144;
0205 phi_8 = (phi_8 + 32) % 32;
0206
0207 m_sp.track(m_id)->setPhi(phi);
0208 m_sp.tracK(m_id)->setPhi(phi_8);
0209 }
0210
0211
0212
0213
0214 void L1MuDTAssignmentUnit::PtAU(const edm::EventSetup& c) {
0215 thePtaLUTs = c.getHandle(thePtaToken);
0216
0217
0218 m_ptAssMethod = getPtMethod();
0219
0220
0221 int bend_angle = getPtAddress(m_ptAssMethod);
0222 int bend_carga = getPtAddress(m_ptAssMethod, 1);
0223
0224
0225 int lut_idx = m_ptAssMethod;
0226 int pt = thePtaLUTs->getPt(lut_idx, bend_angle);
0227
0228 m_sp.track(m_id)->setPt(pt);
0229 m_sp.tracK(m_id)->setPt(pt);
0230
0231
0232 int chsign = getCharge(m_ptAssMethod);
0233 int charge = (bend_carga >= 0) ? chsign : -1 * chsign;
0234 m_sp.track(m_id)->setCharge(charge);
0235 m_sp.tracK(m_id)->setCharge(charge);
0236 }
0237
0238
0239
0240
0241 void L1MuDTAssignmentUnit::QuaAU() {
0242 unsigned int quality = 0;
0243
0244 const TrackClass tc = m_sp.TA()->trackClass(m_id);
0245
0246 switch (tc) {
0247 case T1234: {
0248 quality = 7;
0249 break;
0250 }
0251 case T123: {
0252 quality = 6;
0253 break;
0254 }
0255 case T124: {
0256 quality = 6;
0257 break;
0258 }
0259 case T134: {
0260 quality = 5;
0261 break;
0262 }
0263 case T234: {
0264 quality = 4;
0265 break;
0266 }
0267 case T12: {
0268 quality = 3;
0269 break;
0270 }
0271 case T13: {
0272 quality = 3;
0273 break;
0274 }
0275 case T14: {
0276 quality = 3;
0277 break;
0278 }
0279 case T23: {
0280 quality = 2;
0281 break;
0282 }
0283 case T24: {
0284 quality = 2;
0285 break;
0286 }
0287 case T34: {
0288 quality = 1;
0289 break;
0290 }
0291 default: {
0292 quality = 0;
0293 break;
0294 }
0295 }
0296
0297 m_sp.track(m_id)->setQuality(quality);
0298 m_sp.tracK(m_id)->setQuality(quality);
0299 }
0300
0301
0302
0303
0304 void L1MuDTAssignmentUnit::TSR() {
0305
0306 const L1MuDTTrackSegPhi* ts = nullptr;
0307 for (int stat = 1; stat <= 4; stat++) {
0308 int adr = m_addArray.station(stat);
0309 if (adr != 15) {
0310 ts = m_sp.data()->getTSphi(stat, adr);
0311 if (ts != nullptr)
0312 m_TSphi.push_back(ts);
0313 }
0314 }
0315 }
0316
0317
0318
0319
0320 const L1MuDTTrackSegPhi* L1MuDTAssignmentUnit::getTSphi(int station) const {
0321 vector<const L1MuDTTrackSegPhi*>::const_iterator iter;
0322 for (iter = m_TSphi.begin(); iter != m_TSphi.end(); iter++) {
0323 int stat = (*iter)->station();
0324 if (station == stat) {
0325 return (*iter);
0326 break;
0327 }
0328 }
0329
0330 return nullptr;
0331 }
0332
0333
0334
0335
0336 int L1MuDTAssignmentUnit::convertSector(int sector) {
0337
0338 const int sectorvalues[12] = {0, 12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132};
0339
0340 return sectorvalues[sector];
0341 }
0342
0343
0344
0345
0346 int L1MuDTAssignmentUnit::getCharge(PtAssMethod method) {
0347 int chargesign = 0;
0348 switch (method) {
0349 case PT12L: {
0350 chargesign = -1;
0351 break;
0352 }
0353 case PT12H: {
0354 chargesign = -1;
0355 break;
0356 }
0357 case PT13L: {
0358 chargesign = -1;
0359 break;
0360 }
0361 case PT13H: {
0362 chargesign = -1;
0363 break;
0364 }
0365 case PT14L: {
0366 chargesign = -1;
0367 break;
0368 }
0369 case PT14H: {
0370 chargesign = -1;
0371 break;
0372 }
0373 case PT23L: {
0374 chargesign = -1;
0375 break;
0376 }
0377 case PT23H: {
0378 chargesign = -1;
0379 break;
0380 }
0381 case PT24L: {
0382 chargesign = -1;
0383 break;
0384 }
0385 case PT24H: {
0386 chargesign = -1;
0387 break;
0388 }
0389 case PT34L: {
0390 chargesign = 1;
0391 break;
0392 }
0393 case PT34H: {
0394 chargesign = 1;
0395 break;
0396 }
0397 case PT12LO: {
0398 chargesign = -1;
0399 break;
0400 }
0401 case PT12HO: {
0402 chargesign = -1;
0403 break;
0404 }
0405 case PT13LO: {
0406 chargesign = -1;
0407 break;
0408 }
0409 case PT13HO: {
0410 chargesign = -1;
0411 break;
0412 }
0413 case PT14LO: {
0414 chargesign = -1;
0415 break;
0416 }
0417 case PT14HO: {
0418 chargesign = -1;
0419 break;
0420 }
0421 case PT23LO: {
0422 chargesign = -1;
0423 break;
0424 }
0425 case PT23HO: {
0426 chargesign = -1;
0427 break;
0428 }
0429 case PT24LO: {
0430 chargesign = -1;
0431 break;
0432 }
0433 case PT24HO: {
0434 chargesign = -1;
0435 break;
0436 }
0437 case PT34LO: {
0438 chargesign = 1;
0439 break;
0440 }
0441 case PT34HO: {
0442 chargesign = 1;
0443 break;
0444 }
0445 case PT15LO: {
0446 chargesign = -1;
0447 break;
0448 }
0449 case PT15HO: {
0450 chargesign = -1;
0451 break;
0452 }
0453 case PT25LO: {
0454 chargesign = -1;
0455 break;
0456 }
0457 case PT25HO: {
0458 chargesign = -1;
0459 break;
0460 }
0461 case NODEF: {
0462 chargesign = 0;
0463
0464
0465 break;
0466 }
0467 }
0468
0469 return chargesign;
0470 }
0471
0472
0473
0474
0475 PtAssMethod L1MuDTAssignmentUnit::getPtMethod() const {
0476
0477
0478
0479
0480
0481 const bitset<4> s = m_sp.TA()->trackBitMap(m_id);
0482
0483 int method = -1;
0484
0485 if (s.test(0) && s.test(3))
0486 method = 2;
0487 if (s.test(0) && s.test(2))
0488 method = 1;
0489 if (s.test(0) && s.test(1))
0490 method = 0;
0491 if (!s.test(0) && s.test(1) && s.test(3))
0492 method = 4;
0493 if (!s.test(0) && s.test(1) && s.test(2))
0494 method = 3;
0495 if (!s.test(0) && !s.test(1) && s.test(2) && s.test(3))
0496 method = 5;
0497
0498 if (m_sp.ovl()) {
0499 int adr = m_addArray.station(3);
0500 bool s5 = (adr == 15) ? false : ((adr / 2) % 2 == 1);
0501 if (s.test(0) && s.test(3))
0502 method = 8;
0503 if (s.test(0) && s.test(2) && s5)
0504 method = 12;
0505 if (s.test(0) && s.test(2) && !s5)
0506 method = 7;
0507 if (s.test(0) && s.test(1))
0508 method = 6;
0509 if (!s.test(0) && s.test(1) && s.test(3))
0510 method = 10;
0511 if (!s.test(0) && s.test(1) && s.test(2) && s5)
0512 method = 13;
0513 if (!s.test(0) && s.test(1) && s.test(2) && !s5)
0514 method = 9;
0515 if (!s.test(0) && !s.test(1) && s.test(2) && s.test(3))
0516 method = 11;
0517 }
0518
0519 int threshold = thePtaLUTs->getPtLutThreshold(method);
0520
0521
0522 int phib1 = (getTSphi(1) != nullptr) ? getTSphi(1)->phib() : 0;
0523 int phib2 = (getTSphi(2) != nullptr) ? getTSphi(2)->phib() : 0;
0524 int phib4 = (getTSphi(4) != nullptr) ? getTSphi(4)->phib() : 0;
0525
0526 PtAssMethod pam = NODEF;
0527
0528 switch (method) {
0529 case 0: {
0530 pam = (abs(phib1) < threshold) ? PT12H : PT12L;
0531 break;
0532 }
0533 case 1: {
0534 pam = (abs(phib1) < threshold) ? PT13H : PT13L;
0535 break;
0536 }
0537 case 2: {
0538 pam = (abs(phib1) < threshold) ? PT14H : PT14L;
0539 break;
0540 }
0541 case 3: {
0542 pam = (abs(phib2) < threshold) ? PT23H : PT23L;
0543 break;
0544 }
0545 case 4: {
0546 pam = (abs(phib2) < threshold) ? PT24H : PT24L;
0547 break;
0548 }
0549 case 5: {
0550 pam = (abs(phib4) < threshold) ? PT34H : PT34L;
0551 break;
0552 }
0553 case 6: {
0554 pam = (abs(phib1) < threshold) ? PT12HO : PT12LO;
0555 break;
0556 }
0557 case 7: {
0558 pam = (abs(phib1) < threshold) ? PT13HO : PT13LO;
0559 break;
0560 }
0561 case 8: {
0562 pam = (abs(phib1) < threshold) ? PT14HO : PT14LO;
0563 break;
0564 }
0565 case 9: {
0566 pam = (abs(phib2) < threshold) ? PT23HO : PT23LO;
0567 break;
0568 }
0569 case 10: {
0570 pam = (abs(phib2) < threshold) ? PT24HO : PT24LO;
0571 break;
0572 }
0573 case 11: {
0574 pam = (abs(phib4) < threshold) ? PT34HO : PT34LO;
0575 break;
0576 }
0577 case 12: {
0578 pam = (abs(phib1) < threshold) ? PT15HO : PT15LO;
0579 break;
0580 }
0581 case 13: {
0582 pam = (abs(phib2) < threshold) ? PT25HO : PT25LO;
0583 break;
0584 }
0585 default:;
0586
0587 }
0588
0589 return pam;
0590 }
0591
0592
0593
0594
0595 int L1MuDTAssignmentUnit::getPtAddress(PtAssMethod method, int bendcharge) const {
0596
0597
0598 int bendangle = 0;
0599 switch (method) {
0600 case PT12L: {
0601 bendangle = phiDiff(1, 2);
0602 break;
0603 }
0604 case PT12H: {
0605 bendangle = phiDiff(1, 2);
0606 break;
0607 }
0608 case PT13L: {
0609 bendangle = phiDiff(1, 3);
0610 break;
0611 }
0612 case PT13H: {
0613 bendangle = phiDiff(1, 3);
0614 break;
0615 }
0616 case PT14L: {
0617 bendangle = phiDiff(1, 4);
0618 break;
0619 }
0620 case PT14H: {
0621 bendangle = phiDiff(1, 4);
0622 break;
0623 }
0624 case PT23L: {
0625 bendangle = phiDiff(2, 3);
0626 break;
0627 }
0628 case PT23H: {
0629 bendangle = phiDiff(2, 3);
0630 break;
0631 }
0632 case PT24L: {
0633 bendangle = phiDiff(2, 4);
0634 break;
0635 }
0636 case PT24H: {
0637 bendangle = phiDiff(2, 4);
0638 break;
0639 }
0640 case PT34L: {
0641 bendangle = phiDiff(4, 3);
0642 break;
0643 }
0644 case PT34H: {
0645 bendangle = phiDiff(4, 3);
0646 break;
0647 }
0648 case PT12LO: {
0649 bendangle = phiDiff(1, 2);
0650 break;
0651 }
0652 case PT12HO: {
0653 bendangle = phiDiff(1, 2);
0654 break;
0655 }
0656 case PT13LO: {
0657 bendangle = phiDiff(1, 3);
0658 break;
0659 }
0660 case PT13HO: {
0661 bendangle = phiDiff(1, 3);
0662 break;
0663 }
0664 case PT14LO: {
0665 bendangle = phiDiff(1, 4);
0666 break;
0667 }
0668 case PT14HO: {
0669 bendangle = phiDiff(1, 4);
0670 break;
0671 }
0672 case PT23LO: {
0673 bendangle = phiDiff(2, 3);
0674 break;
0675 }
0676 case PT23HO: {
0677 bendangle = phiDiff(2, 3);
0678 break;
0679 }
0680 case PT24LO: {
0681 bendangle = phiDiff(2, 4);
0682 break;
0683 }
0684 case PT24HO: {
0685 bendangle = phiDiff(2, 4);
0686 break;
0687 }
0688 case PT34LO: {
0689 bendangle = phiDiff(4, 3);
0690 break;
0691 }
0692 case PT34HO: {
0693 bendangle = phiDiff(4, 3);
0694 break;
0695 }
0696 case PT15LO: {
0697 bendangle = phiDiff(1, 3);
0698 break;
0699 }
0700 case PT15HO: {
0701 bendangle = phiDiff(1, 3);
0702 break;
0703 }
0704 case PT25LO: {
0705 bendangle = phiDiff(2, 3);
0706 break;
0707 }
0708 case PT25HO: {
0709 bendangle = phiDiff(2, 3);
0710 break;
0711 }
0712 case NODEF: {
0713 bendangle = 0;
0714
0715 break;
0716 }
0717 }
0718
0719 int signo = 1;
0720 bendangle = (bendangle + 8192) % 4096;
0721 if (bendangle > 2047)
0722 bendangle -= 4096;
0723 if (bendangle < 0)
0724 signo = -1;
0725
0726 if (bendcharge)
0727 return signo;
0728
0729 bendangle = (bendangle + 2048) % 1024;
0730 if (bendangle > 511)
0731 bendangle -= 1024;
0732
0733 return bendangle;
0734 }
0735
0736
0737
0738
0739 int L1MuDTAssignmentUnit::phiDiff(int stat1, int stat2) const {
0740
0741
0742 int sh_phi = 12 - nbit_phi;
0743
0744
0745 int sector1 = getTSphi(stat1)->sector();
0746 int sector2 = getTSphi(stat2)->sector();
0747 int phi1 = getTSphi(stat1)->phi() >> sh_phi;
0748 int phi2 = getTSphi(stat2)->phi() >> sh_phi;
0749
0750
0751
0752 int sectordiff = (sector2 - sector1) % 12;
0753 if (sectordiff >= 6)
0754 sectordiff -= 12;
0755 if (sectordiff < -6)
0756 sectordiff += 12;
0757
0758
0759
0760 int offset = (2144 >> sh_phi) * sectordiff;
0761 int bendangle = l1t::bitShift((phi2 - phi1 + offset), sh_phi);
0762
0763 return bendangle;
0764 }
0765
0766
0767
0768
0769
0770 void L1MuDTAssignmentUnit::setPrecision() {
0771 nbit_phi = m_sp.tf().config()->getNbitsPtaPhi();
0772 nbit_phib = m_sp.tf().config()->getNbitsPtaPhib();
0773 }
0774
0775