File indexing completed on 2024-09-07 04:37:05
0001
0002 #include "L1Trigger/RPCTrigger/interface/RPCHalfSorter.h"
0003
0004 #include "L1Trigger/RPCTrigger/interface/RPCConst.h"
0005 #include <algorithm>
0006
0007 #include "L1Trigger/RPCTrigger/interface/MuonsGrabber.h"
0008
0009 #include <set>
0010 using namespace std;
0011
0012
0013
0014
0015
0016
0017 RPCHalfSorter::RPCHalfSorter(RPCTriggerConfiguration *triggerConfig) {
0018 m_TrigCnfg = triggerConfig;
0019
0020 m_GBOutputMuons.assign(2, L1RpcTBMuonsVec());
0021 }
0022
0023
0024
0025
0026
0027
0028 L1RpcTBMuonsVec2 RPCHalfSorter::runHalf(L1RpcTBMuonsVec2 &tcsMuonsVec2) {
0029
0030 for (unsigned int iTC = 0; iTC < tcsMuonsVec2.size() - 1; iTC++) {
0031 for (unsigned int iMu = 0; iMu < tcsMuonsVec2[iTC].size(); iMu++) {
0032 if (tcsMuonsVec2[iTC][iMu].getCode() == 0)
0033 continue;
0034 if (tcsMuonsVec2[iTC][iMu].gBDataKilledLast()) {
0035 for (unsigned int iMuN = 0; iMuN < tcsMuonsVec2[iTC + 1].size(); iMuN++) {
0036 if (tcsMuonsVec2[iTC + 1][iMuN].getCode() == 0)
0037 continue;
0038 if (tcsMuonsVec2[iTC + 1][iMuN].gBDataKilledFirst()) {
0039 int eta1 = tcsMuonsVec2[iTC][iMu].getEtaAddr();
0040 int eta2 = tcsMuonsVec2[iTC + 1][iMuN].getEtaAddr();
0041 if (eta1 > 16)
0042 eta1 = -((~eta1 & 63) + 1);
0043 if (eta2 > 16)
0044 eta2 = -((~eta2 & 63) + 1);
0045 if (abs(eta1 - eta2) <= 1) {
0046 if (tcsMuonsVec2[iTC][iMu].getCode() <= tcsMuonsVec2[iTC + 1][iMuN].getCode()) {
0047 if (tcsMuonsVec2[iTC][iMu].getSegmentAddr() == RPCConst::m_SEGMENTS_IN_SECTOR_CNT - 1) {
0048 tcsMuonsVec2[iTC][iMu].kill();
0049 }
0050 } else {
0051 tcsMuonsVec2[iTC + 1][iMuN].kill();
0052 }
0053 }
0054 }
0055 }
0056 }
0057 }
0058 }
0059
0060 L1RpcTBMuonsVec outputBarrelMuons;
0061 L1RpcTBMuonsVec outputEndcapMuons;
0062
0063 for (unsigned int iTC = 1; iTC < tcsMuonsVec2.size() - 1; iTC++)
0064 for (unsigned int iMu = 0; iMu < tcsMuonsVec2[iTC].size(); iMu++)
0065 if (tcsMuonsVec2[iTC][iMu].isLive()) {
0066
0067
0068 if (tcsMuonsVec2[iTC][iMu].getEtaAddr() >= 57 || tcsMuonsVec2[iTC][iMu].getEtaAddr() <= 7) {
0069 outputBarrelMuons.push_back(tcsMuonsVec2[iTC][iMu]);
0070 } else {
0071 outputEndcapMuons.push_back(tcsMuonsVec2[iTC][iMu]);
0072 }
0073 }
0074
0075 sort(outputBarrelMuons.begin(), outputBarrelMuons.end(), RPCTBMuon::TMuonMore());
0076 sort(outputEndcapMuons.begin(), outputEndcapMuons.end(), RPCTBMuon::TMuonMore());
0077
0078 while (outputBarrelMuons.size() < RPCConst::m_FINAL_OUT_MUONS_CNT)
0079 outputBarrelMuons.push_back(RPCTBMuon());
0080 while (outputBarrelMuons.size() > RPCConst::m_FINAL_OUT_MUONS_CNT)
0081 outputBarrelMuons.pop_back();
0082
0083 while (outputEndcapMuons.size() < RPCConst::m_FINAL_OUT_MUONS_CNT)
0084 outputEndcapMuons.push_back(RPCTBMuon());
0085 while (outputEndcapMuons.size() > RPCConst::m_FINAL_OUT_MUONS_CNT)
0086 outputEndcapMuons.pop_back();
0087
0088 m_GBOutputMuons[0].insert(m_GBOutputMuons[0].end(), outputBarrelMuons.begin(), outputBarrelMuons.end());
0089 m_GBOutputMuons[1].insert(m_GBOutputMuons[1].end(), outputEndcapMuons.begin(), outputEndcapMuons.end());
0090 return m_GBOutputMuons;
0091 }
0092 void RPCHalfSorter::maskHSBInput(L1RpcTBMuonsVec &newVec, int mask) {
0093 if (mask < 0 || mask > 3) {
0094 throw cms::Exception("RPCHalfSorter::maskHSBInput") << " hsbMask has wrong value - " << mask << " \n";
0095 }
0096
0097 if (mask == 1) {
0098 newVec.at(2) = RPCTBMuon();
0099 newVec.at(3) = RPCTBMuon();
0100 } else if (mask == 2) {
0101 newVec.at(0) = RPCTBMuon();
0102 newVec.at(1) = RPCTBMuon();
0103 } else {
0104 newVec.at(0) = RPCTBMuon();
0105 newVec.at(1) = RPCTBMuon();
0106 newVec.at(2) = RPCTBMuon();
0107 newVec.at(3) = RPCTBMuon();
0108 }
0109 }
0110
0111
0112
0113
0114
0115
0116
0117
0118 L1RpcTBMuonsVec2 RPCHalfSorter::run(L1RpcTBMuonsVec2 &tcsMuonsVec2, edm::ESHandle<L1RPCHsbConfig> hsbConf) {
0119 m_GBOutputMuons[0].clear();
0120 m_GBOutputMuons[1].clear();
0121
0122 L1RpcTBMuonsVec2 firstHalfTcsMuonsVec2;
0123
0124 if (tcsMuonsVec2[m_TrigCnfg->getTCsCnt() - 1].empty() || hsbConf->getHsbMask(0, 0) == 3) {
0125 firstHalfTcsMuonsVec2.push_back(tcsMuonsVec2[m_TrigCnfg->getTCsCnt() - 1]);
0126 } else {
0127 L1RpcTBMuonsVec newVec = tcsMuonsVec2[m_TrigCnfg->getTCsCnt() - 1];
0128 maskHSBInput(newVec, hsbConf->getHsbMask(0, 0));
0129 firstHalfTcsMuonsVec2.push_back(newVec);
0130 }
0131
0132
0133 int secAddr = 1;
0134
0135 for (int iTC = 0; iTC < m_TrigCnfg->getTCsCnt() / 2 + 1; iTC++) {
0136 for (unsigned int iMu = 0; iMu < tcsMuonsVec2[iTC].size(); iMu++) {
0137 if (secAddr != 0 && secAddr != 7) {
0138 tcsMuonsVec2[iTC][iMu].setSectorAddr(secAddr);
0139
0140
0141
0142
0143 }
0144 }
0145 ++secAddr;
0146
0147 if (tcsMuonsVec2[iTC].empty() || hsbConf->getHsbMask(0, iTC + 1) == 3) {
0148 firstHalfTcsMuonsVec2.push_back(tcsMuonsVec2[iTC]);
0149 } else {
0150 L1RpcTBMuonsVec newVec = tcsMuonsVec2[iTC];
0151 maskHSBInput(newVec, hsbConf->getHsbMask(0, iTC + 1));
0152 firstHalfTcsMuonsVec2.push_back(newVec);
0153 }
0154 }
0155
0156 runHalf(firstHalfTcsMuonsVec2);
0157
0158 unsigned int fhBMuons = m_GBOutputMuons[0].size();
0159 unsigned int fhEMuons = m_GBOutputMuons[1].size();
0160
0161 L1RpcTBMuonsVec2 secondHalfTcsMuonsVec2;
0162 secAddr = 0;
0163
0164 for (int iTC = m_TrigCnfg->getTCsCnt() / 2 - 1; iTC < m_TrigCnfg->getTCsCnt(); iTC++) {
0165 for (unsigned int iMu = 0; iMu < tcsMuonsVec2[iTC].size(); iMu++) {
0166 if (secAddr != 0 && secAddr != 7) {
0167 tcsMuonsVec2[iTC][iMu].setSectorAddr(secAddr);
0168
0169
0170 }
0171 }
0172 ++secAddr;
0173 if (tcsMuonsVec2[iTC].empty() || hsbConf->getHsbMask(1, iTC - 5) == 3) {
0174 secondHalfTcsMuonsVec2.push_back(tcsMuonsVec2[iTC]);
0175 } else {
0176 L1RpcTBMuonsVec newVec = tcsMuonsVec2[iTC];
0177 maskHSBInput(newVec, hsbConf->getHsbMask(1, iTC - 5));
0178 secondHalfTcsMuonsVec2.push_back(newVec);
0179 }
0180 }
0181
0182
0183 if (tcsMuonsVec2[0].empty() || hsbConf->getHsbMask(1, 7) == 3) {
0184 secondHalfTcsMuonsVec2.push_back(tcsMuonsVec2[0]);
0185 } else {
0186 L1RpcTBMuonsVec newVec = tcsMuonsVec2[0];
0187 maskHSBInput(newVec, hsbConf->getHsbMask(1, 7));
0188 secondHalfTcsMuonsVec2.push_back(newVec);
0189 }
0190
0191 runHalf(secondHalfTcsMuonsVec2);
0192
0193 for (unsigned int region = 0; region < m_GBOutputMuons.size(); ++region) {
0194 for (unsigned int i = 0; i < m_GBOutputMuons[region].size(); ++i) {
0195 unsigned int halfNum = 0;
0196 int iMod = 0;
0197
0198
0199
0200 if ((region == 0 && i >= fhBMuons) || (region == 1 && i >= fhEMuons)) {
0201 halfNum = 1;
0202 iMod = 4;
0203 }
0204
0205 if (m_TrigCnfg->getDebugLevel() == 1) {
0206 #ifndef _STAND_ALONE
0207
0208
0209
0210
0211 MuonsGrabber::Instance().addMuon(m_GBOutputMuons[region][i], 3, region, halfNum, i - iMod);
0212
0213 #else
0214 std::cout << "GB 3" << region << halfNum << " " << i - iMod << " "
0215 << m_GBOutputMuons[region][i].printDebugInfo(m_TrigCnfg->getDebugLevel()) << std::endl;
0216 #endif
0217 }
0218
0219 int segment = m_GBOutputMuons[region][i].getSegmentAddr();
0220 int sector = m_GBOutputMuons[region][i].getSectorAddr() - 1 + 6 * halfNum;
0221 int pt = m_GBOutputMuons[region][i].getPtCode();
0222 if (pt != 0) {
0223 m_GBOutputMuons[region][i].setPhiAddr((sector * 12 + segment + 2) % 144);
0224 }
0225 }
0226 }
0227
0228 return m_GBOutputMuons;
0229 }