File indexing completed on 2023-03-17 11:10:05
0001
0002
0003
0004
0005
0006
0007
0008 #include <algorithm>
0009 #include <string>
0010 #include <vector>
0011
0012 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0013 #include "FWCore/Framework/interface/Frameworkfwd.h"
0014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0016 #include "FWCore/ServiceRegistry/interface/Service.h"
0017 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
0018 #include "HLTriggerOffline/Muon/interface/HLTMuonPlotter.h"
0019
0020 #include "TPRegexp.h"
0021
0022 class HLTMuonValidator : public DQMEDAnalyzer {
0023 public:
0024 explicit HLTMuonValidator(const edm::ParameterSet &);
0025
0026 private:
0027
0028 void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override;
0029 void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
0030 void analyze(const edm::Event &, const edm::EventSetup &) override;
0031
0032
0033 void fillLabels(std::string const &path,
0034 std::vector<std::string> &moduleLabels,
0035 std::vector<std::string> &stepLabels) const;
0036 std::string stepLabel(std::string const &moduleLabel) const;
0037
0038
0039 edm::ParameterSet pset_;
0040 std::string hltProcessName_;
0041 std::vector<std::string> hltPathsToCheck_;
0042
0043
0044 std::vector<HLTMuonPlotter> analyzers_;
0045 HLTConfigProvider hltConfig_;
0046
0047 edm::EDGetTokenT<trigger::TriggerEventWithRefs> const triggerEventToken_;
0048 edm::EDGetTokenT<reco::GenParticleCollection> const genParticlesToken_;
0049 edm::EDGetTokenT<reco::MuonCollection> const recoMuonsToken_;
0050
0051 HLTMuonPlotter::L1MuonMatcherAlgoForDQM const l1tMuonMatcherAlgo_;
0052 };
0053
0054 HLTMuonValidator::HLTMuonValidator(const edm::ParameterSet &pset)
0055 : pset_(pset),
0056 hltProcessName_(pset.getParameter<std::string>("hltProcessName")),
0057 hltPathsToCheck_(pset.getParameter<std::vector<std::string>>("hltPathsToCheck")),
0058 triggerEventToken_(consumes(edm::InputTag("hltTriggerSummaryRAW"))),
0059 genParticlesToken_(consumes(pset.getParameter<std::string>("genParticleLabel"))),
0060 recoMuonsToken_(consumes(pset.getParameter<std::string>("recMuonLabel"))),
0061 l1tMuonMatcherAlgo_(pset, consumesCollector()) {}
0062
0063 void HLTMuonValidator::fillLabels(std::string const &path,
0064 std::vector<std::string> &moduleLabels,
0065 std::vector<std::string> &stepLabels) const {
0066 auto const &hltFilters = hltConfig_.saveTagsModules(path);
0067
0068 moduleLabels.clear();
0069 moduleLabels.reserve(hltFilters.size());
0070
0071 stepLabels.clear();
0072 stepLabels.reserve(hltFilters.size() + 1);
0073
0074 for (auto const &module : hltFilters) {
0075 if (module.find("Filtered") == std::string::npos)
0076 continue;
0077
0078 auto const step_label = stepLabel(module);
0079 if (step_label.empty() or std::find(stepLabels.begin(), stepLabels.end(), step_label) != stepLabels.end())
0080 continue;
0081
0082 moduleLabels.emplace_back(module);
0083 stepLabels.emplace_back(step_label);
0084 }
0085
0086 if (stepLabels.empty()) {
0087 return;
0088 }
0089
0090 if (stepLabels[0] != "L1" and std::find(stepLabels.begin(), stepLabels.end(), "L1") != stepLabels.end()) {
0091 edm::LogWarning wrn("HLTMuonValidator");
0092 wrn << "Unsupported list of 'step' labels (the label 'L1' is present, but is not the first one): stepLabels=(";
0093 for (auto const &foo : stepLabels)
0094 wrn << " " << foo;
0095 wrn << " )";
0096
0097 moduleLabels.clear();
0098 stepLabels.clear();
0099 return;
0100 }
0101
0102 stepLabels.insert(stepLabels.begin(), "All");
0103 }
0104
0105 std::string HLTMuonValidator::stepLabel(std::string const &module) const {
0106 if (module.find("IsoFiltered") != std::string::npos) {
0107 return (module.find("L3") != std::string::npos) ? "L3TkIso" : "L2Iso";
0108 } else if (module.find("pfecalIsoRhoFiltered") != std::string::npos) {
0109 if (module.find("L3") != std::string::npos)
0110 return "L3EcalIso";
0111 else if (module.find("TkFiltered") != std::string::npos)
0112 return "TkEcalIso";
0113 } else if (module.find("pfhcalIsoRhoFiltered") != std::string::npos) {
0114 if (module.find("L3") != std::string::npos)
0115 return "L3HcalIso";
0116 else if (module.find("TkFiltered") != std::string::npos)
0117 return "TkHcalIso";
0118 } else if (module.find("TkFiltered") != std::string::npos)
0119 return "Tk";
0120 else if (module.find("L3") != std::string::npos)
0121 return "L3";
0122 else if (module.find("L2") != std::string::npos)
0123 return "L2";
0124 else if (module.find("L1") != std::string::npos)
0125 return "L1";
0126
0127 return "";
0128 }
0129
0130 void HLTMuonValidator::dqmBeginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) {
0131
0132 bool changedConfig;
0133 if (!hltConfig_.init(iRun, iSetup, hltProcessName_, changedConfig)) {
0134 edm::LogError("HLTMuonVal") << "Initialization of HLTConfigProvider failed!!";
0135 return;
0136 }
0137
0138
0139 std::set<std::string> hltPaths;
0140 for (size_t i = 0; i < hltPathsToCheck_.size(); i++) {
0141 TPRegexp pattern(hltPathsToCheck_[i]);
0142 for (size_t j = 0; j < hltConfig_.triggerNames().size(); j++)
0143 if (TString(hltConfig_.triggerNames()[j]).Contains(pattern))
0144 hltPaths.insert(hltConfig_.triggerNames()[j]);
0145 }
0146
0147
0148 analyzers_.clear();
0149 std::set<std::string>::iterator iPath;
0150 for (iPath = hltPaths.begin(); iPath != hltPaths.end(); iPath++) {
0151 const std::string &path = *iPath;
0152 std::string shortpath = path;
0153 if (path.rfind("_v") < path.length())
0154 shortpath = path.substr(0, path.rfind("_v"));
0155
0156 std::vector<std::string> labels;
0157 std::vector<std::string> steps;
0158 fillLabels(path, labels, steps);
0159
0160 if (!labels.empty() && !steps.empty()) {
0161 HLTMuonPlotter analyzer(
0162 pset_, shortpath, labels, steps, triggerEventToken_, genParticlesToken_, recoMuonsToken_, l1tMuonMatcherAlgo_);
0163 analyzers_.push_back(analyzer);
0164 }
0165 }
0166 }
0167
0168 void HLTMuonValidator::bookHistograms(DQMStore::IBooker &iBooker, edm::Run const &iRun, edm::EventSetup const &iSetup) {
0169
0170 for (auto &analyzer : analyzers_) {
0171 analyzer.beginRun(iBooker, iRun, iSetup);
0172 }
0173 }
0174
0175 void HLTMuonValidator::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0176 for (auto &analyzer : analyzers_) {
0177 analyzer.analyze(iEvent, iSetup);
0178 }
0179 }
0180
0181
0182 #include "FWCore/Framework/interface/MakerMacros.h"
0183 DEFINE_FWK_MODULE(HLTMuonValidator);