Skip to content

Commit

Permalink
Merge pull request #46112 from cms-tau-pog/CMSSW_14_2_X_tau-pog_Boost…
Browse files Browse the repository at this point in the history
…edDeepTau

Boosted DeepTauID v2.0
  • Loading branch information
cmsbuild authored Oct 15, 2024
2 parents f27df5f + 8872b79 commit ceae18e
Show file tree
Hide file tree
Showing 9 changed files with 364 additions and 16 deletions.
18 changes: 13 additions & 5 deletions PhysicsTools/NanoAOD/python/boostedTaus_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@

##################### Import reusable funtions and objects from std taus ########
from PhysicsTools.NanoAOD.taus_cff import _tauIdWPMask, tausMCMatchLepTauForTable, tausMCMatchHadTauForTable,tauMCTable

##################### User floats producers, selectors ##########################


finalBoostedTaus = cms.EDFilter("PATTauRefSelector",
src = cms.InputTag("slimmedTausBoosted"),
cut = cms.string("pt > 40 && tauID('decayModeFindingNewDMs') && (tauID('byVVLooseIsolationMVArun2DBoldDMwLT') || tauID('byVVLooseIsolationMVArun2DBnewDMwLT'))")
cut = cms.string("pt > 25 && tauID('decayModeFindingNewDMs') && (tauID('byVVLooseIsolationMVArun2DBoldDMwLT') || tauID('byVVLooseIsolationMVArun2DBnewDMwLT') || tauID('byBoostedDeepTau20161718v2p0VSjetraw') > {})".format(0.82))
)
run2_nanoAOD_106Xv2.toModify(
finalBoostedTaus,
cut = "pt > 40 && tauID('decayModeFindingNewDMs') && (tauID('byVVLooseIsolationMVArun2DBoldDMwLT') || tauID('byVVLooseIsolationMVArun2DBoldDMdR0p3wLT') || tauID('byVVLooseIsolationMVArun2DBnewDMwLT'))"
cut = "pt > 25 && tauID('decayModeFindingNewDMs') && (tauID('byVVLooseIsolationMVArun2DBoldDMwLT') || tauID('byVVLooseIsolationMVArun2DBoldDMdR0p3wLT') || tauID('byVVLooseIsolationMVArun2DBnewDMwLT') || tauID('byBoostedDeepTau20161718v2p0VSjetraw') > {})".format(0.82)
)

boostedTauTable = simplePATTauFlatTableProducer.clone(
Expand Down Expand Up @@ -59,16 +58,25 @@
idAntiEle2018 = _tauIdWPMask("againstElectron%sMVA6", choices=("VLoose","Loose","Medium","Tight","VTight"), doc= "Anti-electron MVA discriminator V6 (2018)")
)

#DeepBoostedTau ID raw score branches
_boostedDeepTauRunIIv2p0Vars = cms.PSet(
rawBoostedDeepTauRunIIv2p0VSe = Var("tauID('byBoostedDeepTau20161718v2p0VSeraw')", float, doc="BoostedDeepTau(v2p0) tagger for boostedTaus raw scores Vs e", precision=10),
rawBoostedDeepTauRunIIv2p0VSmu = Var("tauID('byBoostedDeepTau20161718v2p0VSmuraw')", float, doc="BoostedDeepTau(v2p0) tagger for boostedTaus raw scores Vs mu", precision=10),
rawBoostedDeepTauRunIIv2p0VSjet = Var("tauID('byBoostedDeepTau20161718v2p0VSjetraw')", float, doc="BoostedDeepTau(v2p0) tagger for boostedTaus raw scores Vs jet", precision=10)
)

