Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:26:09

0001 #include "EventFilter/L1TRawToDigi/interface/OmtfDtPacker.h"
0002 
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include "EventFilter/L1TRawToDigi/interface/OmtfDtDataWord64.h"
0005 
0006 namespace omtf {
0007 
0008   void DtPacker::pack(const L1MuDTChambPhContainer* phCont, const L1MuDTChambThContainer* thCont, FedAmcRawsMap& raws) {
0009     const L1MuDTChambPhContainer& dtphDigisBMTF = *phCont;
0010     const L1MuDTChambThContainer& dtthDigisBMTF = *thCont;
0011     for (const auto& chDigi : *dtphDigisBMTF.getContainer()) {
0012       if (std::abs(chDigi.whNum()) != 2)
0013         continue;
0014       if (chDigi.stNum() == 4)
0015         continue;
0016       DtDataWord64 data;
0017       data.st_phi_ = chDigi.phi();
0018       data.st_phib_ = chDigi.phiB();
0019       data.st_q_ = chDigi.code();
0020       int bxNumber = chDigi.bxNum();
0021       data.bxNum_ = (3 + bxNumber);
0022       data.st_ = chDigi.stNum() - 1;
0023       data.valid_ = 1;
0024       int bxCnt = (chDigi.BxCnt() >= 0 && chDigi.BxCnt() <= 3) ? chDigi.BxCnt() : 0;
0025       data.bcnt_st_ = bxCnt;
0026       data.bcnt_e0_ = bxCnt;
0027       data.bcnt_e1_ = bxCnt;
0028       data.fiber_ = chDigi.Ts2Tag();
0029       unsigned int amc;
0030       unsigned int amc2 = 0;
0031       unsigned int fed = (chDigi.whNum() == -2) ? 1380 : 1381;
0032       if (chDigi.scNum() % 2 != 0) {
0033         amc = chDigi.scNum();
0034         data.sector_ = 1;
0035       } else {
0036         amc = chDigi.scNum() + 1;
0037         data.sector_ = 0;
0038         amc2 = (chDigi.scNum() + 11) % 12;  // in this case data.sector_ should be 2, fixed later
0039       }
0040       LogTrace("") << " fed: " << fed << " amc: " << amc << " DT PH DATA: " << data << std::endl;
0041       raws[std::make_pair(fed, amc)].push_back(data.rawData);
0042       if (amc2 != 0) {
0043         data.sector_ = 2;
0044         LogTrace("") << " fed: " << fed << " amc: " << amc2 << " DT PH DATA: " << data << std::endl;
0045         raws[std::make_pair(fed, amc2)].push_back(data.rawData);
0046       }
0047     }
0048 
0049     //
0050     //
0051     //
0052     for (const auto& chDigi : *dtthDigisBMTF.getContainer()) {
0053       if (std::abs(chDigi.whNum()) != 2)
0054         continue;
0055       if (chDigi.stNum() == 4)
0056         continue;
0057       DtDataWord64 data;
0058       int bxNumber = chDigi.bxNum();
0059       data.bxNum_ = (3 + bxNumber);
0060       data.st_ = chDigi.stNum() - 1;
0061       data.valid_ = 1;
0062       unsigned int amc;
0063       unsigned int amc2 = 0;
0064       unsigned int fed = (chDigi.whNum() == -2) ? 1380 : 1381;
0065       if (chDigi.scNum() % 2 != 0) {
0066         amc = chDigi.scNum();
0067         data.sector_ = 1;
0068       } else {
0069         amc = chDigi.scNum() + 1;
0070         data.sector_ = 0;
0071         amc2 = (chDigi.scNum() + 11) % 12;  // in this case data.sector_ should be 2, fixed later
0072       }
0073       unsigned int eta = 0;
0074       unsigned int etaQ = 0;
0075       for (unsigned int ipos = 0; ipos < 7; ipos++) {
0076         if (chDigi.position(ipos) > 1)
0077           edm::LogError("OmtfDtPacker") << "DT TH position to ETA,  PROBLEM !!!!";
0078         if (chDigi.position(ipos) == 1)
0079           eta |= (1 << ipos);
0080         if (chDigi.quality(ipos) == 1)
0081           etaQ |= (1 << ipos);
0082       }
0083       data.eta_qbit_ = etaQ;
0084       data.eta_hit_ = eta;
0085       bool foundDigi = false;
0086       for (auto& raw : raws) {
0087         if (raw.first.first != fed)
0088           continue;
0089         unsigned int amcPh = raw.first.second;
0090         if (amc != amcPh && amc2 != amcPh)
0091           continue;
0092         auto& words = raw.second;
0093         for (auto& word : words) {
0094           if (DataWord64::dt != DataWord64::type(word))
0095             continue;
0096           DtDataWord64 dataRaw(word);
0097           if (dataRaw.bxNum_ != data.bxNum_)
0098             continue;
0099           if (dataRaw.st_ != data.st_)
0100             continue;
0101           if ((amcPh == amc && dataRaw.sector_ == data.sector_) || (amcPh == amc2 && 2 == dataRaw.sector_)) {
0102             foundDigi = true;
0103             dataRaw.eta_qbit_ = data.eta_qbit_;
0104             dataRaw.eta_hit_ = data.eta_hit_;
0105             word = dataRaw.rawData;
0106             LogTrace("") << "AP fed: " << fed << " amc: " << amc << " DT TH DATA: " << dataRaw << std::endl;
0107           }
0108         }
0109       }
0110       if (!foundDigi) {
0111         LogTrace("") << "NFD fed: " << fed << " amc:  " << amc << " DT TH DATA: " << data << std::endl;
0112         raws[std::make_pair(fed, amc)].push_back(data.rawData);
0113         if (amc2 != 0) {
0114           data.sector_ = 2;
0115           LogTrace("") << "NFD fed: " << fed << " amc2: " << amc2 << " DT TH DATA: " << data << std::endl;
0116           raws[std::make_pair(fed, amc2)].push_back(data.rawData);
0117         }
0118       }
0119     }
0120   }
0121 
0122 }  // namespace omtf