Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update DeepTauID to ver. 2017v2p1 #396

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions HLTrigger/Configuration/python/Tools/confdbOfflineConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ class OfflineConverter:

databases = {}
databases['v1'] = {}
databases['v1']['offline'] = ( '-t', 'oracle', '-h', 'cmsr1-s.cern.ch', '-d', 'cms_cond.cern.ch', '-u', 'cms_hltdev_reader', '-s', 'convertme!' )
databases['v1']['offline'] = ( '-t', 'oracle', '-h', 'cmsr1-s.cern.ch', '-d', 'cms_cond.cern.ch', '-u', 'cms_hltdev_reader', '-s', 'ConvertMe!' )
databases['v1']['hltdev'] = databases['v1']['offline'] # for backwards compatibility
databases['v1']['online'] = ( '-t', 'oracle', '-h', 'cmsonr1-s.cms', '-d', 'cms_rcms.cern.ch', '-u', 'cms_hlt_r', '-s', 'convertme!' )
databases['v1']['adg'] = ( '-t', 'oracle', '-h', 'cmsr1-s.cern.ch', '-d', 'cms_cond.cern.ch', '-u', 'cms_hlt_gui_r', '-s', 'convertme!' )
databases['v1']['online'] = ( '-t', 'oracle', '-h', 'cmsonr1-s.cms', '-d', 'cms_rcms.cern.ch', '-u', 'cms_hlt_r', '-s', 'ConvertMe!' )
databases['v1']['adg'] = ( '-t', 'oracle', '-h', 'cmsr1-s.cern.ch', '-d', 'cms_cond.cern.ch', '-u', 'cms_hlt_gui_r', '-s', 'ConvertMe!' )
databases['v1']['orcoff'] = databases['v1']['adg'] # for backwards compatibility
databases['v2'] = {}
databases['v2']['offline'] = ( '-t', 'oracle', '-h', 'cmsr1-s.cern.ch', '-d', 'cms_cond.cern.ch', '-u', 'cms_hlt_gdr_r', '-s', 'convertme!' )
databases['v2']['online'] = ( '-t', 'oracle', '-h', 'cmsonr1-s.cms', '-d', 'cms_rcms.cern.ch', '-u', 'cms_hlt_gdr_r', '-s', 'convertme!' )
databases['v2']['adg'] = ( '-t', 'oracle', '-h', 'cmsonradg1-s.cern.ch', '-d', 'cms_orcon_adg.cern.ch', '-u', 'cms_hlt_gdr_r', '-s', 'convertme!' )
databases['v2']['offline'] = ( '-t', 'oracle', '-h', 'cmsr1-s.cern.ch', '-d', 'cms_cond.cern.ch', '-u', 'cms_hlt_gdr_r', '-s', 'ConvertMe!' )
databases['v2']['online'] = ( '-t', 'oracle', '-h', 'cmsonr1-s.cms', '-d', 'cms_rcms.cern.ch', '-u', 'cms_hlt_gdr_r', '-s', 'ConvertMe!' )
databases['v2']['adg'] = ( '-t', 'oracle', '-h', 'cmsonr1-adg1-s.cern.ch', '-d', 'cms_orcon_adg.cern.ch', '-u', 'cms_hlt_gdr_r', '-s', 'ConvertMe!' )


@staticmethod
Expand Down
4 changes: 2 additions & 2 deletions PhysicsTools/NanoAOD/python/nano_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@
modifier.toModify(extraFlagsTable, variables= cms.PSet())
modifier.toModify(extraFlagsTable, variables = dict(Flag_ecalBadCalibFilterV2 = ExtVar(cms.InputTag("ecalBadCalibFilterNanoTagger"), bool, doc = "Bad ECAL calib flag (updated xtal list)")))

