Skip to content

Commit

Permalink
Merge TagInfo producers.
Browse files Browse the repository at this point in the history
  • Loading branch information
hqucms committed Mar 5, 2020
1 parent d1af63d commit 3c9ce7f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 428 deletions.
64 changes: 40 additions & 24 deletions RecoBTag/FeatureTools/plugins/DeepBoostedJetTagInfoProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class DeepBoostedJetTagInfoProducer : public edm::stream::EDProducer<> {
const double jet_radius_;
const double min_jet_pt_;
const double min_pt_for_track_properties_;
const bool use_puppiP4_;

edm::EDGetTokenT<edm::View<reco::Jet>> jet_token_;
edm::EDGetTokenT<VertexCollection> vtx_token_;
Expand Down Expand Up @@ -83,10 +84,13 @@ const std::vector<std::string> DeepBoostedJetTagInfoProducer::particle_features_
"pfcand_dphidphi", "pfcand_dxydxy", "pfcand_dzdz", "pfcand_dxydz",
"pfcand_dphidxy", "pfcand_dlambdadz", "pfcand_btagEtaRel", "pfcand_btagPtRatio",
"pfcand_btagPParRatio", "pfcand_btagSip2dVal", "pfcand_btagSip2dSig", "pfcand_btagSip3dVal",
"pfcand_btagSip3dSig", "pfcand_btagJetDistVal",
"pfcand_btagSip3dSig", "pfcand_btagJetDistVal", "pfcand_mask", "pfcand_pt_log_nopuppi",
"pfcand_e_log_nopuppi"

};

