Skip to content

Commit

Permalink
Merge pull request #29769 from ahinzmann/revert-29748-revert-29254-pu…
Browse files Browse the repository at this point in the history
…ppiNoLep_weight_in_aod

PUPPI MET in RECO
  • Loading branch information
cmsbuild committed May 9, 2020
2 parents d8aa8d5 + 01dd1d4 commit 60e3a2a
Show file tree
Hide file tree
Showing 65 changed files with 521 additions and 325 deletions.
2 changes: 1 addition & 1 deletion CommonTools/ParticleFlow/plugins/Type1PFMET.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void Type1PFMET::run(const METCollection& uncorMET,
std::vector<CorrMETData> corrections = u->mEtCorr();
corrections.push_back(delta);
//----------------- Push onto MET Collection
MET result = MET(u->sumEt() + delta.sumet, corrections, correctedMET4vector, u->vertex());
MET result = MET(u->sumEt() + delta.sumet, corrections, correctedMET4vector, u->vertex(), u->isWeighted());
corMET->push_back(result);

return;
Expand Down
2 changes: 1 addition & 1 deletion CommonTools/ParticleFlow/python/EITopPAG_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@


#### MET ####
pfMetEI = pfMET.clone(jets=cms.InputTag("pfJetsEI"))
pfMetEI = pfMET.clone(srcJets=cms.InputTag("pfJetsEI"))

#EITopPAG = cms.Sequence(
EIsequence = cms.Sequence(
Expand Down
2 changes: 1 addition & 1 deletion CommonTools/ParticleFlow/python/PFBRECO_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
from CommonTools.ParticleFlow.pfTaus_cff import *

from CommonTools.ParticleFlow.pfMET_cfi import *
pfMETPFBRECO = pfMET.clone( jets = 'pfJetsPFBRECO' )
pfMETPFBRECO = pfMET.clone( srcJets = 'pfJetsPFBRECO' )

##delta beta weighting
#from CommonTools.ParticleFlow.deltaBetaWeights_cfi import *
Expand Down
4 changes: 2 additions & 2 deletions CommonTools/ParticleFlow/python/pfMET_cfi.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import FWCore.ParameterSet.Config as cms

# Clone pfMET producer from RecoMET
from RecoMET.METProducers.PFMET_cfi import *
from RecoMET.METProducers.pfMet_cfi import *

# Should the name be changed se it is similar to pfMet from reco ??
pfMET = pfMet.clone(alias="pfMET")

# Use PF2PAT cleaned jet collection (pfJets) for MET significance
# instead of standard collection (ak4PFJets)?
# It requires that MET is produced at the end.
pfMET.jets = cms.InputTag("pfJets")
pfMET.srcJets = cms.InputTag("pfJets")

# print 'PF2PAT: Jet collection used for pfMET significance: ', pfMET.jets
19 changes: 11 additions & 8 deletions CommonTools/PileupAlgos/plugins/PuppiProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// ------------------------------------------------------------------------------------------
PuppiProducer::PuppiProducer(const edm::ParameterSet& iConfig) {
fPuppiDiagnostics = iConfig.getParameter<bool>("puppiDiagnostics");
fPuppiForLeptons = iConfig.getParameter<bool>("puppiForLeptons");
fPuppiNoLep = iConfig.getParameter<bool>("puppiNoLep");
fUseFromPVLooseTight = iConfig.getParameter<bool>("UseFromPVLooseTight");
fUseDZ = iConfig.getParameter<bool>("UseDeltaZCut");
fDZCut = iConfig.getParameter<double>("DeltaZCut");
Expand All @@ -32,7 +32,6 @@ PuppiProducer::PuppiProducer(const edm::ParameterSet& iConfig) {
fPtMaxPhotons = iConfig.getParameter<double>("PtMaxPhotons");
fEtaMaxPhotons = iConfig.getParameter<double>("EtaMaxPhotons");
fUseExistingWeights = iConfig.getParameter<bool>("useExistingWeights");
fUseWeightsNoLep = iConfig.getParameter<bool>("useWeightsNoLep");
fClonePackedCands = iConfig.getParameter<bool>("clonePackedCands");
fVtxNdofCut = iConfig.getParameter<int>("vtxNdofCut");
fVtxZCut = iConfig.getParameter<double>("vtxZCut");
Expand Down Expand Up @@ -99,6 +98,7 @@ void PuppiProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
double pD0 = -9999;
int pVtxId = -9999;
bool lFirst = true;
bool isLepton = ((std::abs(pReco.pdgId) == 11) || (std::abs(pReco.pdgId) == 13));
const pat::PackedCandidate* lPack = dynamic_cast<const pat::PackedCandidate*>(&aPF);
if (lPack == nullptr) {
const reco::PFCandidate* pPF = dynamic_cast<const reco::PFCandidate*>(&aPF);
Expand Down Expand Up @@ -152,7 +152,9 @@ void PuppiProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
if (std::abs(pReco.charge) == 0) {
pReco.id = 0;
} else {
if (tmpFromPV == 0) {
if (fPuppiNoLep && isLepton)
pReco.id = 3;
else if (tmpFromPV == 0) {
pReco.id = 2;
} // 0 is associated to PU vertex
else if (tmpFromPV == 3) {
Expand Down Expand Up @@ -182,7 +184,9 @@ void PuppiProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
pReco.id = 0;
}
if (std::abs(pReco.charge) > 0) {
if (lPack->fromPV() == 0) {
if (fPuppiNoLep && isLepton)
pReco.id = 3;
else if (lPack->fromPV() == 0) {
pReco.id = 2;
} // 0 is associated to PU vertex
else if (lPack->fromPV() == (pat::PackedCandidate::PVUsedInFit)) {
Expand Down Expand Up @@ -223,7 +227,7 @@ void PuppiProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
throw edm::Exception(edm::errors::LogicError,
"PuppiProducer: cannot get weights since inputs are not PackedCandidates");
} else {
if (fUseWeightsNoLep) {
if (fPuppiNoLep) {
curpupweight = lPack->puppiWeightNoLep();
} else {
curpupweight = lPack->puppiWeight();
Expand Down Expand Up @@ -279,7 +283,7 @@ void PuppiProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {

// Here, we are using new weights computed and putting them in the packed candidates.
if (fClonePackedCands && (!fUseExistingWeights)) {
if (fPuppiForLeptons)
if (fPuppiNoLep)
pCand->setPuppiWeight(pCand->puppiWeight(), lWeights[iCand]);
else
pCand->setPuppiWeight(lWeights[iCand], pCand->puppiWeightNoLep());
Expand Down Expand Up @@ -357,7 +361,7 @@ void PuppiProducer::endJob() {}
void PuppiProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<bool>("puppiDiagnostics", false);
desc.add<bool>("puppiForLeptons", false);
desc.add<bool>("puppiNoLep", false);
desc.add<bool>("UseFromPVLooseTight", false);
desc.add<bool>("UseDeltaZCut", true);
desc.add<double>("DeltaZCut", 0.3);
Expand All @@ -368,7 +372,6 @@ void PuppiProducer::fillDescriptions(edm::ConfigurationDescriptions& description
desc.add<double>("PtMaxNeutrals", 200.);
desc.add<double>("PtMaxNeutralsStartSlope", 0.);
desc.add<bool>("useExistingWeights", false);
desc.add<bool>("useWeightsNoLep", false);
desc.add<bool>("clonePackedCands", false);
desc.add<int>("vtxNdofCut", 4);
desc.add<double>("vtxZCut", 24);
Expand Down
3 changes: 1 addition & 2 deletions CommonTools/PileupAlgos/plugins/PuppiProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class PuppiProducer : public edm::stream::EDProducer<> {
std::string fPFName;
std::string fPVName;
bool fPuppiDiagnostics;
bool fPuppiForLeptons;
bool fPuppiNoLep;
bool fUseFromPVLooseTight;
bool fUseDZ;
float fDZCut;
Expand All @@ -68,7 +68,6 @@ class PuppiProducer : public edm::stream::EDProducer<> {
double fPtMaxPhotons;
double fEtaMaxPhotons;
bool fUseExistingWeights;
bool fUseWeightsNoLep;
bool fClonePackedCands;
int fVtxNdofCut;
double fVtxZCut;
Expand Down
10 changes: 7 additions & 3 deletions CommonTools/PileupAlgos/python/Puppi_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

puppi = cms.EDProducer("PuppiProducer",#cms.PSet(#"PuppiProducer",
puppiDiagnostics = cms.bool(False),
puppiForLeptons = cms.bool(False),
puppiNoLep = cms.bool(False),
UseFromPVLooseTight = cms.bool(False),
UseDeltaZCut = cms.bool(True),
DeltaZCut = cms.double(0.3),
Expand All @@ -45,7 +45,6 @@
useExp = cms.bool (False),
MinPuppiWeight = cms.double(0.01),
useExistingWeights = cms.bool(False),
useWeightsNoLep = cms.bool(False),
clonePackedCands = cms.bool(False), # should only be set to True for MiniAOD
vtxNdofCut = cms.int32(4),
vtxZCut = cms.double(24),
Expand Down Expand Up @@ -87,7 +86,7 @@
# )
)
)

from Configuration.Eras.Modifier_phase2_common_cff import phase2_common
phase2_common.toModify(
puppi,
Expand Down Expand Up @@ -116,3 +115,8 @@
)
)
)

puppiNoLep = puppi.clone(
puppiNoLep = True,
PtMaxPhotons = 20.
)
2 changes: 1 addition & 1 deletion CommonTools/PileupAlgos/python/customizePuppiTune_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def UpdatePuppiTuneV13(process):
process.puppi.useExistingWeights = False
process.puppiNoLep.useExistingWeights = False
from PhysicsTools.PatUtils.tools.runMETCorrectionsAndUncertainties import runMetCorAndUncFromMiniAOD
runMetCorAndUncFromMiniAOD(process,isData=False,metType="Puppi",postfix="Puppi",jetFlavor="AK4PFPuppi",recoMetFromPFCs=True,pfCandColl=cms.InputTag("puppiForMET"))
runMetCorAndUncFromMiniAOD(process,isData=False,metType="Puppi",postfix="Puppi",jetFlavor="AK4PFPuppi",recoMetFromPFCs=True)
from PhysicsTools.PatAlgos.patPuppiJetSpecificProducer_cfi import patPuppiJetSpecificProducer
addToProcessAndTask('patPuppiJetSpecificProducer', patPuppiJetSpecificProducer.clone(src=cms.InputTag("patJetsPuppi")), process, task)
from PhysicsTools.PatAlgos.tools.jetTools import updateJetCollection
Expand Down
5 changes: 5 additions & 0 deletions CommonTools/PileupAlgos/src/PuppiContainer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ double PuppiContainer::var_within_R(int iId,
near_pts.reserve(std::min(50UL, particles.size()));
const double r2 = R * R;
for (auto const &part : particles) {
if (part.puppi_register() == 3)
continue;
//squared_distance is in (y,phi) coords: rap() has faster access -> check it first
if (std::abs(part.rap() - centre.rap()) < R && part.squared_distance(centre) < r2) {
near_dR2s.push_back(reco::deltaR2(part, centre));
Expand Down Expand Up @@ -296,6 +298,9 @@ std::vector<double> const &PuppiContainer::puppiWeights() {
pWeight = 1;
if (rParticle.id == 2 && fApplyCHS)
pWeight = 0;
//Apply weight of 1 for leptons if puppiNoLep
if (rParticle.id == 3)
pWeight = 1;
//Basic Weight Checks
if (!edm::isFinite(pWeight)) {
pWeight = 0.0;
Expand Down
14 changes: 3 additions & 11 deletions CommonTools/PileupAlgos/test/testPUMods.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run2_mc', '')

process.load('CommonTools/PileupAlgos/Puppi_cff')
process.load('CommonTools/PileupAlgos/PhotonPuppi_cff')
from CommonTools.PileupAlgos.PhotonPuppi_cff import setupPuppiPhoton
from PhysicsTools.PatAlgos.slimming.puppiForMET_cff import makePuppiesFromMiniAOD

process.load('CommonTools/PileupAlgos/softKiller_cfi')
Expand All @@ -37,16 +35,10 @@


makePuppiesFromMiniAOD(process)
#setupPuppiPhoton(process)
#process.packedPFCandidatesNoLep = cms.EDFilter("CandPtrSelector", src = cms.InputTag("packedPFCandidates"), cut = cms.string("abs(pdgId) != 13 && abs(pdgId) != 11"))
#process.puppiNoLep = process.puppi.clone()
#process.puppiNoLep.candName = cms.InputTag('packedPFCandidatesNoLep')
#process.puppiNoLep.vertexName = cms.InputTag('offlineSlimmedPrimaryVertices')

process.load('RecoMET.METProducers.PFMET_cfi')
process.pfMet.src = cms.InputTag('puppiForMET')

process.load('RecoMET.METProducers.pfMetPuppi_cfi')
#process.puppiNoLep.useExistingWeights = True
process.puSequence = cms.Sequence(process.pfNoLepPUPPI*process.puppi*process.puppiNoLep*process.egmPhotonIDSequence*process.puppiForMET*process.pfMet)
process.puSequence = cms.Sequence(process.puppi*process.puppiNoLep*process.pfMetPuppi)
process.p = cms.Path(process.puSequence)
process.output = cms.OutputModule("PoolOutputModule",
outputCommands = cms.untracked.vstring('keep *'),
Expand Down
16 changes: 13 additions & 3 deletions DataFormats/METReco/interface/MET.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ namespace reco {
class MET : public RecoCandidate {
public:
MET();
MET(const LorentzVector& p4_, const Point& vtx_);
MET(double sumet_, const LorentzVector& p4_, const Point& vtx_);
MET(double sumet_, const std::vector<CorrMETData>& corr_, const LorentzVector& p4_, const Point& vtx_);
MET(const LorentzVector& p4_, const Point& vtx_, bool isWeighted = false);
MET(double sumet_, const LorentzVector& p4_, const Point& vtx_, bool isWeighted = false);
MET(double sumet_,
const std::vector<CorrMETData>& corr_,
const LorentzVector& p4_,
const Point& vtx_,
bool isWeighted = false);

MET* clone() const override;

Expand All @@ -69,6 +73,11 @@ namespace reco {
void setSignificanceMatrix(const reco::METCovMatrix& matrix);
reco::METCovMatrix getSignificanceMatrix(void) const;

/// Set boolean if weights were applied by algorithm (e.g. PUPPI weights)
void setIsWeighted(bool isWeighted) { mIsWeighted = isWeighted; }
/// boolean if weights were applied by algorithm (e.g. PUPPI weights)
int isWeighted() const { return mIsWeighted; }

private:
bool overlap(const Candidate&) const override;
double sumet;
Expand All @@ -79,6 +88,7 @@ namespace reco {
double signif_dyx;
double signif_dxy;
std::vector<CorrMETData> corr;
bool mIsWeighted;
};
} // namespace reco

Expand Down
8 changes: 6 additions & 2 deletions DataFormats/METReco/interface/PFMET.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ namespace reco {
class PFMET : public MET {
public:
PFMET();
PFMET(const SpecificPFMETData& pf_data_, double sumet_, const LorentzVector& fP4, const Point& fVertex)
: MET(sumet_, fP4, fVertex), pf_data(pf_data_) {}
PFMET(const SpecificPFMETData& pf_data_,
double sumet_,
const LorentzVector& fP4,
const Point& fVertex,
bool isWeighted = false)
: MET(sumet_, fP4, fVertex, isWeighted), pf_data(pf_data_) {}

~PFMET() override {}

Expand Down
11 changes: 8 additions & 3 deletions DataFormats/METReco/src/MET.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,42 @@ MET::MET() {
sumet = 0.0;
elongit = 0.0;
signif_dxx = signif_dyy = signif_dyx = signif_dxy = 0.;
mIsWeighted = false;
}

// Constructer for the case when only p4_ = (mEx, mEy, 0, mEt) is known.
// The vertex information is currently not used (but may be in the future)
// and is required by the RecoCandidate constructer.
//____________________________________________________________________________||
MET::MET(const LorentzVector& p4_, const Point& vtx_) : RecoCandidate(0, p4_, vtx_) {
MET::MET(const LorentzVector& p4_, const Point& vtx_, bool isWeighted) : RecoCandidate(0, p4_, vtx_) {
sumet = 0.0;
elongit = 0.0;
signif_dxx = signif_dyy = signif_dyx = signif_dxy = 0.;
mIsWeighted = isWeighted;
}

// Constructer for the case when the SumET is known in addition to
// p4_ = (mEx, mEy, 0, mEt). The vertex information is currently not used
// (but see above).
//____________________________________________________________________________||
MET::MET(double sumet_, const LorentzVector& p4_, const Point& vtx_) : RecoCandidate(0, p4_, vtx_) {
MET::MET(double sumet_, const LorentzVector& p4_, const Point& vtx_, bool isWeighted) : RecoCandidate(0, p4_, vtx_) {
sumet = sumet_;
elongit = 0.0;
signif_dxx = signif_dyy = signif_dyx = signif_dxy = 0.;
mIsWeighted = isWeighted;
}

// Constructor for the case when the SumET, the corrections which
// were applied to the MET, as well the MET itself p4_ = (mEx, mEy, 0, mEt)
// are all known. See above concerning the vertex information.
//____________________________________________________________________________||
MET::MET(double sumet_, const std::vector<CorrMETData>& corr_, const LorentzVector& p4_, const Point& vtx_)
MET::MET(
double sumet_, const std::vector<CorrMETData>& corr_, const LorentzVector& p4_, const Point& vtx_, bool isWeighted)
: RecoCandidate(0, p4_, vtx_) {
sumet = sumet_;
elongit = 0.0;
signif_dxx = signif_dyy = signif_dyx = signif_dxy = 0.;
mIsWeighted = isWeighted;
//-----------------------------------
// Fill the vector containing the corrections (corr) with vector of
// known corrections (corr_) passed in via the constructor.
Expand Down
15 changes: 10 additions & 5 deletions DataFormats/METReco/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
<version ClassVersion="11" checksum="2260055190"/>
</class>

<class name="reco::MET" ClassVersion="12">
<class name="reco::MET" ClassVersion="13">
<version ClassVersion="13" checksum="3178745935"/>
<version ClassVersion="12" checksum="2052216433"/>
<version ClassVersion="11" checksum="1997832393"/>
<version ClassVersion="10" checksum="3898304931"/>
Expand All @@ -58,7 +59,8 @@
<class name="std::vector<edm::Ref<std::vector<reco::CaloMET>,reco::CaloMET,edm::refhelper::FindUsingAdvance<std::vector<reco::CaloMET>,reco::CaloMET> > >"/>
<class name="std::vector<edm::Ref<std::vector<reco::MET>,reco::MET,edm::refhelper::FindUsingAdvance<std::vector<reco::MET>,reco::MET> > >"/>

<class name="reco::CaloMET" ClassVersion="12">
<class name="reco::CaloMET" ClassVersion="13">
<version ClassVersion="13" checksum="2658524417"/>
<version ClassVersion="12" checksum="3921700739"/>
<version ClassVersion="11" checksum="159132251"/>
<version ClassVersion="10" checksum="3207121440"/>
Expand All @@ -67,7 +69,8 @@
<class name="edm::Wrapper<std::vector<reco::CaloMET> >"/>
<class name="std::vector<reco::CaloMET>"/>

<class name="reco::PFMET" ClassVersion="12">
<class name="reco::PFMET" ClassVersion="13">
<version ClassVersion="13" checksum="1267179224"/>
<version ClassVersion="12" checksum="3350721210"/>
<version ClassVersion="11" checksum="3463342610"/>
<version ClassVersion="10" checksum="3708270533"/>
Expand All @@ -77,7 +80,8 @@
<class name="std::vector<reco::PFMET>"/>
<class name="std::vector<edm::Ref<std::vector<reco::PFMET> > >"/>

<class name="reco::PFClusterMET" ClassVersion="12">
<class name="reco::PFClusterMET" ClassVersion="13">
<version ClassVersion="13" checksum="520383985"/>
<version ClassVersion="12" checksum="3688821779"/>
<version ClassVersion="11" checksum="3634437739"/>
<version ClassVersion="10" checksum="3408846646"/>
Expand All @@ -87,7 +91,8 @@
<class name="std::vector<reco::PFClusterMET>"/>


<class name="reco::GenMET" ClassVersion="12">
<class name="reco::GenMET" ClassVersion="13">
<version ClassVersion="13" checksum="2800901046"/>
<version ClassVersion="12" checksum="77942440"/>
<version ClassVersion="11" checksum="1091535040"/>
<version ClassVersion="10" checksum="595237107"/>
Expand Down
3 changes: 2 additions & 1 deletion DataFormats/PatCandidates/src/classes_def_objects.xml
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@
<ioread sourceClass = "pat::Jet" version="[1-]" targetClass="pat::Jet" source="" target="daughtersTemp_">
<![CDATA[daughtersTemp_.reset();]]>
</ioread>
<class name="pat::MET" ClassVersion="16">
<class name="pat::MET" ClassVersion="17">
<version ClassVersion="17" checksum="1526897576"/>
<version ClassVersion="16" checksum="2416242778"/>
<field name="corMap_" transient="true"/>
<version ClassVersion="15" checksum="428901429"/>
Expand Down

0 comments on commit 60e3a2a

Please sign in to comment.