Skip to content

Commit

Permalink
Merge pull request #31494 from ahinzmann/puppiv15111
Browse files Browse the repository at this point in the history
Adapt track-vertex association in PUPPI (v15) [11_1_X]
  • Loading branch information
cmsbuild committed Nov 4, 2020
2 parents c63f534 + b4d614f commit f58146d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
32 changes: 23 additions & 9 deletions CommonTools/PileupAlgos/plugins/PuppiProducer.cc
Expand Up @@ -31,6 +31,8 @@ PuppiProducer::PuppiProducer(const edm::ParameterSet& iConfig) {
fEtaMaxCharged = iConfig.getParameter<double>("EtaMaxCharged");
fPtMaxPhotons = iConfig.getParameter<double>("PtMaxPhotons");
fEtaMaxPhotons = iConfig.getParameter<double>("EtaMaxPhotons");
fNumOfPUVtxsForCharged = iConfig.getParameter<uint>("NumOfPUVtxsForCharged");
fDZCutForChargedFromPUVtxs = iConfig.getParameter<double>("DeltaZCutForChargedFromPUVtxs");
fUseExistingWeights = iConfig.getParameter<bool>("useExistingWeights");
fClonePackedCands = iConfig.getParameter<bool>("clonePackedCands");
fVtxNdofCut = iConfig.getParameter<int>("vtxNdofCut");
Expand Down Expand Up @@ -96,15 +98,15 @@ void PuppiProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
const reco::Vertex* closestVtx = nullptr;
double pDZ = -9999;
double pD0 = -9999;
int pVtxId = -9999;
bool lFirst = true;
uint pVtxId = 0;
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);
double curdz = 9999;
int closestVtxForUnassociateds = -9999;
const reco::TrackRef aTrackRef = pPF->trackRef();
bool lFirst = true;
for (auto const& aV : *pvCol) {
if (lFirst) {
if (aTrackRef.isNonnull()) {
Expand Down Expand Up @@ -156,10 +158,12 @@ void PuppiProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
pReco.id = 3;
else if (tmpFromPV == 0) {
pReco.id = 2;
} // 0 is associated to PU vertex
else if (tmpFromPV == 3) {
if (fNumOfPUVtxsForCharged > 0 and (pVtxId <= fNumOfPUVtxsForCharged) and
(std::abs(pDZ) < fDZCutForChargedFromPUVtxs))
pReco.id = 1;
} else if (tmpFromPV == 3)
pReco.id = 1;
} else if (tmpFromPV == 1 || tmpFromPV == 2) {
else if (tmpFromPV == 1 || tmpFromPV == 2) {
pReco.id = 0;
if ((fPtMaxCharged > 0) and (pReco.pt > fPtMaxCharged))
pReco.id = 1;
Expand All @@ -184,12 +188,20 @@ void PuppiProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
pReco.id = 0;
}
if (std::abs(pReco.charge) > 0) {
if (fPuppiNoLep && isLepton)
if (fPuppiNoLep && isLepton) {
pReco.id = 3;
else if (lPack->fromPV() == 0) {
} else if (lPack->fromPV() == 0) {
pReco.id = 2;
} // 0 is associated to PU vertex
else if (lPack->fromPV() == (pat::PackedCandidate::PVUsedInFit)) {
if ((fNumOfPUVtxsForCharged > 0) and (std::abs(pDZ) < fDZCutForChargedFromPUVtxs)) {
for (size_t puVtx_idx = 1; puVtx_idx <= fNumOfPUVtxsForCharged && puVtx_idx < pvCol->size();
++puVtx_idx) {
if (lPack->fromPV(puVtx_idx) >= 2) {
pReco.id = 1;
break;
}
}
}
} else if (lPack->fromPV() == (pat::PackedCandidate::PVUsedInFit)) {
pReco.id = 1;
} else if (lPack->fromPV() == (pat::PackedCandidate::PVTight) ||
lPack->fromPV() == (pat::PackedCandidate::PVLoose)) {
Expand Down Expand Up @@ -372,6 +384,8 @@ void PuppiProducer::fillDescriptions(edm::ConfigurationDescriptions& description
desc.add<double>("EtaMaxPhotons", 2.5);
desc.add<double>("PtMaxNeutrals", 200.);
desc.add<double>("PtMaxNeutralsStartSlope", 0.);
desc.add<uint>("NumOfPUVtxsForCharged", 0);
desc.add<double>("DeltaZCutForChargedFromPUVtxs", 0.2);
desc.add<bool>("useExistingWeights", false);
desc.add<bool>("clonePackedCands", false);
desc.add<int>("vtxNdofCut", 4);
Expand Down
2 changes: 2 additions & 0 deletions CommonTools/PileupAlgos/plugins/PuppiProducer.h
Expand Up @@ -68,6 +68,8 @@ class PuppiProducer : public edm::stream::EDProducer<> {
double fEtaMaxCharged;
double fPtMaxPhotons;
double fEtaMaxPhotons;
uint fNumOfPUVtxsForCharged;
double fDZCutForChargedFromPUVtxs;
bool fUseExistingWeights;
bool fClonePackedCands;
int fVtxNdofCut;
Expand Down
2 changes: 2 additions & 0 deletions CommonTools/PileupAlgos/python/Puppi_cff.py
Expand Up @@ -31,6 +31,8 @@
UseDeltaZCut = cms.bool(True),
EtaMinUseDeltaZ = cms.double(2.4),
DeltaZCut = cms.double(0.3),
NumOfPUVtxsForCharged = cms.uint32(0),
DeltaZCutForChargedFromPUVtxs = cms.double(0.2),
PtMaxCharged = cms.double(20.),
EtaMaxCharged = cms.double(99999.),
PtMaxPhotons = cms.double(-1.),
Expand Down
20 changes: 17 additions & 3 deletions CommonTools/PileupAlgos/python/customizePuppiTune_cff.py
@@ -1,10 +1,10 @@
import FWCore.ParameterSet.Config as cms

def UpdatePuppiTuneV14(process):
def UpdatePuppiTuneV15(process, runOnMC=True):
#
# Adapt for re-running PUPPI
#
print("customizePuppiTune_cff::UpdatePuppiTuneV14: Recomputing PUPPI with Tune v14, slimmedJetsPuppi and slimmedMETsPuppi")
print("customizePuppiTune_cff::UpdatePuppiTuneV15: Recomputing PUPPI with Tune v15, slimmedJetsPuppi and slimmedMETsPuppi")
from PhysicsTools.PatAlgos.tools.helpers import getPatAlgosToolsTask, addToProcessAndTask
task = getPatAlgosToolsTask(process)
from PhysicsTools.PatAlgos.slimming.puppiForMET_cff import makePuppiesFromMiniAOD
Expand All @@ -26,11 +26,25 @@ def UpdatePuppiTuneV14(process):
del process.updatedPatJetsPuppiJetSpecific
process.puppiSequence = cms.Sequence(process.puppiMETSequence+process.fullPatMetSequencePuppi+process.patPuppiJetSpecificProducer+process.slimmedJetsPuppi)
#
# Adapt for PUPPI tune V14
# Adapt for PUPPI tune V15
#
process.puppi.PtMaxCharged = 20.
process.puppi.EtaMinUseDeltaZ = 2.4
process.puppi.PtMaxNeutralsStartSlope = 20.
process.puppi.NumOfPUVtxsForCharged = 2
process.puppi.algos[0].etaMin[0] = -0.01
process.puppiNoLep.PtMaxCharged = 20.
process.puppiNoLep.EtaMinUseDeltaZ = 2.4
process.puppiNoLep.PtMaxNeutralsStartSlope = 20.
process.puppiNoLep.NumOfPUVtxsForCharged = 2
process.puppiNoLep.algos[0].etaMin[0] = -0.01

from Configuration.Eras.Modifier_phase2_common_cff import phase2_common
phase2_common.toModify( process.puppi, EtaMinUseDeltaZ = 4.0)
phase2_common.toModify( process.puppiNoLep, EtaMinUseDeltaZ = 4.0)

def UpdatePuppiTuneV15_MC(process):
UpdatePuppiTuneV15(process,runOnMC=True)

def UpdatePuppiTuneV15_Data(process):
UpdatePuppiTuneV15(process,runOnMC=False)

0 comments on commit f58146d

Please sign in to comment.