28 for(vInputTag::const_iterator it=srcLeptonsTags.begin();it!=srcLeptonsTags.end();it++) {
53 produces<reco::PFMETCollection>();
76 produces<double>(
"sfNoPU");
96 metData.
mex += p4.px();
97 metData.
mey += p4.py();
98 metData.
mez += p4.pz();
99 metData.
sumet += p4.pt();
105 metData.
phi = atan2(metData.
mey, metData.
mex);
110 int leptonIdx_dR2min = -1;
111 double dR2min = 1.e+3;
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;
122 assert(leptonIdx_dR2min >= 0 && leptonIdx_dR2min < (
int)leptons.size());
123 return leptonIdx_dR2min;
127 double sf,
double sfMin,
double sfMax)
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 ) {
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);
148 if ( metSignObjects.size() >= 2 ) {
150 pfMEtSignAlgorithm.
addObjects(metSignObjects);
158 <<
"Inversion of PFMEt covariance matrix failed, det = " << det
159 <<
" --> replacing covariance matrix by resolution defaults !!";
171 std::cout << label_part1 <<
" #" << idx << label_part2 <<
": Pt = " << candidate.
pt() <<
", eta = " << candidate.
eta() <<
", phi = " << candidate.
phi()
172 <<
" (charge = " << candidate.
charge() <<
")" << std::endl;
177 std::cout << label <<
": Px = " << metData.
mex <<
", Py = " << metData.
mey <<
", sumEt = " << metData.
sumet << std::endl;
182 std::cout << label <<
" #" << idx <<
" (";
185 std::cout <<
"): Pt = " << jet.
p4().pt() <<
", eta = " << jet.
p4().eta() <<
", phi = " << jet.
p4().phi();
192 std::cout << label <<
" #" << idx <<
" (";
196 std::cout <<
"): Pt = " << pfCand.
p4().pt() <<
", eta = " << pfCand.
p4().eta() <<
", phi = " << pfCand.
p4().phi();
198 if ( pfCand.
isWithinJet() ) isWithinJet_string =
"true";
199 else isWithinJet_string =
"false";
200 std::cout <<
" (isWithinJet = " << isWithinJet_string <<
")";
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 std::auto_ptr<CommonMETData> sumLeptons(
new CommonMETData());
313 std::auto_ptr<CommonMETData> sumLeptonIsoCones(
new 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 std::auto_ptr<CommonMETData> sumNoPUjets(
new CommonMETData());
342 std::vector<metsig::SigInputObj> metSignObjectsNoPUjets;
343 std::auto_ptr<CommonMETData> sumNoPUjetOffsetEnCorr(
new CommonMETData());
345 std::vector<metsig::SigInputObj> metSignObjectsNoPUjetOffsetEnCorr;
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 std::auto_ptr<CommonMETData> sumNoPUunclChargedCands(
new CommonMETData());
379 std::vector<metsig::SigInputObj> metSignObjectsNoPUunclChargedCands;
380 std::auto_ptr<CommonMETData> sumPUunclChargedCands(
new CommonMETData());
382 std::vector<metsig::SigInputObj> metSignObjectsPUunclChargedCands;
383 std::auto_ptr<CommonMETData> sumUnclNeutralCands(
new 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 std::auto_ptr<CommonMETData> type0Correction_output(
new 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;
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
474 noPileUpMEtCollection->push_back(noPileUpMEt);
476 evt.
put(noPileUpMEtCollection);
489 std::auto_ptr<double> sfNoPU(
new double(noPileUpScaleFactor));
490 evt.
put(sfNoPU,
"sfNoPU");
const double defaultPFMEtResolutionY
T getParameter(std::string const &) const
const void addObjects(const std::vector< metsig::SigInputObj > &EventVec)
double sfNoPUunclChargedCands_
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
virtual double pt() const =0
transverse momentum
#define DEFINE_FWK_MODULE(type)
std::string sfLeptonIsoConesName_
edm::EDGetTokenT< reco::PUSubMETCandInfoCollection > srcPFCandInfoLeptonMatch_
void setSignificanceMatrix(const reco::METCovMatrix &matrix)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
virtual void setP4(const LorentzVector &p4)
set 4-momentum
ROOT::Math::SMatrix< double, 2 > METCovMatrix
double sfType0Correction_
void printCommonMETData(const std::string &label, const CommonMETData &metData)
std::string sfNoPUjetsName_
virtual double pt() const
transverse momentum
reco::PUSubMETCandInfoCollection cleanJets(const reco::PUSubMETCandInfoCollection &, const std::vector< reco::Candidate::LorentzVector > &, double, bool)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::vector< PFCandidatePtr > pfCandidates(const PFJet &jet, int particleId, bool sort=true)
edm::EDGetTokenT< reco::PUSubMETCandInfoCollection > srcJetInfo_
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_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
std::string sfUnclNeutralCandsName_
Abs< T >::type abs(const T &t)
const double defaultPFMEtResolutionX
std::vector< reco::PUSubMETCandInfo > PUSubMETCandInfoCollection
double deltaR2(const T1 &t1, const T2 &t2)
Structure containing data common to all types of MET.
virtual int charge() const =0
electric charge
double sfNoPUjetOffsetEnCorr_
edm::EDGetTokenT< CorrMETData > srcType0Correction_
void finalizeCommonMETData(CommonMETData &metData)
std::string sfNoPUunclChargedCandsName_
virtual double px() const
x coordinate of momentum vector
std::string sfType0CorrectionName_
tuple idx
DEBUGGING if hasattr(process,"trackMonIterativeTracking2012"): print "trackMonIterativeTracking2012 D...
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.
reco::METCovMatrix getSignifMatrix() const
edm::EDGetTokenT< reco::PUSubMETCandInfoCollection > srcPFCandInfo_
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
std::vector< reco::PFMET > PFMETCollection
collection of PFMET objects
void produce(edm::Event &, const edm::EventSetup &)
reco::PUSubMETCandInfoCollection cleanPFCandidates(const reco::PUSubMETCandInfoCollection &, const std::vector< reco::Candidate::LorentzVector > &, double, bool)
std::vector< edm::EDGetTokenT< reco::CandidateView > > srcLeptons_
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)
virtual double phi() const
momentum azimuthal angle
float passesLooseJetId() const
void printMVAMEtPFCandInfo(const std::string &label, int idx, const reco::PUSubMETCandInfo &pfCand)
reco::METCovMatrix computePFMEtSignificance(const std::vector< metsig::SigInputObj > &metSignObjects)
virtual double py() const
y coordinate of momentum vector
double sfPUunclChargedCands_
const reco::Candidate::LorentzVector & p4() const
void initializeCommonMETData(CommonMETData &metData)
double sfUnclNeutralCands_
virtual double phi() const =0
momentum azimuthal angle
virtual double eta() const =0
momentum pseudorapidity
reco::METCovMatrix getSignificanceMatrix(void) const
PFMEtSignInterfaceBase * pfMEtSignInterface_
std::string sfNoPUjetOffsetEnCorrName_