Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-04-17 02:46:39

0001 // -*- C++ -*-
0002 //
0003 // Package:    LogMessageMonitor
0004 // Class:      LogMessageMonitor
0005 //
0006 /**\class LogMessageMonitor LogMessageMonitor.cc DQM/LogMonitor/src/LogMessageMonitor.cc
0007 
0008  Description: [one line class summary]
0009   from https://twiki.cern.ch/twiki/bin/view/CMS/TrackingPOGFilters#Filters
0010    Events with (partly) aborted track reconstruction 
0011    The track reconstruction code is protected against events with too large occupancy which can cause an excessive use of CPU time and memory.
0012    Each iteration of the track reconstruction can be aborted if:
0013      - too many strip and/or pixel clusters are present as input to the seeding step (*TooManyClusters* error).
0014        => No track is reconstructed from that iteration
0015      - too many hit triplets or pairs are produced as input to the seeding step (*TooManyPairs/TooManyTriplets* errors).
0016        => All the pairs/triplets found are discarded and the iteration continue (to be checked!)
0017        NB: Despite the thrshold is the same,
0018            similar iterations may have a different rate of errors depending on the CMSSW release,
0019        because the requirement to accept a triplet/pair has been modified (cluster shape filters,...) 
0020      - too many seeds are produced as input to the track building step (*TooManySeeds*).
0021     => No track is reconstructed from that iteration. 
0022 
0023    # ELSeverityLevel
0024       http://cmssdt.cern.ch/SDT/lxr/source/FWCore/MessageLogger/interface/ELseverityLevel.h?v=CMSSW_5_3_4
0025 108   enum ELsev_  {
0026 109     ELsev_noValueAssigned = 0  // default returned by map when not found
0027 110   , ELsev_zeroSeverity         // threshold use only
0028 111   , ELsev_incidental           // flash this on a screen
0029 112   , ELsev_success              // report reaching a milestone
0030 113   , ELsev_info                 // information
0031 114   , ELsev_warning              // warning
0032 115   , ELsev_warning2             // more serious warning
0033 116   , ELsev_error                // error detected
0034 117   , ELsev_error2               // more serious error
0035 118   , ELsev_next                 // advise to skip to next event
0036 119   , ELsev_unspecified          // severity was not specified
0037 120   , ELsev_severe               // future results are suspect
0038 121   , ELsev_severe2              // more severe
0039 122   , ELsev_abort                // suggest aborting
0040 123   , ELsev_fatal                // strongly suggest aborting!
0041 124   , ELsev_highestSeverity      // threshold use only
0042 125   // -----
0043 126   , nLevels                    // how many levels?
0044 127   };  // ELsev_
0045 
0046  Implementation:
0047      [Notes on implementation]
0048 */
0049 //
0050 // Original Author:  Mia Tosi,40 3-B32,+41227671609,
0051 //         Created:  Thu Mar  8 14:34:13 CET 2012
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 // constants, enums and typedefs
0068 //
0069 
0070 //
0071 // static data member definitions
0072 //
0073 
0074 //
0075 // constructors and destructor
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   //now do what ever initialization is needed
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   // do anything here that needs to be done at desctruction time
0096   // (e.g. close files, deallocate resources etc.)
0097   //  if ( lumiDetails_         ) delete lumiDetails_;
0098   if (genTriggerEventFlag_)
0099     delete genTriggerEventFlag_;
0100 }
0101 
0102 //
0103 // member functions
0104 //
0105 
0106 // ------------ method called for each event  ------------
0107 void LogMessageMonitor::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0108   // Filter out events if Trigger Filtering is requested
0109   if (genTriggerEventFlag_->on() && !genTriggerEventFlag_->accept(iEvent, iSetup))
0110     return;
0111 
0112   double BXlumi = -1.;
0113   if (doPUmonitoring_)
0114     lumiDetails_->getValue(iEvent);
0115 
0116   // Take the ErrorSummaryEntry container
0117   edm::Handle<std::vector<edm::ErrorSummaryEntry> > errors = iEvent.getHandle(errorToken_);
0118   // Check that errors is valid
0119   if (!errors.isValid())
0120     return;
0121 
0122   // Find the total number of errors in iEvent
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       //      std::cout << "LogMessageMonitor::analyze] Severity for error/warning: " << (*errors)[i].severity << " " <<(*errors)[i].module  << std::endl;
0136       // remove the first part of the module string, what is before ":"
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         //      std::cout << "LogMessageMonitor::analyze] it: " << " --> " << s_module << std::endl;
0143 
0144         // IF THIS IS AN ERROR on the ELseverityLevel SCALE, FILL ERROR HISTS
0145         if ((*errors)[i].severity.getLevel() >= edm::ELseverityLevel::ELsev_error) {
0146           if (doPUmonitoring_)
0147             ModulesErrorsVsBXlumi[it->second]->Fill(BXlumi, (*errors)[i].count);
0148 
0149           // loop over the different categories of errors
0150           // defined by configuration file
0151           // if the category is not in the given list
0152           // it fills the bin "others"
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       std::cout << "LogMessageMonitor::analyze] ibinX: " << ibinX << " it->second: " << it->second << " it->first: " << it->first << std::endl;
0159       std::cout << "LogMessageMonitor::analyze] ibinY: " << ibinY << " (*errors)[i].category: " << (*errors)[i].category << std::endl;
0160       size_t nbinsX = CategoriesVsModules->getTH1()->GetNbinsX();
0161       for (size_t bin = 1; bin<=nbinsX; bin++) {
0162         std::cout << "binX" << bin << ": " << CategoriesVsModules->getTH1()->GetXaxis()->GetBinLabel(bin) << std::endl;
0163       }
0164       size_t nbinsY = CategoriesVsModules->getTH1()->GetNbinsY();
0165       for (size_t bin = 1; bin<=nbinsY; bin++) {
0166         std::cout << "binY" << bin << ": " << CategoriesVsModules->getTH1()->GetYaxis()->GetBinLabel(bin) << std::endl;
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           // IF ONLY WARNING, FILL WARNING HISTS
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   //   CategoriesVsModules->getTH1()->GetXaxis()->LabelsOption("v");
0211   for (size_t icategories = 0; icategories < nCategories; icategories++)
0212     CategoriesVsModules->setBinLabel(icategories + 1, categories_vector_[icategories], 2);
0213 
0214   // MAKE MODULEMAP USING INPUT FROM CFG FILE
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     // BOOK THE HISTOGRAMS
0221     // get binning from the configuration
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 // ------------ method called once each job just before starting event loop  ------------
0252 void 
0253 LogMessageMonitor::beginJob()
0254 {
0255 
0256 }
0257 */
0258 // ------------ method called once each job just after ending the event loop  ------------
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 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0268 void LogMessageMonitor::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0269   //The following says we do not know what parameters are allowed so do no validation
0270   // Please change this to state exactly what you do use, even if it is no parameters
0271   edm::ParameterSetDescription desc;
0272   desc.setUnknown();
0273   descriptions.addDefault(desc);
0274 }
0275 
0276 DEFINE_FWK_MODULE(LogMessageMonitor);