Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
#include "DQMOffline/PFTau/plugins/PFCandidateDQMAnalyzer.h"

#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include "DataFormats/Common/interface/Handle.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"

#include "DataFormats/Candidate/interface/Candidate.h"
#include "DataFormats/Candidate/interface/CandidateFwd.h"

#include "DQMServices/Core/interface/DQMStore.h"

//
// -- Constructor
//
PFCandidateDQMAnalyzer::PFCandidateDQMAnalyzer(const edm::ParameterSet &parameterSet)

{
  pSet_ = parameterSet;
  inputLabel_ = pSet_.getParameter<edm::InputTag>("InputCollection");
  matchLabel_ = pSet_.getParameter<edm::InputTag>("MatchCollection");
  benchmarkLabel_ = pSet_.getParameter<std::string>("BenchmarkLabel");
  createEfficiencyHistos_ = pSet_.getParameter<bool>("CreateEfficiencyHistos");

  pfCandidateMonitor_.setParameters(parameterSet);

  myCand_ = consumes<edm::View<reco::Candidate>>(inputLabel_);
  myMatchedCand_ = consumes<edm::View<reco::Candidate>>(matchLabel_);

  std::string folder = benchmarkLabel_;

  subsystemname_ = "ParticleFlow";
  eventInfoFolder_ = subsystemname_ + "/" + folder;

  nBadEvents_ = 0;
}

//
// -- BookHistograms
//
void PFCandidateDQMAnalyzer::bookHistograms(DQMStore::IBooker &ibooker,
                                            edm::Run const & /* iRun */,
                                            edm::EventSetup const & /* iSetup */) {
  ibooker.setCurrentFolder(eventInfoFolder_);

  edm::LogInfo("PFCandidateDQMAnalyzer") << " PFCandidateDQMAnalyzer::bookHistograms "
                                         << "Histogram Folder path set to " << eventInfoFolder_;

  pfCandidateMonitor_.setup(ibooker, pSet_);
}

//
// -- Analyze
//
void PFCandidateDQMAnalyzer::analyze(edm::Event const &iEvent, edm::EventSetup const &iSetup) {
  edm::Handle<edm::View<reco::Candidate>> candCollection;
  edm::Handle<edm::View<reco::Candidate>> matchedCandCollection;
  if (!createEfficiencyHistos_) {
    iEvent.getByToken(myCand_, candCollection);
    iEvent.getByToken(myMatchedCand_, matchedCandCollection);
  } else {
    iEvent.getByToken(myMatchedCand_, candCollection);
    iEvent.getByToken(myCand_, matchedCandCollection);
  }

  float maxRes = 0.0;
  float minRes = 99.99;
  if (candCollection.isValid() && matchedCandCollection.isValid()) {
    pfCandidateMonitor_.fill(*candCollection, *matchedCandCollection, minRes, maxRes, pSet_);
  }
}

#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_FWK_MODULE(PFCandidateDQMAnalyzer);