Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-20 10:41:56

0001 #include "DQM/EcalMonitorTasks/interface/RawDataTask.h"
0002 
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/Framework/interface/Run.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 
0007 #include "DQM/EcalCommon/interface/EcalDQMCommonUtils.h"
0008 #include "DQM/EcalCommon/interface/FEFlags.h"
0009 
0010 #include "DataFormats/EcalDetId/interface/EcalElectronicsId.h"
0011 #include "DataFormats/Luminosity/interface/LumiConstants.h"
0012 
0013 namespace ecaldqm {
0014 
0015   RawDataTask::RawDataTask()
0016       : DQWorkerTask(), runNumber_(0), l1A_(0), orbit_(0), bx_(0), triggerType_(0), feL1Offset_(0) {}
0017 
0018   void RawDataTask::addDependencies(DependencySet& _dependencies) {
0019     _dependencies.push_back(Dependency(kEcalRawData, kSource));
0020   }
0021 
0022   void RawDataTask::beginRun(edm::Run const& _run, edm::EventSetup const&) { runNumber_ = _run.run(); }
0023 
0024   void RawDataTask::beginEvent(edm::Event const& _evt, edm::EventSetup const&, bool const& ByLumiResetSwitch, bool&) {
0025     orbit_ = _evt.orbitNumber() & 0xffffffff;
0026 
0027     bx_ = _evt.bunchCrossing() & 0xfff;
0028     // There's no agreement in CMS on how to label the last/first BX
0029     // TCDS calls it always 3564, but some subsystems call it 0.
0030     // From testing: bx_ is labeled 0, dccBX and FEBxs[iFE] labeled 3564
0031     // Setting bx_ to 0 to match the other two
0032     if (bx_ == LumiConstants::numBX)  // 3564
0033       bx_ = 0;
0034 
0035     triggerType_ = _evt.experimentType() & 0xf;
0036     l1A_ = 0;
0037     feL1Offset_ = _evt.isRealData() ? 1 : 0;
0038     if (ByLumiResetSwitch) {
0039       MEs_.at("DesyncByLumi").reset(GetElectronicsMap());
0040       MEs_.at("FEByLumi").reset(GetElectronicsMap());
0041       MEs_.at("FEStatusErrMapByLumi").reset(GetElectronicsMap());
0042     }
0043   }
0044 
0045   void RawDataTask::runOnSource(FEDRawDataCollection const& _fedRaw) {
0046     MESet& meCRC(MEs_.at("CRC"));
0047 
0048     // Get GT L1 info
0049     const FEDRawData& gtFED(_fedRaw.FEDData(812));
0050     if (gtFED.size() > sizeof(uint64_t)) {  // FED header is one 64 bit word
0051       const uint32_t* halfHeader = reinterpret_cast<const uint32_t*>(gtFED.data());
0052       l1A_ = *(halfHeader + 1) & 0xffffff;
0053     }
0054 
0055     for (int iFED(601); iFED <= 654; iFED++) {
0056       const FEDRawData& fedData(_fedRaw.FEDData(iFED));
0057       unsigned length(fedData.size() / sizeof(uint64_t));
0058       if (length > 1) {  // FED header is one 64 bit word
0059         const uint64_t* pData(reinterpret_cast<uint64_t const*>(fedData.data()));
0060         if ((pData[length - 1] & 0x4) != 0)
0061           meCRC.fill(getEcalDQMSetupObjects(), iFED - 600);
0062       }
0063     }
0064   }
0065 
0066   void RawDataTask::runOnRawData(EcalRawDataCollection const& _dcchs) {
0067     using namespace std;
0068 
0069     MESet& meRunNumber(MEs_.at("RunNumber"));
0070     MESet& meOrbit(MEs_.at("Orbit"));
0071     MESet& meOrbitDiff(MEs_.at("OrbitDiff"));
0072     MESet& meTriggerType(MEs_.at("TriggerType"));
0073     MESet& meL1ADCC(MEs_.at("L1ADCC"));
0074     MESet& meBXDCC(MEs_.at("BXDCC"));
0075     MESet& meBXDCCDiff(MEs_.at("BXDCCDiff"));
0076     MESet& meBXFE(MEs_.at("BXFE"));
0077     MESet& meBXFEDiff(MEs_.at("BXFEDiff"));
0078     MESet& meBXFEInvalid(MEs_.at("BXFEInvalid"));
0079     MESet& meL1AFE(MEs_.at("L1AFE"));
0080     MESet& meFEStatus(MEs_.at("FEStatus"));
0081     MESet& meFEStatusErrMapByLumi(MEs_.at("FEStatusErrMapByLumi"));
0082     MESet& meFEStatusMEM(MEs_.at("FEStatusMEM"));
0083     MESet& meDesyncByLumi(MEs_.at("DesyncByLumi"));
0084     MESet& meDesyncTotal(MEs_.at("DesyncTotal"));
0085     MESet& meFEByLumi(MEs_.at("FEByLumi"));
0086     MESet& meBXTCC(MEs_.at("BXTCC"));
0087     MESet& meL1ATCC(MEs_.at("L1ATCC"));
0088     MESet& meBXSRP(MEs_.at("BXSRP"));
0089     MESet& meL1ASRP(MEs_.at("L1ASRP"));
0090     MESet& meTrendNSyncErrors(MEs_.at("L1ATCC"));
0091     MESet& meEventTypePreCalib(MEs_.at("EventTypePreCalib"));
0092     MESet& meEventTypeCalib(MEs_.at("EventTypeCalib"));
0093     MESet& meEventTypePostCalib(MEs_.at("EventTypePostCalib"));
0094 
0095     if (!l1A_) {
0096       // majority vote on L1A.. is there no better implementation?
0097       map<int, int> l1aCounts;
0098       for (EcalRawDataCollection::const_iterator dcchItr(_dcchs.begin()); dcchItr != _dcchs.end(); ++dcchItr) {
0099         l1aCounts[dcchItr->getLV1()]++;
0100       }
0101       int maxVote(0);
0102       for (map<int, int>::iterator l1aItr(l1aCounts.begin()); l1aItr != l1aCounts.end(); ++l1aItr) {
0103         if (l1aItr->second > maxVote) {
0104           maxVote = l1aItr->second;
0105           l1A_ = l1aItr->first;
0106         }
0107       }
0108     }
0109 
0110     for (EcalRawDataCollection::const_iterator dcchItr(_dcchs.begin()); dcchItr != _dcchs.end(); ++dcchItr) {
0111       int dccId(dcchItr->id());
0112 
0113       int dccL1A(dcchItr->getLV1());
0114       short dccL1AShort(dccL1A & 0xfff);
0115       int dccBX(dcchItr->getBX());
0116 
0117       meOrbitDiff.fill(getEcalDQMSetupObjects(), dccId, dcchItr->getOrbit() - orbit_);
0118       meBXDCCDiff.fill(getEcalDQMSetupObjects(), dccId, dccBX - bx_);
0119       if (dccBX == -1)
0120         meBXFEInvalid.fill(getEcalDQMSetupObjects(), dccId, 68.5);
0121 
0122       if (dcchItr->getRunNumber() != int(runNumber_))
0123         meRunNumber.fill(getEcalDQMSetupObjects(), dccId);
0124       if (dcchItr->getOrbit() != orbit_)
0125         meOrbit.fill(getEcalDQMSetupObjects(), dccId);
0126       if (dcchItr->getBasicTriggerType() != triggerType_)
0127         meTriggerType.fill(getEcalDQMSetupObjects(), dccId);
0128       if (dccL1A != l1A_)
0129         meL1ADCC.fill(getEcalDQMSetupObjects(), dccId);
0130       if (dccBX != bx_)
0131         meBXDCC.fill(getEcalDQMSetupObjects(), dccId);
0132 
0133       const vector<short>& feStatus(dcchItr->getFEStatus());
0134       const vector<short>& feBxs(dcchItr->getFEBxs());
0135       const vector<short>& feL1s(dcchItr->getFELv1());
0136 
0137       double feDesync(0.);
0138       double statusError(0.);
0139 
0140       for (unsigned iFE(0); iFE < feStatus.size(); iFE++) {
0141         if (!ccuExists(dccId, iFE + 1))
0142           continue;
0143 
0144         short status(feStatus[iFE]);
0145 
0146         if (feBxs[iFE] != -1 && dccBX != -1) {
0147           meBXFEDiff.fill(getEcalDQMSetupObjects(), dccId, feBxs[iFE] - dccBX);
0148         }
0149         if (feBxs[iFE] == -1)
0150           meBXFEInvalid.fill(getEcalDQMSetupObjects(), dccId, iFE + 0.5);
0151 
0152         if (status != BXDesync && status != L1ABXDesync) {  // BX desync not detected in the DCC
0153           if (feBxs[iFE] != dccBX && feBxs[iFE] != -1 && dccBX != -1) {
0154             meBXFE.fill(getEcalDQMSetupObjects(), dccId, iFE + 0.5);
0155             feDesync += 1.;
0156           }
0157         }
0158 
0159         if (status != L1ADesync && status != L1ABXDesync) {
0160           if (feL1s[iFE] + feL1Offset_ != dccL1AShort && feL1s[iFE] != -1 && dccL1AShort != 0) {
0161             meL1AFE.fill(getEcalDQMSetupObjects(), dccId, iFE + 0.5);
0162             feDesync += 1.;
0163           }
0164         }
0165 
0166         if (iFE >= 68) {
0167           // FE Status for MEM boxes (towerIds 69 and 70)
0168           // Plot contains two bins per dccId. Integer number
0169           // bins correspond to towerId 69 and half integer
0170           // number bins correspond to towerId 70.
0171           if (iFE + 1 == 69)
0172             meFEStatusMEM.fill(getEcalDQMSetupObjects(), dccId + 0.0, status);
0173           else if (iFE + 1 == 70)
0174             meFEStatusMEM.fill(getEcalDQMSetupObjects(), dccId + 0.5, status);
0175           continue;
0176         }
0177 
0178         DetId id(GetElectronicsMap()->dccTowerConstituents(dccId, iFE + 1).at(0));
0179         meFEStatus.fill(getEcalDQMSetupObjects(), id, status);
0180         // Fill FE Status Error Map with error states only
0181         if (status != Enabled && status != Suppressed && status != FIFOFull && status != FIFOFullL1ADesync &&
0182             status != ForcedZS)
0183           meFEStatusErrMapByLumi.fill(getEcalDQMSetupObjects(), id, status);
0184 
0185         switch (status) {
0186           case Timeout:
0187           case HeaderError:
0188           case ChannelId:
0189           case LinkError:
0190           case BlockSize:
0191           case L1ADesync:
0192           case BXDesync:
0193           case L1ABXDesync:
0194           case HParity:
0195           case VParity:
0196             statusError += 1.;
0197             break;
0198           default:
0199             continue;
0200         }
0201       }
0202 
0203       if (feDesync > 0.) {
0204         meDesyncByLumi.fill(getEcalDQMSetupObjects(), dccId, feDesync);
0205         meDesyncTotal.fill(getEcalDQMSetupObjects(), dccId, feDesync);
0206         meTrendNSyncErrors.fill(getEcalDQMSetupObjects(), double(timestamp_.iLumi), feDesync);
0207       }
0208       if (statusError > 0.)
0209         meFEByLumi.fill(getEcalDQMSetupObjects(), dccId, statusError);
0210 
0211       const vector<short>& tccBx(dcchItr->getTCCBx());
0212       const vector<short>& tccL1(dcchItr->getTCCLv1());
0213 
0214       if (tccBx.size() == 4) {  // EB uses tccBx[0]; EE uses all
0215         if (dccId <= kEEmHigh + 1 || dccId >= kEEpLow + 1) {
0216           for (int iTCC(0); iTCC < 4; iTCC++) {
0217             if (tccBx[iTCC] != dccBX && tccBx[iTCC] != -1 && dccBX != -1)
0218               meBXTCC.fill(getEcalDQMSetupObjects(), dccId);
0219 
0220             if (tccL1[iTCC] != dccL1AShort && tccL1[iTCC] != -1 && dccL1AShort != 0)
0221               meL1ATCC.fill(getEcalDQMSetupObjects(), dccId);
0222           }
0223         } else {
0224           if (tccBx[0] != dccBX && tccBx[0] != -1 && dccBX != -1)
0225             meBXTCC.fill(getEcalDQMSetupObjects(), dccId);
0226 
0227           if (tccL1[0] != dccL1AShort && tccL1[0] != -1 && dccL1AShort != 0)
0228             meL1ATCC.fill(getEcalDQMSetupObjects(), dccId);
0229         }
0230       }
0231 
0232       short srpBx(dcchItr->getSRPBx());
0233       short srpL1(dcchItr->getSRPLv1());
0234 
0235       if (srpBx != dccBX && srpBx != -1 && dccBX != -1)
0236         meBXSRP.fill(getEcalDQMSetupObjects(), dccId);
0237 
0238       if (srpL1 != dccL1AShort && srpL1 != -1 && dccL1AShort != 0)
0239         meL1ASRP.fill(getEcalDQMSetupObjects(), dccId);
0240 
0241       const int calibBX(3490);
0242 
0243       short runType(dcchItr->getRunType() + 1);
0244       if (runType < 0 || runType > 22)
0245         runType = 0;
0246       if (dccBX < calibBX)
0247         meEventTypePreCalib.fill(getEcalDQMSetupObjects(), dccId, runType, 1. / 54.);
0248       else if (dccBX == calibBX)
0249         meEventTypeCalib.fill(getEcalDQMSetupObjects(), dccId, runType, 1. / 54.);
0250       else
0251         meEventTypePostCalib.fill(getEcalDQMSetupObjects(), dccId, runType, 1. / 54.);
0252     }
0253   }
0254 
0255   DEFINE_ECALDQM_WORKER(RawDataTask);
0256 }  // namespace ecaldqm