Skip to content

Commit

Permalink
Fix PUID Variable bug and implement PUPPI Weight using a Value Map
Browse files Browse the repository at this point in the history
  • Loading branch information
jshin96 committed Feb 12, 2023
1 parent 2f899a2 commit 703a7cd
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 85 deletions.
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
2 changes: 1 addition & 1 deletion RecoJets/JetProducers/interface/PileupJetIdAlgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PileupJetIdAlgo {
~PileupJetIdAlgo();

PileupJetIdentifier computeIdVariables(
const reco::Jet* jet, float jec, const reco::Vertex*, const reco::VertexCollection&, double rho, bool usePuppi);
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
28 changes: 26 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,12 @@ 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 +68,17 @@ 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 src_ = iConfig.getParameter<edm::InputTag>("src");
// edm::InputTag srcWeights = iConfig.getParameter<edm::InputTag>("srcWeights");
// if (iConfig.getParameter<edm::InputTag>("src").label() == iConfig.getParameter<edm::InputTag>("srcConstituentWeights").label())
// edm::LogWarning("PileupJetIdAlgo")
// << "Particle and weights collection have the same label. You may be applying the same weights twice. \n";
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 +97,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 +190,8 @@ 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

0 comments on commit 703a7cd

Please sign in to comment.