CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/DQMOffline/Trigger/src/HLTMuonOfflineAnalyzer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     HLTMuonOfflineAnalyzer
00004 // Class:       HLTMuonOfflineAnalyzer
00005 // 
00006 
00007 //
00008 // Jason Slaunwhite and Jeff Klukas
00009 // $Id: HLTMuonOfflineAnalyzer.cc,v 1.3 2011/04/01 20:39:01 klukas Exp $
00010 //
00011 //
00012 
00013 // system include files
00014 #include <memory>
00015 #include <iostream>
00016 
00017 // user include files
00018 #include "DQMOffline/Trigger/interface/HLTMuonMatchAndPlot.h"
00019 
00020 #include "DQMServices/Core/interface/DQMStore.h"
00021 
00022 #include "FWCore/Framework/interface/Frameworkfwd.h"
00023 #include "FWCore/Framework/interface/EDAnalyzer.h"
00024 // #include "FWCore/Framework/interface/Event.h"
00025 // #include "FWCore/Framework/interface/Run.h"
00026 // #include "FWCore/Framework/interface/EventSetup.h"
00027 #include "FWCore/Framework/interface/MakerMacros.h"
00028 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00030 
00031 
00032 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
00033 #include "FWCore/ServiceRegistry/interface/Service.h"
00034 
00035 
00036 #include "TFile.h"
00037 #include "TDirectory.h"
00038 #include "TPRegexp.h"
00039 
00040 
00043 
00044 
00045 
00046 class HLTMuonOfflineAnalyzer : public edm::EDAnalyzer {
00047 
00048 public:
00049 
00050   explicit HLTMuonOfflineAnalyzer(const edm::ParameterSet&);
00051 
00052 private:
00053 
00054   // Analyzer Methods
00055   virtual void beginJob();
00056   virtual void beginRun(const edm::Run &, const edm::EventSetup &);
00057   virtual void analyze(const edm::Event &, const edm::EventSetup &);
00058   virtual void endRun(const edm::Run &, const edm::EventSetup &);
00059   virtual void endJob();
00060 
00061   // Extra Methods
00062   std::vector<std::string> moduleLabels(std::string);
00063 
00064   // Input from Configuration File
00065   edm::ParameterSet pset_;
00066   std::string hltProcessName_;
00067   std::string destination_;
00068   std::vector<std::string> hltPathsToCheck_;
00069 
00070   // Member Variables
00071   std::vector<HLTMuonMatchAndPlot> analyzers_;
00072   HLTConfigProvider hltConfig_;
00073 
00074   // Access to the DQM
00075   DQMStore * dbe_;
00076 
00077 };
00078 
00079 
00080 
00083 
00084 using namespace std;
00085 using namespace edm;
00086 using namespace reco;
00087 using namespace trigger;
00088 
00089 typedef vector<string> vstring;
00090 
00091 
00092 
00095 
00096 HLTMuonOfflineAnalyzer::HLTMuonOfflineAnalyzer(const ParameterSet& pset) :
00097   pset_(pset),
00098   hltProcessName_(pset.getParameter<string>("hltProcessName")),
00099   destination_(pset.getUntrackedParameter<string>("destination")),
00100   hltPathsToCheck_(pset.getParameter<vstring>("hltPathsToCheck"))
00101 {
00102   // Prepare the DQMStore object.
00103   dbe_ = edm::Service<DQMStore>().operator->();
00104   dbe_->setVerbose(0);
00105   dbe_->setCurrentFolder(destination_);
00106 }
00107 
00108 
00109 
00110 vector<string> 
00111 HLTMuonOfflineAnalyzer::moduleLabels(string path) {
00112 
00113   vector<string> modules = hltConfig_.moduleLabels(path);
00114   vector<string>::iterator iter = modules.begin();
00115 
00116   while (iter != modules.end())
00117     if (iter->find("Filtered") == string::npos) 
00118       iter = modules.erase(iter);
00119     else
00120       ++iter;
00121 
00122   return modules;
00123 
00124 }
00125 
00126 
00127 
00128 void 
00129 HLTMuonOfflineAnalyzer::beginRun(const edm::Run & iRun, 
00130                                       const edm::EventSetup & iSetup) {
00131 
00132   // Initialize hltConfig
00133   bool changedConfig;
00134   if (!hltConfig_.init(iRun, iSetup, hltProcessName_, changedConfig)) {
00135     LogError("HLTMuonVal") << "Initialization of HLTConfigProvider failed!!"; 
00136     return;
00137   }
00138 
00139   // Get the set of trigger paths we want to make plots for
00140   set<string> hltPaths;
00141   for (size_t i = 0; i < hltPathsToCheck_.size(); i++) {
00142     TPRegexp pattern(hltPathsToCheck_[i]);
00143     for (size_t j = 0; j < hltConfig_.triggerNames().size(); j++)
00144       if (TString(hltConfig_.triggerNames()[j]).Contains(pattern))
00145         hltPaths.insert(hltConfig_.triggerNames()[j]);
00146   }
00147   
00148   // Initialize the analyzers
00149   analyzers_.clear();
00150   set<string>::iterator iPath;
00151   for (iPath = hltPaths.begin(); iPath != hltPaths.end(); iPath++) {
00152     string path = * iPath;
00153     vector<string> labels = moduleLabels(path);
00154     if (labels.size() > 0) {
00155       HLTMuonMatchAndPlot analyzer(pset_, path, moduleLabels(path));
00156       analyzers_.push_back(analyzer);
00157     }
00158   }
00159 
00160   // Call the beginRun (which books all the histograms)
00161   vector<HLTMuonMatchAndPlot>::iterator iter;
00162   for (iter = analyzers_.begin(); iter != analyzers_.end(); ++iter) {
00163     iter->beginRun(iRun, iSetup);
00164   }
00165 
00166 }
00167 
00168 void
00169 HLTMuonOfflineAnalyzer::analyze(const Event& iEvent, 
00170                                      const EventSetup& iSetup)
00171 {
00172 
00173   vector<HLTMuonMatchAndPlot>::iterator iter;
00174   for (iter = analyzers_.begin(); iter != analyzers_.end(); ++iter) {
00175     iter->analyze(iEvent, iSetup);
00176   }
00177 
00178 }
00179 
00180 
00181 
00182 void 
00183 HLTMuonOfflineAnalyzer::beginJob()
00184 {
00185 }
00186 
00187 
00188 
00189 void 
00190 HLTMuonOfflineAnalyzer::endRun(const edm::Run & iRun, 
00191                                     const edm::EventSetup& iSetup)
00192 {
00193 
00194   // vector<HLTMuonMatchAndPlot>::iterator iter;
00195   // for (iter = analyzers_.begin(); iter != analyzers_.end(); ++iter) {
00196   //   iter->endRun(iRun, iSetup);
00197   // }
00198 
00199 }
00200 
00201 
00202 
00203 void 
00204 HLTMuonOfflineAnalyzer::endJob()
00205 {
00206 }
00207 
00208 
00209 
00210 //define this as a plug-in
00211 DEFINE_FWK_MODULE(HLTMuonOfflineAnalyzer);