Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-11 03:13:32

0001 // -*- C++ -*-
0002 //
0003 // Package:
0004 // Class:   PFJetBenchmarkAnalyzer.cc
0005 //
0006 /**\class PFJetBenchmarkAnalyzer PFJetBenchmarkAnalyzer.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011 
0012 
0013 */
0014 //
0015 // Original Author:  Michel Della Negra
0016 //         Created:  Wed Jan 23 10:11:13 CET 2008
0017 // Extensions by Joanna Weng
0018 //
0019 
0020 // system include files
0021 #include <memory>
0022 
0023 // user include files
0024 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0025 #include "FWCore/Framework/interface/Frameworkfwd.h"
0026 
0027 #include "FWCore/Framework/interface/Event.h"
0028 #include "FWCore/Framework/interface/MakerMacros.h"
0029 
0030 #include "DQMServices/Core/interface/DQMStore.h"
0031 #include "DataFormats/Candidate/interface/Candidate.h"
0032 #include "DataFormats/Candidate/interface/CandidateFwd.h"
0033 #include "DataFormats/JetReco/interface/BasicJetCollection.h"
0034 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
0035 #include "DataFormats/JetReco/interface/GenJet.h"
0036 #include "DataFormats/JetReco/interface/Jet.h"
0037 #include "DataFormats/JetReco/interface/PFJet.h"
0038 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0039 #include "FWCore/ServiceRegistry/interface/Service.h"
0040 #include "FWCore/Utilities/interface/InputTag.h"
0041 #include "RecoParticleFlow/Benchmark/interface/PFJetBenchmark.h"
0042 using namespace edm;
0043 using namespace reco;
0044 using namespace std;
0045 
0046 //
0047 // class decleration
0048 
0049 class PFJetBenchmarkAnalyzer : public edm::one::EDAnalyzer<> {
0050 public:
0051   typedef dqm::legacy::DQMStore DQMStore;
0052   typedef dqm::legacy::MonitorElement MonitorElement;
0053 
0054   explicit PFJetBenchmarkAnalyzer(const edm::ParameterSet &);
0055   ~PFJetBenchmarkAnalyzer() override;
0056 
0057 private:
0058   void beginJob() override;
0059   void analyze(const edm::Event &, const edm::EventSetup &) override;
0060   void endJob() override;
0061   // ----------member data ---------------------------
0062   edm::EDGetTokenT<reco::GenJetCollection> sGenJetAlgo_tok_;
0063   edm::EDGetTokenT<reco::PFJetCollection> sJetAlgo_tok_;
0064 
0065   // neuhaus - comment
0066   PFJetBenchmark PFJetBenchmark_;
0067   string outjetfilename;
0068   bool pfjBenchmarkDebug;
0069   bool plotAgainstReco;
0070   bool onlyTwoJets;
0071   double deltaRMax = 0.1;
0072   string benchmarkLabel_;
0073   double recPt;
0074   double maxEta;
0075   dqm::legacy::DQMStore *dbe_;
0076 };
0077 /// PFJet Benchmark
0078 
0079 //
0080 // constants, enums and typedefs
0081 //
0082 
0083 //
0084 // static data member definitions
0085 //
0086 
0087 //
0088 // constructors and destructor
0089 //
0090 PFJetBenchmarkAnalyzer::PFJetBenchmarkAnalyzer(const edm::ParameterSet &iConfig)
0091 
0092 {
0093   // now do what ever initialization is needed
0094   sGenJetAlgo_tok_ = consumes<reco::GenJetCollection>(iConfig.getParameter<edm::InputTag>("InputTruthLabel"));
0095   sJetAlgo_tok_ = consumes<reco::PFJetCollection>(iConfig.getParameter<edm::InputTag>("InputRecoLabel"));
0096   outjetfilename = iConfig.getUntrackedParameter<string>("OutputFile");
0097   pfjBenchmarkDebug = iConfig.getParameter<bool>("pfjBenchmarkDebug");
0098   plotAgainstReco = iConfig.getParameter<bool>("PlotAgainstRecoQuantities");
0099   onlyTwoJets = iConfig.getParameter<bool>("OnlyTwoJets");
0100   deltaRMax = iConfig.getParameter<double>("deltaRMax");
0101   benchmarkLabel_ = iConfig.getParameter<string>("BenchmarkLabel");
0102   recPt = iConfig.getParameter<double>("recPt");
0103   maxEta = iConfig.getParameter<double>("maxEta");
0104 
0105   dbe_ = edm::Service<DQMStore>().operator->();
0106 
0107   PFJetBenchmark_.setup(
0108       outjetfilename, pfjBenchmarkDebug, plotAgainstReco, onlyTwoJets, deltaRMax, benchmarkLabel_, recPt, maxEta, dbe_);
0109 }
0110 
0111 PFJetBenchmarkAnalyzer::~PFJetBenchmarkAnalyzer() {
0112   // do anything here that needs to be done at desctruction time
0113   // (e.g. close files, deallocate resources etc.)
0114 }
0115 
0116 //
0117 // member functions
0118 //
0119 
0120 // ------------ method called to for each event  ------------
0121 void PFJetBenchmarkAnalyzer::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0122   // get gen jet collection
0123   Handle<GenJetCollection> genjets;
0124   bool isGen = iEvent.getByToken(sGenJetAlgo_tok_, genjets);
0125   if (!isGen) {
0126     std::cout << "Warning : no Gen jets in input !" << std::endl;
0127     return;
0128   }
0129 
0130   // get rec PFJet collection
0131   Handle<PFJetCollection> pfjets;
0132   bool isReco = iEvent.getByToken(sJetAlgo_tok_, pfjets);
0133   if (!isReco) {
0134     std::cout << "Warning : no PF jets in input !" << std::endl;
0135     return;
0136   }
0137   // Analyse (no "z" in "analyse" : we are in Europe, dammit!)
0138   PFJetBenchmark_.process(*pfjets, *genjets);
0139 }
0140 
0141 // ------------ method called once each job just before starting event loop
0142 // ------------
0143 void PFJetBenchmarkAnalyzer::beginJob() {}
0144 
0145 // ------------ method called once each job just after ending the event loop
0146 // ------------
0147 void PFJetBenchmarkAnalyzer::endJob() {
0148   //  PFJetBenchmark_.save();
0149   PFJetBenchmark_.write();
0150 }
0151 
0152 // define this as a plug-in
0153 DEFINE_FWK_MODULE(PFJetBenchmarkAnalyzer);