Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:33:11

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/PatCandidates/interface/MET.h"
0014 #include "DataFormats/METReco/interface/MET.h"
0015 #include "DataFormats/METReco/interface/CorrMETData.h"
0016 
0017 #include "JetMETCorrections/Type1MET/interface/AddCorrectionsToGenericMET.h"
0018 #include "RecoMET/METAlgorithms/interface/METSignificance.h"
0019 
0020 #include <vector>
0021 
0022 //____________________________________________________________________________||
0023 class CorrectedPATMETProducer : public edm::stream::EDProducer<> {
0024 public:
0025   explicit CorrectedPATMETProducer(const edm::ParameterSet& cfg)
0026       : corrector(), token_(consumes<METCollection>(cfg.getParameter<edm::InputTag>("src"))) {
0027     std::vector<edm::InputTag> corrInputTags = cfg.getParameter<std::vector<edm::InputTag> >("srcCorrections");
0028     std::vector<edm::EDGetTokenT<CorrMETData> > corrTokens;
0029     for (std::vector<edm::InputTag>::const_iterator inputTag = corrInputTags.begin(); inputTag != corrInputTags.end();
0030          ++inputTag) {
0031       corrTokens.push_back(consumes<CorrMETData>(*inputTag));
0032     }
0033 
0034     corrector.setCorTokens(corrTokens);
0035 
0036     produces<METCollection>("");
0037   }
0038 
0039   ~CorrectedPATMETProducer() override {}
0040 
0041 private:
0042   AddCorrectionsToGenericMET corrector;
0043 
0044   typedef std::vector<pat::MET> METCollection;
0045 
0046   edm::EDGetTokenT<METCollection> token_;
0047 
0048   void produce(edm::Event& evt, const edm::EventSetup& es) override {
0049     edm::Handle<METCollection> srcMETCollection;
0050     evt.getByToken(token_, srcMETCollection);
0051 
0052     const pat::MET& srcMET = (*srcMETCollection)[0];
0053 
0054     //dispatching to be sure we retrieve all the informations
0055     reco::MET corrMET = corrector.getCorrectedMET(srcMET, evt);
0056     pat::MET outMET(corrMET, srcMET);
0057 
0058     auto product = std::make_unique<METCollection>();
0059 
0060     reco::METCovMatrix cov = srcMET.getSignificanceMatrix();
0061     if (!(cov(0, 0) == 0 && cov(0, 1) == 0 && cov(1, 0) == 0 && cov(1, 1) == 0)) {
0062       outMET.setSignificanceMatrix(cov);
0063       double metSig = metsig::METSignificance::getSignificance(cov, outMET);
0064       outMET.setMETSignificance(metSig);
0065     }
0066 
0067     product->push_back(outMET);
0068     evt.put(std::move(product));
0069   }
0070 };
0071 
0072 //____________________________________________________________________________||
0073 
0074 DEFINE_FWK_MODULE(CorrectedPATMETProducer);