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

[PileupJetId, Puppi] Backport of #40762 (Pileup ID input variable fix, puppi weight ValueMap access, optional photon protection for existing puppi weights) to CMSSW_13_0_X #40801

Merged
merged 9 commits into from
Feb 21, 2023
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