Skip to content

Commit

Permalink
Merge pull request #27146 from cms-tau-pog/CMSSW_10_6_X_tau-pog_DeepT…
Browse files Browse the repository at this point in the history
…au2017v2_forUL

Update of DeepTauID to ver. 2017v2 (backport for UL)
  • Loading branch information
cmsbuild authored Jun 14, 2019
2 parents 7118dfe + 1d2c2c7 commit 6af6c5f
Show file tree
Hide file tree
Showing 8 changed files with 1,318 additions and 125 deletions.
10 changes: 5 additions & 5 deletions DataFormats/MuonDetId/interface/MuonSubdetId.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
class MuonSubdetId {
public:

static const int DT= 1;
static const int CSC=2;
static const int RPC=3;
static const int GEM=4;
static const int ME0=5;
static constexpr int DT= 1;
static constexpr int CSC=2;
static constexpr int RPC=3;
static constexpr int GEM=4;
static constexpr int ME0=5;
};

#endif
Expand Down
18 changes: 18 additions & 0 deletions PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,24 @@ def miniAOD_customizeCommon(process):
run2_miniAOD_94XFall17.toReplaceWith(
process.makePatTausTask, _makePatTausTaskWithRetrainedMVATauID
)
#-- Adding DeepTauID
updatedTauName = 'slimmedTausDeepIDs'
noUpdatedTauName = 'slimmedTausNoDeepIDs'
import RecoTauTag.RecoTau.tools.runTauIdMVA as tauIdConfig
tauIdEmbedder = tauIdConfig.TauIDEmbedder(
process, cms, debug = False,
updatedTauName = updatedTauName,
toKeep = ['deepTau2017v2']
)
tauIdEmbedder.runTauID()
addToProcessAndTask(noUpdatedTauName, process.slimmedTaus.clone(),process,task)
delattr(process, 'slimmedTaus')
process.deepTau2017v2.taus = noUpdatedTauName
process.slimmedTaus = getattr(process, updatedTauName).clone(
src = noUpdatedTauName
)
process.rerunMvaIsolationTask.add(process.slimmedTaus)
task.add(process.rerunMvaIsolationTask)
#-- Adding customization for 80X 2016 legacy reMiniAOD and 2018 heavy ions
from Configuration.Eras.Modifier_run2_miniAOD_80XLegacy_cff import run2_miniAOD_80XLegacy
from Configuration.Eras.Modifier_pp_on_AA_2018_cff import pp_on_AA_2018
Expand Down
14 changes: 8 additions & 6 deletions RecoTauTag/RecoTau/interface/DeepTauBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ class DeepTauCache {
public:
using GraphPtr = std::shared_ptr<tensorflow::GraphDef>;

DeepTauCache(const std::string& graph_name, bool mem_mapped);
DeepTauCache(const std::map<std::string, std::string>& graph_names, bool mem_mapped);
~DeepTauCache();

// A Session allows concurrent calls to Run(), though a Session must
// be created / extended by a single thread.
tensorflow::Session& getSession() const { return *session_; }
const tensorflow::GraphDef& getGraph() const { return *graph_; }
tensorflow::Session& getSession(const std::string& name = "") const { return *sessions_.at(name); }
const tensorflow::GraphDef& getGraph(const std::string& name = "") const { return *graphs_.at(name); }

private:
GraphPtr graph_;
tensorflow::Session* session_;
std::unique_ptr<tensorflow::MemmappedEnv> memmappedEnv_;
std::map<std::string, GraphPtr> graphs_;
std::map<std::string, tensorflow::Session*> sessions_;
std::map<std::string, std::unique_ptr<tensorflow::MemmappedEnv>> memmappedEnv_;
};

class DeepTauBase : public edm::stream::EDProducer<edm::GlobalCache<DeepTauCache>> {
Expand Down Expand Up @@ -96,6 +96,8 @@ class DeepTauBase : public edm::stream::EDProducer<edm::GlobalCache<DeepTauCache

protected:
edm::EDGetTokenT<TauCollection> tausToken_;
edm::EDGetTokenT<pat::PackedCandidateCollection> pfcandToken_;
edm::EDGetTokenT<reco::VertexCollection> vtxToken_;
std::map<std::string, WPMap> workingPoints_;
OutputCollection outputs_;
const DeepTauCache* cache_;
Expand Down
11 changes: 3 additions & 8 deletions RecoTauTag/RecoTau/plugins/DPFIsolation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,26 @@ class DPFIsolation : public deep_tau::DeepTauBase {

explicit DPFIsolation(const edm::ParameterSet& cfg,const deep_tau::DeepTauCache* cache) :
DeepTauBase(cfg, GetOutputs(), cache),
pfcand_token(consumes<pat::PackedCandidateCollection>(cfg.getParameter<edm::InputTag>("pfcands"))),
vtx_token(consumes<reco::VertexCollection>(cfg.getParameter<edm::InputTag>("vertices"))),
graphVersion(cfg.getParameter<unsigned>("version"))
{
const auto& shape = cache_->getGraph().node(0).attr().at("shape").shape();

if(!(graphVersion == 1 || graphVersion == 0 ))
throw cms::Exception("DPFIsolation") << "unknown version of the graph_ file.";
throw cms::Exception("DPFIsolation") << "unknown version of the graph file.";

if(!(shape.dim(1).size() == getNumberOfParticles(graphVersion) && shape.dim(2).size() == GetNumberOfFeatures(graphVersion)))
throw cms::Exception("DPFIsolation") << "number of inputs does not match the expected inputs for the given version";

}

private:
tensorflow::Tensor getPredictions(edm::Event& event, const edm::EventSetup& es,
edm::Handle<TauCollection> taus) override
{
edm::Handle<pat::PackedCandidateCollection> pfcands;
event.getByToken(pfcand_token, pfcands);
event.getByToken(pfcandToken_, pfcands);

edm::Handle<reco::VertexCollection> vertices;
event.getByToken(vtx_token, vertices);
event.getByToken(vtxToken_, vertices);

tensorflow::Tensor tensor(tensorflow::DT_FLOAT, {1,
static_cast<int>(getNumberOfParticles(graphVersion)), static_cast<int>(GetNumberOfFeatures(graphVersion))});
Expand Down Expand Up @@ -394,8 +391,6 @@ class DPFIsolation : public deep_tau::DeepTauBase {
}

private:
edm::EDGetTokenT<pat::PackedCandidateCollection> pfcand_token;
edm::EDGetTokenT<reco::VertexCollection> vtx_token;
unsigned graphVersion;
};

Expand Down
Loading

0 comments on commit 6af6c5f

Please sign in to comment.