Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:10:49

0001 #include "DQM/L1TMonitorClient/interface/L1EmulatorErrorFlagClient.h"
0002 
0003 #include "FWCore/ServiceRegistry/interface/Service.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "FWCore/Framework/interface/ESHandle.h"
0006 #include "FWCore/Framework/interface/EventSetup.h"
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 #include "DQMServices/Core/interface/DQMStore.h"
0009 #include "TRandom.h"
0010 #include <TF1.h>
0011 #include <cstdio>
0012 #include <sstream>
0013 #include <cmath>
0014 #include <TProfile.h>
0015 #include <TProfile2D.h>
0016 #include <memory>
0017 #include <iostream>
0018 #include <vector>
0019 #include <iomanip>
0020 #include <string>
0021 #include <fstream>
0022 #include "TROOT.h"
0023 
0024 L1EmulatorErrorFlagClient::L1EmulatorErrorFlagClient(const edm::ParameterSet& parSet)
0025     : m_verbose(parSet.getUntrackedParameter<bool>("verbose", false)),
0026       m_l1Systems(parSet.getParameter<std::vector<edm::ParameterSet> >("L1Systems")),
0027       m_nrL1Systems(0) {
0028   initialize();
0029 }
0030 
0031 L1EmulatorErrorFlagClient::~L1EmulatorErrorFlagClient() {
0032   //empty
0033 }
0034 
0035 void L1EmulatorErrorFlagClient::initialize() {
0036   m_nrL1Systems = m_l1Systems.size();
0037 
0038   m_systemLabel.reserve(m_nrL1Systems);
0039   m_systemLabelExt.reserve(m_nrL1Systems);
0040   m_systemMask.reserve(m_nrL1Systems);
0041   m_systemFolder.reserve(m_nrL1Systems);
0042   m_systemErrorFlag.reserve(m_nrL1Systems);
0043 
0044   int indexSys = 0;
0045 
0046   for (std::vector<edm::ParameterSet>::const_iterator itSystem = m_l1Systems.begin(); itSystem != m_l1Systems.end();
0047        ++itSystem) {
0048     m_systemLabel.push_back(itSystem->getParameter<std::string>("SystemLabel"));
0049 
0050     m_systemLabelExt.push_back(itSystem->getParameter<std::string>("HwValLabel"));
0051 
0052     m_systemMask.push_back(itSystem->getParameter<unsigned int>("SystemMask"));
0053 
0054     m_systemFolder.push_back(itSystem->getParameter<std::string>("SystemFolder"));
0055 
0056     indexSys++;
0057   }
0058 
0059   // [SYS]ErrorFlag histogram
0060   for (unsigned int iSys = 0; iSys < m_nrL1Systems; ++iSys) {
0061     if (m_systemFolder[iSys].empty()) {
0062       m_systemErrorFlag.push_back("L1TEMU/" + m_systemLabel[iSys] + "/" + m_systemLabelExt[iSys] + "ErrorFlag");
0063     } else {
0064       m_systemErrorFlag.push_back(m_systemFolder[iSys] + "/" + m_systemLabelExt[iSys] + "ErrorFlag");
0065     }
0066   }
0067 
0068   m_summaryContent.reserve(m_nrL1Systems);
0069 }
0070 
0071 void L1EmulatorErrorFlagClient::dqmEndJob(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter) {
0072   ibooker.setCurrentFolder("L1TEMU/EventInfo");
0073 
0074   // define a histogram
0075   m_meSummaryErrorFlagMap =
0076       ibooker.book1D("L1SummaryErrorFlagMap", "L1SummaryErrorFlagMap", m_nrL1Systems, 1, m_nrL1Systems + 1);
0077 
0078   m_meSummaryErrorFlagMap->setAxisTitle("Agreement fraction", 2);
0079 
0080   for (unsigned int iSys = 0; iSys < m_nrL1Systems; ++iSys) {
0081     m_meSummaryErrorFlagMap->setBinLabel(iSys + 1, m_systemLabel[iSys], 1);
0082   }
0083 }
0084 
0085 void L1EmulatorErrorFlagClient::dqmEndLuminosityBlock(DQMStore::IBooker& ibooker,
0086                                                       DQMStore::IGetter& igetter,
0087                                                       const edm::LuminosityBlock& lumiSeg,
0088                                                       const edm::EventSetup& evSetup) {
0089   // reset the summary content values
0090   for (unsigned int iMon = 0; iMon < m_nrL1Systems; ++iMon) {
0091     m_summaryContent[iMon] = 0.;
0092   }
0093 
0094   // for masked systems and objects, set the summary content to -1
0095 
0096   for (unsigned int iMon = 0; iMon < m_nrL1Systems; ++iMon) {
0097     if (m_systemMask[iMon] != 0) {
0098       m_summaryContent[iMon] = -1;
0099     }
0100   }
0101 
0102   // then fill content for unmasked systems
0103 
0104   for (unsigned int iSys = 0; iSys < m_nrL1Systems; ++iSys) {
0105     float percAgree = -1.;
0106 
0107     if (m_systemMask[iSys] == 0) {
0108       percAgree = setSummary(igetter, iSys);
0109 
0110       if ((percAgree == -1) && m_verbose) {
0111         std::cout << "\nWarning: ErrorFlag histogram for system " << m_systemLabel[iSys] << " empty!" << std::endl;
0112       }
0113     }
0114 
0115     m_summaryContent[iSys] = percAgree;
0116   }
0117 
0118   int numUnMaskedSystems = 0;
0119   for (unsigned int iMon = 0; iMon < m_nrL1Systems; iMon++) {
0120     if (m_summaryContent[iMon] != -1) {
0121       numUnMaskedSystems++;
0122     }
0123   }
0124 
0125   // fill the SummaryErrorFlagMap histogram for L1 systems
0126   // (bin 0 - underflow, bin iSys + 1 overflow)
0127   for (unsigned int iSys = 0; iSys < m_nrL1Systems; ++iSys) {
0128     m_meSummaryErrorFlagMap->setBinContent(iSys + 1, m_summaryContent[iSys]);
0129   }
0130 
0131   if (m_verbose) {
0132     std::cout << "\nSummary report L1EmulatorErrorFlagClient" << std::endl;
0133 
0134     std::cout << "\nL1 systems: " << m_nrL1Systems << " systems included\n" << std::endl;
0135 
0136     for (unsigned int iSys = 0; iSys < m_nrL1Systems; ++iSys) {
0137       std::cout << std::setw(10) << m_systemLabel[iSys] << std::setw(10) << m_systemLabelExt[iSys] << " \t"
0138                 << m_systemMask[iSys] << " \t" << std::setw(25) << " m_summaryContent[" << std::setw(2) << iSys
0139                 << "] = " << m_summaryContent[iSys] << std::endl;
0140     }
0141   }
0142 }
0143 
0144 // set subsystem agreement value in summary map
0145 Float_t L1EmulatorErrorFlagClient::setSummary(DQMStore::IGetter& igetter, const unsigned int& iMon) const {
0146   MonitorElement* QHist = igetter.get(m_systemErrorFlag[iMon]);
0147 
0148   int ntot = 0;
0149   for (int i = 0; i < QHist->getNbinsX(); i++) {
0150     ntot += QHist->getBinContent(i + 1);
0151   }
0152 
0153   bool isEmpty = (ntot == 0);
0154 
0155   //errflag bins: agree, loc agree, loc disagree, data only, emul only
0156 
0157   return isEmpty ? -1. : ((QHist->getBinContent(1)) / (ntot));
0158 }