Skip to content

Commit 918a7fc

Browse files
authored
Merge pull request cms-sw#40762 from jshin96/from1300pre4_pujetid_fix
[PileupJetId, Puppi] Pileup ID input variable fix, puppi weight ValueMap access, optional photon protection for existing puppi weights
2 parents 57ed23b + 283d569 commit 918a7fc

File tree

7 files changed

+165
-89
lines changed

7 files changed

+165
-89
lines changed

CommonTools/PileupAlgos/plugins/PuppiProducer.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class PuppiProducer : public edm::stream::EDProducer<> {
8080
uint fNumOfPUVtxsForCharged;
8181
double fDZCutForChargedFromPUVtxs;
8282
bool fUseExistingWeights;
83+
bool fApplyPhotonProtectionForExistingWeights;
8384
bool fClonePackedCands;
8485
int fVtxNdofCut;
8586
double fVtxZCut;
@@ -104,6 +105,7 @@ PuppiProducer::PuppiProducer(const edm::ParameterSet& iConfig) {
104105
fNumOfPUVtxsForCharged = iConfig.getParameter<uint>("NumOfPUVtxsForCharged");
105106
fDZCutForChargedFromPUVtxs = iConfig.getParameter<double>("DeltaZCutForChargedFromPUVtxs");
106107
fUseExistingWeights = iConfig.getParameter<bool>("useExistingWeights");
108+
fApplyPhotonProtectionForExistingWeights = iConfig.getParameter<bool>("applyPhotonProtectionForExistingWeights");
107109
fClonePackedCands = iConfig.getParameter<bool>("clonePackedCands");
108110
fVtxNdofCut = iConfig.getParameter<int>("vtxNdofCut");
109111
fVtxZCut = iConfig.getParameter<double>("vtxZCut");
@@ -363,9 +365,9 @@ void PuppiProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
363365
curpupweight = lPack->puppiWeight();
364366
}
365367
}
366-
// Protect high pT photons (important for gamma to hadronic recoil balance)
367-
if ((fPtMaxPhotons > 0) && (lPack->pdgId() == 22) && (std::abs(lPack->eta()) < fEtaMaxPhotons) &&
368-
(lPack->pt() > fPtMaxPhotons))
368+
// Optional: Protect high pT photons (important for gamma to hadronic recoil balance) for existing weights.
369+
if (fApplyPhotonProtectionForExistingWeights && (fPtMaxPhotons > 0) && (lPack->pdgId() == 22) &&
370+
(std::abs(lPack->eta()) < fEtaMaxPhotons) && (lPack->pt() > fPtMaxPhotons))
369371
curpupweight = 1;
370372
lWeights.push_back(curpupweight);
371373
lPackCtr++;
@@ -511,6 +513,7 @@ void PuppiProducer::fillDescriptions(edm::ConfigurationDescriptions& description
511513
desc.add<uint>("NumOfPUVtxsForCharged", 0);
512514
desc.add<double>("DeltaZCutForChargedFromPUVtxs", 0.2);
513515
desc.add<bool>("useExistingWeights", false);
516+
desc.add<bool>("applyPhotonProtectionForExistingWeights", false);
514517
desc.add<bool>("clonePackedCands", false);
515518
desc.add<int>("vtxNdofCut", 4);
516519
desc.add<double>("vtxZCut", 24);

PhysicsTools/NanoAOD/python/custom_jme_cff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def AddPileUpJetIDVars(proc, jetName="", jetSrc="", jetTableName="", jetTaskName
274274
vertexes = "offlineSlimmedPrimaryVertices",
275275
inputIsCorrected = True,
276276
applyJec = False,
277-
usePuppi = True if "PUPPI" in jetName.upper() else False
277+
srcConstituentWeights = "packedPFCandidatespuppi" if "PUPPI" in jetName.upper() else ""
278278
)
279279
)
280280
getattr(proc,jetTaskName).add(getattr(proc, puJetIdVarsCalculator))

