diff --git a/PhysicsTools/PatAlgos/python/tools/jetTools.py b/PhysicsTools/PatAlgos/python/tools/jetTools.py index 9c14efad08a35..ae5ec8da7495e 100644 --- a/PhysicsTools/PatAlgos/python/tools/jetTools.py +++ b/PhysicsTools/PatAlgos/python/tools/jetTools.py @@ -638,27 +638,15 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou if btagInfo == 'pfDeepBoostedJetTagInfos': if pfCandidates.value() == 'packedPFCandidates': # case 1: running over jets whose daughters are PackedCandidates (only via updateJetCollection for now) - jetSrcName = jetSource.value().lower() - if 'updated' in jetSrcName: - puppi_value_map = "" - vertex_associator = "" - if 'withpuppidaughter' in jetSrcName: - # special case for Puppi jets reclustered from MiniAOD by analyzers - # need to specify 'WithPuppiDaughters' in the postfix when calling updateJetCollection - # daughters of these jets are already scaled by their puppi weights - has_puppi_weighted_daughters = True - else: - # default case for updating jet collection stored in MiniAOD, e.g., slimmedJetsAK8 - # daughters are links to the original PackedCandidates, so NOT scaled by their puppi weights yet - has_puppi_weighted_daughters = False - else: + if 'updated' not in jetSource.value().lower(): raise ValueError("Invalid jet collection: %s. pfDeepBoostedJetTagInfos only supports running via updateJetCollection." % jetSource.value()) + puppi_value_map = "" + vertex_associator = "" elif pfCandidates.value() == 'particleFlow': raise ValueError("Running pfDeepBoostedJetTagInfos with reco::PFCandidates is currently not supported.") # case 2: running on new jet collection whose daughters are PFCandidates (e.g., cluster jets in RECO/AOD) # daughters are the particles used in jet clustering, so already scaled by their puppi weights # Uncomment the lines below after running pfDeepBoostedJetTagInfos with reco::PFCandidates becomes supported -# has_puppi_weighted_daughters = True # puppi_value_map = "puppi" # vertex_associator = "primaryVertexAssociation:original" else: @@ -668,7 +656,7 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou jets = jetSource, vertices = pvSource, secondary_vertices = svSource, - has_puppi_weighted_daughters = has_puppi_weighted_daughters, + pf_candidates = pfCandidates, puppi_value_map = puppi_value_map, vertex_associator = vertex_associator, ), diff --git a/RecoBTag/FeatureTools/plugins/DeepBoostedJetTagInfoProducer.cc b/RecoBTag/FeatureTools/plugins/DeepBoostedJetTagInfoProducer.cc index 133a3bd7d555f..c6fc6426f31db 100644 --- a/RecoBTag/FeatureTools/plugins/DeepBoostedJetTagInfoProducer.cc +++ b/RecoBTag/FeatureTools/plugins/DeepBoostedJetTagInfoProducer.cc @@ -34,6 +34,7 @@ class DeepBoostedJetTagInfoProducer : public edm::stream::EDProducer<> { typedef std::vector DeepBoostedJetTagInfoCollection; typedef reco::VertexCompositePtrCandidateCollection SVCollection; typedef reco::VertexCollection VertexCollection; + typedef edm::View CandidateView; void beginStream(edm::StreamID) override {} void produce(edm::Event &, const edm::EventSetup &) override; @@ -42,7 +43,6 @@ class DeepBoostedJetTagInfoProducer : public edm::stream::EDProducer<> { void fillParticleFeatures(DeepBoostedJetFeatures &fts, const reco::Jet &jet); void fillSVFeatures(DeepBoostedJetFeatures &fts, const reco::Jet &jet); - const bool has_puppi_weighted_daughters_; const double jet_radius_; const double min_jet_pt_; const double min_pt_for_track_properties_; @@ -50,6 +50,7 @@ class DeepBoostedJetTagInfoProducer : public edm::stream::EDProducer<> { edm::EDGetTokenT> jet_token_; edm::EDGetTokenT vtx_token_; edm::EDGetTokenT sv_token_; + edm::EDGetTokenT pfcand_token_; bool use_puppi_value_map_; bool use_pvasq_value_map_; @@ -60,6 +61,7 @@ class DeepBoostedJetTagInfoProducer : public edm::stream::EDProducer<> { edm::Handle vtxs_; edm::Handle svs_; + edm::Handle pfcands_; edm::ESHandle track_builder_; edm::Handle> puppi_value_map_; edm::Handle> pvasq_value_map_; @@ -103,13 +105,13 @@ const std::vector DeepBoostedJetTagInfoProducer::sv_features_{ }; DeepBoostedJetTagInfoProducer::DeepBoostedJetTagInfoProducer(const edm::ParameterSet &iConfig) - : has_puppi_weighted_daughters_(iConfig.getParameter("has_puppi_weighted_daughters")), - jet_radius_(iConfig.getParameter("jet_radius")), + : jet_radius_(iConfig.getParameter("jet_radius")), min_jet_pt_(iConfig.getParameter("min_jet_pt")), min_pt_for_track_properties_(iConfig.getParameter("min_pt_for_track_properties")), jet_token_(consumes>(iConfig.getParameter("jets"))), vtx_token_(consumes(iConfig.getParameter("vertices"))), sv_token_(consumes(iConfig.getParameter("secondary_vertices"))), + pfcand_token_(consumes(iConfig.getParameter("pf_candidates"))), use_puppi_value_map_(false), use_pvasq_value_map_(false) { const auto &puppi_value_map_tag = iConfig.getParameter("puppi_value_map"); @@ -133,12 +135,12 @@ DeepBoostedJetTagInfoProducer::~DeepBoostedJetTagInfoProducer() {} void DeepBoostedJetTagInfoProducer::fillDescriptions(edm::ConfigurationDescriptions &descriptions) { // pfDeepBoostedJetTagInfos edm::ParameterSetDescription desc; - desc.add("has_puppi_weighted_daughters", true); desc.add("jet_radius", 0.8); desc.add("min_jet_pt", 150); desc.add("min_pt_for_track_properties", -1); desc.add("vertices", edm::InputTag("offlinePrimaryVertices")); desc.add("secondary_vertices", edm::InputTag("inclusiveCandidateSecondaryVertices")); + desc.add("pf_candidates", edm::InputTag("particleFlow")); desc.add("jets", edm::InputTag("ak8PFJetsPuppi")); desc.add("puppi_value_map", edm::InputTag("puppi")); desc.add("vertex_associator", edm::InputTag("primaryVertexAssociation", "original")); @@ -162,6 +164,8 @@ void DeepBoostedJetTagInfoProducer::produce(edm::Event &iEvent, const edm::Event iEvent.getByToken(sv_token_, svs_); + iEvent.getByToken(pfcand_token_, pfcands_); + iSetup.get().get("TransientTrackBuilder", track_builder_); if (use_puppi_value_map_) { @@ -252,20 +256,14 @@ void DeepBoostedJetTagInfoProducer::fillParticleFeatures(DeepBoostedJetFeatures // remove particles w/ extremely low puppi weights if ((puppiWgt(cand)) < 0.01) continue; - daughters.push_back(cand); - } - // sort by (Puppi-weighted) pt - if (!has_puppi_weighted_daughters_) { - std::sort(daughters.begin(), - daughters.end(), - [&puppi_wgt_cache](const reco::CandidatePtr &a, const reco::CandidatePtr &b) { - return puppi_wgt_cache.at(a.key()) * a->pt() > puppi_wgt_cache.at(b.key()) * b->pt(); - }); - } else { - std::sort(daughters.begin(), daughters.end(), [](const reco::CandidatePtr &a, const reco::CandidatePtr &b) { - return a->pt() > b->pt(); - }); + // get the original reco/packed candidate not scaled by the puppi weight + daughters.push_back(pfcands_->ptrAt(cand.key())); } + // sort by Puppi-weighted pt + std::sort(daughters.begin(), daughters.end(), + [&puppi_wgt_cache](const reco::CandidatePtr &a, const reco::CandidatePtr &b) { + return puppi_wgt_cache.at(a.key()) * a->pt() > puppi_wgt_cache.at(b.key()) * b->pt(); + }); // reserve space for (const auto &name : particle_features_) { @@ -281,12 +279,8 @@ void DeepBoostedJetTagInfoProducer::fillParticleFeatures(DeepBoostedJetFeatures const auto *packed_cand = dynamic_cast(&(*cand)); const auto *reco_cand = dynamic_cast(&(*cand)); - auto puppiP4 = cand->p4(); + auto puppiP4 = puppi_wgt_cache.at(cand.key()) * cand->p4(); if (packed_cand) { - if (!has_puppi_weighted_daughters_) { - puppiP4 *= puppi_wgt_cache.at(cand.key()); - } - float hcal_fraction = 0.; if (packed_cand->pdgId() == 1 || packed_cand->pdgId() == 130) { hcal_fraction = packed_cand->hcalFraction();