# modifier which adds new tauIDs (currently only deepTauId2017v2 is being added)
# modifier which adds new tauIDs (currently only deepTauId2017v2p1 is being added)
import RecoTauTag.RecoTau.tools.runTauIdMVA as tauIdConfig
def nanoAOD_addTauIds(process):
updatedTauName = "slimmedTausUpdated"
tauIdEmbedder = tauIdConfig.TauIDEmbedder(process, cms, debug = False, updatedTauName = updatedTauName,
toKeep = [ "deepTau2017v2" ])
toKeep = [ "deepTau2017v2p1" ])
tauIdEmbedder.runTauID()
process.patTauMVAIDsSeq.insert(process.patTauMVAIDsSeq.index(getattr(process, updatedTauName)),
process.rerunMvaIsolationSequence)
Expand Down
35 changes: 17 additions & 18 deletions PhysicsTools/NanoAOD/python/taus_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

finalTaus = cms.EDFilter("PATTauRefSelector",
src = cms.InputTag("slimmedTausUpdated"),
cut = cms.string("pt > 18 && tauID('decayModeFindingNewDMs') && (tauID('byLooseCombinedIsolationDeltaBetaCorr3Hits') || tauID('byVLooseIsolationMVArun2v1DBoldDMwLT2015') || tauID('byVLooseIsolationMVArun2v1DBnewDMwLT') || tauID('byVLooseIsolationMVArun2v1DBdR03oldDMwLT') || tauID('byVVLooseIsolationMVArun2v1DBoldDMwLT') || tauID('byVVLooseIsolationMVArun2v1DBoldDMwLT2017v2') || tauID('byVVLooseIsolationMVArun2v1DBnewDMwLT2017v2') || tauID('byVVLooseIsolationMVArun2v1DBdR03oldDMwLT2017v2') || tauID('byVVVLooseDeepTau2017v2VSjet'))")
cut = cms.string("pt > 18 && tauID('decayModeFindingNewDMs') && (tauID('byLooseCombinedIsolationDeltaBetaCorr3Hits') || tauID('byVLooseIsolationMVArun2v1DBoldDMwLT2015') || tauID('byVLooseIsolationMVArun2v1DBnewDMwLT') || tauID('byVLooseIsolationMVArun2v1DBdR03oldDMwLT') || tauID('byVVLooseIsolationMVArun2v1DBoldDMwLT') || tauID('byVVLooseIsolationMVArun2v1DBoldDMwLT2017v2') || tauID('byVVLooseIsolationMVArun2v1DBnewDMwLT2017v2') || tauID('byVVLooseIsolationMVArun2v1DBdR03oldDMwLT2017v2') || tauID('byVVVLooseDeepTau2017v2p1VSjet'))")
)