boostedTauTable.variables = cms.PSet(
_boostedTauVarsBase,
_boostedTauVarsMVAIso,
_boostedTauVarsAntiEleMVA
_boostedTauVarsAntiEleMVA,
_boostedDeepTauRunIIv2p0Vars
)
_boostedTauVarsWithDr03 = cms.PSet(
_boostedTauVarsBase,
_boostedTauVarsMVAIso,
_boostedTauVarsMVAIsoDr03,
_boostedTauVarsAntiEleMVA
_boostedTauVarsAntiEleMVA,
_boostedDeepTauRunIIv2p0Vars
)
run2_nanoAOD_106Xv2.toModify(
boostedTauTable,
Expand Down
3 changes: 3 additions & 0 deletions PhysicsTools/NanoAOD/python/nanoDQM_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,9 @@
Plot1D('rawIsodR03', 'rawIsodR03', 20, 0, 200, 'combined isolation (deltaBeta corrections, dR=0.3)'),
Plot1D('rawMVAnewDM2017v2', 'rawMVAnewDM2017v2', 20, -1, 1, 'byIsolationMVArun2017v2DBnewDMwLT raw output discriminator (2017v2)'),
Plot1D('rawMVAoldDM2017v2', 'rawMVAoldDM2017v2', 20, -1, 1, 'byIsolationMVArun2017v2DBoldDMwLT raw output discriminator (2017v2)'),
Plot1D('rawBoostedDeepTauRunIIv2p0VSe', 'rawBoostedDeepTauRunIIv2p0VSe', 20, 0, 1, 'BoostedDeepTau(v2p0) tagger for boostedTaus raw scores Vs e'),
Plot1D('rawBoostedDeepTauRunIIv2p0VSjet', 'rawBoostedDeepTauRunIIv2p0VSjet', 20, 0, 1, 'BoostedDeepTau(v2p0) tagger for boostedTaus raw scores Vs jet'),
Plot1D('rawBoostedDeepTauRunIIv2p0VSmu', 'rawBoostedDeepTauRunIIv2p0VSmu', 20, 0, 1, 'BoostedDeepTau(v2p0) tagger for boostedTaus raw scores Vs mu'),
)
),
L1PreFiringWeight = cms.PSet(
Expand Down
7 changes: 6 additions & 1 deletion PhysicsTools/NanoAOD/python/nano_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,12 @@ def nanoAOD_customizeCommon(process):
idsToAdd = cms.vstring()
)
run2_nanoAOD_106Xv2.toModify(
nanoAOD_boostedTau_switch, idsToAdd = ["mvaIso", "mvaIsoNewDM", "mvaIsoDR0p3", "againstEle"]
nanoAOD_boostedTau_switch, idsToAdd = ["mvaIso", "mvaIsoNewDM", "mvaIsoDR0p3", "againstEle", "boostedDeepTauRunIIv2p0"]
).toModify(
process, lambda p : nanoAOD_addBoostedTauIds(p, nanoAOD_boostedTau_switch.idsToAdd.value())
)
run3_nanoAOD_pre142X.toModify(
nanoAOD_boostedTau_switch, idsToAdd = ["boostedDeepTauRunIIv2p0"]
).toModify(
process, lambda p : nanoAOD_addBoostedTauIds(p, nanoAOD_boostedTau_switch.idsToAdd.value())
)
Expand Down
18 changes: 17 additions & 1 deletion PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,23 @@ def _add_deepFlavour(process):
#-- Adding boosted taus
from RecoTauTag.Configuration.boostedHPSPFTaus_cfi import addBoostedTaus
addBoostedTaus(process)
#-- Adding DeepTauID for boosted taus
import RecoTauTag.RecoTau.tools.runTauIdMVA as tauIdConfig
_updatedBoostedTauName = 'slimmedTausBoostedDeepIDs'
_noUpdatedBoostedTauName = 'slimmedTausBoostedNoDeepIDs'
boostedTauIdEmbedder = tauIdConfig.TauIDEmbedder(
process, debug = False,
originalTauName = _noUpdatedBoostedTauName,
updatedTauName = _updatedBoostedTauName,
postfix = 'BoostedForMini',
toKeep = ['boostedDeepTauRunIIv2p0']
)
boostedTauIdEmbedder.runTauID()
addToProcessAndTask(_noUpdatedBoostedTauName, process.slimmedTausBoosted.clone(),process,task)
delattr(process, 'slimmedTausBoosted')
process.slimmedTausBoosted = getattr(process, _updatedBoostedTauName).clone()
process.rerunMvaIsolationTaskBoostedForMini.add(process.slimmedTausBoosted)
task.add(process.rerunMvaIsolationTaskBoostedForMini)
process.load("RecoTauTag.Configuration.RecoPFTauTag_cff")
process.load("RecoTauTag.Configuration.HPSPFTaus_cff")
#-- Adding customization for 94X 2017 legacy reMniAOD
Expand All @@ -326,7 +343,6 @@ def _add_deepFlavour(process):
#-- Adding DeepTauID
_updatedTauName = 'slimmedTausDeepIDs'
_noUpdatedTauName = 'slimmedTausNoDeepIDs'
import RecoTauTag.RecoTau.tools.runTauIdMVA as tauIdConfig
tauIdEmbedder = tauIdConfig.TauIDEmbedder(
process, debug = False,
originalTauName = _noUpdatedTauName,
Expand Down
12 changes: 7 additions & 5 deletions RecoTauTag/RecoTau/interface/DeepTauIdBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ namespace {
};
inline std::vector<int> varsToDrop = {
tau_phi, tau_dxy_pca_x, tau_dxy_pca_y, tau_dxy_pca_z}; // indices of vars to be dropped in the full var enum
} // namespace TauBlockInputs
} // namespace TauBlockInputs

