Skip to content

Commit

Permalink
Merge pull request #40762 from jshin96/from1300pre4_pujetid_fix
Browse files Browse the repository at this point in the history
[PileupJetId, Puppi] Pileup ID input variable fix, puppi weight ValueMap access, optional photon protection for existing puppi weights
  • Loading branch information
cmsbuild committed Feb 21, 2023
2 parents 57ed23b + 283d569 commit 918a7fc
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 89 deletions.
9 changes: 6 additions & 3 deletions CommonTools/PileupAlgos/plugins/PuppiProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class PuppiProducer : public edm::stream::EDProducer<> {
uint fNumOfPUVtxsForCharged;
double fDZCutForChargedFromPUVtxs;
bool fUseExistingWeights;
bool fApplyPhotonProtectionForExistingWeights;
bool fClonePackedCands;
int fVtxNdofCut;
double fVtxZCut;
Expand All @@ -104,6 +105,7 @@ PuppiProducer::PuppiProducer(const edm::ParameterSet& iConfig) {
fNumOfPUVtxsForCharged = iConfig.getParameter<uint>("NumOfPUVtxsForCharged");
fDZCutForChargedFromPUVtxs = iConfig.getParameter<double>("DeltaZCutForChargedFromPUVtxs");
fUseExistingWeights = iConfig.getParameter<bool>("useExistingWeights");
fApplyPhotonProtectionForExistingWeights = iConfig.getParameter<bool>("applyPhotonProtectionForExistingWeights");
fClonePackedCands = iConfig.getParameter<bool>("clonePackedCands");
fVtxNdofCut = iConfig.getParameter<int>("vtxNdofCut");
fVtxZCut = iConfig.getParameter<double>("vtxZCut");
Expand Down Expand Up @@ -363,9 +365,9 @@ void PuppiProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
curpupweight = lPack->puppiWeight();
}
}
// Protect high pT photons (important for gamma to hadronic recoil balance)
if ((fPtMaxPhotons > 0) && (lPack->pdgId() == 22) && (std::abs(lPack->eta()) < fEtaMaxPhotons) &&
(lPack->pt() > fPtMaxPhotons))
// Optional: Protect high pT photons (important for gamma to hadronic recoil balance) for existing weights.
if (fApplyPhotonProtectionForExistingWeights && (fPtMaxPhotons > 0) && (lPack->pdgId() == 22) &&
(std::abs(lPack->eta()) < fEtaMaxPhotons) && (lPack->pt() > fPtMaxPhotons))
curpupweight = 1;
lWeights.push_back(curpupweight);
lPackCtr++;
Expand Down Expand Up @@ -511,6 +513,7 @@ void PuppiProducer::fillDescriptions(edm::ConfigurationDescriptions& description
desc.add<uint>("NumOfPUVtxsForCharged", 0);
desc.add<double>("DeltaZCutForChargedFromPUVtxs", 0.2);
desc.add<bool>("useExistingWeights", false);
desc.add<bool>("applyPhotonProtectionForExistingWeights", false);
desc.add<bool>("clonePackedCands", false);
desc.add<int>("vtxNdofCut", 4);
desc.add<double>("vtxZCut", 24);
Expand Down
2 changes: 1 addition & 1 deletion PhysicsTools/NanoAOD/python/custom_jme_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def AddPileUpJetIDVars(proc, jetName="", jetSrc="", jetTableName="", jetTaskName
vertexes = "offlineSlimmedPrimaryVertices",
inputIsCorrected = True,
applyJec = False,
usePuppi = True if "PUPPI" in jetName.upper() else False
srcConstituentWeights = "packedPFCandidatespuppi" if "PUPPI" in jetName.upper() else ""
)
)
getattr(proc,jetTaskName).add(getattr(proc, puJetIdVarsCalculator))
Expand Down
9 changes: 7 additions & 2 deletions RecoJets/JetProducers/interface/PileupJetIdAlgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ class PileupJetIdAlgo {
PileupJetIdAlgo(AlgoGBRForestsAndConstants const* cache);
~PileupJetIdAlgo();

PileupJetIdentifier computeIdVariables(
const reco::Jet* jet, float jec, const reco::Vertex*, const reco::VertexCollection&, double rho, bool usePuppi);
PileupJetIdentifier computeIdVariables(const reco::Jet* jet,
float jec,
const reco::Vertex*,
const reco::VertexCollection&,
double rho,
edm::ValueMap<float>& constituentWeights,
bool applyConstituentWeight);

void set(const PileupJetIdentifier&);
float getMVAval(const std::vector<std::string>&, const std::unique_ptr<const GBRForest>&);
Expand Down
22 changes: 20 additions & 2 deletions RecoJets/JetProducers/plugins/PileupJetIdProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ GBRForestsAndConstants::GBRForestsAndConstants(edm::ParameterSet const& iConfig)
applyJec_(iConfig.getParameter<bool>("applyJec")),
jec_(iConfig.getParameter<std::string>("jec")),
residualsFromTxt_(iConfig.getParameter<bool>("residualsFromTxt")),
usePuppi_(iConfig.getParameter<bool>("usePuppi")) {
applyConstituentWeight_(false) {
if (residualsFromTxt_) {
residualsTxt_ = iConfig.getParameter<edm::FileInPath>("residualsTxt");
}
Expand All @@ -40,6 +40,11 @@ GBRForestsAndConstants::GBRForestsAndConstants(edm::ParameterSet const& iConfig)
if (!runMvas_) {
assert(algos.size() == 1);
}

edm::InputTag srcConstituentWeights = iConfig.getParameter<edm::InputTag>("srcConstituentWeights");
if (!srcConstituentWeights.label().empty()) {
applyConstituentWeight_ = true;
}
}

// ------------------------------------------------------------------------------------------
Expand All @@ -62,6 +67,11 @@ PileupJetIdProducer::PileupJetIdProducer(const edm::ParameterSet& iConfig, GBRFo
consumes<edm::ValueMap<StoredPileupJetIdentifier>>(iConfig.getParameter<edm::InputTag>("jetids"));
input_rho_token_ = consumes<double>(iConfig.getParameter<edm::InputTag>("rho"));
parameters_token_ = esConsumes(edm::ESInputTag("", globalCache->jec()));

edm::InputTag srcConstituentWeights = iConfig.getParameter<edm::InputTag>("srcConstituentWeights");
if (!srcConstituentWeights.label().empty()) {
input_constituent_weights_token_ = consumes<edm::ValueMap<float>>(srcConstituentWeights);
}
}

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

// Constituent weight (e.g PUPPI) Value Map
edm::ValueMap<float> constituentWeights;
if (!input_constituent_weights_token_.isUninitialized()) {
constituentWeights = iEvent.get(input_constituent_weights_token_);
}

// input variables
Handle<ValueMap<StoredPileupJetIdentifier>> vmap;
if (!gc->produceJetIds()) {
Expand Down Expand Up @@ -167,7 +183,9 @@ void PileupJetIdProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe
PileupJetIdentifier puIdentifier;
if (gc->produceJetIds()) {
// Compute the input variables
puIdentifier = ialgo->computeIdVariables(theJet, jec, &(*vtx), *vertexes, rho, gc->usePuppi());
////////////////////////////// added PUPPI weight Value Map
puIdentifier = ialgo->computeIdVariables(
theJet, jec, &(*vtx), *vertexes, rho, constituentWeights, gc->applyConstituentWeight());
ids.push_back(puIdentifier);
} else {
// Or read it from the value map
Expand Down
6 changes: 4 additions & 2 deletions RecoJets/JetProducers/plugins/PileupJetIdProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class GBRForestsAndConstants {
std::string const& jec() const { return jec_; }
bool residualsFromTxt() const { return residualsFromTxt_; }
edm::FileInPath const& residualsTxt() const { return residualsTxt_; }
bool usePuppi() const { return usePuppi_; }
bool applyConstituentWeight() const { return applyConstituentWeight_; }

private:
std::vector<PileupJetIdAlgo::AlgoGBRForestsAndConstants> vAlgoGBRForestsAndConstants_;
Expand All @@ -73,7 +73,7 @@ class GBRForestsAndConstants {
std::string jec_;
bool residualsFromTxt_;
edm::FileInPath residualsTxt_;
bool usePuppi_;
bool applyConstituentWeight_;
};

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

edm::ValueMap<float> constituentWeights_;
edm::EDGetTokenT<edm::ValueMap<float>> input_constituent_weights_token_;
edm::EDGetTokenT<edm::View<reco::Jet>> input_jet_token_;
edm::EDGetTokenT<reco::VertexCollection> input_vertex_token_;
edm::EDGetTokenT<edm::ValueMap<StoredPileupJetIdentifier>> input_vm_pujetid_token_;
Expand Down
2 changes: 1 addition & 1 deletion RecoJets/JetProducers/python/PileupJetID_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
applyJec = cms.bool(True),
inputIsCorrected = cms.bool(False),
residualsFromTxt = cms.bool(False),
usePuppi = cms.bool(False),
srcConstituentWeights = cms.InputTag(""),
# residualsTxt = cms.FileInPath("RecoJets/JetProducers/data/download.url") # must be an existing file
)

Expand Down
Loading

0 comments on commit 918a7fc

Please sign in to comment.