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

[9_4_X] DeepDoubleCvL and DeepDoubleCvB tagger integration #25371

Merged
merged 12 commits into from Jan 9, 2019
15 changes: 0 additions & 15 deletions DataFormats/BTauReco/interface/DeepDoubleBTagInfo.h

This file was deleted.

@@ -1,5 +1,5 @@
#ifndef DataFormats_BTauReco_DeepDoubleBFeatures_h
#define DataFormats_BTauReco_DeepDoubleBFeatures_h
#ifndef DataFormats_BTauReco_DeepDoubleXFeatures_h
#define DataFormats_BTauReco_DeepDoubleXFeatures_h

#include <vector>

Expand All @@ -10,9 +10,18 @@

namespace btagbtvdeep {

class DeepDoubleBFeatures {
class DeepDoubleXFeatures {

public:

bool empty() const {
return is_empty_;
}

void filled(){
is_empty_ = false;
}

JetFeatures jet_features;
BoostedDoubleSVTagInfoFeatures tag_info_features;

Expand All @@ -21,9 +30,12 @@ class DeepDoubleBFeatures {
std::vector<ChargedCandidateFeatures> c_pf_features;

std::size_t npv; // used by deep flavour
};

private:
bool is_empty_ = true;

};

}

#endif //DataFormats_BTauReco_DeepDoubleBFeatures_h
#endif //DataFormats_BTauReco_DeepDoubleXFeatures_h
15 changes: 15 additions & 0 deletions DataFormats/BTauReco/interface/DeepDoubleXTagInfo.h
@@ -0,0 +1,15 @@
#ifndef DataFormats_BTauReco_DeepDoubleXTagInfo_h
#define DataFormats_BTauReco_DeepDoubleXTagInfo_h

#include "DataFormats/BTauReco/interface/FeaturesTagInfo.h"
#include "DataFormats/BTauReco/interface/DeepDoubleXFeatures.h"

namespace reco {

typedef FeaturesTagInfo<btagbtvdeep::DeepDoubleXFeatures> DeepDoubleXTagInfo;

DECLARE_EDM_REFS( DeepDoubleXTagInfo )

}

#endif // DataFormats_BTauReco_DeepDoubleXTagInfo_h
23 changes: 12 additions & 11 deletions DataFormats/BTauReco/src/classes.h
Expand Up @@ -54,11 +54,12 @@
#include "DataFormats/BTauReco/interface/ChargedCandidateFeatures.h"
#include "DataFormats/BTauReco/interface/DeepFlavourFeatures.h"
#include "DataFormats/BTauReco/interface/DeepFlavourTagInfo.h"
#include "DataFormats/BTauReco/interface/DeepDoubleBFeatures.h"
#include "DataFormats/BTauReco/interface/DeepDoubleBTagInfo.h"
#include "DataFormats/BTauReco/interface/DeepDoubleXFeatures.h"
#include "DataFormats/BTauReco/interface/DeepDoubleXTagInfo.h"
#include "DataFormats/BTauReco/interface/DeepBoostedJetTagInfo.h"



namespace reco {
typedef TrackTauImpactParameterAssociationCollection::map_type TrackTauImpactParameterAssociationMapType;
typedef TrackTauImpactParameterAssociationCollection::ref_type TrackTauImpactParameterAssociationRefType;
Expand Down Expand Up @@ -419,15 +420,15 @@ namespace DataFormats_BTauReco {
edm::Wrapper<reco::DeepFlavourTagInfoCollection> deep_flavour_tag_info_collection_edm_wrapper;

btagbtvdeep::BoostedDoubleSVTagInfoFeatures boosted_double_sv_tag_info_features;
btagbtvdeep::DeepDoubleBFeatures deep_doubleb_features;
reco::DeepDoubleBTagInfo deep_doubleb_tag_info;
reco::DeepDoubleBTagInfoCollection deep_doubleb_tag_info_collection;
reco::DeepDoubleBTagInfoRef deep_doubleb_tag_info_collection_ref;
reco::DeepDoubleBTagInfoFwdRef deep_doubleb_tag_info_collection_fwd_ref;
reco::DeepDoubleBTagInfoRefProd deep_doubleb_tag_info_collection_ref_prod;
reco::DeepDoubleBTagInfoRefVector deep_doubleb_tag_info_collection_ref_vector;
edm::Wrapper<reco::DeepDoubleBTagInfoCollection> deep_doubleb_tag_info_collection_edm_wrapper;

btagbtvdeep::DeepDoubleXFeatures deep_doublex_features;
reco::DeepDoubleXTagInfo deep_doublex_tag_info;
reco::DeepDoubleXTagInfoCollection deep_doublex_tag_info_collection;
reco::DeepDoubleXTagInfoRef deep_doublex_tag_info_collection_ref;
reco::DeepDoubleXTagInfoFwdRef deep_doublex_tag_info_collection_fwd_ref;
reco::DeepDoubleXTagInfoRefProd deep_doublex_tag_info_collection_ref_prod;
reco::DeepDoubleXTagInfoRefVector deep_doublex_tag_info_collection_ref_vector;
edm::Wrapper<reco::DeepDoubleXTagInfoCollection> deep_doublex_tag_info_collection_edm_wrapper;
btagbtvdeep::DeepBoostedJetFeatures deep_boosted_jet_tag_info_features;
reco::DeepBoostedJetTagInfo deep_boosted_jet_tag_info;
reco::DeepBoostedJetTagInfoCollection deep_boosted_jet_tag_info_collection;
Expand Down
22 changes: 11 additions & 11 deletions DataFormats/BTauReco/src/classes_def.xml
Expand Up @@ -447,8 +447,8 @@
<class name="btagbtvdeep::DeepFlavourFeatures" ClassVersion="3">
<version ClassVersion="3" checksum="2487956635"/>
</class>
<class name="btagbtvdeep::DeepDoubleBFeatures" ClassVersion="3">
<version ClassVersion="3" checksum="2060552560"/>
<class name="btagbtvdeep::DeepDoubleXFeatures" ClassVersion="3">
<version ClassVersion="3" checksum="1764960743"/>
</class>
<class name="btagbtvdeep::BoostedDoubleSVTagInfoFeatures" ClassVersion="3">
<version ClassVersion="3" checksum="683471882"/>
Expand All @@ -462,15 +462,15 @@
<class name="reco::DeepFlavourTagInfoRefProd"/>
<class name="reco::DeepFlavourTagInfoRefVector"/>
<class name="edm::Wrapper<reco::DeepFlavourTagInfoCollection>"/>

<class name="reco::DeepDoubleBTagInfo"/>
<class name="reco::DeepDoubleBTagInfoCollection"/>
<class name="reco::DeepDoubleBTagInfoRef"/>
<class name="reco::DeepDoubleBTagInfoFwdRef"/>
<class name="reco::DeepDoubleBTagInfoRefProd"/>
<class name="reco::DeepDoubleBTagInfoRefVector"/>
<class name="edm::Wrapper<reco::DeepDoubleBTagInfoCollection>"/>

<class name="reco::DeepDoubleXTagInfo"/>
<class name="reco::DeepDoubleXTagInfoCollection"/>
<class name="reco::DeepDoubleXTagInfoRef"/>
<class name="reco::DeepDoubleXTagInfoFwdRef"/>
<class name="reco::DeepDoubleXTagInfoRefProd"/>
<class name="reco::DeepDoubleXTagInfoRefVector"/>
<class name="edm::Wrapper<reco::DeepDoubleXTagInfoCollection>"/>
<class name="btagbtvdeep::DeepBoostedJetFeatures"/>
<class name="reco::DeepBoostedJetTagInfo"/>
<class name="reco::DeepBoostedJetTagInfoCollection"/>
Expand Down
21 changes: 17 additions & 4 deletions PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py
Expand Up @@ -41,8 +41,9 @@
# DeepFlavour tag infos
, 'pfDeepFlavourTagInfos'
, 'pfNegativeDeepFlavourTagInfos'
# DeepDoubleB tag infos
, 'pfDeepDoubleBTagInfos'
# DeepDoubleB/C tag infos
, 'pfDeepDoubleXTagInfos'
, 'pfDeepDoubleXTagInfosNopt'
# DeepBoostedJet tag infos
, 'pfDeepBoostedJetTagInfos'
]
Expand Down Expand Up @@ -189,8 +190,20 @@
, 'pfNegativeDeepFlavourJetTags:probc' : [["pfNegativeDeepFlavourTagInfos"], ['pfDeepCSVNegativeTagInfos', "pfImpactParameterTagInfos", 'pfInclusiveSecondaryVertexFinderNegativeTagInfos']]
, 'pfNegativeDeepFlavourJetTags:probuds' : [["pfNegativeDeepFlavourTagInfos"], ['pfDeepCSVNegativeTagInfos', "pfImpactParameterTagInfos", 'pfInclusiveSecondaryVertexFinderNegativeTagInfos']]
, 'pfNegativeDeepFlavourJetTags:probg' : [["pfNegativeDeepFlavourTagInfos"], ['pfDeepCSVNegativeTagInfos', "pfImpactParameterTagInfos", 'pfInclusiveSecondaryVertexFinderNegativeTagInfos']]
, 'pfDeepDoubleBJetTags:probQ' : [["pfDeepDoubleBTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']]
, 'pfDeepDoubleBJetTags:probH' : [["pfDeepDoubleBTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']]
, 'pfDeepDoubleBJetTags:probQ' : [["pfDeepDoubleXTagInfosNopt"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']]
, 'pfDeepDoubleBJetTags:probH' : [["pfDeepDoubleXTagInfosNopt"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']]
, 'pfDeepDoubleBvLJetTags:probQCD' : [["pfDeepDoubleXTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']]
, 'pfDeepDoubleBvLJetTags:probHbb' : [["pfDeepDoubleXTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']]
, 'pfDeepDoubleCvLJetTags:probQCD' : [["pfDeepDoubleXTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']]
, 'pfDeepDoubleCvLJetTags:probHcc' : [["pfDeepDoubleXTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']]
, 'pfDeepDoubleCvBJetTags:probHbb' : [["pfDeepDoubleXTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']]
, 'pfDeepDoubleCvBJetTags:probHcc' : [["pfDeepDoubleXTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']]
, 'pfMassIndependentDeepDoubleBvLJetTags:probQCD' : [["pfDeepDoubleXTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']]
, 'pfMassIndependentDeepDoubleBvLJetTags:probHbb' : [["pfDeepDoubleXTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']]
, 'pfMassIndependentDeepDoubleCvLJetTags:probQCD' : [["pfDeepDoubleXTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']]
, 'pfMassIndependentDeepDoubleCvLJetTags:probHcc' : [["pfDeepDoubleXTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']]
, 'pfMassIndependentDeepDoubleCvBJetTags:probHbb' : [["pfDeepDoubleXTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']]
, 'pfMassIndependentDeepDoubleCvBJetTags:probHcc' : [["pfDeepDoubleXTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']]
}

# meta-taggers are simple arithmetic on top of other taggers, they are stored here
Expand Down
14 changes: 13 additions & 1 deletion PhysicsTools/PatAlgos/python/slimming/applyDeepBtagging_cff.py
Expand Up @@ -64,10 +64,22 @@ def applyDeepBtagging( process, postfix="" ) :
btagDiscriminators = [
'pfDeepDoubleBJetTags:probQ',
'pfDeepDoubleBJetTags:probH',
'pfDeepDoubleBvLJetTags:probQCD',
'pfDeepDoubleBvLJetTags:probHbb',
'pfDeepDoubleCvLJetTags:probQCD',
'pfDeepDoubleCvLJetTags:probHcc',
'pfDeepDoubleCvBJetTags:probHbb',
'pfDeepDoubleCvBJetTags:probHcc',
'pfMassIndependentDeepDoubleBvLJetTags:probQCD',
'pfMassIndependentDeepDoubleBvLJetTags:probHbb',
'pfMassIndependentDeepDoubleCvLJetTags:probQCD',
'pfMassIndependentDeepDoubleCvLJetTags:probHcc',
'pfMassIndependentDeepDoubleCvBJetTags:probHbb',
'pfMassIndependentDeepDoubleCvBJetTags:probHcc',
] + pfDeepBoostedJetTagsAll,
postfix = 'SlimmedAK8DeepTags' + postfix,
printWarning = False
)
)

# slimmedJetsAK8 with DeepTags (remove DeepTags-less)
delattr(process, 'slimmedJetsAK8')
Expand Down
14 changes: 12 additions & 2 deletions PhysicsTools/PatAlgos/python/tools/jetTools.py
Expand Up @@ -620,9 +620,19 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou
flip = flip),
process, task)

if btagInfo == 'pfDeepDoubleBTagInfos':
if btagInfo == 'pfDeepDoubleXTagInfos':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.pfDeepDoubleBTagInfos.clone(
btag.pfDeepDoubleXTagInfos.clone(
jets = jetSource,
vertices=pvSource,
secondary_vertices=svSource,
shallow_tag_infos = cms.InputTag(btagPrefix+'pfBoostedDoubleSVAK8TagInfos'+labelName+postfix),
),
process, task)

if btagInfo == 'pfDeepDoubleXTagInfosNopt':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.pfDeepDoubleXTagInfosNopt.clone(
jets = jetSource,
vertices=pvSource,
secondary_vertices=svSource,
Expand Down
1 change: 1 addition & 0 deletions RecoBTag/Configuration/python/RecoBTag_cff.py
Expand Up @@ -8,6 +8,7 @@
from RecoBTag.CTagging.RecoCTagging_cff import *
from RecoBTag.Combined.deepFlavour_cff import *
from RecoBTag.TensorFlow.pfDeepFlavour_cff import *
from RecoBTag.TensorFlow.pfDeepDoubleX_cff import *
from RecoBTag.MXNet.pfDeepBoostedJet_cff import *
from RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff import *

Expand Down
Expand Up @@ -18,8 +18,8 @@
#include "TrackingTools/Records/interface/TransientTrackRecord.h"
#include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h"

#include "DataFormats/BTauReco/interface/DeepDoubleBFeatures.h"
#include "DataFormats/BTauReco/interface/DeepDoubleBTagInfo.h"
#include "DataFormats/BTauReco/interface/DeepDoubleXFeatures.h"
#include "DataFormats/BTauReco/interface/DeepDoubleXTagInfo.h"

#include "RecoBTag/FeatureTools/interface/BoostedDoubleSVTagInfoConverter.h"
#include "RecoBTag/FeatureTools/interface/ChargedCandidateConverter.h"
Expand All @@ -34,17 +34,17 @@

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

class DeepDoubleBTagInfoProducer : public edm::stream::EDProducer<>
class DeepDoubleXTagInfoProducer : public edm::stream::EDProducer<>
{

public:
explicit DeepDoubleBTagInfoProducer(const edm::ParameterSet&);
~DeepDoubleBTagInfoProducer() override;
explicit DeepDoubleXTagInfoProducer(const edm::ParameterSet&);
~DeepDoubleXTagInfoProducer() override;

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

private:
typedef std::vector<reco::DeepDoubleBTagInfo> DeepDoubleBTagInfoCollection;
typedef std::vector<reco::DeepDoubleXTagInfo> DeepDoubleXTagInfoCollection;
typedef reco::VertexCompositePtrCandidateCollection SVCollection;
typedef reco::VertexCollection VertexCollection;
typedef edm::View<reco::BoostedDoubleSVTagInfo>
Expand All @@ -59,6 +59,7 @@ class DeepDoubleBTagInfoProducer : public edm::stream::EDProducer<>
}

const double jet_radius_;
const double min_jet_pt_;
const double min_candidate_pt_;

edm::EDGetTokenT<edm::View<reco::Jet>> jet_token_;
Expand All @@ -67,9 +68,10 @@ class DeepDoubleBTagInfoProducer : public edm::stream::EDProducer<>
edm::EDGetTokenT<BoostedDoubleSVTagInfoCollection> shallow_tag_info_token_;
};

DeepDoubleBTagInfoProducer::DeepDoubleBTagInfoProducer(
DeepDoubleXTagInfoProducer::DeepDoubleXTagInfoProducer(
const edm::ParameterSet& iConfig)
: jet_radius_(iConfig.getParameter<double>("jet_radius"))
, min_jet_pt_(iConfig.getParameter<double>("min_jet_pt"))
, min_candidate_pt_(iConfig.getParameter<double>("min_candidate_pt"))
, jet_token_(consumes<edm::View<reco::Jet>>(
iConfig.getParameter<edm::InputTag>("jets")))
Expand All @@ -80,34 +82,35 @@ DeepDoubleBTagInfoProducer::DeepDoubleBTagInfoProducer(
, shallow_tag_info_token_(consumes<BoostedDoubleSVTagInfoCollection>(
iConfig.getParameter<edm::InputTag>("shallow_tag_infos")))
{
produces<DeepDoubleBTagInfoCollection>();
produces<DeepDoubleXTagInfoCollection>();
}

DeepDoubleBTagInfoProducer::~DeepDoubleBTagInfoProducer()
DeepDoubleXTagInfoProducer::~DeepDoubleXTagInfoProducer()
{
}

void DeepDoubleBTagInfoProducer::fillDescriptions(
void DeepDoubleXTagInfoProducer::fillDescriptions(
edm::ConfigurationDescriptions& descriptions)
{
// pfDeepDoubleBTagInfos
// pfDeepDoubleXTagInfos
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("shallow_tag_infos",
edm::InputTag("pfBoostedDoubleSVAK8TagInfos"));
desc.add<double>("jet_radius", 0.8);
desc.add<double>("min_jet_pt", 150);
desc.add<double>("min_candidate_pt", 0.95);
desc.add<edm::InputTag>("vertices", edm::InputTag("offlinePrimaryVertices"));
desc.add<edm::InputTag>("secondary_vertices",
edm::InputTag("inclusiveCandidateSecondaryVertices"));
desc.add<edm::InputTag>("jets", edm::InputTag("ak8PFJetsCHS"));
descriptions.add("pfDeepDoubleBTagInfos", desc);
descriptions.add("pfDeepDoubleXTagInfos", desc);
}

void DeepDoubleBTagInfoProducer::produce(edm::Event& iEvent,
void DeepDoubleXTagInfoProducer::produce(edm::Event& iEvent,
const edm::EventSetup& iSetup)
{

auto output_tag_infos = std::make_unique<DeepDoubleBTagInfoCollection>();
auto output_tag_infos = std::make_unique<DeepDoubleXTagInfoCollection>();

edm::Handle<edm::View<reco::Jet>> jets;
iEvent.getByToken(jet_token_, jets);
Expand Down Expand Up @@ -137,11 +140,15 @@ void DeepDoubleBTagInfoProducer::produce(edm::Event& iEvent,
{

// create data containing structure
btagbtvdeep::DeepDoubleBFeatures features;
btagbtvdeep::DeepDoubleXFeatures features;

// reco jet reference (use as much as possible)
const auto& jet = jets->at(jet_n);

edm::RefToBase<reco::Jet> jet_ref(jets, jet_n);
if (jet.pt() > min_jet_pt_)
{
features.filled();
// TagInfoCollection not in an associative container so search for matchs
const edm::View<reco::BoostedDoubleSVTagInfo>& taginfos = *shallow_tag_infos;
edm::Ptr<reco::BoostedDoubleSVTagInfo> match;
Expand Down Expand Up @@ -338,12 +345,12 @@ void DeepDoubleBTagInfoProducer::produce(edm::Event& iEvent,
}
}
}

}
output_tag_infos->emplace_back(features, jet_ref);
}

iEvent.put(std::move(output_tag_infos));
}

// define this as a plug-in
DEFINE_FWK_MODULE(DeepDoubleBTagInfoProducer);
DEFINE_FWK_MODULE(DeepDoubleXTagInfoProducer);
7 changes: 7 additions & 0 deletions RecoBTag/FeatureTools/python/pfDeepDoubleXTagInfosNopt_cfi.py
@@ -0,0 +1,7 @@
import FWCore.ParameterSet.Config as cms

from pfDeepDoubleXTagInfos_cfi import pfDeepDoubleXTagInfos

pfDeepDoubleXTagInfosNopt = pfDeepDoubleXTagInfos.clone(
min_jet_pt = 0
)
10 changes: 4 additions & 6 deletions RecoBTag/TensorFlow/interface/tensor_fillers.h
Expand Up @@ -3,9 +3,7 @@

#include "PhysicsTools/TensorFlow/interface/TensorFlow.h"
#include "DataFormats/BTauReco/interface/DeepFlavourTagInfo.h"
#include "DataFormats/BTauReco/interface/DeepDoubleBTagInfo.h"


#include "DataFormats/BTauReco/interface/DeepDoubleXTagInfo.h"

namespace btagbtvdeep {

Expand All @@ -23,9 +21,9 @@ namespace btagbtvdeep {

void db_tensor_filler(tensorflow::Tensor & tensor,
std::size_t jet_n,
const btagbtvdeep::DeepDoubleBFeatures & features) ;


const btagbtvdeep::DeepDoubleXFeatures & features) ;
void c_pf_tensor_filler(tensorflow::Tensor & tensor,
std::size_t jet_n,
std::size_t c_pf_n,
Expand Down