Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHS and PUPPI track-vertex-association for Run3 #36639

Merged
merged 7 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CommonTools/ParticleFlow/interface/PFPileUpAlgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class PFPileUpAlgo {
inline void setVerbose(bool verbose) { verbose_ = verbose; }

inline void setCheckClosestZVertex(bool val) { checkClosestZVertex_ = val; }
inline void setNumOfPUVtxsForCharged(unsigned int val) { fNumOfPUVtxsForCharged_ = val; }
inline void setDzCutForChargedFromPUVtxs(double val) { fDzCutForChargedFromPUVtxs_ = val; }

const PFCollection& getPFCandidatesFromPU() const { return pfCandidatesFromPU_; }

Expand All @@ -38,6 +40,8 @@ class PFPileUpAlgo {
private:
/// use the closest z vertex if a track is not in a vertex
bool checkClosestZVertex_;
unsigned int fNumOfPUVtxsForCharged_;
double fDzCutForChargedFromPUVtxs_;

/// verbose ?
bool verbose_;
Expand Down
91 changes: 0 additions & 91 deletions CommonTools/ParticleFlow/plugins/PFNoPileUpPacked.cc

This file was deleted.

6 changes: 6 additions & 0 deletions CommonTools/ParticleFlow/plugins/PFPileUp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class PFPileUp : public edm::stream::EDProducer<> {
edm::EDGetTokenT<edm::ValueMap<int>> tokenVertexAssociationQuality_;
bool fUseVertexAssociation;
int vertexAssociationQuality_;
unsigned int fNumOfPUVtxsForCharged_;
double fDzCutForChargedFromPUVtxs_;
};

PFPileUp::PFPileUp(const edm::ParameterSet& iConfig) {
Expand All @@ -91,6 +93,8 @@ PFPileUp::PFPileUp(const edm::ParameterSet& iConfig) {
tokenVertexAssociationQuality_ =
consumes<edm::ValueMap<int>>(iConfig.getParameter<edm::InputTag>("vertexAssociation"));
}
fNumOfPUVtxsForCharged_ = iConfig.getParameter<unsigned int>("NumOfPUVtxsForCharged");
fDzCutForChargedFromPUVtxs_ = iConfig.getParameter<double>("DzCutForChargedFromPUVtxs");

enable_ = iConfig.getParameter<bool>("Enable");

Expand All @@ -105,6 +109,8 @@ PFPileUp::PFPileUp(const edm::ParameterSet& iConfig) {
// Configure the algo
pileUpAlgo_.setVerbose(verbose_);
pileUpAlgo_.setCheckClosestZVertex(checkClosestZVertex_);
pileUpAlgo_.setNumOfPUVtxsForCharged(fNumOfPUVtxsForCharged_);
pileUpAlgo_.setDzCutForChargedFromPUVtxs(fDzCutForChargedFromPUVtxs_);

//produces<reco::PFCandidateCollection>();
produces<PFCollection>();
Expand Down
19 changes: 7 additions & 12 deletions CommonTools/ParticleFlow/python/pfCHS_cff.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import FWCore.ParameterSet.Config as cms
from CommonTools.ParticleFlow.pfNoPileUpJME_cff import adapt, pfPileUpJME
from CommonTools.RecoAlgos.sortedPackedPrimaryVertices_cfi import sortedPackedPrimaryVertices
from CommonTools.ParticleFlow.pfNoPileUpJME_cff import primaryVertexAssociationJME

packedPrimaryVertexAssociationJME = sortedPackedPrimaryVertices.clone(
produceSortedVertices = False,
producePileUpCollection = False,
produceNoPileUpCollection = False
)
adapt(packedPrimaryVertexAssociationJME)

from CommonTools.ParticleFlow.pfNoPileUpPacked_cfi import pfNoPileUpPacked as _pfNoPileUpPacked
pfCHS = _pfNoPileUpPacked.clone(
vertexAssociationQuality=pfPileUpJME.vertexAssociationQuality
pfCHS = cms.EDFilter("CandPtrSelector",
src = cms.InputTag("packedPFCandidates"),
cut = cms.string("fromPV(0)>0"+\
" || (vertexRef().key<="+str(primaryVertexAssociationJME.assignment.NumOfPUVtxsForCharged.value())+" && "+\
"abs(dz(0))<"+str(primaryVertexAssociationJME.assignment.DzCutForChargedFromPUVtxs.value())+")"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a format string can be considered:

Suggested change
cut = cms.string("fromPV(0)>0"+\
" || (vertexRef().key<="+str(primaryVertexAssociationJME.assignment.NumOfPUVtxsForCharged.value())+" && "+\
"abs(dz(0))<"+str(primaryVertexAssociationJME.assignment.DzCutForChargedFromPUVtxs.value())+")"
cut = cms.string("fromPV(0)>0 || (vertexRef().key<={} && abs(dz(0))<{})".format(
primaryVertexAssociationJME.assignment.NumOfPUVtxsForCharged.value(),
primaryVertexAssociationJME.assignment.DzCutForChargedFromPUVtxs.value())

)
)
41 changes: 21 additions & 20 deletions CommonTools/ParticleFlow/python/pfNoPileUpJME_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,36 @@
from CommonTools.ParticleFlow.goodOfflinePrimaryVertices_cfi import goodOfflinePrimaryVertices
from CommonTools.RecoAlgos.primaryVertexAssociation_cfi import primaryVertexAssociation

def adapt(primaryVertexAssociationJME):
# options for quality PrimaryDz = 6 (used in PUPPI)
primaryVertexAssociationJME.assignment.maxDzSigForPrimaryAssignment = 1e10
primaryVertexAssociationJME.assignment.maxDzForPrimaryAssignment = 0.3
primaryVertexAssociationJME.assignment.maxDzErrorForPrimaryAssignment = 1e10
primaryVertexAssociationJME.assignment.NumOfPUVtxsForCharged = 2
primaryVertexAssociationJME.assignment.PtMaxCharged = 20.
primaryVertexAssociationJME.assignment.EtaMinUseDz = 2.4
primaryVertexAssociationJME.assignment.OnlyUseFirstDz = True
from Configuration.Eras.Modifier_phase2_common_cff import phase2_common
phase2_common.toModify(
primaryVertexAssociationJME.assignment,
maxDzForPrimaryAssignment=0.1,
EtaMinUseDz = 4.0
)
# The following module implements vertex association for JME.
# It is not run by default to save computing time (but can be run to investigate alternative vertex identification criteria).
# Instead its parameters are used as input to faster implementations in pfPileUpJME and pfCHS and puppi.
primaryVertexAssociationJME = primaryVertexAssociation.clone(vertices = 'goodOfflinePrimaryVertices')
adapt(primaryVertexAssociationJME)
primaryVertexAssociationJME.assignment.maxDzSigForPrimaryAssignment = 1e10
primaryVertexAssociationJME.assignment.maxDzForPrimaryAssignment = 0.3
primaryVertexAssociationJME.assignment.maxDzErrorForPrimaryAssignment = 1e10
primaryVertexAssociationJME.assignment.NumOfPUVtxsForCharged = 2
primaryVertexAssociationJME.assignment.DzCutForChargedFromPUVtxs = 0.2
primaryVertexAssociationJME.assignment.PtMaxCharged = 20.
primaryVertexAssociationJME.assignment.EtaMinUseDz = 2.4
primaryVertexAssociationJME.assignment.OnlyUseFirstDz = True
from Configuration.Eras.Modifier_phase2_common_cff import phase2_common
phase2_common.toModify(
primaryVertexAssociationJME.assignment,
maxDzForPrimaryAssignment=0.1,
EtaMinUseDz = 4.0
)

pfPileUpJME = _pfPileUp.clone(PFCandidates='particleFlowPtrs',
useVertexAssociation = True,
vertexAssociationQuality = 7,
vertexAssociation = ('primaryVertexAssociationJME','original'),
Vertices = 'goodOfflinePrimaryVertices',
checkClosestZVertex = False,
NumOfPUVtxsForCharged = primaryVertexAssociationJME.assignment.NumOfPUVtxsForCharged,
DzCutForChargedFromPUVtxs = primaryVertexAssociationJME.assignment.DzCutForChargedFromPUVtxs,
)
pfNoPileUpJME = _pfNoPileUp.clone(topCollection = 'pfPileUpJME',
bottomCollection = 'particleFlowPtrs' )

pfNoPileUpJMETask = cms.Task(
goodOfflinePrimaryVertices,
primaryVertexAssociationJME,
pfPileUpJME,
pfNoPileUpJME
)
Expand Down
2 changes: 2 additions & 0 deletions CommonTools/ParticleFlow/python/pfPileUp_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
useVertexAssociation = cms.bool(False),
vertexAssociationQuality = cms.int32(0),
vertexAssociation = cms.InputTag(''),
NumOfPUVtxsForCharged = cms.uint32(0),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PFPileup could be a good candidate to add fillDescriptions, what do you think?

DzCutForChargedFromPUVtxs = cms.double(0.2),
)
4 changes: 3 additions & 1 deletion CommonTools/ParticleFlow/src/PFPileUpAlgo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ void PFPileUpAlgo::process(const PFCollection& pfCandidates, const reco::VertexC

// no associated vertex, or primary vertex
// not pile-up
if (ivertex == -1 || ivertex == 0) {
if ((ivertex == -1 || ivertex == 0 ||
(fNumOfPUVtxsForCharged_ > 0 && !vertices.empty() && ivertex <= int(fNumOfPUVtxsForCharged_) &&
std::abs(cand.vertex().z() - vertices.at(0).z()) < fDzCutForChargedFromPUVtxs_))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically for performance reasons the non-throwing vertices[0] would be preferred. It looks like it's guaranteed by !vertices.empty() that there is at least one vertex.

if (verbose_)
std::cout << "VTX " << i << " " << *(pfCandidates[i]) << std::endl;
pfCandidatesFromVtx_.push_back(pfCandidates[i]);
Expand Down
15 changes: 11 additions & 4 deletions CommonTools/PileupAlgos/plugins/PuppiProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class PuppiProducer : public edm::stream::EDProducer<> {
bool fPuppiNoLep;
bool fUseFromPVLooseTight;
bool fUseDZ;
bool fUseDZforPileup;
double fDZCut;
double fEtaMinUseDZ;
double fPtMaxCharged;
Expand All @@ -95,6 +96,7 @@ PuppiProducer::PuppiProducer(const edm::ParameterSet& iConfig) {
fPuppiNoLep = iConfig.getParameter<bool>("puppiNoLep");
fUseFromPVLooseTight = iConfig.getParameter<bool>("UseFromPVLooseTight");
fUseDZ = iConfig.getParameter<bool>("UseDeltaZCut");
fUseDZforPileup = iConfig.getParameter<bool>("UseDeltaZCutForPileup");
fDZCut = iConfig.getParameter<double>("DeltaZCut");
fEtaMinUseDZ = iConfig.getParameter<double>("EtaMinUseDeltaZ");
fPtMaxCharged = iConfig.getParameter<double>("PtMaxCharged");
Expand Down Expand Up @@ -281,8 +283,10 @@ void PuppiProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
pReco.id = 1;
else if (std::abs(pReco.eta) > fEtaMaxCharged)
pReco.id = 1;
else if ((fUseDZ) && (std::abs(pReco.eta) >= fEtaMinUseDZ))
pReco.id = (std::abs(pDZ) < fDZCut) ? 1 : 2;
else if ((fUseDZ) && (std::abs(pReco.eta) >= fEtaMinUseDZ) && (std::abs(pDZ) < fDZCut))
pReco.id = 1;
else if ((fUseDZforPileup) && (std::abs(pReco.eta) >= fEtaMinUseDZ) && (std::abs(pDZ) >= fDZCut))
pReco.id = 2;
else if (fUseFromPVLooseTight && tmpFromPV == 1)
pReco.id = 2;
else if (fUseFromPVLooseTight && tmpFromPV == 2)
Expand Down Expand Up @@ -322,8 +326,10 @@ void PuppiProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
pReco.id = 1;
else if (std::abs(pReco.eta) > fEtaMaxCharged)
pReco.id = 1;
else if ((fUseDZ) && (std::abs(pReco.eta) >= fEtaMinUseDZ))
pReco.id = (std::abs(pDZ) < fDZCut) ? 1 : 2;
else if ((fUseDZ) && (std::abs(pReco.eta) >= fEtaMinUseDZ) && (std::abs(pDZ) < fDZCut))
pReco.id = 1;
else if ((fUseDZforPileup) && (std::abs(pReco.eta) >= fEtaMinUseDZ) && (std::abs(pDZ) >= fDZCut))
pReco.id = 2;
else if (fUseFromPVLooseTight && lPack->fromPV() == (pat::PackedCandidate::PVLoose))
pReco.id = 2;
else if (fUseFromPVLooseTight && lPack->fromPV() == (pat::PackedCandidate::PVTight))
Expand Down Expand Up @@ -489,6 +495,7 @@ void PuppiProducer::fillDescriptions(edm::ConfigurationDescriptions& description
desc.add<bool>("puppiNoLep", false);
desc.add<bool>("UseFromPVLooseTight", false);
desc.add<bool>("UseDeltaZCut", true);
desc.add<bool>("UseDeltaZCutForPileup", true);
desc.add<double>("DeltaZCut", 0.3);
desc.add<double>("EtaMinUseDeltaZ", 0.);
desc.add<double>("PtMaxCharged", -1.);
Expand Down
15 changes: 7 additions & 8 deletions CommonTools/PileupAlgos/python/Puppi_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@
)

# from cfipython/, generated by PuppiProducer::fillDescriptions
from CommonTools.ParticleFlow.pfNoPileUpJME_cff import primaryVertexAssociationJME
import CommonTools.PileupAlgos.PuppiProducer_cfi as _mod
puppi = _mod.PuppiProducer.clone(
EtaMinUseDeltaZ = 2.4,
NumOfPUVtxsForCharged = 2,
PtMaxCharged = 20.,
UseDeltaZCutForPileup = False,
DeltaZCut = primaryVertexAssociationJME.assignment.maxDzForPrimaryAssignment,
EtaMinUseDeltaZ = primaryVertexAssociationJME.assignment.EtaMinUseDz,
PtMaxCharged = primaryVertexAssociationJME.assignment.PtMaxCharged,
NumOfPUVtxsForCharged = primaryVertexAssociationJME.assignment.NumOfPUVtxsForCharged,
DeltaZCutForChargedFromPUVtxs = primaryVertexAssociationJME.assignment.DzCutForChargedFromPUVtxs,
PtMaxNeutralsStartSlope = 20.,
useVertexAssociation = True,
vertexAssociationQuality = 6,
vertexAssociation = ('primaryVertexAssociationJME','original'),
clonePackedCands = False, # should only be set to True for MiniAOD
algos = {
0: dict(
Expand Down Expand Up @@ -99,8 +100,6 @@

from Configuration.ProcessModifiers.pp_on_AA_cff import pp_on_AA
pp_on_AA.toModify(puppi, algos = [])
from Configuration.ProcessModifiers.run2_miniAOD_pp_on_AA_103X_cff import run2_miniAOD_pp_on_AA_103X
run2_miniAOD_pp_on_AA_103X.toModify(puppi,useVertexAssociation = False) # because the association is only run on cleanedParticleFlow

puppiNoLep = puppi.clone(
puppiNoLep = True,
Expand Down
4 changes: 2 additions & 2 deletions CommonTools/RecoAlgos/interface/PrimaryVertexAssignment.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class PrimaryVertexAssignment {
useTiming_(iConfig.getParameter<bool>("useTiming")),
useVertexFit_(iConfig.getParameter<bool>("useVertexFit")),
preferHighRanked_(iConfig.getParameter<bool>("preferHighRanked")),
fNumOfPUVtxsForCharged_(iConfig.getParameter<int>("NumOfPUVtxsForCharged")),
fNumOfPUVtxsForCharged_(iConfig.getParameter<unsigned int>("NumOfPUVtxsForCharged")),
fDzCutForChargedFromPUVtxs_(iConfig.getParameter<double>("DzCutForChargedFromPUVtxs")),
fPtMaxCharged_(iConfig.getParameter<double>("PtMaxCharged")),
fEtaMinUseDz_(iConfig.getParameter<double>("EtaMinUseDz")),
Expand Down Expand Up @@ -154,7 +154,7 @@ class PrimaryVertexAssignment {
bool useTiming_;
bool useVertexFit_;
bool preferHighRanked_;
int fNumOfPUVtxsForCharged_;
unsigned int fNumOfPUVtxsForCharged_;
double fDzCutForChargedFromPUVtxs_;
double fPtMaxCharged_;
double fEtaMinUseDz_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
preferHighRanked = cms.bool(False),

#options used in PUPPI
NumOfPUVtxsForCharged = cms.int32(-1),
NumOfPUVtxsForCharged = cms.uint32(0),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch on the incorrect parameter type... it looks like PFCandidatePrimaryVertexSorter could also benefit from a fillDescriptions implementation?

DzCutForChargedFromPUVtxs = cms.double(0.2),
PtMaxCharged = cms.double(-1),
EtaMinUseDz = cms.double(-1),
Expand Down
2 changes: 1 addition & 1 deletion CommonTools/RecoAlgos/python/sortedPrimaryVertices_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
preferHighRanked = cms.bool(False),

#options used in PUPPI
NumOfPUVtxsForCharged = cms.int32(-1),
NumOfPUVtxsForCharged = cms.uint32(0),
DzCutForChargedFromPUVtxs = cms.double(0.2),
PtMaxCharged = cms.double(-1),
EtaMinUseDz = cms.double(-1),
Expand Down
16 changes: 7 additions & 9 deletions CommonTools/RecoAlgos/src/PrimaryVertexAssignment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ std::pair<int, PrimaryVertexAssignment::Quality> PrimaryVertexAssignment::charge
if (!vertices.empty())
firstVertexDz = std::abs(track->dz(vertices.at(0).position()));
// recover cases where the primary vertex is split
if (useVertexFit_ && (iVertex > 0) && (iVertex <= fNumOfPUVtxsForCharged_) &&
if (useVertexFit_ && (iVertex > 0) && (iVertex <= int(fNumOfPUVtxsForCharged_)) &&
firstVertexDz < fDzCutForChargedFromPUVtxs_)
return {0, PrimaryVertexAssignment::PrimaryDz};

Expand Down Expand Up @@ -121,14 +121,12 @@ std::pair<int, PrimaryVertexAssignment::Quality> PrimaryVertexAssignment::charge
(!useTime or dtmin / timeReso < maxDtSigForPrimaryAssignment_))
iVertex = vtxIdMinSignif;
} else {
// consider only distances to first vertex for association of pileup vertices (originally used in PUPPI)
if ((vtxIdMinSignif >= 0) && (std::abs(track->eta()) > fEtaMinUseDz_))
iVertex =
((firstVertexDz < maxDzForPrimaryAssignment_ and firstVertexDz / dzE < maxDzSigForPrimaryAssignment_ and
track->dzError() < maxDzErrorForPrimaryAssignment_) and
(!useTime or std::abs(time - vertices.at(0).t()) / timeReso < maxDtSigForPrimaryAssignment_))
? 0
: vtxIdMinSignif;
// consider only distances to first vertex for association (originally used in PUPPI)
if ((vtxIdMinSignif >= 0) && (std::abs(track->eta()) > fEtaMinUseDz_) and
((firstVertexDz < maxDzForPrimaryAssignment_ and firstVertexDz / dzE < maxDzSigForPrimaryAssignment_ and
track->dzError() < maxDzErrorForPrimaryAssignment_) and
(!useTime or std::abs(time - vertices.at(0).t()) / timeReso < maxDtSigForPrimaryAssignment_)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment here about vertices.at(0) vs. vertices[0].
Also, it seems that boolean operators && and and are mixed here, might be cleaner to just use one or the other.

iVertex = 0;
}
}

Expand Down
1 change: 0 additions & 1 deletion PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ def _add_slimmedMETsNoHF(process):

# ================== CHSMET
process.load("CommonTools.ParticleFlow.pfCHS_cff")
task.add(process.packedPrimaryVertexAssociationJME)
task.add(process.pfCHS)

from RecoMET.METProducers.pfMet_cfi import pfMet
Expand Down
Loading