Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DQM/EcalMonitorClient/interface/CalibrationSummaryClient.h"
0002 
0003 #include "DQM/EcalCommon/interface/EcalDQMCommonUtils.h"
0004 #include "DQM/EcalCommon/interface/MESetMulti.h"
0005 
0006 #include "DataFormats/EcalDetId/interface/EcalPnDiodeDetId.h"
0007 
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 
0010 #include <algorithm>
0011 
0012 namespace ecaldqm {
0013   CalibrationSummaryClient::CalibrationSummaryClient()
0014       : DQWorkerClient(),
0015         laserWlToME_(),
0016         ledWlToME_(),
0017         tpGainToME_(),
0018         tpPNGainToME_(),
0019         pedGainToME_(),
0020         pedPNGainToME_() {}
0021 
0022   void CalibrationSummaryClient::setParams(edm::ParameterSet const& _params) {
0023     std::vector<std::string> sourceList(_params.getUntrackedParameter<std::vector<std::string> >("activeSources"));
0024     if (std::find(sourceList.begin(), sourceList.end(), "Laser") == sourceList.end()) {
0025       sources_.erase(std::string("Laser"));
0026       sources_.erase(std::string("LaserPN"));
0027     }
0028     if (std::find(sourceList.begin(), sourceList.end(), "Led") == sourceList.end()) {
0029       sources_.erase(std::string("Led"));
0030       sources_.erase(std::string("LedPN"));
0031     }
0032     if (std::find(sourceList.begin(), sourceList.end(), "TestPulse") == sourceList.end()) {
0033       sources_.erase(std::string("TestPulse"));
0034       sources_.erase(std::string("TestPulsePN"));
0035     }
0036     if (std::find(sourceList.begin(), sourceList.end(), "Pedestal") == sourceList.end()) {
0037       sources_.erase(std::string("Pedestal"));
0038       sources_.erase(std::string("PedestalPN"));
0039     }
0040 
0041     MESet::PathReplacements repl;
0042 
0043     if (using_("Laser")) {
0044       repl.clear();
0045       std::vector<int> laserWavelengths(_params.getUntrackedParameter<std::vector<int> >("laserWavelengths"));
0046       MESetMulti const& laser(static_cast<MESetMulti const&>(sources_.at("Laser")));
0047       unsigned nWL(laserWavelengths.size());
0048       for (unsigned iWL(0); iWL != nWL; ++iWL) {
0049         int wl(laserWavelengths[iWL]);
0050         if (wl <= 0 || wl >= 5)
0051           throw cms::Exception("InvalidConfiguration") << "Laser Wavelength";
0052         repl["wl"] = std::to_string(wl);
0053         laserWlToME_[wl] = laser.getIndex(repl);
0054       }
0055     }
0056 
0057     if (using_("Led")) {
0058       repl.clear();
0059       std::vector<int> ledWavelengths(_params.getUntrackedParameter<std::vector<int> >("ledWavelengths"));
0060       MESetMulti const& led(static_cast<MESetMulti const&>(sources_.at("Led")));
0061       unsigned nWL(ledWavelengths.size());
0062       for (unsigned iWL(0); iWL != nWL; ++iWL) {
0063         int wl(ledWavelengths[iWL]);
0064         if (wl <= 0 || wl >= 5)
0065           throw cms::Exception("InvalidConfiguration") << "Led Wavelength";
0066         repl["wl"] = std::to_string(wl);
0067         ledWlToME_[wl] = led.getIndex(repl);
0068       }
0069     }
0070 
0071     if (using_("TestPulse")) {
0072       repl.clear();
0073       std::vector<int> tpMGPAGains(_params.getUntrackedParameter<std::vector<int> >("testPulseMGPAGains"));
0074       MESetMulti const& tp(static_cast<MESetMulti const&>(sources_.at("TestPulse")));
0075       unsigned nG(tpMGPAGains.size());
0076       for (unsigned iG(0); iG != nG; ++iG) {
0077         int gain(tpMGPAGains[iG]);
0078         if (gain != 1 && gain != 6 && gain != 12)
0079           throw cms::Exception("InvalidConfiguration") << "MGPA gain";
0080         repl["gain"] = std::to_string(gain);
0081         tpGainToME_[gain] = tp.getIndex(repl);
0082       }
0083 
0084       repl.clear();
0085       std::vector<int> tpMGPAGainsPN(_params.getUntrackedParameter<std::vector<int> >("testPulseMGPAGainsPN"));
0086       MESetMulti const& tppn(static_cast<MESetMulti const&>(sources_.at("TestPulsePN")));
0087       unsigned nGPN(tpMGPAGainsPN.size());
0088       for (unsigned iG(0); iG != nGPN; ++iG) {
0089         int gain(tpMGPAGainsPN[iG]);
0090         if (gain != 1 && gain != 16)
0091           throw cms::Exception("InvalidConfiguration") << "PN MGPA gain";
0092         repl["pngain"] = std::to_string(gain);
0093         tpPNGainToME_[gain] = tppn.getIndex(repl);
0094       }
0095     }
0096 
0097     if (using_("Pedestal")) {
0098       repl.clear();
0099       std::vector<int> pedMGPAGains(_params.getUntrackedParameter<std::vector<int> >("pedestalMGPAGains"));
0100       MESetMulti const& ped(static_cast<MESetMulti const&>(sources_.at("Pedestal")));
0101       unsigned nG(pedMGPAGains.size());
0102       for (unsigned iG(0); iG != nG; ++iG) {
0103         int gain(pedMGPAGains[iG]);
0104         if (gain != 1 && gain != 6 && gain != 12)
0105           throw cms::Exception("InvalidConfiguration") << "MGPA gain";
0106         repl["gain"] = std::to_string(gain);
0107         pedGainToME_[gain] = ped.getIndex(repl);
0108       }
0109 
0110       repl.clear();
0111       std::vector<int> pedMGPAGainsPN(_params.getUntrackedParameter<std::vector<int> >("pedestalMGPAGainsPN"));
0112       MESetMulti const& pedpn(static_cast<MESetMulti const&>(sources_.at("PedestalPN")));
0113       unsigned nGPN(pedMGPAGainsPN.size());
0114       for (unsigned iG(0); iG != nGPN; ++iG) {
0115         int gain(pedMGPAGainsPN[iG]);
0116         if (gain != 1 && gain != 16)
0117           throw cms::Exception("InvalidConfiguration") << "PN MGPA gain";
0118         repl["pngain"] = std::to_string(gain);
0119         pedPNGainToME_[gain] = pedpn.getIndex(repl);
0120       }
0121     }
0122 
0123     qualitySummaries_.insert("QualitySummary");
0124     qualitySummaries_.insert("PNQualitySummary");
0125   }
0126 
0127   void CalibrationSummaryClient::producePlots(ProcessType) {
0128     using namespace std;
0129 
0130     MESet& meQualitySummary(MEs_.at("QualitySummary"));
0131     MESet& mePNQualitySummary(MEs_.at("PNQualitySummary"));
0132 
0133     MESetMulti const* sLaser(using_("Laser") ? static_cast<MESetMulti const*>(&sources_.at("Laser")) : nullptr);
0134     MESetMulti const* sLaserPN(using_("LaserPN") ? static_cast<MESetMulti const*>(&sources_.at("LaserPN")) : nullptr);
0135     MESetMulti const* sLed(using_("Led") ? static_cast<MESetMulti const*>(&sources_.at("Led")) : nullptr);
0136     MESetMulti const* sLedPN(using_("LedPN") ? static_cast<MESetMulti const*>(&sources_.at("LedPN")) : nullptr);
0137     MESetMulti const* sTestPulse(using_("TestPulse") ? static_cast<MESetMulti const*>(&sources_.at("TestPulse"))
0138                                                      : nullptr);
0139     MESetMulti const* sTestPulsePN(using_("TestPulsePN") ? static_cast<MESetMulti const*>(&sources_.at("TestPulsePN"))
0140                                                          : nullptr);
0141     MESetMulti const* sPedestal(using_("Pedestal") ? static_cast<MESetMulti const*>(&sources_.at("Pedestal"))
0142                                                    : nullptr);
0143     MESetMulti const* sPedestalPN(using_("PedestalPN") ? static_cast<MESetMulti const*>(&sources_.at("PedestalPN"))
0144                                                        : nullptr);
0145     MESet const& sPNIntegrity(sources_.at("PNIntegrity"));
0146 
0147     MESet::iterator qEnd(meQualitySummary.end(GetElectronicsMap()));
0148     for (MESet::iterator qItr(meQualitySummary.beginChannel(GetElectronicsMap())); qItr != qEnd;
0149          qItr.toNextChannel(GetElectronicsMap())) {
0150       DetId id(qItr->getId());
0151 
0152       int status(kGood);
0153 
0154       if (status == kGood && sLaser) {
0155         for (map<int, unsigned>::iterator wlItr(laserWlToME_.begin()); wlItr != laserWlToME_.end(); ++wlItr) {
0156           sLaser->use(wlItr->second);
0157           if (sLaser->getBinContent(getEcalDQMSetupObjects(), id) == kBad) {
0158             status = kBad;
0159             break;
0160           }
0161         }
0162       }
0163 
0164       if (status == kGood && sLed) {
0165         DetId id(qItr->getId());
0166         if (id.subdetId() == EcalEndcap) {
0167           for (map<int, unsigned>::iterator wlItr(ledWlToME_.begin()); wlItr != ledWlToME_.end(); ++wlItr) {
0168             sLed->use(wlItr->second);
0169             if (sLed->getBinContent(getEcalDQMSetupObjects(), id) == kBad) {
0170               status = kBad;
0171               break;
0172             }
0173           }
0174         }
0175       }
0176 
0177       if (status == kGood && sTestPulse) {
0178         for (map<int, unsigned>::iterator gainItr(tpGainToME_.begin()); gainItr != tpGainToME_.end(); ++gainItr) {
0179           sTestPulse->use(gainItr->second);
0180           if (sTestPulse->getBinContent(getEcalDQMSetupObjects(), id) == kBad) {
0181             status = kBad;
0182             break;
0183           }
0184         }
0185       }
0186 
0187       if (status == kGood && sPedestal) {
0188         for (map<int, unsigned>::iterator gainItr(pedGainToME_.begin()); gainItr != pedGainToME_.end(); ++gainItr) {
0189           sPedestal->use(gainItr->second);
0190           if (sPedestal->getBinContent(getEcalDQMSetupObjects(), id) == kBad) {
0191             status = kBad;
0192             break;
0193           }
0194         }
0195       }
0196 
0197       qItr->setBinContent(status);
0198     }
0199 
0200     for (unsigned iDCC(0); iDCC < nDCC; ++iDCC) {
0201       if (memDCCIndex(iDCC + 1) == unsigned(-1))
0202         continue;
0203       for (unsigned iPN(0); iPN < 10; ++iPN) {
0204         int subdet(0);
0205         if (iDCC >= kEBmLow && iDCC <= kEBpHigh)
0206           subdet = EcalBarrel;
0207         else
0208           subdet = EcalEndcap;
0209 
0210         EcalPnDiodeDetId id(subdet, iDCC + 1, iPN + 1);
0211 
0212         int status(kGood);
0213 
0214         if (sPNIntegrity.getBinContent(getEcalDQMSetupObjects(), id) == kBad)
0215           status = kBad;
0216 
0217         if (status == kGood && sLaserPN) {
0218           for (map<int, unsigned>::iterator wlItr(laserWlToME_.begin()); wlItr != laserWlToME_.end(); ++wlItr) {
0219             sLaserPN->use(wlItr->second);
0220             if (sLaserPN->getBinContent(getEcalDQMSetupObjects(), id) == kBad) {
0221               status = kBad;
0222               break;
0223             }
0224           }
0225         }
0226 
0227         if (status == kGood && sLedPN) {
0228           for (map<int, unsigned>::iterator wlItr(ledWlToME_.begin()); wlItr != ledWlToME_.end(); ++wlItr) {
0229             sLedPN->use(wlItr->second);
0230             if (sLedPN->getBinContent(getEcalDQMSetupObjects(), id) == kBad) {
0231               status = kBad;
0232               break;
0233             }
0234           }
0235         }
0236 
0237         if (status == kGood && sTestPulsePN) {
0238           for (map<int, unsigned>::iterator gainItr(tpPNGainToME_.begin()); gainItr != tpPNGainToME_.end(); ++gainItr) {
0239             sTestPulsePN->use(gainItr->second);
0240             if (sTestPulsePN->getBinContent(getEcalDQMSetupObjects(), id) == kBad) {
0241               status = kBad;
0242               break;
0243             }
0244           }
0245         }
0246 
0247         if (status == kGood && sPedestalPN) {
0248           for (map<int, unsigned>::iterator gainItr(pedPNGainToME_.begin()); gainItr != pedPNGainToME_.end();
0249                ++gainItr) {
0250             sPedestalPN->use(gainItr->second);
0251             if (sPedestalPN->getBinContent(getEcalDQMSetupObjects(), id) == kBad) {
0252               status = kBad;
0253               break;
0254             }
0255           }
0256         }
0257 
0258         mePNQualitySummary.setBinContent(getEcalDQMSetupObjects(), id, status);
0259       }
0260     }
0261   }
0262 
0263   DEFINE_ECALDQM_WORKER(CalibrationSummaryClient);
0264 }  // namespace ecaldqm