for era in [eras.run2_nanoAOD_94X2016,eras.run2_nanoAOD_94XMiniAODv2,eras.run2_nanoAOD_102Xv1]:
Expand Down Expand Up @@ -118,22 +118,21 @@ def _tauId8WPMask(pattern,doc):
rawAntiEleCat2018 = Var("tauID('againstElectronMVA6category2018')", int, doc="Anti-electron MVA discriminator V6 category (2018)"),
idAntiEle2018 = _tauId5WPMask("againstElectron%sMVA62018", doc= "Anti-electron MVA discriminator V6 (2018)"),
)
_deepTauVars2017v2 = cms.PSet(
rawDeepTau2017v2VSe = Var("tauID('byDeepTau2017v2VSeraw')", float, doc="byDeepTau2017v2VSe raw output discriminator (deepTau2017v2)", precision=10),
rawDeepTau2017v2VSmu = Var("tauID('byDeepTau2017v2VSmuraw')", float, doc="byDeepTau2017v2VSmu raw output discriminator (deepTau2017v2)", precision=10),
rawDeepTau2017v2VSjet = Var("tauID('byDeepTau2017v2VSjetraw')", float, doc="byDeepTau2017v2VSjet raw output discriminator (deepTau2017v2)", precision=10),
idDeepTau2017v2VSe = _tauId8WPMask("by%sDeepTau2017v2VSe", doc="byDeepTau2017v2VSe ID working points (deepTau2017v2)"),
idDeepTau2017v2VSmu = _tauId4WPMask("by%sDeepTau2017v2VSmu", doc="byDeepTau2017v2VSmu ID working points (deepTau2017v2)"),
idDeepTau2017v2VSjet = _tauId8WPMask("by%sDeepTau2017v2VSjet", doc="byDeepTau2017v2VSjet ID working points (deepTau2017v2)"),
_deepTauVars2017v2p1 = cms.PSet(
rawDeepTau2017v2p1VSe = Var("tauID('byDeepTau2017v2p1VSeraw')", float, doc="byDeepTau2017v2p1VSe raw output discriminator (deepTau2017v2p1)", precision=10),
rawDeepTau2017v2p1VSmu = Var("tauID('byDeepTau2017v2p1VSmuraw')", float, doc="byDeepTau2017v2p1VSmu raw output discriminator (deepTau2017v2p1)", precision=10),
rawDeepTau2017v2p1VSjet = Var("tauID('byDeepTau2017v2p1VSjetraw')", float, doc="byDeepTau2017v2p1VSjet raw output discriminator (deepTau2017v2p1)", precision=10),
idDeepTau2017v2p1VSe = _tauId8WPMask("by%sDeepTau2017v2p1VSe", doc="byDeepTau2017v2p1VSe ID working points (deepTau2017v2p1)"),
idDeepTau2017v2p1VSmu = _tauId4WPMask("by%sDeepTau2017v2p1VSmu", doc="byDeepTau2017v2p1VSmu ID working points (deepTau2017v2p1)"),
idDeepTau2017v2p1VSjet = _tauId8WPMask("by%sDeepTau2017v2p1VSjet", doc="byDeepTau2017v2p1VSjet ID working points (deepTau2017v2p1)"),
)

_variablesMiniV2 = cms.PSet(
_tauVarsBase,
_mvaAntiEVars2018,
_mvaIsoVars2015Reduced,
_mvaIsoVars2017v1,
_mvaIsoVars2017v2,
_deepTauVars2017v2
_mvaIsoVars2017v2
)
_variablesMiniV1 = _variablesMiniV2.clone()
_variablesMiniV1.rawMVAoldDM = Var( "tauID('byIsolationMVArun2v1DBoldDMwLTraw')",float, doc="byIsolationMVArun2v1DBoldDMwLT raw output discriminator (2015)",precision=10)
Expand All @@ -145,7 +144,7 @@ def _tauId8WPMask(pattern,doc):
_mvaIsoVars2015
)

tauTable.variables=_variablesMiniV2
tauTable.variables = cms.PSet(_variablesMiniV2,_deepTauVars2017v2p1)

