Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 16 additions & 27 deletions PhysicsTools/PatAlgos/python/tools/jetTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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':
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand Down Expand Up @@ -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,
),
Expand All @@ -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.
Expand All @@ -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,
),
Expand All @@ -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)
Expand All @@ -937,14 +925,15 @@ 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)
else:
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
Expand Down
32 changes: 31 additions & 1 deletion RecoBTag/FeatureTools/plugins/ParticleNetFeatureEvaluator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<pat::MuonCollection> muon_token_;
Expand All @@ -76,11 +78,13 @@ class ParticleNetFeatureEvaluator : public edm::stream::EDProducer<> {
edm::EDGetTokenT<reco::VertexCompositePtrCandidateCollection> sv_token_;
edm::EDGetTokenT<edm::View<reco::Candidate>> pfcand_token_;
edm::ESGetToken<TransientTrackBuilder, TransientTrackRecord> track_builder_token_;
edm::EDGetTokenT<edm::ValueMap<float>> puppi_value_map_token_;

edm::Handle<reco::VertexCollection> vtxs_;
edm::Handle<reco::VertexCompositePtrCandidateCollection> svs_;
edm::Handle<edm::View<reco::Candidate>> pfcands_;
edm::Handle<pat::PackedCandidateCollection> losttracks_;
edm::Handle<edm::ValueMap<float>> puppi_value_map_;
edm::ESHandle<TransientTrackBuilder> track_builder_;

const static std::vector<std::string> particle_features_;
Expand Down Expand Up @@ -264,6 +268,8 @@ ParticleNetFeatureEvaluator::ParticleNetFeatureEvaluator(const edm::ParameterSet
max_eta_for_taus_(iConfig.getParameter<double>("max_eta_for_taus")),
include_neutrals_(iConfig.getParameter<bool>("include_neutrals")),
flip_ip_sign_(iConfig.getParameter<bool>("flip_ip_sign")),
fallback_puppi_weight_(iConfig.getParameter<bool>("fallback_puppi_weight")),
use_puppi_value_map_(false),
max_sip3dsig_for_flip_(iConfig.getParameter<double>("max_sip3dsig_for_flip")),
muon_token_(consumes<pat::MuonCollection>(iConfig.getParameter<edm::InputTag>("muons"))),
electron_token_(consumes<pat::ElectronCollection>(iConfig.getParameter<edm::InputTag>("electrons"))),
Expand All @@ -277,6 +283,11 @@ ParticleNetFeatureEvaluator::ParticleNetFeatureEvaluator(const edm::ParameterSet
pfcand_token_(consumes<edm::View<reco::Candidate>>(iConfig.getParameter<edm::InputTag>("pf_candidates"))),
track_builder_token_(
esConsumes<TransientTrackBuilder, TransientTrackRecord>(edm::ESInputTag("", "TransientTrackBuilder"))) {
const auto &puppi_value_map_tag = iConfig.getParameter<edm::InputTag>("puppi_value_map");
if (!puppi_value_map_tag.label().empty()) {
puppi_value_map_token_ = consumes<edm::ValueMap<float>>(puppi_value_map_tag);
use_puppi_value_map_ = true;
}
produces<std::vector<reco::DeepBoostedJetTagInfo>>();
}

Expand All @@ -297,10 +308,12 @@ void ParticleNetFeatureEvaluator::fillDescriptions(edm::ConfigurationDescription
desc.add<double>("max_eta_for_taus", 2.5);
desc.add<bool>("include_neutrals", true);
desc.add<bool>("flip_ip_sign", false);
desc.add<bool>("fallback_puppi_weight", false);
desc.add<double>("max_sip3dsig_for_flip", 99999);
desc.add<edm::InputTag>("vertices", edm::InputTag("offlineSlimmedPrimaryVertices"));
desc.add<edm::InputTag>("secondary_vertices", edm::InputTag("slimmedSecondaryVertices"));
desc.add<edm::InputTag>("pf_candidates", edm::InputTag("packedPFCandidates"));
desc.add<edm::InputTag>("puppi_value_map", edm::InputTag("puppi"));
desc.add<edm::InputTag>("losttracks", edm::InputTag("lostTracks"));
desc.add<edm::InputTag>("jets", edm::InputTag("slimmedJetsAK8"));
desc.add<edm::InputTag>("muons", edm::InputTag("slimmedMuons"));
Expand All @@ -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()) {
Expand Down Expand Up @@ -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<const pat::PackedCandidate *, float> map_pc2puppiweight;

// make list of pf-candidates to be considered
std::vector<const pat::PackedCandidate *> daughters;
for (const auto &dau : jet.daughterPtrVector()) {
Expand All @@ -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)
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void UnifiedParticleTransformerAK4TagInfoProducer::fillDescriptions(edm::Configu
desc.add<bool>("fallback_puppi_weight", false);
desc.add<bool>("fallback_vertex_association", false);
desc.add<bool>("is_weighted_jet", false);
desc.add<double>("min_jet_pt", 15.0);
desc.add<double>("min_jet_pt", 0.0);
desc.add<double>("max_jet_eta", 2.5);
descriptions.add("pfUnifiedParticleTransformerAK4TagInfos", desc);
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@
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,
)

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,
)


Expand Down