CMS 3D CMS Logo

NoPileUpPFMEtProducer.cc
Go to the documentation of this file.
2 
4 
5 //#include "DataFormats/METReco/interface/PFMEtSignCovMatrix.h" //never used so far
8 
9 #include <cmath>
10 
11 const double defaultPFMEtResolutionX = 10.;
12 const double defaultPFMEtResolutionY = 10.;
13 
14 const double epsilon = 1.e-9;
15 
17  : moduleLabel_(cfg.getParameter<std::string>("@module_label")) {
18  srcMEt_ = consumes<reco::PFMETCollection>(cfg.getParameter<edm::InputTag>("srcMEt"));
19  srcMEtCov_ = edm::InputTag(); //MM, disabled for the moment until we really need it
20  //( cfg.exists("srcMEtCov") ) ?
21  // consumes<edm::Handle<> >(cfg.getParameter<edm::InputTag>("srcMEtCov")) : edm::InputTag();
22  srcJetInfo_ = consumes<reco::PUSubMETCandInfoCollection>(cfg.getParameter<edm::InputTag>("srcPUSubMETDataJet"));
24  consumes<reco::PUSubMETCandInfoCollection>(cfg.getParameter<edm::InputTag>("srcPUSubMETDataJetLeptonMatch"));
26  consumes<reco::PUSubMETCandInfoCollection>(cfg.getParameter<edm::InputTag>("srcPUSubMETDataPFCands"));
28  consumes<reco::PUSubMETCandInfoCollection>(cfg.getParameter<edm::InputTag>("srcPUSubMETDataPFCandsLeptonMatch"));
29  vInputTag srcLeptonsTags = cfg.getParameter<vInputTag>("srcLeptons");
30  for (vInputTag::const_iterator it = srcLeptonsTags.begin(); it != srcLeptonsTags.end(); it++) {
31  srcLeptons_.push_back(consumes<edm::View<reco::Candidate> >(*it));
32  }
33 
34  srcType0Correction_ = consumes<CorrMETData>(cfg.getParameter<edm::InputTag>("srcType0Correction"));
35 
36  sfNoPUjets_ = cfg.getParameter<double>("sfNoPUjets");
37  sfNoPUjetOffsetEnCorr_ = cfg.getParameter<double>("sfNoPUjetOffsetEnCorr");
38  sfPUjets_ = cfg.getParameter<double>("sfPUjets");
39  sfNoPUunclChargedCands_ = cfg.getParameter<double>("sfNoPUunclChargedCands");
40  sfPUunclChargedCands_ = cfg.getParameter<double>("sfPUunclChargedCands");
41  sfUnclNeutralCands_ = cfg.getParameter<double>("sfUnclNeutralCands");
42  sfType0Correction_ = cfg.getParameter<double>("sfType0Correction");
43  sfLeptonIsoCones_ = cfg.getParameter<double>("sfLeptonIsoCones");
44 
45  pfMEtSignInterface_ = new PFMEtSignInterfaceBase(cfg.getParameter<edm::ParameterSet>("resolution"));
46  sfMEtCovMin_ = cfg.getParameter<double>("sfMEtCovMin");
47  sfMEtCovMax_ = cfg.getParameter<double>("sfMEtCovMax");
48 
49  saveInputs_ = (cfg.exists("saveInputs")) ? cfg.getParameter<bool>("saveInputs") : false;
50 
51  verbosity_ = (cfg.exists("verbosity")) ? cfg.getParameter<int>("verbosity") : 0;
52 
53  produces<reco::PFMETCollection>();
54 
55  sfLeptonsName_ = "sumLeptons";
56  sfNoPUjetsName_ = "sumNoPUjets";
57  sfNoPUjetOffsetEnCorrName_ = "sumNoPUjetOffsetEnCorr";
58  sfPUjetsName_ = "sumPUjets";
59  sfNoPUunclChargedCandsName_ = "sumNoPUunclChargedCands";
60  sfPUunclChargedCandsName_ = "sumPUunclChargedCands";
61  sfUnclNeutralCandsName_ = "sumUnclNeutralCands";
62  sfType0CorrectionName_ = "type0Correction";
63  sfLeptonIsoConesName_ = "sumLeptonIsoCones";
64 
65  if (saveInputs_) {
66  produces<CommonMETData>(sfLeptonsName_);
67  produces<CommonMETData>(sfNoPUjetsName_);
68  produces<CommonMETData>(sfNoPUjetOffsetEnCorrName_);
69  produces<CommonMETData>(sfPUjetsName_);
70  produces<CommonMETData>(sfNoPUunclChargedCandsName_);
71  produces<CommonMETData>(sfPUunclChargedCandsName_);
72  produces<CommonMETData>(sfUnclNeutralCandsName_);
73  produces<CommonMETData>(sfType0CorrectionName_);
74  produces<CommonMETData>(sfLeptonIsoConesName_);
75  }
76  produces<double>("sfNoPU");
77 }
78 
80 
82  metData.met = 0.;
83  metData.mex = 0.;
84  metData.mey = 0.;
85  metData.mez = 0.;
86  metData.sumet = 0.;
87  metData.phi = 0.;
88 }
89 
91  metData.mex += p4.px();
92  metData.mey += p4.py();
93  metData.mez += p4.pz();
94  metData.sumet += p4.pt();
95 }
96 
98  metData.met = sqrt(metData.mex * metData.mex + metData.mey * metData.mey);
99  metData.phi = atan2(metData.mey, metData.mex);
100 }
101 
102 int findBestMatchingLepton(const std::vector<reco::Candidate::LorentzVector>& leptons,
103  const reco::Candidate::LorentzVector& p4_ref) {
104  int leptonIdx_dR2min = -1;
105  double dR2min = 1.e+3;
106  int leptonIdx = 0;
107  for (std::vector<reco::Candidate::LorentzVector>::const_iterator lepton = leptons.begin(); lepton != leptons.end();
108  ++lepton) {
109  double dR2 = deltaR2(*lepton, p4_ref);
110  if (leptonIdx_dR2min == -1 || dR2 < dR2min) {
111  leptonIdx_dR2min = leptonIdx;
112  dR2min = dR2;
113  }
114  ++leptonIdx;
115  }
116  assert(leptonIdx_dR2min >= 0 && leptonIdx_dR2min < (int)leptons.size());
117  return leptonIdx_dR2min;
118 }
119 
120 void scaleAndAddPFMEtSignObjects(std::vector<metsig::SigInputObj>& metSignObjects_scaled,
121  const std::vector<metsig::SigInputObj>& metSignObjects,
122  double sf,
123  double sfMin,
124  double sfMax) {
125  double sf_value = sf;
126  if (sf_value > sfMax)
127  sf_value = sfMax;
128  if (sf_value < sfMin)
129  sf_value = sfMin;
130  for (std::vector<metsig::SigInputObj>::const_iterator metSignObject = metSignObjects.begin();
131  metSignObject != metSignObjects.end();
132  ++metSignObject) {
133  metsig::SigInputObj metSignObject_scaled;
134  metSignObject_scaled.set(metSignObject->get_type(),
135  sf_value * metSignObject->get_energy(),
136  metSignObject->get_phi(),
137  sf_value * metSignObject->get_sigma_e(),
138  metSignObject->get_sigma_tan());
139  metSignObjects_scaled.push_back(metSignObject_scaled);
140  }
141 }
142 
143 reco::METCovMatrix computePFMEtSignificance(const std::vector<metsig::SigInputObj>& metSignObjects) {
144  reco::METCovMatrix pfMEtCov;
145  if (metSignObjects.size() >= 2) {
146  metsig::significanceAlgo pfMEtSignAlgorithm;
147  pfMEtSignAlgorithm.addObjects(metSignObjects);
148  pfMEtCov = pfMEtSignAlgorithm.getSignifMatrix();
149  }
150 
151  double det = 0;
152  pfMEtCov.Det(det);
153  if (std::abs(det) < epsilon) {
154  edm::LogWarning("computePFMEtSignificance") << "Inversion of PFMEt covariance matrix failed, det = " << det
155  << " --> replacing covariance matrix by resolution defaults !!";
157  pfMEtCov(0, 1) = 0.;
158  pfMEtCov(1, 0) = 0.;
160  }
161 
162  return pfMEtCov;
163 }
164 
165 void printP4(const std::string& label_part1, int idx, const std::string& label_part2, const reco::Candidate& candidate) {
166  std::cout << label_part1 << " #" << idx << label_part2 << ": Pt = " << candidate.pt() << ", eta = " << candidate.eta()
167  << ", phi = " << candidate.phi() << " (charge = " << candidate.charge() << ")" << std::endl;
168 }
169 
170 void printCommonMETData(const std::string& label, const CommonMETData& metData) {
171  std::cout << label << ": Px = " << metData.mex << ", Py = " << metData.mey << ", sumEt = " << metData.sumet
172  << std::endl;
173 }
174 
176  std::cout << label << " #" << idx << " (";
177  if (jet.type() == reco::PUSubMETCandInfo::kHS)
178  std::cout << "no-PU";
179  else if (jet.type() == reco::PUSubMETCandInfo::kPU)
180  std::cout << "PU";
181  std::cout << "): Pt = " << jet.p4().pt() << ", eta = " << jet.p4().eta() << ", phi = " << jet.p4().phi();
182  std::cout << " id. flags: anti-noise = " << jet.passesLooseJetId() << std::endl;
183  std::cout << std::endl;
184 }
185 
187  std::cout << label << " #" << idx << " (";
188  if (pfCand.type() == reco::PUSubMETCandInfo::kChHS)
189  std::cout << "no-PU charged";
190  else if (pfCand.type() == reco::PUSubMETCandInfo::kChPU)
191  std::cout << "PU charged";
192  else if (pfCand.type() == reco::PUSubMETCandInfo::kNeutral)
193  std::cout << "neutral";
194  std::cout << "): Pt = " << pfCand.p4().pt() << ", eta = " << pfCand.p4().eta() << ", phi = " << pfCand.p4().phi();
195  std::string isWithinJet_string;
196  if (pfCand.isWithinJet())
197  isWithinJet_string = "true";
198  else
199  isWithinJet_string = "false";
200  std::cout << " (isWithinJet = " << isWithinJet_string << ")";
201  if (pfCand.isWithinJet())
202  std::cout << " Jet id. flags: anti-noise = " << pfCand.passesLooseJetId() << std::endl;
203  std::cout << std::endl;
204 }
205 
207  LogDebug("produce") << " moduleLabel = " << moduleLabel_ << std::endl;
208 
209  // get original MET
211  evt.getByToken(srcMEt_, pfMETs);
212  if (!(pfMETs->size() == 1))
213  throw cms::Exception("NoPileUpPFMEtProducer::produce") << "Failed to find unique MET object !!\n";
214  const reco::PFMET& pfMEt_original = pfMETs->front();
215 
216  // get MET covariance matrix
217  reco::METCovMatrix pfMEtCov;
218  if (!srcMEtCov_.label().empty()) {
219  //MM manual bypass to pfMET as this case has neer been presented
220  // edm::Handle<PFMEtSignCovMatrix> pfMEtCovHandle;
221  // evt.getByToken(srcMEtCov_, pfMEtCovHandle);
222  // pfMEtCov = (*pfMEtCovHandle);
223  pfMEtCov = pfMEt_original.getSignificanceMatrix();
224  } else {
225  pfMEtCov = pfMEt_original.getSignificanceMatrix();
226  }
227 
228  // get lepton momenta
229  std::vector<reco::Candidate::LorentzVector> leptons;
230  std::vector<metsig::SigInputObj> metSignObjectsLeptons;
231  reco::Candidate::LorentzVector sumLeptonP4s;
232  for (std::vector<edm::EDGetTokenT<edm::View<reco::Candidate> > >::const_iterator srcLeptons_i = srcLeptons_.begin();
233  srcLeptons_i != srcLeptons_.end();
234  ++srcLeptons_i) {
236  evt.getByToken(*srcLeptons_i, leptons_i);
237  for (reco::CandidateView::const_iterator lepton = leptons_i->begin(); lepton != leptons_i->end(); ++lepton) {
238  leptons.push_back(lepton->p4());
239  metSignObjectsLeptons.push_back(pfMEtSignInterface_->compResolution(&(*lepton)));
240  sumLeptonP4s += lepton->p4();
241  }
242  }
243  LogDebug("produce") << " sum(leptons): Pt = " << sumLeptonP4s.pt() << ", eta = " << sumLeptonP4s.eta()
244  << ", phi = " << sumLeptonP4s.phi() << ","
245  << " mass = " << sumLeptonP4s.mass() << std::endl;
246 
247  // get jet and PFCandidate information
251  evt.getByToken(srcJetInfoLeptonMatch_, jetsLeptonMatch);
254  edm::Handle<reco::PUSubMETCandInfoCollection> pfCandidatesLeptonMatch;
255  evt.getByToken(srcPFCandInfoLeptonMatch_, pfCandidatesLeptonMatch);
256 
257  reco::PUSubMETCandInfoCollection jets_leptons = utils_.cleanJets(*jetsLeptonMatch, leptons, 0.5, true);
258  reco::PUSubMETCandInfoCollection pfCandidates_leptons =
259  utils_.cleanPFCandidates(*pfCandidatesLeptonMatch, leptons, 0.3, true);
260  std::vector<CommonMETData> sumJetsPlusPFCandidates_leptons(leptons.size());
261  for (std::vector<CommonMETData>::iterator sumJetsPlusPFCandidates = sumJetsPlusPFCandidates_leptons.begin();
262  sumJetsPlusPFCandidates != sumJetsPlusPFCandidates_leptons.end();
263  ++sumJetsPlusPFCandidates) {
264  initializeCommonMETData(*sumJetsPlusPFCandidates);
265  }
266  for (reco::PUSubMETCandInfoCollection::const_iterator jet = jets_leptons.begin(); jet != jets_leptons.end(); ++jet) {
267  int leptonIdx_dRmin = findBestMatchingLepton(leptons, jet->p4());
268  assert(leptonIdx_dRmin >= 0 && leptonIdx_dRmin < (int)sumJetsPlusPFCandidates_leptons.size());
269 
270  LogDebug("produce") << "jet-to-lepton match:"
271  << " jetPt = " << jet->p4().pt() << ", jetEta = " << jet->p4().eta()
272  << ", jetPhi = " << jet->p4().phi() << " leptonPt = " << leptons[leptonIdx_dRmin].pt()
273  << ", leptonEta = " << leptons[leptonIdx_dRmin].eta()
274  << ", leptonPhi = " << leptons[leptonIdx_dRmin].phi() << std::endl;
275 
276  sumJetsPlusPFCandidates_leptons[leptonIdx_dRmin].mex += jet->p4().px();
277  sumJetsPlusPFCandidates_leptons[leptonIdx_dRmin].mey += jet->p4().py();
278  sumJetsPlusPFCandidates_leptons[leptonIdx_dRmin].sumet += jet->p4().pt();
279  }
280  for (reco::PUSubMETCandInfoCollection::const_iterator pfCandidate = pfCandidates_leptons.begin();
281  pfCandidate != pfCandidates_leptons.end();
282  ++pfCandidate) {
283  bool isWithinJet_lepton = false;
284  if (pfCandidate->isWithinJet()) {
285  for (reco::PUSubMETCandInfoCollection::const_iterator jet = jets_leptons.begin(); jet != jets_leptons.end();
286  ++jet) {
287  double dR2 = deltaR2(pfCandidate->p4(), jet->p4());
288  if (dR2 < 0.5 * 0.5)
289  isWithinJet_lepton = true;
290  }
291  }
292  if (!isWithinJet_lepton) {
293  int leptonIdx_dRmin = findBestMatchingLepton(leptons, pfCandidate->p4());
294  assert(leptonIdx_dRmin >= 0 && leptonIdx_dRmin < (int)sumJetsPlusPFCandidates_leptons.size());
295  LogDebug("produce") << "pfCandidate-to-lepton match:"
296  << " pfCandidatePt = " << pfCandidate->p4().pt()
297  << ", pfCandidateEta = " << pfCandidate->p4().eta()
298  << ", pfCandidatePhi = " << pfCandidate->p4().phi()
299  << " leptonPt = " << leptons[leptonIdx_dRmin].pt()
300  << ", leptonEta = " << leptons[leptonIdx_dRmin].eta()
301  << ", leptonPhi = " << leptons[leptonIdx_dRmin].phi() << std::endl;
302 
303  sumJetsPlusPFCandidates_leptons[leptonIdx_dRmin].mex += pfCandidate->p4().px();
304  sumJetsPlusPFCandidates_leptons[leptonIdx_dRmin].mey += pfCandidate->p4().py();
305  sumJetsPlusPFCandidates_leptons[leptonIdx_dRmin].sumet += pfCandidate->p4().pt();
306  } else {
307  LogDebug("produce") << " pfCandidate is within jet --> skipping." << std::endl;
308  }
309  }
310  auto sumLeptons = std::make_unique<CommonMETData>();
311  initializeCommonMETData(*sumLeptons);
312  auto sumLeptonIsoCones = std::make_unique<CommonMETData>();
313  initializeCommonMETData(*sumLeptonIsoCones);
314  int leptonIdx = 0;
315  for (std::vector<CommonMETData>::iterator sumJetsPlusPFCandidates = sumJetsPlusPFCandidates_leptons.begin();
316  sumJetsPlusPFCandidates != sumJetsPlusPFCandidates_leptons.end();
317  ++sumJetsPlusPFCandidates) {
318  if (sumJetsPlusPFCandidates->sumet > leptons[leptonIdx].pt()) {
319  double leptonEnFrac = leptons[leptonIdx].pt() / sumJetsPlusPFCandidates->sumet;
320  assert(leptonEnFrac >= 0.0 && leptonEnFrac <= 1.0);
321  sumLeptons->mex += (leptonEnFrac * sumJetsPlusPFCandidates->mex);
322  sumLeptons->mey += (leptonEnFrac * sumJetsPlusPFCandidates->mey);
323  sumLeptons->sumet += (leptonEnFrac * sumJetsPlusPFCandidates->sumet);
324  double leptonIsoConeEnFrac = 1.0 - leptonEnFrac;
325  assert(leptonIsoConeEnFrac >= 0.0 && leptonIsoConeEnFrac <= 1.0);
326  sumLeptonIsoCones->mex += (leptonIsoConeEnFrac * sumJetsPlusPFCandidates->mex);
327  sumLeptonIsoCones->mey += (leptonIsoConeEnFrac * sumJetsPlusPFCandidates->mey);
328  sumLeptonIsoCones->sumet += (leptonIsoConeEnFrac * sumJetsPlusPFCandidates->sumet);
329  } else {
330  sumLeptons->mex += sumJetsPlusPFCandidates->mex;
331  sumLeptons->mey += sumJetsPlusPFCandidates->mey;
332  sumLeptons->sumet += sumJetsPlusPFCandidates->sumet;
333  }
334  ++leptonIdx;
335  }
336 
337  reco::PUSubMETCandInfoCollection jets_cleaned = utils_.cleanJets(*jets, leptons, 0.5, false);
338  reco::PUSubMETCandInfoCollection pfCandidates_cleaned = utils_.cleanPFCandidates(*pfCandidates, leptons, 0.3, false);
339 
340  auto sumNoPUjets = std::make_unique<CommonMETData>();
341  initializeCommonMETData(*sumNoPUjets);
342  std::vector<metsig::SigInputObj> metSignObjectsNoPUjets;
343  auto sumNoPUjetOffsetEnCorr = std::make_unique<CommonMETData>();
344  initializeCommonMETData(*sumNoPUjetOffsetEnCorr);
345  std::vector<metsig::SigInputObj> metSignObjectsNoPUjetOffsetEnCorr;
346  auto sumPUjets = std::make_unique<CommonMETData>();
347  initializeCommonMETData(*sumPUjets);
348  std::vector<metsig::SigInputObj> metSignObjectsPUjets;
349  for (reco::PUSubMETCandInfoCollection::const_iterator jet = jets_cleaned.begin(); jet != jets_cleaned.end(); ++jet) {
350  if (jet->passesLooseJetId()) {
351  if (jet->type() == reco::PUSubMETCandInfo::kHS) {
352  addToCommonMETData(*sumNoPUjets, jet->p4());
353  metSignObjectsNoPUjets.push_back(jet->metSignObj());
354  float jetp = jet->p4().P();
355  float jetcorr = jet->offsetEnCorr();
356  sumNoPUjetOffsetEnCorr->mex += jetcorr * jet->p4().px() / jetp;
357  sumNoPUjetOffsetEnCorr->mey += jetcorr * jet->p4().py() / jetp;
358  sumNoPUjetOffsetEnCorr->mez += jetcorr * jet->p4().pz() / jetp;
359  sumNoPUjetOffsetEnCorr->sumet += jetcorr * jet->p4().pt() / jetp;
360  metsig::SigInputObj pfMEtSignObjectOffsetEnCorr(
361  jet->metSignObj().get_type(),
362  jet->offsetEnCorr(),
363  jet->metSignObj().get_phi(),
364  (jet->offsetEnCorr() / jet->p4().E()) * jet->metSignObj().get_sigma_e(),
365  jet->metSignObj().get_sigma_tan());
366  metSignObjectsNoPUjetOffsetEnCorr.push_back(pfMEtSignObjectOffsetEnCorr);
367  } else {
368  addToCommonMETData(*sumPUjets, jet->p4());
369  metSignObjectsPUjets.push_back(jet->metSignObj());
370  }
371  }
372  }
373 
374  auto sumNoPUunclChargedCands = std::make_unique<CommonMETData>();
375  initializeCommonMETData(*sumNoPUunclChargedCands);
376  std::vector<metsig::SigInputObj> metSignObjectsNoPUunclChargedCands;
377  auto sumPUunclChargedCands = std::make_unique<CommonMETData>();
378  initializeCommonMETData(*sumPUunclChargedCands);
379  std::vector<metsig::SigInputObj> metSignObjectsPUunclChargedCands;
380  auto sumUnclNeutralCands = std::make_unique<CommonMETData>();
381  initializeCommonMETData(*sumUnclNeutralCands);
382  std::vector<metsig::SigInputObj> metSignObjectsUnclNeutralCands;
383  for (reco::PUSubMETCandInfoCollection::const_iterator pfCandidate = pfCandidates_cleaned.begin();
384  pfCandidate != pfCandidates_cleaned.end();
385  ++pfCandidate) {
386  if (pfCandidate->passesLooseJetId()) {
387  if (!pfCandidate->isWithinJet()) {
388  if (pfCandidate->type() == reco::PUSubMETCandInfo::kChHS) {
389  addToCommonMETData(*sumNoPUunclChargedCands, pfCandidate->p4());
390  metSignObjectsNoPUunclChargedCands.push_back(pfCandidate->metSignObj());
391  } else if (pfCandidate->type() == reco::PUSubMETCandInfo::kChPU) {
392  addToCommonMETData(*sumPUunclChargedCands, pfCandidate->p4());
393  metSignObjectsPUunclChargedCands.push_back(pfCandidate->metSignObj());
394  } else if (pfCandidate->type() == reco::PUSubMETCandInfo::kNeutral) {
395  addToCommonMETData(*sumUnclNeutralCands, pfCandidate->p4());
396  metSignObjectsUnclNeutralCands.push_back(pfCandidate->metSignObj());
397  }
398  }
399  }
400  }
401 
402  edm::Handle<CorrMETData> type0Correction_input;
403  evt.getByToken(srcType0Correction_, type0Correction_input);
404  auto type0Correction_output = std::make_unique<CommonMETData>();
405  initializeCommonMETData(*type0Correction_output);
406  type0Correction_output->mex = type0Correction_input->mex;
407  type0Correction_output->mey = type0Correction_input->mey;
408 
409  finalizeCommonMETData(*sumLeptons);
410  finalizeCommonMETData(*sumNoPUjetOffsetEnCorr);
411  finalizeCommonMETData(*sumNoPUjets);
412  finalizeCommonMETData(*sumPUjets);
413  finalizeCommonMETData(*sumNoPUunclChargedCands);
414  finalizeCommonMETData(*sumPUunclChargedCands);
415  finalizeCommonMETData(*sumUnclNeutralCands);
416  finalizeCommonMETData(*type0Correction_output);
417  finalizeCommonMETData(*sumLeptonIsoCones);
418 
419  double noPileUpScaleFactor =
420  (sumPUunclChargedCands->sumet > 0.)
421  ? (sumPUunclChargedCands->sumet / (sumNoPUunclChargedCands->sumet + sumPUunclChargedCands->sumet))
422  : 1.;
423  LogDebug("produce") << "noPileUpScaleFactor = " << noPileUpScaleFactor << std::endl;
424 
425  double noPileUpMEtPx =
426  -(sumLeptons->mex + sumNoPUjets->mex + sumNoPUunclChargedCands->mex +
427  noPileUpScaleFactor *
428  (sfNoPUjetOffsetEnCorr_ * sumNoPUjetOffsetEnCorr->mex + sfUnclNeutralCands_ * sumUnclNeutralCands->mex +
429  sfPUunclChargedCands_ * sumPUunclChargedCands->mex + sfPUjets_ * sumPUjets->mex)) +
430  noPileUpScaleFactor * sfType0Correction_ * type0Correction_output->mex;
431  if (sfLeptonIsoCones_ >= 0.)
432  noPileUpMEtPx -= (noPileUpScaleFactor * sfLeptonIsoCones_ * sumLeptonIsoCones->mex);
433  else
434  noPileUpMEtPx -= (std::abs(sfLeptonIsoCones_) * sumLeptonIsoCones->mex);
435  double noPileUpMEtPy =
436  -(sumLeptons->mey + sumNoPUjets->mey + sumNoPUunclChargedCands->mey +
437  noPileUpScaleFactor *
438  (sfNoPUjetOffsetEnCorr_ * sumNoPUjetOffsetEnCorr->mey + sfUnclNeutralCands_ * sumUnclNeutralCands->mey +
439  sfPUunclChargedCands_ * sumPUunclChargedCands->mey + sfPUjets_ * sumPUjets->mey)) +
440  noPileUpScaleFactor * sfType0Correction_ * type0Correction_output->mey;
441  if (sfLeptonIsoCones_ >= 0.)
442  noPileUpMEtPy -= (noPileUpScaleFactor * sfLeptonIsoCones_ * sumLeptonIsoCones->mey);
443  else
444  noPileUpMEtPy -= (std::abs(sfLeptonIsoCones_) * sumLeptonIsoCones->mey);
445  double noPileUpMEtPt = sqrt(noPileUpMEtPx * noPileUpMEtPx + noPileUpMEtPy * noPileUpMEtPy);
446  reco::Candidate::LorentzVector noPileUpMEtP4(noPileUpMEtPx, noPileUpMEtPy, 0., noPileUpMEtPt);
447 
448  reco::PFMET noPileUpMEt(pfMEt_original);
449  noPileUpMEt.setP4(noPileUpMEtP4);
450  //noPileUpMEt.setSignificanceMatrix(pfMEtCov);
451 
452  std::vector<metsig::SigInputObj> metSignObjects_scaled;
453  scaleAndAddPFMEtSignObjects(metSignObjects_scaled, metSignObjectsLeptons, 1.0, sfMEtCovMin_, sfMEtCovMax_);
455  metSignObjects_scaled, metSignObjectsNoPUjetOffsetEnCorr, sfNoPUjetOffsetEnCorr_, sfMEtCovMin_, sfMEtCovMax_);
456  scaleAndAddPFMEtSignObjects(metSignObjects_scaled, metSignObjectsNoPUjets, sfNoPUjets_, sfMEtCovMin_, sfMEtCovMax_);
458  metSignObjects_scaled, metSignObjectsPUjets, noPileUpScaleFactor * sfPUjets_, sfMEtCovMin_, sfMEtCovMax_);
460  metSignObjects_scaled, metSignObjectsNoPUunclChargedCands, sfNoPUunclChargedCands_, sfMEtCovMin_, sfMEtCovMax_);
461  scaleAndAddPFMEtSignObjects(metSignObjects_scaled,
462  metSignObjectsPUunclChargedCands,
463  noPileUpScaleFactor * sfPUunclChargedCands_,
464  sfMEtCovMin_,
465  sfMEtCovMax_);
466  scaleAndAddPFMEtSignObjects(metSignObjects_scaled,
467  metSignObjectsUnclNeutralCands,
468  noPileUpScaleFactor * sfUnclNeutralCands_,
469  sfMEtCovMin_,
470  sfMEtCovMax_);
471  reco::METCovMatrix pfMEtCov_recomputed = computePFMEtSignificance(metSignObjects_scaled);
472  noPileUpMEt.setSignificanceMatrix(pfMEtCov_recomputed);
473 
474  LogDebug("produce") << "<NoPileUpPFMEtProducer::produce>:" << std::endl
475  << " moduleLabel = " << moduleLabel_ << std::endl
476  << " PFMET: Pt = " << pfMEt_original.pt() << ", phi = " << pfMEt_original.phi() << " "
477  << "(Px = " << pfMEt_original.px() << ", Py = " << pfMEt_original.py() << ")" << std::endl
478  << " Cov:" << std::endl
479  << " " << pfMEtCov(0, 0) << " " << pfMEtCov(0, 1) << "\n " << pfMEtCov(1, 0) << " "
480  << pfMEtCov(1, 1) << std::endl
481  << " no-PU MET: Pt = " << noPileUpMEt.pt() << ", phi = " << noPileUpMEt.phi() << " "
482  << "(Px = " << noPileUpMEt.px() << ", Py = " << noPileUpMEt.py() << ")" << std::endl
483  << " Cov:" << std::endl
484  << " " << (noPileUpMEt.getSignificanceMatrix())(0, 0) << " "
485  << (noPileUpMEt.getSignificanceMatrix())(0, 1) << std::endl
486  << (noPileUpMEt.getSignificanceMatrix())(1, 0) << " "
487  << (noPileUpMEt.getSignificanceMatrix())(1, 1) << std::endl;
488 
489  // add no-PU MET object to the event
490  auto noPileUpMEtCollection = std::make_unique<reco::PFMETCollection>();
491  noPileUpMEtCollection->push_back(noPileUpMEt);
492 
493  evt.put(std::move(noPileUpMEtCollection));
494  if (saveInputs_) {
495  evt.put(std::move(sumLeptons), sfLeptonsName_);
496  evt.put(std::move(sumNoPUjetOffsetEnCorr), sfNoPUjetOffsetEnCorrName_);
497  evt.put(std::move(sumNoPUjets), sfNoPUjetsName_);
498  evt.put(std::move(sumPUjets), sfPUjetsName_);
499  evt.put(std::move(sumNoPUunclChargedCands), sfNoPUunclChargedCandsName_);
500  evt.put(std::move(sumPUunclChargedCands), sfPUunclChargedCandsName_);
501  evt.put(std::move(sumUnclNeutralCands), sfUnclNeutralCandsName_);
502  evt.put(std::move(type0Correction_output), sfType0CorrectionName_);
503  evt.put(std::move(sumLeptonIsoCones), sfLeptonIsoConesName_);
504  }
505 
506  evt.put(std::make_unique<double>(noPileUpScaleFactor), "sfNoPU");
507 }
508 
510 
const double defaultPFMEtResolutionY
const void addObjects(const std::vector< metsig::SigInputObj > &EventVec)
bool isWithinJet() const
Definition: PUSubMETData.h:37
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
reco::METCovMatrix getSignificanceMatrix(void) const
Definition: MET.cc:128
double pt() const final
transverse momentum
edm::EDGetTokenT< reco::PFMETCollection > srcMEt_
void printP4(const std::string &label_part1, int idx, const std::string &label_part2, const reco::Candidate &candidate)
virtual double pt() const =0
transverse momentum
edm::EDGetTokenT< reco::PUSubMETCandInfoCollection > srcPFCandInfoLeptonMatch_
ROOT::Math::SMatrix< double, 2 > METCovMatrix
Definition: MET.h:39
void setSignificanceMatrix(const reco::METCovMatrix &matrix)
Definition: MET.cc:142
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:536
std::string const & label() const
Definition: InputTag.h:36
void printCommonMETData(const std::string &label, const CommonMETData &metData)
assert(be >=bs)
reco::PUSubMETCandInfoCollection cleanJets(const reco::PUSubMETCandInfoCollection &, const std::vector< reco::Candidate::LorentzVector > &, double, bool)
void set(const std::string &m_type, const double &m_energy, const double &m_phi, const double &m_sigma_e, const double &m_sigma_tan)
Definition: SigInputObj.h:42
edm::EDGetTokenT< reco::PUSubMETCandInfoCollection > srcJetInfo_
std::vector< edm::EDGetTokenT< reco::CandidateView > > srcLeptons_
char const * label
double px() const final
x coordinate of momentum vector
int findBestMatchingLepton(const std::vector< reco::Candidate::LorentzVector > &leptons, const reco::Candidate::LorentzVector &p4_ref)
void addToCommonMETData(CommonMETData &metData, const reco::Candidate::LorentzVector &p4)
T sqrt(T t)
Definition: SSEVec.h:19
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const double defaultPFMEtResolutionX
std::vector< reco::PUSubMETCandInfo > PUSubMETCandInfoCollection
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Structure containing data common to all types of MET.
Definition: CommonMETData.h:12
virtual int charge() const =0
electric charge
double py() const final
y coordinate of momentum vector
const reco::Candidate::LorentzVector & p4() const
Definition: PUSubMETData.h:30
void produce(edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< CorrMETData > srcType0Correction_
const double epsilon
void finalizeCommonMETData(CommonMETData &metData)
std::string sfNoPUunclChargedCandsName_
NoPileUpPFMEtProducer(const edm::ParameterSet &)
std::vector< edm::InputTag > vInputTag
edm::EDGetTokenT< reco::PUSubMETCandInfoCollection > srcJetInfoLeptonMatch_
void printMVAMEtJetInfo(const std::string &label, int idx, const reco::PUSubMETCandInfo &jet)
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
edm::EDGetTokenT< reco::PUSubMETCandInfoCollection > srcPFCandInfo_
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
float passesLooseJetId() const
Definition: PUSubMETData.h:38
reco::PUSubMETCandInfoCollection cleanPFCandidates(const reco::PUSubMETCandInfoCollection &, const std::vector< reco::Candidate::LorentzVector > &, double, bool)
metsig::SigInputObj compResolution(const T *particle) const
const_iterator begin() const
Log< level::Warning, false > LogWarning
double mey
Definition: CorrMETData.h:16
NoPileUpMEtUtilities utils_
double mex
Definition: CorrMETData.h:15
void scaleAndAddPFMEtSignObjects(std::vector< metsig::SigInputObj > &metSignObjects_scaled, const std::vector< metsig::SigInputObj > &metSignObjects, double sf, double sfMin, double sfMax)
double phi() const final
momentum azimuthal angle
void printMVAMEtPFCandInfo(const std::string &label, int idx, const reco::PUSubMETCandInfo &pfCand)
const_iterator end() const
void setP4(const LorentzVector &p4) final
set 4-momentum
reco::METCovMatrix computePFMEtSignificance(const std::vector< metsig::SigInputObj > &metSignObjects)
def move(src, dest)
Definition: eostools.py:511
void initializeCommonMETData(CommonMETData &metData)
reco::METCovMatrix getSignifMatrix() const
virtual double phi() const =0
momentum azimuthal angle
virtual double eta() const =0
momentum pseudorapidity
#define LogDebug(id)
PFMEtSignInterfaceBase * pfMEtSignInterface_
std::string sfNoPUjetOffsetEnCorrName_