diff --git a/RecoTauTag/RecoTau/plugins/DeepTauId.cc b/RecoTauTag/RecoTau/plugins/DeepTauId.cc index c266dc178fd96..1747e9ed42ce2 100644 --- a/RecoTauTag/RecoTau/plugins/DeepTauId.cc +++ b/RecoTauTag/RecoTau/plugins/DeepTauId.cc @@ -449,7 +449,7 @@ struct MuonHitMatchV2 { }; enum class CellObjectType { PfCand_electron, PfCand_muon, PfCand_chargedHadron, PfCand_neutralHadron, - PfCand_gamma, Electron, Muon }; + PfCand_gamma, Electron, Muon, Other }; template CellObjectType GetCellObjectType(const Object&); @@ -471,7 +471,7 @@ CellObjectType GetCellObjectType(const pat::PackedCandidate& cand) auto iter = obj_types.find(std::abs(cand.pdgId())); if(iter == obj_types.end()) - throw cms::Exception("DeepTauId") << "Unknown object pdg id = " << cand.pdgId(); + return CellObjectType::Other; return iter->second; } @@ -565,7 +565,7 @@ class DeepTauId : public deep_tau::DeepTauBase { desc.add("pfcands", edm::InputTag("packedPFCandidates")); desc.add("vertices", edm::InputTag("offlineSlimmedPrimaryVertices")); desc.add("rho", edm::InputTag("fixedGridRhoAll")); - desc.add("graph_file", "RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2.pb"); + desc.add("graph_file", "RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e2.pb"); desc.add("mem_mapped", false); desc.add("version", 2); @@ -600,7 +600,6 @@ class DeepTauId : public deep_tau::DeepTauBase { if(shape.dim(1).size() != dnn_inputs_2017v1::NumberOfInputs) throw cms::Exception("DeepTauId") << "number of inputs does not match the expected inputs for the given version"; } else if(version == 2) { - } else { throw cms::Exception("DeepTauId") << "version " << version << " is not supported."; } @@ -724,13 +723,12 @@ class DeepTauId : public deep_tau::DeepTauBase { const auto input_outer_egamma = createEgammaBlockInputs(tau, pv, rho, electrons, pfCands, outer_grid, false); const auto input_outer_muon = createMuonBlockInputs(tau, pv, rho, muons, pfCands, outer_grid, false); const auto input_outer_hadrons = createHadronsBlockInputs(tau, pv, rho, pfCands, outer_grid, false); - tensorflow::run(&(cache_->getSession()), { { "input_tau", input_tau }, { "input_inner_egamma", input_inner_egamma}, { "input_outer_egamma", input_outer_egamma }, { "input_inner_muon", input_inner_muon }, { "input_outer_muon", input_outer_muon }, { "input_inner_hadrons", input_inner_hadrons }, { "input_outer_hadrons", input_outer_hadrons } }, - { "main_output" }, &pred_vector); + { "main_output/Softmax" }, &pred_vector); } template @@ -812,11 +810,14 @@ class DeepTauId : public deep_tau::DeepTauBase { get(tau_ip3d_valid) = tau_ip3d_valid; get(tau_ip3d) = tau_ip3d_valid ? getValueNorm(tau.ip3d(), 0.0026f, 0.0114f) : 0.f; get(tau_ip3d_sig) = tau_ip3d_valid ? getValueNorm(std::abs(tau.ip3d()) / tau.ip3d_error(), 2.928f, 4.466f) : 0.f; - get(tau_dz) = getValueNorm(leadChargedHadrCand->dz(), 0.f, 0.0190f); - const bool tau_dz_sig_valid = std::isnormal(leadChargedHadrCand->dz()) && std::isnormal(leadChargedHadrCand->dzError()) - && leadChargedHadrCand->dzError() > 0; + + get(tau_dz) = leadChargedHadrCand ? getValueNorm(leadChargedHadrCand->dz(), 0.f, 0.0190f) : 0.f; + const bool tau_dz_sig_valid = leadChargedHadrCand && leadChargedHadrCand->hasTrackDetails() && + std::isnormal(leadChargedHadrCand->dz()) && std::isnormal(leadChargedHadrCand->dzError()) && leadChargedHadrCand->dzError() > 0; get(tau_dz_sig_valid) = tau_dz_sig_valid; - get(tau_dz_sig) = getValueNorm(std::abs(leadChargedHadrCand->dz()) / leadChargedHadrCand->dzError(), 4.717f, 11.78f); + get(tau_dz_sig) = tau_dz_sig_valid ? + getValueNorm(std::abs(leadChargedHadrCand->dz()) / leadChargedHadrCand->dzError(), 4.717f, 11.78f) : 0.f; + get(tau_flightLength_x) = getValueNorm(tau.flightLength().x(), -0.0003f, 0.7362f); get(tau_flightLength_y) = getValueNorm(tau.flightLength().y(), -0.0009f, 0.7354f); get(tau_flightLength_z) = getValueNorm(tau.flightLength().z(), -0.0022f, 1.993f); @@ -839,7 +840,6 @@ class DeepTauId : public deep_tau::DeepTauBase { get(tau_inside_ecal_crack) = getValue(isInEcalCrack(tau.p4().eta())); get(leadChargedCand_etaAtEcalEntrance_minus_tau_eta) = getValueNorm(tau.etaAtEcalEntranceLeadChargedCand() - tau.p4().eta(), 0.0042f, 0.0323f); - return inputs; } @@ -853,7 +853,6 @@ class DeepTauId : public deep_tau::DeepTauBase { tensorflow::Tensor inputs(tensorflow::DT_FLOAT, {1, grid.nCellsEta, grid.nCellsPhi, NumberOfInputs}); inputs.flat().setZero(); - for(const auto& cell : grid) { int eta_index = grid.getEtaTensorIndex(cell.first); int phi_index = grid.getPhiTensorIndex(cell.first); @@ -874,7 +873,7 @@ class DeepTauId : public deep_tau::DeepTauBase { get(tau_eta) = getValueLinear(tau.polarP4().eta(), -2.3f, 2.3f, false); get(tau_inside_ecal_crack) = getValue(isInEcalCrack(tau.polarP4().eta())); } - if(valid_index_ele){ + if(valid_index_pf_ele){ size_t index_pf_ele = cell_map.at(CellObjectType::PfCand_electron); get(pfCand_ele_valid) = valid_index_pf_ele; @@ -916,7 +915,7 @@ class DeepTauId : public deep_tau::DeepTauBase { } } if(valid_index_pf_gamma){ - size_t index_pf_gamma = cell_map.at(CellObjectType::PfCand_neutralHadron); + size_t index_pf_gamma = cell_map.at(CellObjectType::PfCand_gamma); get(pfCand_gamma_valid) = valid_index_pf_gamma; get(pfCand_gamma_rel_pt) = getValueNorm(pfCands.at(index_pf_gamma).polarP4().pt() / tau.polarP4().pt(), diff --git a/RecoTauTag/RecoTau/python/tools/runTauIdMVA.py b/RecoTauTag/RecoTau/python/tools/runTauIdMVA.py index def331fad2e10..fc28b3ba0e091 100644 --- a/RecoTauTag/RecoTau/python/tools/runTauIdMVA.py +++ b/RecoTauTag/RecoTau/python/tools/runTauIdMVA.py @@ -9,7 +9,7 @@ class TauIDEmbedder(object): def __init__(self, process, cms, debug = False, updatedTauName = "slimmedTausNewID", - toKeep = ["2016v1", "newDM2016v1","deepTau2017v1","DPFTau_2016_v0"], + toKeep = ["2016v1", "newDM2016v1","deepTau2017v1", "deepTau2017v2","DPFTau_2016_v0"], tauIdDiscrMVA_trainings_run2_2017 = { 'tauIdMVAIsoDBoldDMwLT2017' : "tauIdMVAIsoDBoldDMwLT2017", }, @@ -646,6 +646,60 @@ def runTauID(self): self.process.rerunMvaIsolationTask.add(self.process.deepTau2017v1) self.process.rerunMvaIsolationSequence += self.process.deepTau2017v1 + if "deepTau2017v2" in self.toKeep: + print ("Adding DeepTau IDs") + + workingPoints_ = { + "e": { + "VVVLoose" : 0.96424, + "VVLoose" : 0.98992, + "VLoose" : 0.99574, + "Loose": 0.99831, + "Medium": 0.99868, + "Tight": 0.99898, + "VTight": 0.99911, + "VVTight": 0.99918 + }, + "mu": { + "VVVLoose" : 0.959619, + "VVLoose" : 0.997687, + "VLoose" : 0.999392, + "Loose": 0.999755, + "Medium": 0.999854, + "Tight": 0.999886, + "VTight": 0.999944, + "VVTight": 0.9999971 + }, + + "jet": { + "VVVLoose" : 0.5329, + "VVLoose" : 0.7645, + "VLoose" : 0.8623, + "Loose": 0.9140, + "Medium": 0.9464, + "Tight": 0.9635, + "VTight": 0.9760, + "VVTight": 0.9859 + } + } + file_name = 'RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e2.pb' + self.process.deepTau2017v2 = self.cms.EDProducer("DeepTauId", + electrons = self.cms.InputTag('slimmedElectrons'), + muons = self.cms.InputTag('slimmedMuons'), + taus = self.cms.InputTag('slimmedTaus'), + pfcands = self.cms.InputTag('packedPFCandidates'), + vertices = self.cms.InputTag('offlineSlimmedPrimaryVertices'), + rho = self.cms.InputTag('fixedGridRhoAll'), + graph_file = self.cms.string(file_name), + mem_mapped = self.cms.bool(False), + version = self.cms.uint32(2) + ) + + self.processDeepProducer('deepTau2017v2', tauIDSources, workingPoints_) + + self.process.rerunMvaIsolationTask.add(self.process.deepTau2017v2) + self.process.rerunMvaIsolationSequence += self.process.deepTau2017v2 + if "DPFTau_2016_v0" in self.toKeep: print ("Adding DPFTau isolation (v0)") diff --git a/RecoTauTag/RecoTau/test/runDeepTauIDsOnMiniAOD.py b/RecoTauTag/RecoTau/test/runDeepTauIDsOnMiniAOD.py index 8cfea895a08b3..a61f8ca2e820c 100644 --- a/RecoTauTag/RecoTau/test/runDeepTauIDsOnMiniAOD.py +++ b/RecoTauTag/RecoTau/test/runDeepTauIDsOnMiniAOD.py @@ -23,7 +23,7 @@ # Input source process.source = cms.Source('PoolSource', fileNames = cms.untracked.vstring( # File from dataset DY1JetsToLL_M-50_TuneCP5_13TeV-madgraphMLM-pythia8 - '/store/mc/RunIIFall17MiniAODv2/TTToHadronic_mtop169p5_TuneCP5_PSweights_13TeV-powheg-pythia8/MINIAODSIM/PU2017_12Apr2018_94X_mc2017_realistic_v14-v3/100000/64BE09E8-76A8-E811-8602-FA163EC538AA.root' + ' /store/mc/RunIIFall17MiniAODv2/TTToHadronic_TuneCP5_13TeV-powheg-pythia8/MINIAODSIM/PU2017_12Apr2018_94X_mc2017_realistic_v14-v1/40000/A256C80D-0943-E811-998E-7CD30AB0522C.root' )) process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(eventsToProcess) ) @@ -33,8 +33,9 @@ tauIdEmbedder = tauIdConfig.TauIDEmbedder(process, cms, debug = False, updatedTauName = updatedTauName, toKeep = [ "2017v2", "dR0p32017v2", "newDM2017v2", - "deepTau2017v1", - "DPFTau_2016_v0", + # "deepTau2017v1", + "deepTau2017v2", + # "DPFTau_2016_v0", # "DPFTau_2016_v1", "againstEle2018", ])