diff --git a/PhysicsTools/PatAlgos/python/tools/jetTools.py b/PhysicsTools/PatAlgos/python/tools/jetTools.py index 861ae95fee4c9..b7809bd209a47 100644 --- a/PhysicsTools/PatAlgos/python/tools/jetTools.py +++ b/PhysicsTools/PatAlgos/python/tools/jetTools.py @@ -407,6 +407,11 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou process, task) + # Setup the PUPPI ValueMap that will consumed by the TagInfo producers. + puppi_value_map = "puppi" + if pfCandidates.value() == 'packedPFCandidates': + puppi_value_map = setupPuppiForPackedPF(process)[0] + acceptedTagInfos = list() for btagInfo in requiredTagInfos: if hasattr(btag,btagInfo): @@ -637,14 +642,9 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou process, task) - if 'pfBoostedDouble' in btagInfo or 'SecondaryVertex' in btagInfo: - _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix) - if pfCandidates.value() == 'packedPFCandidates': - packedPFPuppiLabel = setupPuppiForPackedPF(process)[0] - _btagInfo.weights = cms.InputTag(packedPFPuppiLabel) - else: - _btagInfo.weights = cms.InputTag("puppi") + _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix) + _btagInfo.weights = cms.InputTag(puppi_value_map) if 'DeepFlavourTagInfos' in btagInfo: svUsed = svSource @@ -659,10 +659,8 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou # use right input tags when running with RECO PF candidates, which actually # depends of whether jets use "particleFlow" if pfCandidates.value() == 'packedPFCandidates': - puppi_value_map = setupPuppiForPackedPF(process)[0] vertex_associator = cms.InputTag("") else: - puppi_value_map = cms.InputTag("puppi") vertex_associator = cms.InputTag("primaryVertexAssociation","original") # If this jet is a puppi jet, then set is_weighted_jet to true. @@ -680,7 +678,7 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou is_weighted_jet = is_weighted_jet, flip = flip), process, task) - + if ('ParticleTransformerAK4TagInfos' in btagInfo) and ('UnifiedParticleTransformerAK4TagInfos' not in btagInfo): #We also have to veto UParT is we select ParT svUsed = svSource if btagInfo == 'pfNegativeParticleTransformerAK4TagInfos': @@ -690,10 +688,8 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou # use right input tags when running with RECO PF candidates, which actually # depends of whether jets use "particleFlow" if pfCandidates.value() == 'packedPFCandidates': - puppi_value_map = setupPuppiForPackedPF(process)[0] vertex_associator = cms.InputTag("") else: - puppi_value_map = cms.InputTag("puppi") vertex_associator = cms.InputTag("primaryVertexAssociation","original") # If this jet is a puppi jet, then set is_weighted_jet to true. @@ -722,10 +718,8 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou # use right input tags when running with RECO PF candidates, which actually # depends of whether jets use "particleFlow" if pfCandidates.value() == 'packedPFCandidates': - puppi_value_map = setupPuppiForPackedPF(process)[0] vertex_associator = cms.InputTag("") else: - puppi_value_map = cms.InputTag("puppi") vertex_associator = cms.InputTag("primaryVertexAssociation","original") # If this jet is a puppi jet, then set is_weighted_jet to true. @@ -747,8 +741,6 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou # can only run on PAT jets, so the updater needs to be used if 'updated' not in jetSource.value().lower(): raise ValueError("Invalid jet collection: %s. pfDeepDoubleXTagInfos only supports running via updateJetCollection." % jetSource.value()) - packedPFPuppiLabel = setupPuppiForPackedPF(process)[0] - puppi_value_map = cms.InputTag(packedPFPuppiLabel) addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix, btag.pfDeepDoubleXTagInfos.clone( jets = jetSource, @@ -759,8 +751,6 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou ), process, task) if btagInfo == 'pfHiggsInteractionNetTagInfos': - packedPFPuppiLabel = setupPuppiForPackedPF(process)[0] - puppi_value_map = cms.InputTag(packedPFPuppiLabel) addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix, btag.pfHiggsInteractionNetTagInfos.clone( jets = jetSource, @@ -776,14 +766,12 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou # case 1: running over jets whose daughters are PackedCandidates (only via updateJetCollection for now) if 'updated' not in jetSource.value().lower(): raise ValueError("Invalid jet collection: %s. pfDeepBoostedJetTagInfos only supports running via updateJetCollection." % jetSource.value()) - puppi_value_map = setupPuppiForPackedPF(process)[0] 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 -# puppi_value_map = "puppi" # vertex_associator = "primaryVertexAssociation:original" else: raise ValueError("Invalid pfCandidates collection: %s." % pfCandidates.value()) @@ -801,12 +789,10 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou if btagInfo == 'pfParticleNetTagInfos': if pfCandidates.value() == 'packedPFCandidates': # case 1: running over jets whose daughters are PackedCandidates (only via updateJetCollection for now) - puppi_value_map = setupPuppiForPackedPF(process)[0] 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) - puppi_value_map = "puppi" vertex_associator = "primaryVertexAssociation:original" else: raise ValueError("Invalid pfCandidates collection: %s." % pfCandidates.value()) @@ -833,12 +819,10 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou sip3dSigMax = -1 if pfCandidates.value() == 'packedPFCandidates': # case 1: running over jets whose daughters are PackedCandidates (only via updateJetCollection for now) - puppi_value_map = setupPuppiForPackedPF(process)[0] 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) - puppi_value_map = "puppi" vertex_associator = "primaryVertexAssociation:original" else: raise ValueError("Invalid pfCandidates collection: %s." % pfCandidates.value()) @@ -877,6 +861,7 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou vertices = pvSource, secondary_vertices = svUsed, pf_candidates = pfCandidates, + puppi_value_map = puppi_value_map, flip_ip_sign = flip_ip_sign, max_sip3dsig_for_flip = max_sip3dsig_for_flip, ), @@ -892,12 +877,13 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou vertices = pvSource, secondary_vertices = svSource, pf_candidates = pfCandidates, + puppi_value_map = puppi_value_map ), process, task) acceptedTagInfos.append(btagInfo) - elif btagInfo == 'pfParticleNetFromMiniAODAK4CHSCentralTagInfos' or btagInfo == 'pfNegativeParticleNetFromMiniAODAK4PuppiForwardTagInfos': + elif btagInfo == 'pfParticleNetFromMiniAODAK4CHSCentralTagInfos' or btagInfo == 'pfNegativeParticleNetFromMiniAODAK4CHSCentralTagInfos': # ParticleNetFromMiniAOD cannot be run on RECO inputs, so need a workaround - if btagInfo == 'pfNegativeParticleNetFromMiniAODAK4PuppiForwardTagInfos': + if btagInfo == 'pfNegativeParticleNetFromMiniAODAK4CHSCentralTagInfos': svUsed, flip_ip_sign, max_sip3dsig_for_flip = cms.InputTag(btagPrefix+'inclusiveCandidateNegativeSecondaryVertices'+labelName+postfix), True, 10. else: svUsed, flip_ip_sign, max_sip3dsig_for_flip = svSource, False, -1. @@ -909,6 +895,7 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou vertices = pvSource, secondary_vertices = svUsed, pf_candidates = pfCandidates, + puppi_value_map = puppi_value_map, flip_ip_sign = flip_ip_sign, max_sip3dsig_for_flip = max_sip3dsig_for_flip, ), @@ -924,6 +911,7 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou vertices = pvSource, secondary_vertices = svSource, pf_candidates = pfCandidates, + puppi_value_map = puppi_value_map, ), process, task) acceptedTagInfos.append(btagInfo) @@ -937,6 +925,7 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou vertices = pvSource, secondary_vertices = svSource, pf_candidates = pfCandidates, + puppi_value_map = puppi_value_map, ), process, task) acceptedTagInfos.append(btagInfo) @@ -944,7 +933,7 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou print(' --> %s ignored, since not available via RecoBTag.Configuration.RecoBTag_cff!'%(btagInfo)) # setup all required btagDiscriminators acceptedBtagDiscriminators = list() - for discriminator_name in btagDiscriminators : + for discriminator_name in btagDiscriminators : btagDiscr = discriminator_name.split(':')[0] #split input tag to get the producer label #print discriminator_name, '-->', btagDiscr newDiscr = btagPrefix+btagDiscr+labelName+postfix #new discriminator name diff --git a/RecoBTag/FeatureTools/plugins/ParticleNetFeatureEvaluator.cc b/RecoBTag/FeatureTools/plugins/ParticleNetFeatureEvaluator.cc index 03feb93b0b1e7..a9e9791bf28be 100644 --- a/RecoBTag/FeatureTools/plugins/ParticleNetFeatureEvaluator.cc +++ b/RecoBTag/FeatureTools/plugins/ParticleNetFeatureEvaluator.cc @@ -64,6 +64,8 @@ class ParticleNetFeatureEvaluator : public edm::stream::EDProducer<> { const double max_eta_for_taus_; const bool include_neutrals_; const bool flip_ip_sign_; + const bool fallback_puppi_weight_; + bool use_puppi_value_map_; const double max_sip3dsig_for_flip_; edm::EDGetTokenT muon_token_; @@ -76,11 +78,13 @@ class ParticleNetFeatureEvaluator : public edm::stream::EDProducer<> { edm::EDGetTokenT sv_token_; edm::EDGetTokenT> pfcand_token_; edm::ESGetToken track_builder_token_; + edm::EDGetTokenT> puppi_value_map_token_; edm::Handle vtxs_; edm::Handle svs_; edm::Handle> pfcands_; edm::Handle losttracks_; + edm::Handle> puppi_value_map_; edm::ESHandle track_builder_; const static std::vector particle_features_; @@ -264,6 +268,8 @@ ParticleNetFeatureEvaluator::ParticleNetFeatureEvaluator(const edm::ParameterSet max_eta_for_taus_(iConfig.getParameter("max_eta_for_taus")), include_neutrals_(iConfig.getParameter("include_neutrals")), flip_ip_sign_(iConfig.getParameter("flip_ip_sign")), + fallback_puppi_weight_(iConfig.getParameter("fallback_puppi_weight")), + use_puppi_value_map_(false), max_sip3dsig_for_flip_(iConfig.getParameter("max_sip3dsig_for_flip")), muon_token_(consumes(iConfig.getParameter("muons"))), electron_token_(consumes(iConfig.getParameter("electrons"))), @@ -277,6 +283,11 @@ ParticleNetFeatureEvaluator::ParticleNetFeatureEvaluator(const edm::ParameterSet pfcand_token_(consumes>(iConfig.getParameter("pf_candidates"))), track_builder_token_( esConsumes(edm::ESInputTag("", "TransientTrackBuilder"))) { + const auto &puppi_value_map_tag = iConfig.getParameter("puppi_value_map"); + if (!puppi_value_map_tag.label().empty()) { + puppi_value_map_token_ = consumes>(puppi_value_map_tag); + use_puppi_value_map_ = true; + } produces>(); } @@ -297,10 +308,12 @@ void ParticleNetFeatureEvaluator::fillDescriptions(edm::ConfigurationDescription desc.add("max_eta_for_taus", 2.5); desc.add("include_neutrals", true); desc.add("flip_ip_sign", false); + desc.add("fallback_puppi_weight", false); desc.add("max_sip3dsig_for_flip", 99999); desc.add("vertices", edm::InputTag("offlineSlimmedPrimaryVertices")); desc.add("secondary_vertices", edm::InputTag("slimmedSecondaryVertices")); desc.add("pf_candidates", edm::InputTag("packedPFCandidates")); + desc.add("puppi_value_map", edm::InputTag("puppi")); desc.add("losttracks", edm::InputTag("lostTracks")); desc.add("jets", edm::InputTag("slimmedJetsAK8")); desc.add("muons", edm::InputTag("slimmedMuons")); @@ -325,6 +338,11 @@ void ParticleNetFeatureEvaluator::produce(edm::Event &iEvent, const edm::EventSe auto photons = iEvent.getHandle(photon_token_); // Input lost tracks iEvent.getByToken(losttrack_token_, losttracks_); + // Get puuppi value map + if (use_puppi_value_map_) { + iEvent.getByToken(puppi_value_map_token_, puppi_value_map_); + } + // Primary vertexes iEvent.getByToken(vtx_token_, vtxs_); if (vtxs_->empty()) { @@ -413,6 +431,9 @@ void ParticleNetFeatureEvaluator::fillParticleFeatures(DeepBoostedJetFeatures &f // track builder TrackInfoBuilder trackinfo(track_builder_); + //Save puppi weight for selected constituents in this map + std::map map_pc2puppiweight; + // make list of pf-candidates to be considered std::vector daughters; for (const auto &dau : jet.daughterPtrVector()) { @@ -428,6 +449,15 @@ void ParticleNetFeatureEvaluator::fillParticleFeatures(DeepBoostedJetFeatures &f continue; // filling daughters daughters.push_back(cand); + + float puppiw = 1.; + if (use_puppi_value_map_) { + puppiw = (*puppi_value_map_)[dau]; + } else if (!fallback_puppi_weight_) { + throw edm::Exception(edm::errors::InvalidReference, "PUPPI value map missing") + << "use fallback_puppi_weight option to use " << puppiw << " for cand as default"; + } + map_pc2puppiweight[cand] = puppiw; } // sort by original pt (not Puppi-weighted) @@ -486,7 +516,7 @@ void ParticleNetFeatureEvaluator::fillParticleFeatures(DeepBoostedJetFeatures &f fts.fill("jet_pfcand_frompv", cand->fromPV()); fts.fill("jet_pfcand_dz", ip_sign * (std::isnan(cand->dz(pv_ass_pos)) ? 0 : cand->dz(pv_ass_pos))); fts.fill("jet_pfcand_dxy", ip_sign * (std::isnan(cand->dxy(pv_ass_pos)) ? 0 : cand->dxy(pv_ass_pos))); - fts.fill("jet_pfcand_puppiw", cand->puppiWeight()); + fts.fill("jet_pfcand_puppiw", map_pc2puppiweight[cand]); fts.fill("jet_pfcand_nlostinnerhits", cand->lostInnerHits()); fts.fill("jet_pfcand_nhits", cand->numberOfHits()); fts.fill("jet_pfcand_npixhits", cand->numberOfPixelHits()); diff --git a/RecoBTag/FeatureTools/plugins/UnifiedParticleTransformerAK4TagInfoProducer.cc b/RecoBTag/FeatureTools/plugins/UnifiedParticleTransformerAK4TagInfoProducer.cc index f9ba49ed31205..45f55b82f5664 100644 --- a/RecoBTag/FeatureTools/plugins/UnifiedParticleTransformerAK4TagInfoProducer.cc +++ b/RecoBTag/FeatureTools/plugins/UnifiedParticleTransformerAK4TagInfoProducer.cc @@ -171,7 +171,7 @@ void UnifiedParticleTransformerAK4TagInfoProducer::fillDescriptions(edm::Configu desc.add("fallback_puppi_weight", false); desc.add("fallback_vertex_association", false); desc.add("is_weighted_jet", false); - desc.add("min_jet_pt", 15.0); + desc.add("min_jet_pt", 0.0); desc.add("max_jet_eta", 2.5); descriptions.add("pfUnifiedParticleTransformerAK4TagInfos", desc); } @@ -225,10 +225,10 @@ void UnifiedParticleTransformerAK4TagInfoProducer::produce(edm::Event& iEvent, c // reco jet reference (use as much as possible) const auto& jet = jets->at(jet_n); - if (jet.pt() < 15.0) { + if (jet.pt() < min_jet_pt_) { features.is_filled = false; } - if (std::abs(jet.eta()) > 2.5) { + if (std::abs(jet.eta()) > max_jet_eta_) { features.is_filled = false; } // dynamical casting to pointers, null if not possible diff --git a/RecoBTag/ONNXRuntime/python/pfParticleNetFromMiniAODAK4_cff.py b/RecoBTag/ONNXRuntime/python/pfParticleNetFromMiniAODAK4_cff.py index e1ce1914c2d8d..10270a64e6a4a 100644 --- a/RecoBTag/ONNXRuntime/python/pfParticleNetFromMiniAODAK4_cff.py +++ b/RecoBTag/ONNXRuntime/python/pfParticleNetFromMiniAODAK4_cff.py @@ -26,7 +26,7 @@ pfParticleNetFromMiniAODAK4PuppiCentralTagInfos = ParticleNetFeatureEvaluator.clone( jets = "slimmedJetsPuppi", jet_radius = 0.4, - min_jet_pt = 15, + min_jet_pt = 0., min_jet_eta = 0., max_jet_eta = 2.5, ) @@ -34,9 +34,9 @@ pfParticleNetFromMiniAODAK4PuppiForwardTagInfos = ParticleNetFeatureEvaluator.clone( jets = "slimmedJetsPuppi", jet_radius = 0.4, - min_jet_pt = 15, + min_jet_pt = 0., min_jet_eta = 2.5, - max_jet_eta = 4.7, + max_jet_eta = 5.0, )