Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:33:15

0001 // -*- C++ -*-
0002 //
0003 // Package:
0004 // Class:   PFMETBenchmarkAnalyzer.cc
0005 //
0006 /**\class PFMETBenchmarkAnalyzer PFMETBenchmarkAnalyzer.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/HepMCCandidate/interface/GenParticle.h"
0034 #include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h"
0035 #include "DataFormats/METReco/interface/CaloMET.h"
0036 #include "DataFormats/METReco/interface/CaloMETCollection.h"
0037 #include "DataFormats/METReco/interface/GenMET.h"
0038 #include "DataFormats/METReco/interface/MET.h"
0039 #include "DataFormats/METReco/interface/PFMET.h"
0040 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0041 #include "FWCore/ServiceRegistry/interface/Service.h"
0042 #include "FWCore/Utilities/interface/InputTag.h"
0043 #include "RecoParticleFlow/Benchmark/interface/PFMETBenchmark.h"
0044 using namespace edm;
0045 using namespace reco;
0046 using namespace std;
0047 
0048 //
0049 // class decleration
0050 
0051 class PFMETBenchmarkAnalyzer : public edm::one::EDAnalyzer<> {
0052 public:
0053   typedef dqm::legacy::DQMStore DQMStore;
0054   typedef dqm::legacy::MonitorElement MonitorElement;
0055 
0056   explicit PFMETBenchmarkAnalyzer(const edm::ParameterSet &);
0057   ~PFMETBenchmarkAnalyzer() override;
0058 
0059 private:
0060   void beginJob() override;
0061   void analyze(const edm::Event &, const edm::EventSetup &) override;
0062   void endJob() override;
0063   // ----------member data ---------------------------
0064   edm::EDGetTokenT<reco::GenParticleCollection> sInputTruthLabel_tok_;
0065   edm::EDGetTokenT<reco::PFMETCollection> sInputRecoLabel_tok_;
0066   edm::EDGetTokenT<reco::CaloMETCollection> sInputCaloLabel_tok_;
0067   edm::EDGetTokenT<reco::METCollection> sInputTCLabel_tok_;
0068 
0069   // neuhaus - comment
0070   PFMETBenchmark PFMETBenchmark_;
0071   string OutputFileName;
0072   bool pfmBenchmarkDebug;
0073   bool xplotAgainstReco;
0074   string xbenchmarkLabel_;
0075   dqm::legacy::DQMStore *xdbe_;
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 PFMETBenchmarkAnalyzer::PFMETBenchmarkAnalyzer(const edm::ParameterSet &iConfig)
0091 
0092 {
0093   // now do what ever initialization is needed
0094   sInputTruthLabel_tok_ = consumes<reco::GenParticleCollection>(iConfig.getParameter<InputTag>("InputTruthLabel"));
0095   sInputRecoLabel_tok_ = consumes<reco::PFMETCollection>(iConfig.getParameter<InputTag>("InputRecoLabel"));
0096   sInputCaloLabel_tok_ = consumes<reco::CaloMETCollection>(iConfig.getParameter<InputTag>("InputCaloLabel"));
0097   sInputTCLabel_tok_ = consumes<reco::METCollection>(iConfig.getParameter<InputTag>("InputTCLabel"));
0098   OutputFileName = iConfig.getUntrackedParameter<string>("OutputFile");
0099   pfmBenchmarkDebug = iConfig.getParameter<bool>("pfjBenchmarkDebug");
0100   xplotAgainstReco = iConfig.getParameter<bool>("PlotAgainstRecoQuantities");
0101   xbenchmarkLabel_ = iConfig.getParameter<string>("BenchmarkLabel");
0102   xdbe_ = edm::Service<DQMStore>().operator->();
0103 
0104   PFMETBenchmark_.setup(OutputFileName, pfmBenchmarkDebug, xplotAgainstReco, xbenchmarkLabel_, xdbe_);
0105 }
0106 
0107 PFMETBenchmarkAnalyzer::~PFMETBenchmarkAnalyzer() {
0108   // do anything here that needs to be done at desctruction time
0109   // (e.g. close files, deallocate resources etc.)
0110 }
0111 
0112 //
0113 // member functions
0114 //
0115 
0116 // ------------ method called to for each event  ------------
0117 void PFMETBenchmarkAnalyzer::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0118   // get gen jet collection
0119   Handle<GenParticleCollection> genparticles;
0120   bool isGen = iEvent.getByToken(sInputTruthLabel_tok_, genparticles);
0121   if (!isGen) {
0122     std::cout << "Warning : no Gen Particles in input !" << std::endl;
0123     return;
0124   }
0125 
0126   // get rec PFMet collection
0127   Handle<PFMETCollection> pfmets;
0128   bool isReco = iEvent.getByToken(sInputRecoLabel_tok_, pfmets);
0129   if (!isReco) {
0130     std::cout << "Warning : no PF MET in input !" << std::endl;
0131     return;
0132   }
0133 
0134   // get rec TCMet collection
0135   Handle<METCollection> tcmets;
0136   bool isTC = iEvent.getByToken(sInputTCLabel_tok_, tcmets);
0137   if (!isTC) {
0138     std::cout << "Warning : no TC MET in input !" << std::endl;
0139     return;
0140   }
0141 
0142   Handle<CaloMETCollection> calomets;
0143   bool isCalo = iEvent.getByToken(sInputCaloLabel_tok_, calomets);
0144   if (!isCalo) {
0145     std::cout << "Warning : no Calo MET in input !" << std::endl;
0146     return;
0147   }
0148 
0149   // Analyse (no "z" in "analyse" : we are in Europe, dammit!)
0150   PFMETBenchmark_.process(*pfmets, *genparticles, *calomets, *tcmets);
0151 }
0152 
0153 // ------------ method called once each job just before starting event loop
0154 // ------------
0155 void PFMETBenchmarkAnalyzer::beginJob() {}
0156 
0157 // ------------ method called once each job just after ending the event loop
0158 // ------------
0159 void PFMETBenchmarkAnalyzer::endJob() {
0160   //  PFMETBenchmark_.save();
0161   PFMETBenchmark_.analyse();
0162   PFMETBenchmark_.write();
0163 }
0164 
0165 // define this as a plug-in
0166 DEFINE_FWK_MODULE(PFMETBenchmarkAnalyzer);