11 using namespace noPileUpMEtUtilities;
30 for(vInputTag::const_iterator it=srcLeptonsTags.begin();it!=srcLeptonsTags.end();it++) {
55 produces<reco::PFMETCollection>();
78 produces<double>(
"sfNoPU");
98 metData.
mex += p4.px();
99 metData.
mey += p4.py();
100 metData.
mez += p4.pz();
101 metData.
sumet += p4.pt();
107 metData.
phi = atan2(metData.
mey, metData.
mex);
112 int leptonIdx_dR2min = -1;
113 double dR2min = 1.e+3;
115 for ( std::vector<reco::Candidate::LorentzVector>::const_iterator lepton = leptons.begin();
116 lepton != leptons.end(); ++lepton ) {
117 double dR2 =
deltaR2(*lepton, p4_ref);
118 if ( leptonIdx_dR2min == -1 || dR2 < dR2min ) {
119 leptonIdx_dR2min = leptonIdx;
124 assert(leptonIdx_dR2min >= 0 && leptonIdx_dR2min < (
int)leptons.size());
125 return leptonIdx_dR2min;
129 double sf,
double sfMin,
double sfMax)
131 double sf_value = sf;
132 if ( sf_value > sfMax ) sf_value = sfMax;
133 if ( sf_value < sfMin ) sf_value = sfMin;
134 for ( std::vector<metsig::SigInputObj>::const_iterator metSignObject = metSignObjects.begin();
135 metSignObject != metSignObjects.end(); ++metSignObject ) {
137 metSignObject_scaled.
set(
138 metSignObject->get_type(),
139 sf_value*metSignObject->get_energy(),
140 metSignObject->get_phi(),
141 sf_value*metSignObject->get_sigma_e(),
142 metSignObject->get_sigma_tan());
143 metSignObjects_scaled.push_back(metSignObject_scaled);
160 if ( metSignObjects.size() >= 2 ) {
162 pfMEtSignAlgorithm.
addObjects(metSignObjects);
170 <<
"Inversion of PFMEt covariance matrix failed, det = " << det
171 <<
" --> replacing covariance matrix by resolution defaults !!";
183 std::cout << label_part1 <<
" #" << idx << label_part2 <<
": Pt = " << candidate.
pt() <<
", eta = " << candidate.
eta() <<
", phi = " << candidate.
phi()
184 <<
" (charge = " << candidate.
charge() <<
")" << std::endl;
189 std::cout << label <<
": Px = " << metData.
mex <<
", Py = " << metData.
mey <<
", sumEt = " << metData.
sumet << std::endl;
194 std::cout << label <<
" #" << idx <<
" (";
197 std::cout <<
"): Pt = " << jet.
p4_.pt() <<
", eta = " << jet.
p4_.eta() <<
", phi = " << jet.
p4_.phi();
204 std::cout << label <<
" #" << idx <<
" (";
208 std::cout <<
"): Pt = " << pfCand.
p4_.pt() <<
", eta = " << pfCand.
p4_.eta() <<
", phi = " << pfCand.
p4_.phi();
211 else isWithinJet_string =
"false";
212 std::cout <<
" (isWithinJet = " << isWithinJet_string <<
")";
226 if ( !(pfMETs->size() == 1) )
228 <<
"Failed to find unique MET object !!\n";
229 const reco::PFMET& pfMEt_original = pfMETs->front();
244 std::vector<reco::Candidate::LorentzVector>
leptons;
245 std::vector<metsig::SigInputObj> metSignObjectsLeptons;
248 srcLeptons_i !=
srcLeptons_.end(); ++srcLeptons_i ) {
254 lepton != leptons_i->end(); ++lepton ) {
256 leptons.push_back(lepton->p4());
258 sumLeptonP4s += lepton->p4();
263 <<
" sum(leptons): Pt = " << sumLeptonP4s.pt() <<
", eta = " << sumLeptonP4s.eta() <<
", phi = " << sumLeptonP4s.phi() <<
","
264 <<
" mass = " << sumLeptonP4s.mass() << std::endl;
279 std::vector<CommonMETData> sumJetsPlusPFCandidates_leptons(leptons.size());
280 for ( std::vector<CommonMETData>::iterator sumJetsPlusPFCandidates = sumJetsPlusPFCandidates_leptons.begin();
281 sumJetsPlusPFCandidates != sumJetsPlusPFCandidates_leptons.end(); ++sumJetsPlusPFCandidates ) {
284 for ( reco::MVAMEtJetInfoCollection::const_iterator
jet = jets_leptons.begin();
285 jet != jets_leptons.end(); ++
jet ) {
287 assert(leptonIdx_dRmin >= 0 && leptonIdx_dRmin < (
int)sumJetsPlusPFCandidates_leptons.size());
290 <<
"jet-to-lepton match:"
291 <<
" jetPt = " <<
jet->p4_.pt() <<
", jetEta = " <<
jet->p4_.eta() <<
", jetPhi = " <<
jet->p4_.phi()
292 <<
" leptonPt = " << leptons[leptonIdx_dRmin].pt() <<
", leptonEta = " << leptons[leptonIdx_dRmin].eta() <<
", leptonPhi = " << leptons[leptonIdx_dRmin].phi() << std::endl;
294 sumJetsPlusPFCandidates_leptons[leptonIdx_dRmin].mex +=
jet->p4_.px();
295 sumJetsPlusPFCandidates_leptons[leptonIdx_dRmin].mey +=
jet->p4_.py();
296 sumJetsPlusPFCandidates_leptons[leptonIdx_dRmin].sumet +=
jet->p4_.pt();
298 for ( reco::MVAMEtPFCandInfoCollection::const_iterator pfCandidate = pfCandidates_leptons.begin();
299 pfCandidate != pfCandidates_leptons.end(); ++pfCandidate ) {
300 bool isWithinJet_lepton =
false;
301 if ( pfCandidate->isWithinJet_ ) {
302 for ( reco::MVAMEtJetInfoCollection::const_iterator
jet = jets_leptons.begin();
303 jet != jets_leptons.end(); ++
jet ) {
304 double dR2 =
deltaR2(pfCandidate->p4_,
jet->p4_);
305 if ( dR2 < 0.5*0.5 ) isWithinJet_lepton =
true;
308 if ( !isWithinJet_lepton ) {
310 assert(leptonIdx_dRmin >= 0 && leptonIdx_dRmin < (
int)sumJetsPlusPFCandidates_leptons.size());
312 <<
"pfCandidate-to-lepton match:"
313 <<
" pfCandidatePt = " << pfCandidate->p4_.pt() <<
", pfCandidateEta = " << pfCandidate->p4_.eta() <<
", pfCandidatePhi = " << pfCandidate->p4_.phi()
314 <<
" leptonPt = " << leptons[leptonIdx_dRmin].pt() <<
", leptonEta = " << leptons[leptonIdx_dRmin].eta() <<
", leptonPhi = " << leptons[leptonIdx_dRmin].phi() << std::endl;
316 sumJetsPlusPFCandidates_leptons[leptonIdx_dRmin].mex += pfCandidate->p4_.px();
317 sumJetsPlusPFCandidates_leptons[leptonIdx_dRmin].mey += pfCandidate->p4_.py();
318 sumJetsPlusPFCandidates_leptons[leptonIdx_dRmin].sumet += pfCandidate->p4_.pt();
321 <<
" pfCandidate is within jet --> skipping." << std::endl;
324 std::auto_ptr<CommonMETData> sumLeptons(
new CommonMETData());
326 std::auto_ptr<CommonMETData> sumLeptonIsoCones(
new CommonMETData());
329 for ( std::vector<CommonMETData>::iterator sumJetsPlusPFCandidates = sumJetsPlusPFCandidates_leptons.begin();
330 sumJetsPlusPFCandidates != sumJetsPlusPFCandidates_leptons.end(); ++sumJetsPlusPFCandidates ) {
331 if ( sumJetsPlusPFCandidates->sumet > leptons[leptonIdx].pt() ) {
332 double leptonEnFrac = leptons[leptonIdx].pt()/sumJetsPlusPFCandidates->sumet;
333 assert(leptonEnFrac >= 0.0 && leptonEnFrac <= 1.0);
334 sumLeptons->mex += (leptonEnFrac*sumJetsPlusPFCandidates->mex);
335 sumLeptons->mey += (leptonEnFrac*sumJetsPlusPFCandidates->mey);
336 sumLeptons->sumet += (leptonEnFrac*sumJetsPlusPFCandidates->sumet);
337 double leptonIsoConeEnFrac = 1.0 - leptonEnFrac;
338 assert(leptonIsoConeEnFrac >= 0.0 && leptonIsoConeEnFrac <= 1.0);
339 sumLeptonIsoCones->mex += (leptonIsoConeEnFrac*sumJetsPlusPFCandidates->mex);
340 sumLeptonIsoCones->mey += (leptonIsoConeEnFrac*sumJetsPlusPFCandidates->mey);
341 sumLeptonIsoCones->sumet += (leptonIsoConeEnFrac*sumJetsPlusPFCandidates->sumet);
343 sumLeptons->mex += sumJetsPlusPFCandidates->mex;
344 sumLeptons->mey += sumJetsPlusPFCandidates->mey;
345 sumLeptons->sumet += sumJetsPlusPFCandidates->sumet;
353 std::auto_ptr<CommonMETData> sumNoPUjets(
new CommonMETData());
355 std::vector<metsig::SigInputObj> metSignObjectsNoPUjets;
356 std::auto_ptr<CommonMETData> sumNoPUjetOffsetEnCorr(
new CommonMETData());
358 std::vector<metsig::SigInputObj> metSignObjectsNoPUjetOffsetEnCorr;
361 std::vector<metsig::SigInputObj> metSignObjectsPUjets;
363 for ( reco::MVAMEtJetInfoCollection::const_iterator
jet = jets_cleaned.begin();
364 jet != jets_cleaned.end(); ++
jet ) {
366 if (
jet->passesLooseJetId_ ) {
369 metSignObjectsNoPUjets.push_back(
jet->pfMEtSignObj_);
370 sumNoPUjetOffsetEnCorr->mex +=
jet->offsetEnCorr_*
cos(
jet->p4_.phi())*
sin(
jet->p4_.theta());
371 sumNoPUjetOffsetEnCorr->mey +=
jet->offsetEnCorr_*
sin(
jet->p4_.phi())*
sin(
jet->p4_.theta());
372 sumNoPUjetOffsetEnCorr->mez +=
jet->offsetEnCorr_*
cos(
jet->p4_.theta());
373 sumNoPUjetOffsetEnCorr->sumet +=
jet->offsetEnCorr_*
sin(
jet->p4_.theta());
375 jet->pfMEtSignObj_.get_type(),
377 jet->pfMEtSignObj_.get_phi(),
378 (
jet->offsetEnCorr_/
jet->p4_.E())*
jet->pfMEtSignObj_.get_sigma_e(),
379 jet->pfMEtSignObj_.get_sigma_tan());
380 metSignObjectsNoPUjetOffsetEnCorr.push_back(pfMEtSignObjectOffsetEnCorr);
383 metSignObjectsPUjets.push_back(
jet->pfMEtSignObj_);
389 std::auto_ptr<CommonMETData> sumNoPUunclChargedCands(
new CommonMETData());
391 std::vector<metsig::SigInputObj> metSignObjectsNoPUunclChargedCands;
392 std::auto_ptr<CommonMETData> sumPUunclChargedCands(
new CommonMETData());
394 std::vector<metsig::SigInputObj> metSignObjectsPUunclChargedCands;
395 std::auto_ptr<CommonMETData> sumUnclNeutralCands(
new CommonMETData());
397 std::vector<metsig::SigInputObj> metSignObjectsUnclNeutralCands;
399 for ( reco::MVAMEtPFCandInfoCollection::const_iterator pfCandidate = pfCandidates_cleaned.begin();
400 pfCandidate != pfCandidates_cleaned.end(); ++pfCandidate ) {
402 if ( pfCandidate->passesLooseJetId_ ) {
403 if ( !pfCandidate->isWithinJet_ ) {
406 metSignObjectsNoPUunclChargedCands.push_back(pfCandidate->pfMEtSignObj_);
409 metSignObjectsPUunclChargedCands.push_back(pfCandidate->pfMEtSignObj_);
412 metSignObjectsUnclNeutralCands.push_back(pfCandidate->pfMEtSignObj_);
421 std::auto_ptr<CommonMETData> type0Correction_output(
new CommonMETData());
423 type0Correction_output->mex = type0Correction_input->mex;
424 type0Correction_output->mey = type0Correction_input->mey;
448 double noPileUpScaleFactor = ( sumPUunclChargedCands->sumet > 0. ) ?
449 (sumPUunclChargedCands->sumet/(sumNoPUunclChargedCands->sumet + sumPUunclChargedCands->sumet)) : 1.;
450 LogDebug(
"produce") <<
"noPileUpScaleFactor = " << noPileUpScaleFactor << std::endl;
452 double noPileUpMEtPx = -(sumLeptons->mex + sumNoPUjets->mex + sumNoPUunclChargedCands->mex
458 double noPileUpMEtPy = -(sumLeptons->mey + sumNoPUjets->mey + sumNoPUunclChargedCands->mey
464 double noPileUpMEtPt =
sqrt(noPileUpMEtPx*noPileUpMEtPx + noPileUpMEtPy*noPileUpMEtPy);
468 noPileUpMEt.
setP4(noPileUpMEtP4);
471 std::vector<metsig::SigInputObj> metSignObjects_scaled;
483 <<
"<NoPileUpPFMEtProducer::produce>:" << std::endl
485 <<
" PFMET: Pt = " << pfMEt_original.
pt() <<
", phi = "<<pfMEt_original.
phi()<<
" "
486 <<
"(Px = "<<pfMEt_original.
px()<<
", Py = "<<pfMEt_original.
py()<<
")"<<std::endl
487 <<
" Cov:" << std::endl
488 <<
" "<<pfMEtCov(0,0)<<
" "<<pfMEtCov(0,1)<<
"\n "
489 <<pfMEtCov(1,0)<<
" "<<pfMEtCov(1,1)<<std::endl
490 <<
" no-PU MET: Pt = "<<noPileUpMEt.
pt()<<
", phi = "<<noPileUpMEt.
phi()<<
" "
491 <<
"(Px = " << noPileUpMEt.
px() <<
", Py = " << noPileUpMEt.
py()<<
")"<<std::endl
492 <<
" Cov:" << std::endl
499 noPileUpMEtCollection->push_back(noPileUpMEt);
501 evt.
put(noPileUpMEtCollection);
514 std::auto_ptr<double> sfNoPU(
new double(noPileUpScaleFactor));
515 evt.
put(sfNoPU,
"sfNoPU");
const double defaultPFMEtResolutionY
T getParameter(std::string const &) const
const void addObjects(const std::vector< metsig::SigInputObj > &EventVec)
double sfNoPUunclChargedCands_
std::vector< edm::EDGetTokenT< edm::View< reco::Candidate > > > srcLeptons_
void printMVAMEtPFCandInfo(const std::string &label, int idx, const reco::MVAMEtPFCandInfo &pfCand)
virtual float pt() const
transverse momentum
edm::EDGetTokenT< reco::PFMETCollection > srcMEt_
edm::EDGetTokenT< reco::MVAMEtJetInfoCollection > srcJetInfo_
void printMVAMEtJetInfo(const std::string &label, int idx, const reco::MVAMEtJetInfo &jet)
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 float eta() const =0
momentum pseudorapidity
#define DEFINE_FWK_MODULE(type)
virtual float phi() const
momentum azimuthal angle
std::string sfLeptonIsoConesName_
edm::EDGetTokenT< reco::MVAMEtJetInfoCollection > srcJetInfoLeptonMatch_
void setSignificanceMatrix(const reco::METCovMatrix &matrix)
Sin< T >::type sin(const T &t)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
virtual float phi() const =0
momentum azimuthal angle
virtual void setP4(const LorentzVector &p4)
set 4-momentum
ROOT::Math::SMatrix< double, 2 > METCovMatrix
double sfType0Correction_
edm::EDGetTokenT< reco::MVAMEtPFCandInfoCollection > srcPFCandInfoLeptonMatch_
void printCommonMETData(const std::string &label, const CommonMETData &metData)
reco::MVAMEtPFCandInfoCollection cleanPFCandidates(const reco::MVAMEtPFCandInfoCollection &, const std::vector< reco::Candidate::LorentzVector > &, double, bool)
edm::EDGetTokenT< reco::MVAMEtPFCandInfoCollection > srcPFCandInfo_
reco::Candidate::LorentzVector p4_
std::string sfNoPUjetsName_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::vector< PFCandidatePtr > pfCandidates(const PFJet &jet, int particleId, bool sort=true)
virtual float pt() const =0
transverse momentum
std::vector< reco::MVAMEtJetInfo > MVAMEtJetInfoCollection
int findBestMatchingLepton(const std::vector< reco::Candidate::LorentzVector > &leptons, const reco::Candidate::LorentzVector &p4_ref)
reco::Candidate::LorentzVector p4_
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.
Cos< T >::type cos(const T &t)
std::string sfUnclNeutralCandsName_
Abs< T >::type abs(const T &t)
const double defaultPFMEtResolutionX
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_
std::vector< reco::MVAMEtPFCandInfo > MVAMEtPFCandInfoCollection
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
std::string sfLeptonsName_
math::XYZTLorentzVector LorentzVector
Lorentz vector.
reco::METCovMatrix getSignifMatrix() const
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::MVAMEtJetInfoCollection cleanJets(const reco::MVAMEtJetInfoCollection &, const std::vector< reco::Candidate::LorentzVector > &, double, bool)
metsig::SigInputObj compResolution(const T *particle) const
void scaleAndAddPFMEtSignObjects(std::vector< metsig::SigInputObj > &metSignObjects_scaled, const std::vector< metsig::SigInputObj > &metSignObjects, double sf, double sfMin, double sfMax)
reco::METCovMatrix computePFMEtSignificance(const std::vector< metsig::SigInputObj > &metSignObjects)
virtual double py() const
y coordinate of momentum vector
double sfPUunclChargedCands_
void initializeCommonMETData(CommonMETData &metData)
double sfUnclNeutralCands_
reco::METCovMatrix getSignificanceMatrix(void) const
PFMEtSignInterfaceBase * pfMEtSignInterface_
std::string sfNoPUjetOffsetEnCorrName_