Skip to content

Commit e939939

Browse files
authored
Merge pull request #46009 from nurfikri89/from1420pre1_btvChangePtEtaSel_AddpuppiVM
[BTV] Disable pT cut for AK4 Puppi ParticleNet and UParT taggers inference
2 parents 0e76391 + 3eae945 commit e939939

File tree

4 files changed

+53
-34
lines changed

4 files changed

+53
-34
lines changed

PhysicsTools/PatAlgos/python/tools/jetTools.py

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,11 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou
407407
process, task)
408408

409409

410+
# Setup the PUPPI ValueMap that will consumed by the TagInfo producers.
411+
puppi_value_map = "puppi"
412+
if pfCandidates.value() == 'packedPFCandidates':
413+
puppi_value_map = setupPuppiForPackedPF(process)[0]
414+
410415
acceptedTagInfos = list()
411416
for btagInfo in requiredTagInfos:
412417
if hasattr(btag,btagInfo):
@@ -637,14 +642,9 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou
637642
process, task)
638643

639644

640-
641645
if 'pfBoostedDouble' in btagInfo or 'SecondaryVertex' in btagInfo:
642-
_btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
643-
if pfCandidates.value() == 'packedPFCandidates':
644-
packedPFPuppiLabel = setupPuppiForPackedPF(process)[0]
645-
_btagInfo.weights = cms.InputTag(packedPFPuppiLabel)
646-
else:
647-
_btagInfo.weights = cms.InputTag("puppi")
646+
_btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
647+
_btagInfo.weights = cms.InputTag(puppi_value_map)
648648

649649
if 'DeepFlavourTagInfos' in btagInfo:
650650
svUsed = svSource
@@ -659,10 +659,8 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou
659659
# use right input tags when running with RECO PF candidates, which actually
660660
# depends of whether jets use "particleFlow"
661661
if pfCandidates.value() == 'packedPFCandidates':
662-
puppi_value_map = setupPuppiForPackedPF(process)[0]
663662
vertex_associator = cms.InputTag("")
664663
else:
665-
puppi_value_map = cms.InputTag("puppi")
666664
vertex_associator = cms.InputTag("primaryVertexAssociation","original")
667665

668666
# 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
680678
is_weighted_jet = is_weighted_jet,
681679
flip = flip),
682680
process, task)
683-
681+
684682
if ('ParticleTransformerAK4TagInfos' in btagInfo) and ('UnifiedParticleTransformerAK4TagInfos' not in btagInfo): #We also have to veto UParT is we select ParT
685683
svUsed = svSource
686684
if btagInfo == 'pfNegativeParticleTransformerAK4TagInfos':
@@ -690,10 +688,8 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou
690688
# use right input tags when running with RECO PF candidates, which actually
691689
# depends of whether jets use "particleFlow"
692690
if pfCandidates.value() == 'packedPFCandidates':
693-
puppi_value_map = setupPuppiForPackedPF(process)[0]
694691
vertex_associator = cms.InputTag("")
695692
else:
696-
puppi_value_map = cms.InputTag("puppi")
697693
vertex_associator = cms.InputTag("primaryVertexAssociation","original")
698694

699695
# 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
722718
# use right input tags when running with RECO PF candidates, which actually
723719
# depends of whether jets use "particleFlow"
724720
if pfCandidates.value() == 'packedPFCandidates':
725-
puppi_value_map = setupPuppiForPackedPF(process)[0]
726721
vertex_associator = cms.InputTag("")
727722
else:
728-
puppi_value_map = cms.InputTag("puppi")
729723
vertex_associator = cms.InputTag("primaryVertexAssociation","original")
730724

