CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/HLTriggerOffline/Muon/src/HLTMuonValidator.cc

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