Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:19:26

0001 // -*- C++ -*-
0002 
0003 //____________________________________________________________________________||
0004 #include "FWCore/Framework/interface/Frameworkfwd.h"
0005 #include "FWCore/Framework/interface/stream/EDProducer.h"
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/Framework/interface/EventSetup.h"
0008 #include "FWCore/Framework/interface/MakerMacros.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010 #include "DataFormats/Candidate/interface/Candidate.h"
0011 #include "FWCore/Utilities/interface/InputTag.h"
0012 
0013 #include "DataFormats/METReco/interface/PFMET.h"
0014 #include "DataFormats/METReco/interface/CorrMETData.h"
0015 #include "DataFormats/PatCandidates/interface/MET.h"
0016 
0017 #include "JetMETCorrections/Type1MET/interface/AddCorrectionsToGenericMET.h"
0018 
0019 #include <vector>
0020 
0021 //____________________________________________________________________________||
0022 class CorrectedPatMETProducer : public edm::stream::EDProducer<> {
0023 public:
0024   explicit CorrectedPatMETProducer(const edm::ParameterSet& cfg)
0025       : corrector()
0026   //token_(consumes<METCollection>(cfg.getParameter<edm::InputTag>("src")))
0027   {
0028     isMiniAod = (cfg.exists("isMiniAod")) ? cfg.getParameter<bool>("isMiniAod") : true;
0029     if (isMiniAod) {
0030       patToken_ = consumes<patMETCollection>(cfg.getParameter<edm::InputTag>("src"));
0031     } else {
0032       pfToken_ = consumes<pfMETCollection>(cfg.getParameter<edm::InputTag>("src"));
0033     }
0034 
0035     std::vector<edm::InputTag> corrInputTags = cfg.getParameter<std::vector<edm::InputTag> >("srcCorrections");
0036     std::vector<edm::EDGetTokenT<CorrMETData> > corrTokens;
0037     for (std::vector<edm::InputTag>::const_iterator inputTag = corrInputTags.begin(); inputTag != corrInputTags.end();
0038          ++inputTag) {
0039       corrTokens.push_back(consumes<CorrMETData>(*inputTag));
0040     }
0041 
0042     corrector.setCorTokens(corrTokens);
0043 
0044     produces<patMETCollection>("");
0045   }
0046 
0047   ~CorrectedPatMETProducer() override {}
0048 
0049 private:
0050   bool isMiniAod;
0051 
0052   AddCorrectionsToGenericMET corrector;
0053 
0054   typedef std::vector<pat::MET> patMETCollection;
0055   typedef std::vector<reco::PFMET> pfMETCollection;
0056 
0057   edm::EDGetTokenT<patMETCollection> patToken_;
0058   edm::EDGetTokenT<pfMETCollection> pfToken_;
0059 
0060   void produce(edm::Event& evt, const edm::EventSetup& es) override {
0061     edm::Handle<patMETCollection> srcPatMETCollection;
0062     edm::Handle<pfMETCollection> srcPfMETCollection;
0063     if (isMiniAod) {
0064       evt.getByToken(patToken_, srcPatMETCollection);
0065     } else {
0066       evt.getByToken(pfToken_, srcPfMETCollection);
0067     }
0068 
0069     if (isMiniAod) {
0070       //std::unique_ptr<patMETCollection> product(new patMETCollection);
0071       std::unique_ptr<patMETCollection> product(new patMETCollection);
0072       const reco::MET& srcMET = (*srcPatMETCollection)[0];
0073       pat::MET outMEtPat = corrector.getCorrectedMET(srcMET, evt);
0074       product->push_back(outMEtPat);
0075       evt.put(std::move(product));
0076     } else {
0077       std::unique_ptr<pfMETCollection> product(new pfMETCollection);
0078       const reco::PFMET& srcMET = (*srcPfMETCollection)[0];
0079       reco::PFMET outPfMEtReco = corrector.getCorrectedPFMET(srcMET, evt);
0080       product->push_back(outPfMEtReco);
0081       evt.put(std::move(product));
0082     }
0083   }
0084 };
0085 
0086 //____________________________________________________________________________||
0087 
0088 DEFINE_FWK_MODULE(CorrectedPatMETProducer);