Skip to content

Commit

Permalink
Merge pull request #2 from jshin96/backport_CMSSW_1264_applybuggy
Browse files Browse the repository at this point in the history
Backport cmssw 1264 applybuggy
  • Loading branch information
jshin96 authored Apr 17, 2023
2 parents 853463d + 7946e8d commit c478489
Show file tree
Hide file tree
Showing 6 changed files with 335 additions and 133 deletions.
8 changes: 8 additions & 0 deletions CommonTools/PileupAlgos/plugins/PuppiProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class PuppiProducer : public edm::stream::EDProducer<> {
bool fUseExistingWeights;
bool fApplyPhotonProtectionForExistingWeights;
bool fClonePackedCands;
bool fuseBugFix;
int fVtxNdofCut;
double fVtxZCut;
bool fUsePUProxyValue;
Expand All @@ -106,6 +107,7 @@ PuppiProducer::PuppiProducer(const edm::ParameterSet& iConfig) {
fDZCutForChargedFromPUVtxs = iConfig.getParameter<double>("DeltaZCutForChargedFromPUVtxs");
fUseExistingWeights = iConfig.getParameter<bool>("useExistingWeights");
fApplyPhotonProtectionForExistingWeights = iConfig.getParameter<bool>("applyPhotonProtectionForExistingWeights");
fuseBugFix = iConfig.getParameter<bool>("useBugFix");
fClonePackedCands = iConfig.getParameter<bool>("clonePackedCands");
fVtxNdofCut = iConfig.getParameter<int>("vtxNdofCut");
fVtxZCut = iConfig.getParameter<double>("vtxZCut");
Expand Down Expand Up @@ -365,6 +367,11 @@ 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) && fuseBugFix)
curpupweight = 1;

// 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))
Expand Down Expand Up @@ -514,6 +521,7 @@ void PuppiProducer::fillDescriptions(edm::ConfigurationDescriptions& description
desc.add<double>("DeltaZCutForChargedFromPUVtxs", 0.2);
desc.add<bool>("useExistingWeights", false);
desc.add<bool>("applyPhotonProtectionForExistingWeights", false);
desc.add<bool>("useBugFix",false);
desc.add<bool>("clonePackedCands", false);
desc.add<int>("vtxNdofCut", 4);
desc.add<double>("vtxZCut", 24);
Expand Down
4 changes: 3 additions & 1 deletion PhysicsTools/NanoAOD/python/custom_jme_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ def AddPileUpJetIDVars(proc, jetName="", jetSrc="", jetTableName="", jetTaskName
vertexes = "offlineSlimmedPrimaryVertices",
inputIsCorrected = True,
applyJec = False,
srcConstituentWeights = "packedPFCandidatespuppi" if "PUPPI" in jetName.upper() else ""
usePuppi = True if "PUPPI" in jetName.upper() else False,
srcConstituentWeights = "packedPFCandidatespuppi" if "PUPPI" in jetName.upper() else "",
useBugFix = False
)
)
getattr(proc,jetTaskName).add(getattr(proc, puJetIdVarsCalculator))
Expand Down
20 changes: 13 additions & 7 deletions RecoJets/JetProducers/plugins/PileupJetIdProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ GBRForestsAndConstants::GBRForestsAndConstants(edm::ParameterSet const& iConfig)
applyJec_(iConfig.getParameter<bool>("applyJec")),
jec_(iConfig.getParameter<std::string>("jec")),
residualsFromTxt_(iConfig.getParameter<bool>("residualsFromTxt")),
applyConstituentWeight_(false) {
usePuppi_(iConfig.getParameter<bool>("usePuppi")),
applyConstituentWeight_(false),
useBugFix_(iConfig.getParameter<bool>("useBugFix")) {

if (residualsFromTxt_) {
residualsTxt_ = iConfig.getParameter<edm::FileInPath>("residualsTxt");
}
Expand All @@ -42,7 +45,7 @@ GBRForestsAndConstants::GBRForestsAndConstants(edm::ParameterSet const& iConfig)
}

edm::InputTag srcConstituentWeights = iConfig.getParameter<edm::InputTag>("srcConstituentWeights");
if (!srcConstituentWeights.label().empty()) {
if (!srcConstituentWeights.label().empty()){
applyConstituentWeight_ = true;
}
}
Expand All @@ -67,9 +70,8 @@ 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()) {
if (!srcConstituentWeights.label().empty()){
input_constituent_weights_token_ = consumes<edm::ValueMap<float>>(srcConstituentWeights);
}
}
Expand All @@ -89,6 +91,11 @@ void PileupJetIdProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe
Handle<View<Jet>> jetHandle;
iEvent.getByToken(input_jet_token_, jetHandle);
const View<Jet>& jets = *jetHandle;
edm::ValueMap<float> constituentWeights;
if (!input_constituent_weights_token_.isUninitialized()) {
constituentWeights = iEvent.get(input_constituent_weights_token_);
}


// Constituent weight (e.g PUPPI) Value Map
edm::ValueMap<float> constituentWeights;
Expand Down Expand Up @@ -183,9 +190,8 @@ void PileupJetIdProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe
PileupJetIdentifier puIdentifier;
if (gc->produceJetIds()) {
// Compute the input variables
////////////////////////////// added PUPPI weight Value Map
puIdentifier = ialgo->computeIdVariables(
theJet, jec, &(*vtx), *vertexes, rho, constituentWeights, gc->applyConstituentWeight());
puIdentifier = ialgo->computeIdVariables(theJet, jec, &(*vtx), *vertexes, rho, gc->usePuppi(), constituentWeights, gc->applyConstituentWeight(), gc->useBugFix());

ids.push_back(puIdentifier);
} else {
// Or read it from the value map
Expand Down
5 changes: 5 additions & 0 deletions RecoJets/JetProducers/plugins/PileupJetIdProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ 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_; }
bool useBugFix() const {return useBugFix_; }


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

class PileupJetIdProducer : public edm::stream::EDProducer<edm::GlobalCache<GBRForestsAndConstants>> {
Expand Down
3 changes: 3 additions & 0 deletions RecoJets/JetProducers/python/PileupJetID_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
applyJec = cms.bool(True),
inputIsCorrected = cms.bool(False),
residualsFromTxt = cms.bool(False),
usePuppi = cms.bool(False),
srcConstituentWeights = cms.InputTag(""),
useBugFix = cms.bool(False)

# residualsTxt = cms.FileInPath("RecoJets/JetProducers/data/download.url") # must be an existing file
)

Expand Down
Loading

0 comments on commit c478489

Please sign in to comment.