File indexing completed on 2024-07-18 23:17:52
0001 #include "L1Trigger/Phase2L1GMT/interface/L1TPhase2GMTBarrelStubProcessor.h"
0002 #include <cmath>
0003 #include <iostream>
0004 #include <string>
0005 #include <sstream>
0006 #include <iomanip>
0007 #include <ap_int.h>
0008
0009 L1TPhase2GMTBarrelStubProcessor::L1TPhase2GMTBarrelStubProcessor() : minPhiQuality_(0), minBX_(-3), maxBX_(3) {}
0010
0011 L1TPhase2GMTBarrelStubProcessor::L1TPhase2GMTBarrelStubProcessor(const edm::ParameterSet& iConfig)
0012 : minPhiQuality_(iConfig.getParameter<int>("minPhiQuality")),
0013 minBX_(iConfig.getParameter<int>("minBX")),
0014 maxBX_(iConfig.getParameter<int>("maxBX")),
0015 eta1_(iConfig.getParameter<std::vector<int> >("eta_1")),
0016 eta2_(iConfig.getParameter<std::vector<int> >("eta_2")),
0017 eta3_(iConfig.getParameter<std::vector<int> >("eta_3")),
0018 coarseEta1_(iConfig.getParameter<std::vector<int> >("coarseEta_1")),
0019 coarseEta2_(iConfig.getParameter<std::vector<int> >("coarseEta_2")),
0020 coarseEta3_(iConfig.getParameter<std::vector<int> >("coarseEta_3")),
0021 coarseEta4_(iConfig.getParameter<std::vector<int> >("coarseEta_4")),
0022 phiOffset_(iConfig.getParameter<std::vector<int> >("phiOffset")),
0023 phiBFactor_(iConfig.getParameter<int>("phiBDivider")),
0024 verbose_(iConfig.getParameter<int>("verbose")),
0025 phiLSB_(iConfig.getParameter<double>("phiLSB")),
0026 etaLSB_(iConfig.getParameter<double>("etaLSB")) {}
0027
0028 L1TPhase2GMTBarrelStubProcessor::~L1TPhase2GMTBarrelStubProcessor() {}
0029
0030 l1t::MuonStub L1TPhase2GMTBarrelStubProcessor::buildStub(const L1Phase2MuDTPhDigi& phiS,
0031 const L1MuDTChambThDigi* etaS) {
0032 l1t::MuonStub stub = buildStubNoEta(phiS);
0033
0034
0035 int qeta1 = -16384;
0036 int qeta2 = -16384;
0037 int eta1 = -16384;
0038 int eta2 = -16384;
0039
0040 bool hasEta = false;
0041 for (uint i = 0; i < 7; ++i) {
0042 if (etaS->position(i) == 0)
0043 continue;
0044 if (!hasEta) {
0045 hasEta = true;
0046 eta1 = calculateEta(i, etaS->whNum(), etaS->scNum(), etaS->stNum());
0047
0048 if (etaS->quality(i) == 1)
0049 qeta1 = 2;
0050 else
0051 qeta1 = 1;
0052 } else {
0053 eta2 = calculateEta(i, etaS->whNum(), etaS->scNum(), etaS->stNum());
0054 if (etaS->quality(i) == 1)
0055 qeta2 = 2;
0056 else
0057 qeta2 = 1;
0058 }
0059 }
0060
0061 if (qeta2 > 0) {
0062 stub.setEta(eta1, eta2, 3);
0063 stub.setOfflineQuantities(stub.offline_coord1(), stub.offline_coord2(), eta1 * etaLSB_, eta2 * etaLSB_);
0064
0065 } else if (qeta1 > 0) {
0066 stub.setEta(eta1, 0, 1);
0067 stub.setOfflineQuantities(stub.offline_coord1(), stub.offline_coord2(), eta1 * etaLSB_, 0.0);
0068 }
0069
0070 return stub;
0071 }
0072
0073 l1t::MuonStub L1TPhase2GMTBarrelStubProcessor::buildStubNoEta(const L1Phase2MuDTPhDigi& phiS) {
0074 int wheel = phiS.whNum();
0075 int abswheel = fabs(phiS.whNum());
0076 int sign = wheel > 0 ? 1 : -1;
0077 int sector = phiS.scNum();
0078 int station = phiS.stNum();
0079
0080 ap_uint<18> normalization0 = sector * ap_uint<15>(21845);
0081 ap_int<18> normalization1 = ap_int<18>(ap_int<17>(phiS.phi()) * ap_ufixed<8, 0>(0.3183));
0082 ap_int<18> kmtf_phi = ap_int<18>(normalization0 + normalization1);
0083 int phi = int(kmtf_phi);
0084 float globalPhi = phi * M_PI / (1 << 17);
0085
0086
0087 int tag = phiS.index();
0088
0089 int bx = phiS.bxNum() - 20;
0090 int quality = phiS.quality();
0091 uint tfLayer = phiS.stNum() - 1;
0092 int eta = -16384;
0093 if (station == 1) {
0094 eta = coarseEta1_[abswheel];
0095 } else if (station == 2) {
0096 eta = coarseEta2_[abswheel];
0097 } else if (station == 3) {
0098 eta = coarseEta3_[abswheel];
0099 } else if (station == 4) {
0100 eta = coarseEta4_[abswheel];
0101 }
0102
0103
0104
0105
0106
0107
0108 eta = eta * sign;
0109 l1t::MuonStub stub(wheel, sector, station, tfLayer, phi, phiS.phiBend(), tag, bx, quality, eta, 0, 0, 1);
0110
0111 stub.setOfflineQuantities(globalPhi, float(phiS.phiBend() * 0.49e-3), eta * etaLSB_, 0.0);
0112 return stub;
0113 }
0114
0115 l1t::MuonStubCollection L1TPhase2GMTBarrelStubProcessor::makeStubs(const L1Phase2MuDTPhContainer* phiContainer,
0116 const L1MuDTChambThContainer* etaContainer) {
0117 l1t::MuonStubCollection out;
0118 for (int bx = minBX_; bx <= maxBX_; bx++) {
0119 ostringstream os;
0120 if (verbose_ == 2)
0121 os << "PATTERN ";
0122 for (int wheel = -2; wheel <= 2; wheel++) {
0123 for (int sector = 0; sector < 12; sector++) {
0124 for (int station = 1; station < 5; station++) {
0125 bool hasEta = false;
0126 const L1MuDTChambThDigi* tseta = etaContainer->chThetaSegm(wheel, station, sector, bx);
0127 if (tseta != nullptr) {
0128 hasEta = true;
0129 }
0130
0131 for (const auto& phiDigi : *phiContainer->getContainer()) {
0132 if ((phiDigi.bxNum() - 20) != bx || phiDigi.whNum() != wheel || phiDigi.scNum() != sector ||
0133 phiDigi.stNum() != station)
0134 continue;
0135 if (phiDigi.quality() < minPhiQuality_)
0136 continue;
0137
0138 if (verbose_ == 2) {
0139 ap_uint<64> wphi = ap_uint<17>(phiDigi.phi());
0140 ap_uint<64> wphib = ap_uint<13>(phiDigi.phiBend());
0141 ap_uint<64> wr1 = ap_uint<21>(0);
0142 ap_uint<64> wq = ap_uint<4>(phiDigi.quality());
0143 ap_uint<64> wr2 = ap_uint<9>(0);
0144 ap_uint<64> sN = 0;
0145 sN = sN | wphi;
0146 sN = sN | (wphib << 17);
0147 sN = sN | (wr1 << 30);
0148 sN = sN | (wq << 51);
0149 sN = sN | (wr2 << 55);
0150 os << std::setw(0) << std::dec << sector << " " << wheel << " " << station << " ";
0151 os << std::uppercase << std::setfill('0') << std::setw(16) << std::hex << uint64_t(sN) << " ";
0152 }
0153
0154 if (hasEta) {
0155 out.push_back(buildStub(phiDigi, tseta));
0156 } else {
0157 out.push_back(buildStubNoEta(phiDigi));
0158 }
0159 }
0160 }
0161 }
0162 }
0163 if (verbose_ == 2)
0164 edm::LogInfo("BarrelStub") << os.str() << std::endl;
0165 }
0166
0167 if (verbose_) {
0168 edm::LogInfo("BarrelStub") << "Barrel Stubs";
0169 for (const auto& stub : out)
0170 edm::LogInfo("BarrelStub") << "Barrel Stub bx=" << stub.bxNum() << " TF=" << stub.tfLayer()
0171 << " etaRegion=" << stub.etaRegion() << " phiRegion=" << stub.phiRegion()
0172 << " depthRegion=" << stub.depthRegion() << " coord1=" << stub.offline_coord1() << ","
0173 << stub.coord1() << " coord2=" << stub.offline_coord2() << "," << stub.coord2()
0174 << " eta1=" << stub.offline_eta1() << "," << stub.eta1()
0175 << " eta2=" << stub.offline_eta2() << "," << stub.eta2()
0176 << " quality=" << stub.quality() << " etaQuality=" << stub.etaQuality();
0177 }
0178
0179 return out;
0180 }
0181
0182 int L1TPhase2GMTBarrelStubProcessor::calculateEta(uint i, int wheel, uint sector, uint station) {
0183 int eta = 0;
0184 if (wheel > 0) {
0185 eta = 7 * wheel + 3 - i;
0186 } else if (wheel < 0) {
0187 eta = 7 * wheel + i - 3;
0188 } else {
0189 if (sector == 0 || sector == 3 || sector == 4 || sector == 7 || sector == 8 || sector == 11)
0190 eta = i - 3;
0191 else
0192 eta = 3 - i;
0193 }
0194
0195 if (station == 1)
0196 eta = eta1_[eta + 17];
0197 else if (station == 2)
0198 eta = eta2_[eta + 17];
0199 else
0200 eta = eta3_[eta + 17];
0201
0202 return eta;
0203 }