Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:09:44

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