Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:07:17

0001 #include "DQM/EcalMonitorClient/interface/SummaryClient.h"
0002 
0003 #include "DQM/EcalCommon/interface/EcalDQMCommonUtils.h"
0004 
0005 #include "CondFormats/EcalObjects/interface/EcalDQMStatusHelper.h"
0006 
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 
0009 #include <algorithm>
0010 
0011 namespace ecaldqm {
0012   SummaryClient::SummaryClient() : DQWorkerClient(), towerBadFraction_(0.), fedBadFraction_(0.) {
0013     qualitySummaries_.insert("QualitySummary");
0014     qualitySummaries_.insert("ReportSummaryMap");
0015     qualitySummaries_.insert("ReportSummaryContents");
0016     qualitySummaries_.insert("ReportSummary");
0017   }
0018 
0019   void SummaryClient::setParams(edm::ParameterSet const& _params) {
0020     towerBadFraction_ = _params.getUntrackedParameter<double>("towerBadFraction");
0021     fedBadFraction_ = _params.getUntrackedParameter<double>("fedBadFraction");
0022 
0023     std::vector<std::string> sourceList(_params.getUntrackedParameter<std::vector<std::string> >("activeSources"));
0024     if (std::find(sourceList.begin(), sourceList.end(), "Presample") == sourceList.end())
0025       sources_.erase(std::string("Presample"));
0026     if (std::find(sourceList.begin(), sourceList.end(), "Timing") == sourceList.end())
0027       sources_.erase(std::string("Timing"));
0028     if (std::find(sourceList.begin(), sourceList.end(), "TriggerPrimitives") == sourceList.end())
0029       sources_.erase(std::string("TriggerPrimitives"));
0030     if (std::find(sourceList.begin(), sourceList.end(), "HotCell") == sourceList.end())
0031       sources_.erase(std::string("HotCell"));
0032   }
0033 
0034   void SummaryClient::resetMEs() {
0035     DQWorkerClient::resetMEs();
0036 
0037     MESet& meReportSummaryContents(MEs_.at("ReportSummaryContents"));
0038     MESet& meReportSummary(MEs_.at("ReportSummary"));
0039     MESet& meReportSummaryMap(MEs_.at("ReportSummaryMap"));
0040 
0041     for (unsigned iDCC(0); iDCC < nDCC; ++iDCC) {
0042       int dccid(iDCC + 1);
0043       meReportSummaryContents.fill(getEcalDQMSetupObjects(), dccid, -1.);
0044     }
0045 
0046     meReportSummary.fill(getEcalDQMSetupObjects(), -1.);
0047 
0048     meReportSummaryMap.reset(GetElectronicsMap(), -1.);
0049   }
0050 
0051   void SummaryClient::producePlots(ProcessType _pType) {
0052     MESet& meReportSummaryContents(MEs_.at("ReportSummaryContents"));
0053     MESet& meReportSummary(MEs_.at("ReportSummary"));
0054 
0055     for (unsigned iDCC(0); iDCC < nDCC; ++iDCC) {
0056       int dccid(iDCC + 1);
0057       meReportSummaryContents.fill(getEcalDQMSetupObjects(), dccid, -1.);
0058     }
0059     meReportSummary.fill(getEcalDQMSetupObjects(), -1.);
0060 
0061     MESet const& sIntegrityByLumi(sources_.at("IntegrityByLumi"));
0062     MESet const& sDesyncByLumi(sources_.at("DesyncByLumi"));
0063     MESet const& sFEByLumi(sources_.at("FEByLumi"));                          // Does NOT include FE=Disabled
0064     MESet const& sFEStatusErrMapByLumi(sources_.at("FEStatusErrMapByLumi"));  // Includes FE=Disabled
0065 
0066     double integrityByLumi[nDCC];
0067     double rawDataByLumi[nDCC];
0068     for (unsigned iDCC(0); iDCC < nDCC; ++iDCC) {
0069       integrityByLumi[iDCC] = sIntegrityByLumi.getBinContent(getEcalDQMSetupObjects(), iDCC + 1);
0070       rawDataByLumi[iDCC] = sDesyncByLumi.getBinContent(getEcalDQMSetupObjects(), iDCC + 1) +
0071                             sFEByLumi.getBinContent(getEcalDQMSetupObjects(), iDCC + 1);
0072     }
0073 
0074     MESet& meQualitySummary(MEs_.at("QualitySummary"));
0075     MESet& meReportSummaryMap(MEs_.at("ReportSummaryMap"));
0076 
0077     MESet const* sIntegrity(using_("Integrity") ? &sources_.at("Integrity") : nullptr);
0078     MESet const& sRawData(sources_.at("RawData"));
0079     MESet const* sPresample(using_("Presample") ? &sources_.at("Presample") : nullptr);
0080     MESet const* sTiming(using_("Timing") ? &sources_.at("Timing") : nullptr);
0081     MESet const* sTriggerPrimitives(using_("TriggerPrimitives") ? &sources_.at("TriggerPrimitives") : nullptr);
0082     MESet const* sHotCell(using_("HotCell") ? &sources_.at("HotCell") : nullptr);
0083 
0084     float totalChannels(0.);
0085     float totalGood(0.), totalGoodRaw(0);
0086 
0087     double dccChannels[nDCC];
0088     std::fill_n(dccChannels, nDCC, 0.);
0089     double dccGood[nDCC], dccGoodRaw[nDCC];
0090     std::fill_n(dccGood, nDCC, 0.);
0091     std::fill_n(dccGoodRaw, nDCC, 0.);
0092 
0093     std::map<uint32_t, int> badChannelsCount;
0094 
0095     // Override IntegrityByLumi check if any Desync errors present
0096     // Used to set an entire FED to BAD
0097     MESet const& sBXSRP(sources_.at("BXSRP"));
0098     MESet const& sBXTCC(sources_.at("BXTCC"));
0099     std::vector<bool> hasMismatchDCC(nDCC, false);
0100     for (unsigned iDCC(0); iDCC < nDCC; ++iDCC) {
0101       if (sBXSRP.getBinContent(getEcalDQMSetupObjects(), iDCC + 1) > 50. ||
0102           sBXTCC.getBinContent(getEcalDQMSetupObjects(), iDCC + 1) > 50.)  // "any" = 50
0103         hasMismatchDCC[iDCC] = true;
0104     }
0105 
0106     // Get RawData mask
0107     uint32_t mask(1 << EcalDQMStatusHelper::STATUS_FLAG_ERROR);
0108 
0109     MESet::iterator qEnd(meQualitySummary.end(GetElectronicsMap()));
0110     for (MESet::iterator qItr(meQualitySummary.beginChannel(GetElectronicsMap())); qItr != qEnd;
0111          qItr.toNextChannel(GetElectronicsMap())) {
0112       DetId id(qItr->getId());
0113       unsigned iDCC(dccId(id, GetElectronicsMap()) - 1);
0114 
0115       // Initialize individual Quality Summaries
0116       // NOTE: These represent quality over *cumulative* statistics
0117       int integrity(sIntegrity ? (int)sIntegrity->getBinContent(getEcalDQMSetupObjects(), id) : kUnknown);
0118       int presample(sPresample ? (int)sPresample->getBinContent(getEcalDQMSetupObjects(), id) : kUnknown);
0119       int hotcell(sHotCell ? (int)sHotCell->getBinContent(getEcalDQMSetupObjects(), id) : kUnknown);
0120       int timing(sTiming ? (int)sTiming->getBinContent(getEcalDQMSetupObjects(), id) : kUnknown);
0121       int trigprim(sTriggerPrimitives ? (int)sTriggerPrimitives->getBinContent(getEcalDQMSetupObjects(), id)
0122                                       : kUnknown);
0123       int rawdata(sRawData.getBinContent(getEcalDQMSetupObjects(), id));
0124 
0125       double rawdataLS(sFEStatusErrMapByLumi.getBinContent(getEcalDQMSetupObjects(), id));  // Includes FE=Disabled
0126 
0127       // If there are no RawData or Integrity errors in this LS, set them back to GOOD
0128       //if(integrity == kBad && integrityByLumi[iDCC] == 0.) integrity = kGood;
0129       if (integrity == kBad && integrityByLumi[iDCC] == 0. && !hasMismatchDCC[iDCC])
0130         integrity = kGood;
0131       //if(rawdata == kBad && rawDataByLumi[iDCC] == 0.) rawdata = kGood;
0132       if (rawdata == kBad && rawDataByLumi[iDCC] == 0. && rawdataLS == 0.)
0133         rawdata = kGood;
0134 
0135       // Fill Global Quality Summary
0136       int status(kGood);
0137       if (integrity == kBad || presample == kBad || timing == kBad || rawdata == kBad || trigprim == kBad ||
0138           hotcell == kBad)
0139         status = kBad;
0140       else if (integrity == kUnknown && presample == kUnknown && timing == kUnknown && rawdata == kUnknown &&
0141                trigprim == kUnknown)
0142         status = kUnknown;
0143       // Skip channels with no/low integrity statistics (based on digi occupancy)
0144       // Normally, ensures Global Quality and Report Summaries are not filled when stats are still low / channel masked / ECAL not in run
0145       // However, problematic FEDs can sometimes drop hits so check that channel is not flagged as BAD elsewhere
0146       if (status != kBad && (integrity == kUnknown || integrity == kMUnknown)) {
0147         qItr->setBinContent(integrity);
0148         if (onlineMode_)
0149           continue;
0150       }
0151       qItr->setBinContent(status);
0152 
0153       // Keep running count of good/bad channels/towers: Uses cumulative stats.
0154       if (status == kBad) {
0155         if (id.subdetId() == EcalBarrel)
0156           badChannelsCount[EBDetId(id).tower().rawId()] += 1;
0157         if (id.subdetId() == EcalEndcap)
0158           badChannelsCount[EEDetId(id).sc().rawId()] += 1;
0159       } else {
0160         dccGood[iDCC] += 1.;
0161         totalGood += 1.;
0162       }
0163       dccChannels[iDCC] += 1.;
0164       totalChannels += 1.;
0165 
0166       // Keep running count of good channels in RawData only: Uses LS stats only.
0167       // LS-based reports only use RawData as input to save on having to run other workers
0168       bool isMasked(meQualitySummary.maskMatches(id, mask, statusManager_, GetTrigTowerMap()));
0169       if (rawdataLS == 0. || isMasked) {  // channel != kBad in rawdata
0170         dccGoodRaw[iDCC] += 1.;
0171         totalGoodRaw += 1.;
0172       }
0173 
0174     }  // qItr channel loop
0175 
0176     // search clusters of bad towers
0177     /*if(onlineMode_){
0178 
0179       // EB
0180       for(int iz(-1); iz < 2; iz += 2){
0181         for(int ieta(0); ieta < 17; ++ieta){
0182           if(iz == 1 && ieta == 0) continue;
0183           for(int iphi(1); iphi <= 72; ++iphi){
0184             EcalTrigTowerDetId ttids[4];
0185             unsigned badTowers(0);
0186             for(int deta(0); deta < 2; ++deta){
0187               int ttz(ieta == 0 && deta == 0 ? -1 : iz);
0188               int tteta(ieta == 0 && deta == 0 ? 1 : ieta + deta);
0189               for(int dphi(0); dphi < 2; ++dphi){
0190                 int ttphi(iphi != 72 ? iphi + dphi : 1);
0191                 EcalTrigTowerDetId ttid(ttz, EcalBarrel, tteta, ttphi);
0192                 ttids[deta * 2 + dphi] = ttid;
0193 
0194                 if(badChannelsCount[ttid.rawId()] > towerBadFraction_ * 25.)
0195                   badTowers += 1;
0196               } // dphi
0197             } // deta
0198             if(badTowers > 2){
0199               for(unsigned iD(0); iD < 4; ++iD)
0200                 dccGood[dccId(ttids[iD]) - 1] = 0.;
0201             }
0202           } // iphi
0203         } // ieta
0204       } // iz
0205 
0206       // EE
0207       for(int iz(-1); iz <= 1; iz += 2){
0208         for(int ix(1); ix < 20; ++ix){
0209           for(int iy(1); iy < 20; ++iy){
0210             EcalScDetId scids[4];
0211             unsigned badTowers(0);
0212             for(int dx(0); dx < 2; ++dx){
0213               for(int dy(0); dy < 2; ++dy){
0214                 if(!EcalScDetId::validDetId(ix + dx, iy + dy, iz)){
0215                   scids[dx * 2 + dy] = EcalScDetId(0);
0216                   continue;
0217                 }
0218                 EcalScDetId scid(ix + dx, iy + dy, iz);
0219                 scids[dx * 2 + dy] = scid;
0220 
0221                 if(badChannelsCount[scid.rawId()] > towerBadFraction_ * scConstituents(scid).size())
0222                   badTowers += 1;
0223               } // dy
0224             } // dx
0225             // contiguous towers bad -> [(00)(11)] [(11)(00)] [(01)(01)] [(10)(10)] []=>x ()=>y
0226             if(badTowers > 2){
0227               for(unsigned iD(0); iD < 4; ++iD){
0228                 EcalScDetId& scid(scids[iD]);
0229                 if(scid.null()) continue;
0230                 dccGood[dccId(scid) - 1] = 0.;
0231               }
0232             }
0233           } // iy
0234         } // ix
0235       } // iz
0236 
0237     } // cluster search */
0238 
0239     // Fill Report Summaries
0240     double nBad(0.);
0241     for (unsigned iDCC(0); iDCC < nDCC; ++iDCC) {
0242       if (dccChannels[iDCC] < 1.)
0243         continue;
0244 
0245       int dccid(iDCC + 1);
0246       float frac(dccGood[iDCC] / dccChannels[iDCC]);
0247       float fracRaw(dccGoodRaw[iDCC] / dccChannels[iDCC]);
0248       meReportSummaryMap.setBinContent(getEcalDQMSetupObjects(), dccid, frac);
0249       float fracLS(onlineMode_ ? frac : fracRaw);
0250       meReportSummaryContents.fill(getEcalDQMSetupObjects(), dccid, fracLS);  // reported by LS
0251 
0252       if (1. - frac > fedBadFraction_)
0253         nBad += 1.;
0254     }
0255 
0256     float totalGoodLS(onlineMode_ ? totalGood : totalGoodRaw);
0257     if (totalChannels > 0.)
0258       meReportSummary.fill(getEcalDQMSetupObjects(), totalGoodLS / totalChannels);  // reported by LS
0259 
0260     if (onlineMode_) {
0261       if (totalChannels > 0.)
0262         MEs_.at("GlobalSummary").setBinContent(getEcalDQMSetupObjects(), 1, totalGood / totalChannels);
0263       MEs_.at("NBadFEDs").setBinContent(getEcalDQMSetupObjects(), 1, nBad);
0264     }
0265 
0266   }  // producePlots()
0267 
0268   DEFINE_ECALDQM_WORKER(SummaryClient);
0269 }  // namespace ecaldqm