17 : moduleLabel_(
cfg.getParameter<
std::
string>(
"@module_label")) {
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"));
30 for (vInputTag::const_iterator it = srcLeptonsTags.begin(); it != srcLeptonsTags.end(); it++) {
49 saveInputs_ = (
cfg.exists(
"saveInputs")) ?
cfg.getParameter<
bool>(
"saveInputs") :
false;
51 verbosity_ = (
cfg.exists(
"verbosity")) ?
cfg.getParameter<
int>(
"verbosity") : 0;
53 produces<reco::PFMETCollection>();
76 produces<double>(
"sfNoPU");
91 metData.
mex += p4.px();
92 metData.
mey += p4.py();
93 metData.
mez += p4.pz();
94 metData.
sumet += p4.pt();
99 metData.
phi = atan2(metData.
mey, metData.
mex);
104 int leptonIdx_dR2min = -1;
105 double dR2min = 1.e+3;
107 for (std::vector<reco::Candidate::LorentzVector>::const_iterator lepton =
leptons.begin(); lepton !=
leptons.end();
109 double dR2 =
deltaR2(*lepton, p4_ref);
110 if (leptonIdx_dR2min == -1 || dR2 < dR2min) {
111 leptonIdx_dR2min = leptonIdx;
116 assert(leptonIdx_dR2min >= 0 && leptonIdx_dR2min < (
int)
leptons.size());
117 return leptonIdx_dR2min;
121 const std::vector<metsig::SigInputObj>& metSignObjects,
125 double sf_value = sf;
126 if (sf_value > sfMax)
128 if (sf_value < sfMin)
130 for (std::vector<metsig::SigInputObj>::const_iterator metSignObject = metSignObjects.begin();
131 metSignObject != metSignObjects.end();
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);
145 if (metSignObjects.size() >= 2) {
147 pfMEtSignAlgorithm.
addObjects(metSignObjects);
154 edm::LogWarning(
"computePFMEtSignificance") <<
"Inversion of PFMEt covariance matrix failed, det = " << det
155 <<
" --> replacing covariance matrix by resolution defaults !!";
166 std::cout << label_part1 <<
" #" <<
idx << label_part2 <<
": Pt = " << candidate.
pt() <<
", eta = " << candidate.
eta()
167 <<
", phi = " << candidate.
phi() <<
" (charge = " << candidate.
charge() <<
")" << std::endl;
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;
194 std::cout <<
"): Pt = " << pfCand.
p4().pt() <<
", eta = " << pfCand.
p4().eta() <<
", phi = " << pfCand.
p4().phi();
197 isWithinJet_string =
"true";
199 isWithinJet_string =
"false";
200 std::cout <<
" (isWithinJet = " << isWithinJet_string <<
")";
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,
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
496 auto noPileUpMEtCollection = std::make_unique<reco::PFMETCollection>();
497 noPileUpMEtCollection->push_back(noPileUpMEt);
512 evt.
put(std::make_unique<double>(noPileUpScaleFactor),
"sfNoPU");
const double defaultPFMEtResolutionY
const void addObjects(const std::vector< metsig::SigInputObj > &EventVec)
double sfNoPUunclChargedCands_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
reco::METCovMatrix getSignificanceMatrix(void) const
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
#define DEFINE_FWK_MODULE(type)
std::string sfLeptonIsoConesName_
edm::EDGetTokenT< reco::PUSubMETCandInfoCollection > srcPFCandInfoLeptonMatch_
ROOT::Math::SMatrix< double, 2 > METCovMatrix
void setSignificanceMatrix(const reco::METCovMatrix &matrix)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
double sfType0Correction_
void printCommonMETData(const std::string &label, const CommonMETData &metData)
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_
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)
std::string sfPUunclChargedCandsName_
std::string sfPUjetsName_
std::string sfUnclNeutralCandsName_
Abs< T >::type abs(const T &t)
const double defaultPFMEtResolutionX
std::vector< reco::PUSubMETCandInfo > PUSubMETCandInfoCollection
~NoPileUpPFMEtProducer() override
Structure containing data common to all types of MET.
virtual int charge() const =0
electric charge
double py() const final
y coordinate of momentum vector
double sfNoPUjetOffsetEnCorr_
const reco::Candidate::LorentzVector & p4() const
void produce(edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< CorrMETData > srcType0Correction_
void finalizeCommonMETData(CommonMETData &metData)
std::string sfNoPUunclChargedCandsName_
std::string sfType0CorrectionName_
NoPileUpPFMEtProducer(const edm::ParameterSet &)
std::vector< edm::InputTag > vInputTag
edm::EDGetTokenT< reco::PUSubMETCandInfoCollection > srcJetInfoLeptonMatch_
std::string sfLeptonsName_
void printMVAMEtJetInfo(const std::string &label, int idx, const reco::PUSubMETCandInfo &jet)
math::XYZTLorentzVector LorentzVector
Lorentz vector.
edm::EDGetTokenT< reco::PUSubMETCandInfoCollection > srcPFCandInfo_
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
float passesLooseJetId() const
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
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
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)
double sfPUunclChargedCands_
void initializeCommonMETData(CommonMETData &metData)
double sfUnclNeutralCands_
reco::METCovMatrix getSignifMatrix() const
virtual double phi() const =0
momentum azimuthal angle
virtual double eta() const =0
momentum pseudorapidity
PFMEtSignInterfaceBase * pfMEtSignInterface_
std::string sfNoPUjetOffsetEnCorrName_