Skip to content

Commit

Permalink
comments from Andrea
Browse files Browse the repository at this point in the history
  • Loading branch information
ahinzmann committed Aug 31, 2021
1 parent 3936143 commit 556d75d
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 228 deletions.
88 changes: 76 additions & 12 deletions CommonTools/ParticleFlow/plugins/PFPileUp.cc
Original file line number Diff line number Diff line change
@@ -1,19 +1,86 @@
#include "CommonTools/ParticleFlow/plugins/PFPileUp.h"
#ifndef PhysicsTools_PFCandProducer_PFPileUp_
#define PhysicsTools_PFCandProducer_PFPileUp_

// system include files
#include <memory>
#include <string>

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"

#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
#include "DataFormats/VertexReco/interface/VertexFwd.h"
#include "DataFormats/Common/interface/Association.h"

#include "CommonTools/ParticleFlow/interface/PFPileUpAlgo.h"

#include "DataFormats/ParticleFlowCandidate/interface/PileUpPFCandidate.h"
#include "DataFormats/ParticleFlowCandidate/interface/PileUpPFCandidateFwd.h"
#include "DataFormats/VertexReco/interface/Vertex.h"

#include "FWCore/Framework/interface/ESHandle.h"

// #include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/Framework/interface/EventSetup.h"

using namespace std;
using namespace edm;
using namespace reco;

/**\class PFPileUp
\brief Identifies pile-up candidates from a collection of PFCandidates, and
produces the corresponding collection of PileUpCandidates.
\author Colin Bernet
\date february 2008
\updated Florian Beaudette 30/03/2012
*/

class PFPileUp : public edm::stream::EDProducer<> {
public:
typedef std::vector<edm::FwdPtr<reco::PFCandidate>> PFCollection;
typedef edm::View<reco::PFCandidate> PFView;
typedef std::vector<reco::PFCandidate> PFCollectionByValue;
typedef edm::Association<reco::VertexCollection> CandToVertex;

explicit PFPileUp(const edm::ParameterSet&);

~PFPileUp() override;

void produce(edm::Event&, const edm::EventSetup&) override;

private:
PFPileUpAlgo pileUpAlgo_;

/// PFCandidates to be analyzed
edm::EDGetTokenT<PFCollection> tokenPFCandidates_;
/// fall-back token
edm::EDGetTokenT<PFView> tokenPFCandidatesView_;

/// vertices
edm::EDGetTokenT<reco::VertexCollection> tokenVertices_;

/// enable PFPileUp selection
bool enable_;

/// verbose ?
bool verbose_;

/// use the closest z vertex if a track is not in a vertex
bool checkClosestZVertex_;

edm::EDGetTokenT<CandToVertex> tokenVertexAssociation_;
edm::EDGetTokenT<edm::ValueMap<int>> tokenVertexAssociationQuality_;
bool fUseVertexAssociation;
int vertexAssociationQuality_;
};

