Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:13:25

0001 // -*- C++ -*-
0002 //
0003 // Package:     HLTMuonOfflineAnalyzer
0004 // Class:       HLTMuonOfflineAnalyzer
0005 //
0006 
0007 //
0008 // Jason Slaunwhite and Jeff Klukas
0009 //
0010 //
0011 
0012 // system include files
0013 #include <memory>
0014 #include <iostream>
0015 
0016 // user include files
0017 #include "DQMOffline/Trigger/interface/HLTMuonMatchAndPlotContainer.h"
0018 
0019 #include "DQMServices/Core/interface/DQMStore.h"
0020 
0021 #include "FWCore/Framework/interface/Frameworkfwd.h"
0022 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0023 #include "FWCore/Framework/interface/ConsumesCollector.h"
0024 #include "FWCore/Framework/interface/MakerMacros.h"
0025 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0026 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0027 
0028 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
0029 #include "FWCore/ServiceRegistry/interface/Service.h"
0030 
0031 #include "TFile.h"
0032 #include "TDirectory.h"
0033 #include "TPRegexp.h"
0034 
0035 //////////////////////////////////////////////////////////////////////////////
0036 //////// Define the interface ////////////////////////////////////////////////
0037 
0038 class HLTMuonOfflineAnalyzer : public DQMEDAnalyzer {
0039 public:
0040   explicit HLTMuonOfflineAnalyzer(const edm::ParameterSet &);
0041 
0042 private:
0043   // Analyzer Methods
0044   void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override;
0045   void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
0046   void analyze(const edm::Event &, const edm::EventSetup &) override;
0047 
0048   // Extra Methods
0049   std::vector<std::string> moduleLabels(const std::string &);
0050 
0051   // Input from Configuration File
0052   edm::ParameterSet pset_;
0053   std::string hltProcessName_;
0054   std::vector<std::string> hltPathsToCheck_;
0055 
0056   // Member Variables
0057   HLTMuonMatchAndPlotContainer plotterContainer_;
0058   HLTConfigProvider hltConfig_;
0059 };
0060 
0061 //////////////////////////////////////////////////////////////////////////////
0062 //////// Namespaces, Typedefs, and Constants /////////////////////////////////
0063 
0064 using namespace std;
0065 using namespace edm;
0066 using namespace reco;
0067 using namespace trigger;
0068 
0069 using vstring = vector<string>;
0070 
0071 //////////////////////////////////////////////////////////////////////////////
0072 //////// Class Methods ///////////////////////////////////////////////////////
0073 
0074 HLTMuonOfflineAnalyzer::HLTMuonOfflineAnalyzer(const ParameterSet &pset)
0075     : pset_(pset),
0076       hltProcessName_(pset.getParameter<string>("hltProcessName")),
0077       hltPathsToCheck_(pset.getParameter<vstring>("hltPathsToCheck")),
0078       plotterContainer_(consumesCollector(), pset) {}
0079 
0080 vector<string> HLTMuonOfflineAnalyzer::moduleLabels(const string &path) {
0081   vector<string> modules = hltConfig_.moduleLabels(path);
0082   auto iter = modules.begin();
0083   while (iter != modules.end()) {
0084     if ((iter->find("Filtered") == string::npos) && (iter->find("hltL1s") == string::npos)) {
0085       iter = modules.erase(iter);
0086     } else if (iter->find("L1Filtered0") != string::npos)
0087       iter = modules.erase(iter);
0088     else
0089       ++iter;
0090   }
0091   //  iter = modules.begin();
0092   //  while (iter != modules.end()){
0093   //    if ((iter->find("Filtered0") == string::npos)){
0094   //      std::cout<< *iter << std::endl;
0095   //      iter = modules.erase(iter);
0096   //    }
0097   //    else ++iter;
0098   //  }
0099 
0100   return modules;
0101 }
0102 
0103 void HLTMuonOfflineAnalyzer::dqmBeginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) {
0104   // Initialize hltConfig
0105   bool changedConfig;
0106   if (!hltConfig_.init(iRun, iSetup, hltProcessName_, changedConfig)) {
0107     LogError("HLTMuonVal") << "Initialization of HLTConfigProvider failed!!";
0108     return;
0109   }
0110 
0111   // Get the set of trigger paths we want to make plots for
0112   set<string> hltPaths;
0113   for (auto const &i : hltPathsToCheck_) {
0114     for (auto const &j : hltConfig_.triggerNames()) {
0115       if (j.find(i) != std::string::npos) {
0116         hltPaths.insert(j);
0117       }
0118     }
0119   }
0120 
0121   // Initialize the plotters
0122   set<string>::iterator iPath;
0123   vector<string>::const_iterator ilabel;
0124   for (iPath = hltPaths.begin(); iPath != hltPaths.end(); iPath++) {
0125     string path = *iPath;
0126     vector<string> labels = moduleLabels(path);
0127     bool isLastLabel = false;
0128     for (ilabel = labels.begin(); ilabel != labels.end(); ilabel++) {
0129       if (*ilabel == labels.back())
0130         isLastLabel = true;
0131       plotterContainer_.addPlotter(pset_, path, *ilabel, isLastLabel);
0132     }
0133   }
0134 }
0135 
0136 void HLTMuonOfflineAnalyzer::bookHistograms(DQMStore::IBooker &iBooker,
0137                                             edm::Run const &iRun,
0138                                             edm::EventSetup const &iSetup) {
0139   plotterContainer_.beginRun(iBooker, iRun, iSetup);
0140 }
0141 
0142 void HLTMuonOfflineAnalyzer::analyze(const Event &iEvent, const EventSetup &iSetup) {
0143   plotterContainer_.analyze(iEvent, iSetup);
0144 }
0145 
0146 //define this as a plug-in
0147 DEFINE_FWK_MODULE(HLTMuonOfflineAnalyzer);