File indexing completed on 2024-04-06 12:09:06
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055 #include "DQM/TrackingMonitor/interface/LogMessageMonitor.h"
0056
0057 #include "DQMServices/Core/interface/DQMStore.h"
0058 #include "DataFormats/Common/interface/Handle.h"
0059
0060 #include "FWCore/MessageLogger/interface/ELseverityLevel.h"
0061 #include "FWCore/MessageLogger/interface/ErrorSummaryEntry.h"
0062 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0063
0064 #include "DQM/TrackingMonitor/interface/GetLumi.h"
0065 #include "CommonTools/TriggerUtils/interface/GenericTriggerEventFlag.h"
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077 LogMessageMonitor::LogMessageMonitor(const edm::ParameterSet& iConfig)
0078 : dqmStore_(edm::Service<DQMStore>().operator->()),
0079 conf_(iConfig),
0080 pluginsMonName_(iConfig.getParameter<std::string>("pluginsMonName")),
0081 modules_vector_(iConfig.getParameter<std::vector<std::string> >("modules")),
0082 categories_vector_(iConfig.getParameter<std::vector<std::string> >("categories")),
0083 doWarningsPlots_(iConfig.getParameter<bool>("doWarningsPlots")),
0084 doPUmonitoring_(iConfig.getParameter<bool>("doPUmonitoring")) {
0085 errorToken_ = consumes<std::vector<edm::ErrorSummaryEntry> >(edm::InputTag("logErrorHarvester"));
0086
0087 edm::ConsumesCollector c{consumesCollector()};
0088
0089 lumiDetails_ = new GetLumi(iConfig.getParameter<edm::ParameterSet>("BXlumiSetup"), c);
0090 genTriggerEventFlag_ = new GenericTriggerEventFlag(
0091 iConfig.getParameter<edm::ParameterSet>("genericTriggerEventPSet"), consumesCollector(), *this);
0092 }
0093
0094 LogMessageMonitor::~LogMessageMonitor() {
0095
0096
0097
0098 if (genTriggerEventFlag_)
0099 delete genTriggerEventFlag_;
0100 }
0101
0102
0103
0104
0105
0106
0107 void LogMessageMonitor::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0108
0109 if (genTriggerEventFlag_->on() && !genTriggerEventFlag_->accept(iEvent, iSetup))
0110 return;
0111
0112 double BXlumi = -1.;
0113 if (doPUmonitoring_)
0114 lumiDetails_->getValue(iEvent);
0115
0116
0117 edm::Handle<std::vector<edm::ErrorSummaryEntry> > errors = iEvent.getHandle(errorToken_);
0118
0119 if (!errors.isValid())
0120 return;
0121
0122
0123 if (errors->empty()) {
0124 if (doPUmonitoring_) {
0125 for (size_t i = 0; i < modulesMap.size(); i++) {
0126 ModulesErrorsVsBXlumi[i]->Fill(BXlumi, 0.);
0127 if (doWarningsPlots_)
0128 ModulesWarningsVsBXlumi[i]->Fill(BXlumi, 0.);
0129 }
0130 }
0131 } else {
0132 size_t nCategories = categories_vector_.size();
0133
0134 for (size_t i = 0, n = errors->size(); i < n; i++) {
0135
0136
0137 std::string s = (*errors)[i].module;
0138 size_t pos = s.find(':');
0139 std::string s_module = s.substr(pos + 1, s.size());
0140 std::map<std::string, int>::const_iterator it = modulesMap.find(s_module);
0141 if (it != modulesMap.end()) {
0142
0143
0144
0145 if ((*errors)[i].severity.getLevel() >= edm::ELseverityLevel::ELsev_error) {
0146 if (doPUmonitoring_)
0147 ModulesErrorsVsBXlumi[it->second]->Fill(BXlumi, (*errors)[i].count);
0148
0149
0150
0151
0152
0153 TString module = it->first;
0154 TString category = (*errors)[i].category;
0155 int ibinX = CategoriesVsModules->getTH1()->GetXaxis()->FindBin(module);
0156 int ibinY = CategoriesVsModules->getTH1()->GetYaxis()->FindBin(category);
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169 if (ibinY > 0) {
0170 int ncount = CategoriesVsModules->getTH1()->GetBinContent(ibinX, ibinY) + 1;
0171 CategoriesVsModules->getTH1()->SetBinContent(ibinX, ibinY, ncount);
0172 } else {
0173 int ncount = CategoriesVsModules->getTH1()->GetBinContent(ibinX, nCategories) + 1;
0174 CategoriesVsModules->getTH1()->SetBinContent(ibinX, nCategories, ncount);
0175 }
0176 } else {
0177
0178 if (doWarningsPlots_)
0179 if (doPUmonitoring_)
0180 ModulesWarningsVsBXlumi[it->second]->Fill(BXlumi, (*errors)[i].count);
0181 }
0182 }
0183 }
0184 }
0185 }
0186
0187 void LogMessageMonitor::bookHistograms(DQMStore::IBooker& ibooker,
0188 edm::Run const& iRun,
0189 edm::EventSetup const& iSetup) {
0190 if (genTriggerEventFlag_->on())
0191 genTriggerEventFlag_->initRun(iRun, iSetup);
0192
0193 std::string MEFolderName = conf_.getParameter<std::string>("LogFolderName");
0194
0195 ibooker.setCurrentFolder(MEFolderName);
0196
0197 categories_vector_.push_back("others");
0198 size_t nModules = modules_vector_.size();
0199 size_t nCategories = categories_vector_.size();
0200
0201 histname = pluginsMonName_ + "ErrorsVsModules";
0202 CategoriesVsModules =
0203 ibooker.book2D(histname, histname, nModules, 0., double(nModules), nCategories, 0., double(nCategories));
0204 CategoriesVsModules->getTH1()->GetXaxis()->SetNoAlphanumeric();
0205 CategoriesVsModules->getTH1()->GetYaxis()->SetNoAlphanumeric();
0206 CategoriesVsModules->setAxisTitle("modules", 1);
0207 for (size_t imodule = 0; imodule < nModules; imodule++)
0208 CategoriesVsModules->setBinLabel(imodule + 1, modules_vector_[imodule], 1);
0209 CategoriesVsModules->setAxisTitle("categories", 2);
0210
0211 for (size_t icategories = 0; icategories < nCategories; icategories++)
0212 CategoriesVsModules->setBinLabel(icategories + 1, categories_vector_[icategories], 2);
0213
0214
0215 for (size_t i = 0; i < modules_vector_.size(); i++) {
0216 modulesMap.insert(std::pair<std::string, int>(modules_vector_[i], i));
0217 }
0218
0219 if (doPUmonitoring_) {
0220
0221
0222 edm::ParameterSet BXlumiParameters = conf_.getParameter<edm::ParameterSet>("BXlumiSetup");
0223 int BXlumiBin = BXlumiParameters.getParameter<int>("BXlumiBin");
0224 double BXlumiMin = BXlumiParameters.getParameter<double>("BXlumiMin");
0225 double BXlumiMax = BXlumiParameters.getParameter<double>("BXlumiMax");
0226
0227 size_t i = 0;
0228 for (std::map<std::string, int>::const_iterator it = modulesMap.begin(); it != modulesMap.end(); ++it, i++) {
0229 ibooker.setCurrentFolder(MEFolderName + "/PUmonitoring/Errors");
0230
0231 histname = "errorsVsBXlumi_" + it->first;
0232 ModulesErrorsVsBXlumi.push_back(dynamic_cast<MonitorElement*>(
0233 ibooker.bookProfile(histname, histname, BXlumiBin, BXlumiMin, BXlumiMax, 0., 100, "")));
0234 ModulesErrorsVsBXlumi[i]->setAxisTitle("BXlumi [10^{30} Hz cm^{-2}]", 1);
0235 ModulesErrorsVsBXlumi[i]->setAxisTitle("Mean number of errors", 2);
0236
0237 if (doWarningsPlots_) {
0238 ibooker.setCurrentFolder(MEFolderName + "/PUmonitoring/Warnings");
0239
0240 histname = "warningVsBXlumi_" + it->first;
0241 ModulesWarningsVsBXlumi.push_back(dynamic_cast<MonitorElement*>(
0242 ibooker.bookProfile(histname, histname, BXlumiBin, BXlumiMin, BXlumiMax, 0., 100, "")));
0243 ModulesWarningsVsBXlumi[i]->setAxisTitle("BXlumi [10^{30} Hz cm^{-2}]", 1);
0244 ModulesWarningsVsBXlumi[i]->setAxisTitle("Mean number of warnings", 2);
0245 }
0246 }
0247 }
0248 }
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259 void LogMessageMonitor::endJob() {
0260 bool outputMEsInRootFile = conf_.getParameter<bool>("OutputMEsInRootFile");
0261 std::string outputFileName = conf_.getParameter<std::string>("OutputFileName");
0262 if (outputMEsInRootFile) {
0263 dqmStore_->save(outputFileName);
0264 }
0265 }
0266
0267
0268 void LogMessageMonitor::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0269
0270
0271 edm::ParameterSetDescription desc;
0272 desc.setUnknown();
0273 descriptions.addDefault(desc);
0274 }
0275
0276 DEFINE_FWK_MODULE(LogMessageMonitor);