731725
# 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
747741
# can only run on PAT jets, so the updater needs to be used
748742
if 'updated' not in jetSource.value().lower():
749743
raise ValueError("Invalid jet collection: %s. pfDeepDoubleXTagInfos only supports running via updateJetCollection." % jetSource.value())
750-
packedPFPuppiLabel = setupPuppiForPackedPF(process)[0]
751-
puppi_value_map = cms.InputTag(packedPFPuppiLabel)
752744
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
753745
btag.pfDeepDoubleXTagInfos.clone(
754746
jets = jetSource,
@@ -759,8 +751,6 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou
759751
),
760752
process, task)
761753
if btagInfo == 'pfHiggsInteractionNetTagInfos':
762-
packedPFPuppiLabel = setupPuppiForPackedPF(process)[0]
763-
puppi_value_map = cms.InputTag(packedPFPuppiLabel)
764754
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
765755
btag.pfHiggsInteractionNetTagInfos.clone(
766756
jets = jetSource,
@@ -776,14 +766,12 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou
776766
# case 1: running over jets whose daughters are PackedCandidates (only via updateJetCollection for now)
777767
if 'updated' not in jetSource.value().lower():
778768
raise ValueError("Invalid jet collection: %s. pfDeepBoostedJetTagInfos only supports running via updateJetCollection." % jetSource.value())
779-
puppi_value_map = setupPuppiForPackedPF(process)[0]
780769
vertex_associator = ""
781770
elif pfCandidates.value() == 'particleFlow':
782771
raise ValueError("Running pfDeepBoostedJetTagInfos with reco::PFCandidates is currently not supported.")
783772
# case 2: running on new jet collection whose daughters are PFCandidates (e.g., cluster jets in RECO/AOD)
784773
# daughters are the particles used in jet clustering, so already scaled by their puppi weights
785774
# Uncomment the lines below after running pfDeepBoostedJetTagInfos with reco::PFCandidates becomes supported
786-
# puppi_value_map = "puppi"
787775
# vertex_associator = "primaryVertexAssociation:original"
788776
else:
789777
raise ValueError("Invalid pfCandidates collection: %s." % pfCandidates.value())
@@ -801,12 +789,10 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou
801789
if btagInfo == 'pfParticleNetTagInfos':
802790
if pfCandidates.value() == 'packedPFCandidates':
803791
# case 1: running over jets whose daughters are PackedCandidates (only via updateJetCollection for now)
804-
puppi_value_map = setupPuppiForPackedPF(process)[0]
805792
vertex_associator = ""
806793
elif pfCandidates.value() == 'particleFlow':
807794
raise ValueError("Running pfDeepBoostedJetTagInfos with reco::PFCandidates is currently not supported.")
808795
# case 2: running on new jet collection whose daughters are PFCandidates (e.g., cluster jets in RECO/AOD)
809-
puppi_value_map = "puppi"
810796
vertex_associator = "primaryVertexAssociation:original"
811797
else:
812798
raise ValueError("Invalid pfCandidates collection: %s." % pfCandidates.value())
@@ -833,12 +819,10 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou
833819
sip3dSigMax = -1
834820
if pfCandidates.value() == 'packedPFCandidates':
835821
# case 1: running over jets whose daughters are PackedCandidates (only via updateJetCollection for now)
836-
puppi_value_map = setupPuppiForPackedPF(process)[0]
837822
vertex_associator = ""
838823
elif pfCandidates.value() == 'particleFlow':
839824
raise ValueError("Running pfDeepBoostedJetTagInfos with reco::PFCandidates is currently not supported.")
840825
# case 2: running on new jet collection whose daughters are PFCandidates (e.g., cluster jets in RECO/AOD)
841-
puppi_value_map = "puppi"
842826
vertex_associator = "primaryVertexAssociation:original"
843827
else:
844828
raise ValueError("Invalid pfCandidates collection: %s." % pfCandidates.value())
@@ -877,6 +861,7 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou
877861
vertices = pvSource,
878862
secondary_vertices = svUsed,
879863
pf_candidates = pfCandidates,
864+
puppi_value_map = puppi_value_map,
880865
flip_ip_sign = flip_ip_sign,
881866
max_sip3dsig_for_flip = max_sip3dsig_for_flip,
882867
),
@@ -892,12 +877,13 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou
892877
vertices = pvSource,
893878
secondary_vertices = svSource,
894879
pf_candidates = pfCandidates,
880+
puppi_value_map = puppi_value_map
895881
),
896882
process, task)
897883
acceptedTagInfos.append(btagInfo)
898-
elif btagInfo == 'pfParticleNetFromMiniAODAK4CHSCentralTagInfos' or btagInfo == 'pfNegativeParticleNetFromMiniAODAK4PuppiForwardTagInfos':
884+
elif btagInfo == 'pfParticleNetFromMiniAODAK4CHSCentralTagInfos' or btagInfo == 'pfNegativeParticleNetFromMiniAODAK4CHSCentralTagInfos':
899885
# ParticleNetFromMiniAOD cannot be run on RECO inputs, so need a workaround
900-
if btagInfo == 'pfNegativeParticleNetFromMiniAODAK4PuppiForwardTagInfos':
886+
if btagInfo == 'pfNegativeParticleNetFromMiniAODAK4CHSCentralTagInfos':
901887
svUsed, flip_ip_sign, max_sip3dsig_for_flip = cms.InputTag(btagPrefix+'inclusiveCandidateNegativeSecondaryVertices'+labelName+postfix), True, 10.
902888
else:
903889
svUsed, flip_ip_sign, max_sip3dsig_for_flip = svSource, False, -1.
@@ -909,6 +895,7 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou
909895
vertices = pvSource,
910896
secondary_vertices = svUsed,
911897
pf_candidates = pfCandidates,
898+
puppi_value_map = puppi_value_map,
912899
flip_ip_sign = flip_ip_sign,
913900
max_sip3dsig_for_flip = max_sip3dsig_for_flip,
914901
),
@@ -924,6 +911,7 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou
924911
vertices = pvSource,
925912
secondary_vertices = svSource,
926913
pf_candidates = pfCandidates,
914+
puppi_value_map = puppi_value_map,
927915
),
928916
process, task)
929917
acceptedTagInfos.append(btagInfo)
@@ -937,14 +925,15 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou
937925
vertices = pvSource,
938926
secondary_vertices = svSource,
939927
pf_candidates = pfCandidates,
928+
puppi_value_map = puppi_value_map,
940929
),
941930
process, task)
942931
acceptedTagInfos.append(btagInfo)
943932
else:
944933
print(' --> %s ignored, since not available via RecoBTag.Configuration.RecoBTag_cff!'%(btagInfo))
945934
# setup all required btagDiscriminators
946935
acceptedBtagDiscriminators = list()
947-
for discriminator_name in btagDiscriminators :
936+
for discriminator_name in btagDiscriminators :
948937
btagDiscr = discriminator_name.split(':')[0] #split input tag to get the producer label
949938
#print discriminator_name, '-->', btagDiscr
950939
newDiscr = btagPrefix+btagDiscr+labelName+postfix #new discriminator name

