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