diff --git a/RecoTauTag/RecoTau/interface/DeepTauBase.h b/RecoTauTag/RecoTau/interface/DeepTauBase.h index dde15ef7044ad..031ebfd90021a 100644 --- a/RecoTauTag/RecoTau/interface/DeepTauBase.h +++ b/RecoTauTag/RecoTau/interface/DeepTauBase.h @@ -60,18 +60,17 @@ class DeepTauBase : public edm::stream::EDProducer<> { virtual void produce(edm::Event& event, const edm::EventSetup& es) override; private: - virtual tensorflow::Tensor GetPredictions(edm::Event& event, const edm::EventSetup& es) = 0; - virtual void CreateOutputs(edm::Event& event, const tensorflow::Tensor& pred); + virtual tensorflow::Tensor GetPredictions(edm::Event& event, const edm::EventSetup& es, + edm::Handle taus) = 0; + virtual void CreateOutputs(edm::Event& event, const tensorflow::Tensor& pred, edm::Handle taus); protected: edm::EDGetTokenT taus_token; - edm::Handle taus; std::string graphName; GraphPtr graph; tensorflow::Session* session; std::map working_points; OutputCollection outputs; - }; } // namespace deep_tau diff --git a/RecoTauTag/RecoTau/plugins/DPFIsolation.cc b/RecoTauTag/RecoTau/plugins/DPFIsolation.cc index 5b7cab8aa6692..8676abbf7e5de 100644 --- a/RecoTauTag/RecoTau/plugins/DPFIsolation.cc +++ b/RecoTauTag/RecoTau/plugins/DPFIsolation.cc @@ -79,19 +79,25 @@ class DPFIsolation : public deep_tau::DeepTauBase { graphVersion = 1; else throw cms::Exception("DPFIsolation") << "unknown version of the graph file."; - - tensor = tensorflow::Tensor(tensorflow::DT_FLOAT, {1, - static_cast(GetNumberOfParticles(graphVersion)), static_cast(GetNumberOfFeatures(graphVersion))}); } private: - virtual tensorflow::Tensor GetPredictions(edm::Event& event, const edm::EventSetup& es) override + virtual tensorflow::Tensor GetPredictions(edm::Event& event, const edm::EventSetup& es, + edm::Handle taus) override { + edm::Handle pfcands; event.getByToken(pfcand_token, pfcands); + + edm::Handle vertices; event.getByToken(vtx_token, vertices); + tensorflow::Tensor tensor(tensorflow::DT_FLOAT, {1, + static_cast(GetNumberOfParticles(graphVersion)), static_cast(GetNumberOfFeatures(graphVersion))}); + tensorflow::Tensor predictions(tensorflow::DT_FLOAT, { static_cast(taus->size()), 1}); + std::vector outputs; + float pfCandPt, pfCandPz, pfCandPtRel, pfCandPzRel, pfCandDr, pfCandDEta, pfCandDPhi, pfCandEta, pfCandDz, pfCandDzErr, pfCandD0, pfCandD0D0, pfCandD0Dz, pfCandD0Dphi, pfCandPuppiWeight, pfCandPixHits, pfCandHits, pfCandLostInnerHits, pfCandPdgID, pfCandCharge, pfCandFromPV, @@ -378,14 +384,8 @@ class DPFIsolation : public deep_tau::DeepTauBase { private: edm::EDGetTokenT pfcand_token; - edm::EDGetTokenT vtx_token; - - edm::Handle pfcands; - edm::Handle vertices; - + edm::EDGetTokenT vtx_token; unsigned graphVersion; - tensorflow::Tensor tensor; - std::vector outputs; }; #include "FWCore/Framework/interface/MakerMacros.h" diff --git a/RecoTauTag/RecoTau/plugins/DeepTauId.cc b/RecoTauTag/RecoTau/plugins/DeepTauId.cc index c123ecc7e0329..f0ceddb7e1440 100644 --- a/RecoTauTag/RecoTau/plugins/DeepTauId.cc +++ b/RecoTauTag/RecoTau/plugins/DeepTauId.cc @@ -278,7 +278,8 @@ class DeepTauId : public deep_tau::DeepTauBase { } private: - virtual tensorflow::Tensor GetPredictions(edm::Event& event, const edm::EventSetup& es) override + virtual tensorflow::Tensor GetPredictions(edm::Event& event, const edm::EventSetup& es, + edm::Handle taus) override { edm::Handle electrons; event.getByToken(electrons_token, electrons); @@ -306,9 +307,9 @@ class DeepTauId : public deep_tau::DeepTauBase { void SetInputs(const TauCollection& taus, size_t tau_index, tensorflow::Tensor& inputs, const ElectronCollection& electrons, const MuonCollection& muons) const { - static constexpr bool check_all_set = false; static constexpr float magic_number = -42; + static const TauIdMVAAuxiliaries clusterVariables; const auto& get = [&](int var_index) -> float& { return inputs.matrix()(tau_index, var_index); }; const TauType& tau = taus.at(tau_index); auto leadChargedHadrCand = dynamic_cast(tau.leadChargedHadrCand().get()); @@ -604,9 +605,8 @@ class DeepTauId : public deep_tau::DeepTauBase { const double dR2 = deltaR*deltaR; const pat::Electron* matched_ele = nullptr; for(const auto& ele : electrons) { - if(reco::deltaR2(tau.p4(), ele.p4()) < dR2 && - (!matched_ele || matched_ele->pt() < ele.pt())) { - matched_ele = &ele; + if(reco::deltaR2(tau.p4(), ele.p4()) < dR2 && (!matched_ele || matched_ele->pt() < ele.pt())) { + matched_ele = &ele; } } return matched_ele; @@ -616,7 +616,6 @@ class DeepTauId : public deep_tau::DeepTauBase { edm::EDGetTokenT electrons_token; edm::EDGetTokenT muons_token; std::string input_layer, output_layer; - TauIdMVAAuxiliaries clusterVariables; }; #include "FWCore/Framework/interface/MakerMacros.h" diff --git a/RecoTauTag/RecoTau/python/tools/runTauIdMVA.py b/RecoTauTag/RecoTau/python/tools/runTauIdMVA.py index 370a961959b7d..71d318b0f9bea 100644 --- a/RecoTauTag/RecoTau/python/tools/runTauIdMVA.py +++ b/RecoTauTag/RecoTau/python/tools/runTauIdMVA.py @@ -610,7 +610,7 @@ def runTauID(self): "Loose": "0.999755", "Medium": "0.999854", "Tight": "0.999886", - "VTight": "0.99994", + "VTight": "0.999944", "VVTight": "0.9999971" }, @@ -666,6 +666,8 @@ def runTauID(self): if "DPFTau_2016_v1" in self.toKeep: print "Adding DPFTau isolation (v1)" + print "WARNING: WPs are not defined for DPFTau_2016_v1" + print "WARNING: The score of DPFTau_2016_v1 is inverted: i.e. for Sig->0, for Bkg->1 with -1 for undefined input (preselection not passed)." working_points = { "all": {"Tight" : "0.123"} #FIXME: define WP diff --git a/RecoTauTag/RecoTau/src/DeepTauBase.cc b/RecoTauTag/RecoTau/src/DeepTauBase.cc index 61ccbcc4693f3..d94d6d55ebd01 100644 --- a/RecoTauTag/RecoTau/src/DeepTauBase.cc +++ b/RecoTauTag/RecoTau/src/DeepTauBase.cc @@ -65,12 +65,14 @@ DeepTauBase::~DeepTauBase() void DeepTauBase::produce(edm::Event& event, const edm::EventSetup& es) { + edm::Handle taus; event.getByToken(taus_token, taus); - const tensorflow::Tensor& pred = GetPredictions(event, es); - CreateOutputs(event, pred); + + const tensorflow::Tensor& pred = GetPredictions(event, es, taus); + CreateOutputs(event, pred, taus); } -void DeepTauBase::CreateOutputs(edm::Event& event, const tensorflow::Tensor& pred) +void DeepTauBase::CreateOutputs(edm::Event& event, const tensorflow::Tensor& pred, edm::Handle taus) { for(const auto& output_desc : outputs) { auto result_map = output_desc.second.get_value(taus, pred, working_points.at(output_desc.first)); diff --git a/RecoTauTag/RecoTau/test/runDeepTauIDsOnMiniAOD.py b/RecoTauTag/RecoTau/test/runDeepTauIDsOnMiniAOD.py index 057806b3d6809..cf638c302af73 100644 --- a/RecoTauTag/RecoTau/test/runDeepTauIDsOnMiniAOD.py +++ b/RecoTauTag/RecoTau/test/runDeepTauIDsOnMiniAOD.py @@ -33,7 +33,9 @@ updatedTauName = updatedTauName, toKeep = [ "2017v2", "dR0p32017v2", "newDM2017v2", "deepTau2017v1", - "DPFTau_2016_v0","DPFTau_2016_v1"]) + "DPFTau_2016_v0", + #"DPFTau_2016_v1" + ]) tauIdEmbedder.runTauID() # Output definition