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();
229 std::vector<reco::Candidate::LorentzVector>
leptons;
230 std::vector<metsig::SigInputObj> metSignObjectsLeptons;
239 leptons.push_back(lepton->p4());
241 sumLeptonP4s += lepton->p4();
245 LogDebug(
"produce") <<
" sum(leptons): Pt = " << sumLeptonP4s.pt() <<
", eta = " << sumLeptonP4s.eta()
246 <<
", phi = " << sumLeptonP4s.phi() <<
"," 247 <<
" mass = " << sumLeptonP4s.mass() << std::endl;
262 std::vector<CommonMETData> sumJetsPlusPFCandidates_leptons(leptons.size());
263 for (std::vector<CommonMETData>::iterator sumJetsPlusPFCandidates = sumJetsPlusPFCandidates_leptons.begin();
264 sumJetsPlusPFCandidates != sumJetsPlusPFCandidates_leptons.end();
265 ++sumJetsPlusPFCandidates) {
268 for (reco::PUSubMETCandInfoCollection::const_iterator
jet = jets_leptons.begin();
jet != jets_leptons.end(); ++
jet) {
270 assert(leptonIdx_dRmin >= 0 && leptonIdx_dRmin < (
int)sumJetsPlusPFCandidates_leptons.size());
272 LogDebug(
"produce") <<
"jet-to-lepton match:" 273 <<
" jetPt = " <<
jet->p4().pt() <<
", jetEta = " <<
jet->p4().eta()
274 <<
", jetPhi = " <<
jet->p4().phi() <<
" leptonPt = " << leptons[leptonIdx_dRmin].pt()
275 <<
", leptonEta = " << leptons[leptonIdx_dRmin].eta()
276 <<
", leptonPhi = " << leptons[leptonIdx_dRmin].phi() << std::endl;
278 sumJetsPlusPFCandidates_leptons[leptonIdx_dRmin].mex +=
jet->p4().px();
279 sumJetsPlusPFCandidates_leptons[leptonIdx_dRmin].mey +=
jet->p4().py();
280 sumJetsPlusPFCandidates_leptons[leptonIdx_dRmin].sumet +=
jet->p4().pt();
282 for (reco::PUSubMETCandInfoCollection::const_iterator pfCandidate = pfCandidates_leptons.begin();
283 pfCandidate != pfCandidates_leptons.end();
285 bool isWithinJet_lepton =
false;
286 if (pfCandidate->isWithinJet()) {
287 for (reco::PUSubMETCandInfoCollection::const_iterator
jet = jets_leptons.begin();
jet != jets_leptons.end();
289 double dR2 =
deltaR2(pfCandidate->p4(),
jet->p4());
291 isWithinJet_lepton =
true;
294 if (!isWithinJet_lepton) {
296 assert(leptonIdx_dRmin >= 0 && leptonIdx_dRmin < (
int)sumJetsPlusPFCandidates_leptons.size());
297 LogDebug(
"produce") <<
"pfCandidate-to-lepton match:" 298 <<
" pfCandidatePt = " << pfCandidate->p4().pt()
299 <<
", pfCandidateEta = " << pfCandidate->p4().eta()
300 <<
", pfCandidatePhi = " << pfCandidate->p4().phi()
301 <<
" leptonPt = " << leptons[leptonIdx_dRmin].pt()
302 <<
", leptonEta = " << leptons[leptonIdx_dRmin].eta()
303 <<
", leptonPhi = " << leptons[leptonIdx_dRmin].phi() << std::endl;
305 sumJetsPlusPFCandidates_leptons[leptonIdx_dRmin].mex += pfCandidate->p4().px();
306 sumJetsPlusPFCandidates_leptons[leptonIdx_dRmin].mey += pfCandidate->p4().py();
307 sumJetsPlusPFCandidates_leptons[leptonIdx_dRmin].sumet += pfCandidate->p4().pt();
309 LogDebug(
"produce") <<
" pfCandidate is within jet --> skipping." << std::endl;
312 auto sumLeptons = std::make_unique<CommonMETData>();
314 auto sumLeptonIsoCones = std::make_unique<CommonMETData>();
317 for (std::vector<CommonMETData>::iterator sumJetsPlusPFCandidates = sumJetsPlusPFCandidates_leptons.begin();
318 sumJetsPlusPFCandidates != sumJetsPlusPFCandidates_leptons.end();
319 ++sumJetsPlusPFCandidates) {
320 if (sumJetsPlusPFCandidates->sumet > leptons[leptonIdx].pt()) {
321 double leptonEnFrac = leptons[leptonIdx].pt() / sumJetsPlusPFCandidates->sumet;
322 assert(leptonEnFrac >= 0.0 && leptonEnFrac <= 1.0);
323 sumLeptons->mex += (leptonEnFrac * sumJetsPlusPFCandidates->mex);
324 sumLeptons->mey += (leptonEnFrac * sumJetsPlusPFCandidates->mey);
325 sumLeptons->sumet += (leptonEnFrac * sumJetsPlusPFCandidates->sumet);
326 double leptonIsoConeEnFrac = 1.0 - leptonEnFrac;
327 assert(leptonIsoConeEnFrac >= 0.0 && leptonIsoConeEnFrac <= 1.0);
328 sumLeptonIsoCones->mex += (leptonIsoConeEnFrac * sumJetsPlusPFCandidates->mex);
329 sumLeptonIsoCones->mey += (leptonIsoConeEnFrac * sumJetsPlusPFCandidates->mey);
330 sumLeptonIsoCones->sumet += (leptonIsoConeEnFrac * sumJetsPlusPFCandidates->sumet);
332 sumLeptons->mex += sumJetsPlusPFCandidates->mex;
333 sumLeptons->mey += sumJetsPlusPFCandidates->mey;
334 sumLeptons->sumet += sumJetsPlusPFCandidates->sumet;
342 auto sumNoPUjets = std::make_unique<CommonMETData>();
344 std::vector<metsig::SigInputObj> metSignObjectsNoPUjets;
345 auto sumNoPUjetOffsetEnCorr = std::make_unique<CommonMETData>();
347 std::vector<metsig::SigInputObj> metSignObjectsNoPUjetOffsetEnCorr;
348 auto sumPUjets = std::make_unique<CommonMETData>();
350 std::vector<metsig::SigInputObj> metSignObjectsPUjets;
352 for (reco::PUSubMETCandInfoCollection::const_iterator
jet = jets_cleaned.begin();
jet != jets_cleaned.end(); ++
jet) {
353 if (
jet->passesLooseJetId()) {
356 metSignObjectsNoPUjets.push_back(
jet->metSignObj());
357 float jetp =
jet->p4().P();
358 float jetcorr =
jet->offsetEnCorr();
359 sumNoPUjetOffsetEnCorr->mex += jetcorr *
jet->p4().px() / jetp;
360 sumNoPUjetOffsetEnCorr->mey += jetcorr *
jet->p4().py() / jetp;
361 sumNoPUjetOffsetEnCorr->mez += jetcorr *
jet->p4().pz() / jetp;
362 sumNoPUjetOffsetEnCorr->sumet += jetcorr *
jet->p4().pt() / jetp;
364 jet->metSignObj().get_type(),
366 jet->metSignObj().get_phi(),
367 (
jet->offsetEnCorr() /
jet->p4().E()) *
jet->metSignObj().get_sigma_e(),
368 jet->metSignObj().get_sigma_tan());
369 metSignObjectsNoPUjetOffsetEnCorr.push_back(pfMEtSignObjectOffsetEnCorr);
372 metSignObjectsPUjets.push_back(
jet->metSignObj());
378 auto sumNoPUunclChargedCands = std::make_unique<CommonMETData>();
380 std::vector<metsig::SigInputObj> metSignObjectsNoPUunclChargedCands;
381 auto sumPUunclChargedCands = std::make_unique<CommonMETData>();
383 std::vector<metsig::SigInputObj> metSignObjectsPUunclChargedCands;
384 auto sumUnclNeutralCands = std::make_unique<CommonMETData>();
386 std::vector<metsig::SigInputObj> metSignObjectsUnclNeutralCands;
388 for (reco::PUSubMETCandInfoCollection::const_iterator pfCandidate = pfCandidates_cleaned.begin();
389 pfCandidate != pfCandidates_cleaned.end();
391 if (pfCandidate->passesLooseJetId()) {
392 if (!pfCandidate->isWithinJet()) {
395 metSignObjectsNoPUunclChargedCands.push_back(pfCandidate->metSignObj());
398 metSignObjectsPUunclChargedCands.push_back(pfCandidate->metSignObj());
401 metSignObjectsUnclNeutralCands.push_back(pfCandidate->metSignObj());
410 auto type0Correction_output = std::make_unique<CommonMETData>();
412 type0Correction_output->mex = type0Correction_input->
mex;
413 type0Correction_output->mey = type0Correction_input->
mey;
425 double noPileUpScaleFactor =
426 (sumPUunclChargedCands->sumet > 0.)
427 ? (sumPUunclChargedCands->sumet / (sumNoPUunclChargedCands->sumet + sumPUunclChargedCands->sumet))
429 LogDebug(
"produce") <<
"noPileUpScaleFactor = " << noPileUpScaleFactor << std::endl;
431 double noPileUpMEtPx =
432 -(sumLeptons->mex + sumNoPUjets->mex + sumNoPUunclChargedCands->mex +
433 noPileUpScaleFactor *
438 noPileUpMEtPx -= (noPileUpScaleFactor *
sfLeptonIsoCones_ * sumLeptonIsoCones->mex);
441 double noPileUpMEtPy =
442 -(sumLeptons->mey + sumNoPUjets->mey + sumNoPUunclChargedCands->mey +
443 noPileUpScaleFactor *
448 noPileUpMEtPy -= (noPileUpScaleFactor *
sfLeptonIsoCones_ * sumLeptonIsoCones->mey);
451 double noPileUpMEtPt =
sqrt(noPileUpMEtPx * noPileUpMEtPx + noPileUpMEtPy * noPileUpMEtPy);
455 noPileUpMEt.setP4(noPileUpMEtP4);
458 std::vector<metsig::SigInputObj> metSignObjects_scaled;
468 metSignObjectsPUunclChargedCands,
473 metSignObjectsUnclNeutralCands,
478 noPileUpMEt.setSignificanceMatrix(pfMEtCov_recomputed);
480 LogDebug(
"produce") <<
"<NoPileUpPFMEtProducer::produce>:" << std::endl
482 <<
" PFMET: Pt = " << pfMEt_original.
pt() <<
", phi = " << pfMEt_original.
phi() <<
" " 483 <<
"(Px = " << pfMEt_original.
px() <<
", Py = " << pfMEt_original.
py() <<
")" << std::endl
484 <<
" Cov:" << std::endl
485 <<
" " << pfMEtCov(0, 0) <<
" " << pfMEtCov(0, 1) <<
"\n " << pfMEtCov(1, 0) <<
" " 486 << pfMEtCov(1, 1) << std::endl
487 <<
" no-PU MET: Pt = " << noPileUpMEt.pt() <<
", phi = " << noPileUpMEt.phi() <<
" " 488 <<
"(Px = " << noPileUpMEt.px() <<
", Py = " << noPileUpMEt.py() <<
")" << std::endl
489 <<
" Cov:" << std::endl
490 <<
" " << (noPileUpMEt.getSignificanceMatrix())(0, 0) <<
" " 491 << (noPileUpMEt.getSignificanceMatrix())(0, 1) << std::endl
492 << (noPileUpMEt.getSignificanceMatrix())(1, 0) <<
" " 493 << (noPileUpMEt.getSignificanceMatrix())(1, 1) << std::endl;
496 auto noPileUpMEtCollection = std::make_unique<reco::PFMETCollection>();
497 noPileUpMEtCollection->push_back(noPileUpMEt);
512 evt.
put(std::make_unique<double>(noPileUpScaleFactor),
"sfNoPU");
double sfNoPUunclChargedCands_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
edm::EDGetTokenT< reco::PFMETCollection > srcMEt_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
std::string sfLeptonIsoConesName_
edm::EDGetTokenT< reco::PUSubMETCandInfoCollection > srcPFCandInfoLeptonMatch_
ROOT::Math::SMatrix< double, 2 > METCovMatrix
double px() const final
x coordinate of momentum vector
double pt() const final
transverse momentum
double sfType0Correction_
std::string sfNoPUjetsName_
reco::PUSubMETCandInfoCollection cleanJets(const reco::PUSubMETCandInfoCollection &, const std::vector< reco::Candidate::LorentzVector > &, double, bool)
edm::EDGetTokenT< reco::PUSubMETCandInfoCollection > srcJetInfo_
std::vector< edm::EDGetTokenT< reco::CandidateView > > srcLeptons_
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)
std::string sfPUunclChargedCandsName_
std::string sfPUjetsName_
std::string sfUnclNeutralCandsName_
Abs< T >::type abs(const T &t)
std::vector< reco::PUSubMETCandInfo > PUSubMETCandInfoCollection
double sfNoPUjetOffsetEnCorr_
edm::EDGetTokenT< CorrMETData > srcType0Correction_
void finalizeCommonMETData(CommonMETData &metData)
std::string sfNoPUunclChargedCandsName_
std::string sfType0CorrectionName_
edm::EDGetTokenT< reco::PUSubMETCandInfoCollection > srcJetInfoLeptonMatch_
double py() const final
y coordinate of momentum vector
std::string sfLeptonsName_
math::XYZTLorentzVector LorentzVector
Lorentz vector.
edm::EDGetTokenT< reco::PUSubMETCandInfoCollection > srcPFCandInfo_
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
reco::PUSubMETCandInfoCollection cleanPFCandidates(const reco::PUSubMETCandInfoCollection &, const std::vector< reco::Candidate::LorentzVector > &, double, bool)
const_iterator end() const
metsig::SigInputObj compResolution(const T *particle) const
NoPileUpMEtUtilities utils_
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
reco::METCovMatrix computePFMEtSignificance(const std::vector< metsig::SigInputObj > &metSignObjects)
double sfPUunclChargedCands_
void initializeCommonMETData(CommonMETData &metData)
double sfUnclNeutralCands_
reco::METCovMatrix getSignificanceMatrix(void) const
PFMEtSignInterfaceBase * pfMEtSignInterface_
std::string sfNoPUjetOffsetEnCorrName_