CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/DQMOffline/PFTau/plugins/PFMETDQMAnalyzer.cc

Go to the documentation of this file.
00001 #include "DQMOffline/PFTau/plugins/PFMETDQMAnalyzer.h"
00002 
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 
00005 #include "FWCore/Framework/interface/Event.h"
00006 #include "DataFormats/Common/interface/Handle.h"
00007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00008 #include "FWCore/Utilities/interface/InputTag.h"
00009 
00010 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
00011 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
00012 #include "DataFormats/METReco/interface/MET.h"
00013 
00014 #include "DQMServices/Core/interface/DQMStore.h"
00015 #include "DQMServices/Core/interface/MonitorElement.h"
00016 #include "FWCore/ServiceRegistry/interface/Service.h"
00017 //
00018 // -- Constructor
00019 //
00020 PFMETDQMAnalyzer::PFMETDQMAnalyzer(const edm::ParameterSet& parameterSet)  
00021   
00022 {
00023   pSet_                = parameterSet;
00024   inputLabel_          = pSet_.getParameter<edm::InputTag>("InputCollection");
00025   matchLabel_          = pSet_.getParameter<edm::InputTag>("MatchCollection");
00026   benchmarkLabel_      = pSet_.getParameter<std::string>("BenchmarkLabel"); 
00027 
00028   pfMETMonitor_.setParameters(parameterSet);  
00029 
00030 }
00031 //
00032 // -- BeginJob
00033 //
00034 void PFMETDQMAnalyzer::beginJob() {
00035 
00036   Benchmark::DQM_ = edm::Service<DQMStore>().operator->();
00037   // part of the following could be put in the base class
00038   std::string path = "ParticleFlow/" + benchmarkLabel_;
00039   Benchmark::DQM_->setCurrentFolder(path.c_str());
00040   edm::LogInfo("PFJMETDQMAnalyzer") << " PFMETDQMAnalyzer::beginJob " <<"Histogram Folder path set to "<< path;
00041   pfMETMonitor_.setup(pSet_);  
00042   nBadEvents_ = 0;
00043 }
00044 //
00045 // -- Analyze
00046 //
00047 void PFMETDQMAnalyzer::analyze(edm::Event const& iEvent, 
00048                                       edm::EventSetup const& iSetup) {
00049   edm::Handle< edm::View<reco::MET> > metCollection;
00050   iEvent.getByLabel(inputLabel_, metCollection);   
00051   
00052   edm::Handle< edm::View<reco::MET> > matchedMetCollection; 
00053   iEvent.getByLabel( matchLabel_, matchedMetCollection);
00054 
00055   if (metCollection.isValid() && matchedMetCollection.isValid()) {
00056     float maxRes = 0.0;
00057     float minRes = 99.99;
00058     pfMETMonitor_.fillOne( (*metCollection)[0], (*matchedMetCollection)[0], minRes, maxRes);    
00059     edm::ParameterSet skimPS = pSet_.getParameter<edm::ParameterSet>("SkimParameter");
00060     if ( (skimPS.getParameter<bool>("switchOn")) && 
00061          (nBadEvents_ <= skimPS.getParameter<int32_t>("maximumNumberToBeStored")) ) {
00062       if ( minRes < skimPS.getParameter<double>("lowerCutOffOnResolution")) {
00063         storeBadEvents(iEvent,minRes);
00064         nBadEvents_++;
00065       } else if (maxRes > skimPS.getParameter<double>("upperCutOffOnResolution")) {
00066         nBadEvents_++;
00067         storeBadEvents(iEvent,maxRes);
00068       }
00069     }
00070   }
00071 }
00072 void PFMETDQMAnalyzer::storeBadEvents(edm::Event const& iEvent, float& val) {
00073   unsigned int runNb  = iEvent.id().run();
00074   unsigned int evtNb  = iEvent.id().event();
00075   unsigned int lumiNb = iEvent.id().luminosityBlock();
00076   
00077   std::string path = "ParticleFlow/" + benchmarkLabel_ + "/BadEvents";
00078   Benchmark::DQM_->setCurrentFolder(path.c_str());
00079   std::ostringstream eventid_str;
00080   eventid_str << runNb << "_"<< evtNb << "_" << lumiNb;
00081   MonitorElement* me = Benchmark::DQM_->get(path + "/" + eventid_str.str());
00082   if (me) me->Reset();
00083   else me = Benchmark::DQM_->bookFloat(eventid_str.str());
00084   me->Fill(val);  
00085 }
00086 
00087 //
00088 // -- EndJob
00089 // 
00090 void PFMETDQMAnalyzer::endJob() {
00091 }
00092 #include "FWCore/Framework/interface/MakerMacros.h"
00093 DEFINE_FWK_MODULE (PFMETDQMAnalyzer) ;