1- #include " FWCore/Framework/interface/stream /EDProducer.h"
1+ #include " FWCore/Framework/interface/global /EDProducer.h"
22#include " FWCore/Framework/interface/Event.h"
33#include " FWCore/Framework/interface/MakerMacros.h"
44#include " FWCore/ParameterSet/interface/ParameterSet.h"
55
66#include " DataFormats/Common/interface/View.h"
77#include " DataFormats/PatCandidates/interface/Jet.h"
88#include " DataFormats/PatCandidates/interface/MET.h"
9- #include " TLorentzVector.h"
109
1110#include < cmath>
11+ #include < memory>
12+ #include < string>
1213
13- // This producer was written to embed the final refined FastSim jet pT values
14+ // This producer embeds the final refined FastSim jet pT values
1415// so that they can be used as input to the pT-based sorting routine, as well
1516// as to implement the Type-1 MET correction based on the refined jets.
16- class ProcessRefinedJets : public edm ::stream ::EDProducer<> {
17+ class ProcessRefinedJets : public edm ::global ::EDProducer<> {
1718public:
1819 explicit ProcessRefinedJets (const edm::ParameterSet &iConfig)
1920 : jetsToken_(consumes<edm::View<pat::Jet>>(iConfig.getParameter<edm::InputTag>(" jets" ))),
@@ -39,7 +40,7 @@ class ProcessRefinedJets : public edm::stream::EDProducer<> {
3940
4041 ~ProcessRefinedJets () override = default ;
4142
42- void produce (edm::Event &iEvent, const edm::EventSetup &) override {
43+ void produce (edm::StreamID, edm:: Event &iEvent, const edm::EventSetup &) const override {
4344 edm::Handle<edm::View<pat::Jet>> hJets;
4445 iEvent.getByToken (jetsToken_, hJets);
4546
@@ -54,13 +55,15 @@ class ProcessRefinedJets : public edm::stream::EDProducer<> {
5455 pat::Jet j (jIn);
5556
5657 const double pt_orig = j.pt ();
57- const double phi = j.phi ();
58+ const double phi = j.phi ();
5859
5960 // mask: BvsAll > 0
6061 const float bvsAll = j.bDiscriminator (maskBtagName_);
61- const bool refine = (bvsAll > 0 .f );
62+ const bool refine = (bvsAll > 0 .f );
6263
63- const double pt_ref = j.hasUserFloat (refinedPtName_) ? static_cast <double >(j.userFloat (refinedPtName_)) : pt_orig;
64+ const double pt_ref = j.hasUserFloat (refinedPtName_)
65+ ? static_cast <double >(j.userFloat (refinedPtName_))
66+ : pt_orig;
6467
6568 const double pt_final = refine ? pt_ref : pt_orig;
6669
@@ -94,35 +97,25 @@ class ProcessRefinedJets : public edm::stream::EDProducer<> {
9497 for (auto const &mIn : *hMET) {
9598 pat::MET m (mIn );
9699
97- // --- original MET as TLorentzVector ---
98100 const double pxOrig = m.px ();
99101 const double pyOrig = m.py ();
100- const double ptOrig = std::sqrt (pxOrig * pxOrig + pyOrig * pyOrig );
101- const double phiOrig = std::atan2 (pyOrig, pxOrig );
102+ const double ptOrig = m. pt ( );
103+ const double phiOrig = m. phi ( );
102104
103- TLorentzVector metOrig;
104- metOrig.SetPxPyPzE (pxOrig, pyOrig, 0.0 , ptOrig); // pz=0, E ~ pt (E not really used for MET)
105+ const double pxFinal = pxOrig + sumDeltaPx;
106+ const double pyFinal = pyOrig + sumDeltaPy;
107+ const double ptFinal = std::sqrt (pxFinal * pxFinal + pyFinal * pyFinal);
108+ const double phiFinal = std::atan2 (pyFinal, pxFinal);
105109
106- // Type-1 MET correction for PUPPI MET with refined jets:
107- TLorentzVector delta;
108- const double ptDelta = std::sqrt (sumDeltaPx * sumDeltaPx + sumDeltaPy * sumDeltaPy);
109- delta.SetPxPyPzE (sumDeltaPx, sumDeltaPy, 0.0 , ptDelta);
110-
111- TLorentzVector metFinal = metOrig + delta;
112-
113- const double ptFinal = metFinal.Pt ();
114- const double phiFinal = metFinal.Phi ();
115-
116- // stash unrefined values
117- m.addUserFloat (" pt_unrefined" , static_cast <float >(ptOrig));
110+ m.addUserFloat (" pt_unrefined" , static_cast <float >(ptOrig));
118111 m.addUserFloat (" phi_unrefined" , static_cast <float >(phiOrig));
119112
120113 // stash final values, needed for sorting.
121- m.addUserFloat (" pt_final" , static_cast <float >(ptFinal));
114+ m.addUserFloat (" pt_final" , static_cast <float >(ptFinal));
122115 m.addUserFloat (" phi_final" , static_cast <float >(phiFinal));
123116
124117 // push back into pat::MET with reco::Candidate::LorentzVector ---
125- reco::Candidate::LorentzVector p4 (metFinal. Px (), metFinal. Py () , 0.0 , ptFinal);
118+ reco::Candidate::LorentzVector p4 (pxFinal, pyFinal , 0.0 , ptFinal);
126119 m.setP4 (p4);
127120
128121 outMET->push_back (std::move (m));
@@ -134,7 +127,7 @@ class ProcessRefinedJets : public edm::stream::EDProducer<> {
134127private:
135128 edm::EDGetTokenT<edm::View<pat::Jet>> jetsToken_;
136129 edm::EDGetTokenT<edm::View<pat::MET>> metToken_;
137- bool doMET_;
130+ bool doMET_ = false ;
138131
139132 std::string refinedPtName_;
140133 std::string maskBtagName_;
0 commit comments