File indexing completed on 2024-09-07 04:36:14
0001 #include "EventFilter/L1TRawToDigi/plugins/UnpackerFactory.h"
0002
0003 #include "BMTFUnpackerInputs.h"
0004
0005 #include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambPhContainer.h"
0006 #include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambThContainer.h"
0007
0008 namespace l1t {
0009 namespace stage2 {
0010 void numWheelSectorTrTag_bmtf(int& wheelNo, int& tagSegID, int linkNo, int amcNo) {
0011 if (linkNo >= 0 && linkNo < 6)
0012 wheelNo = -2;
0013 else if (linkNo >= 8 && linkNo < 14)
0014 wheelNo = -1;
0015 else if (linkNo >= 16 && linkNo < 22)
0016 wheelNo = 0;
0017 else if (linkNo >= 22 && linkNo < 28)
0018 wheelNo = 1;
0019 else if ((linkNo >= 28 && linkNo < 30) || (linkNo >= 32 && linkNo < 36))
0020 wheelNo = 2;
0021
0022 if (linkNo % 2 == 0)
0023 tagSegID = 0;
0024 else
0025 tagSegID = 1;
0026 }
0027
0028 bool checkQual_bmtf(const unsigned int& value, const bool& isNewFw) {
0029 if (isNewFw)
0030 return (value == 7);
0031 else
0032 return (value == 0);
0033 }
0034
0035 bool unpacking_bmtf(const Block& block, UnpackerCollections* coll, qualityHits& linkAndQual_, const bool& isNewFw) {
0036 unsigned int ownLinks[] = {4, 5, 12, 13, 20, 21, 22, 23, 28, 29};
0037 bool ownFlag(false);
0038
0039
0040 for (int i = 0; i < 10; i++) {
0041 if (block.header().getID() / 2 == ownLinks[i])
0042 ownFlag = true;
0043 }
0044 if (!ownFlag)
0045 return true;
0046
0047
0048 unsigned int blockId = block.header().getID();
0049 LogDebug("L1T") << "Block ID: " << blockId << " size: " << block.header().getSize();
0050
0051
0052 L1MuDTChambPhContainer* resPhi = static_cast<BMTFCollections*>(coll)->getInMuonsPh();
0053 L1MuDTChambThContainer* resThe = static_cast<BMTFCollections*>(coll)->getInMuonsTh();
0054
0055
0056 L1MuDTChambPhContainer::Phi_Container phiData = *(resPhi->getContainer());
0057 L1MuDTChambThContainer::The_Container theData = *(resThe->getContainer());
0058
0059
0060 BxBlocks bxBlocks;
0061 bool ZS_enabled =
0062 (bool)((block.header().getFlags() >> 1) & 0x01);
0063 if (ZS_enabled)
0064 bxBlocks =
0065 block.getBxBlocks((unsigned int)6, true);
0066 else
0067 bxBlocks =
0068 block.getBxBlocks((unsigned int)6, false);
0069
0070 for (const auto& ibx : bxBlocks)
0071 {
0072 int bxNum = ibx.header().getBx();
0073 uint32_t inputWords[ibx.getSize()];
0074
0075
0076
0077
0078
0079
0080 for (unsigned int iw = 0; iw < ibx.getSize(); iw++)
0081 inputWords[iw] = (ibx.payload())[iw];
0082
0083 int wheel, sector, trTag;
0084 numWheelSectorTrTag_bmtf(wheel, trTag, blockId / 2, block.amc().getAMCNumber());
0085 sector = block.amc().getBoardID() - 1;
0086
0087
0088 if (sector < 0 || sector > 11) {
0089 edm::LogInfo("l1t:stage2::BMTFUnpackerInputs::unpack")
0090 << "Sector found out of range so it will be calculated by the slot number";
0091 if (block.amc().getAMCNumber() % 2 != 0)
0092 sector = block.amc().getAMCNumber() / 2;
0093 else
0094 sector = 6 + (block.amc().getAMCNumber() / 2 - 1);
0095 }
0096
0097 int mbPhi[4], mbPhiB[4], mbQual[4], mbBxC[4], mbRPC[4];
0098
0099
0100 for (int iw = 0; iw < 4; iw++)
0101 {
0102 if (((inputWords[iw] & 0xfffffff) == 0) || (inputWords[iw] == 0x505050bc))
0103 continue;
0104 else if ((inputWords[iw] != 0x505050bc) && (inputWords[iw + 2] == 0x505050bc))
0105 continue;
0106
0107 if (((inputWords[iw] >> 11) & 0x1) == 1)
0108 mbPhi[iw] = (inputWords[iw] & 0x7FF) - 2048;
0109 else
0110 mbPhi[iw] = (inputWords[iw] & 0xFFF);
0111
0112 if (((inputWords[iw] >> 21) & 0x1) == 1)
0113 mbPhiB[iw] = ((inputWords[iw] >> 12) & 0x1FF) - 512;
0114 else
0115 mbPhiB[iw] = (inputWords[iw] >> 12) & 0x3FF;
0116
0117 mbQual[iw] = (inputWords[iw] >> 22) & 0x7;
0118 mbRPC[iw] = (inputWords[iw] >> 26) & 0x1;
0119 mbBxC[iw] = (inputWords[iw] >> 30) & 0x3;
0120
0121
0122 if (checkQual_bmtf(mbQual[iw], isNewFw))
0123 continue;
0124
0125 phiData.push_back(L1MuDTChambPhDigi(
0126 bxNum, wheel, sector, iw + 1, mbPhi[iw], mbPhiB[iw], mbQual[iw], trTag, mbBxC[iw], mbRPC[iw]));
0127
0128 }
0129
0130 int etaHits[3][7];
0131 bool zeroFlag[3];
0132 for (int i = 0; i < 3; i++)
0133 {
0134 zeroFlag[i] = false;
0135 for (int j = 0; j < 7; j++) {
0136 etaHits[i][j] = (inputWords[4] >> (i * 7 + j)) & 0x1;
0137 if (etaHits[i][j] != 0)
0138 zeroFlag[i] = true;
0139 }
0140 }
0141
0142 if (trTag == 1) {
0143 for (int i = 0; i < 3; i++) {
0144 if (zeroFlag[i])
0145 theData.push_back(L1MuDTChambThDigi(bxNum, wheel, sector, i + 1, etaHits[i], linkAndQual_.hits[i]));
0146 }
0147
0148 } else {
0149
0150
0151
0152
0153
0154
0155 linkAndQual_.linkNo = blockId / 2;
0156 std::copy(&etaHits[0][0], &etaHits[0][0] + 3 * 7, &linkAndQual_.hits[0][0]);
0157 }
0158
0159 }
0160
0161
0162 resThe->setContainer(theData);
0163 resPhi->setContainer(phiData);
0164
0165 return true;
0166 }
0167
0168 bool BMTFUnpackerInputsOldQual::unpack(const Block& block, UnpackerCollections* coll) {
0169 return unpacking_bmtf(block, coll, linkAndQual_, false);
0170 }
0171
0172 bool BMTFUnpackerInputsNewQual::unpack(const Block& block, UnpackerCollections* coll) {
0173 return unpacking_bmtf(block, coll, linkAndQual_, true);
0174 }
0175 }
0176 }
0177
0178 DEFINE_L1T_UNPACKER(l1t::stage2::BMTFUnpackerInputsOldQual);
0179 DEFINE_L1T_UNPACKER(l1t::stage2::BMTFUnpackerInputsNewQual);