Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-29 01:21:19

0001 #include "DQM/EcalMonitorTasks/interface/EcalFEDMonitor.h"
0002 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
0003 #include "FWCore/Framework/interface/MakerMacros.h"
0004 
0005 template <int SUBDET>
0006 EcalFEDMonitorTemp<SUBDET>::EcalFEDMonitorTemp(edm::ParameterSet const& _ps)
0007     : folderName_(_ps.getUntrackedParameter<std::string>("folderName")),
0008       FEDRawDataToken_(consumes<FEDRawDataCollection>(_ps.getParameter<edm::InputTag>("FEDRawDataCollection"))),
0009       ebGainErrorsToken_(),
0010       eeGainErrorsToken_(),
0011       ebChIdErrorsToken_(),
0012       eeChIdErrorsToken_(),
0013       ebGainSwitchErrorsToken_(),
0014       eeGainSwitchErrorsToken_(),
0015       towerIdErrorsToken_(
0016           consumes<EcalElectronicsIdCollection>(_ps.getParameter<edm::InputTag>("EcalElectronicsIdCollection1"))),
0017       blockSizeErrorsToken_(
0018           consumes<EcalElectronicsIdCollection>(_ps.getParameter<edm::InputTag>("EcalElectronicsIdCollection2"))),
0019       elecMapHandle(esConsumes<edm::Transition::BeginRun>()),
0020       MEs_(nMEs, nullptr) {
0021   if (_ps.existsAs<edm::InputTag>("EBDetIdCollection1"))
0022     ebGainErrorsToken_ = consumes<EBDetIdCollection>(_ps.getParameter<edm::InputTag>("EBDetIdCollection1"));
0023   if (_ps.existsAs<edm::InputTag>("EEDetIdCollection1"))
0024     eeGainErrorsToken_ = consumes<EEDetIdCollection>(_ps.getParameter<edm::InputTag>("EEDetIdCollection1"));
0025   if (_ps.existsAs<edm::InputTag>("EBDetIdCollection2"))
0026     ebChIdErrorsToken_ = consumes<EBDetIdCollection>(_ps.getParameter<edm::InputTag>("EBDetIdCollection2"));
0027   if (_ps.existsAs<edm::InputTag>("EEDetIdCollection2"))
0028     eeChIdErrorsToken_ = consumes<EEDetIdCollection>(_ps.getParameter<edm::InputTag>("EEDetIdCollection2"));
0029   if (_ps.existsAs<edm::InputTag>("EBDetIdCollection3"))
0030     ebGainSwitchErrorsToken_ = consumes<EBDetIdCollection>(_ps.getParameter<edm::InputTag>("EBDetIdCollection3"));
0031   if (_ps.existsAs<edm::InputTag>("EEDetIdCollection3"))
0032     eeGainSwitchErrorsToken_ = consumes<EEDetIdCollection>(_ps.getParameter<edm::InputTag>("EEDetIdCollection3"));
0033 }
0034 
0035 template <int SUBDET>
0036 void EcalFEDMonitorTemp<SUBDET>::dqmBeginRun(edm::Run const&, edm::EventSetup const& _es) {
0037   setElectronicsMap(_es);
0038 }
0039 
0040 template <int SUBDET>
0041 void EcalFEDMonitorTemp<SUBDET>::bookHistograms(DQMStore::IBooker& _ibooker, edm::Run const&, edm::EventSetup const&) {
0042   _ibooker.cd();
0043 
0044   std::string name;
0045 
0046   if (SUBDET == EcalBarrel || SUBDET < 0) {
0047     _ibooker.setCurrentFolder("EcalBarrel/" + folderName_);
0048 
0049     name = "FEDEntries";
0050     MEs_[kEBOccupancy] = _ibooker.book1D(name, name, 36, 610, 646);
0051 
0052     name = "FEDFatal";
0053     MEs_[kEBFatal] = _ibooker.book1D(name, name, 36, 610, 646);
0054 
0055     name = "FEDNonFatal";
0056     MEs_[kEBNonFatal] = _ibooker.book1D(name, name, 36, 610, 646);
0057   }
0058   if (SUBDET == EcalEndcap || SUBDET < 0) {
0059     _ibooker.setCurrentFolder("EcalEndcap/" + folderName_);
0060 
0061     name = "FEDEntries";
0062     MEs_[kEEOccupancy] = _ibooker.book1D(name, name, 54, 601, 655);
0063 
0064     name = "FEDFatal";
0065     MEs_[kEEFatal] = _ibooker.book1D(name, name, 54, 601, 655);
0066 
0067     name = "FEDNonFatal";
0068     MEs_[kEENonFatal] = _ibooker.book1D(name, name, 54, 601, 655);
0069   }
0070 }
0071 
0072 template <int SUBDET>
0073 void EcalFEDMonitorTemp<SUBDET>::analyze(edm::Event const& _evt, edm::EventSetup const&) {
0074   edm::Handle<FEDRawDataCollection> fedHndl;
0075   if (_evt.getByToken(FEDRawDataToken_, fedHndl)) {
0076     for (unsigned fedId(601); fedId <= 654; fedId++) {
0077       if (SUBDET == EcalBarrel && (fedId < 610 || fedId > 645))
0078         continue;
0079       if (SUBDET == EcalEndcap && (fedId > 609 && fedId < 646))
0080         continue;
0081 
0082       unsigned occupancy(-1);
0083       //      unsigned fatal(-1);
0084       if (fedId < 610 || fedId > 645) {
0085         occupancy = kEEOccupancy;
0086         //        fatal = kEEFatal;
0087       } else {
0088         occupancy = kEBOccupancy;
0089         //        fatal = kEBFatal;
0090       }
0091 
0092       const FEDRawData& fedData(fedHndl->FEDData(fedId));
0093       unsigned length(fedData.size() / sizeof(uint64_t));
0094 
0095       if (length > 1) {  // FED header is one 64 bit word
0096         MEs_[occupancy]->Fill(fedId + 0.5);
0097 
0098         //      const uint64_t* pData(reinterpret_cast<const uint64_t*>(fedData.data()));
0099         //      bool crcError(((pData[length - 1] >> 2) & 0x1) == 0x1);
0100 
0101         //  if(crcError) MEs_[fatal]->Fill(fedId + 0.5);
0102       }
0103     }
0104   }
0105 
0106   edm::Handle<EBDetIdCollection> ebHndl;
0107   edm::Handle<EEDetIdCollection> eeHndl;
0108   edm::Handle<EcalElectronicsIdCollection> eleHndl;
0109 
0110   if ((SUBDET == EcalBarrel || SUBDET < 0) && _evt.getByToken(ebGainErrorsToken_, ebHndl)) {
0111     EBDetIdCollection::const_iterator ebEnd(ebHndl->end());
0112     for (EBDetIdCollection::const_iterator ebItr(ebHndl->begin()); ebItr != ebEnd; ++ebItr) {
0113       unsigned iDCC(ecaldqm::dccId(*ebItr, GetElectronicsMap()) - 1);
0114 
0115       double normalization(ecaldqm::nCrystals(iDCC + 1));
0116       if (normalization < 1.)
0117         continue;
0118 
0119       MEs_[kEBNonFatal]->Fill(iDCC + 601.5, 1. / normalization);
0120     }
0121   }
0122   if ((SUBDET == EcalEndcap || SUBDET < 0) && _evt.getByToken(eeGainErrorsToken_, eeHndl)) {
0123     EEDetIdCollection::const_iterator eeEnd(eeHndl->end());
0124     for (EEDetIdCollection::const_iterator eeItr(eeHndl->begin()); eeItr != eeEnd; ++eeItr) {
0125       unsigned iDCC(ecaldqm::dccId(*eeItr, GetElectronicsMap()) - 1);
0126 
0127       double normalization(ecaldqm::nCrystals(iDCC + 1));
0128       if (normalization < 1.)
0129         continue;
0130 
0131       MEs_[kEENonFatal]->Fill(iDCC + 601.5, 1. / normalization);
0132     }
0133   }
0134 
0135   if ((SUBDET == EcalBarrel || SUBDET < 0) && _evt.getByToken(ebChIdErrorsToken_, ebHndl)) {
0136     EBDetIdCollection::const_iterator ebEnd(ebHndl->end());
0137     for (EBDetIdCollection::const_iterator ebItr(ebHndl->begin()); ebItr != ebEnd; ++ebItr) {
0138       unsigned iDCC(ecaldqm::dccId(*ebItr, GetElectronicsMap()) - 1);
0139 
0140       double normalization(ecaldqm::nCrystals(iDCC + 1));
0141       if (normalization < 1.)
0142         continue;
0143 
0144       MEs_[kEBNonFatal]->Fill(iDCC + 601.5, 1. / normalization);
0145     }
0146   }
0147   if ((SUBDET == EcalEndcap || SUBDET < 0) && _evt.getByToken(eeChIdErrorsToken_, eeHndl)) {
0148     EEDetIdCollection::const_iterator eeEnd(eeHndl->end());
0149     for (EEDetIdCollection::const_iterator eeItr(eeHndl->begin()); eeItr != eeEnd; ++eeItr) {
0150       unsigned iDCC(ecaldqm::dccId(*eeItr, GetElectronicsMap()) - 1);
0151 
0152       double normalization(ecaldqm::nCrystals(iDCC + 1));
0153       if (normalization < 1.)
0154         continue;
0155 
0156       MEs_[kEENonFatal]->Fill(iDCC + 601.5, 1. / normalization);
0157     }
0158   }
0159 
0160   if ((SUBDET == EcalBarrel || SUBDET < 0) && _evt.getByToken(ebGainSwitchErrorsToken_, ebHndl)) {
0161     EBDetIdCollection::const_iterator ebEnd(ebHndl->end());
0162     for (EBDetIdCollection::const_iterator ebItr(ebHndl->begin()); ebItr != ebEnd; ++ebItr) {
0163       unsigned iDCC(ecaldqm::dccId(*ebItr, GetElectronicsMap()) - 1);
0164 
0165       double normalization(ecaldqm::nCrystals(iDCC + 1));
0166       if (normalization < 1.)
0167         continue;
0168 
0169       MEs_[kEBNonFatal]->Fill(iDCC + 601.5, 1. / normalization);
0170     }
0171   }
0172   if ((SUBDET == EcalEndcap || SUBDET < 0) && _evt.getByToken(eeGainSwitchErrorsToken_, eeHndl)) {
0173     EEDetIdCollection::const_iterator eeEnd(eeHndl->end());
0174     for (EEDetIdCollection::const_iterator eeItr(eeHndl->begin()); eeItr != eeEnd; ++eeItr) {
0175       unsigned iDCC(ecaldqm::dccId(*eeItr, GetElectronicsMap()) - 1);
0176 
0177       double normalization(ecaldqm::nCrystals(iDCC + 1));
0178       if (normalization < 1.)
0179         continue;
0180 
0181       MEs_[kEENonFatal]->Fill(iDCC + 601.5, 1. / normalization);
0182     }
0183   }
0184 
0185   if (_evt.getByToken(towerIdErrorsToken_, eleHndl)) {
0186     EcalElectronicsIdCollection::const_iterator eleEnd(eleHndl->end());
0187     for (EcalElectronicsIdCollection::const_iterator eleItr(eleHndl->begin()); eleItr != eleEnd; ++eleItr) {
0188       unsigned iDCC(eleItr->dccId() - 1);
0189 
0190       unsigned nonfatal(-1);
0191       if ((SUBDET == EcalBarrel || SUBDET < 0) && iDCC >= ecaldqm::kEBmLow && iDCC <= ecaldqm::kEBpHigh)
0192         nonfatal = kEBNonFatal;
0193       else if ((SUBDET == EcalEndcap || SUBDET < 0) && (iDCC <= ecaldqm::kEEmHigh || iDCC >= ecaldqm::kEEpLow))
0194         nonfatal = kEENonFatal;
0195       else
0196         continue;
0197 
0198       double normalization(ecaldqm::nCrystals(iDCC + 1));
0199       if (normalization < 1.)
0200         continue;
0201 
0202       MEs_[nonfatal]->Fill(iDCC + 601.5, 25. / normalization);
0203     }
0204   }
0205 
0206   if (_evt.getByToken(blockSizeErrorsToken_, eleHndl)) {
0207     EcalElectronicsIdCollection::const_iterator eleEnd(eleHndl->end());
0208     for (EcalElectronicsIdCollection::const_iterator eleItr(eleHndl->begin()); eleItr != eleEnd; ++eleItr) {
0209       unsigned iDCC(eleItr->dccId() - 1);
0210 
0211       unsigned nonfatal(-1);
0212       if ((SUBDET == EcalBarrel || SUBDET < 0) && iDCC >= ecaldqm::kEBmLow && iDCC <= ecaldqm::kEBpHigh)
0213         nonfatal = kEBNonFatal;
0214       else if ((SUBDET == EcalEndcap || SUBDET < 0) && (iDCC <= ecaldqm::kEEmHigh || iDCC >= ecaldqm::kEEpLow))
0215         nonfatal = kEENonFatal;
0216       else
0217         continue;
0218 
0219       double normalization(ecaldqm::nCrystals(iDCC + 1));
0220       if (normalization < 1.)
0221         continue;
0222 
0223       MEs_[nonfatal]->Fill(iDCC + 601.5, 25. / normalization);
0224     }
0225   }
0226 }
0227 
0228 template <int SUBDET>
0229 void EcalFEDMonitorTemp<SUBDET>::setElectronicsMap(edm::EventSetup const& _es) {
0230   electronicsMap = &_es.getData(elecMapHandle);
0231 }
0232 
0233 template <int SUBDET>
0234 EcalElectronicsMapping const* EcalFEDMonitorTemp<SUBDET>::GetElectronicsMap() {
0235   if (!electronicsMap)
0236     throw cms::Exception("InvalidCall") << "Electronics Mapping not initialized";
0237   return electronicsMap;
0238 }
0239 
0240 typedef EcalFEDMonitorTemp<EcalBarrel> EBHltTask;
0241 typedef EcalFEDMonitorTemp<EcalEndcap> EEHltTask;
0242 typedef EcalFEDMonitorTemp<-1> EcalFEDMonitor;
0243 
0244 DEFINE_FWK_MODULE(EBHltTask);
0245 DEFINE_FWK_MODULE(EEHltTask);
0246 DEFINE_FWK_MODULE(EcalFEDMonitor);