Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[94X] DeepFlavour Negative Tagger #23763

Merged
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
2 changes: 1 addition & 1 deletion PhysicsTools/PatAlgos/python/tools/jetTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou
shallow_tag_infos = cms.InputTag(btagPrefix+deep_csv_tag_infos+labelName+postfix),
puppi_value_map = puppi_value_map,
vertex_associator = vertex_associator,
),
flip = flip),
process, task)

if btagInfo == 'pfDeepDoubleBTagInfos':
Expand Down
29 changes: 22 additions & 7 deletions RecoBTag/TensorFlow/interface/ChargedCandidateConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,21 @@ namespace btagbtvdeep {
const reco::Jet & jet,
const TrackInfoBuilder & track_info,
const float & drminpfcandsv, const float & jetR,
ChargedCandidateFeatures & c_pf_features) {
ChargedCandidateFeatures & c_pf_features,
const bool flip = false) {


float trackSip2dVal = track_info.getTrackSip2dVal();
float trackSip2dSig = track_info.getTrackSip2dSig();
float trackSip3dVal = track_info.getTrackSip3dVal();
float trackSip3dSig = track_info.getTrackSip3dSig();
if(flip == true){
trackSip2dVal = -trackSip2dVal;
trackSip2dSig = -trackSip2dSig;
trackSip3dSig = -trackSip3dSig;
trackSip3dVal = -trackSip3dVal;
}

c_pf_features.ptrel = catch_infs_and_bound(c_pf->pt()/jet.pt(),
0,-1,0,-1);

Expand All @@ -27,10 +40,10 @@ namespace btagbtvdeep {
c_pf_features.btagPf_trackDeltaR =catch_infs_and_bound(track_info.getTrackDeltaR(), 0,-5,5 );
c_pf_features.btagPf_trackPtRatio =catch_infs_and_bound(track_info.getTrackPtRatio(), 0,-1,10);
c_pf_features.btagPf_trackPParRatio =catch_infs_and_bound(track_info.getTrackPParRatio(),0,-10,100);
c_pf_features.btagPf_trackSip3dVal =catch_infs_and_bound(track_info.getTrackSip3dVal(), 0, -1,1e5 );
c_pf_features.btagPf_trackSip3dSig =catch_infs_and_bound(track_info.getTrackSip3dSig(), 0, -1,4e4 );
c_pf_features.btagPf_trackSip2dVal =catch_infs_and_bound(track_info.getTrackSip2dVal(), 0, -1,70 );
c_pf_features.btagPf_trackSip2dSig =catch_infs_and_bound(track_info.getTrackSip2dSig(), 0, -1,4e4 );
c_pf_features.btagPf_trackSip3dVal =catch_infs_and_bound(trackSip3dVal, 0, -1,1e5 );
c_pf_features.btagPf_trackSip3dSig =catch_infs_and_bound(trackSip3dSig, 0, -1,4e4 );
c_pf_features.btagPf_trackSip2dVal =catch_infs_and_bound(trackSip2dVal, 0, -1,70 );
c_pf_features.btagPf_trackSip2dSig =catch_infs_and_bound(trackSip2dSig, 0, -1,4e4 );
c_pf_features.btagPf_trackJetDistVal =catch_infs_and_bound(track_info.getTrackJetDistVal(),0,-20,1 );

c_pf_features.drminsv = catch_infs_and_bound(drminpfcandsv,0,-1.*jetR,0,-1.*jetR);
Expand All @@ -41,7 +54,8 @@ namespace btagbtvdeep {
const pat::Jet & jet,
const TrackInfoBuilder & track_info,
const float drminpfcandsv, const float jetR,
ChargedCandidateFeatures & c_pf_features) ;
ChargedCandidateFeatures & c_pf_features,
const bool flip = false) ;


void recoCandidateToFeatures(const reco::PFCandidate * c_pf,
Expand All @@ -50,7 +64,8 @@ namespace btagbtvdeep {
const float drminpfcandsv, const float jetR, const float puppiw,
const int pv_ass_quality,
const reco::VertexRef & pv,
ChargedCandidateFeatures & c_pf_features) ;
ChargedCandidateFeatures & c_pf_features,
const bool flip = false) ;


}
Expand Down
3 changes: 2 additions & 1 deletion RecoBTag/TensorFlow/interface/SecondaryVertexConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ namespace btagbtvdeep {

void svToFeatures( const reco::VertexCompositePtrCandidate & sv,
const reco::Vertex & pv, const reco::Jet & jet,
SecondaryVertexFeatures & sv_features) ;
SecondaryVertexFeatures & sv_features,
const bool flip = false) ;


}
Expand Down
29 changes: 20 additions & 9 deletions RecoBTag/TensorFlow/plugins/DeepFlavourTagInfoProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@