RecoJets/JetProducers/interface/PileupJetIdAlgo.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@ class PileupJetIdAlgo {
2828
PileupJetIdAlgo(AlgoGBRForestsAndConstants const* cache);
2929
~PileupJetIdAlgo();
3030

31-
PileupJetIdentifier computeIdVariables(
32-
const reco::Jet* jet, float jec, const reco::Vertex*, const reco::VertexCollection&, double rho, bool usePuppi);
31+
PileupJetIdentifier computeIdVariables(const reco::Jet* jet,
32+
float jec,
33+
const reco::Vertex*,
34+
const reco::VertexCollection&,
35+
double rho,
36+
edm::ValueMap<float>& constituentWeights,
37+
bool applyConstituentWeight);
3338

3439
void set(const PileupJetIdentifier&);
3540
float getMVAval(const std::vector<std::string>&, const std::unique_ptr<const GBRForest>&);

RecoJets/JetProducers/plugins/PileupJetIdProducer.cc

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ GBRForestsAndConstants::GBRForestsAndConstants(edm::ParameterSet const& iConfig)
2727
applyJec_(iConfig.getParameter<bool>("applyJec")),
2828
jec_(iConfig.getParameter<std::string>("jec")),
2929
residualsFromTxt_(iConfig.getParameter<bool>("residualsFromTxt")),
30-
usePuppi_(iConfig.getParameter<bool>("usePuppi")) {
30+
applyConstituentWeight_(false) {
3131
if (residualsFromTxt_) {
3232
residualsTxt_ = iConfig.getParameter<edm::FileInPath>("residualsTxt");
3333
}
@@ -40,6 +40,11 @@ GBRForestsAndConstants::GBRForestsAndConstants(edm::ParameterSet const& iConfig)
4040
if (!runMvas_) {
4141
assert(algos.size() == 1);
4242
}
43+
44+
edm::InputTag srcConstituentWeights = iConfig.getParameter<edm::InputTag>("srcConstituentWeights");
45+
if (!srcConstituentWeights.label().empty()) {
46+
applyConstituentWeight_ = true;
47+
}
4348
}
4449

4550
// ------------------------------------------------------------------------------------------
@@ -62,6 +67,11 @@ PileupJetIdProducer::PileupJetIdProducer(const edm::ParameterSet& iConfig, GBRFo
6267
consumes<edm::ValueMap<StoredPileupJetIdentifier>>(iConfig.getParameter<edm::InputTag>("jetids"));
6368
input_rho_token_ = consumes<double>(iConfig.getParameter<edm::InputTag>("rho"));
6469
parameters_token_ = esConsumes(edm::ESInputTag("", globalCache->jec()));
70+
71+
edm::InputTag srcConstituentWeights = iConfig.getParameter<edm::InputTag>("srcConstituentWeights");
72+
if (!srcConstituentWeights.label().empty()) {
73+
input_constituent_weights_token_ = consumes<edm::ValueMap<float>>(srcConstituentWeights);
74+
}
6575
}
6676

6777
// ------------------------------------------------------------------------------------------
@@ -80,6 +90,12 @@ void PileupJetIdProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe
8090
iEvent.getByToken(input_jet_token_, jetHandle);
8191
const View<Jet>& jets = *jetHandle;
8292

93+
// Constituent weight (e.g PUPPI) Value Map
94+
edm::ValueMap<float> constituentWeights;
95+
if (!input_constituent_weights_token_.isUninitialized()) {
96+
constituentWeights = iEvent.get(input_constituent_weights_token_);
97+
}
98+
8399
// input variables
84100
Handle<ValueMap<StoredPileupJetIdentifier>> vmap;
85101
if (!gc->produceJetIds()) {
@@ -167,7 +183,9 @@ void PileupJetIdProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe
167183
PileupJetIdentifier puIdentifier;
168184
if (gc->produceJetIds()) {
169185
// Compute the input variables
170-
puIdentifier = ialgo->computeIdVariables(theJet, jec, &(*vtx), *vertexes, rho, gc->usePuppi());
186+
////////////////////////////// added PUPPI weight Value Map
187+
puIdentifier = ialgo->computeIdVariables(
188+
theJet, jec, &(*vtx), *vertexes, rho, constituentWeights, gc->applyConstituentWeight());
171189
ids.push_back(puIdentifier);
172190
} else {
173191
// Or read it from the value map

RecoJets/JetProducers/plugins/PileupJetIdProducer.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class GBRForestsAndConstants {
6161
std::string const& jec() const { return jec_; }
6262
bool residualsFromTxt() const { return residualsFromTxt_; }
6363
edm::FileInPath const& residualsTxt() const { return residualsTxt_; }
64-
bool usePuppi() const { return usePuppi_; }
64+
bool applyConstituentWeight() const { return applyConstituentWeight_; }
6565

6666
private:
6767
std::vector<PileupJetIdAlgo::AlgoGBRForestsAndConstants> vAlgoGBRForestsAndConstants_;
@@ -73,7 +73,7 @@ class GBRForestsAndConstants {
7373
std::string jec_;
7474
bool residualsFromTxt_;
7575
edm::FileInPath residualsTxt_;
76-
bool usePuppi_;
76+
bool applyConstituentWeight_;
7777
};
7878

7979
class PileupJetIdProducer : public edm::stream::EDProducer<edm::GlobalCache<GBRForestsAndConstants>> {
@@ -99,6 +99,8 @@ class PileupJetIdProducer : public edm::stream::EDProducer<edm::GlobalCache<GBRF
9999
std::unique_ptr<FactorizedJetCorrector> jecCor_;
100100
std::vector<JetCorrectorParameters> jetCorPars_;
101101

102+
edm::ValueMap<float> constituentWeights_;
103+
edm::EDGetTokenT<edm::ValueMap<float>> input_constituent_weights_token_;
102104
edm::EDGetTokenT<edm::View<reco::Jet>> input_jet_token_;
103105
edm::EDGetTokenT<reco::VertexCollection> input_vertex_token_;
104106
edm::EDGetTokenT<edm::ValueMap<StoredPileupJetIdentifier>> input_vm_pujetid_token_;

RecoJets/JetProducers/python/PileupJetID_cfi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
applyJec = cms.bool(True),
3333
inputIsCorrected = cms.bool(False),
3434
residualsFromTxt = cms.bool(False),
35-
usePuppi = cms.bool(False),
35+
srcConstituentWeights = cms.InputTag(""),
3636
# residualsTxt = cms.FileInPath("RecoJets/JetProducers/data/download.url") # must be an existing file
3737
)
3838

0 commit comments

Comments
 (0)