Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:21:40

0001 #include "JetMETCorrections/Type1MET/plugins/MuonMETcorrInputProducer.h"
0002 
0003 #include "DataFormats/MuonReco/interface/Muon.h"
0004 #include "DataFormats/Common/interface/Handle.h"
0005 #include "DataFormats/METReco/interface/CorrMETData.h"
0006 
0007 MuonMETcorrInputProducer::MuonMETcorrInputProducer(const edm::ParameterSet& cfg)
0008     : moduleLabel_(cfg.getParameter<std::string>("@module_label")) {
0009   token_ = consumes<reco::MuonCollection>(cfg.getParameter<edm::InputTag>("src"));
0010   muonCorrectionMapToken_ =
0011       consumes<edm::ValueMap<reco::MuonMETCorrectionData> >(cfg.getParameter<edm::InputTag>("srcMuonCorrections"));
0012 
0013   produces<CorrMETData>();
0014 }
0015 
0016 MuonMETcorrInputProducer::~MuonMETcorrInputProducer() {
0017   // nothing to be done yet...
0018 }
0019 
0020 void MuonMETcorrInputProducer::produce(edm::Event& evt, const edm::EventSetup& es) {
0021   std::unique_ptr<CorrMETData> unclEnergySum(new CorrMETData());
0022 
0023   edm::Handle<reco::MuonCollection> muons;
0024   evt.getByToken(token_, muons);
0025 
0026   typedef edm::ValueMap<reco::MuonMETCorrectionData> MuonMETCorrectionMap;
0027   edm::Handle<MuonMETCorrectionMap> muonCorrections;
0028   evt.getByToken(muonCorrectionMapToken_, muonCorrections);
0029 
0030   //--- sum muon corrections.
0031   //
0032   //    NOTE: MET = -(jets + muon corrections + "unclustered energy"),
0033   //          so "unclustered energy" = -(MET + jets + muons),
0034   //          i.e. muon corrections enter the sum of "unclustered energy" with negative sign.
0035   //
0036   int numMuons = muons->size();
0037   for (int muonIndex = 0; muonIndex < numMuons; ++muonIndex) {
0038     const reco::Muon& muon = muons->at(muonIndex);
0039 
0040     reco::MuonRef muonRef(muons, muonIndex);
0041 
0042     reco::MuonMETCorrectionData muonCorrection = (*muonCorrections)[muonRef];
0043     if (muonCorrection.type() != reco::MuonMETCorrectionData::NotUsed) {
0044       unclEnergySum->mex -= muon.px();
0045       unclEnergySum->mey -= muon.py();
0046       unclEnergySum->sumet -= muon.pt();
0047     }
0048   }
0049 
0050   //--- add sum of muon corrections to the event
0051   evt.put(std::move(unclEnergySum));
0052 }
0053 
0054 #include "FWCore/Framework/interface/MakerMacros.h"
0055 
0056 DEFINE_FWK_MODULE(MuonMETcorrInputProducer);