File indexing completed on 2024-04-06 12:08:00
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include "DQM/L1TMonitorClient/interface/L1TEventInfoClient.h"
0015
0016
0017 #include <cstdio>
0018 #include <sstream>
0019 #include <fstream>
0020 #include <iostream>
0021 #include <iomanip>
0022
0023 #include <cmath>
0024 #include <memory>
0025
0026 #include <vector>
0027 #include <string>
0028
0029
0030 #include "FWCore/ServiceRegistry/interface/Service.h"
0031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0032 #include "FWCore/Framework/interface/EventSetup.h"
0033 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0034 #include "FWCore/Utilities/interface/Exception.h"
0035
0036 #include "DQMServices/Core/interface/DQMStore.h"
0037
0038 #include <TH2F.h>
0039 #include "TROOT.h"
0040
0041
0042 L1TEventInfoClient::L1TEventInfoClient(const edm::ParameterSet& parSet)
0043 : m_verbose(parSet.getUntrackedParameter<bool>("verbose", false)),
0044 m_monitorDir(parSet.getUntrackedParameter<std::string>("monitorDir", "")),
0045 m_runInEventLoop(parSet.getUntrackedParameter<bool>("runInEventLoop", false)),
0046 m_runInEndLumi(parSet.getUntrackedParameter<bool>("runInEndLumi", false)),
0047 m_runInEndRun(parSet.getUntrackedParameter<bool>("runInEndRun", false)),
0048 m_runInEndJob(parSet.getUntrackedParameter<bool>("runInEndJob", false)),
0049 m_l1Systems(parSet.getParameter<std::vector<edm::ParameterSet> >("L1Systems")),
0050 m_l1Objects(parSet.getParameter<std::vector<edm::ParameterSet> >("L1Objects")),
0051 m_disableL1Systems(parSet.getParameter<std::vector<std::string> >("DisableL1Systems")),
0052 m_disableL1Objects(parSet.getParameter<std::vector<std::string> >("DisableL1Objects")),
0053 m_nrL1Systems(0),
0054 m_nrL1Objects(0),
0055 m_totalNrQtSummaryEnabled(0) {
0056 initialize();
0057 }
0058
0059
0060 L1TEventInfoClient::~L1TEventInfoClient() {
0061
0062 }
0063
0064 void L1TEventInfoClient::initialize() {
0065 if (m_verbose) {
0066 std::cout << "\nMonitor directory = " << m_monitorDir << std::endl;
0067 }
0068
0069
0070
0071 m_nrL1Systems = m_l1Systems.size();
0072
0073 m_systemLabel.reserve(m_nrL1Systems);
0074 m_systemLabelExt.reserve(m_nrL1Systems);
0075 m_systemDisable.reserve(m_nrL1Systems);
0076
0077
0078 m_systemQualityTestName.reserve(5 * m_nrL1Systems);
0079 m_systemQualityTestHist.reserve(5 * m_nrL1Systems);
0080 m_systemQtSummaryEnabled.reserve(5 * m_nrL1Systems);
0081
0082 int indexSys = 0;
0083
0084 int totalNrQualityTests = 0;
0085
0086 for (std::vector<edm::ParameterSet>::const_iterator itSystem = m_l1Systems.begin(); itSystem != m_l1Systems.end();
0087 ++itSystem) {
0088 m_systemLabel.push_back(itSystem->getParameter<std::string>("SystemLabel"));
0089
0090 m_systemLabelExt.push_back(itSystem->getParameter<std::string>("HwValLabel"));
0091
0092 m_systemDisable.push_back(itSystem->getParameter<unsigned int>("SystemDisable"));
0093
0094 for (std::vector<std::string>::const_iterator itSys = m_disableL1Systems.begin(); itSys != m_disableL1Systems.end();
0095 ++itSys) {
0096 if (*itSys == m_systemLabel[indexSys]) {
0097 m_systemDisable[indexSys] = 1;
0098 }
0099 }
0100
0101 std::vector<edm::ParameterSet> qTests = itSystem->getParameter<std::vector<edm::ParameterSet> >("QualityTests");
0102 size_t qtPerSystem = qTests.size();
0103
0104 std::vector<std::string> qtNames;
0105 qtNames.reserve(qtPerSystem);
0106
0107 std::vector<std::string> qtFullPathHists;
0108 qtFullPathHists.reserve(qtPerSystem);
0109
0110 std::vector<unsigned int> qtSumEnabled;
0111 qtSumEnabled.reserve(qtPerSystem);
0112
0113 for (std::vector<edm::ParameterSet>::const_iterator itQT = qTests.begin(); itQT != qTests.end(); ++itQT) {
0114 totalNrQualityTests++;
0115
0116 qtNames.push_back(itQT->getParameter<std::string>("QualityTestName"));
0117
0118 qtFullPathHists.push_back(itQT->getParameter<std::string>("QualityTestHist"));
0119
0120 unsigned int qtEnabled = itQT->getParameter<unsigned int>("QualityTestSummaryEnabled");
0121
0122 qtSumEnabled.push_back(qtEnabled);
0123
0124 if (qtEnabled) {
0125 m_totalNrQtSummaryEnabled++;
0126 }
0127 }
0128
0129 m_systemQualityTestName.push_back(qtNames);
0130 m_systemQualityTestHist.push_back(qtFullPathHists);
0131 m_systemQtSummaryEnabled.push_back(qtSumEnabled);
0132
0133 indexSys++;
0134 }
0135
0136
0137
0138
0139 m_nrL1Objects = m_l1Objects.size();
0140
0141 m_objectLabel.reserve(m_nrL1Objects);
0142 m_objectDisable.reserve(m_nrL1Objects);
0143
0144
0145 m_objectQualityTestName.reserve(5 * m_nrL1Objects);
0146 m_objectQualityTestHist.reserve(5 * m_nrL1Objects);
0147 m_objectQtSummaryEnabled.reserve(5 * m_nrL1Objects);
0148
0149 int indexObj = 0;
0150
0151 for (std::vector<edm::ParameterSet>::const_iterator itObject = m_l1Objects.begin(); itObject != m_l1Objects.end();
0152 ++itObject) {
0153 m_objectLabel.push_back(itObject->getParameter<std::string>("ObjectLabel"));
0154
0155 m_objectDisable.push_back(itObject->getParameter<unsigned int>("ObjectDisable"));
0156
0157 for (std::vector<std::string>::const_iterator itObj = m_disableL1Objects.begin(); itObj != m_disableL1Objects.end();
0158 ++itObj) {
0159 if (*itObj == m_objectLabel[indexObj]) {
0160 m_objectDisable[indexObj] = 1;
0161 }
0162 }
0163
0164 std::vector<edm::ParameterSet> qTests = itObject->getParameter<std::vector<edm::ParameterSet> >("QualityTests");
0165 size_t qtPerObject = qTests.size();
0166
0167 std::vector<std::string> qtNames;
0168 qtNames.reserve(qtPerObject);
0169
0170 std::vector<std::string> qtFullPathHists;
0171 qtFullPathHists.reserve(qtPerObject);
0172
0173 std::vector<unsigned int> qtSumEnabled;
0174 qtSumEnabled.reserve(qtPerObject);
0175
0176 for (std::vector<edm::ParameterSet>::const_iterator itQT = qTests.begin(); itQT != qTests.end(); ++itQT) {
0177 totalNrQualityTests++;
0178
0179 qtNames.push_back(itQT->getParameter<std::string>("QualityTestName"));
0180
0181 qtFullPathHists.push_back(itQT->getParameter<std::string>("QualityTestHist"));
0182
0183 unsigned int qtEnabled = itQT->getParameter<unsigned int>("QualityTestSummaryEnabled");
0184
0185 qtSumEnabled.push_back(qtEnabled);
0186
0187 if (qtEnabled) {
0188 m_totalNrQtSummaryEnabled++;
0189 }
0190 }
0191
0192 m_objectQualityTestName.push_back(qtNames);
0193 m_objectQualityTestHist.push_back(qtFullPathHists);
0194 m_objectQtSummaryEnabled.push_back(qtSumEnabled);
0195
0196 indexObj++;
0197 }
0198
0199 m_summaryContent.reserve(m_nrL1Systems + m_nrL1Objects);
0200 m_meReportSummaryContent.reserve(totalNrQualityTests);
0201 }
0202
0203 void L1TEventInfoClient::dqmEndLuminosityBlock(DQMStore::IBooker& ibooker,
0204 DQMStore::IGetter& igetter,
0205 const edm::LuminosityBlock& lumiSeg,
0206 const edm::EventSetup& evSetup) {
0207 if (m_runInEndLumi) {
0208 book(ibooker, igetter);
0209 readQtResults(ibooker, igetter);
0210
0211 if (m_verbose) {
0212 std::cout << "\n L1TEventInfoClient::endLuminosityBlock\n" << std::endl;
0213 dumpContentMonitorElements(ibooker, igetter);
0214 }
0215 }
0216 }
0217
0218 void L1TEventInfoClient::dqmEndJob(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter) {
0219 book(ibooker, igetter);
0220
0221 readQtResults(ibooker, igetter);
0222
0223 if (m_verbose) {
0224 std::cout << "\n L1TEventInfoClient::endRun\n" << std::endl;
0225 dumpContentMonitorElements(ibooker, igetter);
0226 }
0227 }
0228
0229 void L1TEventInfoClient::dumpContentMonitorElements(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter) {
0230 std::cout << "\nSummary report " << std::endl;
0231
0232
0233
0234 MonitorElement* me = igetter.get(m_meReportSummaryMap->getName());
0235
0236 std::cout << "\nSummary content per system and object as filled in histogram\n " << m_meReportSummaryMap->getName()
0237 << std::endl;
0238
0239 if (!me) {
0240 std::cout << "\nNo histogram " << m_meReportSummaryMap->getName()
0241 << "\nNo summary content per system and object as filled in histogram.\n " << std::endl;
0242 return;
0243 }
0244
0245 TH2F* hist = me->getTH2F();
0246
0247 const int nBinsX = hist->GetNbinsX();
0248 const int nBinsY = hist->GetNbinsY();
0249 std::cout << nBinsX << " " << nBinsY;
0250
0251 std::vector<std::vector<int> > meReportSummaryMap(nBinsX, std::vector<int>(nBinsY));
0252
0253
0254
0255
0256
0257
0258
0259
0260 std::cout << "\nL1 systems: " << m_nrL1Systems << " systems included\n"
0261 << "\n Summary content size: " << (m_summaryContent.size()) << std::endl;
0262
0263 for (unsigned int iSys = 0; iSys < m_nrL1Systems; ++iSys) {
0264 std::cout << std::setw(10) << m_systemLabel[iSys] << std::setw(10) << m_systemLabelExt[iSys] << " \t"
0265 << m_systemDisable[iSys] << " \t" << std::setw(25) << " m_summaryContent[" << std::setw(2) << iSys
0266 << "] = " << meReportSummaryMap[0][iSys] << std::endl;
0267 }
0268
0269 std::cout << "\n L1 trigger objects: " << m_nrL1Objects << " objects included\n" << std::endl;
0270
0271 for (unsigned int iMon = m_nrL1Systems; iMon < m_nrL1Systems + m_nrL1Objects; ++iMon) {
0272 std::cout << std::setw(20) << m_objectLabel[iMon - m_nrL1Systems] << " \t" << m_objectDisable[iMon - m_nrL1Systems]
0273 << " \t" << std::setw(25) << " m_summaryContent[" << std::setw(2) << iMon << "] = \t"
0274 << m_summaryContent[iMon] << std::endl;
0275 }
0276
0277 std::cout << std::endl;
0278
0279
0280
0281 std::cout << "\nQuality test results as filled in "
0282 << "\n " << m_monitorDir << "/EventInfo/reportSummaryContents\n"
0283 << "\n Total number of quality tests: " << (m_meReportSummaryContent.size()) << "\n"
0284 << std::endl;
0285
0286 for (std::vector<MonitorElement*>::const_iterator itME = m_meReportSummaryContent.begin();
0287 itME != m_meReportSummaryContent.end();
0288 ++itME) {
0289 std::cout << std::setw(50) << (*itME)->getName() << " \t" << std::setw(25) << (*itME)->getFloatValue() << std::endl;
0290 }
0291
0292 std::cout << std::endl;
0293 }
0294
0295 void L1TEventInfoClient::book(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter) {
0296 std::string dirEventInfo = m_monitorDir + "/EventInfo";
0297
0298 ibooker.setCurrentFolder(dirEventInfo);
0299
0300
0301 m_meReportSummary = ibooker.bookFloat("reportSummary");
0302
0303
0304
0305 if (m_meReportSummary) {
0306 m_meReportSummary->Fill(1);
0307 }
0308
0309
0310
0311
0312
0313 ibooker.setCurrentFolder(dirEventInfo + "/reportSummaryContents");
0314
0315
0316 int iAllQTest = 0;
0317
0318 for (unsigned int iMon = 0; iMon < m_nrL1Systems; ++iMon) {
0319 m_summaryContent.push_back(dqm::qstatus::DISABLED);
0320
0321 const std::vector<std::string>& sysQtName = m_systemQualityTestName[iMon];
0322
0323 for (std::vector<std::string>::const_iterator itQtName = sysQtName.begin(); itQtName != sysQtName.end();
0324 ++itQtName) {
0325 const std::string hStr = m_monitorDir + "_L1Sys_" + m_systemLabel[iMon] + "_" + (*itQtName);
0326
0327 m_meReportSummaryContent.push_back(ibooker.bookFloat(hStr));
0328 m_meReportSummaryContent[iAllQTest]->Fill(0.);
0329
0330 iAllQTest++;
0331 }
0332 }
0333
0334 for (unsigned int iMon = 0; iMon < m_nrL1Objects; ++iMon) {
0335 m_summaryContent.push_back(dqm::qstatus::DISABLED);
0336
0337 const std::vector<std::string>& objQtName = m_objectQualityTestName[iMon];
0338
0339 for (std::vector<std::string>::const_iterator itQtName = objQtName.begin(); itQtName != objQtName.end();
0340 ++itQtName) {
0341 const std::string hStr = m_monitorDir + "_L1Obj_" + m_objectLabel[iMon] + "_" + (*itQtName);
0342
0343 m_meReportSummaryContent.push_back(ibooker.bookFloat(hStr));
0344 m_meReportSummaryContent[iAllQTest]->Fill(0.);
0345
0346 iAllQTest++;
0347 }
0348 }
0349
0350 ibooker.setCurrentFolder(dirEventInfo);
0351
0352
0353
0354 int nBinsY = std::max(m_nrL1Systems, m_nrL1Objects);
0355
0356 m_meReportSummaryMap = ibooker.book2D("reportSummaryMap", "reportSummaryMap", 2, 1, 3, nBinsY, 1, nBinsY + 1);
0357
0358 if (m_monitorDir == "L1TEMU") {
0359 m_meReportSummaryMap->setTitle("L1TEMU: L1 Emulator vs Data Report Summary Map");
0360
0361 } else if (m_monitorDir == "L1T") {
0362 m_meReportSummaryMap->setTitle("L1T: L1 Trigger Data Report Summary Map");
0363 } else {
0364
0365 }
0366
0367 m_meReportSummaryMap->setAxisTitle("", 1);
0368 m_meReportSummaryMap->setAxisTitle("", 2);
0369
0370 m_meReportSummaryMap->setBinLabel(1, "L1 systems", 1);
0371 m_meReportSummaryMap->setBinLabel(2, "L1 objects", 1);
0372
0373 for (int iBin = 0; iBin < nBinsY; ++iBin) {
0374 m_meReportSummaryMap->setBinLabel(iBin + 1, " ", 2);
0375 }
0376 }
0377
0378 void L1TEventInfoClient::readQtResults(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter) {
0379
0380
0381
0382 for (std::vector<int>::iterator it = m_summaryContent.begin(); it != m_summaryContent.end(); ++it) {
0383 (*it) = dqm::qstatus::DISABLED;
0384 }
0385
0386 m_summarySum = 0.;
0387
0388 for (std::vector<MonitorElement*>::iterator itME = m_meReportSummaryContent.begin();
0389 itME != m_meReportSummaryContent.end();
0390 ++itME) {
0391 (*itME)->Fill(0.);
0392 }
0393
0394
0395
0396
0397 int iAllQTest = 0;
0398 int iAllMon = 0;
0399
0400
0401
0402 for (unsigned int iSys = 0; iSys < m_nrL1Systems; ++iSys) {
0403
0404
0405 const std::vector<std::string>& sysQtName = m_systemQualityTestName[iSys];
0406 const std::vector<std::string>& sysQtHist = m_systemQualityTestHist[iSys];
0407 const std::vector<unsigned int>& sysQtSummaryEnabled = m_systemQtSummaryEnabled[iSys];
0408
0409
0410 int iSysQTest = 0;
0411
0412 for (std::vector<std::string>::const_iterator itQtName = sysQtName.begin(); itQtName != sysQtName.end();
0413 ++itQtName) {
0414
0415
0416 MonitorElement* qHist = igetter.get(sysQtHist[iSysQTest]);
0417
0418 if (qHist) {
0419 const std::vector<QReport*> qtVec = qHist->getQReports();
0420
0421 if (m_verbose) {
0422 std::cout << "\nNumber of quality tests "
0423 << " for histogram " << sysQtHist[iSysQTest] << ": " << qtVec.size() << "\n"
0424 << std::endl;
0425 }
0426
0427 const QReport* sysQReport = qHist->getQReport(*itQtName);
0428 if (sysQReport) {
0429 const float sysQtResult = sysQReport->getQTresult();
0430 const int sysQtStatus = sysQReport->getStatus();
0431 const std::string& sysQtMessage = sysQReport->getMessage();
0432
0433 if (m_verbose) {
0434 std::cout << "\n"
0435 << (*itQtName) << " quality test:"
0436 << "\n result: " << sysQtResult << "\n status: " << sysQtStatus
0437 << "\n message: " << sysQtMessage << "\n"
0438 << "\nFilling m_meReportSummaryContent[" << iAllQTest << "] with value " << sysQtResult << "\n"
0439 << std::endl;
0440 }
0441
0442 m_meReportSummaryContent[iAllQTest]->Fill(sysQtResult);
0443
0444
0445
0446 if (sysQtSummaryEnabled[iSysQTest]) {
0447 if (sysQtStatus > m_summaryContent[iAllMon]) {
0448 m_summaryContent[iAllMon] = sysQtStatus;
0449 }
0450
0451 m_summarySum += sysQtResult;
0452 }
0453
0454 } else {
0455
0456
0457
0458 int sysQtStatus = dqm::qstatus::INVALID;
0459
0460 if (sysQtSummaryEnabled[iSysQTest]) {
0461 if (sysQtStatus > m_summaryContent[iAllMon]) {
0462 m_summaryContent[iAllMon] = sysQtStatus;
0463 }
0464 }
0465
0466 m_meReportSummaryContent[iAllQTest]->Fill(0.);
0467
0468 if (m_verbose) {
0469 std::cout << "\n" << (*itQtName) << " quality test not found\n" << std::endl;
0470 }
0471 }
0472
0473 } else {
0474
0475
0476
0477 int sysQtStatus = dqm::qstatus::INVALID;
0478
0479 if (sysQtSummaryEnabled[iSysQTest]) {
0480 if (sysQtStatus > m_summaryContent[iAllMon]) {
0481 m_summaryContent[iAllMon] = sysQtStatus;
0482 }
0483 }
0484
0485 m_meReportSummaryContent[iAllQTest]->Fill(0.);
0486
0487 if (m_verbose) {
0488 std::cout << "\nHistogram " << sysQtHist[iSysQTest] << " not found\n" << std::endl;
0489 }
0490 }
0491
0492
0493 iSysQTest++;
0494 iAllQTest++;
0495 }
0496
0497 iAllMon++;
0498 }
0499
0500
0501
0502 for (unsigned int iObj = 0; iObj < m_nrL1Objects; ++iObj) {
0503
0504
0505 const std::vector<std::string>& objQtName = m_objectQualityTestName[iObj];
0506 const std::vector<std::string>& objQtHist = m_objectQualityTestHist[iObj];
0507 const std::vector<unsigned int>& objQtSummaryEnabled = m_objectQtSummaryEnabled[iObj];
0508
0509
0510 int iObjQTest = 0;
0511
0512 for (std::vector<std::string>::const_iterator itQtName = objQtName.begin(); itQtName != objQtName.end();
0513 ++itQtName) {
0514
0515
0516 MonitorElement* qHist = igetter.get(objQtHist[iObjQTest]);
0517
0518 if (qHist) {
0519 const std::vector<QReport*> qtVec = qHist->getQReports();
0520
0521 if (m_verbose) {
0522 std::cout << "\nNumber of quality tests "
0523 << " for histogram " << objQtHist[iObjQTest] << ": " << qtVec.size() << "\n"
0524 << std::endl;
0525 }
0526
0527 const QReport* objQReport = qHist->getQReport(*itQtName);
0528 if (objQReport) {
0529 const float objQtResult = objQReport->getQTresult();
0530 const int objQtStatus = objQReport->getStatus();
0531 const std::string& objQtMessage = objQReport->getMessage();
0532
0533 if (m_verbose) {
0534 std::cout << "\n"
0535 << (*itQtName) << " quality test:"
0536 << "\n result: " << objQtResult << "\n status: " << objQtStatus
0537 << "\n message: " << objQtMessage << "\n"
0538 << "\nFilling m_meReportSummaryContent[" << iAllQTest << "] with value " << objQtResult << "\n"
0539 << std::endl;
0540 }
0541
0542 m_meReportSummaryContent[iAllQTest]->Fill(objQtResult);
0543
0544
0545
0546 if (objQtSummaryEnabled[iObjQTest]) {
0547 if (objQtStatus > m_summaryContent[iAllMon]) {
0548 m_summaryContent[iAllMon] = objQtStatus;
0549 }
0550
0551 m_summarySum += objQtResult;
0552 }
0553
0554 } else {
0555
0556
0557
0558 int objQtStatus = dqm::qstatus::INVALID;
0559
0560 if (objQtSummaryEnabled[iObjQTest]) {
0561 if (objQtStatus > m_summaryContent[iAllMon]) {
0562 m_summaryContent[iAllMon] = objQtStatus;
0563 }
0564 }
0565
0566 m_meReportSummaryContent[iAllQTest]->Fill(0.);
0567
0568 if (m_verbose) {
0569 std::cout << "\n" << (*itQtName) << " quality test not found\n" << std::endl;
0570 }
0571 }
0572
0573 } else {
0574
0575
0576
0577 int objQtStatus = dqm::qstatus::INVALID;
0578
0579 if (objQtSummaryEnabled[iObjQTest]) {
0580 if (objQtStatus > m_summaryContent[iAllMon]) {
0581 m_summaryContent[iAllMon] = objQtStatus;
0582 }
0583 }
0584
0585 m_meReportSummaryContent[iAllQTest]->Fill(0.);
0586
0587 if (m_verbose) {
0588 std::cout << "\nHistogram " << objQtHist[iObjQTest] << " not found\n" << std::endl;
0589 }
0590 }
0591
0592
0593 iObjQTest++;
0594 iAllQTest++;
0595 }
0596
0597 iAllMon++;
0598 }
0599
0600
0601 m_reportSummary = m_summarySum / float(m_totalNrQtSummaryEnabled);
0602 if (m_meReportSummary) {
0603 m_meReportSummary->Fill(m_reportSummary);
0604 }
0605
0606
0607 for (unsigned int iSys = 0; iSys < m_nrL1Systems; ++iSys) {
0608 double summCont = static_cast<double>(m_summaryContent[iSys]);
0609 m_meReportSummaryMap->setBinContent(1, iSys + 1, summCont);
0610 }
0611
0612
0613 for (unsigned int iMon = m_nrL1Systems; iMon < m_nrL1Systems + m_nrL1Objects; ++iMon) {
0614 double summCont = static_cast<double>(m_summaryContent[iMon]);
0615 m_meReportSummaryMap->setBinContent(2, iMon - m_nrL1Systems + 1, summCont);
0616 }
0617 }