const std::vector<std::string> DeepBoostedJetTagInfoProducer::sv_features_{
"sv_mask",
"sv_phirel",
"sv_etarel",
"sv_deltaR",
Expand All @@ -108,6 +112,7 @@ DeepBoostedJetTagInfoProducer::DeepBoostedJetTagInfoProducer(const edm::Paramete
: jet_radius_(iConfig.getParameter<double>("jet_radius")),
min_jet_pt_(iConfig.getParameter<double>("min_jet_pt")),
min_pt_for_track_properties_(iConfig.getParameter<double>("min_pt_for_track_properties")),
use_puppiP4_(iConfig.getParameter<bool>("use_puppiP4")),
jet_token_(consumes<edm::View<reco::Jet>>(iConfig.getParameter<edm::InputTag>("jets"))),
vtx_token_(consumes<VertexCollection>(iConfig.getParameter<edm::InputTag>("vertices"))),
sv_token_(consumes<SVCollection>(iConfig.getParameter<edm::InputTag>("secondary_vertices"))),
Expand Down Expand Up @@ -138,6 +143,7 @@ void DeepBoostedJetTagInfoProducer::fillDescriptions(edm::ConfigurationDescripti
desc.add<double>("jet_radius", 0.8);
desc.add<double>("min_jet_pt", 150);
desc.add<double>("min_pt_for_track_properties", -1);
desc.add<bool>("use_puppiP4", true);
desc.add<edm::InputTag>("vertices", edm::InputTag("offlinePrimaryVertices"));
desc.add<edm::InputTag>("secondary_vertices", edm::InputTag("inclusiveCandidateSecondaryVertices"));
desc.add<edm::InputTag>("pf_candidates", edm::InputTag("particleFlow"));
Expand All @@ -150,8 +156,7 @@ void DeepBoostedJetTagInfoProducer::fillDescriptions(edm::ConfigurationDescripti
void DeepBoostedJetTagInfoProducer::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) {
auto output_tag_infos = std::make_unique<DeepBoostedJetTagInfoCollection>();

edm::Handle<edm::View<reco::Jet>> jets;
iEvent.getByToken(jet_token_, jets);
auto jets = iEvent.getHandle(jet_token_);

iEvent.getByToken(vtx_token_, vtxs_);
if (vtxs_->empty()) {
Expand Down Expand Up @@ -259,11 +264,17 @@ void DeepBoostedJetTagInfoProducer::fillParticleFeatures(DeepBoostedJetFeatures
// 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();
});
if (use_puppiP4_) {
// 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();
});
} else {
// sort by original pt (not Puppi-weighted)
std::sort(daughters.begin(), daughters.end(), [](const auto &a, const auto &b) { return a->pt() > b->pt(); });
}

// reserve space
for (const auto &name : particle_features_) {
Expand All @@ -279,7 +290,7 @@ void DeepBoostedJetTagInfoProducer::fillParticleFeatures(DeepBoostedJetFeatures
const auto *packed_cand = dynamic_cast<const pat::PackedCandidate *>(&(*cand));
const auto *reco_cand = dynamic_cast<const reco::PFCandidate *>(&(*cand));

auto puppiP4 = puppi_wgt_cache.at(cand.key()) * cand->p4();
auto candP4 = use_puppiP4_ ? puppi_wgt_cache.at(cand.key()) * cand->p4() : cand->p4();
if (packed_cand) {
float hcal_fraction = 0.;
if (packed_cand->pdgId() == 1 || packed_cand->pdgId() == 130) {
Expand Down Expand Up @@ -343,14 +354,18 @@ void DeepBoostedJetTagInfoProducer::fillParticleFeatures(DeepBoostedJetFeatures

// basic kinematics
fts.fill("pfcand_puppiw", puppi_wgt_cache.at(cand.key()));
fts.fill("pfcand_phirel", reco::deltaPhi(puppiP4, jet));
fts.fill("pfcand_etarel", etasign * (puppiP4.eta() - jet.eta()));
fts.fill("pfcand_deltaR", reco::deltaR(puppiP4, jet));
fts.fill("pfcand_abseta", std::abs(puppiP4.eta()));
fts.fill("pfcand_phirel", reco::deltaPhi(candP4, jet));
fts.fill("pfcand_etarel", etasign * (candP4.eta() - jet.eta()));
fts.fill("pfcand_deltaR", reco::deltaR(candP4, jet));
fts.fill("pfcand_abseta", std::abs(candP4.eta()));

fts.fill("pfcand_ptrel_log", catch_infs(std::log(candP4.pt() / jet.pt()), -99));
fts.fill("pfcand_erel_log", catch_infs(std::log(candP4.energy() / jet.energy()), -99));
fts.fill("pfcand_pt_log", catch_infs(std::log(candP4.pt()), -99));

fts.fill("pfcand_ptrel_log", catch_infs(std::log(puppiP4.pt() / jet.pt()), -99));
fts.fill("pfcand_erel_log", catch_infs(std::log(puppiP4.energy() / jet.energy()), -99));
fts.fill("pfcand_pt_log", catch_infs(std::log(puppiP4.pt()), -99));
fts.fill("pfcand_mask", 1);
fts.fill("pfcand_pt_log_nopuppi", catch_infs(std::log(cand->pt()), -99));
fts.fill("pfcand_e_log_nopuppi", catch_infs(std::log(cand->energy()), -99));

double minDR = 999;
for (const auto &sv : *svs_) {
Expand Down Expand Up @@ -390,14 +405,14 @@ void DeepBoostedJetTagInfoProducer::fillParticleFeatures(DeepBoostedJetFeatures

TrackInfoBuilder trkinfo(track_builder_);
trkinfo.buildTrackInfo(&(*cand), jet_dir, jet_ref_track_dir, *pv_);
fts.fill("pfcand_btagEtaRel", trkinfo.getTrackEtaRel());
fts.fill("pfcand_btagPtRatio", trkinfo.getTrackPtRatio());
fts.fill("pfcand_btagPParRatio", trkinfo.getTrackPParRatio());
fts.fill("pfcand_btagSip2dVal", trkinfo.getTrackSip2dVal());
fts.fill("pfcand_btagSip2dSig", trkinfo.getTrackSip2dSig());
fts.fill("pfcand_btagSip3dVal", trkinfo.getTrackSip3dVal());
fts.fill("pfcand_btagSip3dSig", trkinfo.getTrackSip3dSig());
fts.fill("pfcand_btagJetDistVal", trkinfo.getTrackJetDistVal());
fts.fill("pfcand_btagEtaRel", catch_infs(trkinfo.getTrackEtaRel()));
fts.fill("pfcand_btagPtRatio", catch_infs(trkinfo.getTrackPtRatio()));
fts.fill("pfcand_btagPParRatio", catch_infs(trkinfo.getTrackPParRatio()));
fts.fill("pfcand_btagSip2dVal", catch_infs(trkinfo.getTrackSip2dVal()));
fts.fill("pfcand_btagSip2dSig", catch_infs(trkinfo.getTrackSip2dSig()));
fts.fill("pfcand_btagSip3dVal", catch_infs(trkinfo.getTrackSip3dVal()));
fts.fill("pfcand_btagSip3dSig", catch_infs(trkinfo.getTrackSip3dSig()));
fts.fill("pfcand_btagJetDistVal", catch_infs(trkinfo.getTrackJetDistVal()));
} else {
fts.fill("pfcand_normchi2", 999);

Expand Down Expand Up @@ -445,6 +460,7 @@ void DeepBoostedJetTagInfoProducer::fillSVFeatures(DeepBoostedJetFeatures &fts,

for (const auto *sv : jetSVs) {
// basic kinematics
fts.fill("sv_mask", 1);
fts.fill("sv_phirel", reco::deltaPhi(*sv, jet));
fts.fill("sv_etarel", etasign * (sv->eta() - jet.eta()));
fts.fill("sv_deltaR", reco::deltaR(*sv, jet));
Expand Down
Loading

0 comments on commit 3c9ce7f

Please sign in to comment.