CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/Validation/RecoParticleFlow/plugins/PFMETBenchmarkAnalyzer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    
00004 // Class:   PFMETBenchmarkAnalyzer.cc    
00005 // 
00014 //
00015 // Original Author:  Michel Della Negra
00016 //         Created:  Wed Jan 23 10:11:13 CET 2008
00017 // $Id: PFMETBenchmarkAnalyzer.cc,v 1.4 2010/02/20 21:02:45 wmtan Exp $
00018 // Extensions by Joanna Weng
00019 //
00020 
00021 
00022 // system include files
00023 #include <memory>
00024 
00025 // user include files
00026 #include "FWCore/Framework/interface/Frameworkfwd.h"
00027 #include "FWCore/Framework/interface/EDAnalyzer.h"
00028 
00029 #include "FWCore/Framework/interface/Event.h"
00030 #include "FWCore/Framework/interface/MakerMacros.h"
00031 
00032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00033 #include "DataFormats/METReco/interface/MET.h"
00034 #include "DataFormats/METReco/interface/CaloMETCollection.h"
00035 #include "DataFormats/METReco/interface/CaloMET.h"
00036 #include "DataFormats/METReco/interface/PFMET.h"
00037 #include "DataFormats/METReco/interface/GenMET.h"
00038 #include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h"
00039 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
00040 #include "DataFormats/Candidate/interface/Candidate.h"
00041 #include "DataFormats/Candidate/interface/CandidateFwd.h"
00042 #include "RecoParticleFlow/Benchmark/interface/PFMETBenchmark.h"
00043 #include "FWCore/ServiceRegistry/interface/Service.h" 
00044 #include "FWCore/Utilities/interface/InputTag.h"
00045 using namespace edm;
00046 using namespace reco;
00047 using namespace std;
00048 
00049 //
00050 // class decleration
00051 
00052  
00053 class PFMETBenchmarkAnalyzer : public edm::EDAnalyzer {
00054 public:
00055   explicit PFMETBenchmarkAnalyzer(const edm::ParameterSet&);
00056   ~PFMETBenchmarkAnalyzer();
00057 
00058 
00059 private:
00060   virtual void beginJob() ;
00061   virtual void analyze(const edm::Event&, const edm::EventSetup&);
00062   virtual void endJob() ;
00063   // ----------member data ---------------------------
00064 
00065 };
00067 
00068 //neuhaus - comment
00069 PFMETBenchmark PFMETBenchmark_;
00070 InputTag sInputTruthLabel;
00071 InputTag sInputRecoLabel;
00072 InputTag sInputCaloLabel;
00073 InputTag sInputTCLabel;
00074 string OutputFileName;
00075 bool pfmBenchmarkDebug;
00076 bool xplotAgainstReco;
00077 string xbenchmarkLabel_;
00078 DQMStore * xdbe_;
00079 //
00080 // constants, enums and typedefs
00081 //
00082 
00083 //
00084 // static data member definitions
00085 //
00086 
00087 //
00088 // constructors and destructor
00089 //
00090 PFMETBenchmarkAnalyzer::PFMETBenchmarkAnalyzer(const edm::ParameterSet& iConfig)
00091 
00092 {
00093   //now do what ever initialization is needed
00094   sInputTruthLabel = 
00095     iConfig.getParameter<InputTag>("InputTruthLabel");
00096   sInputRecoLabel = 
00097     iConfig.getParameter<InputTag>("InputRecoLabel");
00098   sInputCaloLabel = 
00099     iConfig.getParameter<InputTag>("InputCaloLabel");
00100   sInputTCLabel = 
00101     iConfig.getParameter<InputTag>("InputTCLabel");
00102   OutputFileName = 
00103     iConfig.getUntrackedParameter<string>("OutputFile");
00104   pfmBenchmarkDebug = 
00105     iConfig.getParameter<bool>("pfjBenchmarkDebug");
00106   xplotAgainstReco = 
00107     iConfig.getParameter<bool>("PlotAgainstRecoQuantities");
00108   xbenchmarkLabel_  = 
00109     iConfig.getParameter<string>("BenchmarkLabel"); 
00110   xdbe_ = edm::Service<DQMStore>().operator->();
00111 
00112   PFMETBenchmark_.setup(
00113                         OutputFileName, 
00114                         pfmBenchmarkDebug,
00115                         xplotAgainstReco,
00116                         xbenchmarkLabel_, 
00117                         xdbe_);
00118 }
00119 
00120 
00121 PFMETBenchmarkAnalyzer::~PFMETBenchmarkAnalyzer()
00122 {
00123   // do anything here that needs to be done at desctruction time
00124   // (e.g. close files, deallocate resources etc.)
00125 }
00126 
00127 
00128 //
00129 // member functions
00130 //
00131 
00132 // ------------ method called to for each event  ------------
00133 void
00134 PFMETBenchmarkAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00135 {
00136  // get gen jet collection
00137   Handle<GenParticleCollection> genparticles;
00138   bool isGen = iEvent.getByLabel(sInputTruthLabel, genparticles);
00139   if (!isGen) { 
00140     std::cout << "Warning : no Gen Particles in input !" << std::endl;
00141     return;
00142   }
00143 
00144   // get rec PFMet collection
00145   Handle<PFMETCollection> pfmets;
00146   bool isReco = iEvent.getByLabel(sInputRecoLabel, pfmets);   
00147   if (!isReco) { 
00148     std::cout << "Warning : no PF MET in input !" << std::endl;
00149     return;
00150   }
00151 
00152   // get rec TCMet collection
00153   Handle<METCollection> tcmets;
00154   bool isTC = iEvent.getByLabel(sInputTCLabel, tcmets);   
00155   if (!isTC) { 
00156     std::cout << "Warning : no TC MET in input !" << std::endl;
00157     return;
00158   }
00159 
00160   Handle<CaloMETCollection> calomets;
00161   bool isCalo = iEvent.getByLabel(sInputCaloLabel, calomets);   
00162   if (!isCalo) { 
00163     std::cout << "Warning : no Calo MET in input !" << std::endl;
00164     return;
00165   }
00166 
00167   // Analyse (no "z" in "analyse" : we are in Europe, dammit!) 
00168   PFMETBenchmark_.process(*pfmets, *genparticles, *calomets, *tcmets);
00169 }
00170 
00171 
00172 // ------------ method called once each job just before starting event loop  ------------
00173 void 
00174 PFMETBenchmarkAnalyzer::beginJob()
00175 {
00176 
00177 }
00178 
00179 // ------------ method called once each job just after ending the event loop  ------------
00180 void 
00181 PFMETBenchmarkAnalyzer::endJob() {
00182 //  PFMETBenchmark_.save();
00183   PFMETBenchmark_.analyse();
00184   PFMETBenchmark_.write();
00185 }
00186 
00187 //define this as a plug-in
00188 DEFINE_FWK_MODULE(PFMETBenchmarkAnalyzer);