Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DQM/EcalMonitorClient/interface/TestPulseClient.h"
0002 
0003 #include "DQM/EcalCommon/interface/MESetMulti.h"
0004 #include "DQM/EcalCommon/interface/EcalDQMCommonUtils.h"
0005 
0006 #include "DataFormats/EcalDetId/interface/EcalPnDiodeDetId.h"
0007 
0008 #include "CondFormats/EcalObjects/interface/EcalDQMStatusHelper.h"
0009 
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 
0012 #include <iomanip>
0013 
0014 namespace ecaldqm {
0015   TestPulseClient::TestPulseClient()
0016       : DQWorkerClient(),
0017         gainToME_(),
0018         pnGainToME_(),
0019         minChannelEntries_(0),
0020         amplitudeThreshold_(0),
0021         toleranceRMS_(0),
0022         PNAmplitudeThreshold_(0),
0023         tolerancePNRMS_(0) {}
0024 
0025   void TestPulseClient::setParams(edm::ParameterSet const& _params) {
0026     minChannelEntries_ = _params.getUntrackedParameter<int>("minChannelEntries");
0027 
0028     std::vector<int> MGPAGains(_params.getUntrackedParameter<std::vector<int> >("MGPAGains"));
0029     std::vector<int> MGPAGainsPN(_params.getUntrackedParameter<std::vector<int> >("MGPAGainsPN"));
0030 
0031     MESet::PathReplacements repl;
0032 
0033     MESetMulti const& amplitude(static_cast<MESetMulti const&>(sources_.at("Amplitude")));
0034     unsigned nG(MGPAGains.size());
0035     for (unsigned iG(0); iG != nG; ++iG) {
0036       int gain(MGPAGains[iG]);
0037       if (gain != 1 && gain != 6 && gain != 12)
0038         throw cms::Exception("InvalidConfiguration") << "MGPA gain";
0039       repl["gain"] = std::to_string(gain);
0040       gainToME_[gain] = amplitude.getIndex(repl);
0041     }
0042 
0043     repl.clear();
0044 
0045     MESetMulti const& pnAmplitude(static_cast<MESetMulti const&>(sources_.at("PNAmplitude")));
0046     unsigned nGPN(MGPAGainsPN.size());
0047     for (unsigned iG(0); iG != nGPN; ++iG) {
0048       int gain(MGPAGainsPN[iG]);
0049       if (gain != 1 && gain != 16)
0050         throw cms::Exception("InvalidConfiguration") << "PN MGPA gain";
0051       repl["pngain"] = std::to_string(gain);
0052       pnGainToME_[gain] = pnAmplitude.getIndex(repl);
0053     }
0054 
0055     amplitudeThreshold_.resize(nG);
0056     toleranceRMS_.resize(nG);
0057 
0058     std::vector<double> inAmplitudeThreshold(_params.getUntrackedParameter<std::vector<double> >("amplitudeThreshold"));
0059     std::vector<double> inToleranceRMS(_params.getUntrackedParameter<std::vector<double> >("toleranceRMS"));
0060 
0061     for (std::map<int, unsigned>::iterator gainItr(gainToME_.begin()); gainItr != gainToME_.end(); ++gainItr) {
0062       unsigned iME(gainItr->second);
0063       unsigned iGain(0);
0064       switch (gainItr->first) {
0065         case 1:
0066           iGain = 0;
0067           break;
0068         case 6:
0069           iGain = 1;
0070           break;
0071         case 12:
0072           iGain = 2;
0073           break;
0074       }
0075 
0076       amplitudeThreshold_[iME] = inAmplitudeThreshold[iGain];
0077       toleranceRMS_[iME] = inToleranceRMS[iGain];
0078     }
0079 
0080     PNAmplitudeThreshold_.resize(nGPN);
0081     tolerancePNRMS_.resize(nGPN);
0082 
0083     std::vector<double> inPNAmplitudeThreshold(
0084         _params.getUntrackedParameter<std::vector<double> >("PNAmplitudeThreshold"));
0085     std::vector<double> inTolerancePNRMS(_params.getUntrackedParameter<std::vector<double> >("tolerancePNRMS"));
0086 
0087     for (std::map<int, unsigned>::iterator gainItr(pnGainToME_.begin()); gainItr != pnGainToME_.end(); ++gainItr) {
0088       unsigned iME(gainItr->second);
0089       unsigned iGain(0);
0090       switch (gainItr->first) {
0091         case 1:
0092           iGain = 0;
0093           break;
0094         case 16:
0095           iGain = 1;
0096           break;
0097       }
0098 
0099       PNAmplitudeThreshold_[iME] = inPNAmplitudeThreshold[iGain];
0100       tolerancePNRMS_[iME] = inTolerancePNRMS[iGain];
0101     }
0102 
0103     qualitySummaries_.insert("Quality");
0104     qualitySummaries_.insert("QualitySummary");
0105     qualitySummaries_.insert("PNQualitySummary");
0106   }
0107 
0108   void TestPulseClient::producePlots(ProcessType) {
0109     using namespace std;
0110 
0111     MESetMulti& meQuality(static_cast<MESetMulti&>(MEs_.at("Quality")));
0112     MESetMulti& meAmplitudeRMS(static_cast<MESetMulti&>(MEs_.at("AmplitudeRMS")));
0113     MESetMulti& meQualitySummary(static_cast<MESetMulti&>(MEs_.at("QualitySummary")));
0114     MESetMulti& mePNQualitySummary(static_cast<MESetMulti&>(MEs_.at("PNQualitySummary")));
0115 
0116     MESetMulti const& sAmplitude(static_cast<MESetMulti const&>(sources_.at("Amplitude")));
0117     MESetMulti const& sPNAmplitude(static_cast<MESetMulti const&>(sources_.at("PNAmplitude")));
0118 
0119     for (map<int, unsigned>::iterator gainItr(gainToME_.begin()); gainItr != gainToME_.end(); ++gainItr) {
0120       meQuality.use(gainItr->second);
0121       meQualitySummary.use(gainItr->second);
0122       meAmplitudeRMS.use(gainItr->second);
0123 
0124       sAmplitude.use(gainItr->second);
0125 
0126       uint32_t mask(0);
0127       switch (gainItr->first) {
0128         case 1:
0129           mask |= (1 << EcalDQMStatusHelper::TESTPULSE_LOW_GAIN_MEAN_ERROR |
0130                    1 << EcalDQMStatusHelper::TESTPULSE_LOW_GAIN_RMS_ERROR);
0131           break;
0132         case 6:
0133           mask |= (1 << EcalDQMStatusHelper::TESTPULSE_MIDDLE_GAIN_MEAN_ERROR |
0134                    1 << EcalDQMStatusHelper::TESTPULSE_MIDDLE_GAIN_RMS_ERROR);
0135           break;
0136         case 12:
0137           mask |= (1 << EcalDQMStatusHelper::TESTPULSE_HIGH_GAIN_MEAN_ERROR |
0138                    1 << EcalDQMStatusHelper::TESTPULSE_HIGH_GAIN_RMS_ERROR);
0139           break;
0140         default:
0141           break;
0142       }
0143 
0144       MESet::iterator qEnd(meQuality.end(GetElectronicsMap()));
0145       MESet::iterator rItr(GetElectronicsMap(), meAmplitudeRMS);
0146       MESet::const_iterator aItr(GetElectronicsMap(), sAmplitude);
0147       for (MESet::iterator qItr(meQuality.beginChannel(GetElectronicsMap())); qItr != qEnd;
0148            qItr.toNextChannel(GetElectronicsMap())) {
0149         DetId id(qItr->getId());
0150 
0151         bool doMask(meQuality.maskMatches(id, mask, statusManager_, GetTrigTowerMap()));
0152 
0153         aItr = qItr;
0154         rItr = qItr;
0155 
0156         float entries(aItr->getBinEntries());
0157 
0158         if (entries < minChannelEntries_) {
0159           qItr->setBinContent(doMask ? kMUnknown : kUnknown);
0160           continue;
0161         }
0162 
0163         float amp(aItr->getBinContent());
0164         float rms(aItr->getBinError() * sqrt(entries));
0165 
0166         rItr->setBinContent(rms);
0167 
0168         if (amp < amplitudeThreshold_[gainItr->second] || rms > toleranceRMS_[gainItr->second])
0169           qItr->setBinContent(doMask ? kMBad : kBad);
0170         else
0171           qItr->setBinContent(doMask ? kMGood : kGood);
0172       }
0173 
0174       towerAverage_(meQualitySummary, meQuality, 0.2);
0175     }
0176 
0177     for (map<int, unsigned>::iterator gainItr(pnGainToME_.begin()); gainItr != pnGainToME_.end(); ++gainItr) {
0178       mePNQualitySummary.use(gainItr->second);
0179 
0180       sPNAmplitude.use(gainItr->second);
0181 
0182       uint32_t mask(0);
0183       switch (gainItr->first) {
0184         case 1:
0185           mask |= (1 << EcalDQMStatusHelper::TESTPULSE_LOW_GAIN_MEAN_ERROR |
0186                    1 << EcalDQMStatusHelper::TESTPULSE_LOW_GAIN_RMS_ERROR);
0187           break;
0188         case 16:
0189           mask |= (1 << EcalDQMStatusHelper::TESTPULSE_HIGH_GAIN_MEAN_ERROR |
0190                    1 << EcalDQMStatusHelper::TESTPULSE_HIGH_GAIN_RMS_ERROR);
0191           break;
0192         default:
0193           break;
0194       }
0195 
0196       for (unsigned iDCC(0); iDCC < nDCC; ++iDCC) {
0197         if (memDCCIndex(iDCC + 1) == unsigned(-1))
0198           continue;
0199 
0200         for (unsigned iPN(0); iPN < 10; ++iPN) {
0201           int subdet(0);
0202           if (iDCC >= kEBmLow && iDCC <= kEBpHigh)
0203             subdet = EcalBarrel;
0204           else
0205             subdet = EcalEndcap;
0206 
0207           EcalPnDiodeDetId id(subdet, iDCC + 1, iPN + 1);
0208 
0209           bool doMask(mePNQualitySummary.maskMatches(id, mask, statusManager_, GetTrigTowerMap()));
0210 
0211           float amp(sPNAmplitude.getBinContent(getEcalDQMSetupObjects(), id));
0212           float entries(sPNAmplitude.getBinEntries(getEcalDQMSetupObjects(), id));
0213           float rms(sPNAmplitude.getBinError(getEcalDQMSetupObjects(), id) * sqrt(entries));
0214 
0215           if (entries < minChannelEntries_) {
0216             mePNQualitySummary.setBinContent(getEcalDQMSetupObjects(), id, doMask ? kMUnknown : kUnknown);
0217             continue;
0218           }
0219 
0220           if (amp < PNAmplitudeThreshold_[gainItr->second] || rms > tolerancePNRMS_[gainItr->second])
0221             mePNQualitySummary.setBinContent(getEcalDQMSetupObjects(), id, doMask ? kMBad : kBad);
0222           else
0223             mePNQualitySummary.setBinContent(getEcalDQMSetupObjects(), id, doMask ? kMGood : kGood);
0224         }
0225       }
0226     }
0227   }
0228 
0229   DEFINE_ECALDQM_WORKER(TestPulseClient);
0230 }  // namespace ecaldqm