Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-08 06:28:04

0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002 #include "L1Trigger/L1TMuon/interface/RegionalMuonRawDigiTranslator.h"
0003 
0004 void l1t::RegionalMuonRawDigiTranslator::fillRegionalMuonCand(RegionalMuonCand& mu,
0005                                                               const uint32_t raw_data_00_31,
0006                                                               const uint32_t raw_data_32_63,
0007                                                               const int proc,
0008                                                               const tftype tf,
0009                                                               const bool isKbmtf,
0010                                                               const bool useEmtfDisplacementInfo) {
0011   // translations as defined in DN-15-017
0012   mu.setHwPt((raw_data_00_31 >> ptShift_) & ptMask_);
0013   mu.setHwQual((raw_data_00_31 >> qualShift_) & qualMask_);
0014 
0015   // eta is coded as two's complement
0016   int abs_eta = (raw_data_00_31 >> absEtaShift_) & absEtaMask_;
0017   if ((raw_data_00_31 >> etaSignShift_) & 0x1) {
0018     mu.setHwEta(abs_eta - (1 << (etaSignShift_ - absEtaShift_)));
0019   } else {
0020     mu.setHwEta(abs_eta);
0021   }
0022 
0023   // phi is coded as two's complement
0024   int abs_phi = (raw_data_00_31 >> absPhiShift_) & absPhiMask_;
0025   if ((raw_data_00_31 >> phiSignShift_) & 0x1) {
0026     mu.setHwPhi(abs_phi - (1 << (phiSignShift_ - absPhiShift_)));
0027   } else {
0028     mu.setHwPhi(abs_phi);
0029   }
0030 
0031   // sign is coded as -1^signBit
0032   mu.setHwSign((raw_data_32_63 >> signShift_) & 0x1);
0033   mu.setHwSignValid((raw_data_32_63 >> signValidShift_) & 0x1);
0034   mu.setHwHF((raw_data_00_31 >> hfShift_) & hfMask_);
0035 
0036   // set track address with subaddresses
0037   int rawTrackAddress = (raw_data_32_63 >> trackAddressShift_) & trackAddressMask_;
0038   if (tf == bmtf) {
0039     int detSide = (rawTrackAddress >> bmtfTrAddrDetSideShift_) & 0x1;
0040     int wheelNum = (rawTrackAddress >> bmtfTrAddrWheelShift_) & bmtfTrAddrWheelMask_;
0041     int statAddr1 = ((rawTrackAddress >> bmtfTrAddrStat1Shift_) & bmtfTrAddrStat1Mask_);
0042     int statAddr2 = ((rawTrackAddress >> bmtfTrAddrStat2Shift_) & bmtfTrAddrStat2Mask_);
0043     int statAddr3 = ((rawTrackAddress >> bmtfTrAddrStat3Shift_) & bmtfTrAddrStat3Mask_);
0044     int statAddr4 = ((rawTrackAddress >> bmtfTrAddrStat4Shift_) & bmtfTrAddrStat4Mask_);
0045 
0046     mu.setTrackSubAddress(RegionalMuonCand::kWheelSide, detSide);
0047     mu.setTrackSubAddress(RegionalMuonCand::kWheelNum, wheelNum);
0048     if (!isKbmtf) {  // The Run-2 standard configuration for BMTF
0049       mu.setTrackSubAddress(RegionalMuonCand::kStat1, statAddr1);
0050       mu.setTrackSubAddress(RegionalMuonCand::kStat2, statAddr2);
0051       mu.setTrackSubAddress(RegionalMuonCand::kStat3, statAddr3);
0052       mu.setTrackSubAddress(RegionalMuonCand::kStat4, statAddr4);
0053     } else {
0054       // For Run-3 track address encoding has changed as the Kalman Filter tracks from outside in.
0055       // As a result station assignment is inverted
0056       // (i.e. the field that contained the station 1 information for Run-2 now contains station 4 information and so on.)
0057       mu.setTrackSubAddress(RegionalMuonCand::kStat1, statAddr4);
0058       mu.setTrackSubAddress(RegionalMuonCand::kStat2, statAddr3);
0059       mu.setTrackSubAddress(RegionalMuonCand::kStat3, statAddr2);
0060       mu.setTrackSubAddress(RegionalMuonCand::kStat4, statAddr1);
0061       // Additionally we now have displacement information from the BMTF
0062       mu.setHwPtUnconstrained((raw_data_32_63 >> bmtfPtUnconstrainedShift_) & ptUnconstrainedMask_);
0063       mu.setHwDXY((raw_data_32_63 >> bmtfDxyShift_) & dxyMask_);
0064     }
0065     mu.setTrackSubAddress(RegionalMuonCand::kSegSelStat1, 0);
0066     mu.setTrackSubAddress(RegionalMuonCand::kSegSelStat2, 0);
0067     mu.setTrackSubAddress(RegionalMuonCand::kSegSelStat3, 0);
0068     mu.setTrackSubAddress(RegionalMuonCand::kSegSelStat4, 0);
0069     //mu.setTrackSubAddress(RegionalMuonCand::kNumBmtfSubAddr, 0);
0070   } else if (tf == emtf_neg || tf == emtf_pos) {
0071     mu.setTrackSubAddress(RegionalMuonCand::kME1Seg, (rawTrackAddress >> emtfTrAddrMe1SegShift_) & 0x1);
0072     mu.setTrackSubAddress(RegionalMuonCand::kME1Ch, (rawTrackAddress >> emtfTrAddrMe1ChShift_) & emtfTrAddrMe1ChMask_);
0073     mu.setTrackSubAddress(RegionalMuonCand::kME2Seg, (rawTrackAddress >> emtfTrAddrMe2SegShift_) & 0x1);
0074     mu.setTrackSubAddress(RegionalMuonCand::kME2Ch, (rawTrackAddress >> emtfTrAddrMe2ChShift_) & emtfTrAddrMe2ChMask_);
0075     mu.setTrackSubAddress(RegionalMuonCand::kME3Seg, (rawTrackAddress >> emtfTrAddrMe3SegShift_) & 0x1);
0076     mu.setTrackSubAddress(RegionalMuonCand::kME3Ch, (rawTrackAddress >> emtfTrAddrMe3ChShift_) & emtfTrAddrMe3ChMask_);
0077     mu.setTrackSubAddress(RegionalMuonCand::kME4Seg, (rawTrackAddress >> emtfTrAddrMe4SegShift_) & 0x1);
0078     mu.setTrackSubAddress(RegionalMuonCand::kME4Ch, (rawTrackAddress >> emtfTrAddrMe4ChShift_) & emtfTrAddrMe4ChMask_);
0079     if (useEmtfDisplacementInfo) {  // In Run-3 we receive displaced muon information from EMTF
0080       mu.setHwPtUnconstrained((raw_data_32_63 >> emtfPtUnconstrainedShift_) & ptUnconstrainedMask_);
0081       mu.setHwDXY((raw_data_32_63 >> emtfDxyShift_) & dxyMask_);
0082       mu.setTrackSubAddress(RegionalMuonCand::kTrkNum, 0);
0083       mu.setTrackSubAddress(RegionalMuonCand::kBX, 0);
0084     } else {
0085       mu.setTrackSubAddress(RegionalMuonCand::kTrkNum,
0086                             (rawTrackAddress >> emtfTrAddrTrkNumShift_) & emtfTrAddrTrkNumMask_);
0087       mu.setTrackSubAddress(RegionalMuonCand::kBX, (rawTrackAddress >> emtfTrAddrBxShift_) & emtfTrAddrBxMask_);
0088     }
0089   } else if (tf == omtf_neg || tf == omtf_pos) {
0090     mu.setTrackSubAddress(RegionalMuonCand::kLayers,
0091                           (rawTrackAddress >> omtfTrAddrLayersShift_) & omtfTrAddrLayersMask_);
0092     mu.setTrackSubAddress(RegionalMuonCand::kZero, 0);
0093     mu.setTrackSubAddress(RegionalMuonCand::kWeight,
0094                           (rawTrackAddress >> omtfTrAddrWeightShift_) & omtfTrAddrWeightMask_);
0095   } else {
0096     std::map<int, int> trackAddr;
0097     trackAddr[0] = rawTrackAddress;
0098     mu.setTrackAddress(trackAddr);
0099   }
0100 
0101   mu.setTFIdentifiers(proc, tf);
0102   mu.setDataword(raw_data_32_63, raw_data_00_31);
0103 }
0104 
0105 void l1t::RegionalMuonRawDigiTranslator::fillRegionalMuonCand(RegionalMuonCand& mu,
0106                                                               const uint64_t dataword,
0107                                                               const int proc,
0108                                                               const tftype tf,
0109                                                               const bool isKbmtf,
0110                                                               const bool useEmtfDisplacementInfo) {
0111   fillRegionalMuonCand(mu,
0112                        (uint32_t)(dataword & 0xFFFFFFFF),
0113                        (uint32_t)((dataword >> 32) & 0xFFFFFFFF),
0114                        proc,
0115                        tf,
0116                        isKbmtf,
0117                        useEmtfDisplacementInfo);
0118 }
0119 
0120 bool l1t::RegionalMuonRawDigiTranslator::fillRegionalMuonShower(
0121     RegionalMuonShower& muShower, std::vector<uint32_t> bxPayload, int proc, tftype tf, bool useEmtfShowers) {
0122   if (useEmtfShowers && (tf == emtf_pos || tf == emtf_neg)) {
0123     muShower.setTFIdentifiers(proc, tf);
0124 
0125     muShower.setOneNominalInTime(((bxPayload[emtfShowerInTimeFrame_] >> emtfShowerOneNominalShift_) & 1) == 1);
0126     muShower.setOneNominalOutOfTime(((bxPayload[emtfShowerOOTFrame_] >> emtfShowerOneNominalShift_) & 1) == 1);
0127     muShower.setOneTightInTime(((bxPayload[emtfShowerInTimeFrame_] >> emtfShowerOneTightShift_) & 1) == 1);
0128     muShower.setOneTightOutOfTime(((bxPayload[emtfShowerOOTFrame_] >> emtfShowerOneTightShift_) & 1) == 1);
0129 
0130     return muShower.isValid();
0131   } else {
0132     return false;
0133   }
0134 }
0135 
0136 void l1t::RegionalMuonRawDigiTranslator::generatePackedShowerPayload(const RegionalMuonShower& shower,
0137                                                                      std::array<uint32_t, 6>& payload,
0138                                                                      const bool useEmtfShowers) {
0139   if (!useEmtfShowers || !shower.isValid()) {
0140     return;
0141   }
0142   // First we check whether we're going to overwrite something in the payload.
0143   if ((((payload.at(emtfShowerInTimeFrame_) >> emtfShowerOneNominalShift_) & emtfShowerMask_) != 0) ||
0144       (((payload.at(emtfShowerInTimeFrame_) >> emtfShowerOneTightShift_) & emtfShowerMask_) != 0) ||
0145       (((payload.at(emtfShowerOOTFrame_) >> emtfShowerOneNominalShift_) & emtfShowerMask_) != 0) ||
0146       (((payload.at(emtfShowerOOTFrame_) >> emtfShowerOneTightShift_) & emtfShowerMask_) != 0)) {
0147     edm::LogError("L1T") << "Check constants for RegionalMuonShower fields! It looks like we're in danger of "
0148                             "overwriting muon data in the packer! InTimeFrame is "
0149                          << payload.at(emtfShowerInTimeFrame_) << ", OOTFrame is " << payload.at(emtfShowerOOTFrame_);
0150     return;
0151   }
0152   payload.at(emtfShowerInTimeFrame_) |= (shower.isOneNominalInTime() & 1) << emtfShowerOneNominalShift_ |
0153                                         (shower.isOneTightInTime() & 1) << emtfShowerOneTightShift_;
0154   payload.at(emtfShowerOOTFrame_) |= (shower.isOneNominalOutOfTime() & 1) << emtfShowerOneNominalShift_ |
0155                                      (shower.isOneTightOutOfTime() & 1) << emtfShowerOneTightShift_;
0156 }
0157 
0158 void l1t::RegionalMuonRawDigiTranslator::generatePackedDataWords(const RegionalMuonCand& mu,
0159                                                                  uint32_t& raw_data_00_31,
0160                                                                  uint32_t& raw_data_32_63,
0161                                                                  const bool isKbmtf,
0162                                                                  const bool useEmtfDisplacementInfo) {
0163   int abs_eta = mu.hwEta();
0164   if (abs_eta < 0) {
0165     abs_eta += (1 << (etaSignShift_ - absEtaShift_));
0166   }
0167   int abs_phi = mu.hwPhi();
0168   if (abs_phi < 0) {
0169     abs_phi += (1 << (phiSignShift_ - absPhiShift_));
0170   }
0171   raw_data_00_31 = (mu.hwPt() & ptMask_) << ptShift_ | (mu.hwQual() & qualMask_) << qualShift_ |
0172                    (abs_eta & absEtaMask_) << absEtaShift_ | (mu.hwEta() < 0) << etaSignShift_ |
0173                    (mu.hwHF() & hfMask_) << hfShift_ | (abs_phi & absPhiMask_) << absPhiShift_ |
0174                    (mu.hwPhi() < 0) << phiSignShift_;
0175 
0176   // generate the raw track address from the subaddresses
0177   int rawTrkAddr = generateRawTrkAddress(mu, isKbmtf);
0178 
0179   raw_data_32_63 = mu.hwSign() << signShift_ | mu.hwSignValid() << signValidShift_ |
0180                    (rawTrkAddr & trackAddressMask_) << trackAddressShift_;
0181   if (isKbmtf && mu.trackFinderType() == bmtf) {
0182     raw_data_32_63 |= (mu.hwPtUnconstrained() & ptUnconstrainedMask_) << bmtfPtUnconstrainedShift_ |
0183                       (mu.hwDXY() & dxyMask_) << bmtfDxyShift_;
0184   } else if (useEmtfDisplacementInfo && (mu.trackFinderType() == emtf_pos || mu.trackFinderType() == emtf_neg)) {
0185     raw_data_32_63 |= (mu.hwPtUnconstrained() & ptUnconstrainedMask_) << emtfPtUnconstrainedShift_ |
0186                       (mu.hwDXY() & dxyMask_) << emtfDxyShift_;
0187   }
0188 }
0189 
0190 uint64_t l1t::RegionalMuonRawDigiTranslator::generate64bitDataWord(const RegionalMuonCand& mu,
0191                                                                    const bool isKbmtf,
0192                                                                    const bool useEmtfDisplacementInfo) {
0193   uint32_t lsw;
0194   uint32_t msw;
0195 
0196   generatePackedDataWords(mu, lsw, msw, isKbmtf, useEmtfDisplacementInfo);
0197   return (((uint64_t)msw) << 32) + lsw;
0198 }
0199 
0200 int l1t::RegionalMuonRawDigiTranslator::generateRawTrkAddress(const RegionalMuonCand& mu, const bool isKalman) {
0201   int tf = mu.trackFinderType();
0202   int rawTrkAddr = 0;
0203   if (tf == bmtf) {
0204     // protection against a track address map with the wrong size
0205     if (mu.trackAddress().size() == RegionalMuonCand::kNumBmtfSubAddr) {
0206       int detSide = mu.trackSubAddress(RegionalMuonCand::kWheelSide);
0207       int wheelNum = mu.trackSubAddress(RegionalMuonCand::kWheelNum);
0208       int stat1 = mu.trackSubAddress(RegionalMuonCand::kStat1);
0209       int stat2 = mu.trackSubAddress(RegionalMuonCand::kStat2);
0210       int stat3 = mu.trackSubAddress(RegionalMuonCand::kStat3);
0211       int stat4 = mu.trackSubAddress(RegionalMuonCand::kStat4);
0212       if (isKalman) {
0213         stat1 = mu.trackSubAddress(RegionalMuonCand::kStat4);
0214         stat2 = mu.trackSubAddress(RegionalMuonCand::kStat3);
0215         stat3 = mu.trackSubAddress(RegionalMuonCand::kStat2);
0216         stat4 = mu.trackSubAddress(RegionalMuonCand::kStat1);
0217       }
0218 
0219       rawTrkAddr = (detSide & 0x1) << bmtfTrAddrDetSideShift_ |
0220                    (wheelNum & bmtfTrAddrWheelMask_) << bmtfTrAddrWheelShift_ |
0221                    (stat1 & bmtfTrAddrStat1Mask_) << bmtfTrAddrStat1Shift_ |
0222                    (stat2 & bmtfTrAddrStat2Mask_) << bmtfTrAddrStat2Shift_ |
0223                    (stat3 & bmtfTrAddrStat3Mask_) << bmtfTrAddrStat3Shift_ |
0224                    (stat4 & bmtfTrAddrStat4Mask_) << bmtfTrAddrStat4Shift_;
0225     } else {
0226       edm::LogWarning("L1T") << "BMTF muon track address map contains " << mu.trackAddress().size()
0227                              << " instead of the expected " << RegionalMuonCand::kNumBmtfSubAddr
0228                              << " subaddresses. Check the data format. Setting track address to 0.";
0229       rawTrkAddr = 0;
0230     }
0231   } else if (tf == emtf_neg || tf == emtf_pos) {
0232     // protection against a track address map with the wrong size
0233     if (mu.trackAddress().size() == RegionalMuonCand::kNumEmtfSubAddr) {
0234       rawTrkAddr = (mu.trackSubAddress(RegionalMuonCand::kME1Seg) & 0x1) << emtfTrAddrMe1SegShift_ |
0235                    (mu.trackSubAddress(RegionalMuonCand::kME1Ch) & emtfTrAddrMe1ChMask_) << emtfTrAddrMe1ChShift_ |
0236                    (mu.trackSubAddress(RegionalMuonCand::kME2Seg) & 0x1) << emtfTrAddrMe2SegShift_ |
0237                    (mu.trackSubAddress(RegionalMuonCand::kME2Ch) & emtfTrAddrMe2ChMask_) << emtfTrAddrMe2ChShift_ |
0238                    (mu.trackSubAddress(RegionalMuonCand::kME3Seg) & 0x1) << emtfTrAddrMe3SegShift_ |
0239                    (mu.trackSubAddress(RegionalMuonCand::kME3Ch) & emtfTrAddrMe3ChMask_) << emtfTrAddrMe3ChShift_ |
0240                    (mu.trackSubAddress(RegionalMuonCand::kME4Seg) & 0x1) << emtfTrAddrMe4SegShift_ |
0241                    (mu.trackSubAddress(RegionalMuonCand::kME4Ch) & emtfTrAddrMe4ChMask_) << emtfTrAddrMe4ChShift_;
0242 
0243     } else {
0244       edm::LogWarning("L1T") << "EMTF muon track address map contains " << mu.trackAddress().size()
0245                              << " instead of the expected " << RegionalMuonCand::kNumEmtfSubAddr
0246                              << " subaddresses. Check the data format. Setting track address to 0.";
0247       rawTrkAddr = 0;
0248     }
0249   } else if (tf == omtf_neg || tf == omtf_pos) {
0250     // protection against a track address map with the wrong size
0251     if (mu.trackAddress().size() == RegionalMuonCand::kNumOmtfSubAddr) {
0252       rawTrkAddr = (mu.trackSubAddress(RegionalMuonCand::kLayers) & omtfTrAddrLayersMask_) << omtfTrAddrLayersShift_ |
0253                    (mu.trackSubAddress(RegionalMuonCand::kWeight) & omtfTrAddrWeightMask_) << omtfTrAddrWeightShift_;
0254 
0255     } else {
0256       edm::LogWarning("L1T") << "OMTF muon track address map contains " << mu.trackAddress().size()
0257                              << " instead of the expected " << RegionalMuonCand::kNumOmtfSubAddr
0258                              << " subaddresses. Check the data format. Setting track address to 0.";
0259       rawTrkAddr = 0;
0260     }
0261   } else {
0262     rawTrkAddr = mu.trackAddress().at(0);
0263   }
0264 
0265   return rawTrkAddr;
0266 }