From b50ff5d88f59e3a5af3f0b0ab5df0220c2994233 Mon Sep 17 00:00:00 2001 From: Oleg Filatov <20295221+ofivite@users.noreply.github.com> Date: Thu, 5 May 2022 18:31:05 +0200 Subject: [PATCH] fix scaling --- RecoTauTag/RecoTau/interface/DeepTauScaling.h | 27 +++++++++---------- RecoTauTag/RecoTau/plugins/DeepTauId.cc | 20 ++++++++++++++ 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/RecoTauTag/RecoTau/interface/DeepTauScaling.h b/RecoTauTag/RecoTau/interface/DeepTauScaling.h index c505d4ac0a521..a43644f790f05 100644 --- a/RecoTauTag/RecoTau/interface/DeepTauScaling.h +++ b/RecoTauTag/RecoTau/interface/DeepTauScaling.h @@ -13,20 +13,19 @@ namespace deep_tau { std::vector lim_min_; std::vector lim_max_; - template - static float getValue(T value) { - return std::isnormal(value) ? static_cast(value) : 0.f; - } - template float scale(T value, int var_index) const{ - const float fixed_value = getValue(value); - const float mean = mean_.at(var_index); - const float std = std_.at(var_index); - const float lim_min = lim_min_.at(var_index); - const float lim_max = lim_max_.at(var_index); - const float norm_value = (fixed_value - mean) / std; - return std::clamp(norm_value, lim_min, lim_max); + if (std::isfinite(value)) + { + const float mean = mean_.at(var_index); + const float std = std_.at(var_index); + const float lim_min = lim_min_.at(var_index); + const float lim_max = lim_max_.at(var_index); + const float norm_value = (static_cast(value) - mean) / std; + return std::clamp(norm_value, lim_min, lim_max); + } + else + return 0.f; }; }; @@ -77,7 +76,7 @@ namespace deep_tau { 5, 5, 5, inf, 5, 5, 5, 5, inf, 1, 1, 5, 1, 5, inf, - 1, inf, 1, 5, -1.0, + 1, inf, 1, 5, 1.0, inf, 5}, } }, // end TauFlat @@ -855,7 +854,7 @@ namespace deep_tau { 1,1,1,1,5.5, 1.123,1.108,6.913,1.229,1.216, 7.147,1,1.578,58.34,6.915, - 515.9,1,2.933,6.317}, + 515.9,2.933,6.317}, // lim_min {-inf,-5,-1.0,-1.0,-inf, diff --git a/RecoTauTag/RecoTau/plugins/DeepTauId.cc b/RecoTauTag/RecoTau/plugins/DeepTauId.cc index b8b99a3122a35..abf61d90d5c33 100644 --- a/RecoTauTag/RecoTau/plugins/DeepTauId.cc +++ b/RecoTauTag/RecoTau/plugins/DeepTauId.cc @@ -1249,6 +1249,26 @@ class DeepTauId : public deep_tau::DeepTauBase { else throw cms::Exception("DeepTauId") << "subversion " << sub_version_ << " is not supported."; + namespace sc = deep_tau::Scaling; + std::map, std::vector> GridFeatureTypes_map = { + {{false}, {sc::FeatureT::TauFlat, sc::FeatureT::GridGlobal} }, // feature types without inner/outer grid split + {{false,true}, {sc::FeatureT::PfCand_electron, sc::FeatureT::PfCand_muon, // feature types with inner/outer grid split + sc::FeatureT::PfCand_chHad, sc::FeatureT::PfCand_nHad, + sc::FeatureT::PfCand_gamma, sc::FeatureT::Electron, sc::FeatureT::Muon} } + }; + + // check that sizes of mean/std/lim_min/lim_max vectors are equal between each other + for (auto p: GridFeatureTypes_map){ + for (auto is_inner: p.first){ + for (auto featureType: p.second) + { + const deep_tau::Scaling::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(featureType, is_inner)); + if (!(sp.mean_.size() == sp.std_.size() && sp.mean_.size() == sp.lim_min_.size() && sp.mean_.size() == sp.lim_max_.size())) + throw cms::Exception("DeepTauId") << "sizes of scaling parameter vectors do not match between each other"; + } + } + } + for (size_t n = 0; n < 2; ++n) { const bool is_inner = n == 0; const auto n_cells =