Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:21:14

0001 #include "FWCore/Framework/interface/Frameworkfwd.h"
0002 #include "FWCore/Framework/interface/MakerMacros.h"
0003 #include "FWCore/Utilities/interface/InputTag.h"
0004 #include "L1Trigger/L1TNtuples/interface/L1TPFMetNoMuProducer.h"
0005 
0006 L1TPFMetNoMuProducer::L1TPFMetNoMuProducer(const edm::ParameterSet &ps)
0007     : thePFMETCollection_(consumes<reco::PFMETCollection>(ps.getParameter<edm::InputTag>("pfMETCollection"))),
0008       theMuonCollection_(consumes<reco::MuonCollection>(ps.getParameter<edm::InputTag>("muonCollection"))) {
0009   produces<reco::PFMETCollection>();
0010 }
0011 
0012 void L1TPFMetNoMuProducer::produce(edm::Event &event, const edm::EventSetup &eventSetup) {
0013   edm::Handle<reco::PFMETCollection> pfMet;
0014   event.getByToken(thePFMETCollection_, pfMet);
0015 
0016   edm::Handle<reco::MuonCollection> muons;
0017   event.getByToken(theMuonCollection_, muons);
0018 
0019   if (!pfMet.isValid()) {
0020     edm::LogWarning("L1TPFMetNoMuProducer") << "invalid collection for pfMet" << std::endl;
0021     return;
0022   }
0023   if (!muons.isValid()) {
0024     edm::LogWarning("L1TPFMetNoMuProducer") << "invalid collection for muons" << std::endl;
0025     return;
0026   }
0027 
0028   reco::PFMET thePFMetNoMu = pfMet.product()->front();
0029   double pfMetNoMuPx = thePFMetNoMu.px();
0030   double pfMetNoMuPy = thePFMetNoMu.py();
0031 
0032   double muPx(0.), muPy(0.);
0033 
0034   for (auto muon = muons->begin(); muon != muons->end(); ++muon) {
0035     if (muon->isPFMuon()) {
0036       muPx += muon->px();
0037       muPy += muon->py();
0038     }
0039   }
0040 
0041   pfMetNoMuPx += muPx;
0042   pfMetNoMuPy += muPy;
0043   math::XYZTLorentzVector pfMetNoMuP4(pfMetNoMuPx, pfMetNoMuPy, 0, hypot(pfMetNoMuPx, pfMetNoMuPy));
0044 
0045   thePFMetNoMu.setP4(pfMetNoMuP4);
0046 
0047   std::unique_ptr<reco::PFMETCollection> product(new reco::PFMETCollection);
0048   product->emplace_back(thePFMetNoMu.getSpecific(), thePFMetNoMu.sumEt(), thePFMetNoMu.p4(), thePFMetNoMu.vertex());
0049 
0050   event.put(std::move(product));
0051 }
0052 
0053 DEFINE_FWK_MODULE(L1TPFMetNoMuProducer);