Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:42:44

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   for (std::vector<edm::ParameterSet>::const_iterator itSystem = m_l1Systems.begin(); itSystem != m_l1Systems.end();
0045        ++itSystem) {
0046     m_systemLabel.push_back(itSystem->getParameter<std::string>("SystemLabel"));
0047 
0048     m_systemLabelExt.push_back(itSystem->getParameter<std::string>("HwValLabel"));
0049 
0050     m_systemMask.push_back(itSystem->getParameter<unsigned int>("SystemMask"));
0051 
0052     m_systemFolder.push_back(itSystem->getParameter<std::string>("SystemFolder"));
0053   }
0054 
0055   // [SYS]ErrorFlag histogram
0056   for (unsigned int iSys = 0; iSys < m_nrL1Systems; ++iSys) {
0057     if (m_systemFolder[iSys].empty()) {
0058       m_systemErrorFlag.push_back("L1TEMU/" + m_systemLabel[iSys] + "/" + m_systemLabelExt[iSys] + "ErrorFlag");
0059     } else {
0060       m_systemErrorFlag.push_back(m_systemFolder[iSys] + "/" + m_systemLabelExt[iSys] + "ErrorFlag");
0061     }
0062   }
0063 
0064   m_summaryContent.reserve(m_nrL1Systems);
0065 }
0066 
0067 void L1EmulatorErrorFlagClient::dqmEndJob(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter) {
0068   ibooker.setCurrentFolder("L1TEMU/EventInfo");
0069 
0070   // define a histogram
0071   m_meSummaryErrorFlagMap =
0072       ibooker.book1D("L1SummaryErrorFlagMap", "L1SummaryErrorFlagMap", m_nrL1Systems, 1, m_nrL1Systems + 1);
0073 
0074   m_meSummaryErrorFlagMap->setAxisTitle("Agreement fraction", 2);
0075 
0076   for (unsigned int iSys = 0; iSys < m_nrL1Systems; ++iSys) {
0077     m_meSummaryErrorFlagMap->setBinLabel(iSys + 1, m_systemLabel[iSys], 1);
0078   }
0079 }
0080 
0081 void L1EmulatorErrorFlagClient::dqmEndLuminosityBlock(DQMStore::IBooker& ibooker,
0082                                                       DQMStore::IGetter& igetter,
0083                                                       const edm::LuminosityBlock& lumiSeg,
0084                                                       const edm::EventSetup& evSetup) {
0085   // reset the summary content values
0086   for (unsigned int iMon = 0; iMon < m_nrL1Systems; ++iMon) {
0087     m_summaryContent[iMon] = 0.;
0088   }
0089 
0090   // for masked systems and objects, set the summary content to -1
0091 
0092   for (unsigned int iMon = 0; iMon < m_nrL1Systems; ++iMon) {
0093     if (m_systemMask[iMon] != 0) {
0094       m_summaryContent[iMon] = -1;
0095     }
0096   }
0097 
0098   // then fill content for unmasked systems
0099 
0100   for (unsigned int iSys = 0; iSys < m_nrL1Systems; ++iSys) {
0101     float percAgree = -1.;
0102 
0103     if (m_systemMask[iSys] == 0) {
0104       percAgree = setSummary(igetter, iSys);
0105 
0106       if ((percAgree == -1) && m_verbose) {
0107         std::cout << "\nWarning: ErrorFlag histogram for system " << m_systemLabel[iSys] << " empty!" << std::endl;
0108       }
0109     }
0110 
0111     m_summaryContent[iSys] = percAgree;
0112   }
0113 
0114   // fill the SummaryErrorFlagMap histogram for L1 systems
0115   // (bin 0 - underflow, bin iSys + 1 overflow)
0116   for (unsigned int iSys = 0; iSys < m_nrL1Systems; ++iSys) {
0117     m_meSummaryErrorFlagMap->setBinContent(iSys + 1, m_summaryContent[iSys]);
0118   }
0119 
0120   if (m_verbose) {
0121     std::cout << "\nSummary report L1EmulatorErrorFlagClient" << std::endl;
0122 
0123     std::cout << "\nL1 systems: " << m_nrL1Systems << " systems included\n" << std::endl;
0124 
0125     for (unsigned int iSys = 0; iSys < m_nrL1Systems; ++iSys) {
0126       std::cout << std::setw(10) << m_systemLabel[iSys] << std::setw(10) << m_systemLabelExt[iSys] << " \t"
0127                 << m_systemMask[iSys] << " \t" << std::setw(25) << " m_summaryContent[" << std::setw(2) << iSys
0128                 << "] = " << m_summaryContent[iSys] << std::endl;
0129     }
0130   }
0131 }
0132 
0133 // set subsystem agreement value in summary map
0134 Float_t L1EmulatorErrorFlagClient::setSummary(DQMStore::IGetter& igetter, const unsigned int& iMon) const {
0135   MonitorElement* QHist = igetter.get(m_systemErrorFlag[iMon]);
0136 
0137   int ntot = 0;
0138   for (int i = 0; i < QHist->getNbinsX(); i++) {
0139     ntot += QHist->getBinContent(i + 1);
0140   }
0141 
0142   bool isEmpty = (ntot == 0);
0143 
0144   //errflag bins: agree, loc agree, loc disagree, data only, emul only
0145 
0146   return isEmpty ? -1. : ((QHist->getBinContent(1)) / (ntot));
0147 }