Skip to content

Commit

Permalink
Merge pull request #23467 from emilbols/CMSSW_10_2_X_NegativeTagger
Browse files Browse the repository at this point in the history
DeepFlavour Negative Tagger + DeepFlavour 10X training
  • Loading branch information
cmsbuild authored Jun 11, 2018
2 parents 9953083 + b626752 commit c45eeb5
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 30 deletions.
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
4 changes: 2 additions & 2 deletions RecoBTag/TensorFlow/plugins/DeepFlavourTFJetTagsProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ void DeepFlavourTFJetTagsProducer::fillDescriptions(edm::ConfigurationDescriptio
desc.add<std::vector<std::string>>("input_names",
{ "input_1", "input_2", "input_3", "input_4", "input_5" });
desc.add<edm::FileInPath>("graph_path",
edm::FileInPath("RecoBTag/Combined/data/DeepFlavourV01_GraphDef_PtCut/constant_graph.pb"));
edm::FileInPath("RecoBTag/Combined/data/DeepFlavourV03_10X_training/constant_graph.pb"));
desc.add<std::vector<std::string>>("lp_names",
{ "globals_input_batchnorm/keras_learning_phase" });
{ "cpf_input_batchnorm/keras_learning_phase" });
desc.add<std::vector<std::string>>("output_names",
{ "ID_pred/Softmax", "regression_pred/BiasAdd" });
{
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.position() - pv.position(), flip_ ? -jet_dir : 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
9 changes: 5 additions & 4 deletions RecoBTag/TensorFlow/src/SecondaryVertexConverter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ 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.position() - pv.position(), flip ? -jet_dir : jet_dir))-0.5,
0,-2,0);
sv_features.mass = sv.mass();
sv_features.ntracks = sv.numberOfDaughters();
Expand All @@ -31,7 +32,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

0 comments on commit c45eeb5

Please sign in to comment.