for era in [eras.run2_nanoAOD_94XMiniAODv1,]:
era.toModify(tauTable,
Expand All @@ -154,14 +153,14 @@ def _tauId8WPMask(pattern,doc):
eras.run2_miniAOD_80XLegacy.toModify(tauTable,
variables = _variables80X
)
for era in [eras.run2_nanoAOD_94XMiniAODv1,eras.run2_nanoAOD_94X2016,eras.run2_nanoAOD_94XMiniAODv2,eras.run2_nanoAOD_102Xv1]:
for era in [eras.run2_nanoAOD_94X2016,eras.run2_nanoAOD_94XMiniAODv2,eras.run2_nanoAOD_102Xv1]:
era.toModify(tauTable.variables,
rawDeepTau2017v2VSe = None,
rawDeepTau2017v2VSmu = None,
rawDeepTau2017v2VSjet = None,
idDeepTau2017v2VSe = None,
idDeepTau2017v2VSmu = None,
idDeepTau2017v2VSjet = None
rawDeepTau2017v2p1VSe = None,
rawDeepTau2017v2p1VSmu = None,
rawDeepTau2017v2p1VSjet = None,
idDeepTau2017v2p1VSe = None,
idDeepTau2017v2p1VSmu = None,
idDeepTau2017v2p1VSjet = None
)

tauGenJets.GenParticles = cms.InputTag("prunedGenParticles")
Expand Down
21 changes: 17 additions & 4 deletions RecoTauTag/RecoTau/plugins/DeepTauId.cc
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ class DeepTauId : public deep_tau::DeepTauBase {
desc.add<bool>("mem_mapped", false);
desc.add<unsigned>("version", 2);
desc.add<int>("debug_level", 0);
desc.add<bool>("disable_dxy_pca", false);

edm::ParameterSetDescription descWP;
descWP.add<std::string>("VVVLoose", "0");
Expand All @@ -601,7 +602,8 @@ class DeepTauId : public deep_tau::DeepTauBase {
muons_token_(consumes<MuonCollection>(cfg.getParameter<edm::InputTag>("muons"))),
rho_token_(consumes<double>(cfg.getParameter<edm::InputTag>("rho"))),
version(cfg.getParameter<unsigned>("version")),
debug_level(cfg.getParameter<int>("debug_level"))
debug_level(cfg.getParameter<int>("debug_level")),
disable_dxy_pca_(cfg.getParameter<bool>("disable_dxy_pca"))
{
if(version == 1) {
input_layer_ = cache_->getGraph().node(0).name();
Expand Down Expand Up @@ -907,9 +909,19 @@ class DeepTauId : public deep_tau::DeepTauBase {
get(dnn::neutralIsoPtSumdR03_over_dR05) = getValue(tau.tauID("neutralIsoPtSumdR03") / tau.tauID("neutralIsoPtSum"));
get(dnn::photonPtSumOutsideSignalCone) = getValueNorm(tau.tauID("photonPtSumOutsideSignalConedR03"), 1.731f, 6.846f);
get(dnn::puCorrPtSum) = getValueNorm(tau.tauID("puCorrPtSum"), 22.38f, 16.34f);
get(dnn::tau_dxy_pca_x) = getValueNorm(tau.dxy_PCA().x(), -0.0241f, 0.0074f);
get(dnn::tau_dxy_pca_y) = getValueNorm(tau.dxy_PCA().y(),0.0675f, 0.0128f);
get(dnn::tau_dxy_pca_z) = getValueNorm(tau.dxy_PCA().z(), 0.7973f, 3.456f);
// The global PCA coordinates were used as inputs during the NN training, but it was decided to disable
// them for the inference, because modeling of dxy_PCA in MC poorly describes the data, and x and y coordinates
// in data results outside of the expected 5 std. dev. input validity range. On the other hand,
// these coordinates are strongly era-dependent. Kept as comment to document what NN expects.
if (!disable_dxy_pca_) {
get(dnn::tau_dxy_pca_x) = getValueNorm(tau.dxy_PCA().x(), -0.0241f, 0.0074f);
get(dnn::tau_dxy_pca_y) = getValueNorm(tau.dxy_PCA().y(),0.0675f, 0.0128f);
get(dnn::tau_dxy_pca_z) = getValueNorm(tau.dxy_PCA().z(), 0.7973f, 3.456f);
} else {
get(dnn::tau_dxy_pca_x) = 0;
get(dnn::tau_dxy_pca_y) = 0;
get(dnn::tau_dxy_pca_z) = 0;
}

const bool tau_dxy_valid = std::isnormal(tau.dxy()) && tau.dxy() > - 10 && std::isnormal(tau.dxy_error())
&& tau.dxy_error() > 0;
Expand Down Expand Up @@ -1687,6 +1699,7 @@ class DeepTauId : public deep_tau::DeepTauBase {
std::string input_layer_, output_layer_;
const unsigned version;
const int debug_level;
const bool disable_dxy_pca_;
std::shared_ptr<tensorflow::Tensor> tauBlockTensor_;
std::array<std::shared_ptr<tensorflow::Tensor>, 2> eGammaTensor_, muonTensor_, hadronsTensor_,
convTensor_, zeroOutputTensor_;
Expand Down
70 changes: 66 additions & 4 deletions RecoTauTag/RecoTau/python/tools/runTauIdMVA.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ class TauIDEmbedder(object):
"""class to rerun the tau seq and acces trainings from the database"""
availableDiscriminators = [
"2017v1", "2017v2", "newDM2017v2", "dR0p32017v2", "2016v1", "newDM2016v1",
"deepTau2017v1", "deepTau2017v2", "DPFTau_2016_v0", "DPFTau_2016_v1", "againstEle2018"
"deepTau2017v1", "deepTau2017v2", "deepTau2017v2p1",
"DPFTau_2016_v0", "DPFTau_2016_v1",
"againstEle2018"
]

def __init__(self, process, cms, debug = False,
updatedTauName = "slimmedTausNewID",
toKeep = ["deepTau2017v2"],
toKeep = ["deepTau2017v2p1"],
tauIdDiscrMVA_trainings_run2_2017 = { 'tauIdMVAIsoDBoldDMwLT2017' : "tauIdMVAIsoDBoldDMwLT2017", },
tauIdDiscrMVA_WPs_run2_2017 = {
'tauIdMVAIsoDBoldDMwLT2017' : {
Expand Down Expand Up @@ -650,7 +652,9 @@ def runTauID(self):
rho = self.cms.InputTag('fixedGridRhoAll'),
graph_file = self.cms.vstring(file_names),
mem_mapped = self.cms.bool(False),
version = self.cms.uint32(self.getDeepTauVersion(file_names[0])[1])
version = self.cms.uint32(self.getDeepTauVersion(file_names[0])[1]),
debug_level = self.cms.int32(0),
disable_dxy_pca = self.cms.bool(False)
)

self.processDeepProducer('deepTau2017v1', tauIDSources, workingPoints_)
Expand Down Expand Up @@ -705,7 +709,8 @@ def runTauID(self):
graph_file = self.cms.vstring(file_names),
mem_mapped = self.cms.bool(True),
version = self.cms.uint32(self.getDeepTauVersion(file_names[0])[1]),
debug_level = self.cms.int32(0)
debug_level = self.cms.int32(0),
disable_dxy_pca = self.cms.bool(False)

)

Expand All @@ -714,6 +719,63 @@ def runTauID(self):
self.process.rerunMvaIsolationTask.add(self.process.deepTau2017v2)
self.process.rerunMvaIsolationSequence += self.process.deepTau2017v2

if "deepTau2017v2p1" in self.toKeep:
if self.debug: print "Adding DeepTau IDs"

workingPoints_ = {
"e": {
"VVVLoose": 0.0630386,
"VVLoose": 0.1686942,
"VLoose": 0.3628130,
"Loose": 0.6815435,
"Medium": 0.8847544,
"Tight": 0.9675541,
"VTight": 0.9859251,
"VVTight": 0.9928449,
},
"mu": {
"VLoose": 0.1058354,
"Loose": 0.2158633,
"Medium": 0.5551894,
"Tight": 0.8754835,
},
"jet": {
"VVVLoose": 0.2599605,
"VVLoose": 0.4249705,
"VLoose": 0.5983682,
"Loose": 0.7848675,
"Medium": 0.8834768,
"Tight": 0.9308689,
"VTight": 0.9573137,
"VVTight": 0.9733927,
},
}

file_names = [
'core:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_core.pb',
'inner:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_inner.pb',
'outer:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_outer.pb',
]
self.process.deepTau2017v2p1 = 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.vstring(file_names),
mem_mapped = self.cms.bool(True),
version = self.cms.uint32(self.getDeepTauVersion(file_names[0])[1]),
debug_level = self.cms.int32(0),
disable_dxy_pca = self.cms.bool(True)

)

self.processDeepProducer('deepTau2017v2p1', tauIDSources, workingPoints_)

self.process.rerunMvaIsolationTask.add(self.process.deepTau2017v2p1)
self.process.rerunMvaIsolationSequence += self.process.deepTau2017v2p1

if "DPFTau_2016_v0" in self.toKeep:
if self.debug: print "Adding DPFTau isolation (v0)"

Expand Down
2 changes: 1 addition & 1 deletion RecoTauTag/RecoTau/test/runDeepTauIDsOnMiniAOD.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
updatedTauName = updatedTauName,
toKeep = [ "2017v2", "dR0p32017v2", "newDM2017v2",
# "deepTau2017v1",
"deepTau2017v2",
"deepTau2017v2p1",
# "DPFTau_2016_v0",
# "DPFTau_2016_v1",
"againstEle2018"
Expand Down