Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DQM/EcalMonitorClient/interface/TimingClient.h"
0002 
0003 #include "DQM/EcalCommon/interface/EcalDQMCommonUtils.h"
0004 
0005 #include "CondFormats/EcalObjects/interface/EcalDQMStatusHelper.h"
0006 #include "CondFormats/EcalObjects/interface/EcalChannelStatusCode.h"
0007 
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 
0010 #include <cmath>
0011 
0012 namespace ecaldqm {
0013   TimingClient::TimingClient()
0014       : DQWorkerClient(),
0015         toleranceMean_(0.),
0016         toleranceMeanFwd_(0.),
0017         toleranceRMS_(0.),
0018         toleranceRMSFwd_(0.),
0019         minChannelEntries_(0),
0020         minChannelEntriesFwd_(0),
0021         minTowerEntries_(0),
0022         minTowerEntriesFwd_(0),
0023         tailPopulThreshold_(0.) {
0024     qualitySummaries_.insert("Quality");
0025     qualitySummaries_.insert("QualitySummary");
0026   }
0027 
0028   void TimingClient::setParams(edm::ParameterSet const& _params) {
0029     toleranceMean_ = _params.getUntrackedParameter<double>("toleranceMean");
0030     toleranceMeanFwd_ = _params.getUntrackedParameter<double>("toleranceMeanFwd");
0031     toleranceRMS_ = _params.getUntrackedParameter<double>("toleranceRMS");
0032     toleranceRMSFwd_ = _params.getUntrackedParameter<double>("toleranceRMSFwd");
0033     minChannelEntries_ = _params.getUntrackedParameter<int>("minChannelEntries");
0034     minChannelEntriesFwd_ = _params.getUntrackedParameter<int>("minChannelEntriesFwd");
0035     minTowerEntries_ = _params.getUntrackedParameter<int>("minTowerEntries");
0036     minTowerEntriesFwd_ = _params.getUntrackedParameter<int>("minChannelEntriesFwd");
0037     tailPopulThreshold_ = _params.getUntrackedParameter<double>("tailPopulThreshold");
0038   }
0039 
0040   void TimingClient::producePlots(ProcessType) {
0041     MESet& meQuality(MEs_.at("Quality"));
0042     MESet& meMeanSM(MEs_.at("MeanSM"));
0043     MESet& meMeanAll(MEs_.at("MeanAll"));
0044     MESet& meFwdBkwdDiff(MEs_.at("FwdBkwdDiff"));
0045     MESet& meFwdvBkwd(MEs_.at("FwdvBkwd"));
0046     MESet& meRMSMap(MEs_.at("RMSMap"));
0047     MESet& meRMSAll(MEs_.at("RMSAll"));
0048     MESet& meProjEta(MEs_.at("ProjEta"));
0049     MESet& meProjPhi(MEs_.at("ProjPhi"));
0050     MESet& meQualitySummary(MEs_.at("QualitySummary"));
0051 
0052     MESet const& sTimeAllMap(sources_.at("TimeAllMap"));
0053     MESet const& sTimeMap(sources_.at("TimeMap"));
0054     MESet const& sTimeMapByLS(sources_.at("TimeMapByLS"));
0055     MESet const& sChStatus(sources_.at("ChStatus"));
0056 
0057     uint32_t mask(1 << EcalDQMStatusHelper::PHYSICS_BAD_CHANNEL_WARNING);
0058 
0059     MESet::iterator qEnd(meQuality.end(GetElectronicsMap()));
0060 
0061     MESet::iterator rItr(GetElectronicsMap(), meRMSMap);
0062     MESet::const_iterator tItr(GetElectronicsMap(), sTimeMap);
0063     MESet::const_iterator tLSItr(GetElectronicsMap(), sTimeMapByLS);
0064 
0065     float EBentries(0.), EEentries(0.);
0066     float EBmean(0.), EEmean(0.);
0067     float EBrms(0.), EErms(0.);
0068     for (MESet::iterator qItr(meQuality.beginChannel(GetElectronicsMap())); qItr != qEnd;
0069          qItr.toNextChannel(GetElectronicsMap())) {
0070       tItr = qItr;
0071       rItr = qItr;
0072 
0073       DetId id(qItr->getId());
0074 
0075       int minChannelEntries(minChannelEntries_);
0076       float meanThresh(toleranceMean_);
0077       float rmsThresh(toleranceRMS_);
0078 
0079       if (isForward(id)) {
0080         minChannelEntries = minChannelEntriesFwd_;
0081         meanThresh = toleranceMeanFwd_;
0082         rmsThresh = toleranceRMSFwd_;
0083       }
0084 
0085       bool doMask(meQuality.maskMatches(id, mask, statusManager_, GetTrigTowerMap()));
0086 
0087       float entries(tItr->getBinEntries());
0088 
0089       if (entries < minChannelEntries) {
0090         qItr->setBinContent(doMask ? kMUnknown : kUnknown);
0091         rItr->setBinContent(-1.);
0092         continue;
0093       }
0094 
0095       float mean(tItr->getBinContent());
0096       float rms(tItr->getBinError() * sqrt(entries));
0097 
0098       meMeanSM.fill(getEcalDQMSetupObjects(), id, mean);
0099       meMeanAll.fill(getEcalDQMSetupObjects(), id, mean);
0100       meProjEta.fill(getEcalDQMSetupObjects(), id, mean);
0101       meProjPhi.fill(getEcalDQMSetupObjects(), id, mean);
0102       meRMSAll.fill(getEcalDQMSetupObjects(), id, rms);
0103       rItr->setBinContent(rms);
0104 
0105       bool negative(false);
0106       float posTime(0.);
0107 
0108       if (id.subdetId() == EcalBarrel) {
0109         EBDetId ebid(id);
0110         if (ebid.zside() < 0) {
0111           negative = true;
0112           EBDetId posId(EBDetId::switchZSide(ebid));
0113           posTime = sTimeMap.getBinContent(getEcalDQMSetupObjects(), posId);
0114         }
0115       } else {
0116         EEDetId eeid(id);
0117         if (eeid.zside() < 0) {
0118           negative = true;
0119           EEDetId posId(EEDetId::switchZSide(eeid));
0120           posTime = sTimeMap.getBinContent(getEcalDQMSetupObjects(), posId);
0121         }
0122       }
0123       if (negative) {
0124         meFwdBkwdDiff.fill(getEcalDQMSetupObjects(), id, posTime - mean);
0125         meFwdvBkwd.fill(getEcalDQMSetupObjects(), id, mean, posTime);
0126       }
0127 
0128       if (std::abs(mean) > meanThresh || rms > rmsThresh)
0129         qItr->setBinContent(doMask ? kMBad : kBad);
0130       else
0131         qItr->setBinContent(doMask ? kMGood : kGood);
0132 
0133       // For Trend plots:
0134       tLSItr = qItr;
0135       float entriesLS(tLSItr->getBinEntries());
0136       float meanLS(tLSItr->getBinContent());
0137       float rmsLS(tLSItr->getBinError() * sqrt(entriesLS));
0138       float chStatus(sChStatus.getBinContent(getEcalDQMSetupObjects(), id));
0139 
0140       if (entriesLS < minChannelEntries)
0141         continue;
0142       if (chStatus != EcalChannelStatusCode::kOk)
0143         continue;  // exclude problematic channels
0144 
0145       // Keep running count of timing mean, rms, and N_hits
0146       if (id.subdetId() == EcalBarrel) {
0147         EBmean += meanLS;
0148         EBrms += rmsLS;
0149         EBentries += entriesLS;
0150       } else {
0151         EEmean += meanLS;
0152         EErms += rmsLS;
0153         EEentries += entriesLS;
0154       }
0155 
0156     }  // channel loop
0157 
0158     // Fill Timing Trend plots at each LS
0159     MESet& meTrendMean(MEs_.at("TrendMean"));
0160     MESet& meTrendRMS(MEs_.at("TrendRMS"));
0161     if (EBentries > 0.) {
0162       if (std::abs(EBmean) > 0.)
0163         meTrendMean.fill(getEcalDQMSetupObjects(), EcalBarrel, double(timestamp_.iLumi), EBmean / EBentries);
0164       if (std::abs(EBrms) > 0.)
0165         meTrendRMS.fill(getEcalDQMSetupObjects(), EcalBarrel, double(timestamp_.iLumi), EBrms / EBentries);
0166     }
0167     if (EEentries > 0.) {
0168       if (std::abs(EEmean) > 0.)
0169         meTrendMean.fill(getEcalDQMSetupObjects(), EcalEndcap, double(timestamp_.iLumi), EEmean / EEentries);
0170       if (std::abs(EErms) > 0.)
0171         meTrendRMS.fill(getEcalDQMSetupObjects(), EcalEndcap, double(timestamp_.iLumi), EErms / EEentries);
0172     }
0173 
0174     MESet::iterator qsEnd(meQualitySummary.end(GetElectronicsMap()));
0175 
0176     for (MESet::iterator qsItr(meQualitySummary.beginChannel(GetElectronicsMap())); qsItr != qsEnd;
0177          qsItr.toNextChannel(GetElectronicsMap())) {
0178       DetId tId(qsItr->getId());
0179 
0180       std::vector<DetId> ids;
0181 
0182       if (tId.subdetId() == EcalTriggerTower)
0183         ids = GetTrigTowerMap()->constituentsOf(EcalTrigTowerDetId(tId));
0184       else
0185         ids = scConstituents(EcalScDetId(tId));
0186 
0187       int minTowerEntries(minTowerEntries_);
0188       float meanThresh(toleranceMean_);
0189       float rmsThresh(toleranceRMS_);
0190 
0191       if (isForward(tId)) {
0192         minTowerEntries = minTowerEntriesFwd_;
0193         meanThresh = toleranceMeanFwd_;
0194         rmsThresh = toleranceRMSFwd_;
0195       }
0196 
0197       // tower entries != sum(channel entries) because of the difference in timing cut at the source
0198       float summaryEntries(sTimeAllMap.getBinEntries(getEcalDQMSetupObjects(), tId));
0199 
0200       float towerEntries(0.);
0201       float towerMean(0.);
0202       float towerMean2(0.);
0203 
0204       bool doMask(false);
0205 
0206       for (std::vector<DetId>::iterator idItr(ids.begin()); idItr != ids.end(); ++idItr) {
0207         DetId& id(*idItr);
0208 
0209         doMask |= meQuality.maskMatches(id, mask, statusManager_, GetTrigTowerMap());
0210 
0211         MESet::const_iterator tmItr(GetElectronicsMap(), sTimeMap, id);
0212 
0213         float entries(tmItr->getBinEntries());
0214         if (entries < 0.)
0215           continue;
0216         towerEntries += entries;
0217         float mean(tmItr->getBinContent());
0218         towerMean += mean * entries;
0219         float rms(tmItr->getBinError() * sqrt(entries));
0220         towerMean2 += (rms * rms + mean * mean) * entries;
0221       }
0222 
0223       double quality(doMask ? kMUnknown : kUnknown);
0224       if (towerEntries / ids.size() > minTowerEntries / 25.) {
0225         if (summaryEntries < towerEntries * (1. - tailPopulThreshold_))  // large timing deviation
0226           quality = doMask ? kMBad : kBad;
0227         else {
0228           towerMean /= towerEntries;
0229           towerMean2 /= towerEntries;
0230 
0231           float towerRMS(sqrt(towerMean2 - towerMean * towerMean));
0232 
0233           if (std::abs(towerMean) > meanThresh || towerRMS > rmsThresh)
0234             quality = doMask ? kMBad : kBad;
0235           else
0236             quality = doMask ? kMGood : kGood;
0237         }
0238       }
0239       qsItr->setBinContent(quality);
0240     }
0241   }
0242 
0243   DEFINE_ECALDQM_WORKER(TimingClient);
0244 }  // namespace ecaldqm