CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DQMOffline/PFTau/plugins/PFJetDQMAnalyzer.cc

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