Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DQMOffline/PFTau/plugins/PFDQMEventSelector.h"
0002 
0003 #include "DataFormats/Common/interface/Handle.h"
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 
0007 #include "DQMServices/Core/interface/DQMStore.h"
0008 #include "FWCore/ServiceRegistry/interface/Service.h"
0009 
0010 #include <iostream>
0011 
0012 //
0013 // -- Constructor
0014 //
0015 PFDQMEventSelector::PFDQMEventSelector(const edm::ParameterSet &pset) {
0016   verbose_ = pset.getParameter<bool>("DebugOn");
0017   inputFileName_ = pset.getParameter<std::string>("InputFileName");
0018   folderNames_ = pset.getParameter<std::vector<std::string>>("FolderNames");
0019 
0020   nEvents_ = 0;
0021   nSelectedEvents_ = 0;
0022   fileOpened_ = false;
0023 }
0024 //
0025 // -- Destructor
0026 //
0027 PFDQMEventSelector::~PFDQMEventSelector() {}
0028 
0029 //
0030 // -- BeginJob
0031 //
0032 void PFDQMEventSelector::beginJob() {
0033   dqmStore_ = edm::Service<DQMStore>().operator->();
0034   fileOpened_ = openInputFile();
0035 }
0036 //
0037 // -- Event Filtering
0038 //
0039 bool PFDQMEventSelector::filter(edm::Event &iEvent, edm::EventSetup const &iSetup) {
0040   nEvents_++;
0041   if (!fileOpened_)
0042     return false;
0043 
0044   edm::RunNumber_t runNb = iEvent.id().run();
0045   edm::EventNumber_t evtNb = iEvent.id().event();
0046   edm::LuminosityBlockNumber_t lumiNb = iEvent.id().luminosityBlock();
0047   std::ostringstream eventid_str;
0048   eventid_str << runNb << "_" << evtNb << "_" << lumiNb;
0049 
0050   for (std::vector<std::string>::const_iterator ifolder = folderNames_.begin(); ifolder != folderNames_.end();
0051        ifolder++) {
0052     std::string path = "ParticleFlow/" + (*ifolder) + "/BadEvents";
0053     MonitorElement *me = dqmStore_->get(path + "/" + eventid_str.str());
0054     if (me) {
0055       nSelectedEvents_++;
0056       if (verbose_)
0057         std::cout << " Total Events " << nEvents_ << " Selected Events " << nSelectedEvents_ << " Run # : " << runNb
0058                   << " Event # : " << evtNb << " Luminosity Block # : " << lumiNb << std::endl;
0059       return true;
0060     }
0061   }
0062   return false;
0063 }
0064 //
0065 // -- End Job
0066 //
0067 void PFDQMEventSelector::endJob() {
0068   if (verbose_)
0069     std::cout << " Total Events " << nEvents_ << " Selected Events " << nSelectedEvents_ << std::endl;
0070 }
0071 //
0072 // -- Open Input File
0073 //
0074 bool PFDQMEventSelector::openInputFile() {
0075   if (inputFileName_.empty())
0076     return false;
0077   edm::LogInfo("SiStripOfflineDQM") << "SiStripOfflineDQM::openInputFile: Accessing root File" << inputFileName_;
0078   dqmStore_->open(inputFileName_, false, "", "", DQMStore::StripRunDirs);
0079   return true;
0080 }
0081 
0082 #include "FWCore/Framework/interface/MakerMacros.h"
0083 DEFINE_FWK_MODULE(PFDQMEventSelector);