Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-01-08 23:50:27

0001 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0002 #include "DQMServices/Core/interface/DQMStore.h"
0003 #include "DataFormats/Common/interface/TriggerResults.h"
0004 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
0005 #include "DataFormats/HLTReco/interface/TriggerEventWithRefs.h"
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/Framework/interface/MakerMacros.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0012 #include "FWCore/ServiceRegistry/interface/Service.h"
0013 #include "FWCore/Utilities/interface/Exception.h"
0014 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
0015 
0016 #include <algorithm>
0017 #include <string>
0018 #include <unordered_map>
0019 #include <vector>
0020 
0021 class HLTFiltersDQMonitor : public DQMEDAnalyzer {
0022 public:
0023   explicit HLTFiltersDQMonitor(edm::ParameterSet const&);
0024   ~HLTFiltersDQMonitor() override = default;
0025 
0026   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0027 
0028 private:
0029   void dqmBeginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) override;
0030   void bookHistograms(DQMStore::IBooker&, edm::Run const& iRun, edm::EventSetup const& iSetup) override;
0031   void analyze(edm::Event const&, edm::EventSetup const&) override;
0032 
0033   bool skipStreamByName(std::string const& streamName) const;
0034   bool skipPathMonitorElement(std::string const& pathName) const;
0035   bool skipModuleByEDMType(std::string const& moduleEDMType) const;
0036   bool skipModuleByType(std::string const& moduleType) const;
0037 
0038   std::string const folderName_;
0039   std::string const efficPlotNamePrefix_;
0040   std::string processName_;
0041   bool initFailed_;
0042   bool skipRun_;
0043 
0044   MonitorElement* meMenu_;
0045   std::unordered_map<std::string, MonitorElement*> meDatasetMap_;
0046   std::unordered_map<std::string, MonitorElement*> mePathMap_;
0047 
0048   // map of bin-label-keyword -> bin-index in MonitorElement
0049   std::unordered_map<std::string, size_t> binIndexMap_;
0050 
0051   edm::EDGetTokenT<edm::TriggerResults> triggerResultsToken_;
0052   edm::EDGetTokenT<trigger::TriggerEvent> triggerEventToken_;
0053   edm::EDGetTokenT<trigger::TriggerEventWithRefs> triggerEventWithRefsToken_;
0054 
0055   HLTConfigProvider hltConfigProvider_;
0056 };
0057 
0058 HLTFiltersDQMonitor::HLTFiltersDQMonitor(const edm::ParameterSet& iConfig)
0059     : folderName_(iConfig.getParameter<std::string>("folderName")),
0060       efficPlotNamePrefix_(iConfig.getParameter<std::string>("efficPlotNamePrefix")),
0061       processName_(""),
0062       initFailed_(false),
0063       skipRun_(false),
0064       meMenu_(nullptr) {
0065   auto const& triggerResultsInputTag = iConfig.getParameter<edm::InputTag>("triggerResults");
0066 
0067   if (triggerResultsInputTag.process().empty()) {
0068     edm::LogError("HLTFiltersDQMonitor") << "process not specified in HLT TriggerResults InputTag \""
0069                                          << triggerResultsInputTag.encode()
0070                                          << "\" -> plugin will not produce DQM outputs";
0071     initFailed_ = true;
0072     return;
0073   } else {
0074     processName_ = triggerResultsInputTag.process();
0075 
0076     triggerResultsToken_ = consumes<edm::TriggerResults>(triggerResultsInputTag);
0077 
0078     auto triggerEventInputTag = iConfig.getParameter<edm::InputTag>("triggerEvent");
0079     if (triggerEventInputTag.process().empty()) {
0080       triggerEventInputTag = edm::InputTag(triggerEventInputTag.label(), triggerEventInputTag.instance(), processName_);
0081     } else if (triggerEventInputTag.process() != processName_) {
0082       edm::LogWarning("HLTFiltersDQMonitor")
0083           << "edm::TriggerResults process name '" << processName_
0084           << "' differs from trigger::TriggerEvent process name '" << triggerEventInputTag.process()
0085           << "' -> plugin will not produce DQM outputs";
0086       initFailed_ = true;
0087       return;
0088     }
0089     triggerEventToken_ = consumes<trigger::TriggerEvent>(triggerEventInputTag);
0090 
0091     auto triggerEventWithRefsInputTag = iConfig.getParameter<edm::InputTag>("triggerEventWithRefs");
0092     if (triggerEventWithRefsInputTag.process().empty()) {
0093       triggerEventWithRefsInputTag =
0094           edm::InputTag(triggerEventWithRefsInputTag.label(), triggerEventWithRefsInputTag.instance(), processName_);
0095     } else if (triggerEventWithRefsInputTag.process() != processName_) {
0096       edm::LogWarning("HLTFiltersDQMonitor")
0097           << "edm::TriggerResults process name '" << processName_
0098           << "' differs from trigger::TriggerEventWithRefs process name '" << triggerEventWithRefsInputTag.process()
0099           << "' -> plugin will not produce DQM outputs";
0100       initFailed_ = true;
0101       return;
0102     }
0103     triggerEventWithRefsToken_ = mayConsume<trigger::TriggerEventWithRefs>(triggerEventWithRefsInputTag);
0104   }
0105 }
0106 
0107 void HLTFiltersDQMonitor::dqmBeginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
0108   if (initFailed_) {
0109     return;
0110   }
0111 
0112   LogTrace("HLTFiltersDQMonitor")
0113       << "[HLTFiltersDQMonitor] "
0114       << "----------------------------------------------------------------------------------------------------";
0115   LogTrace("HLTFiltersDQMonitor") << "[HLTFiltersDQMonitor::dqmBeginRun] Run = " << iRun.id();
0116 
0117   // reset data members holding information from the previous run
0118   skipRun_ = false;
0119 
0120   bool hltChanged = true;
0121   if (hltConfigProvider_.init(iRun, iSetup, processName_, hltChanged)) {
0122     LogTrace("HLTFiltersDQMonitor")
0123         << "[HLTFiltersDQMonitor::dqmBeginRun] HLTConfigProvider initialized [processName() = "
0124         << hltConfigProvider_.processName() << ", tableName() = " << hltConfigProvider_.tableName()
0125         << ", size() = " << hltConfigProvider_.size() << "]";
0126   } else {
0127     edm::LogError("HLTFiltersDQMonitor") << "initialization of HLTConfigProvider failed for Run=" << iRun.id()
0128                                          << " (process=\"" << processName_
0129                                          << "\") -> plugin will not produce DQM outputs for this run";
0130     skipRun_ = true;
0131     return;
0132   }
0133 }
0134 
0135 void HLTFiltersDQMonitor::bookHistograms(DQMStore::IBooker& iBooker,
0136                                          edm::Run const& iRun,
0137                                          edm::EventSetup const& iSetup) {
0138   if (skipRun_ or initFailed_) {
0139     return;
0140   }
0141 
0142   // clear map of bin-label-keyword -> bin-index in MonitorElement
0143   binIndexMap_.clear();
0144 
0145   iBooker.setCurrentFolder(folderName_);
0146 
0147   iBooker.bookString("HLTMenu", hltConfigProvider_.tableName().c_str());
0148 
0149   auto hltMenuName = hltConfigProvider_.tableName();
0150   std::replace(hltMenuName.begin(), hltMenuName.end(), '/', '_');
0151   std::replace(hltMenuName.begin(), hltMenuName.end(), '.', 'p');
0152   while (hltMenuName.front() == '_') {
0153     hltMenuName.erase(0, 1);
0154   }
0155 
0156   auto const& triggerNames = hltConfigProvider_.triggerNames();
0157 
0158   meMenu_ = iBooker.bookProfile(efficPlotNamePrefix_ + hltMenuName,
0159                                 "Path Efficiency",
0160                                 triggerNames.size(),
0161                                 0.,
0162                                 triggerNames.size(),
0163                                 -0.1,
0164                                 1.1,
0165                                 "",
0166                                 [&triggerNames](TProfile* tprof) {
0167                                   for (size_t idx = 0; idx < triggerNames.size(); ++idx) {
0168                                     tprof->GetXaxis()->SetBinLabel(idx + 1, triggerNames[idx].c_str());
0169                                   }
0170                                 });
0171 
0172   for (size_t idx = 0; idx < triggerNames.size(); ++idx) {
0173     binIndexMap_[triggerNames[idx]] = idx + 1;
0174   }
0175 
0176   LogTrace("HLTFiltersDQMonitor") << "[HLTFiltersDQMonitor::bookHistograms] HLTConfigProvider::size() = "
0177                                   << hltConfigProvider_.size()
0178                                   << ", HLTConfigProvider::triggerNames().size() = " << triggerNames.size();
0179 
0180   for (auto const& istream : hltConfigProvider_.streamNames()) {
0181     LogTrace("HLTFiltersDQMonitor") << "[HLTFiltersDQMonitor::bookHistograms] Stream = \"" << istream << "\"";
0182 
0183     if (this->skipStreamByName(istream)) {
0184       continue;
0185     }
0186 
0187     auto const& dsets = hltConfigProvider_.streamContent(istream);
0188     for (auto const& idset : dsets) {
0189       iBooker.setCurrentFolder(folderName_ + "/" + idset);
0190       LogTrace("HLTFiltersDQMonitor") << "[HLTFiltersDQMonitor::bookHistograms]   Dataset = \"" << idset << "\"";
0191       auto const& dsetPathNames = hltConfigProvider_.datasetContent(idset);
0192       auto const meDatasetName = efficPlotNamePrefix_ + idset;
0193       meDatasetMap_[meDatasetName] = iBooker.bookProfile(
0194           meDatasetName.c_str(),
0195           meDatasetName.c_str(),
0196           dsetPathNames.size(),
0197           0.,
0198           dsetPathNames.size(),
0199           -0.1,
0200           1.1,
0201           "",
0202           [&dsetPathNames, &triggerNames](TProfile* tprof) {
0203             for (size_t idxPath = 0; idxPath < dsetPathNames.size(); ++idxPath) {
0204               auto const& iPathName = dsetPathNames[idxPath];
0205               if (std::find(triggerNames.begin(), triggerNames.end(), iPathName) == triggerNames.end()) {
0206                 continue;
0207               }
0208               tprof->GetXaxis()->SetBinLabel(idxPath + 1, iPathName.c_str());
0209             }
0210           });
0211       for (size_t idxPath = 0; idxPath < dsetPathNames.size(); ++idxPath) {
0212         auto const& iPathName = dsetPathNames[idxPath];
0213         if (std::find(triggerNames.begin(), triggerNames.end(), iPathName) == triggerNames.end()) {
0214           continue;
0215         }
0216         binIndexMap_[idset + "." + iPathName] = idxPath + 1;
0217 
0218         if (this->skipPathMonitorElement(iPathName)) {
0219           continue;
0220         }
0221 
0222         LogTrace("HLTFiltersDQMonitor") << "[HLTFiltersDQMonitor::bookHistograms]     Path = \"" << iPathName << "\"";
0223 
0224         auto const& moduleLabels = hltConfigProvider_.moduleLabels(iPathName);
0225         std::vector<std::string> mePath_binLabels;
0226         mePath_binLabels.reserve(moduleLabels.size());
0227         for (size_t iMod = 0; iMod < moduleLabels.size(); ++iMod) {
0228           auto const& moduleLabel = moduleLabels[iMod];
0229 
0230           bool skipModule = false;
0231           if (this->skipModuleByEDMType(hltConfigProvider_.moduleEDMType(moduleLabel)) or
0232               this->skipModuleByType(hltConfigProvider_.moduleType(moduleLabel))) {
0233             skipModule = true;
0234           } else if (std::find(mePath_binLabels.begin(), mePath_binLabels.end(), moduleLabel) !=
0235                      mePath_binLabels.end()) {
0236             LogDebug("HLTFiltersDQMonitor")
0237                 << "module \"" << moduleLabel << "\" included multiple times in Path \"" << iPathName << "\""
0238                 << "-> only 1 bin labelled \"" << moduleLabel << "\" will be created in the MonitorElement of the Path";
0239             skipModule = true;
0240           }
0241 
0242           if (skipModule) {
0243             LogTrace("HLTFiltersDQMonitor")
0244                 << "[HLTFiltersDQMonitor::bookHistograms]       [-] Module = \"" << moduleLabel << "\"";
0245             continue;
0246           }
0247 
0248           mePath_binLabels.emplace_back(moduleLabel);
0249 
0250           LogTrace("HLTFiltersDQMonitor")
0251               << "[HLTFiltersDQMonitor::bookHistograms]       [bin=" << mePath_binLabels.size() << "] Module = \""
0252               << moduleLabel << "\"";
0253         }
0254 
0255         if (mePath_binLabels.empty()) {
0256           continue;
0257         }
0258 
0259         auto const mePathName = efficPlotNamePrefix_ + idset + "_" + iPathName;
0260 
0261         mePathMap_[mePathName] =
0262             iBooker.bookProfile(mePathName.c_str(),
0263                                 iPathName.c_str(),
0264                                 mePath_binLabels.size(),
0265                                 0.,
0266                                 mePath_binLabels.size(),
0267                                 -0.1,
0268                                 1.1,
0269                                 "",
0270                                 [&mePath_binLabels](TProfile* tprof) {
0271                                   for (size_t iMod = 0; iMod < mePath_binLabels.size(); ++iMod) {
0272                                     tprof->GetXaxis()->SetBinLabel(iMod + 1, mePath_binLabels[iMod].c_str());
0273                                   }
0274                                 });
0275 
0276         for (size_t iMod = 0; iMod < mePath_binLabels.size(); ++iMod) {
0277           binIndexMap_[idset + "." + iPathName + "." + mePath_binLabels[iMod]] = iMod + 1;
0278         }
0279       }
0280     }
0281   }
0282 }
0283 
0284 void HLTFiltersDQMonitor::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0285   if (skipRun_ or initFailed_) {
0286     return;
0287   }
0288 
0289   LogTrace("HLTFiltersDQMonitor")
0290       << "[HLTFiltersDQMonitor::analyze] --------------------------------------------------------";
0291   LogTrace("HLTFiltersDQMonitor") << "[HLTFiltersDQMonitor::analyze] Run = " << iEvent.id().run()
0292                                   << ", LuminosityBlock = " << iEvent.id().luminosityBlock()
0293                                   << ", Event = " << iEvent.id().event();
0294 
0295   auto const& triggerResults = iEvent.getHandle(triggerResultsToken_);
0296 
0297   if (not triggerResults.isValid()) {
0298     edm::EDConsumerBase::Labels labels;
0299     labelsForToken(triggerResultsToken_, labels);
0300     edm::LogWarning("HLTFiltersDQMonitor")
0301         << "invalid handle to edm::TriggerResults (InputTag: \"" << labels.module << ":" << labels.productInstance
0302         << ":" << labels.process << "\") -> plugin will not fill DQM outputs for this event";
0303     return;
0304   }
0305 
0306   // fill MonitorElement: HLT-Menu (bin: Path)
0307   auto const& triggerNames = hltConfigProvider_.triggerNames();
0308   for (auto const& iPathName : triggerNames) {
0309     unsigned int const pathIndex = hltConfigProvider_.triggerIndex(iPathName);
0310     if (pathIndex >= triggerResults->size()) {
0311       edm::LogError("HLTFiltersDQMonitor")
0312           << "[HLTFiltersDQMonitor::analyze]       "
0313           << "index associated to Path \"" << iPathName << "\" (" << pathIndex
0314           << ") is inconsistent with triggerResults::size() (" << triggerResults->size()
0315           << ") -> plugin will not fill bin associated to this Path in HLT-Menu MonitorElement";
0316       continue;
0317     }
0318 
0319     auto const foundBin = binIndexMap_.find(iPathName);
0320     if (foundBin == binIndexMap_.end()) {
0321       throw cms::Exception("HLTFiltersDQMonitorInvalidBinLabel")
0322           << "invalid key for bin-index map (name of Path bin in MonitorElement of HLT Menu): \"" << iPathName << "\"";
0323     }
0324     auto const ibin = foundBin->second;
0325     if ((0 < ibin) and (ibin <= size_t(meMenu_->getNbinsX()))) {
0326       auto const pathAccept = triggerResults->accept(pathIndex);
0327       meMenu_->Fill(ibin - 0.5, pathAccept);
0328     } else {
0329       edm::LogError("HLTFiltersDQMonitor") << "out-of-range bin index of Path \"" << iPathName
0330                                            << "\" in MonitorElement of HLT Menu (MonitorElement not filled): bin_key=\""
0331                                            << iPathName << "\", bin_index=" << ibin;
0332     }
0333   }
0334 
0335   auto const& triggerEventHandle = iEvent.getHandle(triggerEventToken_);
0336   edm::Handle<trigger::TriggerEventWithRefs> triggerEventWithRefs;
0337 
0338   bool useTriggerEvent = true;
0339   if (not triggerEventHandle.isValid()) {
0340     useTriggerEvent = false;
0341 
0342     edm::EDConsumerBase::Labels triggerEventLabels;
0343     labelsForToken(triggerEventToken_, triggerEventLabels);
0344 
0345     edm::EDConsumerBase::Labels triggerEventWithRefsLabels;
0346     labelsForToken(triggerEventWithRefsToken_, triggerEventWithRefsLabels);
0347 
0348     edm::LogInfo("HLTFiltersDQMonitor") << "invalid handle to trigger::TriggerEvent (InputTag: \""
0349                                         << triggerEventLabels.module << ":" << triggerEventLabels.productInstance << ":"
0350                                         << triggerEventLabels.process
0351                                         << "\"), will attempt to access trigger::TriggerEventWithRefs (InputTag:\""
0352                                         << triggerEventWithRefsLabels.module << ":"
0353                                         << triggerEventWithRefsLabels.productInstance << ":"
0354                                         << triggerEventWithRefsLabels.process << "\")";
0355 
0356     triggerEventWithRefs = iEvent.getHandle(triggerEventWithRefsToken_);
0357     if (not triggerEventWithRefs.isValid()) {
0358       edm::LogWarning("HLTFiltersDQMonitor")
0359           << "invalid handle to trigger::TriggerEventWithRefs (InputTag: \"" << triggerEventWithRefsLabels.module << ":"
0360           << triggerEventWithRefsLabels.productInstance << ":" << triggerEventWithRefsLabels.process
0361           << "\") -> plugin will not fill DQM outputs for this event";
0362       return;
0363     }
0364   }
0365 
0366   auto const triggerEventSize = useTriggerEvent ? triggerEventHandle->sizeFilters() : triggerEventWithRefs->size();
0367   LogTrace("HLTFiltersDQMonitor") << "[HLTFiltersDQMonitor::analyze] useTriggerEvent = " << useTriggerEvent
0368                                   << ", triggerEventSize = " << triggerEventSize;
0369 
0370   // fill MonitorElements for PrimaryDatasets and Paths
0371   // loop over Streams
0372   for (auto const& istream : hltConfigProvider_.streamNames()) {
0373     LogTrace("HLTFiltersDQMonitor") << "[HLTFiltersDQMonitor::analyze]   Stream = \"" << istream << "\"";
0374 
0375     // loop over PrimaryDatasets in Stream
0376     auto const& dsets = hltConfigProvider_.streamContent(istream);
0377     for (auto const& idset : dsets) {
0378       LogTrace("HLTFiltersDQMonitor") << "[HLTFiltersDQMonitor::analyze]     Dataset = \"" << idset << "\"";
0379 
0380       // consider only Datasets with a MonitorElement (see bookHistograms)
0381       auto const meDatasetName = efficPlotNamePrefix_ + idset;
0382       auto const meDatasetMapFindIt = meDatasetMap_.find(meDatasetName);
0383       if (meDatasetMapFindIt == meDatasetMap_.end()) {
0384         LogDebug("HLTFiltersDQMonitor") << "No MonitorElement associated to Dataset \"" << idset << "\" in Stream \""
0385                                         << istream << "\" (will be ignored)";
0386         continue;
0387       }
0388       MonitorElement* const meDatasetProf = meDatasetMapFindIt->second;
0389 
0390       // loop over Paths in PrimaryDataset
0391       auto const& dsetPathNames = hltConfigProvider_.datasetContent(idset);
0392       for (auto const& iPathName : dsetPathNames) {
0393         unsigned int const pathIndex = hltConfigProvider_.triggerIndex(iPathName);
0394         if (pathIndex >= triggerResults->size()) {
0395           edm::LogError("HLTFiltersDQMonitor")
0396               << "[HLTFiltersDQMonitor::analyze]       "
0397               << "index associated to Path \"" << iPathName << "\" (" << pathIndex
0398               << ") is inconsistent with triggerResults::size() (" << triggerResults->size()
0399               << ") -> plugin will not fill DQM info related to this Path";
0400           continue;
0401         }
0402         auto const pathAccept = triggerResults->accept(pathIndex);
0403         LogTrace("HLTFiltersDQMonitor") << "[HLTFiltersDQMonitor::analyze]       "
0404                                         << "Path = \"" << iPathName << "\", HLTConfigProvider::triggerIndex(\""
0405                                         << iPathName << "\") = " << pathIndex << ", Accept = " << pathAccept;
0406 
0407         // fill MonitorElement: PrimaryDataset (bin: Path)
0408         auto const ibinKey = idset + "." + iPathName;
0409         auto const foundBin = binIndexMap_.find(ibinKey);
0410         if (foundBin == binIndexMap_.end()) {
0411           throw cms::Exception("HLTFiltersDQMonitorInvalidBinLabel")
0412               << "invalid key for bin-index map (name of Path bin in MonitorElement of Dataset): \"" << ibinKey << "\"";
0413         }
0414         auto const ibin = foundBin->second;
0415         if (0 < ibin and ibin <= size_t(meDatasetProf->getNbinsX())) {
0416           meDatasetProf->Fill(ibin - 0.5, pathAccept);
0417         } else {
0418           edm::LogError("HLTFiltersDQMonitor")
0419               << "out-of-range bin index of Path \"" << iPathName << "\" in MonitorElement of Dataset \"" << idset
0420               << "\" (MonitorElement not filled): bin_key=\"" << ibinKey << "\", bin_index=" << ibin;
0421         }
0422 
0423         // fill MonitorElement: Path (bin: filter)
0424         auto const mePathName = efficPlotNamePrefix_ + idset + "_" + iPathName;
0425 
0426         // consider only Paths with a MonitorElement
0427         auto const mePathMapFindIt = mePathMap_.find(mePathName);
0428         if (mePathMapFindIt == mePathMap_.end()) {
0429           LogDebug("HLTFiltersDQMonitor") << "No MonitorElement associated to Path \"" << iPathName
0430                                           << "\" in Dataset \"" << idset << "\" (will be ignored)";
0431           continue;
0432         }
0433         MonitorElement* const mePathProf = mePathMapFindIt->second;
0434 
0435         unsigned int indexLastFilterInPath = triggerResults->index(pathIndex) + 1;
0436         LogTrace("HLTFiltersDQMonitor") << "[HLTFiltersDQMonitor::analyze]         "
0437                                         << "indexLastFilterInPath = " << indexLastFilterInPath;
0438         // identify module corresponding to last filter executed in the Path
0439         while (indexLastFilterInPath > 0) {
0440           --indexLastFilterInPath;
0441           auto const& labelLastFilterInPath = hltConfigProvider_.moduleLabel(pathIndex, indexLastFilterInPath);
0442           auto const labelLastFilterInPathTag = edm::InputTag(labelLastFilterInPath, "", processName_);
0443           unsigned int const indexLastFilterInTriggerEvent =
0444               useTriggerEvent ? triggerEventHandle->filterIndex(labelLastFilterInPathTag)
0445                               : triggerEventWithRefs->filterIndex(labelLastFilterInPathTag);
0446           LogTrace("HLTFiltersDQMonitor") << "[HLTFiltersDQMonitor::analyze]           "
0447                                           << "indexLastFilterInPath = " << indexLastFilterInPath
0448                                           << ", labelLastFilterInPath = " << labelLastFilterInPath
0449                                           << ", indexLastFilterInTriggerEvent = " << indexLastFilterInTriggerEvent
0450                                           << " (triggerEventSize = " << triggerEventSize << ")";
0451           if (indexLastFilterInTriggerEvent < triggerEventSize) {
0452             if (this->skipModuleByType(hltConfigProvider_.moduleType(labelLastFilterInPath))) {
0453               continue;
0454             }
0455             break;
0456           }
0457         }
0458         // number of modules in the path
0459         unsigned int const nModulesInPath = hltConfigProvider_.size(pathIndex);
0460         LogTrace("HLTFiltersDQMonitor") << "[HLTFiltersDQMonitor::analyze]         "
0461                                         << "-> selected indexLastFilterInPath = " << indexLastFilterInPath
0462                                         << " (HLTConfigProvider::size(" << pathIndex << ") = " << nModulesInPath << ")";
0463         if (indexLastFilterInPath >= nModulesInPath) {
0464           edm::LogError("HLTFiltersDQMonitor")
0465               << " selected index (" << indexLastFilterInPath << ") for last filter of path \"" << iPathName
0466               << "\" is inconsistent with number of modules in the Path (" << nModulesInPath << ")";
0467           continue;
0468         }
0469         // store decision of previous filter
0470         bool previousFilterAccept(true);
0471         for (size_t modIdx = 0; modIdx < nModulesInPath; ++modIdx) {
0472           // each filter-bin is filled, with a 0 or 1, only when all previous filters in the Path have passed
0473           if (not previousFilterAccept) {
0474             break;
0475           }
0476           // consider only selected EDFilter modules
0477           auto const& moduleLabel = hltConfigProvider_.moduleLabel(pathIndex, modIdx);
0478           if (this->skipModuleByEDMType(hltConfigProvider_.moduleEDMType(moduleLabel)) or
0479               this->skipModuleByType(hltConfigProvider_.moduleType(moduleLabel))) {
0480             continue;
0481           }
0482           // index of module in this Path [0,nModulesInPath)
0483           unsigned int const slotModule = hltConfigProvider_.moduleIndex(pathIndex, moduleLabel);
0484           bool filterAccept = false;
0485           if (slotModule < indexLastFilterInPath) {
0486             filterAccept = true;
0487           } else if (slotModule == indexLastFilterInPath) {
0488             filterAccept = pathAccept;
0489           }
0490           LogTrace("HLTFiltersDQMonitor")
0491               << "[HLTFiltersDQMonitor::analyze]         "
0492               << "HLTConfigProvider::moduleLabel(" << pathIndex << ", " << modIdx << ") = \"" << moduleLabel
0493               << "\", HLTConfigProvider::moduleIndex(" << pathIndex << ", \"" << moduleLabel << "\") = " << slotModule
0494               << ", filterAccept = " << filterAccept << ", previousFilterAccept = " << previousFilterAccept;
0495 
0496           auto const ibinKey = idset + "." + iPathName + "." + moduleLabel;
0497           auto const foundBin = binIndexMap_.find(ibinKey);
0498           if (foundBin == binIndexMap_.end()) {
0499             throw cms::Exception("HLTFiltersDQMonitorInvalidBinLabel")
0500                 << "invalid key for bin-index map (name of Module bin in MonitorElement of Path): \"" << ibinKey
0501                 << "\"";
0502           }
0503           auto const ibin = foundBin->second;
0504           if (0 < ibin and ibin <= size_t(mePathProf->getNbinsX())) {
0505             mePathProf->Fill(ibin - 0.5, filterAccept);
0506           } else {
0507             edm::LogError("HLTFiltersDQMonitor")
0508                 << "out-of-range bin index of Module \"" << moduleLabel
0509                 << "\" in MonitorElement of Path \"iPathName\" in Dataset \"" << idset
0510                 << "\" (MonitorElement not filled): bin_key=\"" << ibinKey << "\", bin_index=" << ibin;
0511           }
0512           previousFilterAccept = filterAccept;
0513         }
0514       }
0515     }
0516   }
0517 }
0518 
0519 bool HLTFiltersDQMonitor::skipStreamByName(std::string const& streamName) const {
0520   return ((streamName.find("Physics") == std::string::npos) and (streamName.find("Scouting") == std::string::npos) and
0521           (streamName.find("Parking") == std::string::npos) and (streamName != "A"));
0522 }
0523 
0524 bool HLTFiltersDQMonitor::skipPathMonitorElement(std::string const& pathName) const {
0525   return ((pathName.find("HLT_") == std::string::npos) or (pathName.find("HLT_Physics") != std::string::npos) or
0526           (pathName.find("HLT_Random") != std::string::npos));
0527 }
0528 
0529 bool HLTFiltersDQMonitor::skipModuleByEDMType(std::string const& moduleEDMType) const {
0530   return (moduleEDMType != "EDFilter");
0531 }
0532 
0533 bool HLTFiltersDQMonitor::skipModuleByType(std::string const& moduleType) const { return (moduleType == "HLTBool"); }
0534 
0535 void HLTFiltersDQMonitor::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0536   edm::ParameterSetDescription desc;
0537   desc.add<std::string>("folderName", "HLT/Filters");
0538   desc.add<std::string>("efficPlotNamePrefix", "effic_");
0539   desc.add<edm::InputTag>("triggerResults", edm::InputTag("TriggerResults::HLT"));
0540   desc.add<edm::InputTag>("triggerEvent", edm::InputTag("hltTriggerSummaryAOD::HLT"));
0541   desc.add<edm::InputTag>("triggerEventWithRefs", edm::InputTag("hltTriggerSummaryRAW::HLT"));
0542   descriptions.add("dqmHLTFiltersDQMonitor", desc);
0543 }
0544 
0545 DEFINE_FWK_MODULE(HLTFiltersDQMonitor);