namespace EgammaBlockInputs {
enum vars {
Expand Down Expand Up @@ -1074,7 +1074,7 @@ class DeepTauIdBase : public Producer {

if (sub_version_ == 1) {
scalingParamsMap_ = &sc::scalingParamsMap_v2p1;
} else if (sub_version_ == 5) {
} else if ((sub_version_ == 5) || ((sub_version_ == 0) && (year_ == 20161718))) {
std::sort(TauBlockInputs::varsToDrop.begin(), TauBlockInputs::varsToDrop.end());
for (auto v : TauBlockInputs::varsToDrop) {
tauInputs_indices_.at(v) = TauBlockInputs::NumberOfInputs - TauBlockInputs::varsToDrop.size();
Expand All @@ -1083,6 +1083,8 @@ class DeepTauIdBase : public Producer {
}
if (year_ == 2026) {
scalingParamsMap_ = &sc::scalingParamsMap_PhaseIIv2p5;
} else if ((sub_version_ == 0) && (year_ == 20161718)) {
scalingParamsMap_ = &sc::scalingParamsMap_BoostedRun2_v2p0;
} else {
scalingParamsMap_ = &sc::scalingParamsMap_v2p5;
}
Expand Down Expand Up @@ -1298,7 +1300,7 @@ class DeepTauIdBase : public Producer {
if (sub_version_ == 1)
get(dnn::footprintCorrection) =
sp.scale(tau_funcs.getFootprintCorrectiondR03(tau, tau_ref), tauInputs_indices_[dnn::footprintCorrection]);
else if (sub_version_ == 5) {
else if ((sub_version_ == 5) || ((sub_version_ == 0) && (year_ == 20161718))) {
if (is_online_)
get(dnn::footprintCorrection) =
sp.scale(tau_funcs.getFootprintCorrectiondR03(tau, tau_ref), tauInputs_indices_[dnn::footprintCorrection]);
Expand Down Expand Up @@ -1372,7 +1374,7 @@ class DeepTauIdBase : public Producer {
sp.scale(tau_funcs.getFlightLength(tau, tau_index).z(), tauInputs_indices_[dnn::tau_flightLength_z]);
if (sub_version_ == 1)
get(dnn::tau_flightLength_sig) = 0.55756444; //This value is set due to a bug in the training
else if (sub_version_ == 5)
else if ((sub_version_ == 5) || ((sub_version_ == 0) && (year_ == 20161718)))
get(dnn::tau_flightLength_sig) =
sp.scale(tau_funcs.getFlightLengthSig(tau, tau_index), tauInputs_indices_[dnn::tau_flightLength_sig]);

Expand Down Expand Up @@ -1436,7 +1438,7 @@ class DeepTauIdBase : public Producer {
// to account for swapped order of PfCand_gamma and Electron blocks for v2p5 training w.r.t. v2p1
int fill_index_offset_e = 0;
int fill_index_offset_PFg = 0;
if (sub_version_ == 5) {
if ((sub_version_ == 5) || ((sub_version_ == 0) && (year_ == 20161718))) {
fill_index_offset_e =
scalingParamsMap_->at(std::make_pair(ft_PFg, false)).mean_.size(); // size of PF gamma features
fill_index_offset_PFg =
Expand Down
Loading

0 comments on commit ceae18e

Please sign in to comment.