Skip to content

Commit

Permalink
Merge branch 'portFrom131XTo126X_pujetid_fix' into backport_CMSSW_126…
Browse files Browse the repository at this point in the history
…4_applybuggy
  • Loading branch information
jshin96 authored Apr 17, 2023
2 parents 27cfac4 + 853463d commit 7946e8d
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 10 deletions.
1 change: 0 additions & 1 deletion CommonTools/PileupAlgos/plugins/PuppiProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@ void PuppiProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
(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
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, edm::ValueMap<float>& constituentWeights, bool applyConstituentWeight, bool useBugFix);
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
9 changes: 8 additions & 1 deletion RecoJets/JetProducers/plugins/PileupJetIdProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ GBRForestsAndConstants::GBRForestsAndConstants(edm::ParameterSet const& iConfig)
usePuppi_(iConfig.getParameter<bool>("usePuppi")),
applyConstituentWeight_(false),
useBugFix_(iConfig.getParameter<bool>("useBugFix")) {

if (residualsFromTxt_) {
residualsTxt_ = iConfig.getParameter<edm::FileInPath>("residualsTxt");
}
Expand All @@ -42,11 +43,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 Down Expand Up @@ -96,6 +97,12 @@ void PileupJetIdProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe
}


// 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
1 change: 1 addition & 0 deletions RecoJets/JetProducers/plugins/PileupJetIdProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class GBRForestsAndConstants {
bool applyConstituentWeight() const { return applyConstituentWeight_; }
bool useBugFix() const {return useBugFix_; }


private:
std::vector<PileupJetIdAlgo::AlgoGBRForestsAndConstants> vAlgoGBRForestsAndConstants_;

Expand Down
1 change: 1 addition & 0 deletions RecoJets/JetProducers/python/PileupJetID_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
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
34 changes: 28 additions & 6 deletions RecoJets/JetProducers/src/PileupJetIdAlgo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ PileupJetIdentifier PileupJetIdAlgo::computeIdVariables(const reco::Jet* jet,
edm::ValueMap<float>& constituentWeights,
bool applyConstituentWeight,
bool useBugFix) {

// initialize all variables to 0
resetVariables();

Expand All @@ -284,6 +283,7 @@ PileupJetIdentifier PileupJetIdAlgo::computeIdVariables(const reco::Jet* jet,

const reco::Candidate *lLead = nullptr, *lSecond = nullptr, *lLeadNeut = nullptr, *lLeadEm = nullptr,
*lLeadCh = nullptr, *lTrail = nullptr;

std::vector<float> frac, fracCh, fracEm, fracNeut;
float cones[] = {0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7};
size_t ncones = sizeof(cones) / sizeof(float);
Expand Down Expand Up @@ -324,6 +324,9 @@ PileupJetIdentifier PileupJetIdAlgo::computeIdVariables(const reco::Jet* jet,
float sum_deta(0.0), sum_dphi(0.0);
float ave_deta(0.0), ave_dphi(0.0);
float multNeut = 0.0;
float sumW2(0.0);
float sum_deta(0.0), sum_dphi(0.0);
float ave_deta(0.0), ave_dphi(0.0);
setPtEtaPhi(
*jet, internalId_.jetPt_, internalId_.jetEta_, internalId_.jetPhi_); // use corrected pt for jet kinematics
internalId_.jetM_ = jet->mass();
Expand All @@ -346,7 +349,6 @@ PileupJetIdentifier PileupJetIdAlgo::computeIdVariables(const reco::Jet* jet,
}
for (unsigned i = 0; i < nCandPtrs; ++i) {
reco::CandidatePtr pfJetConstituent = jet->sourceCandidatePtr(i);

const reco::Candidate* icand = pfJetConstituent.get();
const pat::PackedCandidate* lPack = dynamic_cast<const pat::PackedCandidate*>(icand);
const reco::PFCandidate* lPF = dynamic_cast<const reco::PFCandidate*>(icand);
Expand Down Expand Up @@ -376,7 +378,6 @@ PileupJetIdentifier PileupJetIdAlgo::computeIdVariables(const reco::Jet* jet,

if (candDr < dRmin)
dRmin = candDr;

// // all particles
if (!useBugFix) {
if (lLead == nullptr || candPt > lLead->pt()) {
Expand Down Expand Up @@ -417,8 +418,7 @@ PileupJetIdentifier PileupJetIdAlgo::computeIdVariables(const reco::Jet* jet,
if (icone < ncones) {
*coneFracs[icone] += candPt;
}

// neutrals
// neutrals Neutral hadrons
if (abs(icand->pdgId()) == 130) {
if (!useBugFix) {
if (lLeadNeut == nullptr || candPt > lLeadNeut->pt()) {
Expand All @@ -433,6 +433,7 @@ PileupJetIdentifier PileupJetIdAlgo::computeIdVariables(const reco::Jet* jet,
}
}
}

internalId_.dRMeanNeut_ += candPtDr;
fracNeut.push_back(candPtFrac);
if (icone < ncones) {
Expand All @@ -445,7 +446,8 @@ PileupJetIdentifier PileupJetIdAlgo::computeIdVariables(const reco::Jet* jet,
else
multNeut += candWeight;
}
// EM candidated

// EM candidated photon
if (icand->pdgId() == 22) {
if (!useBugFix) {
if (lLeadEm == nullptr || candPt > lLeadEm->pt()) {
Expand Down Expand Up @@ -636,6 +638,22 @@ PileupJetIdentifier PileupJetIdAlgo::computeIdVariables(const reco::Jet* jet,
// trailing candidate
if ((!useBugFix) && (lTrail == nullptr || candPt < lTrail->pt())) {
lTrail = icand;
if (applyConstituentWeight) {
TrailcandWeight = constituentWeights[jet->sourceCandidatePtr(i)];
}
}

// average for pull variable

float weight2 = candPt * candPt;
sumW2 += weight2;
float deta = icand->eta() - jet->eta();
float dphi = reco::deltaPhi(*icand, *jet);
sum_deta += deta * weight2;
sum_dphi += dphi * weight2;
if (sumW2 > 0) {
ave_deta = sum_deta / sumW2;
ave_dphi = sum_dphi / sumW2;
}
else if ((useBugFix) && (lTrail == nullptr || candPt < (lTrail->pt())*TrailcandWeight)){
lTrail = icand;
Expand All @@ -661,6 +679,8 @@ PileupJetIdentifier PileupJetIdAlgo::computeIdVariables(const reco::Jet* jet,


// // Finalize all variables
// Most of Below values are not used for puID variable generation at the moment, except lLeadCh Pt for JetRchg, so I assign that zero if there is no charged constituent.

assert(!(lLead == nullptr));
if (!useBugFix) {
if (lSecond == nullptr) {
Expand Down Expand Up @@ -737,6 +757,8 @@ PileupJetIdentifier PileupJetIdAlgo::computeIdVariables(const reco::Jet* jet,
internalId_.neuEMfrac_ = pfjet->neutralEmEnergy() / jet->energy();
internalId_.chgHadrfrac_ = pfjet->chargedHadronEnergy() / jet->energy();
internalId_.neuHadrfrac_ = pfjet->neutralHadronEnergy() / jet->energy();
if (applyConstituentWeight)
internalId_.nNeutrals_ = multNeut;
}
internalId_.nParticles_ = jet->nConstituents();

Expand Down

0 comments on commit 7946e8d

Please sign in to comment.