From 217ee7c8f97571f72506fc1c9743344294a9d7f4 Mon Sep 17 00:00:00 2001 From: anovak10 Date: Tue, 16 Oct 2018 17:39:14 +0200 Subject: [PATCH 01/30] WIP 10X --- .../interface/DeepDoubleCvBFeatures.h | 29 ++ .../BTauReco/interface/DeepDoubleCvBTagInfo.h | 19 + .../interface/DeepDoubleCvLFeatures.h | 29 ++ .../BTauReco/interface/DeepDoubleCvLTagInfo.h | 19 + DataFormats/BTauReco/src/classes.h | 24 +- DataFormats/BTauReco/src/classes_def.xml | 24 +- .../python/recoLayer0/bTagging_cff.py | 12 +- .../python/slimming/applyDeepBtagging_cff.py | 4 + .../PatAlgos/python/tools/jetTools.py | 20 + .../plugins/DeepDoubleCvBTagInfoProducer.cc | 349 ++++++++++++++++++ .../plugins/DeepDoubleCvLTagInfoProducer.cc | 349 ++++++++++++++++++ .../TensorFlow/interface/tensor_fillers.h | 11 +- .../plugins/DeepDoubleCvBTFJetTagsProducer.cc | 292 +++++++++++++++ .../plugins/DeepDoubleCvBTagInfoProducer.cc | 349 ++++++++++++++++++ .../plugins/DeepDoubleCvLTFJetTagsProducer.cc | 292 +++++++++++++++ .../plugins/DeepDoubleCvLTagInfoProducer.cc | 349 ++++++++++++++++++ .../TensorFlow/python/pfDeepFlavour_cff.py | 5 +- RecoBTag/TensorFlow/src/tensor_fillers.cc | 78 ++++ .../TensorFlow/test/test_deep_doublec_cfg.py | 90 +++++ 19 files changed, 2337 insertions(+), 7 deletions(-) create mode 100644 DataFormats/BTauReco/interface/DeepDoubleCvBFeatures.h create mode 100644 DataFormats/BTauReco/interface/DeepDoubleCvBTagInfo.h create mode 100644 DataFormats/BTauReco/interface/DeepDoubleCvLFeatures.h create mode 100644 DataFormats/BTauReco/interface/DeepDoubleCvLTagInfo.h create mode 100644 RecoBTag/FeatureTools/plugins/DeepDoubleCvBTagInfoProducer.cc create mode 100644 RecoBTag/FeatureTools/plugins/DeepDoubleCvLTagInfoProducer.cc create mode 100644 RecoBTag/TensorFlow/plugins/DeepDoubleCvBTFJetTagsProducer.cc create mode 100644 RecoBTag/TensorFlow/plugins/DeepDoubleCvBTagInfoProducer.cc create mode 100644 RecoBTag/TensorFlow/plugins/DeepDoubleCvLTFJetTagsProducer.cc create mode 100644 RecoBTag/TensorFlow/plugins/DeepDoubleCvLTagInfoProducer.cc create mode 100644 RecoBTag/TensorFlow/test/test_deep_doublec_cfg.py diff --git a/DataFormats/BTauReco/interface/DeepDoubleCvBFeatures.h b/DataFormats/BTauReco/interface/DeepDoubleCvBFeatures.h new file mode 100644 index 0000000000000..741829659bbc6 --- /dev/null +++ b/DataFormats/BTauReco/interface/DeepDoubleCvBFeatures.h @@ -0,0 +1,29 @@ +#ifndef DataFormats_BTauReco_DeepDoubleCvBFeatures_h +#define DataFormats_BTauReco_DeepDoubleCvBFeatures_h + +#include + +#include "DataFormats/BTauReco/interface/JetFeatures.h" +#include "DataFormats/BTauReco/interface/SecondaryVertexFeatures.h" +#include "DataFormats/BTauReco/interface/BoostedDoubleSVTagInfoFeatures.h" +#include "DataFormats/BTauReco/interface/ChargedCandidateFeatures.h" + +namespace btagbtvdeep { + +class DeepDoubleCvBFeatures { + + public: + JetFeatures jet_features; + BoostedDoubleSVTagInfoFeatures tag_info_features; + + std::vector sv_features; + + std::vector c_pf_features; + + std::size_t npv; // used by deep flavour +}; + + +} + +#endif //DataFormats_BTauReco_DeepDoubleCvBFeatures_h diff --git a/DataFormats/BTauReco/interface/DeepDoubleCvBTagInfo.h b/DataFormats/BTauReco/interface/DeepDoubleCvBTagInfo.h new file mode 100644 index 0000000000000..f4fcde11b51bf --- /dev/null +++ b/DataFormats/BTauReco/interface/DeepDoubleCvBTagInfo.h @@ -0,0 +1,19 @@ +#ifndef DataFormats_BTauReco_DeepDoubleCvBTagInfo_h +#define DataFormats_BTauReco_DeepDoubleCvBTagInfo_h + +#include "DataFormats/Common/interface/CMS_CLASS_VERSION.h" +#include "DataFormats/BTauReco/interface/BaseTagInfo.h" +#include "DataFormats/BTauReco/interface/DeepFlavourTagInfo.h" +#include "DataFormats/BTauReco/interface/DeepDoubleCvBFeatures.h" + +#include "DataFormats/PatCandidates/interface/Jet.h" + +namespace reco { + +typedef FeaturesTagInfo DeepDoubleCvBTagInfo; + +DECLARE_EDM_REFS( DeepDoubleCvBTagInfo ) + +} + +#endif // DataFormats_BTauReco_DeepDoubleCvBTagInfo_h diff --git a/DataFormats/BTauReco/interface/DeepDoubleCvLFeatures.h b/DataFormats/BTauReco/interface/DeepDoubleCvLFeatures.h new file mode 100644 index 0000000000000..1c008534b088f --- /dev/null +++ b/DataFormats/BTauReco/interface/DeepDoubleCvLFeatures.h @@ -0,0 +1,29 @@ +#ifndef DataFormats_BTauReco_DeepDoubleCvLFeatures_h +#define DataFormats_BTauReco_DeepDoubleCvLFeatures_h + +#include + +#include "DataFormats/BTauReco/interface/JetFeatures.h" +#include "DataFormats/BTauReco/interface/SecondaryVertexFeatures.h" +#include "DataFormats/BTauReco/interface/BoostedDoubleSVTagInfoFeatures.h" +#include "DataFormats/BTauReco/interface/ChargedCandidateFeatures.h" + +namespace btagbtvdeep { + +class DeepDoubleCvLFeatures { + + public: + JetFeatures jet_features; + BoostedDoubleSVTagInfoFeatures tag_info_features; + + std::vector sv_features; + + std::vector c_pf_features; + + std::size_t npv; // used by deep flavour +}; + + +} + +#endif //DataFormats_BTauReco_DeepDoubleCvLFeatures_h diff --git a/DataFormats/BTauReco/interface/DeepDoubleCvLTagInfo.h b/DataFormats/BTauReco/interface/DeepDoubleCvLTagInfo.h new file mode 100644 index 0000000000000..2aaef32888040 --- /dev/null +++ b/DataFormats/BTauReco/interface/DeepDoubleCvLTagInfo.h @@ -0,0 +1,19 @@ +#ifndef DataFormats_BTauReco_DeepDoubleCvLTagInfo_h +#define DataFormats_BTauReco_DeepDoubleCvLTagInfo_h + +#include "DataFormats/Common/interface/CMS_CLASS_VERSION.h" +#include "DataFormats/BTauReco/interface/BaseTagInfo.h" +#include "DataFormats/BTauReco/interface/DeepFlavourTagInfo.h" +#include "DataFormats/BTauReco/interface/DeepDoubleCvLFeatures.h" + +#include "DataFormats/PatCandidates/interface/Jet.h" + +namespace reco { + +typedef FeaturesTagInfo DeepDoubleCvLTagInfo; + +DECLARE_EDM_REFS( DeepDoubleCvLTagInfo ) + +} + +#endif // DataFormats_BTauReco_DeepDoubleCvLTagInfo_h diff --git a/DataFormats/BTauReco/src/classes.h b/DataFormats/BTauReco/src/classes.h index 2d35f90389e99..9c8b6a36b4192 100755 --- a/DataFormats/BTauReco/src/classes.h +++ b/DataFormats/BTauReco/src/classes.h @@ -56,6 +56,10 @@ #include "DataFormats/BTauReco/interface/DeepFlavourTagInfo.h" #include "DataFormats/BTauReco/interface/DeepDoubleBFeatures.h" #include "DataFormats/BTauReco/interface/DeepDoubleBTagInfo.h" +#include "DataFormats/BTauReco/interface/DeepDoubleCvLFeatures.h" +#include "DataFormats/BTauReco/interface/DeepDoubleCvLTagInfo.h" +#include "DataFormats/BTauReco/interface/DeepDoubleCvBFeatures.h" +#include "DataFormats/BTauReco/interface/DeepDoubleCvBTagInfo.h" #include "DataFormats/BTauReco/interface/DeepBoostedJetTagInfo.h" @@ -427,7 +431,25 @@ namespace DataFormats_BTauReco { reco::DeepDoubleBTagInfoRefProd deep_doubleb_tag_info_collection_ref_prod; reco::DeepDoubleBTagInfoRefVector deep_doubleb_tag_info_collection_ref_vector; edm::Wrapper deep_doubleb_tag_info_collection_edm_wrapper; - + + btagbtvdeep::DeepDoubleCvLFeatures deep_doublecvl_features; + reco::DeepDoubleCvLTagInfo deep_doublecvl_tag_info; + reco::DeepDoubleCvLTagInfoCollection deep_doublecvl_tag_info_collection; + reco::DeepDoubleCvLTagInfoRef deep_doublecvl_tag_info_collection_ref; + reco::DeepDoubleCvLTagInfoFwdRef deep_doublecvl_tag_info_collection_fwd_ref; + reco::DeepDoubleCvLTagInfoRefProd deep_doublecvl_tag_info_collection_ref_prod; + reco::DeepDoubleCvLTagInfoRefVector deep_doublecvl_tag_info_collection_ref_vector; + edm::Wrapper deep_doublecvl_tag_info_collection_edm_wrapper; + + btagbtvdeep::DeepDoubleCvBFeatures deep_doublecvb_features; + reco::DeepDoubleCvBTagInfo deep_doublecvb_tag_info; + reco::DeepDoubleCvBTagInfoCollection deep_doublecvb_tag_info_collection; + reco::DeepDoubleCvBTagInfoRef deep_doublecvb_tag_info_collection_ref; + reco::DeepDoubleCvBTagInfoFwdRef deep_doublecvb_tag_info_collection_fwd_ref; + reco::DeepDoubleCvBTagInfoRefProd deep_doublecvb_tag_info_collection_ref_prod; + reco::DeepDoubleCvBTagInfoRefVector deep_doublecvb_tag_info_collection_ref_vector; + edm::Wrapper deep_doublecvb_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; diff --git a/DataFormats/BTauReco/src/classes_def.xml b/DataFormats/BTauReco/src/classes_def.xml index 38ae4a5b9ad72..35fb567cc514a 100644 --- a/DataFormats/BTauReco/src/classes_def.xml +++ b/DataFormats/BTauReco/src/classes_def.xml @@ -450,6 +450,12 @@ + + + + + + @@ -470,7 +476,23 @@ - + + + + + + + + + + + + + + + + + diff --git a/PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py b/PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py index d8a42f9dc32b0..22596a39777b7 100644 --- a/PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py +++ b/PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py @@ -43,6 +43,10 @@ , 'pfNegativeDeepFlavourTagInfos' # DeepDoubleB tag infos , 'pfDeepDoubleBTagInfos' + # DeepDoubleCvL tag infos + , 'pfDeepDoubleCvLTagInfos' + # DeepDoubleCvB tag infos + , 'pfDeepDoubleCvBTagInfos' # DeepBoostedJet tag infos , 'pfDeepBoostedJetTagInfos' ] @@ -189,8 +193,12 @@ , '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' : [["pfDeepDoubleBTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']] + , 'pfDeepDoubleBJetTags:probH' : [["pfDeepDoubleBTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']] + , 'pfDeepDoubleCvLJetTags:probQCD' : [["pfDeepDoubleCvLTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']] + , 'pfDeepDoubleCvLJetTags:probHcc' : [["pfDeepDoubleCvLTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']] + , 'pfDeepDoubleCvBJetTags:probHbb' : [["pfDeepDoubleCvBTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']] + , 'pfDeepDoubleCvBJetTags:probHcc' : [["pfDeepDoubleCvBTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']] } # meta-taggers are simple arithmetic on top of other taggers, they are stored here diff --git a/PhysicsTools/PatAlgos/python/slimming/applyDeepBtagging_cff.py b/PhysicsTools/PatAlgos/python/slimming/applyDeepBtagging_cff.py index 5eb06b01e120b..0dd11924dd490 100644 --- a/PhysicsTools/PatAlgos/python/slimming/applyDeepBtagging_cff.py +++ b/PhysicsTools/PatAlgos/python/slimming/applyDeepBtagging_cff.py @@ -62,6 +62,10 @@ def applyDeepBtagging( process, postfix="" ) : btagDiscriminators = [ 'pfDeepDoubleBJetTags:probQ', 'pfDeepDoubleBJetTags:probH', + 'pfDeepDoubleCvLJetTags:probQCD', + 'pfDeepDoubleCvLJetTags:probHcc', + 'pfDeepDoubleCvBJetTags:probHbb', + 'pfDeepDoubleCvBJetTags:probHcc', ] + pfDeepBoostedJetTagsAll, postfix = 'SlimmedAK8DeepTags'+postfix, printWarning = False diff --git a/PhysicsTools/PatAlgos/python/tools/jetTools.py b/PhysicsTools/PatAlgos/python/tools/jetTools.py index 102e75b9c60d0..6037c662b1b4b 100644 --- a/PhysicsTools/PatAlgos/python/tools/jetTools.py +++ b/PhysicsTools/PatAlgos/python/tools/jetTools.py @@ -631,6 +631,26 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou ), process, task) + if btagInfo == 'pfDeepDoubleCvLTagInfos': + addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix, + btag.pfDeepDoubleCvLTagInfos.clone( + jets = jetSource, + vertices=pvSource, + secondary_vertices=svSource, + shallow_tag_infos = cms.InputTag(btagPrefix+'pfBoostedDoubleSVAK8TagInfos'+labelName+postfix), + ), + process, task) + + if btagInfo == 'pfDeepDoubleCvBTagInfos': + addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix, + btag.pfDeepDoubleCvBTagInfos.clone( + jets = jetSource, + vertices=pvSource, + secondary_vertices=svSource, + shallow_tag_infos = cms.InputTag(btagPrefix+'pfBoostedDoubleSVAK8TagInfos'+labelName+postfix), + ), + process, task) + if btagInfo == 'pfDeepBoostedJetTagInfos': if pfCandidates.value() == 'packedPFCandidates': # case 1: running over jets whose daughters are PackedCandidates (only via updateJetCollection for now) diff --git a/RecoBTag/FeatureTools/plugins/DeepDoubleCvBTagInfoProducer.cc b/RecoBTag/FeatureTools/plugins/DeepDoubleCvBTagInfoProducer.cc new file mode 100644 index 0000000000000..c65928356b7af --- /dev/null +++ b/RecoBTag/FeatureTools/plugins/DeepDoubleCvBTagInfoProducer.cc @@ -0,0 +1,349 @@ + +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/StreamID.h" + +#include "DataFormats/Candidate/interface/Candidate.h" + +#include "DataFormats/PatCandidates/interface/Jet.h" +#include "DataFormats/PatCandidates/interface/PackedCandidate.h" + +#include "DataFormats/BTauReco/interface/BoostedDoubleSVTagInfo.h" + +#include "TrackingTools/Records/interface/TransientTrackRecord.h" +#include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h" + +#include "DataFormats/BTauReco/interface/DeepDoubleCvBFeatures.h" +#include "DataFormats/BTauReco/interface/DeepDoubleCvBTagInfo.h" + +#include "RecoBTag/FeatureTools/interface/BoostedDoubleSVTagInfoConverter.h" +#include "RecoBTag/FeatureTools/interface/ChargedCandidateConverter.h" +#include "RecoBTag/FeatureTools/interface/JetConverter.h" +#include "RecoBTag/FeatureTools/interface/SecondaryVertexConverter.h" + +#include "RecoBTag/FeatureTools/interface/TrackInfoBuilder.h" +#include "RecoBTag/FeatureTools/interface/sorting_modules.h" + +#include "DataFormats/Candidate/interface/VertexCompositePtrCandidate.h" +#include "DataFormats/VertexReco/interface/VertexFwd.h" + +#include "RecoBTag/FeatureTools/interface/deep_helpers.h" + +class DeepDoubleCvBTagInfoProducer : public edm::stream::EDProducer<> +{ + +public: + explicit DeepDoubleCvBTagInfoProducer(const edm::ParameterSet&); + ~DeepDoubleCvBTagInfoProducer() override; + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + +private: + typedef std::vector DeepDoubleCvBTagInfoCollection; + typedef reco::VertexCompositePtrCandidateCollection SVCollection; + typedef reco::VertexCollection VertexCollection; + typedef edm::View + BoostedDoubleSVTagInfoCollection; + + void beginStream(edm::StreamID) override + { + } + void produce(edm::Event&, const edm::EventSetup&) override; + void endStream() override + { + } + + const double jet_radius_; + const double min_candidate_pt_; + + edm::EDGetTokenT> jet_token_; + edm::EDGetTokenT vtx_token_; + edm::EDGetTokenT sv_token_; + edm::EDGetTokenT shallow_tag_info_token_; +}; + +DeepDoubleCvBTagInfoProducer::DeepDoubleCvBTagInfoProducer( + const edm::ParameterSet& iConfig) + : jet_radius_(iConfig.getParameter("jet_radius")) + , min_candidate_pt_(iConfig.getParameter("min_candidate_pt")) + , jet_token_(consumes>( + iConfig.getParameter("jets"))) + , vtx_token_(consumes( + iConfig.getParameter("vertices"))) + , sv_token_(consumes( + iConfig.getParameter("secondary_vertices"))) + , shallow_tag_info_token_(consumes( + iConfig.getParameter("shallow_tag_infos"))) +{ + produces(); +} + +DeepDoubleCvBTagInfoProducer::~DeepDoubleCvBTagInfoProducer() +{ +} + +void DeepDoubleCvBTagInfoProducer::fillDescriptions( + edm::ConfigurationDescriptions& descriptions) +{ + // pfDeepDoubleCvBTagInfos + edm::ParameterSetDescription desc; + desc.add("shallow_tag_infos", + edm::InputTag("pfBoostedDoubleSVAK8TagInfos")); + desc.add("jet_radius", 0.8); + desc.add("min_candidate_pt", 0.95); + desc.add("vertices", edm::InputTag("offlinePrimaryVertices")); + desc.add("secondary_vertices", + edm::InputTag("inclusiveCandidateSecondaryVertices")); + desc.add("jets", edm::InputTag("ak8PFJetsCHS")); + descriptions.add("pfDeepDoubleCvBTagInfos", desc); +} + +void DeepDoubleCvBTagInfoProducer::produce(edm::Event& iEvent, + const edm::EventSetup& iSetup) +{ + + auto output_tag_infos = std::make_unique(); + + edm::Handle> jets; + iEvent.getByToken(jet_token_, jets); + + edm::Handle vtxs; + iEvent.getByToken(vtx_token_, vtxs); + if (vtxs->empty()) + { + // produce empty TagInfos in case no primary vertex + iEvent.put(std::move(output_tag_infos)); + return; // exit event + } + // reference to primary vertex + const auto& pv = vtxs->at(0); + + edm::Handle svs; + iEvent.getByToken(sv_token_, svs); + + edm::Handle shallow_tag_infos; + iEvent.getByToken(shallow_tag_info_token_, shallow_tag_infos); + + edm::ESHandle track_builder; + iSetup.get().get("TransientTrackBuilder", + track_builder); + + for (std::size_t jet_n = 0; jet_n < jets->size(); jet_n++) + { + + // create data containing structure + btagbtvdeep::DeepDoubleCvBFeatures features; + + // reco jet reference (use as much as possible) + const auto& jet = jets->at(jet_n); + edm::RefToBase jet_ref(jets, jet_n); + // TagInfoCollection not in an associative container so search for matchs + const edm::View& taginfos = *shallow_tag_infos; + edm::Ptr match; + // Try first by 'same index' + if ((jet_n < taginfos.size()) && (taginfos[jet_n].jet() == jet_ref)) + { + match = taginfos.ptrAt(jet_n); + } + else + { + // otherwise fall back to a simple search + for (auto itTI = taginfos.begin(), edTI = taginfos.end(); itTI != edTI; + ++itTI) + { + if (itTI->jet() == jet_ref) + { + match = taginfos.ptrAt(itTI - taginfos.begin()); + break; + } + } + } + reco::BoostedDoubleSVTagInfo tag_info; + if (match.isNonnull()) + { + tag_info = *match; + } // will be default values otherwise + + // fill basic jet features + btagbtvdeep::JetConverter::jetToFeatures(jet, features.jet_features); + + // fill number of pv + features.npv = vtxs->size(); + + // fill features from BoostedDoubleSVTagInfo + const auto& tag_info_vars = tag_info.taggingVariables(); + btagbtvdeep::doubleBTagToFeatures(tag_info_vars, + features.tag_info_features); + + // copy which will be sorted + auto svs_sorted = *svs; + // sort by dxy + std::sort(svs_sorted.begin(), svs_sorted.end(), + [&pv](const auto& sva, const auto& svb) { + 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; + 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); + } + } + + // 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> c_sorted; + + // to cache the TrackInfo + std::map trackinfos; + + // unsorted reference to sv + const auto& svs_unsorted = *svs; + // fill collection, from DeepTNtuples plus some styling + // std::vector daughters; + std::vector daughters; + for (unsigned int i = 0; i < jet.numberOfDaughters(); i++) + { + auto const* cand = jet.daughter(i); + auto packed_cand = dynamic_cast(cand); + auto reco_cand = dynamic_cast(cand); + if (packed_cand) + { + if (cand->numberOfDaughters() > 0) + { + for (unsigned int k = 0; k < cand->numberOfDaughters(); k++) + { + daughters.push_back( + dynamic_cast(cand->daughter(k))); + } + } + else + { + auto packed_cand = dynamic_cast(cand); + daughters.push_back(packed_cand); + } + } + else if (reco_cand) + { + // need some edm::Ptr or edm::Ref if reco candidates + // dynamical casting to pointers, null if not possible + daughters.push_back(reco_cand); + } + } + + for (unsigned int i = 0; i < daughters.size(); i++) + { + auto const* cand = daughters.at(i); + + if (cand) + { + // candidates under 950MeV (configurable) are not considered + // might change if we use also white-listing + if (cand->pt() < min_candidate_pt_) + continue; + if (cand->charge() != 0) + { + auto& trackinfo = trackinfos.emplace(i, track_builder).first->second; + trackinfo.buildTrackInfo(cand, jet_dir, jet_ref_track_dir, pv); + c_sorted.emplace_back( + i, trackinfo.getTrackSip2dSig(), + -btagbtvdeep::mindrsvpfcand(svs_unsorted, cand, jet_radius_), + cand->pt() / jet.pt()); + } + } + } + + // sort collections (open the black-box if you please) + std::sort(c_sorted.begin(), c_sorted.end(), + btagbtvdeep::SortingClass::compareByABCInv); + + std::vector c_sortedindices; + + // this puts 0 everywhere and the right position in ind + c_sortedindices = btagbtvdeep::invertSortingVector(c_sorted); + + // set right size to vectors + features.c_pf_features.clear(); + features.c_pf_features.resize(c_sorted.size()); + + for (unsigned int i = 0; i < daughters.size(); i++) + { + auto const* cand = daughters.at(i); + if (cand) + { + // candidates under 950MeV are not considered + // might change if we use also white-listing + if (cand->pt() < 0.95) + continue; + + // get PUPPI weight from value map + float puppiw = 1.0; // fallback value + + float drminpfcandsv = btagbtvdeep::mindrsvpfcand(svs_unsorted, cand, jet_radius_); + + if (cand->charge() != 0) + { + // is charged candidate + auto entry = c_sortedindices.at(i); + // get cached track info + auto& trackinfo = trackinfos.at(i); + // get_ref to vector element + auto& c_pf_features = features.c_pf_features.at(entry); + // fill feature structure + auto packed_cand = dynamic_cast(cand); + auto reco_cand = dynamic_cast(cand); + if (packed_cand) + { + btagbtvdeep::packedCandidateToFeatures( + packed_cand, jet, trackinfo, drminpfcandsv, + static_cast(jet_radius_), c_pf_features); + } + else if (reco_cand) + { + // get vertex association quality + int pv_ass_quality = 0; // fallback value + // getting the PV as PackedCandidatesProducer + // but using not the slimmed but original vertices + auto ctrack = reco_cand->bestTrack(); + int pvi = -1; + float dist = 1e99; + for (size_t ii = 0; ii < vtxs->size(); ii++) + { + float dz = (ctrack) ? std::abs(ctrack->dz(((*vtxs)[ii]).position())) : 0; + if (dz < dist) + { + pvi = ii; + dist = dz; + } + } + auto pv = reco::VertexRef(vtxs, pvi); + btagbtvdeep::recoCandidateToFeatures( + reco_cand, jet, trackinfo, drminpfcandsv, + static_cast(jet_radius_), puppiw, pv_ass_quality, pv, + c_pf_features); + } + } + } + } + + output_tag_infos->emplace_back(features, jet_ref); + } + + iEvent.put(std::move(output_tag_infos)); +} + +// define this as a plug-in +DEFINE_FWK_MODULE(DeepDoubleCvBTagInfoProducer); diff --git a/RecoBTag/FeatureTools/plugins/DeepDoubleCvLTagInfoProducer.cc b/RecoBTag/FeatureTools/plugins/DeepDoubleCvLTagInfoProducer.cc new file mode 100644 index 0000000000000..2d6a9699a0a12 --- /dev/null +++ b/RecoBTag/FeatureTools/plugins/DeepDoubleCvLTagInfoProducer.cc @@ -0,0 +1,349 @@ + +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/StreamID.h" + +#include "DataFormats/Candidate/interface/Candidate.h" + +#include "DataFormats/PatCandidates/interface/Jet.h" +#include "DataFormats/PatCandidates/interface/PackedCandidate.h" + +#include "DataFormats/BTauReco/interface/BoostedDoubleSVTagInfo.h" + +#include "TrackingTools/Records/interface/TransientTrackRecord.h" +#include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h" + +#include "DataFormats/BTauReco/interface/DeepDoubleCvLFeatures.h" +#include "DataFormats/BTauReco/interface/DeepDoubleCvLTagInfo.h" + +#include "RecoBTag/FeatureTools/interface/BoostedDoubleSVTagInfoConverter.h" +#include "RecoBTag/FeatureTools/interface/ChargedCandidateConverter.h" +#include "RecoBTag/FeatureTools/interface/JetConverter.h" +#include "RecoBTag/FeatureTools/interface/SecondaryVertexConverter.h" + +#include "RecoBTag/FeatureTools/interface/TrackInfoBuilder.h" +#include "RecoBTag/FeatureTools/interface/sorting_modules.h" + +#include "DataFormats/Candidate/interface/VertexCompositePtrCandidate.h" +#include "DataFormats/VertexReco/interface/VertexFwd.h" + +#include "RecoBTag/FeatureTools/interface/deep_helpers.h" + +class DeepDoubleCvLTagInfoProducer : public edm::stream::EDProducer<> +{ + +public: + explicit DeepDoubleCvLTagInfoProducer(const edm::ParameterSet&); + ~DeepDoubleCvLTagInfoProducer() override; + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + +private: + typedef std::vector DeepDoubleCvLTagInfoCollection; + typedef reco::VertexCompositePtrCandidateCollection SVCollection; + typedef reco::VertexCollection VertexCollection; + typedef edm::View + BoostedDoubleSVTagInfoCollection; + + void beginStream(edm::StreamID) override + { + } + void produce(edm::Event&, const edm::EventSetup&) override; + void endStream() override + { + } + + const double jet_radius_; + const double min_candidate_pt_; + + edm::EDGetTokenT> jet_token_; + edm::EDGetTokenT vtx_token_; + edm::EDGetTokenT sv_token_; + edm::EDGetTokenT shallow_tag_info_token_; +}; + +DeepDoubleCvLTagInfoProducer::DeepDoubleCvLTagInfoProducer( + const edm::ParameterSet& iConfig) + : jet_radius_(iConfig.getParameter("jet_radius")) + , min_candidate_pt_(iConfig.getParameter("min_candidate_pt")) + , jet_token_(consumes>( + iConfig.getParameter("jets"))) + , vtx_token_(consumes( + iConfig.getParameter("vertices"))) + , sv_token_(consumes( + iConfig.getParameter("secondary_vertices"))) + , shallow_tag_info_token_(consumes( + iConfig.getParameter("shallow_tag_infos"))) +{ + produces(); +} + +DeepDoubleCvLTagInfoProducer::~DeepDoubleCvLTagInfoProducer() +{ +} + +void DeepDoubleCvLTagInfoProducer::fillDescriptions( + edm::ConfigurationDescriptions& descriptions) +{ + // pfDeepDoubleCvLTagInfos + edm::ParameterSetDescription desc; + desc.add("shallow_tag_infos", + edm::InputTag("pfBoostedDoubleSVAK8TagInfos")); + desc.add("jet_radius", 0.8); + desc.add("min_candidate_pt", 0.95); + desc.add("vertices", edm::InputTag("offlinePrimaryVertices")); + desc.add("secondary_vertices", + edm::InputTag("inclusiveCandidateSecondaryVertices")); + desc.add("jets", edm::InputTag("ak8PFJetsCHS")); + descriptions.add("pfDeepDoubleCvLTagInfos", desc); +} + +void DeepDoubleCvLTagInfoProducer::produce(edm::Event& iEvent, + const edm::EventSetup& iSetup) +{ + + auto output_tag_infos = std::make_unique(); + + edm::Handle> jets; + iEvent.getByToken(jet_token_, jets); + + edm::Handle vtxs; + iEvent.getByToken(vtx_token_, vtxs); + if (vtxs->empty()) + { + // produce empty TagInfos in case no primary vertex + iEvent.put(std::move(output_tag_infos)); + return; // exit event + } + // reference to primary vertex + const auto& pv = vtxs->at(0); + + edm::Handle svs; + iEvent.getByToken(sv_token_, svs); + + edm::Handle shallow_tag_infos; + iEvent.getByToken(shallow_tag_info_token_, shallow_tag_infos); + + edm::ESHandle track_builder; + iSetup.get().get("TransientTrackBuilder", + track_builder); + + for (std::size_t jet_n = 0; jet_n < jets->size(); jet_n++) + { + + // create data containing structure + btagbtvdeep::DeepDoubleCvLFeatures features; + + // reco jet reference (use as much as possible) + const auto& jet = jets->at(jet_n); + edm::RefToBase jet_ref(jets, jet_n); + // TagInfoCollection not in an associative container so search for matchs + const edm::View& taginfos = *shallow_tag_infos; + edm::Ptr match; + // Try first by 'same index' + if ((jet_n < taginfos.size()) && (taginfos[jet_n].jet() == jet_ref)) + { + match = taginfos.ptrAt(jet_n); + } + else + { + // otherwise fall back to a simple search + for (auto itTI = taginfos.begin(), edTI = taginfos.end(); itTI != edTI; + ++itTI) + { + if (itTI->jet() == jet_ref) + { + match = taginfos.ptrAt(itTI - taginfos.begin()); + break; + } + } + } + reco::BoostedDoubleSVTagInfo tag_info; + if (match.isNonnull()) + { + tag_info = *match; + } // will be default values otherwise + + // fill basic jet features + btagbtvdeep::JetConverter::jetToFeatures(jet, features.jet_features); + + // fill number of pv + features.npv = vtxs->size(); + + // fill features from BoostedDoubleSVTagInfo + const auto& tag_info_vars = tag_info.taggingVariables(); + btagbtvdeep::doubleBTagToFeatures(tag_info_vars, + features.tag_info_features); + + // copy which will be sorted + auto svs_sorted = *svs; + // sort by dxy + std::sort(svs_sorted.begin(), svs_sorted.end(), + [&pv](const auto& sva, const auto& svb) { + 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; + 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); + } + } + + // 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> c_sorted; + + // to cache the TrackInfo + std::map trackinfos; + + // unsorted reference to sv + const auto& svs_unsorted = *svs; + // fill collection, from DeepTNtuples plus some styling + // std::vector daughters; + std::vector daughters; + for (unsigned int i = 0; i < jet.numberOfDaughters(); i++) + { + auto const* cand = jet.daughter(i); + auto packed_cand = dynamic_cast(cand); + auto reco_cand = dynamic_cast(cand); + if (packed_cand) + { + if (cand->numberOfDaughters() > 0) + { + for (unsigned int k = 0; k < cand->numberOfDaughters(); k++) + { + daughters.push_back( + dynamic_cast(cand->daughter(k))); + } + } + else + { + auto packed_cand = dynamic_cast(cand); + daughters.push_back(packed_cand); + } + } + else if (reco_cand) + { + // need some edm::Ptr or edm::Ref if reco candidates + // dynamical casting to pointers, null if not possible + daughters.push_back(reco_cand); + } + } + + for (unsigned int i = 0; i < daughters.size(); i++) + { + auto const* cand = daughters.at(i); + + if (cand) + { + // candidates under 950MeV (configurable) are not considered + // might change if we use also white-listing + if (cand->pt() < min_candidate_pt_) + continue; + if (cand->charge() != 0) + { + auto& trackinfo = trackinfos.emplace(i, track_builder).first->second; + trackinfo.buildTrackInfo(cand, jet_dir, jet_ref_track_dir, pv); + c_sorted.emplace_back( + i, trackinfo.getTrackSip2dSig(), + -btagbtvdeep::mindrsvpfcand(svs_unsorted, cand, jet_radius_), + cand->pt() / jet.pt()); + } + } + } + + // sort collections (open the black-box if you please) + std::sort(c_sorted.begin(), c_sorted.end(), + btagbtvdeep::SortingClass::compareByABCInv); + + std::vector c_sortedindices; + + // this puts 0 everywhere and the right position in ind + c_sortedindices = btagbtvdeep::invertSortingVector(c_sorted); + + // set right size to vectors + features.c_pf_features.clear(); + features.c_pf_features.resize(c_sorted.size()); + + for (unsigned int i = 0; i < daughters.size(); i++) + { + auto const* cand = daughters.at(i); + if (cand) + { + // candidates under 950MeV are not considered + // might change if we use also white-listing + if (cand->pt() < 0.95) + continue; + + // get PUPPI weight from value map + float puppiw = 1.0; // fallback value + + float drminpfcandsv = btagbtvdeep::mindrsvpfcand(svs_unsorted, cand, jet_radius_); + + if (cand->charge() != 0) + { + // is charged candidate + auto entry = c_sortedindices.at(i); + // get cached track info + auto& trackinfo = trackinfos.at(i); + // get_ref to vector element + auto& c_pf_features = features.c_pf_features.at(entry); + // fill feature structure + auto packed_cand = dynamic_cast(cand); + auto reco_cand = dynamic_cast(cand); + if (packed_cand) + { + btagbtvdeep::packedCandidateToFeatures( + packed_cand, jet, trackinfo, drminpfcandsv, + static_cast(jet_radius_), c_pf_features); + } + else if (reco_cand) + { + // get vertex association quality + int pv_ass_quality = 0; // fallback value + // getting the PV as PackedCandidatesProducer + // but using not the slimmed but original vertices + auto ctrack = reco_cand->bestTrack(); + int pvi = -1; + float dist = 1e99; + for (size_t ii = 0; ii < vtxs->size(); ii++) + { + float dz = (ctrack) ? std::abs(ctrack->dz(((*vtxs)[ii]).position())) : 0; + if (dz < dist) + { + pvi = ii; + dist = dz; + } + } + auto pv = reco::VertexRef(vtxs, pvi); + btagbtvdeep::recoCandidateToFeatures( + reco_cand, jet, trackinfo, drminpfcandsv, + static_cast(jet_radius_), puppiw, pv_ass_quality, pv, + c_pf_features); + } + } + } + } + + output_tag_infos->emplace_back(features, jet_ref); + } + + iEvent.put(std::move(output_tag_infos)); +} + +// define this as a plug-in +DEFINE_FWK_MODULE(DeepDoubleCvLTagInfoProducer); diff --git a/RecoBTag/TensorFlow/interface/tensor_fillers.h b/RecoBTag/TensorFlow/interface/tensor_fillers.h index 6ea1de6f3315b..cb60d6ede8abf 100644 --- a/RecoBTag/TensorFlow/interface/tensor_fillers.h +++ b/RecoBTag/TensorFlow/interface/tensor_fillers.h @@ -4,8 +4,8 @@ #include "PhysicsTools/TensorFlow/interface/TensorFlow.h" #include "DataFormats/BTauReco/interface/DeepFlavourTagInfo.h" #include "DataFormats/BTauReco/interface/DeepDoubleBTagInfo.h" - - +#include "DataFormats/BTauReco/interface/DeepDoubleCvLTagInfo.h" +#include "DataFormats/BTauReco/interface/DeepDoubleCvBTagInfo.h" namespace btagbtvdeep { @@ -25,6 +25,13 @@ namespace btagbtvdeep { std::size_t jet_n, const btagbtvdeep::DeepDoubleBFeatures & features) ; + void db_tensor_filler(tensorflow::Tensor & tensor, + std::size_t jet_n, + const btagbtvdeep::DeepDoubleCvLFeatures & features) ; + + void db_tensor_filler(tensorflow::Tensor & tensor, + std::size_t jet_n, + const btagbtvdeep::DeepDoubleCvBFeatures & features) ; void c_pf_tensor_filler(tensorflow::Tensor & tensor, std::size_t jet_n, diff --git a/RecoBTag/TensorFlow/plugins/DeepDoubleCvBTFJetTagsProducer.cc b/RecoBTag/TensorFlow/plugins/DeepDoubleCvBTFJetTagsProducer.cc new file mode 100644 index 0000000000000..7e8d26326e138 --- /dev/null +++ b/RecoBTag/TensorFlow/plugins/DeepDoubleCvBTFJetTagsProducer.cc @@ -0,0 +1,292 @@ + +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/Framework/interface/makeRefToBaseProdFrom.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/StreamID.h" + +#include "DataFormats/BTauReco/interface/JetTag.h" + +#include "DataFormats/BTauReco/interface/DeepDoubleCvBTagInfo.h" + +#include "PhysicsTools/TensorFlow/interface/TensorFlow.h" + +#include "RecoBTag/TensorFlow/interface/tensor_fillers.h" + +// Declaration of the data structure that is hold by the edm::GlobalCache. +// In TensorFlow, the computational graph is stored in a stateless graph object which can be shared +// by multiple session instances which handle the initialization of variables related to the graph. +// Following this approach in CMSSW, a graph should be stored in a GlobalCache which can be accessed +// by sessions owned by multiple stream module copies. Instead of using only the plain graph, we +// make use of a cache struct that can be extended in the future if nedded. In addition, the graph +// is protected via std::atomic, which should not affect the performance as it is only accessed in +// the module constructor and not in the actual produce loop. +struct DeepDoubleCvBTFCache { + DeepDoubleCvBTFCache() : graphDef(nullptr) { + } + + std::atomic graphDef; +}; + +class DeepDoubleCvBTFJetTagsProducer : public edm::stream::EDProducer> { + + public: + explicit DeepDoubleCvBTFJetTagsProducer(const edm::ParameterSet&, const DeepDoubleCvBTFCache*); + ~DeepDoubleCvBTFJetTagsProducer() override; + + static void fillDescriptions(edm::ConfigurationDescriptions&); + + static std::unique_ptr initializeGlobalCache(const edm::ParameterSet&); + static void globalEndJob(const DeepDoubleCvBTFCache*); + + enum InputIndexes { + kGlobal = 0, + kChargedCandidates = 1, + kVertices = 2 + }; + + enum OutputIndexes { + kJetFlavour = 0 + }; + + private: + typedef std::vector TagInfoCollection; + typedef reco::JetTagCollection JetTagCollection; + + void beginStream(edm::StreamID) override {} + void produce(edm::Event&, const edm::EventSetup&) override; + void endStream() override {} + + const edm::EDGetTokenT< TagInfoCollection > src_; + std::vector>> flav_pairs_; + std::vector input_names_; + std::vector output_names_; + std::vector lp_names_; + + // session for TF evaluation + tensorflow::Session* session_; + // vector of learning phase tensors, i.e., boolean scalar tensors pointing to false + std::vector lp_tensors_; + // flag to evaluate model batch or jet by jet + bool batch_eval_; +}; + +DeepDoubleCvBTFJetTagsProducer::DeepDoubleCvBTFJetTagsProducer(const edm::ParameterSet& iConfig, + const DeepDoubleCvBTFCache* cache) : + src_(consumes(iConfig.getParameter("src"))), + input_names_(iConfig.getParameter>("input_names")), + output_names_(iConfig.getParameter>("output_names")), + lp_names_(iConfig.getParameter>("lp_names")), + session_(nullptr), + batch_eval_(iConfig.getParameter("batch_eval")) +{ + // get threading config and build session options + size_t nThreads = iConfig.getParameter("nThreads"); + std::string singleThreadPool = iConfig.getParameter("singleThreadPool"); + tensorflow::SessionOptions sessionOptions; + tensorflow::setThreading(sessionOptions, nThreads, singleThreadPool); + + // create the session using the meta graph from the cache + session_ = tensorflow::createSession(cache->graphDef, sessionOptions); + + // get output names from flav_table + const auto & flav_pset = iConfig.getParameter("flav_table"); + for (const auto flav_pair : flav_pset.tbl()) { + const auto & flav_name = flav_pair.first; + flav_pairs_.emplace_back(flav_name, + flav_pset.getParameter>(flav_name)); + } + + for (const auto & flav_pair : flav_pairs_) { + produces(flav_pair.first); + } + + // flag inputs (required because of batch norm) + // names for the learing phase placeholders (to init and set as false) + for (size_t i = 0; i < lp_names_.size(); i++) { + // create a bool tensor, set its value to false and store it + tensorflow::Tensor t(tensorflow::DT_BOOL, {}); + t.scalar()() = false; + lp_tensors_.push_back(t); + } +} + +DeepDoubleCvBTFJetTagsProducer::~DeepDoubleCvBTFJetTagsProducer() +{ + // close and delete the session + if (session_ != nullptr) { + tensorflow::closeSession(session_); + } +} + +void DeepDoubleCvBTFJetTagsProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) +{ + + // pfDeepDoubleCvBJetTags + edm::ParameterSetDescription desc; + desc.add("src", edm::InputTag("pfDeepDoubleCvBTagInfos")); + desc.add>("input_names", + { "input_1", "input_2", "input_3" }); + desc.add("graph_path", + edm::FileInPath("RecoBTag/Combined/data/DeepDoubleC/V01/DDCvB.pb")); + desc.add>("lp_names", + { "db_input_batchnorm/keras_learning_phase" }); + desc.add>("output_names", + { "ID_pred/Softmax" }); + { + edm::ParameterSetDescription psd0; + psd0.add>("probHbb", {0}); + psd0.add>("probHcc", {1}); + desc.add("flav_table", psd0); + } + + desc.add("batch_eval", false); + + desc.add("nThreads", 1); + desc.add("singleThreadPool", "no_threads"); + + descriptions.add("pfDeepDoubleCvBJetTags", desc); +} + +std::unique_ptr DeepDoubleCvBTFJetTagsProducer::initializeGlobalCache( + const edm::ParameterSet& iConfig) +{ + // set the tensorflow log level to error + tensorflow::setLogging("3"); + + // get the pb file + std::string pbFile = iConfig.getParameter("graph_path").fullPath(); + + // load the graph def and save it in the cache + DeepDoubleCvBTFCache* cache = new DeepDoubleCvBTFCache(); + cache->graphDef = tensorflow::loadGraphDef(pbFile); + + return std::unique_ptr(cache); +} + +void DeepDoubleCvBTFJetTagsProducer::globalEndJob(const DeepDoubleCvBTFCache* cache) +{ + if (cache->graphDef != nullptr) { + delete cache->graphDef; + } +} + +void DeepDoubleCvBTFJetTagsProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) +{ + + edm::Handle tag_infos; + iEvent.getByToken(src_, tag_infos); + + // initialize output collection + std::vector> output_tags; + for (std::size_t i=0; i < flav_pairs_.size(); i++) { + if (!tag_infos->empty()) { + auto jet_ref = tag_infos->begin()->jet(); + output_tags.emplace_back(std::make_unique( + edm::makeRefToBaseProdFrom(jet_ref, iEvent))); + } else { + output_tags.emplace_back(std::make_unique()); + } + } + + const int64_t n_jets = tag_infos->size(); + // either all jets or one per batch for the time being + const int64_t n_batch_jets = batch_eval_ ? n_jets : 1; + + + std::vector input_sizes { + {n_batch_jets, 1, 27}, // input_1 - global double-b features + {n_batch_jets, 60, 8}, // input_2 - charged pf + {n_batch_jets, 5, 2}, // input_3 - vertices + }; + + // create a list of named tensors, i.e. a vector of (string, Tensor) pairs, with proper size to + // prevent element copying that would occur via push_back's + // the default Tensor constructor creates a scalar so this should be fine w.r.t. to memory + tensorflow::NamedTensorList input_tensors; + input_tensors.resize(input_sizes.size() + lp_tensors_.size()); + + // add actual input tensors that hold physics information + for (std::size_t i=0; i < input_sizes.size(); i++) { + input_tensors[i] = tensorflow::NamedTensor( + input_names_[i], tensorflow::Tensor(tensorflow::DT_FLOAT, input_sizes.at(i))); + } + + // add learning-phase tensors behind them + for (std::size_t i=0; i < lp_tensors_.size(); i++) { + input_tensors[input_sizes.size() + i] = tensorflow::NamedTensor(lp_names_[i], lp_tensors_[i]); + } + + std::size_t n_batches = n_jets/n_batch_jets; // either 1 or n_jets + for (std::size_t batch_n=0; batch_n < n_batches; batch_n++) { + + // tensors have to be zeroed before filling per batch + for (std::size_t i=0; i < input_sizes.size(); i++) { + input_tensors[i].second.flat().setZero(); + } + + // fill values of the input tensors + for (std::size_t jet_bn=0; jet_bn < (std::size_t) n_batch_jets; jet_bn++) { + + // global jet index (jet_bn is the jet batch index) + std::size_t jet_n = batch_n*n_batch_jets + jet_bn; + + // jet and other global features + const auto & features = tag_infos->at(jet_n).features(); + db_tensor_filler(input_tensors.at(kGlobal).second, jet_bn, features); + + + // c_pf candidates + auto max_c_pf_n = std::min(features.c_pf_features.size(), + (std::size_t) input_sizes.at(kChargedCandidates).dim_size(1)); + for (std::size_t c_pf_n=0; c_pf_n < max_c_pf_n; c_pf_n++) { + const auto & c_pf_features = features.c_pf_features.at(c_pf_n); + c_pf_reduced_tensor_filler(input_tensors.at(kChargedCandidates).second, + jet_bn, c_pf_n, c_pf_features); + } + + // sv candidates + auto max_sv_n = std::min(features.sv_features.size(), + (std::size_t) input_sizes.at(kVertices).dim_size(1)); + for (std::size_t sv_n=0; sv_n < max_sv_n; sv_n++) { + const auto & sv_features = features.sv_features.at(sv_n); + sv_reduced_tensor_filler(input_tensors.at(kVertices).second, + jet_bn, sv_n, sv_features); + } + + } + // run the session + std::vector outputs; + tensorflow::run(session_, input_tensors, output_names_, &outputs); + + // set output values for flavour probs + for (std::size_t jet_bn=0; jet_bn < (std::size_t) n_batch_jets; jet_bn++) { + + // global jet index (jet_bn is the jet batch index) + std::size_t jet_n = batch_n*n_batch_jets + jet_bn; + + const auto & jet_ref = tag_infos->at(jet_n).jet(); + for (std::size_t flav_n=0; flav_n < flav_pairs_.size(); flav_n++) { + const auto & flav_pair = flav_pairs_.at(flav_n); + float o_sum = 0.; + for (const unsigned int & ind : flav_pair.second) { + o_sum += outputs.at(kJetFlavour).matrix()(jet_bn, ind); + } + (*(output_tags.at(flav_n)))[jet_ref] = o_sum; + } + } + } + + for (std::size_t i=0; i < flav_pairs_.size(); i++) { + iEvent.put(std::move(output_tags[i]), flav_pairs_.at(i).first); + } + +} + +//define this as a plug-in +DEFINE_FWK_MODULE(DeepDoubleCvBTFJetTagsProducer); diff --git a/RecoBTag/TensorFlow/plugins/DeepDoubleCvBTagInfoProducer.cc b/RecoBTag/TensorFlow/plugins/DeepDoubleCvBTagInfoProducer.cc new file mode 100644 index 0000000000000..8946fa8eddbd1 --- /dev/null +++ b/RecoBTag/TensorFlow/plugins/DeepDoubleCvBTagInfoProducer.cc @@ -0,0 +1,349 @@ + +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/StreamID.h" + +#include "DataFormats/Candidate/interface/Candidate.h" + +#include "DataFormats/PatCandidates/interface/Jet.h" +#include "DataFormats/PatCandidates/interface/PackedCandidate.h" + +#include "DataFormats/BTauReco/interface/BoostedDoubleSVTagInfo.h" + +#include "TrackingTools/Records/interface/TransientTrackRecord.h" +#include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h" + +#include "DataFormats/BTauReco/interface/DeepDoubleCvBFeatures.h" +#include "DataFormats/BTauReco/interface/DeepDoubleCvBTagInfo.h" + +#include "RecoBTag/TensorFlow/interface/BoostedDoubleSVTagInfoConverter.h" +#include "RecoBTag/TensorFlow/interface/ChargedCandidateConverter.h" +#include "RecoBTag/TensorFlow/interface/JetConverter.h" +#include "RecoBTag/TensorFlow/interface/SecondaryVertexConverter.h" + +#include "RecoBTag/TensorFlow/interface/TrackInfoBuilder.h" +#include "RecoBTag/TensorFlow/interface/sorting_modules.h" + +#include "DataFormats/Candidate/interface/VertexCompositePtrCandidate.h" +#include "DataFormats/VertexReco/interface/VertexFwd.h" + +#include "RecoBTag/TensorFlow/interface/deep_helpers.h" + +class DeepDoubleCvBTagInfoProducer : public edm::stream::EDProducer<> +{ + +public: + explicit DeepDoubleCvBTagInfoProducer(const edm::ParameterSet&); + ~DeepDoubleCvBTagInfoProducer() override; + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + +private: + typedef std::vector DeepDoubleCvBTagInfoCollection; + typedef reco::VertexCompositePtrCandidateCollection SVCollection; + typedef reco::VertexCollection VertexCollection; + typedef edm::View + BoostedDoubleSVTagInfoCollection; + + void beginStream(edm::StreamID) override + { + } + void produce(edm::Event&, const edm::EventSetup&) override; + void endStream() override + { + } + + const double jet_radius_; + const double min_candidate_pt_; + + edm::EDGetTokenT> jet_token_; + edm::EDGetTokenT vtx_token_; + edm::EDGetTokenT sv_token_; + edm::EDGetTokenT shallow_tag_info_token_; +}; + +DeepDoubleCvBTagInfoProducer::DeepDoubleCvBTagInfoProducer( + const edm::ParameterSet& iConfig) + : jet_radius_(iConfig.getParameter("jet_radius")) + , min_candidate_pt_(iConfig.getParameter("min_candidate_pt")) + , jet_token_(consumes>( + iConfig.getParameter("jets"))) + , vtx_token_(consumes( + iConfig.getParameter("vertices"))) + , sv_token_(consumes( + iConfig.getParameter("secondary_vertices"))) + , shallow_tag_info_token_(consumes( + iConfig.getParameter("shallow_tag_infos"))) +{ + produces(); +} + +DeepDoubleCvBTagInfoProducer::~DeepDoubleCvBTagInfoProducer() +{ +} + +void DeepDoubleCvBTagInfoProducer::fillDescriptions( + edm::ConfigurationDescriptions& descriptions) +{ + // pfDeepDoubleCvBTagInfos + edm::ParameterSetDescription desc; + desc.add("shallow_tag_infos", + edm::InputTag("pfBoostedDoubleSVAK8TagInfos")); + desc.add("jet_radius", 0.8); + desc.add("min_candidate_pt", 0.95); + desc.add("vertices", edm::InputTag("offlinePrimaryVertices")); + desc.add("secondary_vertices", + edm::InputTag("inclusiveCandidateSecondaryVertices")); + desc.add("jets", edm::InputTag("ak8PFJetsCHS")); + descriptions.add("pfDeepDoubleCvBTagInfos", desc); +} + +void DeepDoubleCvBTagInfoProducer::produce(edm::Event& iEvent, + const edm::EventSetup& iSetup) +{ + + auto output_tag_infos = std::make_unique(); + + edm::Handle> jets; + iEvent.getByToken(jet_token_, jets); + + edm::Handle vtxs; + iEvent.getByToken(vtx_token_, vtxs); + if (vtxs->empty()) + { + // produce empty TagInfos in case no primary vertex + iEvent.put(std::move(output_tag_infos)); + return; // exit event + } + // reference to primary vertex + const auto& pv = vtxs->at(0); + + edm::Handle svs; + iEvent.getByToken(sv_token_, svs); + + edm::Handle shallow_tag_infos; + iEvent.getByToken(shallow_tag_info_token_, shallow_tag_infos); + + edm::ESHandle track_builder; + iSetup.get().get("TransientTrackBuilder", + track_builder); + + for (std::size_t jet_n = 0; jet_n < jets->size(); jet_n++) + { + + // create data containing structure + btagbtvdeep::DeepDoubleCvBFeatures features; + + // reco jet reference (use as much as possible) + const auto& jet = jets->at(jet_n); + edm::RefToBase jet_ref(jets, jet_n); + // TagInfoCollection not in an associative container so search for matchs + const edm::View& taginfos = *shallow_tag_infos; + edm::Ptr match; + // Try first by 'same index' + if ((jet_n < taginfos.size()) && (taginfos[jet_n].jet() == jet_ref)) + { + match = taginfos.ptrAt(jet_n); + } + else + { + // otherwise fall back to a simple search + for (auto itTI = taginfos.begin(), edTI = taginfos.end(); itTI != edTI; + ++itTI) + { + if (itTI->jet() == jet_ref) + { + match = taginfos.ptrAt(itTI - taginfos.begin()); + break; + } + } + } + reco::BoostedDoubleSVTagInfo tag_info; + if (match.isNonnull()) + { + tag_info = *match; + } // will be default values otherwise + + // fill basic jet features + btagbtvdeep::JetConverter::jetToFeatures(jet, features.jet_features); + + // fill number of pv + features.npv = vtxs->size(); + + // fill features from BoostedDoubleSVTagInfo + const auto& tag_info_vars = tag_info.taggingVariables(); + btagbtvdeep::doubleBTagToFeatures(tag_info_vars, + features.tag_info_features); + + // copy which will be sorted + auto svs_sorted = *svs; + // sort by dxy + std::sort(svs_sorted.begin(), svs_sorted.end(), + [&pv](const auto& sva, const auto& svb) { + 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; + 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); + } + } + + // 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> c_sorted; + + // to cache the TrackInfo + std::map trackinfos; + + // unsorted reference to sv + const auto& svs_unsorted = *svs; + // fill collection, from DeepTNtuples plus some styling + // std::vector daughters; + std::vector daughters; + for (unsigned int i = 0; i < jet.numberOfDaughters(); i++) + { + auto const* cand = jet.daughter(i); + auto packed_cand = dynamic_cast(cand); + auto reco_cand = dynamic_cast(cand); + if (packed_cand) + { + if (cand->numberOfDaughters() > 0) + { + for (unsigned int k = 0; k < cand->numberOfDaughters(); k++) + { + daughters.push_back( + dynamic_cast(cand->daughter(k))); + } + } + else + { + auto packed_cand = dynamic_cast(cand); + daughters.push_back(packed_cand); + } + } + else if (reco_cand) + { + // need some edm::Ptr or edm::Ref if reco candidates + // dynamical casting to pointers, null if not possible + daughters.push_back(reco_cand); + } + } + + for (unsigned int i = 0; i < daughters.size(); i++) + { + auto const* cand = daughters.at(i); + + if (cand) + { + // candidates under 950MeV (configurable) are not considered + // might change if we use also white-listing + if (cand->pt() < min_candidate_pt_) + continue; + if (cand->charge() != 0) + { + auto& trackinfo = trackinfos.emplace(i, track_builder).first->second; + trackinfo.buildTrackInfo(cand, jet_dir, jet_ref_track_dir, pv); + c_sorted.emplace_back( + i, trackinfo.getTrackSip2dSig(), + -btagbtvdeep::mindrsvpfcand(svs_unsorted, cand, jet_radius_), + cand->pt() / jet.pt()); + } + } + } + + // sort collections (open the black-box if you please) + std::sort(c_sorted.begin(), c_sorted.end(), + btagbtvdeep::SortingClass::compareByABCInv); + + std::vector c_sortedindices; + + // this puts 0 everywhere and the right position in ind + c_sortedindices = btagbtvdeep::invertSortingVector(c_sorted); + + // set right size to vectors + features.c_pf_features.clear(); + features.c_pf_features.resize(c_sorted.size()); + + for (unsigned int i = 0; i < daughters.size(); i++) + { + auto const* cand = daughters.at(i); + if (cand) + { + // candidates under 950MeV are not considered + // might change if we use also white-listing + if (cand->pt() < 0.95) + continue; + + // get PUPPI weight from value map + float puppiw = 1.0; // fallback value + + float drminpfcandsv = btagbtvdeep::mindrsvpfcand(svs_unsorted, cand, jet_radius_); + + if (cand->charge() != 0) + { + // is charged candidate + auto entry = c_sortedindices.at(i); + // get cached track info + auto& trackinfo = trackinfos.at(i); + // get_ref to vector element + auto& c_pf_features = features.c_pf_features.at(entry); + // fill feature structure + auto packed_cand = dynamic_cast(cand); + auto reco_cand = dynamic_cast(cand); + if (packed_cand) + { + btagbtvdeep::packedCandidateToFeatures( + packed_cand, jet, trackinfo, drminpfcandsv, + static_cast(jet_radius_), c_pf_features); + } + else if (reco_cand) + { + // get vertex association quality + int pv_ass_quality = 0; // fallback value + // getting the PV as PackedCandidatesProducer + // but using not the slimmed but original vertices + auto ctrack = reco_cand->bestTrack(); + int pvi = -1; + float dist = 1e99; + for (size_t ii = 0; ii < vtxs->size(); ii++) + { + float dz = (ctrack) ? std::abs(ctrack->dz(((*vtxs)[ii]).position())) : 0; + if (dz < dist) + { + pvi = ii; + dist = dz; + } + } + auto pv = reco::VertexRef(vtxs, pvi); + btagbtvdeep::recoCandidateToFeatures( + reco_cand, jet, trackinfo, drminpfcandsv, + static_cast(jet_radius_), puppiw, pv_ass_quality, pv, + c_pf_features); + } + } + } + } + + output_tag_infos->emplace_back(features, jet_ref); + } + + iEvent.put(std::move(output_tag_infos)); +} + +// define this as a plug-in +DEFINE_FWK_MODULE(DeepDoubleCvBTagInfoProducer); diff --git a/RecoBTag/TensorFlow/plugins/DeepDoubleCvLTFJetTagsProducer.cc b/RecoBTag/TensorFlow/plugins/DeepDoubleCvLTFJetTagsProducer.cc new file mode 100644 index 0000000000000..4eb504f229fa3 --- /dev/null +++ b/RecoBTag/TensorFlow/plugins/DeepDoubleCvLTFJetTagsProducer.cc @@ -0,0 +1,292 @@ + +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/Framework/interface/makeRefToBaseProdFrom.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/StreamID.h" + +#include "DataFormats/BTauReco/interface/JetTag.h" + +#include "DataFormats/BTauReco/interface/DeepDoubleCvLTagInfo.h" + +#include "PhysicsTools/TensorFlow/interface/TensorFlow.h" + +#include "RecoBTag/TensorFlow/interface/tensor_fillers.h" + +// Declaration of the data structure that is hold by the edm::GlobalCache. +// In TensorFlow, the computational graph is stored 1in a stateless graph object which can be shared +// by multiple session instances which handle the initialization of variables related to the graph. +// Following this approach in CMSSW, a graph should be stored in a GlobalCache which can be accessed +// by sessions owned by multiple stream module copies. Instead of using only the plain graph, we +// make use of a cache struct that can be extended in the future if nedded. In addition, the graph +// is protected via std::atomic, which should not affect the performance as it is only accessed in +// the module constructor and not in the actual produce loop. +struct DeepDoubleCvLTFCache { + DeepDoubleCvLTFCache() : graphDef(nullptr) { + } + + std::atomic graphDef; +}; + +class DeepDoubleCvLTFJetTagsProducer : public edm::stream::EDProducer> { + + public: + explicit DeepDoubleCvLTFJetTagsProducer(const edm::ParameterSet&, const DeepDoubleCvLTFCache*); + ~DeepDoubleCvLTFJetTagsProducer() override; + + static void fillDescriptions(edm::ConfigurationDescriptions&); + + static std::unique_ptr initializeGlobalCache(const edm::ParameterSet&); + static void globalEndJob(const DeepDoubleCvLTFCache*); + + enum InputIndexes { + kGlobal = 0, + kChargedCandidates = 1, + kVertices = 2 + }; + + enum OutputIndexes { + kJetFlavour = 0 + }; + + private: + typedef std::vector TagInfoCollection; + typedef reco::JetTagCollection JetTagCollection; + + void beginStream(edm::StreamID) override {} + void produce(edm::Event&, const edm::EventSetup&) override; + void endStream() override {} + + const edm::EDGetTokenT< TagInfoCollection > src_; + std::vector>> flav_pairs_; + std::vector input_names_; + std::vector output_names_; + std::vector lp_names_; + + // session for TF evaluation + tensorflow::Session* session_; + // vector of learning phase tensors, i.e., boolean scalar tensors pointing to false + std::vector lp_tensors_; + // flag to evaluate model batch or jet by jet + bool batch_eval_; +}; + +DeepDoubleCvLTFJetTagsProducer::DeepDoubleCvLTFJetTagsProducer(const edm::ParameterSet& iConfig, + const DeepDoubleCvLTFCache* cache) : + src_(consumes(iConfig.getParameter("src"))), + input_names_(iConfig.getParameter>("input_names")), + output_names_(iConfig.getParameter>("output_names")), + lp_names_(iConfig.getParameter>("lp_names")), + session_(nullptr), + batch_eval_(iConfig.getParameter("batch_eval")) +{ + // get threading config and build session options + size_t nThreads = iConfig.getParameter("nThreads"); + std::string singleThreadPool = iConfig.getParameter("singleThreadPool"); + tensorflow::SessionOptions sessionOptions; + tensorflow::setThreading(sessionOptions, nThreads, singleThreadPool); + + // create the session using the meta graph from the cache + session_ = tensorflow::createSession(cache->graphDef, sessionOptions); + + // get output names from flav_table + const auto & flav_pset = iConfig.getParameter("flav_table"); + for (const auto flav_pair : flav_pset.tbl()) { + const auto & flav_name = flav_pair.first; + flav_pairs_.emplace_back(flav_name, + flav_pset.getParameter>(flav_name)); + } + + for (const auto & flav_pair : flav_pairs_) { + produces(flav_pair.first); + } + + // flag inputs (required because of batch norm) + // names for the learing phase placeholders (to init and set as false) + for (size_t i = 0; i < lp_names_.size(); i++) { + // create a bool tensor, set its value to false and store it + tensorflow::Tensor t(tensorflow::DT_BOOL, {}); + t.scalar()() = false; + lp_tensors_.push_back(t); + } +} + +DeepDoubleCvLTFJetTagsProducer::~DeepDoubleCvLTFJetTagsProducer() +{ + // close and delete the session + if (session_ != nullptr) { + tensorflow::closeSession(session_); + } +} + +void DeepDoubleCvLTFJetTagsProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) +{ + + // pfDeepDoubleCvLJetTags + edm::ParameterSetDescription desc; + desc.add("src", edm::InputTag("pfDeepDoubleCvLTagInfos")); + desc.add>("input_names", + { "input_1", "input_2", "input_3" }); + desc.add("graph_path", + edm::FileInPath("RecoBTag/Combined/data/DeepDoubleC/V01/DDCvL.pb")); + desc.add>("lp_names", + { "db_input_batchnorm/keras_learning_phase" }); + desc.add>("output_names", + { "ID_pred/Softmax" }); + { + edm::ParameterSetDescription psd0; + psd0.add>("probQCD", {0}); + psd0.add>("probHcc", {1}); + desc.add("flav_table", psd0); + } + + desc.add("batch_eval", false); + + desc.add("nThreads", 1); + desc.add("singleThreadPool", "no_threads"); + + descriptions.add("pfDeepDoubleCvLJetTags", desc); +} + +std::unique_ptr DeepDoubleCvLTFJetTagsProducer::initializeGlobalCache( + const edm::ParameterSet& iConfig) +{ + // set the tensorflow log level to error + tensorflow::setLogging("3"); + + // get the pb file + std::string pbFile = iConfig.getParameter("graph_path").fullPath(); + + // load the graph def and save it in the cache + DeepDoubleCvLTFCache* cache = new DeepDoubleCvLTFCache(); + cache->graphDef = tensorflow::loadGraphDef(pbFile); + + return std::unique_ptr(cache); +} + +void DeepDoubleCvLTFJetTagsProducer::globalEndJob(const DeepDoubleCvLTFCache* cache) +{ + if (cache->graphDef != nullptr) { + delete cache->graphDef; + } +} + +void DeepDoubleCvLTFJetTagsProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) +{ + + edm::Handle tag_infos; + iEvent.getByToken(src_, tag_infos); + + // initialize output collection + std::vector> output_tags; + for (std::size_t i=0; i < flav_pairs_.size(); i++) { + if (!tag_infos->empty()) { + auto jet_ref = tag_infos->begin()->jet(); + output_tags.emplace_back(std::make_unique( + edm::makeRefToBaseProdFrom(jet_ref, iEvent))); + } else { + output_tags.emplace_back(std::make_unique()); + } + } + + const int64_t n_jets = tag_infos->size(); + // either all jets or one per batch for the time being + const int64_t n_batch_jets = batch_eval_ ? n_jets : 1; + + + std::vector input_sizes { + {n_batch_jets, 1, 27}, // input_1 - global double-b features + {n_batch_jets, 60, 8}, // input_2 - charged pf + {n_batch_jets, 5, 2}, // input_3 - vertices + }; + + // create a list of named tensors, i.e. a vector of (string, Tensor) pairs, with proper size to + // prevent element copying that would occur via push_back's + // the default Tensor constructor creates a scalar so this should be fine w.r.t. to memory + tensorflow::NamedTensorList input_tensors; + input_tensors.resize(input_sizes.size() + lp_tensors_.size()); + + // add actual input tensors that hold physics information + for (std::size_t i=0; i < input_sizes.size(); i++) { + input_tensors[i] = tensorflow::NamedTensor( + input_names_[i], tensorflow::Tensor(tensorflow::DT_FLOAT, input_sizes.at(i))); + } + + // add learning-phase tensors behind them + for (std::size_t i=0; i < lp_tensors_.size(); i++) { + input_tensors[input_sizes.size() + i] = tensorflow::NamedTensor(lp_names_[i], lp_tensors_[i]); + } + + std::size_t n_batches = n_jets/n_batch_jets; // either 1 or n_jets + for (std::size_t batch_n=0; batch_n < n_batches; batch_n++) { + + // tensors have to be zeroed before filling per batch + for (std::size_t i=0; i < input_sizes.size(); i++) { + input_tensors[i].second.flat().setZero(); + } + + // fill values of the input tensors + for (std::size_t jet_bn=0; jet_bn < (std::size_t) n_batch_jets; jet_bn++) { + + // global jet index (jet_bn is the jet batch index) + std::size_t jet_n = batch_n*n_batch_jets + jet_bn; + + // jet and other global features + const auto & features = tag_infos->at(jet_n).features(); + db_tensor_filler(input_tensors.at(kGlobal).second, jet_bn, features); + + + // c_pf candidates + auto max_c_pf_n = std::min(features.c_pf_features.size(), + (std::size_t) input_sizes.at(kChargedCandidates).dim_size(1)); + for (std::size_t c_pf_n=0; c_pf_n < max_c_pf_n; c_pf_n++) { + const auto & c_pf_features = features.c_pf_features.at(c_pf_n); + c_pf_reduced_tensor_filler(input_tensors.at(kChargedCandidates).second, + jet_bn, c_pf_n, c_pf_features); + } + + // sv candidates + auto max_sv_n = std::min(features.sv_features.size(), + (std::size_t) input_sizes.at(kVertices).dim_size(1)); + for (std::size_t sv_n=0; sv_n < max_sv_n; sv_n++) { + const auto & sv_features = features.sv_features.at(sv_n); + sv_reduced_tensor_filler(input_tensors.at(kVertices).second, + jet_bn, sv_n, sv_features); + } + + } + // run the session + std::vector outputs; + tensorflow::run(session_, input_tensors, output_names_, &outputs); + + // set output values for flavour probs + for (std::size_t jet_bn=0; jet_bn < (std::size_t) n_batch_jets; jet_bn++) { + + // global jet index (jet_bn is the jet batch index) + std::size_t jet_n = batch_n*n_batch_jets + jet_bn; + + const auto & jet_ref = tag_infos->at(jet_n).jet(); + for (std::size_t flav_n=0; flav_n < flav_pairs_.size(); flav_n++) { + const auto & flav_pair = flav_pairs_.at(flav_n); + float o_sum = 0.; + for (const unsigned int & ind : flav_pair.second) { + o_sum += outputs.at(kJetFlavour).matrix()(jet_bn, ind); + } + (*(output_tags.at(flav_n)))[jet_ref] = o_sum; + } + } + } + + for (std::size_t i=0; i < flav_pairs_.size(); i++) { + iEvent.put(std::move(output_tags[i]), flav_pairs_.at(i).first); + } + +} + +//define this as a plug-in +DEFINE_FWK_MODULE(DeepDoubleCvLTFJetTagsProducer); diff --git a/RecoBTag/TensorFlow/plugins/DeepDoubleCvLTagInfoProducer.cc b/RecoBTag/TensorFlow/plugins/DeepDoubleCvLTagInfoProducer.cc new file mode 100644 index 0000000000000..e683dfe76470e --- /dev/null +++ b/RecoBTag/TensorFlow/plugins/DeepDoubleCvLTagInfoProducer.cc @@ -0,0 +1,349 @@ + +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/StreamID.h" + +#include "DataFormats/Candidate/interface/Candidate.h" + +#include "DataFormats/PatCandidates/interface/Jet.h" +#include "DataFormats/PatCandidates/interface/PackedCandidate.h" + +#include "DataFormats/BTauReco/interface/BoostedDoubleSVTagInfo.h" + +#include "TrackingTools/Records/interface/TransientTrackRecord.h" +#include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h" + +#include "DataFormats/BTauReco/interface/DeepDoubleCvLFeatures.h" +#include "DataFormats/BTauReco/interface/DeepDoubleCvLTagInfo.h" + +#include "RecoBTag/TensorFlow/interface/BoostedDoubleSVTagInfoConverter.h" +#include "RecoBTag/TensorFlow/interface/ChargedCandidateConverter.h" +#include "RecoBTag/TensorFlow/interface/JetConverter.h" +#include "RecoBTag/TensorFlow/interface/SecondaryVertexConverter.h" + +#include "RecoBTag/TensorFlow/interface/TrackInfoBuilder.h" +#include "RecoBTag/TensorFlow/interface/sorting_modules.h" + +#include "DataFormats/Candidate/interface/VertexCompositePtrCandidate.h" +#include "DataFormats/VertexReco/interface/VertexFwd.h" + +#include "RecoBTag/TensorFlow/interface/deep_helpers.h" + +class DeepDoubleCvLTagInfoProducer : public edm::stream::EDProducer<> +{ + +public: + explicit DeepDoubleCvLTagInfoProducer(const edm::ParameterSet&); + ~DeepDoubleCvLTagInfoProducer() override; + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + +private: + typedef std::vector DeepDoubleCvLTagInfoCollection; + typedef reco::VertexCompositePtrCandidateCollection SVCollection; + typedef reco::VertexCollection VertexCollection; + typedef edm::View + BoostedDoubleSVTagInfoCollection; + + void beginStream(edm::StreamID) override + { + } + void produce(edm::Event&, const edm::EventSetup&) override; + void endStream() override + { + } + + const double jet_radius_; + const double min_candidate_pt_; + + edm::EDGetTokenT> jet_token_; + edm::EDGetTokenT vtx_token_; + edm::EDGetTokenT sv_token_; + edm::EDGetTokenT shallow_tag_info_token_; +}; + +DeepDoubleCvLTagInfoProducer::DeepDoubleCvLTagInfoProducer( + const edm::ParameterSet& iConfig) + : jet_radius_(iConfig.getParameter("jet_radius")) + , min_candidate_pt_(iConfig.getParameter("min_candidate_pt")) + , jet_token_(consumes>( + iConfig.getParameter("jets"))) + , vtx_token_(consumes( + iConfig.getParameter("vertices"))) + , sv_token_(consumes( + iConfig.getParameter("secondary_vertices"))) + , shallow_tag_info_token_(consumes( + iConfig.getParameter("shallow_tag_infos"))) +{ + produces(); +} + +DeepDoubleCvLTagInfoProducer::~DeepDoubleCvLTagInfoProducer() +{ +} + +void DeepDoubleCvLTagInfoProducer::fillDescriptions( + edm::ConfigurationDescriptions& descriptions) +{ + // pfDeepDoubleCvLTagInfos + edm::ParameterSetDescription desc; + desc.add("shallow_tag_infos", + edm::InputTag("pfBoostedDoubleSVAK8TagInfos")); + desc.add("jet_radius", 0.8); + desc.add("min_candidate_pt", 0.95); + desc.add("vertices", edm::InputTag("offlinePrimaryVertices")); + desc.add("secondary_vertices", + edm::InputTag("inclusiveCandidateSecondaryVertices")); + desc.add("jets", edm::InputTag("ak8PFJetsCHS")); + descriptions.add("pfDeepDoubleCvLTagInfos", desc); +} + +void DeepDoubleCvLTagInfoProducer::produce(edm::Event& iEvent, + const edm::EventSetup& iSetup) +{ + + auto output_tag_infos = std::make_unique(); + + edm::Handle> jets; + iEvent.getByToken(jet_token_, jets); + + edm::Handle vtxs; + iEvent.getByToken(vtx_token_, vtxs); + if (vtxs->empty()) + { + // produce empty TagInfos in case no primary vertex + iEvent.put(std::move(output_tag_infos)); + return; // exit event + } + // reference to primary vertex + const auto& pv = vtxs->at(0); + + edm::Handle svs; + iEvent.getByToken(sv_token_, svs); + + edm::Handle shallow_tag_infos; + iEvent.getByToken(shallow_tag_info_token_, shallow_tag_infos); + + edm::ESHandle track_builder; + iSetup.get().get("TransientTrackBuilder", + track_builder); + + for (std::size_t jet_n = 0; jet_n < jets->size(); jet_n++) + { + + // create data containing structure + btagbtvdeep::DeepDoubleCvLFeatures features; + + // reco jet reference (use as much as possible) + const auto& jet = jets->at(jet_n); + edm::RefToBase jet_ref(jets, jet_n); + // TagInfoCollection not in an associative container so search for matchs + const edm::View& taginfos = *shallow_tag_infos; + edm::Ptr match; + // Try first by 'same index' + if ((jet_n < taginfos.size()) && (taginfos[jet_n].jet() == jet_ref)) + { + match = taginfos.ptrAt(jet_n); + } + else + { + // otherwise fall back to a simple search + for (auto itTI = taginfos.begin(), edTI = taginfos.end(); itTI != edTI; + ++itTI) + { + if (itTI->jet() == jet_ref) + { + match = taginfos.ptrAt(itTI - taginfos.begin()); + break; + } + } + } + reco::BoostedDoubleSVTagInfo tag_info; + if (match.isNonnull()) + { + tag_info = *match; + } // will be default values otherwise + + // fill basic jet features + btagbtvdeep::JetConverter::jetToFeatures(jet, features.jet_features); + + // fill number of pv + features.npv = vtxs->size(); + + // fill features from BoostedDoubleSVTagInfo + const auto& tag_info_vars = tag_info.taggingVariables(); + btagbtvdeep::doubleBTagToFeatures(tag_info_vars, + features.tag_info_features); + + // copy which will be sorted + auto svs_sorted = *svs; + // sort by dxy + std::sort(svs_sorted.begin(), svs_sorted.end(), + [&pv](const auto& sva, const auto& svb) { + 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; + 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); + } + } + + // 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> c_sorted; + + // to cache the TrackInfo + std::map trackinfos; + + // unsorted reference to sv + const auto& svs_unsorted = *svs; + // fill collection, from DeepTNtuples plus some styling + // std::vector daughters; + std::vector daughters; + for (unsigned int i = 0; i < jet.numberOfDaughters(); i++) + { + auto const* cand = jet.daughter(i); + auto packed_cand = dynamic_cast(cand); + auto reco_cand = dynamic_cast(cand); + if (packed_cand) + { + if (cand->numberOfDaughters() > 0) + { + for (unsigned int k = 0; k < cand->numberOfDaughters(); k++) + { + daughters.push_back( + dynamic_cast(cand->daughter(k))); + } + } + else + { + auto packed_cand = dynamic_cast(cand); + daughters.push_back(packed_cand); + } + } + else if (reco_cand) + { + // need some edm::Ptr or edm::Ref if reco candidates + // dynamical casting to pointers, null if not possible + daughters.push_back(reco_cand); + } + } + + for (unsigned int i = 0; i < daughters.size(); i++) + { + auto const* cand = daughters.at(i); + + if (cand) + { + // candidates under 950MeV (configurable) are not considered + // might change if we use also white-listing + if (cand->pt() < min_candidate_pt_) + continue; + if (cand->charge() != 0) + { + auto& trackinfo = trackinfos.emplace(i, track_builder).first->second; + trackinfo.buildTrackInfo(cand, jet_dir, jet_ref_track_dir, pv); + c_sorted.emplace_back( + i, trackinfo.getTrackSip2dSig(), + -btagbtvdeep::mindrsvpfcand(svs_unsorted, cand, jet_radius_), + cand->pt() / jet.pt()); + } + } + } + + // sort collections (open the black-box if you please) + std::sort(c_sorted.begin(), c_sorted.end(), + btagbtvdeep::SortingClass::compareByABCInv); + + std::vector c_sortedindices; + + // this puts 0 everywhere and the right position in ind + c_sortedindices = btagbtvdeep::invertSortingVector(c_sorted); + + // set right size to vectors + features.c_pf_features.clear(); + features.c_pf_features.resize(c_sorted.size()); + + for (unsigned int i = 0; i < daughters.size(); i++) + { + auto const* cand = daughters.at(i); + if (cand) + { + // candidates under 950MeV are not considered + // might change if we use also white-listing + if (cand->pt() < 0.95) + continue; + + // get PUPPI weight from value map + float puppiw = 1.0; // fallback value + + float drminpfcandsv = btagbtvdeep::mindrsvpfcand(svs_unsorted, cand, jet_radius_); + + if (cand->charge() != 0) + { + // is charged candidate + auto entry = c_sortedindices.at(i); + // get cached track info + auto& trackinfo = trackinfos.at(i); + // get_ref to vector element + auto& c_pf_features = features.c_pf_features.at(entry); + // fill feature structure + auto packed_cand = dynamic_cast(cand); + auto reco_cand = dynamic_cast(cand); + if (packed_cand) + { + btagbtvdeep::packedCandidateToFeatures( + packed_cand, jet, trackinfo, drminpfcandsv, + static_cast(jet_radius_), c_pf_features); + } + else if (reco_cand) + { + // get vertex association quality + int pv_ass_quality = 0; // fallback value + // getting the PV as PackedCandidatesProducer + // but using not the slimmed but original vertices + auto ctrack = reco_cand->bestTrack(); + int pvi = -1; + float dist = 1e99; + for (size_t ii = 0; ii < vtxs->size(); ii++) + { + float dz = (ctrack) ? std::abs(ctrack->dz(((*vtxs)[ii]).position())) : 0; + if (dz < dist) + { + pvi = ii; + dist = dz; + } + } + auto pv = reco::VertexRef(vtxs, pvi); + btagbtvdeep::recoCandidateToFeatures( + reco_cand, jet, trackinfo, drminpfcandsv, + static_cast(jet_radius_), puppiw, pv_ass_quality, pv, + c_pf_features); + } + } + } + } + + output_tag_infos->emplace_back(features, jet_ref); + } + + iEvent.put(std::move(output_tag_infos)); +} + +// define this as a plug-in +DEFINE_FWK_MODULE(DeepDoubleCvLTagInfoProducer); diff --git a/RecoBTag/TensorFlow/python/pfDeepFlavour_cff.py b/RecoBTag/TensorFlow/python/pfDeepFlavour_cff.py index 9f41d24a4d3cd..cdf4b227f52e3 100644 --- a/RecoBTag/TensorFlow/python/pfDeepFlavour_cff.py +++ b/RecoBTag/TensorFlow/python/pfDeepFlavour_cff.py @@ -3,11 +3,14 @@ from RecoBTag.FeatureTools.pfDeepFlavourTagInfos_cfi import pfDeepFlavourTagInfos from RecoBTag.FeatureTools.pfNegativeDeepFlavourTagInfos_cfi import pfNegativeDeepFlavourTagInfos from RecoBTag.FeatureTools.pfDeepDoubleBTagInfos_cfi import pfDeepDoubleBTagInfos +from RecoBTag.FeatureTools.pfDeepDoubleCvLTagInfos_cfi import pfDeepDoubleCvLTagInfos +from RecoBTag.FeatureTools.pfDeepDoubleCvBTagInfos_cfi import pfDeepDoubleCvBTagInfos from RecoBTag.TensorFlow.pfDeepFlavourJetTags_cfi import pfDeepFlavourJetTags from RecoBTag.TensorFlow.pfNegativeDeepFlavourJetTags_cfi import pfNegativeDeepFlavourJetTags from RecoBTag.TensorFlow.pfDeepDoubleBJetTags_cfi import pfDeepDoubleBJetTags - +from RecoBTag.TensorFlow.pfDeepDoubleCvLJetTags_cfi import pfDeepDoubleCvLJetTags +from RecoBTag.TensorFlow.pfDeepDoubleCvBJetTags_cfi import pfDeepDoubleCvBJetTags from CommonTools.PileupAlgos.Puppi_cff import puppi from PhysicsTools.PatAlgos.slimming.primaryVertexAssociation_cfi import primaryVertexAssociation diff --git a/RecoBTag/TensorFlow/src/tensor_fillers.cc b/RecoBTag/TensorFlow/src/tensor_fillers.cc index 524f9b880edd3..cd5066e2e6e81 100644 --- a/RecoBTag/TensorFlow/src/tensor_fillers.cc +++ b/RecoBTag/TensorFlow/src/tensor_fillers.cc @@ -77,6 +77,84 @@ namespace btagbtvdeep { *(++ptr) = tag_info_features.z_ratio; } + void db_tensor_filler(tensorflow::Tensor & tensor, + std::size_t jet_n, + const btagbtvdeep::DeepDoubleCvLFeatures & features) { + + float* ptr = &tensor.tensor()(jet_n, 0, 0); + + // variables from BoostedDoubleSVTagInfo + const auto & tag_info_features = features.tag_info_features; + *ptr = tag_info_features.jetNTracks; + *(++ptr) = tag_info_features.jetNSecondaryVertices; + *(++ptr) = tag_info_features.tau1_trackEtaRel_0; + *(++ptr) = tag_info_features.tau1_trackEtaRel_1; + *(++ptr) = tag_info_features.tau1_trackEtaRel_2; + *(++ptr) = tag_info_features.tau2_trackEtaRel_0; + *(++ptr) = tag_info_features.tau2_trackEtaRel_1; + *(++ptr) = tag_info_features.tau2_trackEtaRel_2; + *(++ptr) = tag_info_features.tau1_flightDistance2dSig; + *(++ptr) = tag_info_features.tau2_flightDistance2dSig; + *(++ptr) = tag_info_features.tau1_vertexDeltaR; + // Note: this variable is not used in the 27-input BDT + // *(++ptr) = tag_info_features.tau2_vertexDeltaR; + *(++ptr) = tag_info_features.tau1_vertexEnergyRatio; + *(++ptr) = tag_info_features.tau2_vertexEnergyRatio; + *(++ptr) = tag_info_features.tau1_vertexMass; + *(++ptr) = tag_info_features.tau2_vertexMass; + *(++ptr) = tag_info_features.trackSip2dSigAboveBottom_0; + *(++ptr) = tag_info_features.trackSip2dSigAboveBottom_1; + *(++ptr) = tag_info_features.trackSip2dSigAboveCharm; + *(++ptr) = tag_info_features.trackSip3dSig_0; + *(++ptr) = tag_info_features.tau1_trackSip3dSig_0; + *(++ptr) = tag_info_features.tau1_trackSip3dSig_1; + *(++ptr) = tag_info_features.trackSip3dSig_1; + *(++ptr) = tag_info_features.tau2_trackSip3dSig_0; + *(++ptr) = tag_info_features.tau2_trackSip3dSig_1; + *(++ptr) = tag_info_features.trackSip3dSig_2; + *(++ptr) = tag_info_features.trackSip3dSig_3; + *(++ptr) = tag_info_features.z_ratio; + } + + void db_tensor_filler(tensorflow::Tensor & tensor, + std::size_t jet_n, + const btagbtvdeep::DeepDoubleCvBFeatures & features) { + + float* ptr = &tensor.tensor()(jet_n, 0, 0); + + // variables from BoostedDoubleSVTagInfo + const auto & tag_info_features = features.tag_info_features; + *ptr = tag_info_features.jetNTracks; + *(++ptr) = tag_info_features.jetNSecondaryVertices; + *(++ptr) = tag_info_features.tau1_trackEtaRel_0; + *(++ptr) = tag_info_features.tau1_trackEtaRel_1; + *(++ptr) = tag_info_features.tau1_trackEtaRel_2; + *(++ptr) = tag_info_features.tau2_trackEtaRel_0; + *(++ptr) = tag_info_features.tau2_trackEtaRel_1; + *(++ptr) = tag_info_features.tau2_trackEtaRel_2; + *(++ptr) = tag_info_features.tau1_flightDistance2dSig; + *(++ptr) = tag_info_features.tau2_flightDistance2dSig; + *(++ptr) = tag_info_features.tau1_vertexDeltaR; + // Note: this variable is not used in the 27-input BDT + // *(++ptr) = tag_info_features.tau2_vertexDeltaR; + *(++ptr) = tag_info_features.tau1_vertexEnergyRatio; + *(++ptr) = tag_info_features.tau2_vertexEnergyRatio; + *(++ptr) = tag_info_features.tau1_vertexMass; + *(++ptr) = tag_info_features.tau2_vertexMass; + *(++ptr) = tag_info_features.trackSip2dSigAboveBottom_0; + *(++ptr) = tag_info_features.trackSip2dSigAboveBottom_1; + *(++ptr) = tag_info_features.trackSip2dSigAboveCharm; + *(++ptr) = tag_info_features.trackSip3dSig_0; + *(++ptr) = tag_info_features.tau1_trackSip3dSig_0; + *(++ptr) = tag_info_features.tau1_trackSip3dSig_1; + *(++ptr) = tag_info_features.trackSip3dSig_1; + *(++ptr) = tag_info_features.tau2_trackSip3dSig_0; + *(++ptr) = tag_info_features.tau2_trackSip3dSig_1; + *(++ptr) = tag_info_features.trackSip3dSig_2; + *(++ptr) = tag_info_features.trackSip3dSig_3; + *(++ptr) = tag_info_features.z_ratio; + } + void c_pf_tensor_filler(tensorflow::Tensor & tensor, std::size_t jet_n, std::size_t c_pf_n, diff --git a/RecoBTag/TensorFlow/test/test_deep_doublec_cfg.py b/RecoBTag/TensorFlow/test/test_deep_doublec_cfg.py new file mode 100644 index 0000000000000..d1bc76c786187 --- /dev/null +++ b/RecoBTag/TensorFlow/test/test_deep_doublec_cfg.py @@ -0,0 +1,90 @@ + +import FWCore.ParameterSet.Config as cms +from PhysicsTools.PatAlgos.tools.helpers import getPatAlgosToolsTask + +process = cms.Process("PATtest") + +## MessageLogger +process.load("FWCore.MessageLogger.MessageLogger_cfi") +process.MessageLogger.cerr.FwkReport.reportEvery = 1000 + + +## Options and Output Report +process.options = cms.untracked.PSet( wantSummary = cms.untracked.bool(True) ) + +## Source +process.source = cms.Source("PoolSource", + fileNames = cms.untracked.vstring() +) +## Maximal Number of Events +process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(-1) ) + +## Geometry and Detector Conditions (needed for a few patTuple production steps) +process.load("Configuration.Geometry.GeometryRecoDB_cff") +process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff") +from Configuration.AlCa.GlobalTag import GlobalTag +process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run2_mc') +process.load("Configuration.StandardSequences.MagneticField_cff") + +## Output Module Configuration (expects a path 'p') +from PhysicsTools.PatAlgos.patEventContent_cff import patEventContentNoCleaning +process.out = cms.OutputModule("PoolOutputModule", + fileName = cms.untracked.string('patTuple.root'), + ## save only events passing the full path + #SelectEvents = cms.untracked.PSet( SelectEvents = cms.vstring('p') ), + ## save PAT output; you need a '*' to unpack the list of commands + ## 'patEventContent' + outputCommands = cms.untracked.vstring('drop *', *patEventContentNoCleaning ) + ) + +patAlgosToolsTask = getPatAlgosToolsTask(process) +process.outpath = cms.EndPath(process.out, patAlgosToolsTask) + +## and add them to the event content +from PhysicsTools.PatAlgos.tools.jetTools import updateJetCollection + +updateJetCollection( + process, + jetSource = cms.InputTag('slimmedJetsAK8'), + pvSource = cms.InputTag('offlineSlimmedPrimaryVertices'), + svSource = cms.InputTag('slimmedSecondaryVertices'), + rParam = 0.8, + jetCorrections = ('AK8PFchs', cms.vstring(['L2Relative', 'L3Absolute']), 'None'), + btagDiscriminators = [ + 'pfBoostedDoubleSecondaryVertexAK8BJetTags', + 'pfDeepDoubleBJetTags:probQ', + 'pfDeepDoubleBJetTags:probH', + 'pfDeepDoubleCvLJetTags:probQCD', + 'pfDeepDoubleCvLJetTags:probHcc', + 'pfDeepDoubleCvBJetTags:probHbb', + 'pfDeepDoubleCvBJetTags:probHcc' + ] + ) + +from PhysicsTools.PatAlgos.patInputFiles_cff import filesRelValTTbarPileUpMINIAODSIM + +process.source.fileNames = filesRelValTTbarPileUpMINIAODSIM +process.source.fileNames = cms.untracked.vstring( +'root://cmsxrootd.fnal.gov//store/mc/RunIIFall17MiniAOD/GluGluHToBB_M125_13TeV_powheg_pythia8/MINIAODSIM/94X_mc2017_realistic_v10-v1/20000/C8932584-5006-E811-9840-141877410512.root', +#'root://cmsxrootd.fnal.gov//store/mc/RunIIFall17MiniAODv2/GluGluHToCC_M125_13TeV_powheg_pythia8/MINIAODSIM/PU2017_12Apr2018_94X_mc2017_realistic_v14-v2/30000/72164088-CB67-E811-9D0D-008CFA197AC4.root', +#'root://cmsxrootd.fnal.gov//store/mc/RunIIFall17MiniAOD/QCD_HT700to1000_TuneCP5_13TeV-madgraph-pythia8/MINIAODSIM/94X_mc2017_realistic_v10-v1/20000/C0F304A4-23FA-E711-942E-E0071B6CAD20.root' +) +process.maxEvents.input = 1000 + +from Configuration.EventContent.EventContent_cff import MINIAODSIMEventContent +process.out.outputCommands.append('keep *_slimmedJetsAK8*_*_*') +process.out.outputCommands.append('keep *_offlineSlimmedPrimaryVertices*_*_*') +process.out.outputCommands.append('keep *_slimmedSecondaryVertices*_*_*') +process.out.outputCommands.append('keep *_selectedPatJets*_*_*') +process.out.outputCommands.append('keep *_selectedUpdatedPatJets*_*_*') +process.out.outputCommands.append('keep *_pfBoostedDoubleSVAK8TagInfos*_*_*') +process.out.outputCommands.append('keep *_pfDeepDoubleBTagInfos*_*_*') +process.out.outputCommands.append('keep *_pfDeepDoubleCvLTagInfos*_*_*') +process.out.outputCommands.append('keep *_pfDeepDoubleCvBTagInfos*_*_*') +process.out.outputCommands.append('keep *_updatedPatJets*_*_*') + +process.out.fileName = 'output_test_DDX.root' + +# ## +# process.options.wantSummary = False ## (to suppress the long output at the end of the job) +# process.add_(cms.Service("InitRootHandlers", DebugLevel =cms.untracked.int32(3))) From 40f86077c73aa88e0ec4b3f0c8271dbbc6526834 Mon Sep 17 00:00:00 2001 From: anovak10 Date: Wed, 17 Oct 2018 18:15:39 +0200 Subject: [PATCH 02/30] Fixing modules --- .../plugins/DeepDoubleCvBTagInfoProducer.cc | 349 ------------------ .../plugins/DeepDoubleCvLTagInfoProducer.cc | 349 ------------------ .../TensorFlow/test/test_deep_doublec_cfg.py | 3 +- 3 files changed, 2 insertions(+), 699 deletions(-) delete mode 100644 RecoBTag/TensorFlow/plugins/DeepDoubleCvBTagInfoProducer.cc delete mode 100644 RecoBTag/TensorFlow/plugins/DeepDoubleCvLTagInfoProducer.cc diff --git a/RecoBTag/TensorFlow/plugins/DeepDoubleCvBTagInfoProducer.cc b/RecoBTag/TensorFlow/plugins/DeepDoubleCvBTagInfoProducer.cc deleted file mode 100644 index 8946fa8eddbd1..0000000000000 --- a/RecoBTag/TensorFlow/plugins/DeepDoubleCvBTagInfoProducer.cc +++ /dev/null @@ -1,349 +0,0 @@ - -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/stream/EDProducer.h" - -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" - -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/Utilities/interface/StreamID.h" - -#include "DataFormats/Candidate/interface/Candidate.h" - -#include "DataFormats/PatCandidates/interface/Jet.h" -#include "DataFormats/PatCandidates/interface/PackedCandidate.h" - -#include "DataFormats/BTauReco/interface/BoostedDoubleSVTagInfo.h" - -#include "TrackingTools/Records/interface/TransientTrackRecord.h" -#include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h" - -#include "DataFormats/BTauReco/interface/DeepDoubleCvBFeatures.h" -#include "DataFormats/BTauReco/interface/DeepDoubleCvBTagInfo.h" - -#include "RecoBTag/TensorFlow/interface/BoostedDoubleSVTagInfoConverter.h" -#include "RecoBTag/TensorFlow/interface/ChargedCandidateConverter.h" -#include "RecoBTag/TensorFlow/interface/JetConverter.h" -#include "RecoBTag/TensorFlow/interface/SecondaryVertexConverter.h" - -#include "RecoBTag/TensorFlow/interface/TrackInfoBuilder.h" -#include "RecoBTag/TensorFlow/interface/sorting_modules.h" - -#include "DataFormats/Candidate/interface/VertexCompositePtrCandidate.h" -#include "DataFormats/VertexReco/interface/VertexFwd.h" - -#include "RecoBTag/TensorFlow/interface/deep_helpers.h" - -class DeepDoubleCvBTagInfoProducer : public edm::stream::EDProducer<> -{ - -public: - explicit DeepDoubleCvBTagInfoProducer(const edm::ParameterSet&); - ~DeepDoubleCvBTagInfoProducer() override; - - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - -private: - typedef std::vector DeepDoubleCvBTagInfoCollection; - typedef reco::VertexCompositePtrCandidateCollection SVCollection; - typedef reco::VertexCollection VertexCollection; - typedef edm::View - BoostedDoubleSVTagInfoCollection; - - void beginStream(edm::StreamID) override - { - } - void produce(edm::Event&, const edm::EventSetup&) override; - void endStream() override - { - } - - const double jet_radius_; - const double min_candidate_pt_; - - edm::EDGetTokenT> jet_token_; - edm::EDGetTokenT vtx_token_; - edm::EDGetTokenT sv_token_; - edm::EDGetTokenT shallow_tag_info_token_; -}; - -DeepDoubleCvBTagInfoProducer::DeepDoubleCvBTagInfoProducer( - const edm::ParameterSet& iConfig) - : jet_radius_(iConfig.getParameter("jet_radius")) - , min_candidate_pt_(iConfig.getParameter("min_candidate_pt")) - , jet_token_(consumes>( - iConfig.getParameter("jets"))) - , vtx_token_(consumes( - iConfig.getParameter("vertices"))) - , sv_token_(consumes( - iConfig.getParameter("secondary_vertices"))) - , shallow_tag_info_token_(consumes( - iConfig.getParameter("shallow_tag_infos"))) -{ - produces(); -} - -DeepDoubleCvBTagInfoProducer::~DeepDoubleCvBTagInfoProducer() -{ -} - -void DeepDoubleCvBTagInfoProducer::fillDescriptions( - edm::ConfigurationDescriptions& descriptions) -{ - // pfDeepDoubleCvBTagInfos - edm::ParameterSetDescription desc; - desc.add("shallow_tag_infos", - edm::InputTag("pfBoostedDoubleSVAK8TagInfos")); - desc.add("jet_radius", 0.8); - desc.add("min_candidate_pt", 0.95); - desc.add("vertices", edm::InputTag("offlinePrimaryVertices")); - desc.add("secondary_vertices", - edm::InputTag("inclusiveCandidateSecondaryVertices")); - desc.add("jets", edm::InputTag("ak8PFJetsCHS")); - descriptions.add("pfDeepDoubleCvBTagInfos", desc); -} - -void DeepDoubleCvBTagInfoProducer::produce(edm::Event& iEvent, - const edm::EventSetup& iSetup) -{ - - auto output_tag_infos = std::make_unique(); - - edm::Handle> jets; - iEvent.getByToken(jet_token_, jets); - - edm::Handle vtxs; - iEvent.getByToken(vtx_token_, vtxs); - if (vtxs->empty()) - { - // produce empty TagInfos in case no primary vertex - iEvent.put(std::move(output_tag_infos)); - return; // exit event - } - // reference to primary vertex - const auto& pv = vtxs->at(0); - - edm::Handle svs; - iEvent.getByToken(sv_token_, svs); - - edm::Handle shallow_tag_infos; - iEvent.getByToken(shallow_tag_info_token_, shallow_tag_infos); - - edm::ESHandle track_builder; - iSetup.get().get("TransientTrackBuilder", - track_builder); - - for (std::size_t jet_n = 0; jet_n < jets->size(); jet_n++) - { - - // create data containing structure - btagbtvdeep::DeepDoubleCvBFeatures features; - - // reco jet reference (use as much as possible) - const auto& jet = jets->at(jet_n); - edm::RefToBase jet_ref(jets, jet_n); - // TagInfoCollection not in an associative container so search for matchs - const edm::View& taginfos = *shallow_tag_infos; - edm::Ptr match; - // Try first by 'same index' - if ((jet_n < taginfos.size()) && (taginfos[jet_n].jet() == jet_ref)) - { - match = taginfos.ptrAt(jet_n); - } - else - { - // otherwise fall back to a simple search - for (auto itTI = taginfos.begin(), edTI = taginfos.end(); itTI != edTI; - ++itTI) - { - if (itTI->jet() == jet_ref) - { - match = taginfos.ptrAt(itTI - taginfos.begin()); - break; - } - } - } - reco::BoostedDoubleSVTagInfo tag_info; - if (match.isNonnull()) - { - tag_info = *match; - } // will be default values otherwise - - // fill basic jet features - btagbtvdeep::JetConverter::jetToFeatures(jet, features.jet_features); - - // fill number of pv - features.npv = vtxs->size(); - - // fill features from BoostedDoubleSVTagInfo - const auto& tag_info_vars = tag_info.taggingVariables(); - btagbtvdeep::doubleBTagToFeatures(tag_info_vars, - features.tag_info_features); - - // copy which will be sorted - auto svs_sorted = *svs; - // sort by dxy - std::sort(svs_sorted.begin(), svs_sorted.end(), - [&pv](const auto& sva, const auto& svb) { - 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; - 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); - } - } - - // 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> c_sorted; - - // to cache the TrackInfo - std::map trackinfos; - - // unsorted reference to sv - const auto& svs_unsorted = *svs; - // fill collection, from DeepTNtuples plus some styling - // std::vector daughters; - std::vector daughters; - for (unsigned int i = 0; i < jet.numberOfDaughters(); i++) - { - auto const* cand = jet.daughter(i); - auto packed_cand = dynamic_cast(cand); - auto reco_cand = dynamic_cast(cand); - if (packed_cand) - { - if (cand->numberOfDaughters() > 0) - { - for (unsigned int k = 0; k < cand->numberOfDaughters(); k++) - { - daughters.push_back( - dynamic_cast(cand->daughter(k))); - } - } - else - { - auto packed_cand = dynamic_cast(cand); - daughters.push_back(packed_cand); - } - } - else if (reco_cand) - { - // need some edm::Ptr or edm::Ref if reco candidates - // dynamical casting to pointers, null if not possible - daughters.push_back(reco_cand); - } - } - - for (unsigned int i = 0; i < daughters.size(); i++) - { - auto const* cand = daughters.at(i); - - if (cand) - { - // candidates under 950MeV (configurable) are not considered - // might change if we use also white-listing - if (cand->pt() < min_candidate_pt_) - continue; - if (cand->charge() != 0) - { - auto& trackinfo = trackinfos.emplace(i, track_builder).first->second; - trackinfo.buildTrackInfo(cand, jet_dir, jet_ref_track_dir, pv); - c_sorted.emplace_back( - i, trackinfo.getTrackSip2dSig(), - -btagbtvdeep::mindrsvpfcand(svs_unsorted, cand, jet_radius_), - cand->pt() / jet.pt()); - } - } - } - - // sort collections (open the black-box if you please) - std::sort(c_sorted.begin(), c_sorted.end(), - btagbtvdeep::SortingClass::compareByABCInv); - - std::vector c_sortedindices; - - // this puts 0 everywhere and the right position in ind - c_sortedindices = btagbtvdeep::invertSortingVector(c_sorted); - - // set right size to vectors - features.c_pf_features.clear(); - features.c_pf_features.resize(c_sorted.size()); - - for (unsigned int i = 0; i < daughters.size(); i++) - { - auto const* cand = daughters.at(i); - if (cand) - { - // candidates under 950MeV are not considered - // might change if we use also white-listing - if (cand->pt() < 0.95) - continue; - - // get PUPPI weight from value map - float puppiw = 1.0; // fallback value - - float drminpfcandsv = btagbtvdeep::mindrsvpfcand(svs_unsorted, cand, jet_radius_); - - if (cand->charge() != 0) - { - // is charged candidate - auto entry = c_sortedindices.at(i); - // get cached track info - auto& trackinfo = trackinfos.at(i); - // get_ref to vector element - auto& c_pf_features = features.c_pf_features.at(entry); - // fill feature structure - auto packed_cand = dynamic_cast(cand); - auto reco_cand = dynamic_cast(cand); - if (packed_cand) - { - btagbtvdeep::packedCandidateToFeatures( - packed_cand, jet, trackinfo, drminpfcandsv, - static_cast(jet_radius_), c_pf_features); - } - else if (reco_cand) - { - // get vertex association quality - int pv_ass_quality = 0; // fallback value - // getting the PV as PackedCandidatesProducer - // but using not the slimmed but original vertices - auto ctrack = reco_cand->bestTrack(); - int pvi = -1; - float dist = 1e99; - for (size_t ii = 0; ii < vtxs->size(); ii++) - { - float dz = (ctrack) ? std::abs(ctrack->dz(((*vtxs)[ii]).position())) : 0; - if (dz < dist) - { - pvi = ii; - dist = dz; - } - } - auto pv = reco::VertexRef(vtxs, pvi); - btagbtvdeep::recoCandidateToFeatures( - reco_cand, jet, trackinfo, drminpfcandsv, - static_cast(jet_radius_), puppiw, pv_ass_quality, pv, - c_pf_features); - } - } - } - } - - output_tag_infos->emplace_back(features, jet_ref); - } - - iEvent.put(std::move(output_tag_infos)); -} - -// define this as a plug-in -DEFINE_FWK_MODULE(DeepDoubleCvBTagInfoProducer); diff --git a/RecoBTag/TensorFlow/plugins/DeepDoubleCvLTagInfoProducer.cc b/RecoBTag/TensorFlow/plugins/DeepDoubleCvLTagInfoProducer.cc deleted file mode 100644 index e683dfe76470e..0000000000000 --- a/RecoBTag/TensorFlow/plugins/DeepDoubleCvLTagInfoProducer.cc +++ /dev/null @@ -1,349 +0,0 @@ - -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/stream/EDProducer.h" - -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" - -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/Utilities/interface/StreamID.h" - -#include "DataFormats/Candidate/interface/Candidate.h" - -#include "DataFormats/PatCandidates/interface/Jet.h" -#include "DataFormats/PatCandidates/interface/PackedCandidate.h" - -#include "DataFormats/BTauReco/interface/BoostedDoubleSVTagInfo.h" - -#include "TrackingTools/Records/interface/TransientTrackRecord.h" -#include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h" - -#include "DataFormats/BTauReco/interface/DeepDoubleCvLFeatures.h" -#include "DataFormats/BTauReco/interface/DeepDoubleCvLTagInfo.h" - -#include "RecoBTag/TensorFlow/interface/BoostedDoubleSVTagInfoConverter.h" -#include "RecoBTag/TensorFlow/interface/ChargedCandidateConverter.h" -#include "RecoBTag/TensorFlow/interface/JetConverter.h" -#include "RecoBTag/TensorFlow/interface/SecondaryVertexConverter.h" - -#include "RecoBTag/TensorFlow/interface/TrackInfoBuilder.h" -#include "RecoBTag/TensorFlow/interface/sorting_modules.h" - -#include "DataFormats/Candidate/interface/VertexCompositePtrCandidate.h" -#include "DataFormats/VertexReco/interface/VertexFwd.h" - -#include "RecoBTag/TensorFlow/interface/deep_helpers.h" - -class DeepDoubleCvLTagInfoProducer : public edm::stream::EDProducer<> -{ - -public: - explicit DeepDoubleCvLTagInfoProducer(const edm::ParameterSet&); - ~DeepDoubleCvLTagInfoProducer() override; - - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - -private: - typedef std::vector DeepDoubleCvLTagInfoCollection; - typedef reco::VertexCompositePtrCandidateCollection SVCollection; - typedef reco::VertexCollection VertexCollection; - typedef edm::View - BoostedDoubleSVTagInfoCollection; - - void beginStream(edm::StreamID) override - { - } - void produce(edm::Event&, const edm::EventSetup&) override; - void endStream() override - { - } - - const double jet_radius_; - const double min_candidate_pt_; - - edm::EDGetTokenT> jet_token_; - edm::EDGetTokenT vtx_token_; - edm::EDGetTokenT sv_token_; - edm::EDGetTokenT shallow_tag_info_token_; -}; - -DeepDoubleCvLTagInfoProducer::DeepDoubleCvLTagInfoProducer( - const edm::ParameterSet& iConfig) - : jet_radius_(iConfig.getParameter("jet_radius")) - , min_candidate_pt_(iConfig.getParameter("min_candidate_pt")) - , jet_token_(consumes>( - iConfig.getParameter("jets"))) - , vtx_token_(consumes( - iConfig.getParameter("vertices"))) - , sv_token_(consumes( - iConfig.getParameter("secondary_vertices"))) - , shallow_tag_info_token_(consumes( - iConfig.getParameter("shallow_tag_infos"))) -{ - produces(); -} - -DeepDoubleCvLTagInfoProducer::~DeepDoubleCvLTagInfoProducer() -{ -} - -void DeepDoubleCvLTagInfoProducer::fillDescriptions( - edm::ConfigurationDescriptions& descriptions) -{ - // pfDeepDoubleCvLTagInfos - edm::ParameterSetDescription desc; - desc.add("shallow_tag_infos", - edm::InputTag("pfBoostedDoubleSVAK8TagInfos")); - desc.add("jet_radius", 0.8); - desc.add("min_candidate_pt", 0.95); - desc.add("vertices", edm::InputTag("offlinePrimaryVertices")); - desc.add("secondary_vertices", - edm::InputTag("inclusiveCandidateSecondaryVertices")); - desc.add("jets", edm::InputTag("ak8PFJetsCHS")); - descriptions.add("pfDeepDoubleCvLTagInfos", desc); -} - -void DeepDoubleCvLTagInfoProducer::produce(edm::Event& iEvent, - const edm::EventSetup& iSetup) -{ - - auto output_tag_infos = std::make_unique(); - - edm::Handle> jets; - iEvent.getByToken(jet_token_, jets); - - edm::Handle vtxs; - iEvent.getByToken(vtx_token_, vtxs); - if (vtxs->empty()) - { - // produce empty TagInfos in case no primary vertex - iEvent.put(std::move(output_tag_infos)); - return; // exit event - } - // reference to primary vertex - const auto& pv = vtxs->at(0); - - edm::Handle svs; - iEvent.getByToken(sv_token_, svs); - - edm::Handle shallow_tag_infos; - iEvent.getByToken(shallow_tag_info_token_, shallow_tag_infos); - - edm::ESHandle track_builder; - iSetup.get().get("TransientTrackBuilder", - track_builder); - - for (std::size_t jet_n = 0; jet_n < jets->size(); jet_n++) - { - - // create data containing structure - btagbtvdeep::DeepDoubleCvLFeatures features; - - // reco jet reference (use as much as possible) - const auto& jet = jets->at(jet_n); - edm::RefToBase jet_ref(jets, jet_n); - // TagInfoCollection not in an associative container so search for matchs - const edm::View& taginfos = *shallow_tag_infos; - edm::Ptr match; - // Try first by 'same index' - if ((jet_n < taginfos.size()) && (taginfos[jet_n].jet() == jet_ref)) - { - match = taginfos.ptrAt(jet_n); - } - else - { - // otherwise fall back to a simple search - for (auto itTI = taginfos.begin(), edTI = taginfos.end(); itTI != edTI; - ++itTI) - { - if (itTI->jet() == jet_ref) - { - match = taginfos.ptrAt(itTI - taginfos.begin()); - break; - } - } - } - reco::BoostedDoubleSVTagInfo tag_info; - if (match.isNonnull()) - { - tag_info = *match; - } // will be default values otherwise - - // fill basic jet features - btagbtvdeep::JetConverter::jetToFeatures(jet, features.jet_features); - - // fill number of pv - features.npv = vtxs->size(); - - // fill features from BoostedDoubleSVTagInfo - const auto& tag_info_vars = tag_info.taggingVariables(); - btagbtvdeep::doubleBTagToFeatures(tag_info_vars, - features.tag_info_features); - - // copy which will be sorted - auto svs_sorted = *svs; - // sort by dxy - std::sort(svs_sorted.begin(), svs_sorted.end(), - [&pv](const auto& sva, const auto& svb) { - 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; - 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); - } - } - - // 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> c_sorted; - - // to cache the TrackInfo - std::map trackinfos; - - // unsorted reference to sv - const auto& svs_unsorted = *svs; - // fill collection, from DeepTNtuples plus some styling - // std::vector daughters; - std::vector daughters; - for (unsigned int i = 0; i < jet.numberOfDaughters(); i++) - { - auto const* cand = jet.daughter(i); - auto packed_cand = dynamic_cast(cand); - auto reco_cand = dynamic_cast(cand); - if (packed_cand) - { - if (cand->numberOfDaughters() > 0) - { - for (unsigned int k = 0; k < cand->numberOfDaughters(); k++) - { - daughters.push_back( - dynamic_cast(cand->daughter(k))); - } - } - else - { - auto packed_cand = dynamic_cast(cand); - daughters.push_back(packed_cand); - } - } - else if (reco_cand) - { - // need some edm::Ptr or edm::Ref if reco candidates - // dynamical casting to pointers, null if not possible - daughters.push_back(reco_cand); - } - } - - for (unsigned int i = 0; i < daughters.size(); i++) - { - auto const* cand = daughters.at(i); - - if (cand) - { - // candidates under 950MeV (configurable) are not considered - // might change if we use also white-listing - if (cand->pt() < min_candidate_pt_) - continue; - if (cand->charge() != 0) - { - auto& trackinfo = trackinfos.emplace(i, track_builder).first->second; - trackinfo.buildTrackInfo(cand, jet_dir, jet_ref_track_dir, pv); - c_sorted.emplace_back( - i, trackinfo.getTrackSip2dSig(), - -btagbtvdeep::mindrsvpfcand(svs_unsorted, cand, jet_radius_), - cand->pt() / jet.pt()); - } - } - } - - // sort collections (open the black-box if you please) - std::sort(c_sorted.begin(), c_sorted.end(), - btagbtvdeep::SortingClass::compareByABCInv); - - std::vector c_sortedindices; - - // this puts 0 everywhere and the right position in ind - c_sortedindices = btagbtvdeep::invertSortingVector(c_sorted); - - // set right size to vectors - features.c_pf_features.clear(); - features.c_pf_features.resize(c_sorted.size()); - - for (unsigned int i = 0; i < daughters.size(); i++) - { - auto const* cand = daughters.at(i); - if (cand) - { - // candidates under 950MeV are not considered - // might change if we use also white-listing - if (cand->pt() < 0.95) - continue; - - // get PUPPI weight from value map - float puppiw = 1.0; // fallback value - - float drminpfcandsv = btagbtvdeep::mindrsvpfcand(svs_unsorted, cand, jet_radius_); - - if (cand->charge() != 0) - { - // is charged candidate - auto entry = c_sortedindices.at(i); - // get cached track info - auto& trackinfo = trackinfos.at(i); - // get_ref to vector element - auto& c_pf_features = features.c_pf_features.at(entry); - // fill feature structure - auto packed_cand = dynamic_cast(cand); - auto reco_cand = dynamic_cast(cand); - if (packed_cand) - { - btagbtvdeep::packedCandidateToFeatures( - packed_cand, jet, trackinfo, drminpfcandsv, - static_cast(jet_radius_), c_pf_features); - } - else if (reco_cand) - { - // get vertex association quality - int pv_ass_quality = 0; // fallback value - // getting the PV as PackedCandidatesProducer - // but using not the slimmed but original vertices - auto ctrack = reco_cand->bestTrack(); - int pvi = -1; - float dist = 1e99; - for (size_t ii = 0; ii < vtxs->size(); ii++) - { - float dz = (ctrack) ? std::abs(ctrack->dz(((*vtxs)[ii]).position())) : 0; - if (dz < dist) - { - pvi = ii; - dist = dz; - } - } - auto pv = reco::VertexRef(vtxs, pvi); - btagbtvdeep::recoCandidateToFeatures( - reco_cand, jet, trackinfo, drminpfcandsv, - static_cast(jet_radius_), puppiw, pv_ass_quality, pv, - c_pf_features); - } - } - } - } - - output_tag_infos->emplace_back(features, jet_ref); - } - - iEvent.put(std::move(output_tag_infos)); -} - -// define this as a plug-in -DEFINE_FWK_MODULE(DeepDoubleCvLTagInfoProducer); diff --git a/RecoBTag/TensorFlow/test/test_deep_doublec_cfg.py b/RecoBTag/TensorFlow/test/test_deep_doublec_cfg.py index d1bc76c786187..245f4a5725396 100644 --- a/RecoBTag/TensorFlow/test/test_deep_doublec_cfg.py +++ b/RecoBTag/TensorFlow/test/test_deep_doublec_cfg.py @@ -65,7 +65,8 @@ process.source.fileNames = filesRelValTTbarPileUpMINIAODSIM process.source.fileNames = cms.untracked.vstring( -'root://cmsxrootd.fnal.gov//store/mc/RunIIFall17MiniAOD/GluGluHToBB_M125_13TeV_powheg_pythia8/MINIAODSIM/94X_mc2017_realistic_v10-v1/20000/C8932584-5006-E811-9840-141877410512.root', +'root://cmsxrootd.fnal.gov//store/relval/CMSSW_10_3_0_pre2/RelValTTbar_13/MINIAODSIM/PU25ns_103X_upgrade2018_realistic_v2-v1/20000/85820ACA-657B-BC44-AC74-AACD6D54B348.root' +#'root://cmsxrootd.fnal.gov//store/mc/RunIIFall17MiniAOD/GluGluHToBB_M125_13TeV_powheg_pythia8/MINIAODSIM/94X_mc2017_realistic_v10-v1/20000/C8932584-5006-E811-9840-141877410512.root', #'root://cmsxrootd.fnal.gov//store/mc/RunIIFall17MiniAODv2/GluGluHToCC_M125_13TeV_powheg_pythia8/MINIAODSIM/PU2017_12Apr2018_94X_mc2017_realistic_v14-v2/30000/72164088-CB67-E811-9D0D-008CFA197AC4.root', #'root://cmsxrootd.fnal.gov//store/mc/RunIIFall17MiniAOD/QCD_HT700to1000_TuneCP5_13TeV-madgraph-pythia8/MINIAODSIM/94X_mc2017_realistic_v10-v1/20000/C0F304A4-23FA-E711-942E-E0071B6CAD20.root' ) From 9a49df94e03cea9e1a374cd0faa9dc0b824201e9 Mon Sep 17 00:00:00 2001 From: anovak10 Date: Fri, 26 Oct 2018 16:39:46 +0200 Subject: [PATCH 03/30] Removing redundant --- .../interface/DeepDoubleCvBFeatures.h | 29 -- .../BTauReco/interface/DeepDoubleCvBTagInfo.h | 19 - .../interface/DeepDoubleCvLFeatures.h | 29 -- .../BTauReco/interface/DeepDoubleCvLTagInfo.h | 19 - DataFormats/BTauReco/src/classes.h | 22 -- DataFormats/BTauReco/src/classes_def.xml | 22 -- .../python/recoLayer0/bTagging_cff.py | 8 +- .../PatAlgos/python/tools/jetTools.py | 4 +- .../plugins/DeepDoubleCvBTagInfoProducer.cc | 349 ------------------ .../plugins/DeepDoubleCvLTagInfoProducer.cc | 349 ------------------ .../TensorFlow/interface/tensor_fillers.h | 8 +- .../plugins/DeepDoubleCvBTFJetTagsProducer.cc | 9 +- .../plugins/DeepDoubleCvLTFJetTagsProducer.cc | 9 +- .../TensorFlow/python/pfDeepFlavour_cff.py | 4 +- RecoBTag/TensorFlow/src/tensor_fillers.cc | 4 +- .../TensorFlow/test/test_deep_doublec_cfg.py | 6 +- 16 files changed, 28 insertions(+), 862 deletions(-) delete mode 100644 DataFormats/BTauReco/interface/DeepDoubleCvBFeatures.h delete mode 100644 DataFormats/BTauReco/interface/DeepDoubleCvBTagInfo.h delete mode 100644 DataFormats/BTauReco/interface/DeepDoubleCvLFeatures.h delete mode 100644 DataFormats/BTauReco/interface/DeepDoubleCvLTagInfo.h delete mode 100644 RecoBTag/FeatureTools/plugins/DeepDoubleCvBTagInfoProducer.cc delete mode 100644 RecoBTag/FeatureTools/plugins/DeepDoubleCvLTagInfoProducer.cc diff --git a/DataFormats/BTauReco/interface/DeepDoubleCvBFeatures.h b/DataFormats/BTauReco/interface/DeepDoubleCvBFeatures.h deleted file mode 100644 index 741829659bbc6..0000000000000 --- a/DataFormats/BTauReco/interface/DeepDoubleCvBFeatures.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef DataFormats_BTauReco_DeepDoubleCvBFeatures_h -#define DataFormats_BTauReco_DeepDoubleCvBFeatures_h - -#include - -#include "DataFormats/BTauReco/interface/JetFeatures.h" -#include "DataFormats/BTauReco/interface/SecondaryVertexFeatures.h" -#include "DataFormats/BTauReco/interface/BoostedDoubleSVTagInfoFeatures.h" -#include "DataFormats/BTauReco/interface/ChargedCandidateFeatures.h" - -namespace btagbtvdeep { - -class DeepDoubleCvBFeatures { - - public: - JetFeatures jet_features; - BoostedDoubleSVTagInfoFeatures tag_info_features; - - std::vector sv_features; - - std::vector c_pf_features; - - std::size_t npv; // used by deep flavour -}; - - -} - -#endif //DataFormats_BTauReco_DeepDoubleCvBFeatures_h diff --git a/DataFormats/BTauReco/interface/DeepDoubleCvBTagInfo.h b/DataFormats/BTauReco/interface/DeepDoubleCvBTagInfo.h deleted file mode 100644 index f4fcde11b51bf..0000000000000 --- a/DataFormats/BTauReco/interface/DeepDoubleCvBTagInfo.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef DataFormats_BTauReco_DeepDoubleCvBTagInfo_h -#define DataFormats_BTauReco_DeepDoubleCvBTagInfo_h - -#include "DataFormats/Common/interface/CMS_CLASS_VERSION.h" -#include "DataFormats/BTauReco/interface/BaseTagInfo.h" -#include "DataFormats/BTauReco/interface/DeepFlavourTagInfo.h" -#include "DataFormats/BTauReco/interface/DeepDoubleCvBFeatures.h" - -#include "DataFormats/PatCandidates/interface/Jet.h" - -namespace reco { - -typedef FeaturesTagInfo DeepDoubleCvBTagInfo; - -DECLARE_EDM_REFS( DeepDoubleCvBTagInfo ) - -} - -#endif // DataFormats_BTauReco_DeepDoubleCvBTagInfo_h diff --git a/DataFormats/BTauReco/interface/DeepDoubleCvLFeatures.h b/DataFormats/BTauReco/interface/DeepDoubleCvLFeatures.h deleted file mode 100644 index 1c008534b088f..0000000000000 --- a/DataFormats/BTauReco/interface/DeepDoubleCvLFeatures.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef DataFormats_BTauReco_DeepDoubleCvLFeatures_h -#define DataFormats_BTauReco_DeepDoubleCvLFeatures_h - -#include - -#include "DataFormats/BTauReco/interface/JetFeatures.h" -#include "DataFormats/BTauReco/interface/SecondaryVertexFeatures.h" -#include "DataFormats/BTauReco/interface/BoostedDoubleSVTagInfoFeatures.h" -#include "DataFormats/BTauReco/interface/ChargedCandidateFeatures.h" - -namespace btagbtvdeep { - -class DeepDoubleCvLFeatures { - - public: - JetFeatures jet_features; - BoostedDoubleSVTagInfoFeatures tag_info_features; - - std::vector sv_features; - - std::vector c_pf_features; - - std::size_t npv; // used by deep flavour -}; - - -} - -#endif //DataFormats_BTauReco_DeepDoubleCvLFeatures_h diff --git a/DataFormats/BTauReco/interface/DeepDoubleCvLTagInfo.h b/DataFormats/BTauReco/interface/DeepDoubleCvLTagInfo.h deleted file mode 100644 index 2aaef32888040..0000000000000 --- a/DataFormats/BTauReco/interface/DeepDoubleCvLTagInfo.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef DataFormats_BTauReco_DeepDoubleCvLTagInfo_h -#define DataFormats_BTauReco_DeepDoubleCvLTagInfo_h - -#include "DataFormats/Common/interface/CMS_CLASS_VERSION.h" -#include "DataFormats/BTauReco/interface/BaseTagInfo.h" -#include "DataFormats/BTauReco/interface/DeepFlavourTagInfo.h" -#include "DataFormats/BTauReco/interface/DeepDoubleCvLFeatures.h" - -#include "DataFormats/PatCandidates/interface/Jet.h" - -namespace reco { - -typedef FeaturesTagInfo DeepDoubleCvLTagInfo; - -DECLARE_EDM_REFS( DeepDoubleCvLTagInfo ) - -} - -#endif // DataFormats_BTauReco_DeepDoubleCvLTagInfo_h diff --git a/DataFormats/BTauReco/src/classes.h b/DataFormats/BTauReco/src/classes.h index 9c8b6a36b4192..fbf1a37a801fc 100755 --- a/DataFormats/BTauReco/src/classes.h +++ b/DataFormats/BTauReco/src/classes.h @@ -56,10 +56,6 @@ #include "DataFormats/BTauReco/interface/DeepFlavourTagInfo.h" #include "DataFormats/BTauReco/interface/DeepDoubleBFeatures.h" #include "DataFormats/BTauReco/interface/DeepDoubleBTagInfo.h" -#include "DataFormats/BTauReco/interface/DeepDoubleCvLFeatures.h" -#include "DataFormats/BTauReco/interface/DeepDoubleCvLTagInfo.h" -#include "DataFormats/BTauReco/interface/DeepDoubleCvBFeatures.h" -#include "DataFormats/BTauReco/interface/DeepDoubleCvBTagInfo.h" #include "DataFormats/BTauReco/interface/DeepBoostedJetTagInfo.h" @@ -432,24 +428,6 @@ namespace DataFormats_BTauReco { reco::DeepDoubleBTagInfoRefVector deep_doubleb_tag_info_collection_ref_vector; edm::Wrapper deep_doubleb_tag_info_collection_edm_wrapper; - btagbtvdeep::DeepDoubleCvLFeatures deep_doublecvl_features; - reco::DeepDoubleCvLTagInfo deep_doublecvl_tag_info; - reco::DeepDoubleCvLTagInfoCollection deep_doublecvl_tag_info_collection; - reco::DeepDoubleCvLTagInfoRef deep_doublecvl_tag_info_collection_ref; - reco::DeepDoubleCvLTagInfoFwdRef deep_doublecvl_tag_info_collection_fwd_ref; - reco::DeepDoubleCvLTagInfoRefProd deep_doublecvl_tag_info_collection_ref_prod; - reco::DeepDoubleCvLTagInfoRefVector deep_doublecvl_tag_info_collection_ref_vector; - edm::Wrapper deep_doublecvl_tag_info_collection_edm_wrapper; - - btagbtvdeep::DeepDoubleCvBFeatures deep_doublecvb_features; - reco::DeepDoubleCvBTagInfo deep_doublecvb_tag_info; - reco::DeepDoubleCvBTagInfoCollection deep_doublecvb_tag_info_collection; - reco::DeepDoubleCvBTagInfoRef deep_doublecvb_tag_info_collection_ref; - reco::DeepDoubleCvBTagInfoFwdRef deep_doublecvb_tag_info_collection_fwd_ref; - reco::DeepDoubleCvBTagInfoRefProd deep_doublecvb_tag_info_collection_ref_prod; - reco::DeepDoubleCvBTagInfoRefVector deep_doublecvb_tag_info_collection_ref_vector; - edm::Wrapper deep_doublecvb_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; diff --git a/DataFormats/BTauReco/src/classes_def.xml b/DataFormats/BTauReco/src/classes_def.xml index 35fb567cc514a..96afe58e09a12 100644 --- a/DataFormats/BTauReco/src/classes_def.xml +++ b/DataFormats/BTauReco/src/classes_def.xml @@ -450,12 +450,6 @@ - - - - - - @@ -477,22 +471,6 @@ - - - - - - - - - - - - - - - - diff --git a/PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py b/PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py index 22596a39777b7..98e7c067d94a9 100644 --- a/PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py +++ b/PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py @@ -195,10 +195,10 @@ , 'pfNegativeDeepFlavourJetTags:probg' : [["pfNegativeDeepFlavourTagInfos"], ['pfDeepCSVNegativeTagInfos', "pfImpactParameterTagInfos", 'pfInclusiveSecondaryVertexFinderNegativeTagInfos']] , 'pfDeepDoubleBJetTags:probQ' : [["pfDeepDoubleBTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']] , 'pfDeepDoubleBJetTags:probH' : [["pfDeepDoubleBTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']] - , 'pfDeepDoubleCvLJetTags:probQCD' : [["pfDeepDoubleCvLTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']] - , 'pfDeepDoubleCvLJetTags:probHcc' : [["pfDeepDoubleCvLTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']] - , 'pfDeepDoubleCvBJetTags:probHbb' : [["pfDeepDoubleCvBTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']] - , 'pfDeepDoubleCvBJetTags:probHcc' : [["pfDeepDoubleCvBTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']] + , 'pfDeepDoubleCvLJetTags:probQCD' : [["pfDeepDoubleBTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']] + , 'pfDeepDoubleCvLJetTags:probHcc' : [["pfDeepDoubleBTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']] + , 'pfDeepDoubleCvBJetTags:probHbb' : [["pfDeepDoubleBTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']] + , 'pfDeepDoubleCvBJetTags:probHcc' : [["pfDeepDoubleBTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']] } # meta-taggers are simple arithmetic on top of other taggers, they are stored here diff --git a/PhysicsTools/PatAlgos/python/tools/jetTools.py b/PhysicsTools/PatAlgos/python/tools/jetTools.py index 6037c662b1b4b..a7531bcb976f3 100644 --- a/PhysicsTools/PatAlgos/python/tools/jetTools.py +++ b/PhysicsTools/PatAlgos/python/tools/jetTools.py @@ -630,7 +630,7 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou shallow_tag_infos = cms.InputTag(btagPrefix+'pfBoostedDoubleSVAK8TagInfos'+labelName+postfix), ), process, task) - + ''' if btagInfo == 'pfDeepDoubleCvLTagInfos': addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix, btag.pfDeepDoubleCvLTagInfos.clone( @@ -650,7 +650,7 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou shallow_tag_infos = cms.InputTag(btagPrefix+'pfBoostedDoubleSVAK8TagInfos'+labelName+postfix), ), process, task) - + ''' if btagInfo == 'pfDeepBoostedJetTagInfos': if pfCandidates.value() == 'packedPFCandidates': # case 1: running over jets whose daughters are PackedCandidates (only via updateJetCollection for now) diff --git a/RecoBTag/FeatureTools/plugins/DeepDoubleCvBTagInfoProducer.cc b/RecoBTag/FeatureTools/plugins/DeepDoubleCvBTagInfoProducer.cc deleted file mode 100644 index c65928356b7af..0000000000000 --- a/RecoBTag/FeatureTools/plugins/DeepDoubleCvBTagInfoProducer.cc +++ /dev/null @@ -1,349 +0,0 @@ - -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/stream/EDProducer.h" - -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" - -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/Utilities/interface/StreamID.h" - -#include "DataFormats/Candidate/interface/Candidate.h" - -#include "DataFormats/PatCandidates/interface/Jet.h" -#include "DataFormats/PatCandidates/interface/PackedCandidate.h" - -#include "DataFormats/BTauReco/interface/BoostedDoubleSVTagInfo.h" - -#include "TrackingTools/Records/interface/TransientTrackRecord.h" -#include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h" - -#include "DataFormats/BTauReco/interface/DeepDoubleCvBFeatures.h" -#include "DataFormats/BTauReco/interface/DeepDoubleCvBTagInfo.h" - -#include "RecoBTag/FeatureTools/interface/BoostedDoubleSVTagInfoConverter.h" -#include "RecoBTag/FeatureTools/interface/ChargedCandidateConverter.h" -#include "RecoBTag/FeatureTools/interface/JetConverter.h" -#include "RecoBTag/FeatureTools/interface/SecondaryVertexConverter.h" - -#include "RecoBTag/FeatureTools/interface/TrackInfoBuilder.h" -#include "RecoBTag/FeatureTools/interface/sorting_modules.h" - -#include "DataFormats/Candidate/interface/VertexCompositePtrCandidate.h" -#include "DataFormats/VertexReco/interface/VertexFwd.h" - -#include "RecoBTag/FeatureTools/interface/deep_helpers.h" - -class DeepDoubleCvBTagInfoProducer : public edm::stream::EDProducer<> -{ - -public: - explicit DeepDoubleCvBTagInfoProducer(const edm::ParameterSet&); - ~DeepDoubleCvBTagInfoProducer() override; - - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - -private: - typedef std::vector DeepDoubleCvBTagInfoCollection; - typedef reco::VertexCompositePtrCandidateCollection SVCollection; - typedef reco::VertexCollection VertexCollection; - typedef edm::View - BoostedDoubleSVTagInfoCollection; - - void beginStream(edm::StreamID) override - { - } - void produce(edm::Event&, const edm::EventSetup&) override; - void endStream() override - { - } - - const double jet_radius_; - const double min_candidate_pt_; - - edm::EDGetTokenT> jet_token_; - edm::EDGetTokenT vtx_token_; - edm::EDGetTokenT sv_token_; - edm::EDGetTokenT shallow_tag_info_token_; -}; - -DeepDoubleCvBTagInfoProducer::DeepDoubleCvBTagInfoProducer( - const edm::ParameterSet& iConfig) - : jet_radius_(iConfig.getParameter("jet_radius")) - , min_candidate_pt_(iConfig.getParameter("min_candidate_pt")) - , jet_token_(consumes>( - iConfig.getParameter("jets"))) - , vtx_token_(consumes( - iConfig.getParameter("vertices"))) - , sv_token_(consumes( - iConfig.getParameter("secondary_vertices"))) - , shallow_tag_info_token_(consumes( - iConfig.getParameter("shallow_tag_infos"))) -{ - produces(); -} - -DeepDoubleCvBTagInfoProducer::~DeepDoubleCvBTagInfoProducer() -{ -} - -void DeepDoubleCvBTagInfoProducer::fillDescriptions( - edm::ConfigurationDescriptions& descriptions) -{ - // pfDeepDoubleCvBTagInfos - edm::ParameterSetDescription desc; - desc.add("shallow_tag_infos", - edm::InputTag("pfBoostedDoubleSVAK8TagInfos")); - desc.add("jet_radius", 0.8); - desc.add("min_candidate_pt", 0.95); - desc.add("vertices", edm::InputTag("offlinePrimaryVertices")); - desc.add("secondary_vertices", - edm::InputTag("inclusiveCandidateSecondaryVertices")); - desc.add("jets", edm::InputTag("ak8PFJetsCHS")); - descriptions.add("pfDeepDoubleCvBTagInfos", desc); -} - -void DeepDoubleCvBTagInfoProducer::produce(edm::Event& iEvent, - const edm::EventSetup& iSetup) -{ - - auto output_tag_infos = std::make_unique(); - - edm::Handle> jets; - iEvent.getByToken(jet_token_, jets); - - edm::Handle vtxs; - iEvent.getByToken(vtx_token_, vtxs); - if (vtxs->empty()) - { - // produce empty TagInfos in case no primary vertex - iEvent.put(std::move(output_tag_infos)); - return; // exit event - } - // reference to primary vertex - const auto& pv = vtxs->at(0); - - edm::Handle svs; - iEvent.getByToken(sv_token_, svs); - - edm::Handle shallow_tag_infos; - iEvent.getByToken(shallow_tag_info_token_, shallow_tag_infos); - - edm::ESHandle track_builder; - iSetup.get().get("TransientTrackBuilder", - track_builder); - - for (std::size_t jet_n = 0; jet_n < jets->size(); jet_n++) - { - - // create data containing structure - btagbtvdeep::DeepDoubleCvBFeatures features; - - // reco jet reference (use as much as possible) - const auto& jet = jets->at(jet_n); - edm::RefToBase jet_ref(jets, jet_n); - // TagInfoCollection not in an associative container so search for matchs - const edm::View& taginfos = *shallow_tag_infos; - edm::Ptr match; - // Try first by 'same index' - if ((jet_n < taginfos.size()) && (taginfos[jet_n].jet() == jet_ref)) - { - match = taginfos.ptrAt(jet_n); - } - else - { - // otherwise fall back to a simple search - for (auto itTI = taginfos.begin(), edTI = taginfos.end(); itTI != edTI; - ++itTI) - { - if (itTI->jet() == jet_ref) - { - match = taginfos.ptrAt(itTI - taginfos.begin()); - break; - } - } - } - reco::BoostedDoubleSVTagInfo tag_info; - if (match.isNonnull()) - { - tag_info = *match; - } // will be default values otherwise - - // fill basic jet features - btagbtvdeep::JetConverter::jetToFeatures(jet, features.jet_features); - - // fill number of pv - features.npv = vtxs->size(); - - // fill features from BoostedDoubleSVTagInfo - const auto& tag_info_vars = tag_info.taggingVariables(); - btagbtvdeep::doubleBTagToFeatures(tag_info_vars, - features.tag_info_features); - - // copy which will be sorted - auto svs_sorted = *svs; - // sort by dxy - std::sort(svs_sorted.begin(), svs_sorted.end(), - [&pv](const auto& sva, const auto& svb) { - 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; - 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); - } - } - - // 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> c_sorted; - - // to cache the TrackInfo - std::map trackinfos; - - // unsorted reference to sv - const auto& svs_unsorted = *svs; - // fill collection, from DeepTNtuples plus some styling - // std::vector daughters; - std::vector daughters; - for (unsigned int i = 0; i < jet.numberOfDaughters(); i++) - { - auto const* cand = jet.daughter(i); - auto packed_cand = dynamic_cast(cand); - auto reco_cand = dynamic_cast(cand); - if (packed_cand) - { - if (cand->numberOfDaughters() > 0) - { - for (unsigned int k = 0; k < cand->numberOfDaughters(); k++) - { - daughters.push_back( - dynamic_cast(cand->daughter(k))); - } - } - else - { - auto packed_cand = dynamic_cast(cand); - daughters.push_back(packed_cand); - } - } - else if (reco_cand) - { - // need some edm::Ptr or edm::Ref if reco candidates - // dynamical casting to pointers, null if not possible - daughters.push_back(reco_cand); - } - } - - for (unsigned int i = 0; i < daughters.size(); i++) - { - auto const* cand = daughters.at(i); - - if (cand) - { - // candidates under 950MeV (configurable) are not considered - // might change if we use also white-listing - if (cand->pt() < min_candidate_pt_) - continue; - if (cand->charge() != 0) - { - auto& trackinfo = trackinfos.emplace(i, track_builder).first->second; - trackinfo.buildTrackInfo(cand, jet_dir, jet_ref_track_dir, pv); - c_sorted.emplace_back( - i, trackinfo.getTrackSip2dSig(), - -btagbtvdeep::mindrsvpfcand(svs_unsorted, cand, jet_radius_), - cand->pt() / jet.pt()); - } - } - } - - // sort collections (open the black-box if you please) - std::sort(c_sorted.begin(), c_sorted.end(), - btagbtvdeep::SortingClass::compareByABCInv); - - std::vector c_sortedindices; - - // this puts 0 everywhere and the right position in ind - c_sortedindices = btagbtvdeep::invertSortingVector(c_sorted); - - // set right size to vectors - features.c_pf_features.clear(); - features.c_pf_features.resize(c_sorted.size()); - - for (unsigned int i = 0; i < daughters.size(); i++) - { - auto const* cand = daughters.at(i); - if (cand) - { - // candidates under 950MeV are not considered - // might change if we use also white-listing - if (cand->pt() < 0.95) - continue; - - // get PUPPI weight from value map - float puppiw = 1.0; // fallback value - - float drminpfcandsv = btagbtvdeep::mindrsvpfcand(svs_unsorted, cand, jet_radius_); - - if (cand->charge() != 0) - { - // is charged candidate - auto entry = c_sortedindices.at(i); - // get cached track info - auto& trackinfo = trackinfos.at(i); - // get_ref to vector element - auto& c_pf_features = features.c_pf_features.at(entry); - // fill feature structure - auto packed_cand = dynamic_cast(cand); - auto reco_cand = dynamic_cast(cand); - if (packed_cand) - { - btagbtvdeep::packedCandidateToFeatures( - packed_cand, jet, trackinfo, drminpfcandsv, - static_cast(jet_radius_), c_pf_features); - } - else if (reco_cand) - { - // get vertex association quality - int pv_ass_quality = 0; // fallback value - // getting the PV as PackedCandidatesProducer - // but using not the slimmed but original vertices - auto ctrack = reco_cand->bestTrack(); - int pvi = -1; - float dist = 1e99; - for (size_t ii = 0; ii < vtxs->size(); ii++) - { - float dz = (ctrack) ? std::abs(ctrack->dz(((*vtxs)[ii]).position())) : 0; - if (dz < dist) - { - pvi = ii; - dist = dz; - } - } - auto pv = reco::VertexRef(vtxs, pvi); - btagbtvdeep::recoCandidateToFeatures( - reco_cand, jet, trackinfo, drminpfcandsv, - static_cast(jet_radius_), puppiw, pv_ass_quality, pv, - c_pf_features); - } - } - } - } - - output_tag_infos->emplace_back(features, jet_ref); - } - - iEvent.put(std::move(output_tag_infos)); -} - -// define this as a plug-in -DEFINE_FWK_MODULE(DeepDoubleCvBTagInfoProducer); diff --git a/RecoBTag/FeatureTools/plugins/DeepDoubleCvLTagInfoProducer.cc b/RecoBTag/FeatureTools/plugins/DeepDoubleCvLTagInfoProducer.cc deleted file mode 100644 index 2d6a9699a0a12..0000000000000 --- a/RecoBTag/FeatureTools/plugins/DeepDoubleCvLTagInfoProducer.cc +++ /dev/null @@ -1,349 +0,0 @@ - -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/stream/EDProducer.h" - -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" - -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/Utilities/interface/StreamID.h" - -#include "DataFormats/Candidate/interface/Candidate.h" - -#include "DataFormats/PatCandidates/interface/Jet.h" -#include "DataFormats/PatCandidates/interface/PackedCandidate.h" - -#include "DataFormats/BTauReco/interface/BoostedDoubleSVTagInfo.h" - -#include "TrackingTools/Records/interface/TransientTrackRecord.h" -#include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h" - -#include "DataFormats/BTauReco/interface/DeepDoubleCvLFeatures.h" -#include "DataFormats/BTauReco/interface/DeepDoubleCvLTagInfo.h" - -#include "RecoBTag/FeatureTools/interface/BoostedDoubleSVTagInfoConverter.h" -#include "RecoBTag/FeatureTools/interface/ChargedCandidateConverter.h" -#include "RecoBTag/FeatureTools/interface/JetConverter.h" -#include "RecoBTag/FeatureTools/interface/SecondaryVertexConverter.h" - -#include "RecoBTag/FeatureTools/interface/TrackInfoBuilder.h" -#include "RecoBTag/FeatureTools/interface/sorting_modules.h" - -#include "DataFormats/Candidate/interface/VertexCompositePtrCandidate.h" -#include "DataFormats/VertexReco/interface/VertexFwd.h" - -#include "RecoBTag/FeatureTools/interface/deep_helpers.h" - -class DeepDoubleCvLTagInfoProducer : public edm::stream::EDProducer<> -{ - -public: - explicit DeepDoubleCvLTagInfoProducer(const edm::ParameterSet&); - ~DeepDoubleCvLTagInfoProducer() override; - - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - -private: - typedef std::vector DeepDoubleCvLTagInfoCollection; - typedef reco::VertexCompositePtrCandidateCollection SVCollection; - typedef reco::VertexCollection VertexCollection; - typedef edm::View - BoostedDoubleSVTagInfoCollection; - - void beginStream(edm::StreamID) override - { - } - void produce(edm::Event&, const edm::EventSetup&) override; - void endStream() override - { - } - - const double jet_radius_; - const double min_candidate_pt_; - - edm::EDGetTokenT> jet_token_; - edm::EDGetTokenT vtx_token_; - edm::EDGetTokenT sv_token_; - edm::EDGetTokenT shallow_tag_info_token_; -}; - -DeepDoubleCvLTagInfoProducer::DeepDoubleCvLTagInfoProducer( - const edm::ParameterSet& iConfig) - : jet_radius_(iConfig.getParameter("jet_radius")) - , min_candidate_pt_(iConfig.getParameter("min_candidate_pt")) - , jet_token_(consumes>( - iConfig.getParameter("jets"))) - , vtx_token_(consumes( - iConfig.getParameter("vertices"))) - , sv_token_(consumes( - iConfig.getParameter("secondary_vertices"))) - , shallow_tag_info_token_(consumes( - iConfig.getParameter("shallow_tag_infos"))) -{ - produces(); -} - -DeepDoubleCvLTagInfoProducer::~DeepDoubleCvLTagInfoProducer() -{ -} - -void DeepDoubleCvLTagInfoProducer::fillDescriptions( - edm::ConfigurationDescriptions& descriptions) -{ - // pfDeepDoubleCvLTagInfos - edm::ParameterSetDescription desc; - desc.add("shallow_tag_infos", - edm::InputTag("pfBoostedDoubleSVAK8TagInfos")); - desc.add("jet_radius", 0.8); - desc.add("min_candidate_pt", 0.95); - desc.add("vertices", edm::InputTag("offlinePrimaryVertices")); - desc.add("secondary_vertices", - edm::InputTag("inclusiveCandidateSecondaryVertices")); - desc.add("jets", edm::InputTag("ak8PFJetsCHS")); - descriptions.add("pfDeepDoubleCvLTagInfos", desc); -} - -void DeepDoubleCvLTagInfoProducer::produce(edm::Event& iEvent, - const edm::EventSetup& iSetup) -{ - - auto output_tag_infos = std::make_unique(); - - edm::Handle> jets; - iEvent.getByToken(jet_token_, jets); - - edm::Handle vtxs; - iEvent.getByToken(vtx_token_, vtxs); - if (vtxs->empty()) - { - // produce empty TagInfos in case no primary vertex - iEvent.put(std::move(output_tag_infos)); - return; // exit event - } - // reference to primary vertex - const auto& pv = vtxs->at(0); - - edm::Handle svs; - iEvent.getByToken(sv_token_, svs); - - edm::Handle shallow_tag_infos; - iEvent.getByToken(shallow_tag_info_token_, shallow_tag_infos); - - edm::ESHandle track_builder; - iSetup.get().get("TransientTrackBuilder", - track_builder); - - for (std::size_t jet_n = 0; jet_n < jets->size(); jet_n++) - { - - // create data containing structure - btagbtvdeep::DeepDoubleCvLFeatures features; - - // reco jet reference (use as much as possible) - const auto& jet = jets->at(jet_n); - edm::RefToBase jet_ref(jets, jet_n); - // TagInfoCollection not in an associative container so search for matchs - const edm::View& taginfos = *shallow_tag_infos; - edm::Ptr match; - // Try first by 'same index' - if ((jet_n < taginfos.size()) && (taginfos[jet_n].jet() == jet_ref)) - { - match = taginfos.ptrAt(jet_n); - } - else - { - // otherwise fall back to a simple search - for (auto itTI = taginfos.begin(), edTI = taginfos.end(); itTI != edTI; - ++itTI) - { - if (itTI->jet() == jet_ref) - { - match = taginfos.ptrAt(itTI - taginfos.begin()); - break; - } - } - } - reco::BoostedDoubleSVTagInfo tag_info; - if (match.isNonnull()) - { - tag_info = *match; - } // will be default values otherwise - - // fill basic jet features - btagbtvdeep::JetConverter::jetToFeatures(jet, features.jet_features); - - // fill number of pv - features.npv = vtxs->size(); - - // fill features from BoostedDoubleSVTagInfo - const auto& tag_info_vars = tag_info.taggingVariables(); - btagbtvdeep::doubleBTagToFeatures(tag_info_vars, - features.tag_info_features); - - // copy which will be sorted - auto svs_sorted = *svs; - // sort by dxy - std::sort(svs_sorted.begin(), svs_sorted.end(), - [&pv](const auto& sva, const auto& svb) { - 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; - 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); - } - } - - // 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> c_sorted; - - // to cache the TrackInfo - std::map trackinfos; - - // unsorted reference to sv - const auto& svs_unsorted = *svs; - // fill collection, from DeepTNtuples plus some styling - // std::vector daughters; - std::vector daughters; - for (unsigned int i = 0; i < jet.numberOfDaughters(); i++) - { - auto const* cand = jet.daughter(i); - auto packed_cand = dynamic_cast(cand); - auto reco_cand = dynamic_cast(cand); - if (packed_cand) - { - if (cand->numberOfDaughters() > 0) - { - for (unsigned int k = 0; k < cand->numberOfDaughters(); k++) - { - daughters.push_back( - dynamic_cast(cand->daughter(k))); - } - } - else - { - auto packed_cand = dynamic_cast(cand); - daughters.push_back(packed_cand); - } - } - else if (reco_cand) - { - // need some edm::Ptr or edm::Ref if reco candidates - // dynamical casting to pointers, null if not possible - daughters.push_back(reco_cand); - } - } - - for (unsigned int i = 0; i < daughters.size(); i++) - { - auto const* cand = daughters.at(i); - - if (cand) - { - // candidates under 950MeV (configurable) are not considered - // might change if we use also white-listing - if (cand->pt() < min_candidate_pt_) - continue; - if (cand->charge() != 0) - { - auto& trackinfo = trackinfos.emplace(i, track_builder).first->second; - trackinfo.buildTrackInfo(cand, jet_dir, jet_ref_track_dir, pv); - c_sorted.emplace_back( - i, trackinfo.getTrackSip2dSig(), - -btagbtvdeep::mindrsvpfcand(svs_unsorted, cand, jet_radius_), - cand->pt() / jet.pt()); - } - } - } - - // sort collections (open the black-box if you please) - std::sort(c_sorted.begin(), c_sorted.end(), - btagbtvdeep::SortingClass::compareByABCInv); - - std::vector c_sortedindices; - - // this puts 0 everywhere and the right position in ind - c_sortedindices = btagbtvdeep::invertSortingVector(c_sorted); - - // set right size to vectors - features.c_pf_features.clear(); - features.c_pf_features.resize(c_sorted.size()); - - for (unsigned int i = 0; i < daughters.size(); i++) - { - auto const* cand = daughters.at(i); - if (cand) - { - // candidates under 950MeV are not considered - // might change if we use also white-listing - if (cand->pt() < 0.95) - continue; - - // get PUPPI weight from value map - float puppiw = 1.0; // fallback value - - float drminpfcandsv = btagbtvdeep::mindrsvpfcand(svs_unsorted, cand, jet_radius_); - - if (cand->charge() != 0) - { - // is charged candidate - auto entry = c_sortedindices.at(i); - // get cached track info - auto& trackinfo = trackinfos.at(i); - // get_ref to vector element - auto& c_pf_features = features.c_pf_features.at(entry); - // fill feature structure - auto packed_cand = dynamic_cast(cand); - auto reco_cand = dynamic_cast(cand); - if (packed_cand) - { - btagbtvdeep::packedCandidateToFeatures( - packed_cand, jet, trackinfo, drminpfcandsv, - static_cast(jet_radius_), c_pf_features); - } - else if (reco_cand) - { - // get vertex association quality - int pv_ass_quality = 0; // fallback value - // getting the PV as PackedCandidatesProducer - // but using not the slimmed but original vertices - auto ctrack = reco_cand->bestTrack(); - int pvi = -1; - float dist = 1e99; - for (size_t ii = 0; ii < vtxs->size(); ii++) - { - float dz = (ctrack) ? std::abs(ctrack->dz(((*vtxs)[ii]).position())) : 0; - if (dz < dist) - { - pvi = ii; - dist = dz; - } - } - auto pv = reco::VertexRef(vtxs, pvi); - btagbtvdeep::recoCandidateToFeatures( - reco_cand, jet, trackinfo, drminpfcandsv, - static_cast(jet_radius_), puppiw, pv_ass_quality, pv, - c_pf_features); - } - } - } - } - - output_tag_infos->emplace_back(features, jet_ref); - } - - iEvent.put(std::move(output_tag_infos)); -} - -// define this as a plug-in -DEFINE_FWK_MODULE(DeepDoubleCvLTagInfoProducer); diff --git a/RecoBTag/TensorFlow/interface/tensor_fillers.h b/RecoBTag/TensorFlow/interface/tensor_fillers.h index cb60d6ede8abf..b5f080857f0dc 100644 --- a/RecoBTag/TensorFlow/interface/tensor_fillers.h +++ b/RecoBTag/TensorFlow/interface/tensor_fillers.h @@ -4,8 +4,8 @@ #include "PhysicsTools/TensorFlow/interface/TensorFlow.h" #include "DataFormats/BTauReco/interface/DeepFlavourTagInfo.h" #include "DataFormats/BTauReco/interface/DeepDoubleBTagInfo.h" -#include "DataFormats/BTauReco/interface/DeepDoubleCvLTagInfo.h" -#include "DataFormats/BTauReco/interface/DeepDoubleCvBTagInfo.h" +//#include "DataFormats/BTauReco/interface/DeepDoubleCvLTagInfo.h" +//#include "DataFormats/BTauReco/interface/DeepDoubleCvBTagInfo.h" namespace btagbtvdeep { @@ -24,7 +24,7 @@ namespace btagbtvdeep { void db_tensor_filler(tensorflow::Tensor & tensor, std::size_t jet_n, const btagbtvdeep::DeepDoubleBFeatures & features) ; - +/* void db_tensor_filler(tensorflow::Tensor & tensor, std::size_t jet_n, const btagbtvdeep::DeepDoubleCvLFeatures & features) ; @@ -32,7 +32,7 @@ namespace btagbtvdeep { void db_tensor_filler(tensorflow::Tensor & tensor, std::size_t jet_n, const btagbtvdeep::DeepDoubleCvBFeatures & features) ; - +*/ void c_pf_tensor_filler(tensorflow::Tensor & tensor, std::size_t jet_n, std::size_t c_pf_n, diff --git a/RecoBTag/TensorFlow/plugins/DeepDoubleCvBTFJetTagsProducer.cc b/RecoBTag/TensorFlow/plugins/DeepDoubleCvBTFJetTagsProducer.cc index 7e8d26326e138..71975e8efaa1b 100644 --- a/RecoBTag/TensorFlow/plugins/DeepDoubleCvBTFJetTagsProducer.cc +++ b/RecoBTag/TensorFlow/plugins/DeepDoubleCvBTFJetTagsProducer.cc @@ -12,7 +12,8 @@ #include "DataFormats/BTauReco/interface/JetTag.h" -#include "DataFormats/BTauReco/interface/DeepDoubleCvBTagInfo.h" +//#include "DataFormats/BTauReco/interface/DeepDoubleCvBTagInfo.h" +#include "DataFormats/BTauReco/interface/DeepDoubleBTagInfo.h" #include "PhysicsTools/TensorFlow/interface/TensorFlow.h" @@ -55,7 +56,8 @@ class DeepDoubleCvBTFJetTagsProducer : public edm::stream::EDProducer TagInfoCollection; + //typedef std::vector TagInfoCollection; + typedef std::vector TagInfoCollection; typedef reco::JetTagCollection JetTagCollection; void beginStream(edm::StreamID) override {} @@ -129,7 +131,8 @@ void DeepDoubleCvBTFJetTagsProducer::fillDescriptions(edm::ConfigurationDescript // pfDeepDoubleCvBJetTags edm::ParameterSetDescription desc; - desc.add("src", edm::InputTag("pfDeepDoubleCvBTagInfos")); + //desc.add("src", edm::InputTag("pfDeepDoubleCvBTagInfos")); + desc.add("src", edm::InputTag("pfDeepDoubleBTagInfos")); desc.add>("input_names", { "input_1", "input_2", "input_3" }); desc.add("graph_path", diff --git a/RecoBTag/TensorFlow/plugins/DeepDoubleCvLTFJetTagsProducer.cc b/RecoBTag/TensorFlow/plugins/DeepDoubleCvLTFJetTagsProducer.cc index 4eb504f229fa3..f92d1819ece47 100644 --- a/RecoBTag/TensorFlow/plugins/DeepDoubleCvLTFJetTagsProducer.cc +++ b/RecoBTag/TensorFlow/plugins/DeepDoubleCvLTFJetTagsProducer.cc @@ -12,7 +12,8 @@ #include "DataFormats/BTauReco/interface/JetTag.h" -#include "DataFormats/BTauReco/interface/DeepDoubleCvLTagInfo.h" +//#include "DataFormats/BTauReco/interface/DeepDoubleCvLTagInfo.h" +#include "DataFormats/BTauReco/interface/DeepDoubleBTagInfo.h" #include "PhysicsTools/TensorFlow/interface/TensorFlow.h" @@ -55,7 +56,8 @@ class DeepDoubleCvLTFJetTagsProducer : public edm::stream::EDProducer TagInfoCollection; + //typedef std::vector TagInfoCollection; + typedef std::vector TagInfoCollection; typedef reco::JetTagCollection JetTagCollection; void beginStream(edm::StreamID) override {} @@ -129,7 +131,8 @@ void DeepDoubleCvLTFJetTagsProducer::fillDescriptions(edm::ConfigurationDescript // pfDeepDoubleCvLJetTags edm::ParameterSetDescription desc; - desc.add("src", edm::InputTag("pfDeepDoubleCvLTagInfos")); + //desc.add("src", edm::InputTag("pfDeepDoubleCvLTagInfos")); + desc.add("src", edm::InputTag("pfDeepDoubleBTagInfos")); desc.add>("input_names", { "input_1", "input_2", "input_3" }); desc.add("graph_path", diff --git a/RecoBTag/TensorFlow/python/pfDeepFlavour_cff.py b/RecoBTag/TensorFlow/python/pfDeepFlavour_cff.py index cdf4b227f52e3..668fce34bf030 100644 --- a/RecoBTag/TensorFlow/python/pfDeepFlavour_cff.py +++ b/RecoBTag/TensorFlow/python/pfDeepFlavour_cff.py @@ -3,14 +3,12 @@ from RecoBTag.FeatureTools.pfDeepFlavourTagInfos_cfi import pfDeepFlavourTagInfos from RecoBTag.FeatureTools.pfNegativeDeepFlavourTagInfos_cfi import pfNegativeDeepFlavourTagInfos from RecoBTag.FeatureTools.pfDeepDoubleBTagInfos_cfi import pfDeepDoubleBTagInfos -from RecoBTag.FeatureTools.pfDeepDoubleCvLTagInfos_cfi import pfDeepDoubleCvLTagInfos -from RecoBTag.FeatureTools.pfDeepDoubleCvBTagInfos_cfi import pfDeepDoubleCvBTagInfos from RecoBTag.TensorFlow.pfDeepFlavourJetTags_cfi import pfDeepFlavourJetTags from RecoBTag.TensorFlow.pfNegativeDeepFlavourJetTags_cfi import pfNegativeDeepFlavourJetTags from RecoBTag.TensorFlow.pfDeepDoubleBJetTags_cfi import pfDeepDoubleBJetTags -from RecoBTag.TensorFlow.pfDeepDoubleCvLJetTags_cfi import pfDeepDoubleCvLJetTags from RecoBTag.TensorFlow.pfDeepDoubleCvBJetTags_cfi import pfDeepDoubleCvBJetTags +from RecoBTag.TensorFlow.pfDeepDoubleCvLJetTags_cfi import pfDeepDoubleCvLJetTags from CommonTools.PileupAlgos.Puppi_cff import puppi from PhysicsTools.PatAlgos.slimming.primaryVertexAssociation_cfi import primaryVertexAssociation diff --git a/RecoBTag/TensorFlow/src/tensor_fillers.cc b/RecoBTag/TensorFlow/src/tensor_fillers.cc index cd5066e2e6e81..cad5e3af82ee5 100644 --- a/RecoBTag/TensorFlow/src/tensor_fillers.cc +++ b/RecoBTag/TensorFlow/src/tensor_fillers.cc @@ -76,7 +76,7 @@ namespace btagbtvdeep { *(++ptr) = tag_info_features.trackSip3dSig_3; *(++ptr) = tag_info_features.z_ratio; } - +/* void db_tensor_filler(tensorflow::Tensor & tensor, std::size_t jet_n, const btagbtvdeep::DeepDoubleCvLFeatures & features) { @@ -154,7 +154,7 @@ namespace btagbtvdeep { *(++ptr) = tag_info_features.trackSip3dSig_3; *(++ptr) = tag_info_features.z_ratio; } - +*/ void c_pf_tensor_filler(tensorflow::Tensor & tensor, std::size_t jet_n, std::size_t c_pf_n, diff --git a/RecoBTag/TensorFlow/test/test_deep_doublec_cfg.py b/RecoBTag/TensorFlow/test/test_deep_doublec_cfg.py index 245f4a5725396..a0756fd1c2000 100644 --- a/RecoBTag/TensorFlow/test/test_deep_doublec_cfg.py +++ b/RecoBTag/TensorFlow/test/test_deep_doublec_cfg.py @@ -70,7 +70,7 @@ #'root://cmsxrootd.fnal.gov//store/mc/RunIIFall17MiniAODv2/GluGluHToCC_M125_13TeV_powheg_pythia8/MINIAODSIM/PU2017_12Apr2018_94X_mc2017_realistic_v14-v2/30000/72164088-CB67-E811-9D0D-008CFA197AC4.root', #'root://cmsxrootd.fnal.gov//store/mc/RunIIFall17MiniAOD/QCD_HT700to1000_TuneCP5_13TeV-madgraph-pythia8/MINIAODSIM/94X_mc2017_realistic_v10-v1/20000/C0F304A4-23FA-E711-942E-E0071B6CAD20.root' ) -process.maxEvents.input = 1000 +process.maxEvents.input = -1 from Configuration.EventContent.EventContent_cff import MINIAODSIMEventContent process.out.outputCommands.append('keep *_slimmedJetsAK8*_*_*') @@ -80,8 +80,8 @@ process.out.outputCommands.append('keep *_selectedUpdatedPatJets*_*_*') process.out.outputCommands.append('keep *_pfBoostedDoubleSVAK8TagInfos*_*_*') process.out.outputCommands.append('keep *_pfDeepDoubleBTagInfos*_*_*') -process.out.outputCommands.append('keep *_pfDeepDoubleCvLTagInfos*_*_*') -process.out.outputCommands.append('keep *_pfDeepDoubleCvBTagInfos*_*_*') +#process.out.outputCommands.append('keep *_pfDeepDoubleCvLTagInfos*_*_*') +#process.out.outputCommands.append('keep *_pfDeepDoubleCvBTagInfos*_*_*') process.out.outputCommands.append('keep *_updatedPatJets*_*_*') process.out.fileName = 'output_test_DDX.root' From f22430b82d16d4f5b18ad2c527dc6e6d2fc71377 Mon Sep 17 00:00:00 2001 From: anovak10 Date: Fri, 26 Oct 2018 18:22:29 +0200 Subject: [PATCH 04/30] renaming --- .../BTauReco/interface/DeepDoubleBFeatures.h | 29 ----------------- .../BTauReco/interface/DeepDoubleBTagInfo.h | 15 --------- DataFormats/BTauReco/src/classes.h | 20 ++++++------ DataFormats/BTauReco/src/classes_def.xml | 19 +++++------ .../python/recoLayer0/bTagging_cff.py | 18 +++++------ .../PatAlgos/python/tools/jetTools.py | 24 ++------------ .../plugins/DeepDoubleBTagInfoProducer.cc | 32 +++++++++---------- .../TensorFlow/interface/tensor_fillers.h | 4 +-- .../plugins/DeepDoubleBTFJetTagsProducer.cc | 6 ++-- .../plugins/DeepDoubleCvBTFJetTagsProducer.cc | 6 ++-- .../plugins/DeepDoubleCvLTFJetTagsProducer.cc | 6 ++-- .../TensorFlow/python/pfDeepFlavour_cff.py | 2 +- RecoBTag/TensorFlow/src/tensor_fillers.cc | 2 +- .../TensorFlow/test/test_deep_doublec_cfg.py | 2 +- 14 files changed, 61 insertions(+), 124 deletions(-) delete mode 100644 DataFormats/BTauReco/interface/DeepDoubleBFeatures.h delete mode 100644 DataFormats/BTauReco/interface/DeepDoubleBTagInfo.h diff --git a/DataFormats/BTauReco/interface/DeepDoubleBFeatures.h b/DataFormats/BTauReco/interface/DeepDoubleBFeatures.h deleted file mode 100644 index 08859f343c88c..0000000000000 --- a/DataFormats/BTauReco/interface/DeepDoubleBFeatures.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef DataFormats_BTauReco_DeepDoubleBFeatures_h -#define DataFormats_BTauReco_DeepDoubleBFeatures_h - -#include - -#include "DataFormats/BTauReco/interface/JetFeatures.h" -#include "DataFormats/BTauReco/interface/SecondaryVertexFeatures.h" -#include "DataFormats/BTauReco/interface/BoostedDoubleSVTagInfoFeatures.h" -#include "DataFormats/BTauReco/interface/ChargedCandidateFeatures.h" - -namespace btagbtvdeep { - -class DeepDoubleBFeatures { - - public: - JetFeatures jet_features; - BoostedDoubleSVTagInfoFeatures tag_info_features; - - std::vector sv_features; - - std::vector c_pf_features; - - std::size_t npv; // used by deep flavour -}; - - -} - -#endif //DataFormats_BTauReco_DeepDoubleBFeatures_h diff --git a/DataFormats/BTauReco/interface/DeepDoubleBTagInfo.h b/DataFormats/BTauReco/interface/DeepDoubleBTagInfo.h deleted file mode 100644 index 70ec4aa9941f0..0000000000000 --- a/DataFormats/BTauReco/interface/DeepDoubleBTagInfo.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef DataFormats_BTauReco_DeepDoubleBTagInfo_h -#define DataFormats_BTauReco_DeepDoubleBTagInfo_h - -#include "DataFormats/BTauReco/interface/FeaturesTagInfo.h" -#include "DataFormats/BTauReco/interface/DeepDoubleBFeatures.h" - -namespace reco { - -typedef FeaturesTagInfo DeepDoubleBTagInfo; - -DECLARE_EDM_REFS( DeepDoubleBTagInfo ) - -} - -#endif // DataFormats_BTauReco_DeepDoubleBTagInfo_h diff --git a/DataFormats/BTauReco/src/classes.h b/DataFormats/BTauReco/src/classes.h index fbf1a37a801fc..36271e92248b9 100755 --- a/DataFormats/BTauReco/src/classes.h +++ b/DataFormats/BTauReco/src/classes.h @@ -54,8 +54,8 @@ #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" @@ -419,14 +419,14 @@ namespace DataFormats_BTauReco { edm::Wrapper 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 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 deep_doublex_tag_info_collection_edm_wrapper; btagbtvdeep::DeepBoostedJetFeatures deep_boosted_jet_tag_info_features; reco::DeepBoostedJetTagInfo deep_boosted_jet_tag_info; diff --git a/DataFormats/BTauReco/src/classes_def.xml b/DataFormats/BTauReco/src/classes_def.xml index 96afe58e09a12..533520da494b7 100644 --- a/DataFormats/BTauReco/src/classes_def.xml +++ b/DataFormats/BTauReco/src/classes_def.xml @@ -447,8 +447,9 @@ - - + + + @@ -463,13 +464,13 @@ - - - - - - - + + + + + + + diff --git a/PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py b/PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py index 98e7c067d94a9..3ad2b8dfee25f 100644 --- a/PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py +++ b/PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py @@ -42,11 +42,11 @@ , 'pfDeepFlavourTagInfos' , 'pfNegativeDeepFlavourTagInfos' # DeepDoubleB tag infos - , 'pfDeepDoubleBTagInfos' + , 'pfDeepDoubleXTagInfos' # DeepDoubleCvL tag infos - , 'pfDeepDoubleCvLTagInfos' +# , 'pfDeepDoubleCvLTagInfos' # DeepDoubleCvB tag infos - , 'pfDeepDoubleCvBTagInfos' +# , 'pfDeepDoubleCvBTagInfos' # DeepBoostedJet tag infos , 'pfDeepBoostedJetTagInfos' ] @@ -193,12 +193,12 @@ , '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']] - , 'pfDeepDoubleCvLJetTags:probQCD' : [["pfDeepDoubleBTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']] - , 'pfDeepDoubleCvLJetTags:probHcc' : [["pfDeepDoubleBTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']] - , 'pfDeepDoubleCvBJetTags:probHbb' : [["pfDeepDoubleBTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']] - , 'pfDeepDoubleCvBJetTags:probHcc' : [["pfDeepDoubleBTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']] + , 'pfDeepDoubleBJetTags:probQ' : [["pfDeepDoubleXTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']] + , 'pfDeepDoubleBJetTags:probH' : [["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']] } # meta-taggers are simple arithmetic on top of other taggers, they are stored here diff --git a/PhysicsTools/PatAlgos/python/tools/jetTools.py b/PhysicsTools/PatAlgos/python/tools/jetTools.py index a7531bcb976f3..8d4acd84e70b1 100644 --- a/PhysicsTools/PatAlgos/python/tools/jetTools.py +++ b/PhysicsTools/PatAlgos/python/tools/jetTools.py @@ -621,19 +621,9 @@ 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( - jets = jetSource, - vertices=pvSource, - secondary_vertices=svSource, - shallow_tag_infos = cms.InputTag(btagPrefix+'pfBoostedDoubleSVAK8TagInfos'+labelName+postfix), - ), - process, task) - ''' - if btagInfo == 'pfDeepDoubleCvLTagInfos': - addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix, - btag.pfDeepDoubleCvLTagInfos.clone( + btag.pfDeepDoubleXTagInfos.clone( jets = jetSource, vertices=pvSource, secondary_vertices=svSource, @@ -641,16 +631,6 @@ def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSou ), process, task) - if btagInfo == 'pfDeepDoubleCvBTagInfos': - addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix, - btag.pfDeepDoubleCvBTagInfos.clone( - jets = jetSource, - vertices=pvSource, - secondary_vertices=svSource, - shallow_tag_infos = cms.InputTag(btagPrefix+'pfBoostedDoubleSVAK8TagInfos'+labelName+postfix), - ), - process, task) - ''' if btagInfo == 'pfDeepBoostedJetTagInfos': if pfCandidates.value() == 'packedPFCandidates': # case 1: running over jets whose daughters are PackedCandidates (only via updateJetCollection for now) diff --git a/RecoBTag/FeatureTools/plugins/DeepDoubleBTagInfoProducer.cc b/RecoBTag/FeatureTools/plugins/DeepDoubleBTagInfoProducer.cc index b69b23a762035..4fe1c7aae5a7e 100644 --- a/RecoBTag/FeatureTools/plugins/DeepDoubleBTagInfoProducer.cc +++ b/RecoBTag/FeatureTools/plugins/DeepDoubleBTagInfoProducer.cc @@ -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" @@ -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 DeepDoubleBTagInfoCollection; + typedef std::vector DeepDoubleXTagInfoCollection; typedef reco::VertexCompositePtrCandidateCollection SVCollection; typedef reco::VertexCollection VertexCollection; typedef edm::View @@ -67,7 +67,7 @@ class DeepDoubleBTagInfoProducer : public edm::stream::EDProducer<> edm::EDGetTokenT shallow_tag_info_token_; }; -DeepDoubleBTagInfoProducer::DeepDoubleBTagInfoProducer( +DeepDoubleXTagInfoProducer::DeepDoubleXTagInfoProducer( const edm::ParameterSet& iConfig) : jet_radius_(iConfig.getParameter("jet_radius")) , min_candidate_pt_(iConfig.getParameter("min_candidate_pt")) @@ -80,17 +80,17 @@ DeepDoubleBTagInfoProducer::DeepDoubleBTagInfoProducer( , shallow_tag_info_token_(consumes( iConfig.getParameter("shallow_tag_infos"))) { - produces(); + produces(); } -DeepDoubleBTagInfoProducer::~DeepDoubleBTagInfoProducer() +DeepDoubleXTagInfoProducer::~DeepDoubleXTagInfoProducer() { } -void DeepDoubleBTagInfoProducer::fillDescriptions( +void DeepDoubleXTagInfoProducer::fillDescriptions( edm::ConfigurationDescriptions& descriptions) { - // pfDeepDoubleBTagInfos + // pfDeepDoubleXTagInfos edm::ParameterSetDescription desc; desc.add("shallow_tag_infos", edm::InputTag("pfBoostedDoubleSVAK8TagInfos")); @@ -100,14 +100,14 @@ void DeepDoubleBTagInfoProducer::fillDescriptions( desc.add("secondary_vertices", edm::InputTag("inclusiveCandidateSecondaryVertices")); desc.add("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(); + auto output_tag_infos = std::make_unique(); edm::Handle> jets; iEvent.getByToken(jet_token_, jets); @@ -137,7 +137,7 @@ 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); @@ -346,4 +346,4 @@ void DeepDoubleBTagInfoProducer::produce(edm::Event& iEvent, } // define this as a plug-in -DEFINE_FWK_MODULE(DeepDoubleBTagInfoProducer); +DEFINE_FWK_MODULE(DeepDoubleXTagInfoProducer); diff --git a/RecoBTag/TensorFlow/interface/tensor_fillers.h b/RecoBTag/TensorFlow/interface/tensor_fillers.h index b5f080857f0dc..5ed4b5c9494a1 100644 --- a/RecoBTag/TensorFlow/interface/tensor_fillers.h +++ b/RecoBTag/TensorFlow/interface/tensor_fillers.h @@ -3,7 +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" //#include "DataFormats/BTauReco/interface/DeepDoubleCvLTagInfo.h" //#include "DataFormats/BTauReco/interface/DeepDoubleCvBTagInfo.h" @@ -23,7 +23,7 @@ namespace btagbtvdeep { void db_tensor_filler(tensorflow::Tensor & tensor, std::size_t jet_n, - const btagbtvdeep::DeepDoubleBFeatures & features) ; + const btagbtvdeep::DeepDoubleXFeatures & features) ; /* void db_tensor_filler(tensorflow::Tensor & tensor, std::size_t jet_n, diff --git a/RecoBTag/TensorFlow/plugins/DeepDoubleBTFJetTagsProducer.cc b/RecoBTag/TensorFlow/plugins/DeepDoubleBTFJetTagsProducer.cc index dadc9ba959d46..3589183eb5787 100644 --- a/RecoBTag/TensorFlow/plugins/DeepDoubleBTFJetTagsProducer.cc +++ b/RecoBTag/TensorFlow/plugins/DeepDoubleBTFJetTagsProducer.cc @@ -12,7 +12,7 @@ #include "DataFormats/BTauReco/interface/JetTag.h" -#include "DataFormats/BTauReco/interface/DeepDoubleBTagInfo.h" +#include "DataFormats/BTauReco/interface/DeepDoubleXTagInfo.h" #include "PhysicsTools/TensorFlow/interface/TensorFlow.h" @@ -55,7 +55,7 @@ class DeepDoubleBTFJetTagsProducer : public edm::stream::EDProducer TagInfoCollection; + typedef std::vector TagInfoCollection; typedef reco::JetTagCollection JetTagCollection; void beginStream(edm::StreamID) override {} @@ -129,7 +129,7 @@ void DeepDoubleBTFJetTagsProducer::fillDescriptions(edm::ConfigurationDescriptio // pfDeepDoubleBJetTags edm::ParameterSetDescription desc; - desc.add("src", edm::InputTag("pfDeepDoubleBTagInfos")); + desc.add("src", edm::InputTag("pfDeepDoubleXTagInfos")); desc.add>("input_names", { "input_1", "input_2", "input_3" }); desc.add("graph_path", diff --git a/RecoBTag/TensorFlow/plugins/DeepDoubleCvBTFJetTagsProducer.cc b/RecoBTag/TensorFlow/plugins/DeepDoubleCvBTFJetTagsProducer.cc index 71975e8efaa1b..a1b5ee73fc461 100644 --- a/RecoBTag/TensorFlow/plugins/DeepDoubleCvBTFJetTagsProducer.cc +++ b/RecoBTag/TensorFlow/plugins/DeepDoubleCvBTFJetTagsProducer.cc @@ -13,7 +13,7 @@ #include "DataFormats/BTauReco/interface/JetTag.h" //#include "DataFormats/BTauReco/interface/DeepDoubleCvBTagInfo.h" -#include "DataFormats/BTauReco/interface/DeepDoubleBTagInfo.h" +#include "DataFormats/BTauReco/interface/DeepDoubleXTagInfo.h" #include "PhysicsTools/TensorFlow/interface/TensorFlow.h" @@ -57,7 +57,7 @@ class DeepDoubleCvBTFJetTagsProducer : public edm::stream::EDProducer TagInfoCollection; - typedef std::vector TagInfoCollection; + typedef std::vector TagInfoCollection; typedef reco::JetTagCollection JetTagCollection; void beginStream(edm::StreamID) override {} @@ -132,7 +132,7 @@ void DeepDoubleCvBTFJetTagsProducer::fillDescriptions(edm::ConfigurationDescript // pfDeepDoubleCvBJetTags edm::ParameterSetDescription desc; //desc.add("src", edm::InputTag("pfDeepDoubleCvBTagInfos")); - desc.add("src", edm::InputTag("pfDeepDoubleBTagInfos")); + desc.add("src", edm::InputTag("pfDeepDoubleXTagInfos")); desc.add>("input_names", { "input_1", "input_2", "input_3" }); desc.add("graph_path", diff --git a/RecoBTag/TensorFlow/plugins/DeepDoubleCvLTFJetTagsProducer.cc b/RecoBTag/TensorFlow/plugins/DeepDoubleCvLTFJetTagsProducer.cc index f92d1819ece47..abd489423fd2b 100644 --- a/RecoBTag/TensorFlow/plugins/DeepDoubleCvLTFJetTagsProducer.cc +++ b/RecoBTag/TensorFlow/plugins/DeepDoubleCvLTFJetTagsProducer.cc @@ -13,7 +13,7 @@ #include "DataFormats/BTauReco/interface/JetTag.h" //#include "DataFormats/BTauReco/interface/DeepDoubleCvLTagInfo.h" -#include "DataFormats/BTauReco/interface/DeepDoubleBTagInfo.h" +#include "DataFormats/BTauReco/interface/DeepDoubleXTagInfo.h" #include "PhysicsTools/TensorFlow/interface/TensorFlow.h" @@ -57,7 +57,7 @@ class DeepDoubleCvLTFJetTagsProducer : public edm::stream::EDProducer TagInfoCollection; - typedef std::vector TagInfoCollection; + typedef std::vector TagInfoCollection; typedef reco::JetTagCollection JetTagCollection; void beginStream(edm::StreamID) override {} @@ -132,7 +132,7 @@ void DeepDoubleCvLTFJetTagsProducer::fillDescriptions(edm::ConfigurationDescript // pfDeepDoubleCvLJetTags edm::ParameterSetDescription desc; //desc.add("src", edm::InputTag("pfDeepDoubleCvLTagInfos")); - desc.add("src", edm::InputTag("pfDeepDoubleBTagInfos")); + desc.add("src", edm::InputTag("pfDeepDoubleXTagInfos")); desc.add>("input_names", { "input_1", "input_2", "input_3" }); desc.add("graph_path", diff --git a/RecoBTag/TensorFlow/python/pfDeepFlavour_cff.py b/RecoBTag/TensorFlow/python/pfDeepFlavour_cff.py index 668fce34bf030..4cd9109b07c8a 100644 --- a/RecoBTag/TensorFlow/python/pfDeepFlavour_cff.py +++ b/RecoBTag/TensorFlow/python/pfDeepFlavour_cff.py @@ -2,7 +2,7 @@ from RecoBTag.FeatureTools.pfDeepFlavourTagInfos_cfi import pfDeepFlavourTagInfos from RecoBTag.FeatureTools.pfNegativeDeepFlavourTagInfos_cfi import pfNegativeDeepFlavourTagInfos -from RecoBTag.FeatureTools.pfDeepDoubleBTagInfos_cfi import pfDeepDoubleBTagInfos +from RecoBTag.FeatureTools.pfDeepDoubleXTagInfos_cfi import pfDeepDoubleXTagInfos from RecoBTag.TensorFlow.pfDeepFlavourJetTags_cfi import pfDeepFlavourJetTags from RecoBTag.TensorFlow.pfNegativeDeepFlavourJetTags_cfi import pfNegativeDeepFlavourJetTags diff --git a/RecoBTag/TensorFlow/src/tensor_fillers.cc b/RecoBTag/TensorFlow/src/tensor_fillers.cc index cad5e3af82ee5..4a40676d42979 100644 --- a/RecoBTag/TensorFlow/src/tensor_fillers.cc +++ b/RecoBTag/TensorFlow/src/tensor_fillers.cc @@ -40,7 +40,7 @@ namespace btagbtvdeep { void db_tensor_filler(tensorflow::Tensor & tensor, std::size_t jet_n, - const btagbtvdeep::DeepDoubleBFeatures & features) { + const btagbtvdeep::DeepDoubleXFeatures & features) { float* ptr = &tensor.tensor()(jet_n, 0, 0); diff --git a/RecoBTag/TensorFlow/test/test_deep_doublec_cfg.py b/RecoBTag/TensorFlow/test/test_deep_doublec_cfg.py index a0756fd1c2000..750b9614b978e 100644 --- a/RecoBTag/TensorFlow/test/test_deep_doublec_cfg.py +++ b/RecoBTag/TensorFlow/test/test_deep_doublec_cfg.py @@ -79,7 +79,7 @@ process.out.outputCommands.append('keep *_selectedPatJets*_*_*') process.out.outputCommands.append('keep *_selectedUpdatedPatJets*_*_*') process.out.outputCommands.append('keep *_pfBoostedDoubleSVAK8TagInfos*_*_*') -process.out.outputCommands.append('keep *_pfDeepDoubleBTagInfos*_*_*') +process.out.outputCommands.append('keep *_pfDeepDoubleXTagInfos*_*_*') #process.out.outputCommands.append('keep *_pfDeepDoubleCvLTagInfos*_*_*') #process.out.outputCommands.append('keep *_pfDeepDoubleCvBTagInfos*_*_*') process.out.outputCommands.append('keep *_updatedPatJets*_*_*') From 4c34f163953383e03e7f87c714f52250a0e32581 Mon Sep 17 00:00:00 2001 From: anovak10 Date: Sat, 27 Oct 2018 10:40:58 +0200 Subject: [PATCH 05/30] renaming" --- .../BTauReco/interface/DeepDoubleXFeatures.h | 29 +++++++++++++++++++ .../BTauReco/interface/DeepDoubleXTagInfo.h | 15 ++++++++++ 2 files changed, 44 insertions(+) create mode 100644 DataFormats/BTauReco/interface/DeepDoubleXFeatures.h create mode 100644 DataFormats/BTauReco/interface/DeepDoubleXTagInfo.h diff --git a/DataFormats/BTauReco/interface/DeepDoubleXFeatures.h b/DataFormats/BTauReco/interface/DeepDoubleXFeatures.h new file mode 100644 index 0000000000000..81f5ffc839873 --- /dev/null +++ b/DataFormats/BTauReco/interface/DeepDoubleXFeatures.h @@ -0,0 +1,29 @@ +#ifndef DataFormats_BTauReco_DeepDoubleXFeatures_h +#define DataFormats_BTauReco_DeepDoubleXFeatures_h + +#include + +#include "DataFormats/BTauReco/interface/JetFeatures.h" +#include "DataFormats/BTauReco/interface/SecondaryVertexFeatures.h" +#include "DataFormats/BTauReco/interface/BoostedDoubleSVTagInfoFeatures.h" +#include "DataFormats/BTauReco/interface/ChargedCandidateFeatures.h" + +namespace btagbtvdeep { + +class DeepDoubleXFeatures { + + public: + JetFeatures jet_features; + BoostedDoubleSVTagInfoFeatures tag_info_features; + + std::vector sv_features; + + std::vector c_pf_features; + + std::size_t npv; // used by deep flavour +}; + + +} + +#endif //DataFormats_BTauReco_DeepDoubleXFeatures_h diff --git a/DataFormats/BTauReco/interface/DeepDoubleXTagInfo.h b/DataFormats/BTauReco/interface/DeepDoubleXTagInfo.h new file mode 100644 index 0000000000000..f126c1b686a46 --- /dev/null +++ b/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 DeepDoubleXTagInfo; + +DECLARE_EDM_REFS( DeepDoubleXTagInfo ) + +} + +#endif // DataFormats_BTauReco_DeepDoubleXTagInfo_h From 912c23daa9b68d1029a95445cb687a61e411b1e2 Mon Sep 17 00:00:00 2001 From: anovak10 Date: Sun, 28 Oct 2018 11:24:47 +0100 Subject: [PATCH 06/30] cleaning up --- RecoBTag/TensorFlow/test/test_deep_doublec_cfg.py | 1 - 1 file changed, 1 deletion(-) diff --git a/RecoBTag/TensorFlow/test/test_deep_doublec_cfg.py b/RecoBTag/TensorFlow/test/test_deep_doublec_cfg.py index 750b9614b978e..835d20d1c0562 100644 --- a/RecoBTag/TensorFlow/test/test_deep_doublec_cfg.py +++ b/RecoBTag/TensorFlow/test/test_deep_doublec_cfg.py @@ -81,7 +81,6 @@ process.out.outputCommands.append('keep *_pfBoostedDoubleSVAK8TagInfos*_*_*') process.out.outputCommands.append('keep *_pfDeepDoubleXTagInfos*_*_*') #process.out.outputCommands.append('keep *_pfDeepDoubleCvLTagInfos*_*_*') -#process.out.outputCommands.append('keep *_pfDeepDoubleCvBTagInfos*_*_*') process.out.outputCommands.append('keep *_updatedPatJets*_*_*') process.out.fileName = 'output_test_DDX.root' From dd24af3875b6addb2ddb341fe2919e538761864f Mon Sep 17 00:00:00 2001 From: anovak10 Date: Sun, 28 Oct 2018 15:07:37 +0100 Subject: [PATCH 07/30] Removing straggling comments --- .../python/recoLayer0/bTagging_cff.py | 6 +- .../TensorFlow/interface/tensor_fillers.h | 12 +-- .../TensorFlow/test/test_deep_doubleb_cfg.py | 88 ------------------- .../TensorFlow/test/test_deep_doublec_cfg.py | 1 - 4 files changed, 2 insertions(+), 105 deletions(-) delete mode 100644 RecoBTag/TensorFlow/test/test_deep_doubleb_cfg.py diff --git a/PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py b/PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py index 3ad2b8dfee25f..507a4a3e65194 100644 --- a/PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py +++ b/PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py @@ -41,12 +41,8 @@ # DeepFlavour tag infos , 'pfDeepFlavourTagInfos' , 'pfNegativeDeepFlavourTagInfos' - # DeepDoubleB tag infos + # DeepDoubleB/C tag infos , 'pfDeepDoubleXTagInfos' - # DeepDoubleCvL tag infos -# , 'pfDeepDoubleCvLTagInfos' - # DeepDoubleCvB tag infos -# , 'pfDeepDoubleCvBTagInfos' # DeepBoostedJet tag infos , 'pfDeepBoostedJetTagInfos' ] diff --git a/RecoBTag/TensorFlow/interface/tensor_fillers.h b/RecoBTag/TensorFlow/interface/tensor_fillers.h index 5ed4b5c9494a1..c6e3bd39ad8c6 100644 --- a/RecoBTag/TensorFlow/interface/tensor_fillers.h +++ b/RecoBTag/TensorFlow/interface/tensor_fillers.h @@ -4,8 +4,6 @@ #include "PhysicsTools/TensorFlow/interface/TensorFlow.h" #include "DataFormats/BTauReco/interface/DeepFlavourTagInfo.h" #include "DataFormats/BTauReco/interface/DeepDoubleXTagInfo.h" -//#include "DataFormats/BTauReco/interface/DeepDoubleCvLTagInfo.h" -//#include "DataFormats/BTauReco/interface/DeepDoubleCvBTagInfo.h" namespace btagbtvdeep { @@ -24,15 +22,7 @@ namespace btagbtvdeep { void db_tensor_filler(tensorflow::Tensor & tensor, std::size_t jet_n, const btagbtvdeep::DeepDoubleXFeatures & features) ; -/* - void db_tensor_filler(tensorflow::Tensor & tensor, - std::size_t jet_n, - const btagbtvdeep::DeepDoubleCvLFeatures & features) ; - - void db_tensor_filler(tensorflow::Tensor & tensor, - std::size_t jet_n, - const btagbtvdeep::DeepDoubleCvBFeatures & features) ; -*/ + void c_pf_tensor_filler(tensorflow::Tensor & tensor, std::size_t jet_n, std::size_t c_pf_n, diff --git a/RecoBTag/TensorFlow/test/test_deep_doubleb_cfg.py b/RecoBTag/TensorFlow/test/test_deep_doubleb_cfg.py deleted file mode 100644 index 71e1ab3a61c3b..0000000000000 --- a/RecoBTag/TensorFlow/test/test_deep_doubleb_cfg.py +++ /dev/null @@ -1,88 +0,0 @@ - -import FWCore.ParameterSet.Config as cms -from PhysicsTools.PatAlgos.tools.helpers import getPatAlgosToolsTask - -process = cms.Process("PATtest") - -## MessageLogger -process.load("FWCore.MessageLogger.MessageLogger_cfi") -process.MessageLogger.cerr.FwkReport.reportEvery = 1000 - - -## Options and Output Report -process.options = cms.untracked.PSet( wantSummary = cms.untracked.bool(True) ) - -## Source -process.source = cms.Source("PoolSource", - fileNames = cms.untracked.vstring() -) -## Maximal Number of Events -process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(-1) ) - -## Geometry and Detector Conditions (needed for a few patTuple production steps) -process.load("Configuration.Geometry.GeometryRecoDB_cff") -process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff") -from Configuration.AlCa.GlobalTag import GlobalTag -process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run2_mc') -process.load("Configuration.StandardSequences.MagneticField_cff") - -## Output Module Configuration (expects a path 'p') -from PhysicsTools.PatAlgos.patEventContent_cff import patEventContentNoCleaning -process.out = cms.OutputModule("PoolOutputModule", - fileName = cms.untracked.string('patTuple.root'), - ## save only events passing the full path - #SelectEvents = cms.untracked.PSet( SelectEvents = cms.vstring('p') ), - ## save PAT output; you need a '*' to unpack the list of commands - ## 'patEventContent' - outputCommands = cms.untracked.vstring('drop *', *patEventContentNoCleaning ) - ) - -patAlgosToolsTask = getPatAlgosToolsTask(process) -process.outpath = cms.EndPath(process.out, patAlgosToolsTask) - -## and add them to the event content -from PhysicsTools.PatAlgos.tools.jetTools import updateJetCollection - -updateJetCollection( - process, - jetSource = cms.InputTag('slimmedJetsAK8'), - pvSource = cms.InputTag('offlineSlimmedPrimaryVertices'), - svSource = cms.InputTag('slimmedSecondaryVertices'), - rParam = 0.8, - jetCorrections = ('AK8PFchs', cms.vstring(['L1FastJet', 'L2Relative', 'L3Absolute']), 'None'), - btagDiscriminators = [ - 'pfBoostedDoubleSecondaryVertexAK8BJetTags', - 'pfDeepDoubleBJetTags:probQ', - 'pfDeepDoubleBJetTags:probH', - ] - ) - -from PhysicsTools.PatAlgos.patInputFiles_cff import filesRelValTTbarPileUpMINIAODSIM - -process.source.fileNames = filesRelValTTbarPileUpMINIAODSIM -#process.source.fileNames = cms.untracked.vstring('root://cmsxrootd.fnal.gov//store/mc/PhaseIFall16MiniAOD/TT_TuneCUETP8M2T4_13TeV-powheg-pythia8/MINIAODSIM/PhaseIFall16PUFlat20to50_PhaseIFall16_81X_upgrade2017_realistic_v26-v1/50000/08358A47-61E3-E611-8B77-001E677928AE.root') -#process.source.fileNames = cms.untracked.vstring('root://cmsxrootd.fnal.gov//store/mc/RunIISummer16MiniAODv2/BulkGravTohhTohbbhbb_narrow_M-2500_13TeV-madgraph/MINIAODSIM/PUMoriond17_80X_mcRun2_asymptotic_2016_TrancheIV_v6-v1/80000/0A83E4E2-34B6-E611-89A0-549F35AE4FA2.root', -# 'root://cmsxrootd.fnal.gov//store/mc/RunIISummer16MiniAODv2/BulkGravTohhTohbbhbb_narrow_M-2500_13TeV-madgraph/MINIAODSIM/PUMoriond17_80X_mcRun2_asymptotic_2016_TrancheIV_v6-v1/80000/A88400F5-39B6-E611-BEB3-A0369F7F9DE0.root') - -process.source.fileNames = cms.untracked.vstring('root://cmsxrootd.fnal.gov//store/relval/CMSSW_10_1_0_pre2/RelValTTbar_13/MINIAODSIM/100X_mcRun2_asymptotic_v2_FastSim-v1/20000/3E39F14C-0420-E811-B368-0025905A6068.root', - 'root://cmsxrootd.fnal.gov//store/relval/CMSSW_10_1_0_pre2/RelValTTbar_13/MINIAODSIM/100X_mcRun2_asymptotic_v2_FastSim-v1/20000/40C11C7A-0E1F-E811-8A3A-0025905A607E.root', - 'root://cmsxrootd.fnal.gov//store/relval/CMSSW_10_1_0_pre2/RelValTTbar_13/MINIAODSIM/100X_mcRun2_asymptotic_v2_FastSim-v1/20000/F297A748-B220-E811-B9DD-0CC47A4C8EA8.root') -#process.source.fileNames = cms.untracked.vstring('root://cmsxrootd.fnal.gov//store/relval/CMSSW_10_1_0_pre2/RelValQCD_FlatPt_15_3000_13/MINIAODSIM/100X_mcRun2_asymptotic_v2_FastSim-v1/20000/8C8833F5-D822-E811-8ED5-0CC47A4D76A2.root') - -process.maxEvents.input = -1 - -from Configuration.EventContent.EventContent_cff import MINIAODSIMEventContent -process.out.outputCommands.append('keep *_slimmedJetsAK8*_*_*') -process.out.outputCommands.append('keep *_offlineSlimmedPrimaryVertices*_*_*') -process.out.outputCommands.append('keep *_slimmedSecondaryVertices*_*_*') -process.out.outputCommands.append('keep *_selectedPatJets*_*_*') -process.out.outputCommands.append('keep *_selectedUpdatedPatJets*_*_*') -process.out.outputCommands.append('keep *_pfBoostedDoubleSVAK8TagInfos*_*_*') -process.out.outputCommands.append('keep *_pfDeepDoubleBTagInfos*_*_*') -process.out.outputCommands.append('keep *_updatedPatJets*_*_*') - -process.out.fileName = 'test_deep_doubleb_MINIAODSIM.root' - -# ## -# process.options.wantSummary = False ## (to suppress the long output at the end of the job) -# process.add_(cms.Service("InitRootHandlers", DebugLevel =cms.untracked.int32(3))) diff --git a/RecoBTag/TensorFlow/test/test_deep_doublec_cfg.py b/RecoBTag/TensorFlow/test/test_deep_doublec_cfg.py index 835d20d1c0562..e1c5018f4fc5c 100644 --- a/RecoBTag/TensorFlow/test/test_deep_doublec_cfg.py +++ b/RecoBTag/TensorFlow/test/test_deep_doublec_cfg.py @@ -80,7 +80,6 @@ process.out.outputCommands.append('keep *_selectedUpdatedPatJets*_*_*') process.out.outputCommands.append('keep *_pfBoostedDoubleSVAK8TagInfos*_*_*') process.out.outputCommands.append('keep *_pfDeepDoubleXTagInfos*_*_*') -#process.out.outputCommands.append('keep *_pfDeepDoubleCvLTagInfos*_*_*') process.out.outputCommands.append('keep *_updatedPatJets*_*_*') process.out.fileName = 'output_test_DDX.root' From c8210366067afbef2dcf4ddb51ab502554f11af8 Mon Sep 17 00:00:00 2001 From: anovak10 Date: Mon, 29 Oct 2018 20:15:25 +0100 Subject: [PATCH 08/30] Using one produces for all models --- .../python/recoLayer0/bTagging_cff.py | 8 +- .../python/slimming/applyDeepBtagging_cff.py | 4 +- .../TensorFlow/interface/tensor_fillers.h | 10 - .../plugins/DeepDoubleCvBTFJetTagsProducer.cc | 295 ------------------ .../plugins/DeepDoubleCvLTFJetTagsProducer.cc | 295 ------------------ ...cer.cc => DeepDoubleXTFJetTagsProducer.cc} | 96 ++++-- .../TensorFlow/python/pfDeepFlavour_cff.py | 2 +- RecoBTag/TensorFlow/src/tensor_fillers.cc | 78 ----- RecoBTag/TensorFlow/test/plot.py | 83 +++++ .../TensorFlow/test/test_deep_doubleb_cfg.py | 88 ------ .../test/test_deep_doubleb_cfg_AOD.py | 4 +- ...oublec_cfg.py => test_deep_doublex_cfg.py} | 6 +- 12 files changed, 167 insertions(+), 802 deletions(-) delete mode 100644 RecoBTag/TensorFlow/plugins/DeepDoubleCvBTFJetTagsProducer.cc delete mode 100644 RecoBTag/TensorFlow/plugins/DeepDoubleCvLTFJetTagsProducer.cc rename RecoBTag/TensorFlow/plugins/{DeepDoubleBTFJetTagsProducer.cc => DeepDoubleXTFJetTagsProducer.cc} (74%) create mode 100644 RecoBTag/TensorFlow/test/plot.py delete mode 100644 RecoBTag/TensorFlow/test/test_deep_doubleb_cfg.py rename RecoBTag/TensorFlow/test/{test_deep_doublec_cfg.py => test_deep_doublex_cfg.py} (97%) diff --git a/PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py b/PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py index 3ad2b8dfee25f..9b002ac9d9839 100644 --- a/PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py +++ b/PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py @@ -43,10 +43,6 @@ , 'pfNegativeDeepFlavourTagInfos' # DeepDoubleB tag infos , 'pfDeepDoubleXTagInfos' - # DeepDoubleCvL tag infos -# , 'pfDeepDoubleCvLTagInfos' - # DeepDoubleCvB tag infos -# , 'pfDeepDoubleCvBTagInfos' # DeepBoostedJet tag infos , 'pfDeepBoostedJetTagInfos' ] @@ -193,8 +189,8 @@ , 'pfNegativeDeepFlavourJetTags:probc' : [["pfNegativeDeepFlavourTagInfos"], ['pfDeepCSVNegativeTagInfos', "pfImpactParameterTagInfos", 'pfInclusiveSecondaryVertexFinderNegativeTagInfos']] , 'pfNegativeDeepFlavourJetTags:probuds' : [["pfNegativeDeepFlavourTagInfos"], ['pfDeepCSVNegativeTagInfos', "pfImpactParameterTagInfos", 'pfInclusiveSecondaryVertexFinderNegativeTagInfos']] , 'pfNegativeDeepFlavourJetTags:probg' : [["pfNegativeDeepFlavourTagInfos"], ['pfDeepCSVNegativeTagInfos', "pfImpactParameterTagInfos", 'pfInclusiveSecondaryVertexFinderNegativeTagInfos']] - , 'pfDeepDoubleBJetTags:probQ' : [["pfDeepDoubleXTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']] - , 'pfDeepDoubleBJetTags:probH' : [["pfDeepDoubleXTagInfos"], ['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']] diff --git a/PhysicsTools/PatAlgos/python/slimming/applyDeepBtagging_cff.py b/PhysicsTools/PatAlgos/python/slimming/applyDeepBtagging_cff.py index 0dd11924dd490..9659059af4dc2 100644 --- a/PhysicsTools/PatAlgos/python/slimming/applyDeepBtagging_cff.py +++ b/PhysicsTools/PatAlgos/python/slimming/applyDeepBtagging_cff.py @@ -60,8 +60,8 @@ def applyDeepBtagging( process, postfix="" ) : rParam = 0.8, jetCorrections = ('AK8PFPuppi', cms.vstring(['L2Relative', 'L3Absolute']), 'None'), btagDiscriminators = [ - 'pfDeepDoubleBJetTags:probQ', - 'pfDeepDoubleBJetTags:probH', + 'pfDeepDoubleBvLJetTags:probQCD', + 'pfDeepDoubleBvLJetTags:probHbb', 'pfDeepDoubleCvLJetTags:probQCD', 'pfDeepDoubleCvLJetTags:probHcc', 'pfDeepDoubleCvBJetTags:probHbb', diff --git a/RecoBTag/TensorFlow/interface/tensor_fillers.h b/RecoBTag/TensorFlow/interface/tensor_fillers.h index 5ed4b5c9494a1..5118ae01003d1 100644 --- a/RecoBTag/TensorFlow/interface/tensor_fillers.h +++ b/RecoBTag/TensorFlow/interface/tensor_fillers.h @@ -4,8 +4,6 @@ #include "PhysicsTools/TensorFlow/interface/TensorFlow.h" #include "DataFormats/BTauReco/interface/DeepFlavourTagInfo.h" #include "DataFormats/BTauReco/interface/DeepDoubleXTagInfo.h" -//#include "DataFormats/BTauReco/interface/DeepDoubleCvLTagInfo.h" -//#include "DataFormats/BTauReco/interface/DeepDoubleCvBTagInfo.h" namespace btagbtvdeep { @@ -24,15 +22,7 @@ namespace btagbtvdeep { void db_tensor_filler(tensorflow::Tensor & tensor, std::size_t jet_n, const btagbtvdeep::DeepDoubleXFeatures & features) ; -/* - void db_tensor_filler(tensorflow::Tensor & tensor, - std::size_t jet_n, - const btagbtvdeep::DeepDoubleCvLFeatures & features) ; - void db_tensor_filler(tensorflow::Tensor & tensor, - std::size_t jet_n, - const btagbtvdeep::DeepDoubleCvBFeatures & features) ; -*/ void c_pf_tensor_filler(tensorflow::Tensor & tensor, std::size_t jet_n, std::size_t c_pf_n, diff --git a/RecoBTag/TensorFlow/plugins/DeepDoubleCvBTFJetTagsProducer.cc b/RecoBTag/TensorFlow/plugins/DeepDoubleCvBTFJetTagsProducer.cc deleted file mode 100644 index a1b5ee73fc461..0000000000000 --- a/RecoBTag/TensorFlow/plugins/DeepDoubleCvBTFJetTagsProducer.cc +++ /dev/null @@ -1,295 +0,0 @@ - -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/stream/EDProducer.h" - -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" - -#include "FWCore/Framework/interface/makeRefToBaseProdFrom.h" - -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/Utilities/interface/StreamID.h" - -#include "DataFormats/BTauReco/interface/JetTag.h" - -//#include "DataFormats/BTauReco/interface/DeepDoubleCvBTagInfo.h" -#include "DataFormats/BTauReco/interface/DeepDoubleXTagInfo.h" - -#include "PhysicsTools/TensorFlow/interface/TensorFlow.h" - -#include "RecoBTag/TensorFlow/interface/tensor_fillers.h" - -// Declaration of the data structure that is hold by the edm::GlobalCache. -// In TensorFlow, the computational graph is stored in a stateless graph object which can be shared -// by multiple session instances which handle the initialization of variables related to the graph. -// Following this approach in CMSSW, a graph should be stored in a GlobalCache which can be accessed -// by sessions owned by multiple stream module copies. Instead of using only the plain graph, we -// make use of a cache struct that can be extended in the future if nedded. In addition, the graph -// is protected via std::atomic, which should not affect the performance as it is only accessed in -// the module constructor and not in the actual produce loop. -struct DeepDoubleCvBTFCache { - DeepDoubleCvBTFCache() : graphDef(nullptr) { - } - - std::atomic graphDef; -}; - -class DeepDoubleCvBTFJetTagsProducer : public edm::stream::EDProducer> { - - public: - explicit DeepDoubleCvBTFJetTagsProducer(const edm::ParameterSet&, const DeepDoubleCvBTFCache*); - ~DeepDoubleCvBTFJetTagsProducer() override; - - static void fillDescriptions(edm::ConfigurationDescriptions&); - - static std::unique_ptr initializeGlobalCache(const edm::ParameterSet&); - static void globalEndJob(const DeepDoubleCvBTFCache*); - - enum InputIndexes { - kGlobal = 0, - kChargedCandidates = 1, - kVertices = 2 - }; - - enum OutputIndexes { - kJetFlavour = 0 - }; - - private: - //typedef std::vector TagInfoCollection; - typedef std::vector TagInfoCollection; - typedef reco::JetTagCollection JetTagCollection; - - void beginStream(edm::StreamID) override {} - void produce(edm::Event&, const edm::EventSetup&) override; - void endStream() override {} - - const edm::EDGetTokenT< TagInfoCollection > src_; - std::vector>> flav_pairs_; - std::vector input_names_; - std::vector output_names_; - std::vector lp_names_; - - // session for TF evaluation - tensorflow::Session* session_; - // vector of learning phase tensors, i.e., boolean scalar tensors pointing to false - std::vector lp_tensors_; - // flag to evaluate model batch or jet by jet - bool batch_eval_; -}; - -DeepDoubleCvBTFJetTagsProducer::DeepDoubleCvBTFJetTagsProducer(const edm::ParameterSet& iConfig, - const DeepDoubleCvBTFCache* cache) : - src_(consumes(iConfig.getParameter("src"))), - input_names_(iConfig.getParameter>("input_names")), - output_names_(iConfig.getParameter>("output_names")), - lp_names_(iConfig.getParameter>("lp_names")), - session_(nullptr), - batch_eval_(iConfig.getParameter("batch_eval")) -{ - // get threading config and build session options - size_t nThreads = iConfig.getParameter("nThreads"); - std::string singleThreadPool = iConfig.getParameter("singleThreadPool"); - tensorflow::SessionOptions sessionOptions; - tensorflow::setThreading(sessionOptions, nThreads, singleThreadPool); - - // create the session using the meta graph from the cache - session_ = tensorflow::createSession(cache->graphDef, sessionOptions); - - // get output names from flav_table - const auto & flav_pset = iConfig.getParameter("flav_table"); - for (const auto flav_pair : flav_pset.tbl()) { - const auto & flav_name = flav_pair.first; - flav_pairs_.emplace_back(flav_name, - flav_pset.getParameter>(flav_name)); - } - - for (const auto & flav_pair : flav_pairs_) { - produces(flav_pair.first); - } - - // flag inputs (required because of batch norm) - // names for the learing phase placeholders (to init and set as false) - for (size_t i = 0; i < lp_names_.size(); i++) { - // create a bool tensor, set its value to false and store it - tensorflow::Tensor t(tensorflow::DT_BOOL, {}); - t.scalar()() = false; - lp_tensors_.push_back(t); - } -} - -DeepDoubleCvBTFJetTagsProducer::~DeepDoubleCvBTFJetTagsProducer() -{ - // close and delete the session - if (session_ != nullptr) { - tensorflow::closeSession(session_); - } -} - -void DeepDoubleCvBTFJetTagsProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) -{ - - // pfDeepDoubleCvBJetTags - edm::ParameterSetDescription desc; - //desc.add("src", edm::InputTag("pfDeepDoubleCvBTagInfos")); - desc.add("src", edm::InputTag("pfDeepDoubleXTagInfos")); - desc.add>("input_names", - { "input_1", "input_2", "input_3" }); - desc.add("graph_path", - edm::FileInPath("RecoBTag/Combined/data/DeepDoubleC/V01/DDCvB.pb")); - desc.add>("lp_names", - { "db_input_batchnorm/keras_learning_phase" }); - desc.add>("output_names", - { "ID_pred/Softmax" }); - { - edm::ParameterSetDescription psd0; - psd0.add>("probHbb", {0}); - psd0.add>("probHcc", {1}); - desc.add("flav_table", psd0); - } - - desc.add("batch_eval", false); - - desc.add("nThreads", 1); - desc.add("singleThreadPool", "no_threads"); - - descriptions.add("pfDeepDoubleCvBJetTags", desc); -} - -std::unique_ptr DeepDoubleCvBTFJetTagsProducer::initializeGlobalCache( - const edm::ParameterSet& iConfig) -{ - // set the tensorflow log level to error - tensorflow::setLogging("3"); - - // get the pb file - std::string pbFile = iConfig.getParameter("graph_path").fullPath(); - - // load the graph def and save it in the cache - DeepDoubleCvBTFCache* cache = new DeepDoubleCvBTFCache(); - cache->graphDef = tensorflow::loadGraphDef(pbFile); - - return std::unique_ptr(cache); -} - -void DeepDoubleCvBTFJetTagsProducer::globalEndJob(const DeepDoubleCvBTFCache* cache) -{ - if (cache->graphDef != nullptr) { - delete cache->graphDef; - } -} - -void DeepDoubleCvBTFJetTagsProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) -{ - - edm::Handle tag_infos; - iEvent.getByToken(src_, tag_infos); - - // initialize output collection - std::vector> output_tags; - for (std::size_t i=0; i < flav_pairs_.size(); i++) { - if (!tag_infos->empty()) { - auto jet_ref = tag_infos->begin()->jet(); - output_tags.emplace_back(std::make_unique( - edm::makeRefToBaseProdFrom(jet_ref, iEvent))); - } else { - output_tags.emplace_back(std::make_unique()); - } - } - - const int64_t n_jets = tag_infos->size(); - // either all jets or one per batch for the time being - const int64_t n_batch_jets = batch_eval_ ? n_jets : 1; - - - std::vector input_sizes { - {n_batch_jets, 1, 27}, // input_1 - global double-b features - {n_batch_jets, 60, 8}, // input_2 - charged pf - {n_batch_jets, 5, 2}, // input_3 - vertices - }; - - // create a list of named tensors, i.e. a vector of (string, Tensor) pairs, with proper size to - // prevent element copying that would occur via push_back's - // the default Tensor constructor creates a scalar so this should be fine w.r.t. to memory - tensorflow::NamedTensorList input_tensors; - input_tensors.resize(input_sizes.size() + lp_tensors_.size()); - - // add actual input tensors that hold physics information - for (std::size_t i=0; i < input_sizes.size(); i++) { - input_tensors[i] = tensorflow::NamedTensor( - input_names_[i], tensorflow::Tensor(tensorflow::DT_FLOAT, input_sizes.at(i))); - } - - // add learning-phase tensors behind them - for (std::size_t i=0; i < lp_tensors_.size(); i++) { - input_tensors[input_sizes.size() + i] = tensorflow::NamedTensor(lp_names_[i], lp_tensors_[i]); - } - - std::size_t n_batches = n_jets/n_batch_jets; // either 1 or n_jets - for (std::size_t batch_n=0; batch_n < n_batches; batch_n++) { - - // tensors have to be zeroed before filling per batch - for (std::size_t i=0; i < input_sizes.size(); i++) { - input_tensors[i].second.flat().setZero(); - } - - // fill values of the input tensors - for (std::size_t jet_bn=0; jet_bn < (std::size_t) n_batch_jets; jet_bn++) { - - // global jet index (jet_bn is the jet batch index) - std::size_t jet_n = batch_n*n_batch_jets + jet_bn; - - // jet and other global features - const auto & features = tag_infos->at(jet_n).features(); - db_tensor_filler(input_tensors.at(kGlobal).second, jet_bn, features); - - - // c_pf candidates - auto max_c_pf_n = std::min(features.c_pf_features.size(), - (std::size_t) input_sizes.at(kChargedCandidates).dim_size(1)); - for (std::size_t c_pf_n=0; c_pf_n < max_c_pf_n; c_pf_n++) { - const auto & c_pf_features = features.c_pf_features.at(c_pf_n); - c_pf_reduced_tensor_filler(input_tensors.at(kChargedCandidates).second, - jet_bn, c_pf_n, c_pf_features); - } - - // sv candidates - auto max_sv_n = std::min(features.sv_features.size(), - (std::size_t) input_sizes.at(kVertices).dim_size(1)); - for (std::size_t sv_n=0; sv_n < max_sv_n; sv_n++) { - const auto & sv_features = features.sv_features.at(sv_n); - sv_reduced_tensor_filler(input_tensors.at(kVertices).second, - jet_bn, sv_n, sv_features); - } - - } - // run the session - std::vector outputs; - tensorflow::run(session_, input_tensors, output_names_, &outputs); - - // set output values for flavour probs - for (std::size_t jet_bn=0; jet_bn < (std::size_t) n_batch_jets; jet_bn++) { - - // global jet index (jet_bn is the jet batch index) - std::size_t jet_n = batch_n*n_batch_jets + jet_bn; - - const auto & jet_ref = tag_infos->at(jet_n).jet(); - for (std::size_t flav_n=0; flav_n < flav_pairs_.size(); flav_n++) { - const auto & flav_pair = flav_pairs_.at(flav_n); - float o_sum = 0.; - for (const unsigned int & ind : flav_pair.second) { - o_sum += outputs.at(kJetFlavour).matrix()(jet_bn, ind); - } - (*(output_tags.at(flav_n)))[jet_ref] = o_sum; - } - } - } - - for (std::size_t i=0; i < flav_pairs_.size(); i++) { - iEvent.put(std::move(output_tags[i]), flav_pairs_.at(i).first); - } - -} - -//define this as a plug-in -DEFINE_FWK_MODULE(DeepDoubleCvBTFJetTagsProducer); diff --git a/RecoBTag/TensorFlow/plugins/DeepDoubleCvLTFJetTagsProducer.cc b/RecoBTag/TensorFlow/plugins/DeepDoubleCvLTFJetTagsProducer.cc deleted file mode 100644 index abd489423fd2b..0000000000000 --- a/RecoBTag/TensorFlow/plugins/DeepDoubleCvLTFJetTagsProducer.cc +++ /dev/null @@ -1,295 +0,0 @@ - -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/stream/EDProducer.h" - -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" - -#include "FWCore/Framework/interface/makeRefToBaseProdFrom.h" - -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/Utilities/interface/StreamID.h" - -#include "DataFormats/BTauReco/interface/JetTag.h" - -//#include "DataFormats/BTauReco/interface/DeepDoubleCvLTagInfo.h" -#include "DataFormats/BTauReco/interface/DeepDoubleXTagInfo.h" - -#include "PhysicsTools/TensorFlow/interface/TensorFlow.h" - -#include "RecoBTag/TensorFlow/interface/tensor_fillers.h" - -// Declaration of the data structure that is hold by the edm::GlobalCache. -// In TensorFlow, the computational graph is stored 1in a stateless graph object which can be shared -// by multiple session instances which handle the initialization of variables related to the graph. -// Following this approach in CMSSW, a graph should be stored in a GlobalCache which can be accessed -// by sessions owned by multiple stream module copies. Instead of using only the plain graph, we -// make use of a cache struct that can be extended in the future if nedded. In addition, the graph -// is protected via std::atomic, which should not affect the performance as it is only accessed in -// the module constructor and not in the actual produce loop. -struct DeepDoubleCvLTFCache { - DeepDoubleCvLTFCache() : graphDef(nullptr) { - } - - std::atomic graphDef; -}; - -class DeepDoubleCvLTFJetTagsProducer : public edm::stream::EDProducer> { - - public: - explicit DeepDoubleCvLTFJetTagsProducer(const edm::ParameterSet&, const DeepDoubleCvLTFCache*); - ~DeepDoubleCvLTFJetTagsProducer() override; - - static void fillDescriptions(edm::ConfigurationDescriptions&); - - static std::unique_ptr initializeGlobalCache(const edm::ParameterSet&); - static void globalEndJob(const DeepDoubleCvLTFCache*); - - enum InputIndexes { - kGlobal = 0, - kChargedCandidates = 1, - kVertices = 2 - }; - - enum OutputIndexes { - kJetFlavour = 0 - }; - - private: - //typedef std::vector TagInfoCollection; - typedef std::vector TagInfoCollection; - typedef reco::JetTagCollection JetTagCollection; - - void beginStream(edm::StreamID) override {} - void produce(edm::Event&, const edm::EventSetup&) override; - void endStream() override {} - - const edm::EDGetTokenT< TagInfoCollection > src_; - std::vector>> flav_pairs_; - std::vector input_names_; - std::vector output_names_; - std::vector lp_names_; - - // session for TF evaluation - tensorflow::Session* session_; - // vector of learning phase tensors, i.e., boolean scalar tensors pointing to false - std::vector lp_tensors_; - // flag to evaluate model batch or jet by jet - bool batch_eval_; -}; - -DeepDoubleCvLTFJetTagsProducer::DeepDoubleCvLTFJetTagsProducer(const edm::ParameterSet& iConfig, - const DeepDoubleCvLTFCache* cache) : - src_(consumes(iConfig.getParameter("src"))), - input_names_(iConfig.getParameter>("input_names")), - output_names_(iConfig.getParameter>("output_names")), - lp_names_(iConfig.getParameter>("lp_names")), - session_(nullptr), - batch_eval_(iConfig.getParameter("batch_eval")) -{ - // get threading config and build session options - size_t nThreads = iConfig.getParameter("nThreads"); - std::string singleThreadPool = iConfig.getParameter("singleThreadPool"); - tensorflow::SessionOptions sessionOptions; - tensorflow::setThreading(sessionOptions, nThreads, singleThreadPool); - - // create the session using the meta graph from the cache - session_ = tensorflow::createSession(cache->graphDef, sessionOptions); - - // get output names from flav_table - const auto & flav_pset = iConfig.getParameter("flav_table"); - for (const auto flav_pair : flav_pset.tbl()) { - const auto & flav_name = flav_pair.first; - flav_pairs_.emplace_back(flav_name, - flav_pset.getParameter>(flav_name)); - } - - for (const auto & flav_pair : flav_pairs_) { - produces(flav_pair.first); - } - - // flag inputs (required because of batch norm) - // names for the learing phase placeholders (to init and set as false) - for (size_t i = 0; i < lp_names_.size(); i++) { - // create a bool tensor, set its value to false and store it - tensorflow::Tensor t(tensorflow::DT_BOOL, {}); - t.scalar()() = false; - lp_tensors_.push_back(t); - } -} - -DeepDoubleCvLTFJetTagsProducer::~DeepDoubleCvLTFJetTagsProducer() -{ - // close and delete the session - if (session_ != nullptr) { - tensorflow::closeSession(session_); - } -} - -void DeepDoubleCvLTFJetTagsProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) -{ - - // pfDeepDoubleCvLJetTags - edm::ParameterSetDescription desc; - //desc.add("src", edm::InputTag("pfDeepDoubleCvLTagInfos")); - desc.add("src", edm::InputTag("pfDeepDoubleXTagInfos")); - desc.add>("input_names", - { "input_1", "input_2", "input_3" }); - desc.add("graph_path", - edm::FileInPath("RecoBTag/Combined/data/DeepDoubleC/V01/DDCvL.pb")); - desc.add>("lp_names", - { "db_input_batchnorm/keras_learning_phase" }); - desc.add>("output_names", - { "ID_pred/Softmax" }); - { - edm::ParameterSetDescription psd0; - psd0.add>("probQCD", {0}); - psd0.add>("probHcc", {1}); - desc.add("flav_table", psd0); - } - - desc.add("batch_eval", false); - - desc.add("nThreads", 1); - desc.add("singleThreadPool", "no_threads"); - - descriptions.add("pfDeepDoubleCvLJetTags", desc); -} - -std::unique_ptr DeepDoubleCvLTFJetTagsProducer::initializeGlobalCache( - const edm::ParameterSet& iConfig) -{ - // set the tensorflow log level to error - tensorflow::setLogging("3"); - - // get the pb file - std::string pbFile = iConfig.getParameter("graph_path").fullPath(); - - // load the graph def and save it in the cache - DeepDoubleCvLTFCache* cache = new DeepDoubleCvLTFCache(); - cache->graphDef = tensorflow::loadGraphDef(pbFile); - - return std::unique_ptr(cache); -} - -void DeepDoubleCvLTFJetTagsProducer::globalEndJob(const DeepDoubleCvLTFCache* cache) -{ - if (cache->graphDef != nullptr) { - delete cache->graphDef; - } -} - -void DeepDoubleCvLTFJetTagsProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) -{ - - edm::Handle tag_infos; - iEvent.getByToken(src_, tag_infos); - - // initialize output collection - std::vector> output_tags; - for (std::size_t i=0; i < flav_pairs_.size(); i++) { - if (!tag_infos->empty()) { - auto jet_ref = tag_infos->begin()->jet(); - output_tags.emplace_back(std::make_unique( - edm::makeRefToBaseProdFrom(jet_ref, iEvent))); - } else { - output_tags.emplace_back(std::make_unique()); - } - } - - const int64_t n_jets = tag_infos->size(); - // either all jets or one per batch for the time being - const int64_t n_batch_jets = batch_eval_ ? n_jets : 1; - - - std::vector input_sizes { - {n_batch_jets, 1, 27}, // input_1 - global double-b features - {n_batch_jets, 60, 8}, // input_2 - charged pf - {n_batch_jets, 5, 2}, // input_3 - vertices - }; - - // create a list of named tensors, i.e. a vector of (string, Tensor) pairs, with proper size to - // prevent element copying that would occur via push_back's - // the default Tensor constructor creates a scalar so this should be fine w.r.t. to memory - tensorflow::NamedTensorList input_tensors; - input_tensors.resize(input_sizes.size() + lp_tensors_.size()); - - // add actual input tensors that hold physics information - for (std::size_t i=0; i < input_sizes.size(); i++) { - input_tensors[i] = tensorflow::NamedTensor( - input_names_[i], tensorflow::Tensor(tensorflow::DT_FLOAT, input_sizes.at(i))); - } - - // add learning-phase tensors behind them - for (std::size_t i=0; i < lp_tensors_.size(); i++) { - input_tensors[input_sizes.size() + i] = tensorflow::NamedTensor(lp_names_[i], lp_tensors_[i]); - } - - std::size_t n_batches = n_jets/n_batch_jets; // either 1 or n_jets - for (std::size_t batch_n=0; batch_n < n_batches; batch_n++) { - - // tensors have to be zeroed before filling per batch - for (std::size_t i=0; i < input_sizes.size(); i++) { - input_tensors[i].second.flat().setZero(); - } - - // fill values of the input tensors - for (std::size_t jet_bn=0; jet_bn < (std::size_t) n_batch_jets; jet_bn++) { - - // global jet index (jet_bn is the jet batch index) - std::size_t jet_n = batch_n*n_batch_jets + jet_bn; - - // jet and other global features - const auto & features = tag_infos->at(jet_n).features(); - db_tensor_filler(input_tensors.at(kGlobal).second, jet_bn, features); - - - // c_pf candidates - auto max_c_pf_n = std::min(features.c_pf_features.size(), - (std::size_t) input_sizes.at(kChargedCandidates).dim_size(1)); - for (std::size_t c_pf_n=0; c_pf_n < max_c_pf_n; c_pf_n++) { - const auto & c_pf_features = features.c_pf_features.at(c_pf_n); - c_pf_reduced_tensor_filler(input_tensors.at(kChargedCandidates).second, - jet_bn, c_pf_n, c_pf_features); - } - - // sv candidates - auto max_sv_n = std::min(features.sv_features.size(), - (std::size_t) input_sizes.at(kVertices).dim_size(1)); - for (std::size_t sv_n=0; sv_n < max_sv_n; sv_n++) { - const auto & sv_features = features.sv_features.at(sv_n); - sv_reduced_tensor_filler(input_tensors.at(kVertices).second, - jet_bn, sv_n, sv_features); - } - - } - // run the session - std::vector outputs; - tensorflow::run(session_, input_tensors, output_names_, &outputs); - - // set output values for flavour probs - for (std::size_t jet_bn=0; jet_bn < (std::size_t) n_batch_jets; jet_bn++) { - - // global jet index (jet_bn is the jet batch index) - std::size_t jet_n = batch_n*n_batch_jets + jet_bn; - - const auto & jet_ref = tag_infos->at(jet_n).jet(); - for (std::size_t flav_n=0; flav_n < flav_pairs_.size(); flav_n++) { - const auto & flav_pair = flav_pairs_.at(flav_n); - float o_sum = 0.; - for (const unsigned int & ind : flav_pair.second) { - o_sum += outputs.at(kJetFlavour).matrix()(jet_bn, ind); - } - (*(output_tags.at(flav_n)))[jet_ref] = o_sum; - } - } - } - - for (std::size_t i=0; i < flav_pairs_.size(); i++) { - iEvent.put(std::move(output_tags[i]), flav_pairs_.at(i).first); - } - -} - -//define this as a plug-in -DEFINE_FWK_MODULE(DeepDoubleCvLTFJetTagsProducer); diff --git a/RecoBTag/TensorFlow/plugins/DeepDoubleBTFJetTagsProducer.cc b/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc similarity index 74% rename from RecoBTag/TensorFlow/plugins/DeepDoubleBTFJetTagsProducer.cc rename to RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc index 3589183eb5787..d9fa52e691c29 100644 --- a/RecoBTag/TensorFlow/plugins/DeepDoubleBTFJetTagsProducer.cc +++ b/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc @@ -26,23 +26,23 @@ // make use of a cache struct that can be extended in the future if nedded. In addition, the graph // is protected via std::atomic, which should not affect the performance as it is only accessed in // the module constructor and not in the actual produce loop. -struct DeepDoubleBTFCache { - DeepDoubleBTFCache() : graphDef(nullptr) { +struct DeepDoubleXTFCache { + DeepDoubleXTFCache() : graphDef(nullptr) { } std::atomic graphDef; }; -class DeepDoubleBTFJetTagsProducer : public edm::stream::EDProducer> { +class DeepDoubleXTFJetTagsProducer : public edm::stream::EDProducer> { public: - explicit DeepDoubleBTFJetTagsProducer(const edm::ParameterSet&, const DeepDoubleBTFCache*); - ~DeepDoubleBTFJetTagsProducer() override; + explicit DeepDoubleXTFJetTagsProducer(const edm::ParameterSet&, const DeepDoubleXTFCache*); + ~DeepDoubleXTFJetTagsProducer() override; static void fillDescriptions(edm::ConfigurationDescriptions&); - static std::unique_ptr initializeGlobalCache(const edm::ParameterSet&); - static void globalEndJob(const DeepDoubleBTFCache*); + static std::unique_ptr initializeGlobalCache(const edm::ParameterSet&); + static void globalEndJob(const DeepDoubleXTFCache*); enum InputIndexes { kGlobal = 0, @@ -76,8 +76,8 @@ class DeepDoubleBTFJetTagsProducer : public edm::stream::EDProducer(iConfig.getParameter("src"))), input_names_(iConfig.getParameter>("input_names")), output_names_(iConfig.getParameter>("output_names")), @@ -116,7 +116,7 @@ DeepDoubleBTFJetTagsProducer::DeepDoubleBTFJetTagsProducer(const edm::ParameterS } } -DeepDoubleBTFJetTagsProducer::~DeepDoubleBTFJetTagsProducer() +DeepDoubleXTFJetTagsProducer::~DeepDoubleXTFJetTagsProducer() { // close and delete the session if (session_ != nullptr) { @@ -124,24 +124,25 @@ DeepDoubleBTFJetTagsProducer::~DeepDoubleBTFJetTagsProducer() } } -void DeepDoubleBTFJetTagsProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) +void DeepDoubleXTFJetTagsProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - // pfDeepDoubleBJetTags + // pfDeepDoubleBvLJetTags edm::ParameterSetDescription desc; desc.add("src", edm::InputTag("pfDeepDoubleXTagInfos")); desc.add>("input_names", { "input_1", "input_2", "input_3" }); desc.add("graph_path", - edm::FileInPath("RecoBTag/Combined/data/DeepDoubleB/V01/constant_graph_PtCut_MassSculptPen.pb")); + //edm::FileInPath("RecoBTag/Combined/data/DeepDoubleB/V01/constant_graph_PtCut_MassSculptPen.pb")); + edm::FileInPath("RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDB.pb")); desc.add>("lp_names", { "db_input_batchnorm/keras_learning_phase" }); desc.add>("output_names", { "ID_pred/Softmax" }); { edm::ParameterSetDescription psd0; - psd0.add>("probQ", {0}); - psd0.add>("probH", {1}); + psd0.add>("probQCD", {0}); + psd0.add>("probHbb", {1}); desc.add("flav_table", psd0); } @@ -150,10 +151,61 @@ void DeepDoubleBTFJetTagsProducer::fillDescriptions(edm::ConfigurationDescriptio desc.add("nThreads", 1); desc.add("singleThreadPool", "no_threads"); - descriptions.add("pfDeepDoubleBJetTags", desc); + descriptions.add("pfDeepDoubleBvLJetTags", desc); + + // pfDeepDoubleCvLJetTags + edm::ParameterSetDescription desc2; + desc2.add("src", edm::InputTag("pfDeepDoubleXTagInfos")); + desc2.add>("input_names", + { "input_1", "input_2", "input_3" }); + desc2.add("graph_path", + edm::FileInPath("RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDC.pb")); + desc2.add>("lp_names", + { "db_input_batchnorm/keras_learning_phase" }); + desc2.add>("output_names", + { "ID_pred/Softmax" }); + { + edm::ParameterSetDescription psd0; + psd0.add>("probQCD", {0}); + psd0.add>("probHcc", {1}); + desc2.add("flav_table", psd0); + } + + desc2.add("batch_eval", false); + + desc2.add("nThreads", 1); + desc2.add("singleThreadPool", "no_threads"); + + descriptions.add("pfDeepDoubleCvLJetTags", desc2); + + // pfDeepDoubleCvBJetTags + edm::ParameterSetDescription desc3; + desc3.add("src", edm::InputTag("pfDeepDoubleXTagInfos")); + desc3.add>("input_names", + { "input_1", "input_2", "input_3" }); + desc3.add("graph_path", + edm::FileInPath("RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDCvB.pb")); + desc3.add>("lp_names", + { "db_input_batchnorm/keras_learning_phase" }); + desc3.add>("output_names", + { "ID_pred/Softmax" }); + { + edm::ParameterSetDescription psd0; + psd0.add>("probHbb", {0}); + psd0.add>("probHcc", {1}); + desc3.add("flav_table", psd0); + } + + desc3.add("batch_eval", false); + + desc3.add("nThreads", 1); + desc3.add("singleThreadPool", "no_threads"); + descriptions.add("pfDeepDoubleCvBJetTags", desc3); + + } -std::unique_ptr DeepDoubleBTFJetTagsProducer::initializeGlobalCache( +std::unique_ptr DeepDoubleXTFJetTagsProducer::initializeGlobalCache( const edm::ParameterSet& iConfig) { // set the tensorflow log level to error @@ -163,20 +215,20 @@ std::unique_ptr DeepDoubleBTFJetTagsProducer::initializeGlob std::string pbFile = iConfig.getParameter("graph_path").fullPath(); // load the graph def and save it in the cache - DeepDoubleBTFCache* cache = new DeepDoubleBTFCache(); + DeepDoubleXTFCache* cache = new DeepDoubleXTFCache(); cache->graphDef = tensorflow::loadGraphDef(pbFile); - return std::unique_ptr(cache); + return std::unique_ptr(cache); } -void DeepDoubleBTFJetTagsProducer::globalEndJob(const DeepDoubleBTFCache* cache) +void DeepDoubleXTFJetTagsProducer::globalEndJob(const DeepDoubleXTFCache* cache) { if (cache->graphDef != nullptr) { delete cache->graphDef; } } -void DeepDoubleBTFJetTagsProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) +void DeepDoubleXTFJetTagsProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { edm::Handle tag_infos; @@ -289,4 +341,4 @@ void DeepDoubleBTFJetTagsProducer::produce(edm::Event& iEvent, const edm::EventS } //define this as a plug-in -DEFINE_FWK_MODULE(DeepDoubleBTFJetTagsProducer); +DEFINE_FWK_MODULE(DeepDoubleXTFJetTagsProducer); diff --git a/RecoBTag/TensorFlow/python/pfDeepFlavour_cff.py b/RecoBTag/TensorFlow/python/pfDeepFlavour_cff.py index 4cd9109b07c8a..447923b550829 100644 --- a/RecoBTag/TensorFlow/python/pfDeepFlavour_cff.py +++ b/RecoBTag/TensorFlow/python/pfDeepFlavour_cff.py @@ -6,7 +6,7 @@ from RecoBTag.TensorFlow.pfDeepFlavourJetTags_cfi import pfDeepFlavourJetTags from RecoBTag.TensorFlow.pfNegativeDeepFlavourJetTags_cfi import pfNegativeDeepFlavourJetTags -from RecoBTag.TensorFlow.pfDeepDoubleBJetTags_cfi import pfDeepDoubleBJetTags +from RecoBTag.TensorFlow.pfDeepDoubleBvLJetTags_cfi import pfDeepDoubleBvLJetTags from RecoBTag.TensorFlow.pfDeepDoubleCvBJetTags_cfi import pfDeepDoubleCvBJetTags from RecoBTag.TensorFlow.pfDeepDoubleCvLJetTags_cfi import pfDeepDoubleCvLJetTags from CommonTools.PileupAlgos.Puppi_cff import puppi diff --git a/RecoBTag/TensorFlow/src/tensor_fillers.cc b/RecoBTag/TensorFlow/src/tensor_fillers.cc index 4a40676d42979..35629465b8d6e 100644 --- a/RecoBTag/TensorFlow/src/tensor_fillers.cc +++ b/RecoBTag/TensorFlow/src/tensor_fillers.cc @@ -76,85 +76,7 @@ namespace btagbtvdeep { *(++ptr) = tag_info_features.trackSip3dSig_3; *(++ptr) = tag_info_features.z_ratio; } -/* - void db_tensor_filler(tensorflow::Tensor & tensor, - std::size_t jet_n, - const btagbtvdeep::DeepDoubleCvLFeatures & features) { - - float* ptr = &tensor.tensor()(jet_n, 0, 0); - - // variables from BoostedDoubleSVTagInfo - const auto & tag_info_features = features.tag_info_features; - *ptr = tag_info_features.jetNTracks; - *(++ptr) = tag_info_features.jetNSecondaryVertices; - *(++ptr) = tag_info_features.tau1_trackEtaRel_0; - *(++ptr) = tag_info_features.tau1_trackEtaRel_1; - *(++ptr) = tag_info_features.tau1_trackEtaRel_2; - *(++ptr) = tag_info_features.tau2_trackEtaRel_0; - *(++ptr) = tag_info_features.tau2_trackEtaRel_1; - *(++ptr) = tag_info_features.tau2_trackEtaRel_2; - *(++ptr) = tag_info_features.tau1_flightDistance2dSig; - *(++ptr) = tag_info_features.tau2_flightDistance2dSig; - *(++ptr) = tag_info_features.tau1_vertexDeltaR; - // Note: this variable is not used in the 27-input BDT - // *(++ptr) = tag_info_features.tau2_vertexDeltaR; - *(++ptr) = tag_info_features.tau1_vertexEnergyRatio; - *(++ptr) = tag_info_features.tau2_vertexEnergyRatio; - *(++ptr) = tag_info_features.tau1_vertexMass; - *(++ptr) = tag_info_features.tau2_vertexMass; - *(++ptr) = tag_info_features.trackSip2dSigAboveBottom_0; - *(++ptr) = tag_info_features.trackSip2dSigAboveBottom_1; - *(++ptr) = tag_info_features.trackSip2dSigAboveCharm; - *(++ptr) = tag_info_features.trackSip3dSig_0; - *(++ptr) = tag_info_features.tau1_trackSip3dSig_0; - *(++ptr) = tag_info_features.tau1_trackSip3dSig_1; - *(++ptr) = tag_info_features.trackSip3dSig_1; - *(++ptr) = tag_info_features.tau2_trackSip3dSig_0; - *(++ptr) = tag_info_features.tau2_trackSip3dSig_1; - *(++ptr) = tag_info_features.trackSip3dSig_2; - *(++ptr) = tag_info_features.trackSip3dSig_3; - *(++ptr) = tag_info_features.z_ratio; - } - void db_tensor_filler(tensorflow::Tensor & tensor, - std::size_t jet_n, - const btagbtvdeep::DeepDoubleCvBFeatures & features) { - - float* ptr = &tensor.tensor()(jet_n, 0, 0); - - // variables from BoostedDoubleSVTagInfo - const auto & tag_info_features = features.tag_info_features; - *ptr = tag_info_features.jetNTracks; - *(++ptr) = tag_info_features.jetNSecondaryVertices; - *(++ptr) = tag_info_features.tau1_trackEtaRel_0; - *(++ptr) = tag_info_features.tau1_trackEtaRel_1; - *(++ptr) = tag_info_features.tau1_trackEtaRel_2; - *(++ptr) = tag_info_features.tau2_trackEtaRel_0; - *(++ptr) = tag_info_features.tau2_trackEtaRel_1; - *(++ptr) = tag_info_features.tau2_trackEtaRel_2; - *(++ptr) = tag_info_features.tau1_flightDistance2dSig; - *(++ptr) = tag_info_features.tau2_flightDistance2dSig; - *(++ptr) = tag_info_features.tau1_vertexDeltaR; - // Note: this variable is not used in the 27-input BDT - // *(++ptr) = tag_info_features.tau2_vertexDeltaR; - *(++ptr) = tag_info_features.tau1_vertexEnergyRatio; - *(++ptr) = tag_info_features.tau2_vertexEnergyRatio; - *(++ptr) = tag_info_features.tau1_vertexMass; - *(++ptr) = tag_info_features.tau2_vertexMass; - *(++ptr) = tag_info_features.trackSip2dSigAboveBottom_0; - *(++ptr) = tag_info_features.trackSip2dSigAboveBottom_1; - *(++ptr) = tag_info_features.trackSip2dSigAboveCharm; - *(++ptr) = tag_info_features.trackSip3dSig_0; - *(++ptr) = tag_info_features.tau1_trackSip3dSig_0; - *(++ptr) = tag_info_features.tau1_trackSip3dSig_1; - *(++ptr) = tag_info_features.trackSip3dSig_1; - *(++ptr) = tag_info_features.tau2_trackSip3dSig_0; - *(++ptr) = tag_info_features.tau2_trackSip3dSig_1; - *(++ptr) = tag_info_features.trackSip3dSig_2; - *(++ptr) = tag_info_features.trackSip3dSig_3; - *(++ptr) = tag_info_features.z_ratio; - } -*/ void c_pf_tensor_filler(tensorflow::Tensor & tensor, std::size_t jet_n, std::size_t c_pf_n, diff --git a/RecoBTag/TensorFlow/test/plot.py b/RecoBTag/TensorFlow/test/plot.py new file mode 100644 index 0000000000000..0f28525154e03 --- /dev/null +++ b/RecoBTag/TensorFlow/test/plot.py @@ -0,0 +1,83 @@ +import ROOT +from DataFormats.FWLite import Handle, Events + +events_c = Events('output_test_DDX.root') + +handleJ = Handle ("std::vector") +#labelJ = ("slimmedJetsAK8","","PAT") +#labelJ = ("updatedPatJets","","PATtest") +labelJ = ("selectedUpdatedPatJets","","PATtest") +#labelJ = ("updatedPatJetsTransientCorrected","","PATtest") + + +# Type Module Label Process +# ----------------------------------------------------------------------------------------------- +# edm::ValueMap "offlineSlimmedPrimaryVertices" "" "PAT" +# vector "slimmedJetsAK8" "" "PAT" +# vector "slimmedJetsAK8PFPuppiSoftDropPacked" "SubJets" "PAT" +# vector "offlineSlimmedPrimaryVertices" "" "PAT" +# vector "slimmedSecondaryVertices" "" "PAT" +# edm::OwnVector > "selectedUpdatedPatJets" "tagInfos" "PATtest" +# edm::OwnVector > "updatedPatJets" "tagInfos" "PATtest" +# edm::OwnVector > "updatedPatJetsTransientCorrected" "tagInfos" "PATtest" +# vector "selectedUpdatedPatJets" "caloTowers" "PATtest" +# vector "selectedUpdatedPatJets" "" "PATtest" +# vector "updatedPatJets" "" "PATtest" +# vector "updatedPatJetsTransientCorrected" "" "PATtest" +# vector "pfBoostedDoubleSVAK8TagInfos" "" "PATtest" +# vector > "pfDeepDoubleBTagInfos" "" "PATtest" +# vector "selectedUpdatedPatJets" "genJets" "PATtest" +# vector "selectedUpdatedPatJets" "pfCandidates" "PATtest" + +h_probQ_ddb = ROOT.TH1F('h_probQ_ddb', ';prob Q;', 40, 0., 1.) +h_probH_ddb = ROOT.TH1F('h_probH_ddb', ';prob H;', 40, 0., 1.) +h_probQplusH_ddb = ROOT.TH1F('h_probQplusH_ddb', ';prob Q + H;', 44, 0., 1.1) + +h_probQ_ddc = ROOT.TH1F('h_probQ_ddc', ';prob Q;', 40, 0., 1.) +h_probH_ddc = ROOT.TH1F('h_probH_ddc', ';prob H;', 40, 0., 1.) +h_probQplusH_ddc = ROOT.TH1F('h_probQplusH_ddc', ';prob Q + H;', 44, 0., 1.1) + +for iev,event in enumerate(events_c): + event.getByLabel (labelJ, handleJ) + jets = handleJ.product() + print "eta phi probQ probH probQCD probH" + for jet in jets : + if jet.pt() < 300 or jet.pt() > 2000: continue + if jet.mass() < 40 or jet.mass() > 200: continue + + print jet.pt(), jet.mass() + print "DDB", jet.bDiscriminator("pfDeepDoubleBJetTags:probQ"), jet.bDiscriminator("pfDeepDoubleBJetTags:probH") + print "DDCvL", jet.bDiscriminator("pfDeepDoubleCvLJetTags:probQCD"), jet.bDiscriminator("pfDeepDoubleCvLJetTags:probHcc") + print "DDCvB", jet.bDiscriminator("pfDeepDoubleCvBJetTags:probHbb"), jet.bDiscriminator("pfDeepDoubleCvBJetTags:probHcc") + h_probQ_ddb.Fill(jet.bDiscriminator("pfDeepDoubleBJetTags:probQ")) + h_probH_ddb.Fill(jet.bDiscriminator("pfDeepDoubleBJetTags:probH")) + #h_probQplusH_ddb.Fill(jet.bDiscriminator("pfDeepDoubleBJetTags:probQ")+jet.bDiscriminator("pfDeepDoubleBJetTags:probH")) + h_probQ_ddc.Fill(jet.bDiscriminator("pfDeepDoubleCvLJetTags:probQCD")) + h_probH_ddc.Fill(jet.bDiscriminator("pfDeepDoubleCvLJetTags:probHcc")) + print "\nEvent", iev + if iev > 10000: break + +c1a = ROOT.TCanvas() +h_probH_ddb.Draw("HISTO") +h_probH_ddb.SetLineColor(632) +h_probH_ddb.SetLineStyle(10) +h_probQ_ddb.Draw("SAME") +c1a.Draw() +c1a.SaveAs("ProbQ_vc_vb.png") + +c1b = ROOT.TCanvas() +h_probH_ddc.Draw("HISTO") +h_probH_ddc.SetLineColor(632) +h_probH_ddc.SetLineStyle(10) +h_probQ_ddc.Draw("SAME") +c1b.Draw() +c1b.SaveAs("ProbH_vc_vb.png") + +#c1c = ROOT.TCanvas() +#h_probQplusH_ddb.Draw("HISTO") +#h_probQplusH_ddc.SetLineColor(632) +#h_probQplusH_ddc.SetLineStyle(10) +#h_probQplusH_ddc.Draw("SAME") +#c1c.Draw() +#c1c.SaveAs("ProbQplusH_vc_vc.pdf") + diff --git a/RecoBTag/TensorFlow/test/test_deep_doubleb_cfg.py b/RecoBTag/TensorFlow/test/test_deep_doubleb_cfg.py deleted file mode 100644 index 71e1ab3a61c3b..0000000000000 --- a/RecoBTag/TensorFlow/test/test_deep_doubleb_cfg.py +++ /dev/null @@ -1,88 +0,0 @@ - -import FWCore.ParameterSet.Config as cms -from PhysicsTools.PatAlgos.tools.helpers import getPatAlgosToolsTask - -process = cms.Process("PATtest") - -## MessageLogger -process.load("FWCore.MessageLogger.MessageLogger_cfi") -process.MessageLogger.cerr.FwkReport.reportEvery = 1000 - - -## Options and Output Report -process.options = cms.untracked.PSet( wantSummary = cms.untracked.bool(True) ) - -## Source -process.source = cms.Source("PoolSource", - fileNames = cms.untracked.vstring() -) -## Maximal Number of Events -process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(-1) ) - -## Geometry and Detector Conditions (needed for a few patTuple production steps) -process.load("Configuration.Geometry.GeometryRecoDB_cff") -process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff") -from Configuration.AlCa.GlobalTag import GlobalTag -process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run2_mc') -process.load("Configuration.StandardSequences.MagneticField_cff") - -## Output Module Configuration (expects a path 'p') -from PhysicsTools.PatAlgos.patEventContent_cff import patEventContentNoCleaning -process.out = cms.OutputModule("PoolOutputModule", - fileName = cms.untracked.string('patTuple.root'), - ## save only events passing the full path - #SelectEvents = cms.untracked.PSet( SelectEvents = cms.vstring('p') ), - ## save PAT output; you need a '*' to unpack the list of commands - ## 'patEventContent' - outputCommands = cms.untracked.vstring('drop *', *patEventContentNoCleaning ) - ) - -patAlgosToolsTask = getPatAlgosToolsTask(process) -process.outpath = cms.EndPath(process.out, patAlgosToolsTask) - -## and add them to the event content -from PhysicsTools.PatAlgos.tools.jetTools import updateJetCollection - -updateJetCollection( - process, - jetSource = cms.InputTag('slimmedJetsAK8'), - pvSource = cms.InputTag('offlineSlimmedPrimaryVertices'), - svSource = cms.InputTag('slimmedSecondaryVertices'), - rParam = 0.8, - jetCorrections = ('AK8PFchs', cms.vstring(['L1FastJet', 'L2Relative', 'L3Absolute']), 'None'), - btagDiscriminators = [ - 'pfBoostedDoubleSecondaryVertexAK8BJetTags', - 'pfDeepDoubleBJetTags:probQ', - 'pfDeepDoubleBJetTags:probH', - ] - ) - -from PhysicsTools.PatAlgos.patInputFiles_cff import filesRelValTTbarPileUpMINIAODSIM - -process.source.fileNames = filesRelValTTbarPileUpMINIAODSIM -#process.source.fileNames = cms.untracked.vstring('root://cmsxrootd.fnal.gov//store/mc/PhaseIFall16MiniAOD/TT_TuneCUETP8M2T4_13TeV-powheg-pythia8/MINIAODSIM/PhaseIFall16PUFlat20to50_PhaseIFall16_81X_upgrade2017_realistic_v26-v1/50000/08358A47-61E3-E611-8B77-001E677928AE.root') -#process.source.fileNames = cms.untracked.vstring('root://cmsxrootd.fnal.gov//store/mc/RunIISummer16MiniAODv2/BulkGravTohhTohbbhbb_narrow_M-2500_13TeV-madgraph/MINIAODSIM/PUMoriond17_80X_mcRun2_asymptotic_2016_TrancheIV_v6-v1/80000/0A83E4E2-34B6-E611-89A0-549F35AE4FA2.root', -# 'root://cmsxrootd.fnal.gov//store/mc/RunIISummer16MiniAODv2/BulkGravTohhTohbbhbb_narrow_M-2500_13TeV-madgraph/MINIAODSIM/PUMoriond17_80X_mcRun2_asymptotic_2016_TrancheIV_v6-v1/80000/A88400F5-39B6-E611-BEB3-A0369F7F9DE0.root') - -process.source.fileNames = cms.untracked.vstring('root://cmsxrootd.fnal.gov//store/relval/CMSSW_10_1_0_pre2/RelValTTbar_13/MINIAODSIM/100X_mcRun2_asymptotic_v2_FastSim-v1/20000/3E39F14C-0420-E811-B368-0025905A6068.root', - 'root://cmsxrootd.fnal.gov//store/relval/CMSSW_10_1_0_pre2/RelValTTbar_13/MINIAODSIM/100X_mcRun2_asymptotic_v2_FastSim-v1/20000/40C11C7A-0E1F-E811-8A3A-0025905A607E.root', - 'root://cmsxrootd.fnal.gov//store/relval/CMSSW_10_1_0_pre2/RelValTTbar_13/MINIAODSIM/100X_mcRun2_asymptotic_v2_FastSim-v1/20000/F297A748-B220-E811-B9DD-0CC47A4C8EA8.root') -#process.source.fileNames = cms.untracked.vstring('root://cmsxrootd.fnal.gov//store/relval/CMSSW_10_1_0_pre2/RelValQCD_FlatPt_15_3000_13/MINIAODSIM/100X_mcRun2_asymptotic_v2_FastSim-v1/20000/8C8833F5-D822-E811-8ED5-0CC47A4D76A2.root') - -process.maxEvents.input = -1 - -from Configuration.EventContent.EventContent_cff import MINIAODSIMEventContent -process.out.outputCommands.append('keep *_slimmedJetsAK8*_*_*') -process.out.outputCommands.append('keep *_offlineSlimmedPrimaryVertices*_*_*') -process.out.outputCommands.append('keep *_slimmedSecondaryVertices*_*_*') -process.out.outputCommands.append('keep *_selectedPatJets*_*_*') -process.out.outputCommands.append('keep *_selectedUpdatedPatJets*_*_*') -process.out.outputCommands.append('keep *_pfBoostedDoubleSVAK8TagInfos*_*_*') -process.out.outputCommands.append('keep *_pfDeepDoubleBTagInfos*_*_*') -process.out.outputCommands.append('keep *_updatedPatJets*_*_*') - -process.out.fileName = 'test_deep_doubleb_MINIAODSIM.root' - -# ## -# process.options.wantSummary = False ## (to suppress the long output at the end of the job) -# process.add_(cms.Service("InitRootHandlers", DebugLevel =cms.untracked.int32(3))) diff --git a/RecoBTag/TensorFlow/test/test_deep_doubleb_cfg_AOD.py b/RecoBTag/TensorFlow/test/test_deep_doubleb_cfg_AOD.py index d7133de5b1ed5..e601a060a97ca 100644 --- a/RecoBTag/TensorFlow/test/test_deep_doubleb_cfg_AOD.py +++ b/RecoBTag/TensorFlow/test/test_deep_doubleb_cfg_AOD.py @@ -72,8 +72,8 @@ jetCorrections = ('AK8PFPuppi', cms.vstring(['L1FastJet', 'L2Relative', 'L3Absolute']), 'Type-2'), btagDiscriminators = [ 'pfBoostedDoubleSecondaryVertexAK8BJetTags', - 'pfDeepDoubleBJetTags:probQ', - 'pfDeepDoubleBJetTags:probH', + 'pfDeepDoubleBvLJetTags:probQCD', + 'pfDeepDoubleBvLJetTags:probHbb', ] ) diff --git a/RecoBTag/TensorFlow/test/test_deep_doublec_cfg.py b/RecoBTag/TensorFlow/test/test_deep_doublex_cfg.py similarity index 97% rename from RecoBTag/TensorFlow/test/test_deep_doublec_cfg.py rename to RecoBTag/TensorFlow/test/test_deep_doublex_cfg.py index 835d20d1c0562..aad436b7ccfc9 100644 --- a/RecoBTag/TensorFlow/test/test_deep_doublec_cfg.py +++ b/RecoBTag/TensorFlow/test/test_deep_doublex_cfg.py @@ -6,7 +6,7 @@ ## MessageLogger process.load("FWCore.MessageLogger.MessageLogger_cfi") -process.MessageLogger.cerr.FwkReport.reportEvery = 1000 +process.MessageLogger.cerr.FwkReport.reportEvery = 100 ## Options and Output Report @@ -52,8 +52,8 @@ jetCorrections = ('AK8PFchs', cms.vstring(['L2Relative', 'L3Absolute']), 'None'), btagDiscriminators = [ 'pfBoostedDoubleSecondaryVertexAK8BJetTags', - 'pfDeepDoubleBJetTags:probQ', - 'pfDeepDoubleBJetTags:probH', + 'pfDeepDoubleBvLJetTags:probQCD', + 'pfDeepDoubleBvLJetTags:probHbb', 'pfDeepDoubleCvLJetTags:probQCD', 'pfDeepDoubleCvLJetTags:probHcc', 'pfDeepDoubleCvBJetTags:probHbb', From 901764783c28405e44fbf7bcd84acb1b9823caeb Mon Sep 17 00:00:00 2001 From: anovak10 Date: Mon, 29 Oct 2018 20:20:06 +0100 Subject: [PATCH 09/30] cleaning up --- RecoBTag/TensorFlow/test/plot.py | 10 ---------- RecoBTag/TensorFlow/test/test_deep_doublex_cfg.py | 3 +-- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/RecoBTag/TensorFlow/test/plot.py b/RecoBTag/TensorFlow/test/plot.py index 0f28525154e03..870f790c9511e 100644 --- a/RecoBTag/TensorFlow/test/plot.py +++ b/RecoBTag/TensorFlow/test/plot.py @@ -51,7 +51,6 @@ print "DDCvB", jet.bDiscriminator("pfDeepDoubleCvBJetTags:probHbb"), jet.bDiscriminator("pfDeepDoubleCvBJetTags:probHcc") h_probQ_ddb.Fill(jet.bDiscriminator("pfDeepDoubleBJetTags:probQ")) h_probH_ddb.Fill(jet.bDiscriminator("pfDeepDoubleBJetTags:probH")) - #h_probQplusH_ddb.Fill(jet.bDiscriminator("pfDeepDoubleBJetTags:probQ")+jet.bDiscriminator("pfDeepDoubleBJetTags:probH")) h_probQ_ddc.Fill(jet.bDiscriminator("pfDeepDoubleCvLJetTags:probQCD")) h_probH_ddc.Fill(jet.bDiscriminator("pfDeepDoubleCvLJetTags:probHcc")) print "\nEvent", iev @@ -72,12 +71,3 @@ h_probQ_ddc.Draw("SAME") c1b.Draw() c1b.SaveAs("ProbH_vc_vb.png") - -#c1c = ROOT.TCanvas() -#h_probQplusH_ddb.Draw("HISTO") -#h_probQplusH_ddc.SetLineColor(632) -#h_probQplusH_ddc.SetLineStyle(10) -#h_probQplusH_ddc.Draw("SAME") -#c1c.Draw() -#c1c.SaveAs("ProbQplusH_vc_vc.pdf") - diff --git a/RecoBTag/TensorFlow/test/test_deep_doublex_cfg.py b/RecoBTag/TensorFlow/test/test_deep_doublex_cfg.py index aad436b7ccfc9..53f681b0d47cf 100644 --- a/RecoBTag/TensorFlow/test/test_deep_doublex_cfg.py +++ b/RecoBTag/TensorFlow/test/test_deep_doublex_cfg.py @@ -6,7 +6,7 @@ ## MessageLogger process.load("FWCore.MessageLogger.MessageLogger_cfi") -process.MessageLogger.cerr.FwkReport.reportEvery = 100 +process.MessageLogger.cerr.FwkReport.reportEvery = 1000 ## Options and Output Report @@ -80,7 +80,6 @@ process.out.outputCommands.append('keep *_selectedUpdatedPatJets*_*_*') process.out.outputCommands.append('keep *_pfBoostedDoubleSVAK8TagInfos*_*_*') process.out.outputCommands.append('keep *_pfDeepDoubleXTagInfos*_*_*') -#process.out.outputCommands.append('keep *_pfDeepDoubleCvLTagInfos*_*_*') process.out.outputCommands.append('keep *_updatedPatJets*_*_*') process.out.fileName = 'output_test_DDX.root' From 147839a1a337b849db50c7db8f9cb7729d07067f Mon Sep 17 00:00:00 2001 From: anovak10 Date: Mon, 29 Oct 2018 20:22:02 +0100 Subject: [PATCH 10/30] Use default DDB model --- RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc b/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc index d9fa52e691c29..f47d4591326dc 100644 --- a/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc +++ b/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc @@ -133,8 +133,8 @@ void DeepDoubleXTFJetTagsProducer::fillDescriptions(edm::ConfigurationDescriptio desc.add>("input_names", { "input_1", "input_2", "input_3" }); desc.add("graph_path", - //edm::FileInPath("RecoBTag/Combined/data/DeepDoubleB/V01/constant_graph_PtCut_MassSculptPen.pb")); - edm::FileInPath("RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDB.pb")); + edm::FileInPath("RecoBTag/Combined/data/DeepDoubleB/V01/constant_graph_PtCut_MassSculptPen.pb")); + //edm::FileInPath("RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDB.pb")); desc.add>("lp_names", { "db_input_batchnorm/keras_learning_phase" }); desc.add>("output_names", From eb3e3ea18af1f77f785073eceee6d2c632f89f56 Mon Sep 17 00:00:00 2001 From: anovak10 Date: Tue, 30 Oct 2018 12:04:06 +0100 Subject: [PATCH 11/30] Addressing comments --- DataFormats/BTauReco/src/classes_def.xml | 3 +- ...ducer.cc => DeepDoubleXTagInfoProducer.cc} | 0 .../plugins/DeepDoubleXTFJetTagsProducer.cc | 1 - RecoBTag/TensorFlow/test/plot.py | 73 ------------------- .../test/test_deep_doubleb_cfg_AOD.py | 2 +- .../TensorFlow/test/test_deep_doublex_cfg.py | 8 +- 6 files changed, 6 insertions(+), 81 deletions(-) rename RecoBTag/FeatureTools/plugins/{DeepDoubleBTagInfoProducer.cc => DeepDoubleXTagInfoProducer.cc} (100%) delete mode 100644 RecoBTag/TensorFlow/test/plot.py diff --git a/DataFormats/BTauReco/src/classes_def.xml b/DataFormats/BTauReco/src/classes_def.xml index 533520da494b7..d0a8e9bb90f91 100644 --- a/DataFormats/BTauReco/src/classes_def.xml +++ b/DataFormats/BTauReco/src/classes_def.xml @@ -448,8 +448,7 @@ - - + diff --git a/RecoBTag/FeatureTools/plugins/DeepDoubleBTagInfoProducer.cc b/RecoBTag/FeatureTools/plugins/DeepDoubleXTagInfoProducer.cc similarity index 100% rename from RecoBTag/FeatureTools/plugins/DeepDoubleBTagInfoProducer.cc rename to RecoBTag/FeatureTools/plugins/DeepDoubleXTagInfoProducer.cc diff --git a/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc b/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc index f47d4591326dc..8b8d9971feebe 100644 --- a/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc +++ b/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc @@ -134,7 +134,6 @@ void DeepDoubleXTFJetTagsProducer::fillDescriptions(edm::ConfigurationDescriptio { "input_1", "input_2", "input_3" }); desc.add("graph_path", edm::FileInPath("RecoBTag/Combined/data/DeepDoubleB/V01/constant_graph_PtCut_MassSculptPen.pb")); - //edm::FileInPath("RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDB.pb")); desc.add>("lp_names", { "db_input_batchnorm/keras_learning_phase" }); desc.add>("output_names", diff --git a/RecoBTag/TensorFlow/test/plot.py b/RecoBTag/TensorFlow/test/plot.py deleted file mode 100644 index 870f790c9511e..0000000000000 --- a/RecoBTag/TensorFlow/test/plot.py +++ /dev/null @@ -1,73 +0,0 @@ -import ROOT -from DataFormats.FWLite import Handle, Events - -events_c = Events('output_test_DDX.root') - -handleJ = Handle ("std::vector") -#labelJ = ("slimmedJetsAK8","","PAT") -#labelJ = ("updatedPatJets","","PATtest") -labelJ = ("selectedUpdatedPatJets","","PATtest") -#labelJ = ("updatedPatJetsTransientCorrected","","PATtest") - - -# Type Module Label Process -# ----------------------------------------------------------------------------------------------- -# edm::ValueMap "offlineSlimmedPrimaryVertices" "" "PAT" -# vector "slimmedJetsAK8" "" "PAT" -# vector "slimmedJetsAK8PFPuppiSoftDropPacked" "SubJets" "PAT" -# vector "offlineSlimmedPrimaryVertices" "" "PAT" -# vector "slimmedSecondaryVertices" "" "PAT" -# edm::OwnVector > "selectedUpdatedPatJets" "tagInfos" "PATtest" -# edm::OwnVector > "updatedPatJets" "tagInfos" "PATtest" -# edm::OwnVector > "updatedPatJetsTransientCorrected" "tagInfos" "PATtest" -# vector "selectedUpdatedPatJets" "caloTowers" "PATtest" -# vector "selectedUpdatedPatJets" "" "PATtest" -# vector "updatedPatJets" "" "PATtest" -# vector "updatedPatJetsTransientCorrected" "" "PATtest" -# vector "pfBoostedDoubleSVAK8TagInfos" "" "PATtest" -# vector > "pfDeepDoubleBTagInfos" "" "PATtest" -# vector "selectedUpdatedPatJets" "genJets" "PATtest" -# vector "selectedUpdatedPatJets" "pfCandidates" "PATtest" - -h_probQ_ddb = ROOT.TH1F('h_probQ_ddb', ';prob Q;', 40, 0., 1.) -h_probH_ddb = ROOT.TH1F('h_probH_ddb', ';prob H;', 40, 0., 1.) -h_probQplusH_ddb = ROOT.TH1F('h_probQplusH_ddb', ';prob Q + H;', 44, 0., 1.1) - -h_probQ_ddc = ROOT.TH1F('h_probQ_ddc', ';prob Q;', 40, 0., 1.) -h_probH_ddc = ROOT.TH1F('h_probH_ddc', ';prob H;', 40, 0., 1.) -h_probQplusH_ddc = ROOT.TH1F('h_probQplusH_ddc', ';prob Q + H;', 44, 0., 1.1) - -for iev,event in enumerate(events_c): - event.getByLabel (labelJ, handleJ) - jets = handleJ.product() - print "eta phi probQ probH probQCD probH" - for jet in jets : - if jet.pt() < 300 or jet.pt() > 2000: continue - if jet.mass() < 40 or jet.mass() > 200: continue - - print jet.pt(), jet.mass() - print "DDB", jet.bDiscriminator("pfDeepDoubleBJetTags:probQ"), jet.bDiscriminator("pfDeepDoubleBJetTags:probH") - print "DDCvL", jet.bDiscriminator("pfDeepDoubleCvLJetTags:probQCD"), jet.bDiscriminator("pfDeepDoubleCvLJetTags:probHcc") - print "DDCvB", jet.bDiscriminator("pfDeepDoubleCvBJetTags:probHbb"), jet.bDiscriminator("pfDeepDoubleCvBJetTags:probHcc") - h_probQ_ddb.Fill(jet.bDiscriminator("pfDeepDoubleBJetTags:probQ")) - h_probH_ddb.Fill(jet.bDiscriminator("pfDeepDoubleBJetTags:probH")) - h_probQ_ddc.Fill(jet.bDiscriminator("pfDeepDoubleCvLJetTags:probQCD")) - h_probH_ddc.Fill(jet.bDiscriminator("pfDeepDoubleCvLJetTags:probHcc")) - print "\nEvent", iev - if iev > 10000: break - -c1a = ROOT.TCanvas() -h_probH_ddb.Draw("HISTO") -h_probH_ddb.SetLineColor(632) -h_probH_ddb.SetLineStyle(10) -h_probQ_ddb.Draw("SAME") -c1a.Draw() -c1a.SaveAs("ProbQ_vc_vb.png") - -c1b = ROOT.TCanvas() -h_probH_ddc.Draw("HISTO") -h_probH_ddc.SetLineColor(632) -h_probH_ddc.SetLineStyle(10) -h_probQ_ddc.Draw("SAME") -c1b.Draw() -c1b.SaveAs("ProbH_vc_vb.png") diff --git a/RecoBTag/TensorFlow/test/test_deep_doubleb_cfg_AOD.py b/RecoBTag/TensorFlow/test/test_deep_doubleb_cfg_AOD.py index e601a060a97ca..7ad0824949662 100644 --- a/RecoBTag/TensorFlow/test/test_deep_doubleb_cfg_AOD.py +++ b/RecoBTag/TensorFlow/test/test_deep_doubleb_cfg_AOD.py @@ -111,7 +111,7 @@ process.out.outputCommands.append('keep *_selectedPatJets*_*_*') process.out.outputCommands.append('keep *_selectedUpdatedPatJets*_*_*') process.out.outputCommands.append('keep *_pfBoostedDoubleSVAK8TagInfos*_*_*') -process.out.outputCommands.append('keep *_pfDeepDoubleBTagInfos*_*_*') +process.out.outputCommands.append('keep *_pfDeepDoubleXTagInfos*_*_*') process.out.outputCommands.append('keep *_updatedPatJets*_*_*') print(process.out.outputCommands) diff --git a/RecoBTag/TensorFlow/test/test_deep_doublex_cfg.py b/RecoBTag/TensorFlow/test/test_deep_doublex_cfg.py index 53f681b0d47cf..e721cdf816dfe 100644 --- a/RecoBTag/TensorFlow/test/test_deep_doublex_cfg.py +++ b/RecoBTag/TensorFlow/test/test_deep_doublex_cfg.py @@ -65,10 +65,10 @@ process.source.fileNames = filesRelValTTbarPileUpMINIAODSIM process.source.fileNames = cms.untracked.vstring( -'root://cmsxrootd.fnal.gov//store/relval/CMSSW_10_3_0_pre2/RelValTTbar_13/MINIAODSIM/PU25ns_103X_upgrade2018_realistic_v2-v1/20000/85820ACA-657B-BC44-AC74-AACD6D54B348.root' -#'root://cmsxrootd.fnal.gov//store/mc/RunIIFall17MiniAOD/GluGluHToBB_M125_13TeV_powheg_pythia8/MINIAODSIM/94X_mc2017_realistic_v10-v1/20000/C8932584-5006-E811-9840-141877410512.root', -#'root://cmsxrootd.fnal.gov//store/mc/RunIIFall17MiniAODv2/GluGluHToCC_M125_13TeV_powheg_pythia8/MINIAODSIM/PU2017_12Apr2018_94X_mc2017_realistic_v14-v2/30000/72164088-CB67-E811-9D0D-008CFA197AC4.root', -#'root://cmsxrootd.fnal.gov//store/mc/RunIIFall17MiniAOD/QCD_HT700to1000_TuneCP5_13TeV-madgraph-pythia8/MINIAODSIM/94X_mc2017_realistic_v10-v1/20000/C0F304A4-23FA-E711-942E-E0071B6CAD20.root' +'/store/relval/CMSSW_10_3_0_pre2/RelValTTbar_13/MINIAODSIM/PU25ns_103X_upgrade2018_realistic_v2-v1/20000/85820ACA-657B-BC44-AC74-AACD6D54B348.root' +#'/store/mc/RunIIFall17MiniAOD/GluGluHToBB_M125_13TeV_powheg_pythia8/MINIAODSIM/94X_mc2017_realistic_v10-v1/20000/C8932584-5006-E811-9840-141877410512.root', +#'/store/mc/RunIIFall17MiniAODv2/GluGluHToCC_M125_13TeV_powheg_pythia8/MINIAODSIM/PU2017_12Apr2018_94X_mc2017_realistic_v14-v2/30000/72164088-CB67-E811-9D0D-008CFA197AC4.root', +#'/store/mc/RunIIFall17MiniAOD/QCD_HT700to1000_TuneCP5_13TeV-madgraph-pythia8/MINIAODSIM/94X_mc2017_realistic_v10-v1/20000/C0F304A4-23FA-E711-942E-E0071B6CAD20.root' ) process.maxEvents.input = -1 From 9163e90a5fda757db56d0c29d501c41031ff84d1 Mon Sep 17 00:00:00 2001 From: anovak10 Date: Fri, 2 Nov 2018 11:33:09 +0100 Subject: [PATCH 12/30] Adding dummy optional params to pass validation --- .../python/recoLayer0/bTagging_cff.py | 4 +- .../python/slimming/applyDeepBtagging_cff.py | 2 +- .../plugins/DeepDoubleXTFJetTagsProducer.cc | 3 + RecoBTag/TensorFlow/test/plotDDX.py | 71 +++++++++++++++++++ 4 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 RecoBTag/TensorFlow/test/plotDDX.py diff --git a/PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py b/PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py index ddb2f908e1df1..7a4aa256b6a61 100644 --- a/PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py +++ b/PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py @@ -189,8 +189,8 @@ , 'pfNegativeDeepFlavourJetTags:probc' : [["pfNegativeDeepFlavourTagInfos"], ['pfDeepCSVNegativeTagInfos', "pfImpactParameterTagInfos", 'pfInclusiveSecondaryVertexFinderNegativeTagInfos']] , 'pfNegativeDeepFlavourJetTags:probuds' : [["pfNegativeDeepFlavourTagInfos"], ['pfDeepCSVNegativeTagInfos', "pfImpactParameterTagInfos", 'pfInclusiveSecondaryVertexFinderNegativeTagInfos']] , 'pfNegativeDeepFlavourJetTags:probg' : [["pfNegativeDeepFlavourTagInfos"], ['pfDeepCSVNegativeTagInfos', "pfImpactParameterTagInfos", 'pfInclusiveSecondaryVertexFinderNegativeTagInfos']] - , 'pfDeepDoubleBvLJetTags:probQCD' : [["pfDeepDoubleXTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']] - , 'pfDeepDoubleBvLJetTags:probHbb' : [["pfDeepDoubleXTagInfos"], ['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']] diff --git a/PhysicsTools/PatAlgos/python/slimming/applyDeepBtagging_cff.py b/PhysicsTools/PatAlgos/python/slimming/applyDeepBtagging_cff.py index 9659059af4dc2..89ae0413762c0 100644 --- a/PhysicsTools/PatAlgos/python/slimming/applyDeepBtagging_cff.py +++ b/PhysicsTools/PatAlgos/python/slimming/applyDeepBtagging_cff.py @@ -65,7 +65,7 @@ def applyDeepBtagging( process, postfix="" ) : 'pfDeepDoubleCvLJetTags:probQCD', 'pfDeepDoubleCvLJetTags:probHcc', 'pfDeepDoubleCvBJetTags:probHbb', - 'pfDeepDoubleCvBJetTags:probHcc', + 'pfDeepDoubleCvBJetTags:probHcc' ] + pfDeepBoostedJetTagsAll, postfix = 'SlimmedAK8DeepTags'+postfix, printWarning = False diff --git a/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc b/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc index 8b8d9971feebe..f8521fad886fd 100644 --- a/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc +++ b/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc @@ -142,6 +142,7 @@ void DeepDoubleXTFJetTagsProducer::fillDescriptions(edm::ConfigurationDescriptio edm::ParameterSetDescription psd0; psd0.add>("probQCD", {0}); psd0.add>("probHbb", {1}); + psd0.addOptional>("probHcc"); desc.add("flav_table", psd0); } @@ -167,6 +168,7 @@ void DeepDoubleXTFJetTagsProducer::fillDescriptions(edm::ConfigurationDescriptio edm::ParameterSetDescription psd0; psd0.add>("probQCD", {0}); psd0.add>("probHcc", {1}); + psd0.addOptional>("probHbb"); desc2.add("flav_table", psd0); } @@ -192,6 +194,7 @@ void DeepDoubleXTFJetTagsProducer::fillDescriptions(edm::ConfigurationDescriptio edm::ParameterSetDescription psd0; psd0.add>("probHbb", {0}); psd0.add>("probHcc", {1}); + psd0.addOptional>("probQCD"); desc3.add("flav_table", psd0); } diff --git a/RecoBTag/TensorFlow/test/plotDDX.py b/RecoBTag/TensorFlow/test/plotDDX.py new file mode 100644 index 0000000000000..503e16bd985ea --- /dev/null +++ b/RecoBTag/TensorFlow/test/plotDDX.py @@ -0,0 +1,71 @@ +import ROOT +from DataFormats.FWLite import Handle, Events + +events_c = Events('output_test_DDX.root') + +handleJ = Handle ("std::vector") +#labelJ = ("slimmedJetsAK8","","PAT") +#labelJ = ("updatedPatJets","","PATtest") +labelJ = ("selectedUpdatedPatJets","","PATtest") +#labelJ = ("updatedPatJetsTransientCorrected","","PATtest") + + +# Type Module Label Process +# ----------------------------------------------------------------------------------------------- +# edm::ValueMap "offlineSlimmedPrimaryVertices" "" "PAT" +# vector "slimmedJetsAK8" "" "PAT" +# vector "slimmedJetsAK8PFPuppiSoftDropPacked" "SubJets" "PAT" +# vector "offlineSlimmedPrimaryVertices" "" "PAT" +# vector "slimmedSecondaryVertices" "" "PAT" +# edm::OwnVector > "selectedUpdatedPatJets" "tagInfos" "PATtest" +# edm::OwnVector > "updatedPatJets" "tagInfos" "PATtest" +# edm::OwnVector > "updatedPatJetsTransientCorrected" "tagInfos" "PATtest" +# vector "selectedUpdatedPatJets" "caloTowers" "PATtest" +# vector "selectedUpdatedPatJets" "" "PATtest" +# vector "updatedPatJets" "" "PATtest" +# vector "updatedPatJetsTransientCorrected" "" "PATtest" +# vector "pfBoostedDoubleSVAK8TagInfos" "" "PATtest" +# vector > "pfDeepDoubleBTagInfos" "" "PATtest" +# vector "selectedUpdatedPatJets" "genJets" "PATtest" +# vector "selectedUpdatedPatJets" "pfCandidates" "PATtest" + +h_probQ_ddb = ROOT.TH1F('h_probQ_ddb', ';prob Q;', 40, 0., 1.) +h_probH_ddb = ROOT.TH1F('h_probH_ddb', ';prob H;', 40, 0., 1.) +h_probQplusH_ddb = ROOT.TH1F('h_probQplusH_ddb', ';prob Q + H;', 44, 0., 1.1) + +h_probQ_ddc = ROOT.TH1F('h_probQ_ddc', ';prob Q;', 40, 0., 1.) +h_probH_ddc = ROOT.TH1F('h_probH_ddc', ';prob H;', 40, 0., 1.) +h_probQplusH_ddc = ROOT.TH1F('h_probQplusH_ddc', ';prob Q + H;', 44, 0., 1.1) + +for iev,event in enumerate(events_c): + event.getByLabel (labelJ, handleJ) + jets = handleJ.product() + for jet in jets : + if jet.pt() < 300 or jet.pt() > 2000: continue + if jet.mass() < 40 or jet.mass() > 200: continue + + print jet.pt(), jet.mass() + print "DDB", jet.bDiscriminator("pfDeepDoubleBvLJetTags:probQCD"), jet.bDiscriminator("pfDeepDoubleBvLJetTags:probHbb") + print "DDCvL", jet.bDiscriminator("pfDeepDoubleCvLJetTags:probQCD"), jet.bDiscriminator("pfDeepDoubleCvLJetTags:probHcc") + print "DDCvB", jet.bDiscriminator("pfDeepDoubleCvBJetTags:probHbb"), jet.bDiscriminator("pfDeepDoubleCvBJetTags:probHcc") + h_probQ_ddb.Fill(jet.bDiscriminator("pfDeepDoubleBvLJetTags:probQCD")) + h_probH_ddb.Fill(jet.bDiscriminator("pfDeepDoubleBvLJetTags:probHbb")) + h_probQ_ddc.Fill(jet.bDiscriminator("pfDeepDoubleCvLJetTags:probQCD")) + h_probH_ddc.Fill(jet.bDiscriminator("pfDeepDoubleCvLJetTags:probHcc")) + if iev > 10000: break + +c1a = ROOT.TCanvas() +h_probH_ddb.Draw("HISTO") +h_probH_ddb.SetLineColor(632) +h_probH_ddb.SetLineStyle(10) +h_probQ_ddb.Draw("SAME") +c1a.Draw() +c1a.SaveAs("ProbQ_vc_vb.png") + +c1b = ROOT.TCanvas() +h_probH_ddc.Draw("HISTO") +h_probH_ddc.SetLineColor(632) +h_probH_ddc.SetLineStyle(10) +h_probQ_ddc.Draw("SAME") +c1b.Draw() +c1b.SaveAs("ProbH_vc_vb.png") From d656aa915e11d6ebaf723b748d61b16bb972c7b5 Mon Sep 17 00:00:00 2001 From: anovak10 Date: Fri, 2 Nov 2018 17:30:43 +0100 Subject: [PATCH 13/30] Slava might be fine with this, I guess --- .../python/recoLayer0/bTagging_cff.py | 4 ++ .../python/slimming/applyDeepBtagging_cff.py | 6 +- RecoBTag/Configuration/python/RecoBTag_cff.py | 1 + .../plugins/DeepDoubleXTFJetTagsProducer.cc | 56 +------------------ .../python/pfDeepDoubleCvBJetTags_cfi.py | 20 +++++++ .../python/pfDeepDoubleCvLJetTags_cfi.py | 20 +++++++ .../TensorFlow/python/pfDeepDoubleX_cff.py | 8 +++ .../TensorFlow/python/pfDeepFlavour_cff.py | 3 - ...MassIndependentDeepDoubleBvLJetTags_cfi.py | 20 +++++++ ...MassIndependentDeepDoubleCvBJetTags_cfi.py | 20 +++++++ ...MassIndependentDeepDoubleCvLJetTags_cfi.py | 20 +++++++ RecoBTag/TensorFlow/test/plotDDX.py | 8 ++- 12 files changed, 125 insertions(+), 61 deletions(-) create mode 100644 RecoBTag/TensorFlow/python/pfDeepDoubleCvBJetTags_cfi.py create mode 100644 RecoBTag/TensorFlow/python/pfDeepDoubleCvLJetTags_cfi.py create mode 100644 RecoBTag/TensorFlow/python/pfDeepDoubleX_cff.py create mode 100644 RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleBvLJetTags_cfi.py create mode 100644 RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleCvBJetTags_cfi.py create mode 100644 RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleCvLJetTags_cfi.py diff --git a/PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py b/PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py index 7a4aa256b6a61..687b00c92c501 100644 --- a/PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py +++ b/PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py @@ -195,6 +195,10 @@ , 'pfDeepDoubleCvLJetTags:probHcc' : [["pfDeepDoubleXTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']] , 'pfDeepDoubleCvBJetTags:probHbb' : [["pfDeepDoubleXTagInfos"], ['pfBoostedDoubleSVAK8TagInfos', "pfImpactParameterAK8TagInfos", 'pfInclusiveSecondaryVertexFinderAK8TagInfos']] , 'pfDeepDoubleCvBJetTags:probHcc' : [["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 diff --git a/PhysicsTools/PatAlgos/python/slimming/applyDeepBtagging_cff.py b/PhysicsTools/PatAlgos/python/slimming/applyDeepBtagging_cff.py index 89ae0413762c0..fec7331ad7ce4 100644 --- a/PhysicsTools/PatAlgos/python/slimming/applyDeepBtagging_cff.py +++ b/PhysicsTools/PatAlgos/python/slimming/applyDeepBtagging_cff.py @@ -65,7 +65,11 @@ def applyDeepBtagging( process, postfix="" ) : 'pfDeepDoubleCvLJetTags:probQCD', 'pfDeepDoubleCvLJetTags:probHcc', 'pfDeepDoubleCvBJetTags:probHbb', - 'pfDeepDoubleCvBJetTags:probHcc' + 'pfDeepDoubleCvBJetTags:probHcc', + 'pfMassIndependentDeepDoubleCvLJetTags:probQCD', + 'pfMassIndependentDeepDoubleCvLJetTags:probHcc', + 'pfMassIndependentDeepDoubleCvBJetTags:probHbb', + 'pfMassIndependentDeepDoubleCvBJetTags:probHcc', ] + pfDeepBoostedJetTagsAll, postfix = 'SlimmedAK8DeepTags'+postfix, printWarning = False diff --git a/RecoBTag/Configuration/python/RecoBTag_cff.py b/RecoBTag/Configuration/python/RecoBTag_cff.py index 170ceb6abe864..cb5fd4c174b7d 100644 --- a/RecoBTag/Configuration/python/RecoBTag_cff.py +++ b/RecoBTag/Configuration/python/RecoBTag_cff.py @@ -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 * diff --git a/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc b/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc index f8521fad886fd..1224ca847ddca 100644 --- a/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc +++ b/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc @@ -140,8 +140,8 @@ void DeepDoubleXTFJetTagsProducer::fillDescriptions(edm::ConfigurationDescriptio { "ID_pred/Softmax" }); { edm::ParameterSetDescription psd0; - psd0.add>("probQCD", {0}); - psd0.add>("probHbb", {1}); + psd0.addOptional>("probQCD", {0}); + psd0.addOptional>("probHbb", {1}); psd0.addOptional>("probHcc"); desc.add("flav_table", psd0); } @@ -153,58 +153,6 @@ void DeepDoubleXTFJetTagsProducer::fillDescriptions(edm::ConfigurationDescriptio descriptions.add("pfDeepDoubleBvLJetTags", desc); - // pfDeepDoubleCvLJetTags - edm::ParameterSetDescription desc2; - desc2.add("src", edm::InputTag("pfDeepDoubleXTagInfos")); - desc2.add>("input_names", - { "input_1", "input_2", "input_3" }); - desc2.add("graph_path", - edm::FileInPath("RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDC.pb")); - desc2.add>("lp_names", - { "db_input_batchnorm/keras_learning_phase" }); - desc2.add>("output_names", - { "ID_pred/Softmax" }); - { - edm::ParameterSetDescription psd0; - psd0.add>("probQCD", {0}); - psd0.add>("probHcc", {1}); - psd0.addOptional>("probHbb"); - desc2.add("flav_table", psd0); - } - - desc2.add("batch_eval", false); - - desc2.add("nThreads", 1); - desc2.add("singleThreadPool", "no_threads"); - - descriptions.add("pfDeepDoubleCvLJetTags", desc2); - - // pfDeepDoubleCvBJetTags - edm::ParameterSetDescription desc3; - desc3.add("src", edm::InputTag("pfDeepDoubleXTagInfos")); - desc3.add>("input_names", - { "input_1", "input_2", "input_3" }); - desc3.add("graph_path", - edm::FileInPath("RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDCvB.pb")); - desc3.add>("lp_names", - { "db_input_batchnorm/keras_learning_phase" }); - desc3.add>("output_names", - { "ID_pred/Softmax" }); - { - edm::ParameterSetDescription psd0; - psd0.add>("probHbb", {0}); - psd0.add>("probHcc", {1}); - psd0.addOptional>("probQCD"); - desc3.add("flav_table", psd0); - } - - desc3.add("batch_eval", false); - - desc3.add("nThreads", 1); - desc3.add("singleThreadPool", "no_threads"); - descriptions.add("pfDeepDoubleCvBJetTags", desc3); - - } std::unique_ptr DeepDoubleXTFJetTagsProducer::initializeGlobalCache( diff --git a/RecoBTag/TensorFlow/python/pfDeepDoubleCvBJetTags_cfi.py b/RecoBTag/TensorFlow/python/pfDeepDoubleCvBJetTags_cfi.py new file mode 100644 index 0000000000000..97dd42458b191 --- /dev/null +++ b/RecoBTag/TensorFlow/python/pfDeepDoubleCvBJetTags_cfi.py @@ -0,0 +1,20 @@ +import FWCore.ParameterSet.Config as cms + +pfDeepDoubleCvBJetTags = cms.EDProducer('DeepDoubleXTFJetTagsProducer', + src = cms.InputTag('pfDeepDoubleXTagInfos'), + input_names = cms.vstring( + 'input_1', + 'input_2', + 'input_3' + ), + graph_path = cms.FileInPath('RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDCvB.pb'), + lp_names = cms.vstring('db_input_batchnorm/keras_learning_phase'), + output_names = cms.vstring('ID_pred/Softmax'), + flav_table = cms.PSet( + probHbb = cms.vuint32(0), + probHcc = cms.vuint32(1) + ), + batch_eval = cms.bool(False), + nThreads = cms.uint32(1), + singleThreadPool = cms.string('no_threads') +) diff --git a/RecoBTag/TensorFlow/python/pfDeepDoubleCvLJetTags_cfi.py b/RecoBTag/TensorFlow/python/pfDeepDoubleCvLJetTags_cfi.py new file mode 100644 index 0000000000000..8ff8e90d5d9d1 --- /dev/null +++ b/RecoBTag/TensorFlow/python/pfDeepDoubleCvLJetTags_cfi.py @@ -0,0 +1,20 @@ +import FWCore.ParameterSet.Config as cms + +pfDeepDoubleCvLJetTags = cms.EDProducer('DeepDoubleXTFJetTagsProducer', + src = cms.InputTag('pfDeepDoubleXTagInfos'), + input_names = cms.vstring( + 'input_1', + 'input_2', + 'input_3' + ), + graph_path = cms.FileInPath('RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDC.pb'), + lp_names = cms.vstring('db_input_batchnorm/keras_learning_phase'), + output_names = cms.vstring('ID_pred/Softmax'), + flav_table = cms.PSet( + probQCD = cms.vuint32(0), + probHcc = cms.vuint32(1) + ), + batch_eval = cms.bool(False), + nThreads = cms.uint32(1), + singleThreadPool = cms.string('no_threads') +) diff --git a/RecoBTag/TensorFlow/python/pfDeepDoubleX_cff.py b/RecoBTag/TensorFlow/python/pfDeepDoubleX_cff.py new file mode 100644 index 0000000000000..d8b563a757e13 --- /dev/null +++ b/RecoBTag/TensorFlow/python/pfDeepDoubleX_cff.py @@ -0,0 +1,8 @@ +from RecoBTag.TensorFlow.pfDeepDoubleBvLJetTags_cfi import pfDeepDoubleBvLJetTags +from RecoBTag.TensorFlow.pfDeepDoubleCvBJetTags_cfi import pfDeepDoubleCvBJetTags +from RecoBTag.TensorFlow.pfDeepDoubleCvLJetTags_cfi import pfDeepDoubleCvLJetTags + +from RecoBTag.TensorFlow.pfMassIndependentDeepDoubleBvLJetTags_cfi import pfMassIndependentDeepDoubleBvLJetTags +from RecoBTag.TensorFlow.pfMassIndependentDeepDoubleCvBJetTags_cfi import pfMassIndependentDeepDoubleCvBJetTags +from RecoBTag.TensorFlow.pfMassIndependentDeepDoubleCvLJetTags_cfi import pfMassIndependentDeepDoubleCvLJetTags + diff --git a/RecoBTag/TensorFlow/python/pfDeepFlavour_cff.py b/RecoBTag/TensorFlow/python/pfDeepFlavour_cff.py index 447923b550829..481b0efa90f7e 100644 --- a/RecoBTag/TensorFlow/python/pfDeepFlavour_cff.py +++ b/RecoBTag/TensorFlow/python/pfDeepFlavour_cff.py @@ -6,9 +6,6 @@ from RecoBTag.TensorFlow.pfDeepFlavourJetTags_cfi import pfDeepFlavourJetTags from RecoBTag.TensorFlow.pfNegativeDeepFlavourJetTags_cfi import pfNegativeDeepFlavourJetTags -from RecoBTag.TensorFlow.pfDeepDoubleBvLJetTags_cfi import pfDeepDoubleBvLJetTags -from RecoBTag.TensorFlow.pfDeepDoubleCvBJetTags_cfi import pfDeepDoubleCvBJetTags -from RecoBTag.TensorFlow.pfDeepDoubleCvLJetTags_cfi import pfDeepDoubleCvLJetTags from CommonTools.PileupAlgos.Puppi_cff import puppi from PhysicsTools.PatAlgos.slimming.primaryVertexAssociation_cfi import primaryVertexAssociation diff --git a/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleBvLJetTags_cfi.py b/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleBvLJetTags_cfi.py new file mode 100644 index 0000000000000..ecb8e17dc0d23 --- /dev/null +++ b/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleBvLJetTags_cfi.py @@ -0,0 +1,20 @@ +import FWCore.ParameterSet.Config as cms + +pfMassIndependentDeepDoubleBvLJetTags = cms.EDProducer('DeepDoubleXTFJetTagsProducer', + src = cms.InputTag('pfDeepDoubleXTagInfos'), + input_names = cms.vstring( + 'input_1', + 'input_2', + 'input_3' + ), + graph_path = cms.FileInPath('RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDB_mass_independent.pb'), + lp_names = cms.vstring('db_input_batchnorm/keras_learning_phase'), + output_names = cms.vstring('ID_pred/Softmax'), + flav_table = cms.PSet( + probQCD = cms.vuint32(0), + probHbb = cms.vuint32(1) + ), + batch_eval = cms.bool(False), + nThreads = cms.uint32(1), + singleThreadPool = cms.string('no_threads') +) diff --git a/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleCvBJetTags_cfi.py b/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleCvBJetTags_cfi.py new file mode 100644 index 0000000000000..49c4c62c42b45 --- /dev/null +++ b/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleCvBJetTags_cfi.py @@ -0,0 +1,20 @@ +import FWCore.ParameterSet.Config as cms + +pfMassIndependentDeepDoubleCvBJetTags = cms.EDProducer('DeepDoubleXTFJetTagsProducer', + src = cms.InputTag('pfDeepDoubleXTagInfos'), + input_names = cms.vstring( + 'input_1', + 'input_2', + 'input_3' + ), + graph_path = cms.FileInPath('RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDCvB_mass_independent.pb'), + lp_names = cms.vstring('db_input_batchnorm/keras_learning_phase'), + output_names = cms.vstring('ID_pred/Softmax'), + flav_table = cms.PSet( + probHbb = cms.vuint32(0), + probHcc = cms.vuint32(1) + ), + batch_eval = cms.bool(False), + nThreads = cms.uint32(1), + singleThreadPool = cms.string('no_threads') +) diff --git a/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleCvLJetTags_cfi.py b/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleCvLJetTags_cfi.py new file mode 100644 index 0000000000000..8ce842a1c86de --- /dev/null +++ b/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleCvLJetTags_cfi.py @@ -0,0 +1,20 @@ +import FWCore.ParameterSet.Config as cms + +pfMassIndependentDeepDoubleCvLJetTags = cms.EDProducer('DeepDoubleXTFJetTagsProducer', + src = cms.InputTag('pfDeepDoubleXTagInfos'), + input_names = cms.vstring( + 'input_1', + 'input_2', + 'input_3' + ), + graph_path = cms.FileInPath('RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDC_mass_independent.pb'), + lp_names = cms.vstring('db_input_batchnorm/keras_learning_phase'), + output_names = cms.vstring('ID_pred/Softmax'), + flav_table = cms.PSet( + probQCD = cms.vuint32(0), + probHcc = cms.vuint32(1) + ), + batch_eval = cms.bool(False), + nThreads = cms.uint32(1), + singleThreadPool = cms.string('no_threads') +) diff --git a/RecoBTag/TensorFlow/test/plotDDX.py b/RecoBTag/TensorFlow/test/plotDDX.py index 503e16bd985ea..305468e51e5df 100644 --- a/RecoBTag/TensorFlow/test/plotDDX.py +++ b/RecoBTag/TensorFlow/test/plotDDX.py @@ -45,9 +45,11 @@ if jet.mass() < 40 or jet.mass() > 200: continue print jet.pt(), jet.mass() - print "DDB", jet.bDiscriminator("pfDeepDoubleBvLJetTags:probQCD"), jet.bDiscriminator("pfDeepDoubleBvLJetTags:probHbb") - print "DDCvL", jet.bDiscriminator("pfDeepDoubleCvLJetTags:probQCD"), jet.bDiscriminator("pfDeepDoubleCvLJetTags:probHcc") - print "DDCvB", jet.bDiscriminator("pfDeepDoubleCvBJetTags:probHbb"), jet.bDiscriminator("pfDeepDoubleCvBJetTags:probHcc") + print "DDB", jet.bDiscriminator("pfDeepDoubleBvLJetTags:probQCD"), jet.bDiscriminator("pfDeepDoubleBvLJetTags:probHbb") , jet.bDiscriminator("pfDeepDoubleBvLJetTags:probHcc") + print "DDCvL", jet.bDiscriminator("pfDeepDoubleCvLJetTags:probQCD"), jet.bDiscriminator("pfDeepDoubleCvLJetTags:probHcc") , jet.bDiscriminator("pfDeepDoubleCvLJetTags:probHbb") + print "DDCvL", jet.bDiscriminator("pfMassIndependentDeepDoubleCvLJetTags:probQCD"), jet.bDiscriminator("pfMassIndependentDeepDoubleCvLJetTags:probHcc") , jet.bDiscriminator("pfDeepDoubleMassIndependentCvLJetTags:probHbb") + print "DDCvB", jet.bDiscriminator("pfDeepDoubleCvBJetTags:probHbb"), jet.bDiscriminator("pfDeepDoubleCvBJetTags:probHcc") , jet.bDiscriminator("pfDeepDoubleCvBJetTags:probQCD") + print "DDCvB", jet.bDiscriminator("pfMassIndependentDeepDoubleCvBJetTags:probHbb"), jet.bDiscriminator("pfMassIndependentDeepDoubleCvBJetTags:probHcc") , jet.bDiscriminator("pfMassIndependentDeepDoubleCvBJetTags:probQCD") h_probQ_ddb.Fill(jet.bDiscriminator("pfDeepDoubleBvLJetTags:probQCD")) h_probH_ddb.Fill(jet.bDiscriminator("pfDeepDoubleBvLJetTags:probHbb")) h_probQ_ddc.Fill(jet.bDiscriminator("pfDeepDoubleCvLJetTags:probQCD")) From 0ed5f6f21652f07dd100a718f64fa881943fa6f7 Mon Sep 17 00:00:00 2001 From: anovak10 Date: Fri, 2 Nov 2018 18:39:29 +0100 Subject: [PATCH 14/30] Using switch in producer --- .../plugins/DeepDoubleXTFJetTagsProducer.cc | 42 +++++++++++++++++-- .../python/pfDeepDoubleCvBJetTags_cfi.py | 1 + .../python/pfDeepDoubleCvLJetTags_cfi.py | 1 + ...MassIndependentDeepDoubleBvLJetTags_cfi.py | 1 + ...MassIndependentDeepDoubleCvBJetTags_cfi.py | 1 + ...MassIndependentDeepDoubleCvLJetTags_cfi.py | 1 + .../TensorFlow/test/test_deep_doublex_cfg.py | 8 +++- 7 files changed, 50 insertions(+), 5 deletions(-) diff --git a/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc b/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc index 1224ca847ddca..d91bfc86b10fd 100644 --- a/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc +++ b/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc @@ -132,19 +132,55 @@ void DeepDoubleXTFJetTagsProducer::fillDescriptions(edm::ConfigurationDescriptio desc.add("src", edm::InputTag("pfDeepDoubleXTagInfos")); desc.add>("input_names", { "input_1", "input_2", "input_3" }); - desc.add("graph_path", - edm::FileInPath("RecoBTag/Combined/data/DeepDoubleB/V01/constant_graph_PtCut_MassSculptPen.pb")); + //desc.add("graph_path", + // edm::FileInPath("RecoBTag/Combined/data/DeepDoubleB/V01/constant_graph_PtCut_MassSculptPen.pb")); desc.add>("lp_names", { "db_input_batchnorm/keras_learning_phase" }); desc.add>("output_names", { "ID_pred/Softmax" }); + + /*desc.ifValue( edm::ParameterDescription("model", "BvL", true), + "BvL" >> edm::ParameterDescription("graph_path", edm::FileInPath("RecoBTag/Combined/data/DeepDoubleB/V01/constant_graph_PtCut_MassSculptPen.pb"), true) or + "CvL" >> edm::ParameterDescription("graph_path", edm::FileInPath("RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDC.pb"), true) or + "CvB" >> edm::ParameterDescription("graph_path", edm::FileInPath("RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDCvB.pb"), true) + );*/ + { + edm::ParameterSetDescription psBvL; + psBvL.add>("probQCD", {0}); + psBvL.add>("probHbb", {1}); + //psBvL.add("graph_path", edm::FileInPath("RecoBTag/Combined/data/DeepDoubleB/V01/constant_graph_PtCut_MassSculptPen.pb")); + + edm::ParameterSetDescription psCvL; + psCvL.add>("probQCD", {0}); + psCvL.add>("probHcc", {1}); + //psCvL.add("graph_path", edm::FileInPath("RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDC.pb")); + + edm::ParameterSetDescription psCvB; + psCvB.add>("probHbb", {0}); + psCvB.add>("probHcc", {1}); + //psCvB.add("graph_path", edm::FileInPath("RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDCvB.pb")); + + desc.ifValue( edm::ParameterDescription("flavor", "BvL", true), + "BvL" >> (edm::ParameterDescription("flav_table", psBvL, true) and + edm::ParameterDescription("graph_path", edm::FileInPath("RecoBTag/Combined/data/DeepDoubleB/V01/constant_graph_PtCut_MassSculptPen.pb"), true)) or + "CvL" >> (edm::ParameterDescription("flav_table", psCvL, true) and + edm::ParameterDescription("graph_path", edm::FileInPath("RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDC.pb"), true) ) or + "CvB" >> (edm::ParameterDescription("flav_table", psCvB, true) and + edm::ParameterDescription("graph_path", edm::FileInPath("RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDCvB.pb"), true)) + ); + } + /* { edm::ParameterSetDescription psd0; psd0.addOptional>("probQCD", {0}); psd0.addOptional>("probHbb", {1}); psd0.addOptional>("probHcc"); desc.add("flav_table", psd0); - } + + desc.add("graph_path", + edm::FileInPath("RecoBTag/Combined/data/DeepDoubleB/V01/constant_graph_PtCut_MassSculptPen.pb")); + + } */ desc.add("batch_eval", false); diff --git a/RecoBTag/TensorFlow/python/pfDeepDoubleCvBJetTags_cfi.py b/RecoBTag/TensorFlow/python/pfDeepDoubleCvBJetTags_cfi.py index 97dd42458b191..5ca1a9d8ce1b8 100644 --- a/RecoBTag/TensorFlow/python/pfDeepDoubleCvBJetTags_cfi.py +++ b/RecoBTag/TensorFlow/python/pfDeepDoubleCvBJetTags_cfi.py @@ -10,6 +10,7 @@ graph_path = cms.FileInPath('RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDCvB.pb'), lp_names = cms.vstring('db_input_batchnorm/keras_learning_phase'), output_names = cms.vstring('ID_pred/Softmax'), + flavor = cms.string('CvB'), flav_table = cms.PSet( probHbb = cms.vuint32(0), probHcc = cms.vuint32(1) diff --git a/RecoBTag/TensorFlow/python/pfDeepDoubleCvLJetTags_cfi.py b/RecoBTag/TensorFlow/python/pfDeepDoubleCvLJetTags_cfi.py index 8ff8e90d5d9d1..1ad3e28517179 100644 --- a/RecoBTag/TensorFlow/python/pfDeepDoubleCvLJetTags_cfi.py +++ b/RecoBTag/TensorFlow/python/pfDeepDoubleCvLJetTags_cfi.py @@ -10,6 +10,7 @@ graph_path = cms.FileInPath('RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDC.pb'), lp_names = cms.vstring('db_input_batchnorm/keras_learning_phase'), output_names = cms.vstring('ID_pred/Softmax'), + flavor = cms.string('CvL'), flav_table = cms.PSet( probQCD = cms.vuint32(0), probHcc = cms.vuint32(1) diff --git a/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleBvLJetTags_cfi.py b/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleBvLJetTags_cfi.py index ecb8e17dc0d23..dd13293716f1c 100644 --- a/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleBvLJetTags_cfi.py +++ b/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleBvLJetTags_cfi.py @@ -10,6 +10,7 @@ graph_path = cms.FileInPath('RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDB_mass_independent.pb'), lp_names = cms.vstring('db_input_batchnorm/keras_learning_phase'), output_names = cms.vstring('ID_pred/Softmax'), + flavor = cms.string('BvL'), flav_table = cms.PSet( probQCD = cms.vuint32(0), probHbb = cms.vuint32(1) diff --git a/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleCvBJetTags_cfi.py b/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleCvBJetTags_cfi.py index 49c4c62c42b45..0a86eb1b7502b 100644 --- a/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleCvBJetTags_cfi.py +++ b/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleCvBJetTags_cfi.py @@ -10,6 +10,7 @@ graph_path = cms.FileInPath('RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDCvB_mass_independent.pb'), lp_names = cms.vstring('db_input_batchnorm/keras_learning_phase'), output_names = cms.vstring('ID_pred/Softmax'), + flavor = cms.string('CvB'), flav_table = cms.PSet( probHbb = cms.vuint32(0), probHcc = cms.vuint32(1) diff --git a/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleCvLJetTags_cfi.py b/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleCvLJetTags_cfi.py index 8ce842a1c86de..469dd8f1b4f6f 100644 --- a/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleCvLJetTags_cfi.py +++ b/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleCvLJetTags_cfi.py @@ -10,6 +10,7 @@ graph_path = cms.FileInPath('RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDC_mass_independent.pb'), lp_names = cms.vstring('db_input_batchnorm/keras_learning_phase'), output_names = cms.vstring('ID_pred/Softmax'), + flavor = cms.string('CvL'), flav_table = cms.PSet( probQCD = cms.vuint32(0), probHcc = cms.vuint32(1) diff --git a/RecoBTag/TensorFlow/test/test_deep_doublex_cfg.py b/RecoBTag/TensorFlow/test/test_deep_doublex_cfg.py index e721cdf816dfe..fd3236900a67c 100644 --- a/RecoBTag/TensorFlow/test/test_deep_doublex_cfg.py +++ b/RecoBTag/TensorFlow/test/test_deep_doublex_cfg.py @@ -57,7 +57,11 @@ 'pfDeepDoubleCvLJetTags:probQCD', 'pfDeepDoubleCvLJetTags:probHcc', 'pfDeepDoubleCvBJetTags:probHbb', - 'pfDeepDoubleCvBJetTags:probHcc' + 'pfDeepDoubleCvBJetTags:probHcc', + 'pfMassIndependentDeepDoubleCvLJetTags:probQCD', + 'pfMassIndependentDeepDoubleCvLJetTags:probHcc', + 'pfMassIndependentDeepDoubleCvBJetTags:probHbb', + 'pfMassIndependentDeepDoubleCvBJetTags:probHcc', ] ) @@ -70,7 +74,7 @@ #'/store/mc/RunIIFall17MiniAODv2/GluGluHToCC_M125_13TeV_powheg_pythia8/MINIAODSIM/PU2017_12Apr2018_94X_mc2017_realistic_v14-v2/30000/72164088-CB67-E811-9D0D-008CFA197AC4.root', #'/store/mc/RunIIFall17MiniAOD/QCD_HT700to1000_TuneCP5_13TeV-madgraph-pythia8/MINIAODSIM/94X_mc2017_realistic_v10-v1/20000/C0F304A4-23FA-E711-942E-E0071B6CAD20.root' ) -process.maxEvents.input = -1 +process.maxEvents.input = 1000 from Configuration.EventContent.EventContent_cff import MINIAODSIMEventContent process.out.outputCommands.append('keep *_slimmedJetsAK8*_*_*') From afc1a591ec2d9b2b43a2e1c5c18238c5477668d4 Mon Sep 17 00:00:00 2001 From: anovak10 Date: Fri, 2 Nov 2018 18:42:26 +0100 Subject: [PATCH 15/30] cleaning comments --- .../plugins/DeepDoubleXTFJetTagsProducer.cc | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc b/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc index d91bfc86b10fd..b003fd9693715 100644 --- a/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc +++ b/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc @@ -132,34 +132,23 @@ void DeepDoubleXTFJetTagsProducer::fillDescriptions(edm::ConfigurationDescriptio desc.add("src", edm::InputTag("pfDeepDoubleXTagInfos")); desc.add>("input_names", { "input_1", "input_2", "input_3" }); - //desc.add("graph_path", - // edm::FileInPath("RecoBTag/Combined/data/DeepDoubleB/V01/constant_graph_PtCut_MassSculptPen.pb")); desc.add>("lp_names", { "db_input_batchnorm/keras_learning_phase" }); desc.add>("output_names", { "ID_pred/Softmax" }); - /*desc.ifValue( edm::ParameterDescription("model", "BvL", true), - "BvL" >> edm::ParameterDescription("graph_path", edm::FileInPath("RecoBTag/Combined/data/DeepDoubleB/V01/constant_graph_PtCut_MassSculptPen.pb"), true) or - "CvL" >> edm::ParameterDescription("graph_path", edm::FileInPath("RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDC.pb"), true) or - "CvB" >> edm::ParameterDescription("graph_path", edm::FileInPath("RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDCvB.pb"), true) - );*/ - { edm::ParameterSetDescription psBvL; psBvL.add>("probQCD", {0}); psBvL.add>("probHbb", {1}); - //psBvL.add("graph_path", edm::FileInPath("RecoBTag/Combined/data/DeepDoubleB/V01/constant_graph_PtCut_MassSculptPen.pb")); edm::ParameterSetDescription psCvL; psCvL.add>("probQCD", {0}); psCvL.add>("probHcc", {1}); - //psCvL.add("graph_path", edm::FileInPath("RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDC.pb")); edm::ParameterSetDescription psCvB; psCvB.add>("probHbb", {0}); psCvB.add>("probHcc", {1}); - //psCvB.add("graph_path", edm::FileInPath("RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDCvB.pb")); desc.ifValue( edm::ParameterDescription("flavor", "BvL", true), "BvL" >> (edm::ParameterDescription("flav_table", psBvL, true) and @@ -170,17 +159,6 @@ void DeepDoubleXTFJetTagsProducer::fillDescriptions(edm::ConfigurationDescriptio edm::ParameterDescription("graph_path", edm::FileInPath("RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDCvB.pb"), true)) ); } - /* { - edm::ParameterSetDescription psd0; - psd0.addOptional>("probQCD", {0}); - psd0.addOptional>("probHbb", {1}); - psd0.addOptional>("probHcc"); - desc.add("flav_table", psd0); - - desc.add("graph_path", - edm::FileInPath("RecoBTag/Combined/data/DeepDoubleB/V01/constant_graph_PtCut_MassSculptPen.pb")); - - } */ desc.add("batch_eval", false); From 79471b35868e7a867a2df9369b6c74d8ed3422c5 Mon Sep 17 00:00:00 2001 From: anovak10 Date: Thu, 8 Nov 2018 12:10:35 +0100 Subject: [PATCH 16/30] using cloning for modules --- .../BTauReco/interface/DeepDoubleBTagInfo.h | 16 +++++++++++ .../plugins/DeepDoubleXTFJetTagsProducer.cc | 4 +-- .../python/pfDeepDoubleCvBJetTags_cfi.py | 27 +++++++------------ .../python/pfDeepDoubleCvLJetTags_cfi.py | 26 ++++++------------ ...MassIndependentDeepDoubleBvLJetTags_cfi.py | 27 +++++++------------ ...MassIndependentDeepDoubleCvBJetTags_cfi.py | 27 +++++++------------ ...MassIndependentDeepDoubleCvLJetTags_cfi.py | 26 ++++++------------ RecoBTag/TensorFlow/test/plotDDX.py | 2 +- 8 files changed, 62 insertions(+), 93 deletions(-) create mode 100644 DataFormats/BTauReco/interface/DeepDoubleBTagInfo.h diff --git a/DataFormats/BTauReco/interface/DeepDoubleBTagInfo.h b/DataFormats/BTauReco/interface/DeepDoubleBTagInfo.h new file mode 100644 index 0000000000000..a6a4c497fa719 --- /dev/null +++ b/DataFormats/BTauReco/interface/DeepDoubleBTagInfo.h @@ -0,0 +1,16 @@ +#ifndef DataFormats_BTauReco_DeepDoubleBTagInfo_h +#define DataFormats_BTauReco_DeepDoubleBTagInfo_h + +#include "DataFormats/BTauReco/interface/FeaturesTagInfo.h" +#include "DataFormats/BTauReco/interface/DeepDoubleXFeatures.h" + +//keeping for posterity +namespace reco { + +typedef FeaturesTagInfo DeepDoubleBTagInfo; + +DECLARE_EDM_REFS( DeepDoubleBTagInfo ) + +} + +#endif // DataFormats_BTauReco_DeepDoubleBTagInfo_h diff --git a/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc b/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc index b003fd9693715..ccac397332c8c 100644 --- a/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc +++ b/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc @@ -137,7 +137,7 @@ void DeepDoubleXTFJetTagsProducer::fillDescriptions(edm::ConfigurationDescriptio desc.add>("output_names", { "ID_pred/Softmax" }); - { + //{ edm::ParameterSetDescription psBvL; psBvL.add>("probQCD", {0}); psBvL.add>("probHbb", {1}); @@ -158,7 +158,7 @@ void DeepDoubleXTFJetTagsProducer::fillDescriptions(edm::ConfigurationDescriptio "CvB" >> (edm::ParameterDescription("flav_table", psCvB, true) and edm::ParameterDescription("graph_path", edm::FileInPath("RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDCvB.pb"), true)) ); - } + //} desc.add("batch_eval", false); diff --git a/RecoBTag/TensorFlow/python/pfDeepDoubleCvBJetTags_cfi.py b/RecoBTag/TensorFlow/python/pfDeepDoubleCvBJetTags_cfi.py index 5ca1a9d8ce1b8..2620dfdc7749f 100644 --- a/RecoBTag/TensorFlow/python/pfDeepDoubleCvBJetTags_cfi.py +++ b/RecoBTag/TensorFlow/python/pfDeepDoubleCvBJetTags_cfi.py @@ -1,21 +1,12 @@ import FWCore.ParameterSet.Config as cms +from pfDeepDoubleBvLJetTags_cfi import pfDeepDoubleBvLJetTags -pfDeepDoubleCvBJetTags = cms.EDProducer('DeepDoubleXTFJetTagsProducer', - src = cms.InputTag('pfDeepDoubleXTagInfos'), - input_names = cms.vstring( - 'input_1', - 'input_2', - 'input_3' - ), - graph_path = cms.FileInPath('RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDCvB.pb'), - lp_names = cms.vstring('db_input_batchnorm/keras_learning_phase'), - output_names = cms.vstring('ID_pred/Softmax'), - flavor = cms.string('CvB'), - flav_table = cms.PSet( - probHbb = cms.vuint32(0), - probHcc = cms.vuint32(1) - ), - batch_eval = cms.bool(False), - nThreads = cms.uint32(1), - singleThreadPool = cms.string('no_threads') +pfDeepDoubleCvBJetTags = pfDeepDoubleBvLJetTags.clone( + flavor = 'CvB', + graph_path = cms.FileInPath('RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDCvB.pb'), + flav_table = cms.PSet( + probHbb = cms.vuint32(0), + probHcc = cms.vuint32(1) + ) ) + diff --git a/RecoBTag/TensorFlow/python/pfDeepDoubleCvLJetTags_cfi.py b/RecoBTag/TensorFlow/python/pfDeepDoubleCvLJetTags_cfi.py index 1ad3e28517179..65a57a4d0cb0f 100644 --- a/RecoBTag/TensorFlow/python/pfDeepDoubleCvLJetTags_cfi.py +++ b/RecoBTag/TensorFlow/python/pfDeepDoubleCvLJetTags_cfi.py @@ -1,21 +1,11 @@ import FWCore.ParameterSet.Config as cms +from pfDeepDoubleBvLJetTags_cfi import pfDeepDoubleBvLJetTags -pfDeepDoubleCvLJetTags = cms.EDProducer('DeepDoubleXTFJetTagsProducer', - src = cms.InputTag('pfDeepDoubleXTagInfos'), - input_names = cms.vstring( - 'input_1', - 'input_2', - 'input_3' - ), - graph_path = cms.FileInPath('RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDC.pb'), - lp_names = cms.vstring('db_input_batchnorm/keras_learning_phase'), - output_names = cms.vstring('ID_pred/Softmax'), - flavor = cms.string('CvL'), - flav_table = cms.PSet( - probQCD = cms.vuint32(0), - probHcc = cms.vuint32(1) - ), - batch_eval = cms.bool(False), - nThreads = cms.uint32(1), - singleThreadPool = cms.string('no_threads') +pfDeepDoubleCvLJetTags = pfDeepDoubleBvLJetTags.clone( + flavor = 'CvL', + graph_path = cms.FileInPath('RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDC.pb'), + flav_table = cms.PSet( + probQCD = cms.vuint32(0), + probHcc = cms.vuint32(1) + ) ) diff --git a/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleBvLJetTags_cfi.py b/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleBvLJetTags_cfi.py index dd13293716f1c..4d9ba54fdd621 100644 --- a/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleBvLJetTags_cfi.py +++ b/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleBvLJetTags_cfi.py @@ -1,21 +1,12 @@ import FWCore.ParameterSet.Config as cms +from pfDeepDoubleBvLJetTags_cfi import pfDeepDoubleBvLJetTags -pfMassIndependentDeepDoubleBvLJetTags = cms.EDProducer('DeepDoubleXTFJetTagsProducer', - src = cms.InputTag('pfDeepDoubleXTagInfos'), - input_names = cms.vstring( - 'input_1', - 'input_2', - 'input_3' - ), - graph_path = cms.FileInPath('RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDB_mass_independent.pb'), - lp_names = cms.vstring('db_input_batchnorm/keras_learning_phase'), - output_names = cms.vstring('ID_pred/Softmax'), - flavor = cms.string('BvL'), - flav_table = cms.PSet( - probQCD = cms.vuint32(0), - probHbb = cms.vuint32(1) - ), - batch_eval = cms.bool(False), - nThreads = cms.uint32(1), - singleThreadPool = cms.string('no_threads') +pfMassIndependentDeepDoubleBvLJetTags = pfDeepDoubleBvLJetTags.clone( + flavor = 'BvL', + graph_path = cms.FileInPath('RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDB_mass_independent.pb'), + flav_table = cms.PSet( + probQCD = cms.vuint32(0), + probHbb = cms.vuint32(1) + ) ) + diff --git a/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleCvBJetTags_cfi.py b/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleCvBJetTags_cfi.py index 0a86eb1b7502b..9c2ad90bf82b3 100644 --- a/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleCvBJetTags_cfi.py +++ b/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleCvBJetTags_cfi.py @@ -1,21 +1,12 @@ import FWCore.ParameterSet.Config as cms +from pfDeepDoubleBvLJetTags_cfi import pfDeepDoubleBvLJetTags -pfMassIndependentDeepDoubleCvBJetTags = cms.EDProducer('DeepDoubleXTFJetTagsProducer', - src = cms.InputTag('pfDeepDoubleXTagInfos'), - input_names = cms.vstring( - 'input_1', - 'input_2', - 'input_3' - ), - graph_path = cms.FileInPath('RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDCvB_mass_independent.pb'), - lp_names = cms.vstring('db_input_batchnorm/keras_learning_phase'), - output_names = cms.vstring('ID_pred/Softmax'), - flavor = cms.string('CvB'), - flav_table = cms.PSet( - probHbb = cms.vuint32(0), - probHcc = cms.vuint32(1) - ), - batch_eval = cms.bool(False), - nThreads = cms.uint32(1), - singleThreadPool = cms.string('no_threads') +pfMassIndependentDeepDoubleCvBJetTags = pfDeepDoubleBvLJetTags.clone( + flavor = 'CvB', + graph_path = cms.FileInPath('RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDCvB_mass_independent.pb'), + flav_table = cms.PSet( + probHbb = cms.vuint32(0), + probHcc = cms.vuint32(1) + ) ) + diff --git a/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleCvLJetTags_cfi.py b/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleCvLJetTags_cfi.py index 469dd8f1b4f6f..84528b0adad22 100644 --- a/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleCvLJetTags_cfi.py +++ b/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleCvLJetTags_cfi.py @@ -1,21 +1,11 @@ import FWCore.ParameterSet.Config as cms +from pfDeepDoubleBvLJetTags_cfi import pfDeepDoubleBvLJetTags -pfMassIndependentDeepDoubleCvLJetTags = cms.EDProducer('DeepDoubleXTFJetTagsProducer', - src = cms.InputTag('pfDeepDoubleXTagInfos'), - input_names = cms.vstring( - 'input_1', - 'input_2', - 'input_3' - ), - graph_path = cms.FileInPath('RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDC_mass_independent.pb'), - lp_names = cms.vstring('db_input_batchnorm/keras_learning_phase'), - output_names = cms.vstring('ID_pred/Softmax'), - flavor = cms.string('CvL'), - flav_table = cms.PSet( - probQCD = cms.vuint32(0), - probHcc = cms.vuint32(1) - ), - batch_eval = cms.bool(False), - nThreads = cms.uint32(1), - singleThreadPool = cms.string('no_threads') +pfMassIndependentDeepDoubleCvLJetTags = pfDeepDoubleBvLJetTags.clone( + flavor = 'CvL', + graph_path = cms.FileInPath('RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDC_mass_independent.pb'), + flav_table = cms.PSet( + probQCD = cms.vuint32(0), + probHcc = cms.vuint32(1) + ) ) diff --git a/RecoBTag/TensorFlow/test/plotDDX.py b/RecoBTag/TensorFlow/test/plotDDX.py index 305468e51e5df..b403f65a2b44b 100644 --- a/RecoBTag/TensorFlow/test/plotDDX.py +++ b/RecoBTag/TensorFlow/test/plotDDX.py @@ -45,7 +45,7 @@ if jet.mass() < 40 or jet.mass() > 200: continue print jet.pt(), jet.mass() - print "DDB", jet.bDiscriminator("pfDeepDoubleBvLJetTags:probQCD"), jet.bDiscriminator("pfDeepDoubleBvLJetTags:probHbb") , jet.bDiscriminator("pfDeepDoubleBvLJetTags:probHcc") + print "DDB", jet.bDiscriminator("pfDeepDoubleBvLJetTags:probQCD"), jet.bDiscriminator("pfDeepDoubleBvLJetTags:probHbb") , jet.bDiscriminator("pfDeepDoubleBvLJetTags:probHcc") print "DDCvL", jet.bDiscriminator("pfDeepDoubleCvLJetTags:probQCD"), jet.bDiscriminator("pfDeepDoubleCvLJetTags:probHcc") , jet.bDiscriminator("pfDeepDoubleCvLJetTags:probHbb") print "DDCvL", jet.bDiscriminator("pfMassIndependentDeepDoubleCvLJetTags:probQCD"), jet.bDiscriminator("pfMassIndependentDeepDoubleCvLJetTags:probHcc") , jet.bDiscriminator("pfDeepDoubleMassIndependentCvLJetTags:probHbb") print "DDCvB", jet.bDiscriminator("pfDeepDoubleCvBJetTags:probHbb"), jet.bDiscriminator("pfDeepDoubleCvBJetTags:probHcc") , jet.bDiscriminator("pfDeepDoubleCvBJetTags:probQCD") From 27bdb12a8d338ac8452ea7188dec3fb61e1e0e5b Mon Sep 17 00:00:00 2001 From: anovak10 Date: Thu, 8 Nov 2018 15:01:22 +0100 Subject: [PATCH 17/30] fix comments --- RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc b/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc index ccac397332c8c..21a187304730c 100644 --- a/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc +++ b/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc @@ -137,7 +137,6 @@ void DeepDoubleXTFJetTagsProducer::fillDescriptions(edm::ConfigurationDescriptio desc.add>("output_names", { "ID_pred/Softmax" }); - //{ edm::ParameterSetDescription psBvL; psBvL.add>("probQCD", {0}); psBvL.add>("probHbb", {1}); @@ -158,7 +157,6 @@ void DeepDoubleXTFJetTagsProducer::fillDescriptions(edm::ConfigurationDescriptio "CvB" >> (edm::ParameterDescription("flav_table", psCvB, true) and edm::ParameterDescription("graph_path", edm::FileInPath("RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDCvB.pb"), true)) ); - //} desc.add("batch_eval", false); From f6ac641743f133eba8cf83ab7e3eda6a5fd32c70 Mon Sep 17 00:00:00 2001 From: anovak10 Date: Sat, 10 Nov 2018 15:48:25 +0100 Subject: [PATCH 18/30] one mass-independent cff file --- DataFormats/BTauReco/src/classes.h | 1 + DataFormats/BTauReco/src/classes_def.xml | 1 + RecoBTag/TensorFlow/python/pfDeepDoubleX_cff.py | 4 +--- .../pfMassIndependentDeepDoubleBvLJetTags_cfi.py | 12 ------------ .../pfMassIndependentDeepDoubleCvBJetTags_cfi.py | 12 ------------ .../pfMassIndependentDeepDoubleCvLJetTags_cfi.py | 11 ----------- 6 files changed, 3 insertions(+), 38 deletions(-) delete mode 100644 RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleBvLJetTags_cfi.py delete mode 100644 RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleCvBJetTags_cfi.py delete mode 100644 RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleCvLJetTags_cfi.py diff --git a/DataFormats/BTauReco/src/classes.h b/DataFormats/BTauReco/src/classes.h index 36271e92248b9..134b6a3a14426 100755 --- a/DataFormats/BTauReco/src/classes.h +++ b/DataFormats/BTauReco/src/classes.h @@ -56,6 +56,7 @@ #include "DataFormats/BTauReco/interface/DeepFlavourTagInfo.h" #include "DataFormats/BTauReco/interface/DeepDoubleXFeatures.h" #include "DataFormats/BTauReco/interface/DeepDoubleXTagInfo.h" +#include "DataFormats/BTauReco/interface/DeepDoubleBTagInfo.h" // for posterity #include "DataFormats/BTauReco/interface/DeepBoostedJetTagInfo.h" diff --git a/DataFormats/BTauReco/src/classes_def.xml b/DataFormats/BTauReco/src/classes_def.xml index d0a8e9bb90f91..7cda1ffdfb885 100644 --- a/DataFormats/BTauReco/src/classes_def.xml +++ b/DataFormats/BTauReco/src/classes_def.xml @@ -463,6 +463,7 @@ + diff --git a/RecoBTag/TensorFlow/python/pfDeepDoubleX_cff.py b/RecoBTag/TensorFlow/python/pfDeepDoubleX_cff.py index d8b563a757e13..32331fc050bd2 100644 --- a/RecoBTag/TensorFlow/python/pfDeepDoubleX_cff.py +++ b/RecoBTag/TensorFlow/python/pfDeepDoubleX_cff.py @@ -2,7 +2,5 @@ from RecoBTag.TensorFlow.pfDeepDoubleCvBJetTags_cfi import pfDeepDoubleCvBJetTags from RecoBTag.TensorFlow.pfDeepDoubleCvLJetTags_cfi import pfDeepDoubleCvLJetTags -from RecoBTag.TensorFlow.pfMassIndependentDeepDoubleBvLJetTags_cfi import pfMassIndependentDeepDoubleBvLJetTags -from RecoBTag.TensorFlow.pfMassIndependentDeepDoubleCvBJetTags_cfi import pfMassIndependentDeepDoubleCvBJetTags -from RecoBTag.TensorFlow.pfMassIndependentDeepDoubleCvLJetTags_cfi import pfMassIndependentDeepDoubleCvLJetTags +from RecoBTag.TensorFlow.pfMassIndependentDeepDoubleXJetTags_cff import * diff --git a/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleBvLJetTags_cfi.py b/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleBvLJetTags_cfi.py deleted file mode 100644 index 4d9ba54fdd621..0000000000000 --- a/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleBvLJetTags_cfi.py +++ /dev/null @@ -1,12 +0,0 @@ -import FWCore.ParameterSet.Config as cms -from pfDeepDoubleBvLJetTags_cfi import pfDeepDoubleBvLJetTags - -pfMassIndependentDeepDoubleBvLJetTags = pfDeepDoubleBvLJetTags.clone( - flavor = 'BvL', - graph_path = cms.FileInPath('RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDB_mass_independent.pb'), - flav_table = cms.PSet( - probQCD = cms.vuint32(0), - probHbb = cms.vuint32(1) - ) -) - diff --git a/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleCvBJetTags_cfi.py b/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleCvBJetTags_cfi.py deleted file mode 100644 index 9c2ad90bf82b3..0000000000000 --- a/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleCvBJetTags_cfi.py +++ /dev/null @@ -1,12 +0,0 @@ -import FWCore.ParameterSet.Config as cms -from pfDeepDoubleBvLJetTags_cfi import pfDeepDoubleBvLJetTags - -pfMassIndependentDeepDoubleCvBJetTags = pfDeepDoubleBvLJetTags.clone( - flavor = 'CvB', - graph_path = cms.FileInPath('RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDCvB_mass_independent.pb'), - flav_table = cms.PSet( - probHbb = cms.vuint32(0), - probHcc = cms.vuint32(1) - ) -) - diff --git a/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleCvLJetTags_cfi.py b/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleCvLJetTags_cfi.py deleted file mode 100644 index 84528b0adad22..0000000000000 --- a/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleCvLJetTags_cfi.py +++ /dev/null @@ -1,11 +0,0 @@ -import FWCore.ParameterSet.Config as cms -from pfDeepDoubleBvLJetTags_cfi import pfDeepDoubleBvLJetTags - -pfMassIndependentDeepDoubleCvLJetTags = pfDeepDoubleBvLJetTags.clone( - flavor = 'CvL', - graph_path = cms.FileInPath('RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDC_mass_independent.pb'), - flav_table = cms.PSet( - probQCD = cms.vuint32(0), - probHcc = cms.vuint32(1) - ) -) From d3b1b86cd8b9a6460ef7bda2c27aac1df5a08d3f Mon Sep 17 00:00:00 2001 From: anovak10 Date: Sat, 10 Nov 2018 15:54:09 +0100 Subject: [PATCH 19/30] missing cff --- .../pfMassIndependentDeepDoubleXJetTags_cff.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleXJetTags_cff.py diff --git a/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleXJetTags_cff.py b/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleXJetTags_cff.py new file mode 100644 index 0000000000000..f965b2422d8f3 --- /dev/null +++ b/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleXJetTags_cff.py @@ -0,0 +1,15 @@ +import FWCore.ParameterSet.Config as cms +from pfDeepDoubleBvLJetTags_cfi import pfDeepDoubleBvLJetTags +from pfDeepDoubleCvLJetTags_cfi import pfDeepDoubleCvLJetTags +from pfDeepDoubleCvBJetTags_cfi import pfDeepDoubleCvBJetTags + +pfMassIndependentDeepDoubleBvLJetTags = pfDeepDoubleBvLJetTags.clone( + graph_path = cms.FileInPath('RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDB_mass_independent.pb') +) +pfMassIndependentDeepDoubleCvLJetTags = pfDeepDoubleCvLJetTags.clone( + graph_path = cms.FileInPath('RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDC_mass_independent.pb') +) +pfMassIndependentDeepDoubleCvBJetTags = pfDeepDoubleCvBJetTags.clone( + graph_path = cms.FileInPath('RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDCvB_mass_independent.pb') +) + From d17215a6a49ad13fc5e39ec0c2133cde0a924694 Mon Sep 17 00:00:00 2001 From: anovak10 Date: Mon, 12 Nov 2018 18:34:34 +0100 Subject: [PATCH 20/30] Making sure of backwards compatibility for DDBFeatures&JetTags --- .../BTauReco/interface/DeepDoubleBFeatures.h | 29 +++++++++++++++++++ DataFormats/BTauReco/src/classes.h | 10 +++++++ DataFormats/BTauReco/src/classes_def.xml | 12 +++++++- 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 DataFormats/BTauReco/interface/DeepDoubleBFeatures.h diff --git a/DataFormats/BTauReco/interface/DeepDoubleBFeatures.h b/DataFormats/BTauReco/interface/DeepDoubleBFeatures.h new file mode 100644 index 0000000000000..08859f343c88c --- /dev/null +++ b/DataFormats/BTauReco/interface/DeepDoubleBFeatures.h @@ -0,0 +1,29 @@ +#ifndef DataFormats_BTauReco_DeepDoubleBFeatures_h +#define DataFormats_BTauReco_DeepDoubleBFeatures_h + +#include + +#include "DataFormats/BTauReco/interface/JetFeatures.h" +#include "DataFormats/BTauReco/interface/SecondaryVertexFeatures.h" +#include "DataFormats/BTauReco/interface/BoostedDoubleSVTagInfoFeatures.h" +#include "DataFormats/BTauReco/interface/ChargedCandidateFeatures.h" + +namespace btagbtvdeep { + +class DeepDoubleBFeatures { + + public: + JetFeatures jet_features; + BoostedDoubleSVTagInfoFeatures tag_info_features; + + std::vector sv_features; + + std::vector c_pf_features; + + std::size_t npv; // used by deep flavour +}; + + +} + +#endif //DataFormats_BTauReco_DeepDoubleBFeatures_h diff --git a/DataFormats/BTauReco/src/classes.h b/DataFormats/BTauReco/src/classes.h index 134b6a3a14426..dbddbd773277b 100755 --- a/DataFormats/BTauReco/src/classes.h +++ b/DataFormats/BTauReco/src/classes.h @@ -56,6 +56,7 @@ #include "DataFormats/BTauReco/interface/DeepFlavourTagInfo.h" #include "DataFormats/BTauReco/interface/DeepDoubleXFeatures.h" #include "DataFormats/BTauReco/interface/DeepDoubleXTagInfo.h" +#include "DataFormats/BTauReco/interface/DeepDoubleBFeatures.h" // for posterity #include "DataFormats/BTauReco/interface/DeepDoubleBTagInfo.h" // for posterity #include "DataFormats/BTauReco/interface/DeepBoostedJetTagInfo.h" @@ -428,6 +429,15 @@ namespace DataFormats_BTauReco { reco::DeepDoubleXTagInfoRefProd deep_doublex_tag_info_collection_ref_prod; reco::DeepDoubleXTagInfoRefVector deep_doublex_tag_info_collection_ref_vector; edm::Wrapper deep_doublex_tag_info_collection_edm_wrapper; + // for posterity + 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 deep_doubleb_tag_info_collection_edm_wrapper; btagbtvdeep::DeepBoostedJetFeatures deep_boosted_jet_tag_info_features; reco::DeepBoostedJetTagInfo deep_boosted_jet_tag_info; diff --git a/DataFormats/BTauReco/src/classes_def.xml b/DataFormats/BTauReco/src/classes_def.xml index 7cda1ffdfb885..ae9968ec62921 100644 --- a/DataFormats/BTauReco/src/classes_def.xml +++ b/DataFormats/BTauReco/src/classes_def.xml @@ -450,6 +450,9 @@ + + + @@ -462,8 +465,15 @@ + + + + + + + + - From 2e9926bcfe1cc81d2a817fd38bec637809cf3198 Mon Sep 17 00:00:00 2001 From: anovak10 Date: Wed, 14 Nov 2018 15:48:34 +0100 Subject: [PATCH 21/30] Cleaning up references --- .../BTauReco/interface/DeepDoubleBFeatures.h | 29 ------------------- .../BTauReco/interface/DeepDoubleBTagInfo.h | 16 ---------- DataFormats/BTauReco/src/classes.h | 12 +------- DataFormats/BTauReco/src/classes_def.xml | 11 ------- 4 files changed, 1 insertion(+), 67 deletions(-) delete mode 100644 DataFormats/BTauReco/interface/DeepDoubleBFeatures.h delete mode 100644 DataFormats/BTauReco/interface/DeepDoubleBTagInfo.h diff --git a/DataFormats/BTauReco/interface/DeepDoubleBFeatures.h b/DataFormats/BTauReco/interface/DeepDoubleBFeatures.h deleted file mode 100644 index 08859f343c88c..0000000000000 --- a/DataFormats/BTauReco/interface/DeepDoubleBFeatures.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef DataFormats_BTauReco_DeepDoubleBFeatures_h -#define DataFormats_BTauReco_DeepDoubleBFeatures_h - -#include - -#include "DataFormats/BTauReco/interface/JetFeatures.h" -#include "DataFormats/BTauReco/interface/SecondaryVertexFeatures.h" -#include "DataFormats/BTauReco/interface/BoostedDoubleSVTagInfoFeatures.h" -#include "DataFormats/BTauReco/interface/ChargedCandidateFeatures.h" - -namespace btagbtvdeep { - -class DeepDoubleBFeatures { - - public: - JetFeatures jet_features; - BoostedDoubleSVTagInfoFeatures tag_info_features; - - std::vector sv_features; - - std::vector c_pf_features; - - std::size_t npv; // used by deep flavour -}; - - -} - -#endif //DataFormats_BTauReco_DeepDoubleBFeatures_h diff --git a/DataFormats/BTauReco/interface/DeepDoubleBTagInfo.h b/DataFormats/BTauReco/interface/DeepDoubleBTagInfo.h deleted file mode 100644 index a6a4c497fa719..0000000000000 --- a/DataFormats/BTauReco/interface/DeepDoubleBTagInfo.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef DataFormats_BTauReco_DeepDoubleBTagInfo_h -#define DataFormats_BTauReco_DeepDoubleBTagInfo_h - -#include "DataFormats/BTauReco/interface/FeaturesTagInfo.h" -#include "DataFormats/BTauReco/interface/DeepDoubleXFeatures.h" - -//keeping for posterity -namespace reco { - -typedef FeaturesTagInfo DeepDoubleBTagInfo; - -DECLARE_EDM_REFS( DeepDoubleBTagInfo ) - -} - -#endif // DataFormats_BTauReco_DeepDoubleBTagInfo_h diff --git a/DataFormats/BTauReco/src/classes.h b/DataFormats/BTauReco/src/classes.h index dbddbd773277b..7a25b4bbb1c2b 100755 --- a/DataFormats/BTauReco/src/classes.h +++ b/DataFormats/BTauReco/src/classes.h @@ -56,11 +56,10 @@ #include "DataFormats/BTauReco/interface/DeepFlavourTagInfo.h" #include "DataFormats/BTauReco/interface/DeepDoubleXFeatures.h" #include "DataFormats/BTauReco/interface/DeepDoubleXTagInfo.h" -#include "DataFormats/BTauReco/interface/DeepDoubleBFeatures.h" // for posterity -#include "DataFormats/BTauReco/interface/DeepDoubleBTagInfo.h" // for posterity #include "DataFormats/BTauReco/interface/DeepBoostedJetTagInfo.h" + namespace reco { typedef TrackTauImpactParameterAssociationCollection::map_type TrackTauImpactParameterAssociationMapType; typedef TrackTauImpactParameterAssociationCollection::ref_type TrackTauImpactParameterAssociationRefType; @@ -429,15 +428,6 @@ namespace DataFormats_BTauReco { reco::DeepDoubleXTagInfoRefProd deep_doublex_tag_info_collection_ref_prod; reco::DeepDoubleXTagInfoRefVector deep_doublex_tag_info_collection_ref_vector; edm::Wrapper deep_doublex_tag_info_collection_edm_wrapper; - // for posterity - 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 deep_doubleb_tag_info_collection_edm_wrapper; btagbtvdeep::DeepBoostedJetFeatures deep_boosted_jet_tag_info_features; reco::DeepBoostedJetTagInfo deep_boosted_jet_tag_info; diff --git a/DataFormats/BTauReco/src/classes_def.xml b/DataFormats/BTauReco/src/classes_def.xml index ae9968ec62921..640f0fe50f32a 100644 --- a/DataFormats/BTauReco/src/classes_def.xml +++ b/DataFormats/BTauReco/src/classes_def.xml @@ -450,9 +450,6 @@ - - - @@ -466,14 +463,6 @@ - - - - - - - - From 3d8733b4f6c19b272a826a56170d7b3600675b06 Mon Sep 17 00:00:00 2001 From: anovak10 Date: Wed, 14 Nov 2018 16:39:49 +0100 Subject: [PATCH 22/30] add missing mass ind ddb --- PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py | 2 ++ PhysicsTools/PatAlgos/python/slimming/applyDeepBtagging_cff.py | 2 ++ RecoBTag/TensorFlow/test/plotDDX.py | 1 + RecoBTag/TensorFlow/test/test_deep_doublex_cfg.py | 2 ++ 4 files changed, 7 insertions(+) diff --git a/PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py b/PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py index 687b00c92c501..af501cf0a219f 100644 --- a/PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py +++ b/PhysicsTools/PatAlgos/python/recoLayer0/bTagging_cff.py @@ -195,6 +195,8 @@ , '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']] diff --git a/PhysicsTools/PatAlgos/python/slimming/applyDeepBtagging_cff.py b/PhysicsTools/PatAlgos/python/slimming/applyDeepBtagging_cff.py index fec7331ad7ce4..d0403c001f9e6 100644 --- a/PhysicsTools/PatAlgos/python/slimming/applyDeepBtagging_cff.py +++ b/PhysicsTools/PatAlgos/python/slimming/applyDeepBtagging_cff.py @@ -66,6 +66,8 @@ def applyDeepBtagging( process, postfix="" ) : 'pfDeepDoubleCvLJetTags:probHcc', 'pfDeepDoubleCvBJetTags:probHbb', 'pfDeepDoubleCvBJetTags:probHcc', + 'pfMassIndependentDeepDoubleBvLJetTags:probQCD', + 'pfMassIndependentDeepDoubleBvLJetTags:probHcc', 'pfMassIndependentDeepDoubleCvLJetTags:probQCD', 'pfMassIndependentDeepDoubleCvLJetTags:probHcc', 'pfMassIndependentDeepDoubleCvBJetTags:probHbb', diff --git a/RecoBTag/TensorFlow/test/plotDDX.py b/RecoBTag/TensorFlow/test/plotDDX.py index b403f65a2b44b..04eece65ccd46 100644 --- a/RecoBTag/TensorFlow/test/plotDDX.py +++ b/RecoBTag/TensorFlow/test/plotDDX.py @@ -46,6 +46,7 @@ print jet.pt(), jet.mass() print "DDB", jet.bDiscriminator("pfDeepDoubleBvLJetTags:probQCD"), jet.bDiscriminator("pfDeepDoubleBvLJetTags:probHbb") , jet.bDiscriminator("pfDeepDoubleBvLJetTags:probHcc") + print "DDB", jet.bDiscriminator("pfMassIndependentDeepDoubleBvLJetTags:probQCD"), jet.bDiscriminator("pfMassIndependentDeepDoubleBvLJetTags:probHbb") , jet.bDiscriminator("pfMassIndependentDeepDoubleBvLJetTags:probHcc") print "DDCvL", jet.bDiscriminator("pfDeepDoubleCvLJetTags:probQCD"), jet.bDiscriminator("pfDeepDoubleCvLJetTags:probHcc") , jet.bDiscriminator("pfDeepDoubleCvLJetTags:probHbb") print "DDCvL", jet.bDiscriminator("pfMassIndependentDeepDoubleCvLJetTags:probQCD"), jet.bDiscriminator("pfMassIndependentDeepDoubleCvLJetTags:probHcc") , jet.bDiscriminator("pfDeepDoubleMassIndependentCvLJetTags:probHbb") print "DDCvB", jet.bDiscriminator("pfDeepDoubleCvBJetTags:probHbb"), jet.bDiscriminator("pfDeepDoubleCvBJetTags:probHcc") , jet.bDiscriminator("pfDeepDoubleCvBJetTags:probQCD") diff --git a/RecoBTag/TensorFlow/test/test_deep_doublex_cfg.py b/RecoBTag/TensorFlow/test/test_deep_doublex_cfg.py index fd3236900a67c..fd25123598981 100644 --- a/RecoBTag/TensorFlow/test/test_deep_doublex_cfg.py +++ b/RecoBTag/TensorFlow/test/test_deep_doublex_cfg.py @@ -58,6 +58,8 @@ 'pfDeepDoubleCvLJetTags:probHcc', 'pfDeepDoubleCvBJetTags:probHbb', 'pfDeepDoubleCvBJetTags:probHcc', + 'pfMassIndependentDeepDoubleBvLJetTags:probQCD', + 'pfMassIndependentDeepDoubleBvLJetTags:probHbb', 'pfMassIndependentDeepDoubleCvLJetTags:probQCD', 'pfMassIndependentDeepDoubleCvLJetTags:probHcc', 'pfMassIndependentDeepDoubleCvBJetTags:probHbb', From f804c4e972c4ac4d74236829a5a4aeb1329ef2c0 Mon Sep 17 00:00:00 2001 From: anovak10 Date: Thu, 15 Nov 2018 23:41:22 +0100 Subject: [PATCH 23/30] Adding a pt>150 cut to DDX --- .../BTauReco/interface/DeepDoubleXFeatures.h | 15 ++++++++++++++- DataFormats/BTauReco/src/classes_def.xml | 4 ++-- .../plugins/DeepDoubleXTagInfoProducer.cc | 9 ++++++++- .../plugins/DeepDoubleXTFJetTagsProducer.cc | 4 ++++ 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/DataFormats/BTauReco/interface/DeepDoubleXFeatures.h b/DataFormats/BTauReco/interface/DeepDoubleXFeatures.h index 81f5ffc839873..84e6f3066d294 100644 --- a/DataFormats/BTauReco/interface/DeepDoubleXFeatures.h +++ b/DataFormats/BTauReco/interface/DeepDoubleXFeatures.h @@ -12,7 +12,16 @@ namespace btagbtvdeep { class DeepDoubleXFeatures { - public: +public: + + bool empty() const { + return is_empty_; + } + + void filled(){ + is_empty_ = false; + } + JetFeatures jet_features; BoostedDoubleSVTagInfoFeatures tag_info_features; @@ -21,6 +30,10 @@ class DeepDoubleXFeatures { std::vector c_pf_features; std::size_t npv; // used by deep flavour + +private: + bool is_empty_ = true; + }; diff --git a/DataFormats/BTauReco/src/classes_def.xml b/DataFormats/BTauReco/src/classes_def.xml index 640f0fe50f32a..d613c8786d61f 100644 --- a/DataFormats/BTauReco/src/classes_def.xml +++ b/DataFormats/BTauReco/src/classes_def.xml @@ -447,8 +447,8 @@ - - + + diff --git a/RecoBTag/FeatureTools/plugins/DeepDoubleXTagInfoProducer.cc b/RecoBTag/FeatureTools/plugins/DeepDoubleXTagInfoProducer.cc index 4fe1c7aae5a7e..891c6028c2615 100644 --- a/RecoBTag/FeatureTools/plugins/DeepDoubleXTagInfoProducer.cc +++ b/RecoBTag/FeatureTools/plugins/DeepDoubleXTagInfoProducer.cc @@ -59,6 +59,7 @@ class DeepDoubleXTagInfoProducer : public edm::stream::EDProducer<> } const double jet_radius_; + const double min_jet_pt_; const double min_candidate_pt_; edm::EDGetTokenT> jet_token_; @@ -70,6 +71,7 @@ class DeepDoubleXTagInfoProducer : public edm::stream::EDProducer<> DeepDoubleXTagInfoProducer::DeepDoubleXTagInfoProducer( const edm::ParameterSet& iConfig) : jet_radius_(iConfig.getParameter("jet_radius")) + , min_jet_pt_(iConfig.getParameter("min_jet_pt")) , min_candidate_pt_(iConfig.getParameter("min_candidate_pt")) , jet_token_(consumes>( iConfig.getParameter("jets"))) @@ -95,6 +97,7 @@ void DeepDoubleXTagInfoProducer::fillDescriptions( desc.add("shallow_tag_infos", edm::InputTag("pfBoostedDoubleSVAK8TagInfos")); desc.add("jet_radius", 0.8); + desc.add("min_jet_pt", 150); desc.add("min_candidate_pt", 0.95); desc.add("vertices", edm::InputTag("offlinePrimaryVertices")); desc.add("secondary_vertices", @@ -141,7 +144,11 @@ void DeepDoubleXTagInfoProducer::produce(edm::Event& iEvent, // reco jet reference (use as much as possible) const auto& jet = jets->at(jet_n); + edm::RefToBase 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& taginfos = *shallow_tag_infos; edm::Ptr match; @@ -338,7 +345,7 @@ void DeepDoubleXTagInfoProducer::produce(edm::Event& iEvent, } } } - + } output_tag_infos->emplace_back(features, jet_ref); } diff --git a/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc b/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc index 21a187304730c..948d16be9372d 100644 --- a/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc +++ b/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc @@ -252,6 +252,7 @@ void DeepDoubleXTFJetTagsProducer::produce(edm::Event& iEvent, const edm::EventS // jet and other global features const auto & features = tag_infos->at(jet_n).features(); + if (features.empty()) continue ; db_tensor_filler(input_tensors.at(kGlobal).second, jet_bn, features); @@ -284,6 +285,9 @@ void DeepDoubleXTFJetTagsProducer::produce(edm::Event& iEvent, const edm::EventS // global jet index (jet_bn is the jet batch index) std::size_t jet_n = batch_n*n_batch_jets + jet_bn; + const auto & features = tag_infos->at(jet_n).features(); + if (features.empty()) continue ; + const auto & jet_ref = tag_infos->at(jet_n).jet(); for (std::size_t flav_n=0; flav_n < flav_pairs_.size(); flav_n++) { const auto & flav_pair = flav_pairs_.at(flav_n); From aa324400e13cd0887c37b5479261c0817331b544 Mon Sep 17 00:00:00 2001 From: anovak10 Date: Sun, 18 Nov 2018 21:24:28 +0100 Subject: [PATCH 24/30] Default not predicted values to -1, use auto descriptions --- .../BTauReco/interface/DeepDoubleXFeatures.h | 17 ++++--- DataFormats/BTauReco/src/classes_def.xml | 4 +- .../python/slimming/applyDeepBtagging_cff.py | 2 +- .../plugins/DeepDoubleXTFJetTagsProducer.cc | 46 +++++++++++++------ .../python/pfDeepDoubleCvBJetTags_cfi.py | 12 ----- .../python/pfDeepDoubleCvLJetTags_cfi.py | 11 ----- 6 files changed, 42 insertions(+), 50 deletions(-) delete mode 100644 RecoBTag/TensorFlow/python/pfDeepDoubleCvBJetTags_cfi.py delete mode 100644 RecoBTag/TensorFlow/python/pfDeepDoubleCvLJetTags_cfi.py diff --git a/DataFormats/BTauReco/interface/DeepDoubleXFeatures.h b/DataFormats/BTauReco/interface/DeepDoubleXFeatures.h index 84e6f3066d294..71e1c7d884be8 100644 --- a/DataFormats/BTauReco/interface/DeepDoubleXFeatures.h +++ b/DataFormats/BTauReco/interface/DeepDoubleXFeatures.h @@ -12,15 +12,15 @@ namespace btagbtvdeep { class DeepDoubleXFeatures { -public: + public: - bool empty() const { - return is_empty_; - } + bool empty() const { + return is_empty_; + } - void filled(){ + void filled(){ is_empty_ = false; - } + } JetFeatures jet_features; BoostedDoubleSVTagInfoFeatures tag_info_features; @@ -31,12 +31,11 @@ class DeepDoubleXFeatures { std::size_t npv; // used by deep flavour -private: - bool is_empty_ = true; + private: + bool is_empty_ = true; }; - } #endif //DataFormats_BTauReco_DeepDoubleXFeatures_h diff --git a/DataFormats/BTauReco/src/classes_def.xml b/DataFormats/BTauReco/src/classes_def.xml index d613c8786d61f..70f22e609fd86 100644 --- a/DataFormats/BTauReco/src/classes_def.xml +++ b/DataFormats/BTauReco/src/classes_def.xml @@ -447,8 +447,8 @@ - - + + diff --git a/PhysicsTools/PatAlgos/python/slimming/applyDeepBtagging_cff.py b/PhysicsTools/PatAlgos/python/slimming/applyDeepBtagging_cff.py index d0403c001f9e6..0543cdbd41808 100644 --- a/PhysicsTools/PatAlgos/python/slimming/applyDeepBtagging_cff.py +++ b/PhysicsTools/PatAlgos/python/slimming/applyDeepBtagging_cff.py @@ -67,7 +67,7 @@ def applyDeepBtagging( process, postfix="" ) : 'pfDeepDoubleCvBJetTags:probHbb', 'pfDeepDoubleCvBJetTags:probHcc', 'pfMassIndependentDeepDoubleBvLJetTags:probQCD', - 'pfMassIndependentDeepDoubleBvLJetTags:probHcc', + 'pfMassIndependentDeepDoubleBvLJetTags:probHbb', 'pfMassIndependentDeepDoubleCvLJetTags:probQCD', 'pfMassIndependentDeepDoubleCvLJetTags:probHcc', 'pfMassIndependentDeepDoubleCvBJetTags:probHbb', diff --git a/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc b/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc index 948d16be9372d..5b0dc7a57d592 100644 --- a/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc +++ b/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc @@ -137,6 +137,11 @@ void DeepDoubleXTFJetTagsProducer::fillDescriptions(edm::ConfigurationDescriptio desc.add>("output_names", { "ID_pred/Softmax" }); + desc.add("batch_eval", false); + + desc.add("nThreads", 1); + desc.add("singleThreadPool", "no_threads"); + edm::ParameterSetDescription psBvL; psBvL.add>("probQCD", {0}); psBvL.add>("probHbb", {1}); @@ -149,21 +154,29 @@ void DeepDoubleXTFJetTagsProducer::fillDescriptions(edm::ConfigurationDescriptio psCvB.add>("probHbb", {0}); psCvB.add>("probHcc", {1}); - desc.ifValue( edm::ParameterDescription("flavor", "BvL", true), - "BvL" >> (edm::ParameterDescription("flav_table", psBvL, true) and - edm::ParameterDescription("graph_path", edm::FileInPath("RecoBTag/Combined/data/DeepDoubleB/V01/constant_graph_PtCut_MassSculptPen.pb"), true)) or - "CvL" >> (edm::ParameterDescription("flav_table", psCvL, true) and - edm::ParameterDescription("graph_path", edm::FileInPath("RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDC.pb"), true) ) or - "CvB" >> (edm::ParameterDescription("flav_table", psCvB, true) and - edm::ParameterDescription("graph_path", edm::FileInPath("RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDCvB.pb"), true)) - ); - - desc.add("batch_eval", false); + using FIP = edm::FileInPath; + using PDFIP = edm::ParameterDescription; + using PDPSD = edm::ParameterDescription; + using PDCases = edm::ParameterDescriptionCases; + auto flavorCases = [&](){ return + "BvL" >> (PDPSD("flav_table", psBvL, true) and + PDFIP("graph_path", FIP("RecoBTag/Combined/data/DeepDoubleB/V01/constant_graph_PtCut_MassSculptPen.pb"), true)) or + "CvL" >> (PDPSD("flav_table", psCvL, true) and + PDFIP("graph_path", FIP("RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDC.pb"), true) ) or + "CvB" >> (PDPSD("flav_table", psCvB, true) and + PDFIP("graph_path", FIP("RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDCvB.pb"), true)); + }; + auto descBvL(desc); + descBvL.ifValue( edm::ParameterDescription("flavor", "BvL", true), flavorCases()); + descriptions.add("pfDeepDoubleBvLJetTags", descBvL); - desc.add("nThreads", 1); - desc.add("singleThreadPool", "no_threads"); + auto descCvL(desc); + descCvL.ifValue( edm::ParameterDescription("flavor", "CvL", true), flavorCases()); + descriptions.add("pfDeepDoubleCvLJetTags", descCvL); - descriptions.add("pfDeepDoubleBvLJetTags", desc); + auto descCvB(desc); + descCvB.ifValue( edm::ParameterDescription("flavor", "CvB", true), flavorCases()); + descriptions.add("pfDeepDoubleCvBJetTags", descCvB); } @@ -286,7 +299,6 @@ void DeepDoubleXTFJetTagsProducer::produce(edm::Event& iEvent, const edm::EventS std::size_t jet_n = batch_n*n_batch_jets + jet_bn; const auto & features = tag_infos->at(jet_n).features(); - if (features.empty()) continue ; const auto & jet_ref = tag_infos->at(jet_n).jet(); for (std::size_t flav_n=0; flav_n < flav_pairs_.size(); flav_n++) { @@ -295,7 +307,11 @@ void DeepDoubleXTFJetTagsProducer::produce(edm::Event& iEvent, const edm::EventS for (const unsigned int & ind : flav_pair.second) { o_sum += outputs.at(kJetFlavour).matrix()(jet_bn, ind); } - (*(output_tags.at(flav_n)))[jet_ref] = o_sum; + if (!features.empty()) { + (*(output_tags.at(flav_n)))[jet_ref] = o_sum; + } else { + (*(output_tags.at(flav_n)))[jet_ref] = -1.; + } } } } diff --git a/RecoBTag/TensorFlow/python/pfDeepDoubleCvBJetTags_cfi.py b/RecoBTag/TensorFlow/python/pfDeepDoubleCvBJetTags_cfi.py deleted file mode 100644 index 2620dfdc7749f..0000000000000 --- a/RecoBTag/TensorFlow/python/pfDeepDoubleCvBJetTags_cfi.py +++ /dev/null @@ -1,12 +0,0 @@ -import FWCore.ParameterSet.Config as cms -from pfDeepDoubleBvLJetTags_cfi import pfDeepDoubleBvLJetTags - -pfDeepDoubleCvBJetTags = pfDeepDoubleBvLJetTags.clone( - flavor = 'CvB', - graph_path = cms.FileInPath('RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDCvB.pb'), - flav_table = cms.PSet( - probHbb = cms.vuint32(0), - probHcc = cms.vuint32(1) - ) -) - diff --git a/RecoBTag/TensorFlow/python/pfDeepDoubleCvLJetTags_cfi.py b/RecoBTag/TensorFlow/python/pfDeepDoubleCvLJetTags_cfi.py deleted file mode 100644 index 65a57a4d0cb0f..0000000000000 --- a/RecoBTag/TensorFlow/python/pfDeepDoubleCvLJetTags_cfi.py +++ /dev/null @@ -1,11 +0,0 @@ -import FWCore.ParameterSet.Config as cms -from pfDeepDoubleBvLJetTags_cfi import pfDeepDoubleBvLJetTags - -pfDeepDoubleCvLJetTags = pfDeepDoubleBvLJetTags.clone( - flavor = 'CvL', - graph_path = cms.FileInPath('RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDC.pb'), - flav_table = cms.PSet( - probQCD = cms.vuint32(0), - probHcc = cms.vuint32(1) - ) -) From 5703a714c67c45ee492b2325b944dd3bda5f7873 Mon Sep 17 00:00:00 2001 From: anovak10 Date: Thu, 22 Nov 2018 00:05:27 +0100 Subject: [PATCH 25/30] Run TF only when features are filled --- .../plugins/DeepDoubleXTFJetTagsProducer.cc | 53 ++++++++++--------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc b/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc index 5b0dc7a57d592..7a2996f6b14ac 100644 --- a/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc +++ b/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc @@ -205,10 +205,10 @@ void DeepDoubleXTFJetTagsProducer::globalEndJob(const DeepDoubleXTFCache* cache) void DeepDoubleXTFJetTagsProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { - + edm::Handle tag_infos; iEvent.getByToken(src_, tag_infos); - + // initialize output collection std::vector> output_tags; for (std::size_t i=0; i < flav_pairs_.size(); i++) { @@ -220,12 +220,17 @@ void DeepDoubleXTFJetTagsProducer::produce(edm::Event& iEvent, const edm::EventS output_tags.emplace_back(std::make_unique()); } } - - const int64_t n_jets = tag_infos->size(); + + // count jets to actually run inference on + int64_t n_jets = 0; + for (std::size_t i=0; i < tag_infos->size(); i++){ + const auto & features = tag_infos->at(i).features(); + if (!features.empty()) n_jets += 1 ; + } + // count all jets to generate output_tags for each and set to default (-1) + const int64_t n_jets_all = tag_infos->size(); // either all jets or one per batch for the time being const int64_t n_batch_jets = batch_eval_ ? n_jets : 1; - - std::vector input_sizes { {n_batch_jets, 1, 27}, // input_1 - global double-b features {n_batch_jets, 60, 8}, // input_2 - charged pf @@ -248,27 +253,28 @@ void DeepDoubleXTFJetTagsProducer::produce(edm::Event& iEvent, const edm::EventS for (std::size_t i=0; i < lp_tensors_.size(); i++) { input_tensors[input_sizes.size() + i] = tensorflow::NamedTensor(lp_names_[i], lp_tensors_[i]); } - - std::size_t n_batches = n_jets/n_batch_jets; // either 1 or n_jets + + std::size_t n_batches = n_jets_all/n_batch_jets; // either 1 or n_jets for (std::size_t batch_n=0; batch_n < n_batches; batch_n++) { - // tensors have to be zeroed before filling per batch for (std::size_t i=0; i < input_sizes.size(); i++) { input_tensors[i].second.flat().setZero(); } - + // don't run batch unless filled + bool run_this_batch = false; // fill values of the input tensors for (std::size_t jet_bn=0; jet_bn < (std::size_t) n_batch_jets; jet_bn++) { // global jet index (jet_bn is the jet batch index) std::size_t jet_n = batch_n*n_batch_jets + jet_bn; - - // jet and other global features + // only fill if features not empty const auto & features = tag_infos->at(jet_n).features(); if (features.empty()) continue ; + // if at least one jet has features, run inferences + run_this_batch = true; + // jet and other global features db_tensor_filler(input_tensors.at(kGlobal).second, jet_bn, features); - // c_pf candidates auto max_c_pf_n = std::min(features.c_pf_features.size(), (std::size_t) input_sizes.at(kChargedCandidates).dim_size(1)); @@ -290,8 +296,9 @@ void DeepDoubleXTFJetTagsProducer::produce(edm::Event& iEvent, const edm::EventS } // run the session std::vector outputs; + if (run_this_batch){ tensorflow::run(session_, input_tensors, output_names_, &outputs); - + } // set output values for flavour probs for (std::size_t jet_bn=0; jet_bn < (std::size_t) n_batch_jets; jet_bn++) { @@ -299,27 +306,25 @@ void DeepDoubleXTFJetTagsProducer::produce(edm::Event& iEvent, const edm::EventS std::size_t jet_n = batch_n*n_batch_jets + jet_bn; const auto & features = tag_infos->at(jet_n).features(); - const auto & jet_ref = tag_infos->at(jet_n).jet(); for (std::size_t flav_n=0; flav_n < flav_pairs_.size(); flav_n++) { const auto & flav_pair = flav_pairs_.at(flav_n); float o_sum = 0.; - for (const unsigned int & ind : flav_pair.second) { - o_sum += outputs.at(kJetFlavour).matrix()(jet_bn, ind); - } - if (!features.empty()) { - (*(output_tags.at(flav_n)))[jet_ref] = o_sum; - } else { - (*(output_tags.at(flav_n)))[jet_ref] = -1.; + if (!features.empty()) { + for (const unsigned int & ind : flav_pair.second) { + o_sum += outputs.at(kJetFlavour).matrix()(jet_bn, ind); } + (*(output_tags.at(flav_n)))[jet_ref] = o_sum; + } else { + (*(output_tags.at(flav_n)))[jet_ref] = -1.; + } } - } + } } for (std::size_t i=0; i < flav_pairs_.size(); i++) { iEvent.put(std::move(output_tags[i]), flav_pairs_.at(i).first); } - } //define this as a plug-in From b456bf985f641aed268a79778f21440cbd2a19ca Mon Sep 17 00:00:00 2001 From: anovak10 Date: Thu, 22 Nov 2018 02:10:35 +0100 Subject: [PATCH 26/30] Fix batch eval --- .../plugins/DeepDoubleXTFJetTagsProducer.cc | 3 ++- RecoBTag/TensorFlow/test/plotDDX.py | 26 ------------------- 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc b/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc index 7a2996f6b14ac..19a52c6fa4d3e 100644 --- a/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc +++ b/RecoBTag/TensorFlow/plugins/DeepDoubleXTFJetTagsProducer.cc @@ -230,7 +230,8 @@ void DeepDoubleXTFJetTagsProducer::produce(edm::Event& iEvent, const edm::EventS // count all jets to generate output_tags for each and set to default (-1) const int64_t n_jets_all = tag_infos->size(); // either all jets or one per batch for the time being - const int64_t n_batch_jets = batch_eval_ ? n_jets : 1; + const int64_t n_batch_jets = batch_eval_ ? n_jets_all : 1; + std::vector input_sizes { {n_batch_jets, 1, 27}, // input_1 - global double-b features {n_batch_jets, 60, 8}, // input_2 - charged pf diff --git a/RecoBTag/TensorFlow/test/plotDDX.py b/RecoBTag/TensorFlow/test/plotDDX.py index 04eece65ccd46..7bfd0f5f4acb1 100644 --- a/RecoBTag/TensorFlow/test/plotDDX.py +++ b/RecoBTag/TensorFlow/test/plotDDX.py @@ -4,38 +4,13 @@ events_c = Events('output_test_DDX.root') handleJ = Handle ("std::vector") -#labelJ = ("slimmedJetsAK8","","PAT") -#labelJ = ("updatedPatJets","","PATtest") labelJ = ("selectedUpdatedPatJets","","PATtest") -#labelJ = ("updatedPatJetsTransientCorrected","","PATtest") - - -# Type Module Label Process -# ----------------------------------------------------------------------------------------------- -# edm::ValueMap "offlineSlimmedPrimaryVertices" "" "PAT" -# vector "slimmedJetsAK8" "" "PAT" -# vector "slimmedJetsAK8PFPuppiSoftDropPacked" "SubJets" "PAT" -# vector "offlineSlimmedPrimaryVertices" "" "PAT" -# vector "slimmedSecondaryVertices" "" "PAT" -# edm::OwnVector > "selectedUpdatedPatJets" "tagInfos" "PATtest" -# edm::OwnVector > "updatedPatJets" "tagInfos" "PATtest" -# edm::OwnVector > "updatedPatJetsTransientCorrected" "tagInfos" "PATtest" -# vector "selectedUpdatedPatJets" "caloTowers" "PATtest" -# vector "selectedUpdatedPatJets" "" "PATtest" -# vector "updatedPatJets" "" "PATtest" -# vector "updatedPatJetsTransientCorrected" "" "PATtest" -# vector "pfBoostedDoubleSVAK8TagInfos" "" "PATtest" -# vector > "pfDeepDoubleBTagInfos" "" "PATtest" -# vector "selectedUpdatedPatJets" "genJets" "PATtest" -# vector "selectedUpdatedPatJets" "pfCandidates" "PATtest" h_probQ_ddb = ROOT.TH1F('h_probQ_ddb', ';prob Q;', 40, 0., 1.) h_probH_ddb = ROOT.TH1F('h_probH_ddb', ';prob H;', 40, 0., 1.) -h_probQplusH_ddb = ROOT.TH1F('h_probQplusH_ddb', ';prob Q + H;', 44, 0., 1.1) h_probQ_ddc = ROOT.TH1F('h_probQ_ddc', ';prob Q;', 40, 0., 1.) h_probH_ddc = ROOT.TH1F('h_probH_ddc', ';prob H;', 40, 0., 1.) -h_probQplusH_ddc = ROOT.TH1F('h_probQplusH_ddc', ';prob Q + H;', 44, 0., 1.1) for iev,event in enumerate(events_c): event.getByLabel (labelJ, handleJ) @@ -55,7 +30,6 @@ h_probH_ddb.Fill(jet.bDiscriminator("pfDeepDoubleBvLJetTags:probHbb")) h_probQ_ddc.Fill(jet.bDiscriminator("pfDeepDoubleCvLJetTags:probQCD")) h_probH_ddc.Fill(jet.bDiscriminator("pfDeepDoubleCvLJetTags:probHcc")) - if iev > 10000: break c1a = ROOT.TCanvas() h_probH_ddb.Draw("HISTO") From f3eb7564b2f61e60329e5499e72e1f93d6617529 Mon Sep 17 00:00:00 2001 From: anovak10 Date: Tue, 27 Nov 2018 16:46:11 +0100 Subject: [PATCH 27/30] Fix print for python3 --- RecoBTag/TensorFlow/test/plotDDX.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/RecoBTag/TensorFlow/test/plotDDX.py b/RecoBTag/TensorFlow/test/plotDDX.py index 7bfd0f5f4acb1..12b962f843eb5 100644 --- a/RecoBTag/TensorFlow/test/plotDDX.py +++ b/RecoBTag/TensorFlow/test/plotDDX.py @@ -1,3 +1,4 @@ +from __future__ import print_function import ROOT from DataFormats.FWLite import Handle, Events @@ -19,13 +20,13 @@ if jet.pt() < 300 or jet.pt() > 2000: continue if jet.mass() < 40 or jet.mass() > 200: continue - print jet.pt(), jet.mass() - print "DDB", jet.bDiscriminator("pfDeepDoubleBvLJetTags:probQCD"), jet.bDiscriminator("pfDeepDoubleBvLJetTags:probHbb") , jet.bDiscriminator("pfDeepDoubleBvLJetTags:probHcc") - print "DDB", jet.bDiscriminator("pfMassIndependentDeepDoubleBvLJetTags:probQCD"), jet.bDiscriminator("pfMassIndependentDeepDoubleBvLJetTags:probHbb") , jet.bDiscriminator("pfMassIndependentDeepDoubleBvLJetTags:probHcc") - print "DDCvL", jet.bDiscriminator("pfDeepDoubleCvLJetTags:probQCD"), jet.bDiscriminator("pfDeepDoubleCvLJetTags:probHcc") , jet.bDiscriminator("pfDeepDoubleCvLJetTags:probHbb") - print "DDCvL", jet.bDiscriminator("pfMassIndependentDeepDoubleCvLJetTags:probQCD"), jet.bDiscriminator("pfMassIndependentDeepDoubleCvLJetTags:probHcc") , jet.bDiscriminator("pfDeepDoubleMassIndependentCvLJetTags:probHbb") - print "DDCvB", jet.bDiscriminator("pfDeepDoubleCvBJetTags:probHbb"), jet.bDiscriminator("pfDeepDoubleCvBJetTags:probHcc") , jet.bDiscriminator("pfDeepDoubleCvBJetTags:probQCD") - print "DDCvB", jet.bDiscriminator("pfMassIndependentDeepDoubleCvBJetTags:probHbb"), jet.bDiscriminator("pfMassIndependentDeepDoubleCvBJetTags:probHcc") , jet.bDiscriminator("pfMassIndependentDeepDoubleCvBJetTags:probQCD") + print(jet.pt(), jet.mass()) + print("DDB", jet.bDiscriminator("pfDeepDoubleBvLJetTags:probQCD"), jet.bDiscriminator("pfDeepDoubleBvLJetTags:probHbb") , jet.bDiscriminator("pfDeepDoubleBvLJetTags:probHcc")) + print("DDB", jet.bDiscriminator("pfMassIndependentDeepDoubleBvLJetTags:probQCD"), jet.bDiscriminator("pfMassIndependentDeepDoubleBvLJetTags:probHbb") , jet.bDiscriminator("pfMassIndependentDeepDoubleBvLJetTags:probHcc")) + print("DDCvL", jet.bDiscriminator("pfDeepDoubleCvLJetTags:probQCD"), jet.bDiscriminator("pfDeepDoubleCvLJetTags:probHcc") , jet.bDiscriminator("pfDeepDoubleCvLJetTags:probHbb")) + print("DDCvL", jet.bDiscriminator("pfMassIndependentDeepDoubleCvLJetTags:probQCD"), jet.bDiscriminator("pfMassIndependentDeepDoubleCvLJetTags:probHcc") , jet.bDiscriminator("pfDeepDoubleMassIndependentCvLJetTags:probHbb")) + print("DDCvB", jet.bDiscriminator("pfDeepDoubleCvBJetTags:probHbb"), jet.bDiscriminator("pfDeepDoubleCvBJetTags:probHcc") , jet.bDiscriminator("pfDeepDoubleCvBJetTags:probQCD")) + print("DDCvB", jet.bDiscriminator("pfMassIndependentDeepDoubleCvBJetTags:probHbb"), jet.bDiscriminator("pfMassIndependentDeepDoubleCvBJetTags:probHcc") , jet.bDiscriminator("pfMassIndependentDeepDoubleCvBJetTags:probQCD")) h_probQ_ddb.Fill(jet.bDiscriminator("pfDeepDoubleBvLJetTags:probQCD")) h_probH_ddb.Fill(jet.bDiscriminator("pfDeepDoubleBvLJetTags:probHbb")) h_probQ_ddc.Fill(jet.bDiscriminator("pfDeepDoubleCvLJetTags:probQCD")) From 40f5b44c8dcc9aad768eb5aba526dc481793daf6 Mon Sep 17 00:00:00 2001 From: anovak10 Date: Tue, 27 Nov 2018 16:58:31 +0100 Subject: [PATCH 28/30] Remove type specification --- .../python/pfMassIndependentDeepDoubleXJetTags_cff.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleXJetTags_cff.py b/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleXJetTags_cff.py index f965b2422d8f3..0cacbdfa85c33 100644 --- a/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleXJetTags_cff.py +++ b/RecoBTag/TensorFlow/python/pfMassIndependentDeepDoubleXJetTags_cff.py @@ -4,12 +4,10 @@ from pfDeepDoubleCvBJetTags_cfi import pfDeepDoubleCvBJetTags pfMassIndependentDeepDoubleBvLJetTags = pfDeepDoubleBvLJetTags.clone( - graph_path = cms.FileInPath('RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDB_mass_independent.pb') -) + graph_path = 'RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDB_mass_independent.pb') pfMassIndependentDeepDoubleCvLJetTags = pfDeepDoubleCvLJetTags.clone( - graph_path = cms.FileInPath('RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDC_mass_independent.pb') -) + graph_path = 'RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDC_mass_independent.pb') pfMassIndependentDeepDoubleCvBJetTags = pfDeepDoubleCvBJetTags.clone( - graph_path = cms.FileInPath('RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDCvB_mass_independent.pb') -) + graph_path = 'RecoBTag/Combined/data/DeepDoubleX/94X/V01/DDCvB_mass_independent.pb') + From 2c45ee33ebd508260fdac6706357df9e1977b2c6 Mon Sep 17 00:00:00 2001 From: anovak10 Date: Tue, 27 Nov 2018 17:01:31 +0100 Subject: [PATCH 29/30] Remove wrong flavour print check --- RecoBTag/TensorFlow/test/plotDDX.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/RecoBTag/TensorFlow/test/plotDDX.py b/RecoBTag/TensorFlow/test/plotDDX.py index 12b962f843eb5..044d8055cf4b8 100644 --- a/RecoBTag/TensorFlow/test/plotDDX.py +++ b/RecoBTag/TensorFlow/test/plotDDX.py @@ -21,12 +21,12 @@ if jet.mass() < 40 or jet.mass() > 200: continue print(jet.pt(), jet.mass()) - print("DDB", jet.bDiscriminator("pfDeepDoubleBvLJetTags:probQCD"), jet.bDiscriminator("pfDeepDoubleBvLJetTags:probHbb") , jet.bDiscriminator("pfDeepDoubleBvLJetTags:probHcc")) - print("DDB", jet.bDiscriminator("pfMassIndependentDeepDoubleBvLJetTags:probQCD"), jet.bDiscriminator("pfMassIndependentDeepDoubleBvLJetTags:probHbb") , jet.bDiscriminator("pfMassIndependentDeepDoubleBvLJetTags:probHcc")) - print("DDCvL", jet.bDiscriminator("pfDeepDoubleCvLJetTags:probQCD"), jet.bDiscriminator("pfDeepDoubleCvLJetTags:probHcc") , jet.bDiscriminator("pfDeepDoubleCvLJetTags:probHbb")) - print("DDCvL", jet.bDiscriminator("pfMassIndependentDeepDoubleCvLJetTags:probQCD"), jet.bDiscriminator("pfMassIndependentDeepDoubleCvLJetTags:probHcc") , jet.bDiscriminator("pfDeepDoubleMassIndependentCvLJetTags:probHbb")) - print("DDCvB", jet.bDiscriminator("pfDeepDoubleCvBJetTags:probHbb"), jet.bDiscriminator("pfDeepDoubleCvBJetTags:probHcc") , jet.bDiscriminator("pfDeepDoubleCvBJetTags:probQCD")) - print("DDCvB", jet.bDiscriminator("pfMassIndependentDeepDoubleCvBJetTags:probHbb"), jet.bDiscriminator("pfMassIndependentDeepDoubleCvBJetTags:probHcc") , jet.bDiscriminator("pfMassIndependentDeepDoubleCvBJetTags:probQCD")) + print("DDB", jet.bDiscriminator("pfDeepDoubleBvLJetTags:probQCD"), jet.bDiscriminator("pfDeepDoubleBvLJetTags:probHbb")) + print("DDB", jet.bDiscriminator("pfMassIndependentDeepDoubleBvLJetTags:probQCD"), jet.bDiscriminator("pfMassIndependentDeepDoubleBvLJetTags:probHbb")) + print("DDCvL", jet.bDiscriminator("pfDeepDoubleCvLJetTags:probQCD"), jet.bDiscriminator("pfDeepDoubleCvLJetTags:probHcc")) + print("DDCvL", jet.bDiscriminator("pfMassIndependentDeepDoubleCvLJetTags:probQCD"), jet.bDiscriminator("pfMassIndependentDeepDoubleCvLJetTags:probHcc")) + print("DDCvB", jet.bDiscriminator("pfDeepDoubleCvBJetTags:probHbb"), jet.bDiscriminator("pfDeepDoubleCvBJetTags:probHcc") ) + print("DDCvB", jet.bDiscriminator("pfMassIndependentDeepDoubleCvBJetTags:probHbb"), jet.bDiscriminator("pfMassIndependentDeepDoubleCvBJetTags:probHcc")) h_probQ_ddb.Fill(jet.bDiscriminator("pfDeepDoubleBvLJetTags:probQCD")) h_probH_ddb.Fill(jet.bDiscriminator("pfDeepDoubleBvLJetTags:probHbb")) h_probQ_ddc.Fill(jet.bDiscriminator("pfDeepDoubleCvLJetTags:probQCD")) From bbadee22b968560c5d50c2d9f60f7b202258e192 Mon Sep 17 00:00:00 2001 From: anovak10 Date: Wed, 28 Nov 2018 12:04:16 +0100 Subject: [PATCH 30/30] Fix indentation --- RecoBTag/TensorFlow/test/plotDDX.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RecoBTag/TensorFlow/test/plotDDX.py b/RecoBTag/TensorFlow/test/plotDDX.py index 044d8055cf4b8..acc86108c48d6 100644 --- a/RecoBTag/TensorFlow/test/plotDDX.py +++ b/RecoBTag/TensorFlow/test/plotDDX.py @@ -17,8 +17,8 @@ event.getByLabel (labelJ, handleJ) jets = handleJ.product() for jet in jets : - if jet.pt() < 300 or jet.pt() > 2000: continue - if jet.mass() < 40 or jet.mass() > 200: continue + if jet.pt() < 300 or jet.pt() > 2000: continue + if jet.mass() < 40 or jet.mass() > 200: continue print(jet.pt(), jet.mass()) print("DDB", jet.bDiscriminator("pfDeepDoubleBvLJetTags:probQCD"), jet.bDiscriminator("pfDeepDoubleBvLJetTags:probHbb"))