Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-03-17 23:26:23

0001 #include "DQM/EcalMonitorClient/interface/TrigPrimClient.h"
0002 
0003 #include "DQM/EcalCommon/interface/EcalDQMCommonUtils.h"
0004 #include "DQM/EcalCommon/interface/MESetNonObject.h"
0005 
0006 #include "CondFormats/EcalObjects/interface/EcalDQMStatusHelper.h"
0007 
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 
0010 #include <cmath>
0011 
0012 namespace ecaldqm {
0013   TrigPrimClient::TrigPrimClient()
0014       : DQWorkerClient(), minEntries_(0), errorFractionThreshold_(0.), TTF4MaskingAlarmThreshold_(0.) {
0015     qualitySummaries_.insert("EmulQualitySummary");
0016   }
0017 
0018   void TrigPrimClient::setParams(edm::ParameterSet const& _params) {
0019     minEntries_ = _params.getUntrackedParameter<int>("minEntries");
0020     errorFractionThreshold_ = _params.getUntrackedParameter<double>("errorFractionThreshold");
0021     TTF4MaskingAlarmThreshold_ = _params.getUntrackedParameter<double>("TTF4MaskingAlarmThreshold");
0022     sourceFromEmul_ = _params.getUntrackedParameter<bool>("sourceFromEmul");
0023     if (!sourceFromEmul_) {
0024       MEs_.erase(std::string("NonSingleSummary"));
0025       MEs_.erase(std::string("TimingSummary"));
0026       sources_.erase(std::string("EtEmulError"));
0027       sources_.erase(std::string("MatchedIndex"));
0028     }
0029   }
0030 
0031   void TrigPrimClient::producePlots(ProcessType) {
0032     MESet* meNonSingleSummary = nullptr;
0033     MESet* meTimingSummary = nullptr;
0034     MESet* sEtEmulError = nullptr;
0035     MESet* sMatchedIndex = nullptr;
0036 
0037     MESet& meEmulQualitySummary(MEs_.at("EmulQualitySummary"));
0038     MESet& meTrendTTF4Flags(MEs_.at("TrendTTF4Flags"));
0039 
0040     MESet const& sTPDigiThrAll(sources_.at("TPDigiThrAll"));
0041     MESetNonObject const& sLHCStatusByLumi(static_cast<MESetNonObject&>(sources_.at("LHCStatusByLumi")));
0042 
0043     uint32_t mask(1 << EcalDQMStatusHelper::PHYSICS_BAD_CHANNEL_WARNING);
0044 
0045     // Store # of entries for Occupancy analysis
0046     std::vector<float> Nentries(nDCC, 0.);
0047 
0048     double currentLHCStatus = sLHCStatusByLumi.getFloatValue();
0049     bool statsCheckEnabled =
0050         ((currentLHCStatus > 10.5 && currentLHCStatus < 11.5) ||
0051          currentLHCStatus < 0);  // currentLHCStatus = -1 is the default when no beam info is available
0052 
0053     for (unsigned iTT(0); iTT < EcalTrigTowerDetId::kSizeForDenseIndexing; iTT++) {
0054       EcalTrigTowerDetId ttid(EcalTrigTowerDetId::detIdFromDenseIndex(iTT));
0055 
0056       bool doMask(meEmulQualitySummary.maskMatches(ttid, mask, statusManager_, GetTrigTowerMap()));
0057 
0058       if (sourceFromEmul_) {
0059         sEtEmulError = &sources_.at("EtEmulError");
0060         sMatchedIndex = &sources_.at("MatchedIndex");
0061         meNonSingleSummary = &MEs_.at("NonSingleSummary");
0062         meTimingSummary = &MEs_.at("TimingSummary");
0063         float towerEntries(0.);
0064         float tMax(0.5);
0065         float nMax(0.);
0066         for (int iBin(0); iBin < 6; iBin++) {
0067           float entries(sMatchedIndex->getBinContent(getEcalDQMSetupObjects(), ttid, iBin + 1));
0068           towerEntries += entries;
0069 
0070           if (entries > nMax) {
0071             nMax = entries;
0072             tMax = iBin == 0 ? -0.5 : iBin + 0.5;  // historical reasons.. much clearer to say "no entry = -0.5"
0073           }
0074         }
0075         meTimingSummary->setBinContent(getEcalDQMSetupObjects(), ttid, tMax);
0076         if (towerEntries < minEntries_) {
0077           meEmulQualitySummary.setBinContent(getEcalDQMSetupObjects(), ttid, doMask ? kMUnknown : kUnknown);
0078           continue;
0079         }
0080 
0081         float nonsingleFraction(1. - nMax / towerEntries);
0082 
0083         if (nonsingleFraction > 0.) {
0084           meNonSingleSummary->setBinContent(getEcalDQMSetupObjects(), ttid, nonsingleFraction);
0085         }
0086 
0087         if (sEtEmulError->getBinContent(getEcalDQMSetupObjects(), ttid) / towerEntries > errorFractionThreshold_) {
0088           meEmulQualitySummary.setBinContent(getEcalDQMSetupObjects(), ttid, doMask ? kMBad : kBad);
0089         } else {
0090           meEmulQualitySummary.setBinContent(getEcalDQMSetupObjects(), ttid, doMask ? kMGood : kGood);
0091         }
0092       }
0093 
0094       // Keep count for Occupancy analysis
0095       unsigned iDCC(dccId(ttid, GetElectronicsMap()) - 1);
0096       Nentries[iDCC] += sTPDigiThrAll.getBinContent(getEcalDQMSetupObjects(), ttid);
0097     }
0098 
0099     // Fill TTF4 v Masking ME
0100     // NOT an occupancy plot: only tells you if non-zero TTF4 occupancy was seen
0101     // without giving info about how many were seen
0102     MESet& meTTF4vMask(MEs_.at("TTF4vMask"));
0103     MESet& meTTF4vMaskByLumi(MEs_.at("TTF4vMaskByLumi"));
0104     MESet const& sTTFlags4(sources_.at("TTFlags4"));
0105     MESet const& sTTFlags4ByLumi(sources_.at("TTFlags4ByLumi"));
0106     MESet const& sTTMaskMapAll(sources_.at("TTMaskMapAll"));
0107 
0108     std::vector<float> nWithTTF4(nDCC,
0109                                  0.);  // counters to keep track of number of towers in a DCC that have TTF4 flag set
0110     int nWithTTF4_EE = 0;              // total number of towers in EE with TTF4
0111     int nWithTTF4_EB = 0;              // total number of towers in EB with TTF4
0112     // Loop over all TTs
0113     for (unsigned iTT(0); iTT < EcalTrigTowerDetId::kSizeForDenseIndexing; iTT++) {
0114       EcalTrigTowerDetId ttid(EcalTrigTowerDetId::detIdFromDenseIndex(iTT));
0115       unsigned iDCC(dccId(ttid, GetElectronicsMap()) - 1);
0116       bool isMasked(sTTMaskMapAll.getBinContent(getEcalDQMSetupObjects(), ttid) > 0.);
0117       bool hasTTF4(sTTFlags4.getBinContent(getEcalDQMSetupObjects(), ttid) > 0.);
0118       bool hasTTF4InThisLumiSection(sTTFlags4ByLumi.getBinContent(getEcalDQMSetupObjects(), ttid) > 0.);
0119       if (hasTTF4InThisLumiSection) {
0120         nWithTTF4[iDCC]++;
0121         if (ttid.subDet() == EcalBarrel)
0122           nWithTTF4_EB++;
0123         else if (ttid.subDet() == EcalEndcap)
0124           nWithTTF4_EE++;
0125       }
0126       if (isMasked) {
0127         if (hasTTF4) {
0128           meTTF4vMask.setBinContent(getEcalDQMSetupObjects(), ttid, 12);  // Masked, has TTF4
0129         } else {
0130           meTTF4vMask.setBinContent(getEcalDQMSetupObjects(), ttid, 11);  // Masked, no TTF4
0131         }
0132         if (hasTTF4InThisLumiSection) {
0133           meTTF4vMaskByLumi.setBinContent(getEcalDQMSetupObjects(), ttid, 12);  // Masked, has TTF4
0134         } else {
0135           meTTF4vMaskByLumi.setBinContent(getEcalDQMSetupObjects(), ttid, 11);  // Masked, no TTF4
0136         }
0137       } else {
0138         if (hasTTF4)
0139           meTTF4vMask.setBinContent(getEcalDQMSetupObjects(), ttid, 13);  // not Masked, has TTF4
0140         if (hasTTF4InThisLumiSection)
0141           meTTF4vMaskByLumi.setBinContent(getEcalDQMSetupObjects(), ttid, 13);  // not Masked, has TTF4
0142       }
0143     }  // TT loop
0144 
0145     // Fill trend plots for number of TTs with TTF4 flag set
0146     meTrendTTF4Flags.fill(getEcalDQMSetupObjects(), EcalBarrel, double(timestamp_.iLumi), nWithTTF4_EB);
0147     meTrendTTF4Flags.fill(getEcalDQMSetupObjects(), EcalEndcap, double(timestamp_.iLumi), nWithTTF4_EE);
0148 
0149     // Quality check: set an entire FED to BAD if a more than 80% of the TTs in that FED show any DCC-SRP flag mismatch errors
0150     // Fill flag mismatch statistics
0151     std::vector<float> nTTs(nDCC, 0.);
0152     std::vector<float> nTTFMismath(nDCC, 0.);
0153     MESet const& sTTFMismatch(sources_.at("TTFMismatch"));
0154     for (unsigned iTT(0); iTT < EcalTrigTowerDetId::kSizeForDenseIndexing; iTT++) {
0155       EcalTrigTowerDetId ttid(EcalTrigTowerDetId::detIdFromDenseIndex(iTT));
0156       unsigned iDCC(dccId(ttid, GetElectronicsMap()) - 1);
0157       if (sTTFMismatch.getBinContent(getEcalDQMSetupObjects(), ttid) > 0.)
0158         nTTFMismath[iDCC]++;
0159       nTTs[iDCC]++;
0160     }
0161     // Analyze flag mismatch statistics and TTF4 fraction statistics
0162     for (unsigned iTT(0); iTT < EcalTrigTowerDetId::kSizeForDenseIndexing; iTT++) {
0163       EcalTrigTowerDetId ttid(EcalTrigTowerDetId::detIdFromDenseIndex(iTT));
0164       unsigned iDCC(dccId(ttid, GetElectronicsMap()) - 1);
0165       if (nTTFMismath[iDCC] > 0.8 * nTTs[iDCC] || nWithTTF4[iDCC] > TTF4MaskingAlarmThreshold_ * nTTs[iDCC]) {
0166         meEmulQualitySummary.setBinContent(
0167             getEcalDQMSetupObjects(),
0168             ttid,
0169             meEmulQualitySummary.maskMatches(ttid, mask, statusManager_, GetTrigTowerMap()) ? kMBad : kBad);
0170       }
0171     }
0172 
0173     // Quality check: set entire FED to BAD if its occupancy begins to vanish
0174     // Fill FED statistics from TP digi occupancy
0175     float meanFEDEB(0.), meanFEDEE(0.), rmsFEDEB(0.), rmsFEDEE(0.);
0176     unsigned int nFEDEB(0), nFEDEE(0);
0177     for (unsigned iDCC(0); iDCC < nDCC; iDCC++) {
0178       if (iDCC >= kEBmLow && iDCC <= kEBpHigh) {
0179         meanFEDEB += Nentries[iDCC];
0180         rmsFEDEB += Nentries[iDCC] * Nentries[iDCC];
0181         nFEDEB++;
0182       } else {
0183         meanFEDEE += Nentries[iDCC];
0184         rmsFEDEE += Nentries[iDCC] * Nentries[iDCC];
0185         nFEDEE++;
0186       }
0187     }
0188     meanFEDEB /= float(nFEDEB);
0189     rmsFEDEB /= float(nFEDEB);
0190     meanFEDEE /= float(nFEDEE);
0191     rmsFEDEE /= float(nFEDEE);
0192     rmsFEDEB = sqrt(std::abs(rmsFEDEB - meanFEDEB * meanFEDEB));
0193     rmsFEDEE = sqrt(std::abs(rmsFEDEE - meanFEDEE * meanFEDEE));
0194     // Analyze FED statistics
0195     float meanFED(0.), rmsFED(0.), nRMS(5.);
0196     for (unsigned iTT(0); iTT < EcalTrigTowerDetId::kSizeForDenseIndexing; iTT++) {
0197       EcalTrigTowerDetId ttid(EcalTrigTowerDetId::detIdFromDenseIndex(iTT));
0198       unsigned iDCC(dccId(ttid, GetElectronicsMap()) - 1);
0199       if (iDCC >= kEBmLow && iDCC <= kEBpHigh) {
0200         meanFED = meanFEDEB;
0201         rmsFED = rmsFEDEB;
0202       } else {
0203         meanFED = meanFEDEE;
0204         rmsFED = rmsFEDEE;
0205       }
0206       float threshold(meanFED < nRMS * rmsFED ? minEntries_ : meanFED - nRMS * rmsFED);
0207       if ((meanFED > 100. && Nentries[iDCC] < threshold) && statsCheckEnabled)
0208         meEmulQualitySummary.setBinContent(
0209             getEcalDQMSetupObjects(),
0210             ttid,
0211             meEmulQualitySummary.maskMatches(ttid, mask, statusManager_, GetTrigTowerMap()) ? kMBad : kBad);
0212     }
0213 
0214   }  // producePlots()
0215 
0216   DEFINE_ECALDQM_WORKER(TrigPrimClient);
0217 }  // namespace ecaldqm