214 if ( !(pfMETs->size() == 1) )
216 <<
"Failed to find unique MET object !!\n";
217 const reco::PFMET& pfMEt_original = pfMETs->front();
232 std::vector<reco::Candidate::LorentzVector>
leptons;
233 std::vector<metsig::SigInputObj> metSignObjectsLeptons;
236 srcLeptons_i !=
srcLeptons_.end(); ++srcLeptons_i ) {
242 lepton != leptons_i->
end(); ++lepton ) {
243 leptons.push_back(lepton->p4());
245 sumLeptonP4s += lepton->p4();
250 <<
" sum(leptons): Pt = " << sumLeptonP4s.pt() <<
", eta = " << sumLeptonP4s.eta() <<
", phi = " << sumLeptonP4s.phi() <<
"," 251 <<
" mass = " << sumLeptonP4s.mass() << std::endl;
266 std::vector<CommonMETData> sumJetsPlusPFCandidates_leptons(leptons.size());
267 for ( std::vector<CommonMETData>::iterator sumJetsPlusPFCandidates = sumJetsPlusPFCandidates_leptons.begin();
268 sumJetsPlusPFCandidates != sumJetsPlusPFCandidates_leptons.end(); ++sumJetsPlusPFCandidates ) {
271 for ( reco::PUSubMETCandInfoCollection::const_iterator
jet = jets_leptons.begin();
272 jet != jets_leptons.end(); ++
jet ) {
274 assert(leptonIdx_dRmin >= 0 && leptonIdx_dRmin < (
int)sumJetsPlusPFCandidates_leptons.size());
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;
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();
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;
295 if ( !isWithinJet_lepton ) {
297 assert(leptonIdx_dRmin >= 0 && leptonIdx_dRmin < (
int)sumJetsPlusPFCandidates_leptons.size());
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;
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();
308 <<
" pfCandidate is within jet --> skipping." << std::endl;
311 auto sumLeptons = std::make_unique<CommonMETData>();
313 auto sumLeptonIsoCones = std::make_unique<CommonMETData>();
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);
330 sumLeptons->mex += sumJetsPlusPFCandidates->mex;
331 sumLeptons->mey += sumJetsPlusPFCandidates->mey;
332 sumLeptons->sumet += sumJetsPlusPFCandidates->sumet;
340 auto sumNoPUjets = std::make_unique<CommonMETData>();
342 std::vector<metsig::SigInputObj> metSignObjectsNoPUjets;
343 auto sumNoPUjetOffsetEnCorr = std::make_unique<CommonMETData>();
345 std::vector<metsig::SigInputObj> metSignObjectsNoPUjetOffsetEnCorr;
346 auto sumPUjets = std::make_unique<CommonMETData>();
348 std::vector<metsig::SigInputObj> metSignObjectsPUjets;
350 for ( reco::PUSubMETCandInfoCollection::const_iterator
jet = jets_cleaned.begin();
351 jet != jets_cleaned.end(); ++
jet ) {
352 if (
jet->passesLooseJetId() ) {
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;
363 jet->metSignObj().get_type(),
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);
371 metSignObjectsPUjets.push_back(
jet->metSignObj() );
377 auto sumNoPUunclChargedCands = std::make_unique<CommonMETData>();
379 std::vector<metsig::SigInputObj> metSignObjectsNoPUunclChargedCands;
380 auto sumPUunclChargedCands = std::make_unique<CommonMETData>();
382 std::vector<metsig::SigInputObj> metSignObjectsPUunclChargedCands;
383 auto sumUnclNeutralCands = std::make_unique<CommonMETData>();
385 std::vector<metsig::SigInputObj> metSignObjectsUnclNeutralCands;
387 for ( reco::PUSubMETCandInfoCollection::const_iterator pfCandidate = pfCandidates_cleaned.begin();
388 pfCandidate != pfCandidates_cleaned.end(); ++pfCandidate ) {
389 if ( pfCandidate->passesLooseJetId() ) {
390 if ( !pfCandidate->isWithinJet() ) {
393 metSignObjectsNoPUunclChargedCands.push_back(pfCandidate->metSignObj() );
396 metSignObjectsPUunclChargedCands.push_back(pfCandidate->metSignObj() );
399 metSignObjectsUnclNeutralCands.push_back(pfCandidate->metSignObj() );
408 auto type0Correction_output = std::make_unique<CommonMETData>();
410 type0Correction_output->mex = type0Correction_input->
mex;
411 type0Correction_output->mey = type0Correction_input->
mey;
423 double noPileUpScaleFactor = ( sumPUunclChargedCands->sumet > 0. ) ?
424 (sumPUunclChargedCands->sumet/(sumNoPUunclChargedCands->sumet + sumPUunclChargedCands->sumet)) : 1.;
425 LogDebug(
"produce") <<
"noPileUpScaleFactor = " << noPileUpScaleFactor << std::endl;
427 double noPileUpMEtPx = -(sumLeptons->mex + sumNoPUjets->mex + sumNoPUunclChargedCands->mex
433 double noPileUpMEtPy = -(sumLeptons->mey + sumNoPUjets->mey + sumNoPUunclChargedCands->mey
439 double noPileUpMEtPt =
sqrt(noPileUpMEtPx*noPileUpMEtPx + noPileUpMEtPy*noPileUpMEtPy);
443 noPileUpMEt.setP4(noPileUpMEtP4);
446 std::vector<metsig::SigInputObj> metSignObjects_scaled;
455 noPileUpMEt.setSignificanceMatrix(pfMEtCov_recomputed);
458 <<
"<NoPileUpPFMEtProducer::produce>:" << 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;
473 auto noPileUpMEtCollection = std::make_unique<reco::PFMETCollection>();
474 noPileUpMEtCollection->push_back(noPileUpMEt);
489 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_
double px() const final
x coordinate of momentum vector
double pt() const final
transverse momentum
ROOT::Math::SMatrix< double, 2 > METCovMatrix
double sfType0Correction_
std::string sfNoPUjetsName_
reco::PUSubMETCandInfoCollection cleanJets(const reco::PUSubMETCandInfoCollection &, const std::vector< reco::Candidate::LorentzVector > &, double, bool)
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)
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_
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
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)
std::vector< edm::EDGetTokenT< reco::CandidateView > > srcLeptons_
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_