RecoBTag/FeatureTools/plugins/ParticleNetFeatureEvaluator.cc

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class ParticleNetFeatureEvaluator : public edm::stream::EDProducer<> {
6464
const double max_eta_for_taus_;
6565
const bool include_neutrals_;
6666
const bool flip_ip_sign_;
67+
const bool fallback_puppi_weight_;
68+
bool use_puppi_value_map_;
6769
const double max_sip3dsig_for_flip_;
6870

6971
edm::EDGetTokenT<pat::MuonCollection> muon_token_;
@@ -76,11 +78,13 @@ class ParticleNetFeatureEvaluator : public edm::stream::EDProducer<> {
7678
edm::EDGetTokenT<reco::VertexCompositePtrCandidateCollection> sv_token_;
7779
edm::EDGetTokenT<edm::View<reco::Candidate>> pfcand_token_;
7880
edm::ESGetToken<TransientTrackBuilder, TransientTrackRecord> track_builder_token_;
81+
edm::EDGetTokenT<edm::ValueMap<float>> puppi_value_map_token_;
7982

8083
edm::Handle<reco::VertexCollection> vtxs_;
8184
edm::Handle<reco::VertexCompositePtrCandidateCollection> svs_;
8285
edm::Handle<edm::View<reco::Candidate>> pfcands_;
8386
edm::Handle<pat::PackedCandidateCollection> losttracks_;
87+
edm::Handle<edm::ValueMap<float>> puppi_value_map_;
8488
edm::ESHandle<TransientTrackBuilder> track_builder_;
8589

8690
const static std::vector<std::string> particle_features_;
@@ -264,6 +268,8 @@ ParticleNetFeatureEvaluator::ParticleNetFeatureEvaluator(const edm::ParameterSet
264268
max_eta_for_taus_(iConfig.getParameter<double>("max_eta_for_taus")),
265269
include_neutrals_(iConfig.getParameter<bool>("include_neutrals")),
266270
flip_ip_sign_(iConfig.getParameter<bool>("flip_ip_sign")),
271+
fallback_puppi_weight_(iConfig.getParameter<bool>("fallback_puppi_weight")),
272+
use_puppi_value_map_(false),
267273
max_sip3dsig_for_flip_(iConfig.getParameter<double>("max_sip3dsig_for_flip")),
268274
muon_token_(consumes<pat::MuonCollection>(iConfig.getParameter<edm::InputTag>("muons"))),
269275
electron_token_(consumes<pat::ElectronCollection>(iConfig.getParameter<edm::InputTag>("electrons"))),
@@ -277,6 +283,11 @@ ParticleNetFeatureEvaluator::ParticleNetFeatureEvaluator(const edm::ParameterSet
277283
pfcand_token_(consumes<edm::View<reco::Candidate>>(iConfig.getParameter<edm::InputTag>("pf_candidates"))),
278284
track_builder_token_(
279285
esConsumes<TransientTrackBuilder, TransientTrackRecord>(edm::ESInputTag("", "TransientTrackBuilder"))) {
286+
const auto &puppi_value_map_tag = iConfig.getParameter<edm::InputTag>("puppi_value_map");
287+
if (!puppi_value_map_tag.label().empty()) {
288+
puppi_value_map_token_ = consumes<edm::ValueMap<float>>(puppi_value_map_tag);
289+
use_puppi_value_map_ = true;
290+
}
280291
produces<std::vector<reco::DeepBoostedJetTagInfo>>();
281292
}
282293

@@ -297,10 +308,12 @@ void ParticleNetFeatureEvaluator::fillDescriptions(edm::ConfigurationDescription
297308
desc.add<double>("max_eta_for_taus", 2.5);
298309
desc.add<bool>("include_neutrals", true);
299310
desc.add<bool>("flip_ip_sign", false);
311+
desc.add<bool>("fallback_puppi_weight", false);
300312
desc.add<double>("max_sip3dsig_for_flip", 99999);
301313
desc.add<edm::InputTag>("vertices", edm::InputTag("offlineSlimmedPrimaryVertices"));
302314
desc.add<edm::InputTag>("secondary_vertices", edm::InputTag("slimmedSecondaryVertices"));
303315
desc.add<edm::InputTag>("pf_candidates", edm::InputTag("packedPFCandidates"));
316+
desc.add<edm::InputTag>("puppi_value_map", edm::InputTag("puppi"));
304317
desc.add<edm::InputTag>("losttracks", edm::InputTag("lostTracks"));
305318
desc.add<edm::InputTag>("jets", edm::InputTag("slimmedJetsAK8"));
306319
desc.add<edm::InputTag>("muons", edm::InputTag("slimmedMuons"));
@@ -325,6 +338,11 @@ void ParticleNetFeatureEvaluator::produce(edm::Event &iEvent, const edm::EventSe
325338
auto photons = iEvent.getHandle(photon_token_);
326339
// Input lost tracks
327340
iEvent.getByToken(losttrack_token_, losttracks_);
341+
// Get puuppi value map
342+
if (use_puppi_value_map_) {
343+
iEvent.getByToken(puppi_value_map_token_, puppi_value_map_);
344+
}
345+
328346
// Primary vertexes
329347
iEvent.getByToken(vtx_token_, vtxs_);
330348
if (vtxs_->empty()) {
@@ -413,6 +431,9 @@ void ParticleNetFeatureEvaluator::fillParticleFeatures(DeepBoostedJetFeatures &f
413431
// track builder
414432
TrackInfoBuilder trackinfo(track_builder_);
415433

434+
//Save puppi weight for selected constituents in this map
435+
std::map<const pat::PackedCandidate *, float> map_pc2puppiweight;
436+
416437
// make list of pf-candidates to be considered
417438
std::vector<const pat::PackedCandidate *> daughters;
418439
for (const auto &dau : jet.daughterPtrVector()) {
@@ -428,6 +449,15 @@ void ParticleNetFeatureEvaluator::fillParticleFeatures(DeepBoostedJetFeatures &f
428449
continue;
429450
// filling daughters
430451
daughters.push_back(cand);
452+
453+
float puppiw = 1.;
454+
if (use_puppi_value_map_) {
455+
puppiw = (*puppi_value_map_)[dau];
456+
} else if (!fallback_puppi_weight_) {
457+
throw edm::Exception(edm::errors::InvalidReference, "PUPPI value map missing")
458+
<< "use fallback_puppi_weight option to use " << puppiw << " for cand as default";
459+
}
460+
map_pc2puppiweight[cand] = puppiw;
431461
}
432462

433463
// sort by original pt (not Puppi-weighted)
@@ -486,7 +516,7 @@ void ParticleNetFeatureEvaluator::fillParticleFeatures(DeepBoostedJetFeatures &f
486516
fts.fill("jet_pfcand_frompv", cand->fromPV());
487517
fts.fill("jet_pfcand_dz", ip_sign * (std::isnan(cand->dz(pv_ass_pos)) ? 0 : cand->dz(pv_ass_pos)));
488518
fts.fill("jet_pfcand_dxy", ip_sign * (std::isnan(cand->dxy(pv_ass_pos)) ? 0 : cand->dxy(pv_ass_pos)));
489-
fts.fill("jet_pfcand_puppiw", cand->puppiWeight());
519+
fts.fill("jet_pfcand_puppiw", map_pc2puppiweight[cand]);
490520
fts.fill("jet_pfcand_nlostinnerhits", cand->lostInnerHits());
491521
fts.fill("jet_pfcand_nhits", cand->numberOfHits());
492522
fts.fill("jet_pfcand_npixhits", cand->numberOfPixelHits());

RecoBTag/FeatureTools/plugins/UnifiedParticleTransformerAK4TagInfoProducer.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ void UnifiedParticleTransformerAK4TagInfoProducer::fillDescriptions(edm::Configu
171171
desc.add<bool>("fallback_puppi_weight", false);
172172
desc.add<bool>("fallback_vertex_association", false);
173173
desc.add<bool>("is_weighted_jet", false);
174-
desc.add<double>("min_jet_pt", 15.0);
174+
desc.add<double>("min_jet_pt", 0.0);
175175
desc.add<double>("max_jet_eta", 2.5);
176176
descriptions.add("pfUnifiedParticleTransformerAK4TagInfos", desc);
177177
}
@@ -225,10 +225,10 @@ void UnifiedParticleTransformerAK4TagInfoProducer::produce(edm::Event& iEvent, c
225225

226226
// reco jet reference (use as much as possible)
227227
const auto& jet = jets->at(jet_n);
228-
if (jet.pt() < 15.0) {
228+
if (jet.pt() < min_jet_pt_) {
229229
features.is_filled = false;
230230
}
231-
if (std::abs(jet.eta()) > 2.5) {
231+
if (std::abs(jet.eta()) > max_jet_eta_) {
232232
features.is_filled = false;
233233
}
234234
// dynamical casting to pointers, null if not possible

RecoBTag/ONNXRuntime/python/pfParticleNetFromMiniAODAK4_cff.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@
2626
pfParticleNetFromMiniAODAK4PuppiCentralTagInfos = ParticleNetFeatureEvaluator.clone(
2727
jets = "slimmedJetsPuppi",
2828
jet_radius = 0.4,
29-
min_jet_pt = 15,
29+
min_jet_pt = 0.,
3030
min_jet_eta = 0.,
3131
max_jet_eta = 2.5,
3232
)
3333

3434
pfParticleNetFromMiniAODAK4PuppiForwardTagInfos = ParticleNetFeatureEvaluator.clone(
3535
jets = "slimmedJetsPuppi",
3636
jet_radius = 0.4,
37-
min_jet_pt = 15,
37+
min_jet_pt = 0.,
3838
min_jet_eta = 2.5,
39-
max_jet_eta = 4.7,
39+
max_jet_eta = 5.0,
4040
)
4141

4242

0 commit comments

Comments
 (0)