Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DQM/EcalMonitorClient/interface/TowerStatusTask.h"
0002 
0003 #include "FWCore/Framework/interface/ESHandle.h"
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 
0008 #include "DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h"
0009 #include "DataFormats/EcalDetId/interface/EcalScDetId.h"
0010 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0011 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0012 
0013 namespace ecaldqm {
0014 
0015   TowerStatusTask::TowerStatusTask() : DQWorkerClient(), doDAQInfo_(false), doDCSInfo_(false) {
0016     std::fill_n(daqStatus_, nDCC, 0.);
0017     std::fill_n(dcsStatus_, nDCC, 0.);
0018   }
0019 
0020   void TowerStatusTask::setParams(edm::ParameterSet const& _params) {
0021     doDAQInfo_ = _params.getUntrackedParameter<bool>("doDAQInfo");
0022     doDCSInfo_ = _params.getUntrackedParameter<bool>("doDCSInfo");
0023 
0024     if (doDAQInfo_ && doDCSInfo_)
0025       return;
0026     if (doDAQInfo_) {
0027       MEs_.erase(std::string("DCSSummary"));
0028       MEs_.erase(std::string("DCSSummaryMap"));
0029       MEs_.erase(std::string("DCSContents"));
0030     } else if (doDCSInfo_) {
0031       MEs_.erase(std::string("DAQSummary"));
0032       MEs_.erase(std::string("DAQSummaryMap"));
0033       MEs_.erase(std::string("DAQContents"));
0034     } else
0035       throw cms::Exception("InvalidConfiguration") << "Nothing to do in TowerStatusTask";
0036   }
0037 
0038   void TowerStatusTask::setTokens(edm::ConsumesCollector& _collector) {
0039     daqHndlToken = _collector.esConsumes<edm::Transition::EndLuminosityBlock>();
0040     dcsHndlToken = _collector.esConsumes<edm::Transition::EndLuminosityBlock>();
0041   }
0042 
0043   void TowerStatusTask::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const& _es) {
0044     if (doDAQInfo_) {
0045       std::fill_n(daqStatus_, nDCC, 1.);
0046 
0047       const EcalDAQTowerStatus* daqHndl = &_es.getData(daqHndlToken);
0048       auto daqhandle = _es.getHandle(daqHndlToken);
0049       if (daqhandle.isValid()) {
0050         for (unsigned id(0); id < EcalTrigTowerDetId::kEBTotalTowers; id++) {
0051           if (daqHndl->barrel(id).getStatusCode() != 0) {
0052             EcalTrigTowerDetId ttid(EcalTrigTowerDetId::detIdFromDenseIndex(id));
0053             daqStatus_[dccId(ttid, GetElectronicsMap()) - 1] -= 25. / 1700.;
0054           }
0055         }
0056         for (unsigned id(0); id < EcalScDetId::kSizeForDenseIndexing; id++) {
0057           if (daqHndl->endcap(id).getStatusCode() != 0) {
0058             EcalScDetId scid(EcalScDetId::unhashIndex(id));
0059             unsigned dccid(dccId(scid, GetElectronicsMap()));
0060             daqStatus_[dccid - 1] -= double(scConstituents(scid).size()) / nCrystals(dccid);
0061           }
0062         }
0063       } else
0064         edm::LogWarning("EventSetup") << "EcalDAQTowerStatus record not valid";
0065     }
0066 
0067     if (doDCSInfo_) {
0068       std::fill_n(dcsStatus_, nDCC, 1.);
0069 
0070       const EcalDCSTowerStatus* dcsHndl = &_es.getData(dcsHndlToken);
0071       auto dcshandle = _es.getHandle(dcsHndlToken);
0072       if (dcshandle.isValid()) {
0073         for (unsigned id(0); id < EcalTrigTowerDetId::kEBTotalTowers; id++) {
0074           if (dcsHndl->barrel(id).getStatusCode() != 0) {
0075             EcalTrigTowerDetId ttid(EcalTrigTowerDetId::detIdFromDenseIndex(id));
0076             dcsStatus_[dccId(ttid, GetElectronicsMap()) - 1] -= 25. / 1700.;
0077           }
0078         }
0079         for (unsigned id(0); id < EcalScDetId::kSizeForDenseIndexing; id++) {
0080           if (dcsHndl->endcap(id).getStatusCode() != 0) {
0081             EcalScDetId scid(EcalScDetId::unhashIndex(id));
0082             unsigned dccid(dccId(scid, GetElectronicsMap()));
0083             dcsStatus_[dccid - 1] -= double(scConstituents(scid).size()) / nCrystals(dccid);
0084           }
0085         }
0086       } else
0087         edm::LogWarning("EventSetup") << "EcalDCSTowerStatus record not valid";
0088     }
0089   }
0090 
0091   void TowerStatusTask::producePlots(ProcessType) {
0092     if (doDAQInfo_)
0093       producePlotsTask_(daqStatus_, "DAQ");
0094     if (doDCSInfo_)
0095       producePlotsTask_(dcsStatus_, "DCS");
0096   }
0097 
0098   void TowerStatusTask::producePlotsTask_(float const* _status, std::string const& _type) {
0099     MESet* meSummary(nullptr);
0100     MESet* meSummaryMap(nullptr);
0101     MESet* meContents(nullptr);
0102     meSummary = &MEs_.at(_type + "Summary");
0103     meSummaryMap = &MEs_.at(_type + "SummaryMap");
0104     meContents = &MEs_.at(_type + "Contents");
0105 
0106     meSummary->reset(GetElectronicsMap(), -1.);
0107     meSummaryMap->resetAll(-1.);
0108     meSummaryMap->reset(GetElectronicsMap());
0109     meContents->reset(GetElectronicsMap(), -1.);
0110 
0111     float totalFraction(0.);
0112     for (int iDCC(0); iDCC < nDCC; iDCC++) {
0113       meSummaryMap->setBinContent(getEcalDQMSetupObjects(), iDCC + 1, _status[iDCC]);
0114       meContents->fill(getEcalDQMSetupObjects(), iDCC + 1, _status[iDCC]);
0115       totalFraction += _status[iDCC] / nCrystals(iDCC + 1);
0116     }
0117 
0118     meSummary->fill(getEcalDQMSetupObjects(), totalFraction);
0119   }
0120 
0121   DEFINE_ECALDQM_WORKER(TowerStatusTask);
0122 }  // namespace ecaldqm