#include "RecoBTag/TensorFlow/interface/deep_helpers.h"


#include "FWCore/ParameterSet/interface/Registry.h"
#include "FWCore/Common/interface/Provenance.h"
#include "DataFormats/Provenance/interface/ProductProvenance.h"

class DeepFlavourTagInfoProducer : public edm::stream::EDProducer<> {

Expand All @@ -56,6 +58,7 @@ class DeepFlavourTagInfoProducer : public edm::stream::EDProducer<> {

const double jet_radius_;
const double min_candidate_pt_;
const bool flip_;

edm::EDGetTokenT<edm::View<reco::Jet>> jet_token_;
edm::EDGetTokenT<VertexCollection> vtx_token_;
Expand All @@ -76,6 +79,7 @@ class DeepFlavourTagInfoProducer : public edm::stream::EDProducer<> {
DeepFlavourTagInfoProducer::DeepFlavourTagInfoProducer(const edm::ParameterSet& iConfig) :
jet_radius_(iConfig.getParameter<double>("jet_radius")),
min_candidate_pt_(iConfig.getParameter<double>("min_candidate_pt")),
flip_(iConfig.getParameter<bool>("flip")),
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 @@ -114,6 +118,7 @@ void DeepFlavourTagInfoProducer::fillDescriptions(edm::ConfigurationDescriptions
desc.add<edm::InputTag>("shallow_tag_infos", edm::InputTag("pfDeepCSVTagInfos"));
desc.add<double>("jet_radius", 0.4);
desc.add<double>("min_candidate_pt", 0.95);
desc.add<bool>("flip", false);
desc.add<edm::InputTag>("vertices", edm::InputTag("offlinePrimaryVertices"));
desc.add<edm::InputTag>("puppi_value_map", edm::InputTag("puppi"));
desc.add<edm::InputTag>("secondary_vertices", edm::InputTag("inclusiveCandidateSecondaryVertices"));
Expand Down Expand Up @@ -196,6 +201,10 @@ void DeepFlavourTagInfoProducer::produce(edm::Event& iEvent, const edm::EventSet

// fill number of pv
features.npv = vtxs->size();
math::XYZVector jet_dir = jet.momentum().Unit();
GlobalVector jet_ref_track_dir(jet.px(),
jet.py(),
jet.pz());

// fill features from ShallowTagInfo
const auto & tag_info_vars = tag_info.taggingVariables();
Expand All @@ -209,20 +218,16 @@ void DeepFlavourTagInfoProducer::produce(edm::Event& iEvent, const edm::EventSet
{ return btagbtvdeep::sv_vertex_comparator(sva, svb, pv); });
// fill features from secondary vertices
for (const auto & sv : svs_sorted) {
if (reco::deltaR(sv, jet) > jet_radius_) continue;
if (reco::deltaR2(sv, jet_dir) > (jet_radius_*jet_radius_)) continue;
else {
features.sv_features.emplace_back();
// in C++17 could just get from emplace_back output
auto & sv_features = features.sv_features.back();
btagbtvdeep::svToFeatures(sv, pv, jet, sv_features);
btagbtvdeep::svToFeatures(sv, pv, jet, sv_features, flip_);
}
}

// stuff required for dealing with pf candidates
math::XYZVector jet_dir = jet.momentum().Unit();
GlobalVector jet_ref_track_dir(jet.px(),
jet.py(),
jet.pz());

std::vector<btagbtvdeep::SortingClass<size_t> > c_sorted, n_sorted;

Expand Down Expand Up @@ -269,6 +274,11 @@ void DeepFlavourTagInfoProducer::produce(edm::Event& iEvent, const edm::EventSet
features.n_pf_features.resize(n_sorted.size());


const edm::Provenance *prov = shallow_tag_infos.provenance();
const edm::ParameterSet& psetFromProvenance = edm::parameterSet(*prov);
double negative_cut = ( ( psetFromProvenance.getParameter<edm::ParameterSet>("computer")
).getParameter<edm::ParameterSet>("trackSelection")
).getParameter<double>("sip3dSigMax");

for (unsigned int i = 0; i < jet.numberOfDaughters(); i++){

Expand Down Expand Up @@ -305,12 +315,13 @@ void DeepFlavourTagInfoProducer::produce(edm::Event& iEvent, const edm::EventSet
auto entry = c_sortedindices.at(i);
// get cached track info
auto & trackinfo = trackinfos.at(i);
if(flip_ && (trackinfo.getTrackSip3dSig() > negative_cut)){continue;}
// get_ref to vector element
auto & c_pf_features = features.c_pf_features.at(entry);
// fill feature structure
if (packed_cand) {
btagbtvdeep::packedCandidateToFeatures(packed_cand, jet, trackinfo,
drminpfcandsv, static_cast<float> (jet_radius_), c_pf_features);
drminpfcandsv, static_cast<float> (jet_radius_), c_pf_features, flip_);
} else if (reco_cand) {
// get vertex association quality
int pv_ass_quality = 0; // fallback value
Expand All @@ -337,7 +348,7 @@ void DeepFlavourTagInfoProducer::produce(edm::Event& iEvent, const edm::EventSet
}
btagbtvdeep::recoCandidateToFeatures(reco_cand, jet, trackinfo,
drminpfcandsv, static_cast<float> (jet_radius_), puppiw,
pv_ass_quality, PV, c_pf_features);
pv_ass_quality, PV, c_pf_features, flip_);
}
} else {
// is neutral candidate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
from RecoBTag.TensorFlow.pfDeepFlavourTagInfos_cfi import pfDeepFlavourTagInfos

pfNegativeDeepFlavourTagInfos = pfDeepFlavourTagInfos.clone(
shallow_tag_infos = cms.InputTag('pfDeepCSVNegativeTagInfos')
)
shallow_tag_infos = 'pfDeepCSVNegativeTagInfos',
secondary_vertices = 'inclusiveCandidateNegativeSecondaryVertices',
flip = True
)
10 changes: 6 additions & 4 deletions RecoBTag/TensorFlow/src/ChargedCandidateConverter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ namespace btagbtvdeep {
const pat::Jet & jet,
const TrackInfoBuilder & track_info,
const float drminpfcandsv, const float jetR,
ChargedCandidateFeatures & c_pf_features) {
ChargedCandidateFeatures & c_pf_features,
const bool flip) {

commonCandidateToFeatures(c_pf, jet, track_info, drminpfcandsv, jetR, c_pf_features);
commonCandidateToFeatures(c_pf, jet, track_info, drminpfcandsv, jetR, c_pf_features, flip);

c_pf_features.vtx_ass = c_pf->pvAssociationQuality();

Expand All @@ -50,9 +51,10 @@ namespace btagbtvdeep {
const float drminpfcandsv, const float jetR, const float puppiw,
const int pv_ass_quality,
const reco::VertexRef & pv,
ChargedCandidateFeatures & c_pf_features) {
ChargedCandidateFeatures & c_pf_features,
const bool flip) {

commonCandidateToFeatures(c_pf, jet, track_info, drminpfcandsv, jetR, c_pf_features);
commonCandidateToFeatures(c_pf, jet, track_info, drminpfcandsv, jetR, c_pf_features, flip);

c_pf_features.vtx_ass = (float) pat::PackedCandidate::PVAssociationQuality(qualityMap[pv_ass_quality]);
if (c_pf->trackRef().isNonnull() &&
Expand Down
10 changes: 5 additions & 5 deletions RecoBTag/TensorFlow/src/SecondaryVertexConverter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ namespace btagbtvdeep {

void svToFeatures( const reco::VertexCompositePtrCandidate & sv,
const reco::Vertex & pv, const reco::Jet & jet,
SecondaryVertexFeatures & sv_features) {

SecondaryVertexFeatures & sv_features,
const bool flip) {
math::XYZVector jet_dir = jet.momentum().Unit();
sv_features.pt = sv.pt();
sv_features.deltaR = catch_infs_and_bound(
std::fabs(reco::deltaR(sv,jet))-0.5,
sv_features.deltaR = catch_infs_and_bound(std::fabs(reco::deltaR(sv, jet_dir))-0.5,
0,-2,0);
sv_features.mass = sv.mass();
sv_features.ntracks = sv.numberOfDaughters();
Expand All @@ -31,7 +31,7 @@ namespace btagbtvdeep {
sv_features.d3d = d3d_meas.value();
sv_features.d3dsig = catch_infs_and_bound(d3d_meas.value()/d3d_meas.error(),
0,-1,800);
sv_features.costhetasvpv = vertexDdotP(sv,pv);
sv_features.costhetasvpv = (flip ? -1.f : 1.f)* vertexDdotP(sv,pv);
sv_features.enratio = sv.energy()/jet.energy();

}
Expand Down