PFPileUp::PFPileUp(const edm::ParameterSet& iConfig) {
tokenPFCandidates_ = consumes<PFCollection>(iConfig.getParameter<InputTag>("PFCandidates"));
tokenPFCandidatesView_ = mayConsume<PFView>(iConfig.getParameter<InputTag>("PFCandidates"));
Expand Down Expand Up @@ -102,18 +169,14 @@ void PFPileUp::produce(Event& iEvent, const EventSetup& iSetup) {
}

if (fUseVertexAssociation) {
edm::Handle<edm::Association<reco::VertexCollection>> assoHandle;
iEvent.getByToken(tokenVertexAssociation_, assoHandle);
const edm::Association<reco::VertexCollection>* associatedPV = assoHandle.product();
edm::Handle<edm::ValueMap<int>> assoQualityHandle;
iEvent.getByToken(tokenVertexAssociationQuality_, assoQualityHandle);
const edm::ValueMap<int>* associationQuality = assoQualityHandle.product();
const edm::Association<reco::VertexCollection> associatedPV = iEvent.get(tokenVertexAssociation_);
const edm::ValueMap<int> associationQuality = iEvent.get(tokenVertexAssociationQuality_);
PFCollection pfCandidatesFromPU;
for (unsigned i = 0; i < (*pfCandidatesRef).size(); i++) {
const reco::VertexRef& PVOrig = (*associatedPV)[(*pfCandidatesRef)[i]];
int quality = (*associationQuality)[(*pfCandidatesRef)[i]];
for (auto& p : (*pfCandidatesRef)) {
const reco::VertexRef& PVOrig = associatedPV[p];
int quality = associationQuality[p];
if (PVOrig.isNonnull() && (PVOrig.key() > 0) && (quality >= vertexAssociationQuality_))
pfCandidatesFromPU.push_back((*pfCandidatesRef)[i]);
pfCandidatesFromPU.push_back(p);
}
pOutput->insert(pOutput->end(), pfCandidatesFromPU.begin(), pfCandidatesFromPU.end());
} else {
Expand All @@ -132,3 +195,4 @@ void PFPileUp::produce(Event& iEvent, const EventSetup& iSetup) {
iEvent.put(std::move(pOutput));
// iEvent.put(std::move(pOutputByValue));
}
#endif
71 changes: 0 additions & 71 deletions CommonTools/ParticleFlow/plugins/PFPileUp.h

This file was deleted.

45 changes: 0 additions & 45 deletions CommonTools/ParticleFlow/plugins/PFnoPileUp.cc

This file was deleted.

48 changes: 0 additions & 48 deletions CommonTools/ParticleFlow/plugins/PFnoPileUp.h

This file was deleted.

2 changes: 1 addition & 1 deletion CommonTools/ParticleFlow/python/pfCHS_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
)
adapt(packedPrimaryVertexAssociationJME)

pfCHS = cms.EDProducer("PFnoPileUp",
pfCHS = cms.EDProducer("PFnoPileUpPacked",
candidates = cms.InputTag("packedPFCandidates"),
vertexAssociationQuality = pfPileUpJME.vertexAssociationQuality,
vertexAssociation = cms.InputTag("packedPrimaryVertexAssociationJME","original")
Expand Down
2 changes: 1 addition & 1 deletion CommonTools/ParticleFlow/python/pfNoPileUpJME_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def adapt(primaryVertexAssociationJME):
pfPileUpJME = _pfPileUp.clone(PFCandidates='particleFlowPtrs',
useVertexAssociation = True,
vertexAssociationQuality = 7,
vertexAssociation = cms.InputTag('primaryVertexAssociationJME','original'),
vertexAssociation = ('primaryVertexAssociationJME','original'),
)
pfNoPileUpJME = _pfNoPileUp.clone(topCollection = 'pfPileUpJME',
bottomCollection = 'particleFlowPtrs' )
Expand Down
18 changes: 7 additions & 11 deletions CommonTools/PileupAlgos/plugins/PuppiProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,11 @@ void PuppiProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
iEvent.getByToken(tokenVertices_, hVertexProduct);
const reco::VertexCollection* pvCol = hVertexProduct.product();

edm::Handle<edm::Association<reco::VertexCollection>> assoHandle;
const edm::Association<reco::VertexCollection>* associatedPV = nullptr;
edm::Handle<edm::ValueMap<int>> assoQualityHandle;
const edm::ValueMap<int>* associationQuality = nullptr;
edm::Association<reco::VertexCollection> associatedPV;
edm::ValueMap<int> associationQuality;
if ((fUseVertexAssociation) && (!fUseExistingWeights)) {
iEvent.getByToken(tokenVertexAssociation_, assoHandle);
associatedPV = assoHandle.product();
iEvent.getByToken(tokenVertexAssociationQuality_, assoQualityHandle);
associationQuality = assoQualityHandle.product();
associatedPV = iEvent.get(tokenVertexAssociation_);
associationQuality = iEvent.get(tokenVertexAssociationQuality_);
}

double puProxyValue = 0.;
Expand All @@ -113,7 +109,7 @@ void PuppiProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
//Fill the reco objects
fRecoObjCollection.clear();
fRecoObjCollection.reserve(pfCol->size());
size_t ic = 0;
int ic = 0;
for (auto const& aPF : *pfCol) {
RecoObj pReco;
pReco.pt = aPF.pt();
Expand All @@ -131,8 +127,8 @@ void PuppiProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
const pat::PackedCandidate* lPack = dynamic_cast<const pat::PackedCandidate*>(&aPF);

if (fUseVertexAssociation) {
const reco::VertexRef& PVOrig = (*associatedPV)[reco::CandidatePtr(hPFProduct, ic)];
int quality = (*associationQuality)[reco::CandidatePtr(hPFProduct, ic)];
const reco::VertexRef& PVOrig = associatedPV[reco::CandidatePtr(hPFProduct, ic)];
int quality = associationQuality[reco::CandidatePtr(hPFProduct, ic)];
if (PVOrig.isNonnull() && (quality >= vertexAssociationQuality_)) {
closestVtx = PVOrig.get();
pVtxId = PVOrig.key();
Expand Down
10 changes: 5 additions & 5 deletions CommonTools/PileupAlgos/python/Puppi_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
PtMaxCharged = 20.,
PtMaxNeutralsStartSlope = 20.,
useVertexAssociation = True,
vertexAssociationQuality = cms.int32(6),
vertexAssociation = cms.InputTag('primaryVertexAssociationJME','original'),
#candName = cms.string('packedPFCandidates'),
#vertexName = cms.string('offlineSlimmedPrimaryVertices'),
vertexAssociationQuality = 6,
vertexAssociation = ('primaryVertexAssociationJME','original'),
#candName = 'packedPFCandidates',
#vertexName = 'offlineSlimmedPrimaryVertices',
clonePackedCands = False, # should only be set to True for MiniAOD
algos = {
0: dict(
Expand Down Expand Up @@ -102,7 +102,7 @@
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 cleandParticleFlow
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: 3 additions & 1 deletion CommonTools/RecoAlgos/interface/PrimaryVertexAssignment.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ class PrimaryVertexAssignment {
else
return chargedHadronVertex(
vertices,
(useVertexFit_ && (pfcand.pvAssociationQuality() >= pat::PackedCandidate::UsedInFitLoose)) ? pfcand.vertexRef().key() : -1,
(useVertexFit_ && (pfcand.pvAssociationQuality() >= pat::PackedCandidate::UsedInFitLoose))
? pfcand.vertexRef().key()
: -1,
&pfcand.pseudoTrack(),
time,
timeResolution,
Expand Down
Loading

0 comments on commit 556d75d

Please sign in to comment.