Skip to content

Commit

Permalink
fix scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
ofivite committed May 8, 2022
1 parent a563b7d commit b50ff5d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
27 changes: 13 additions & 14 deletions RecoTauTag/RecoTau/interface/DeepTauScaling.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,19 @@ namespace deep_tau {
std::vector<float> lim_min_;
std::vector<float> lim_max_;

template <typename T>
static float getValue(T value) {
return std::isnormal(value) ? static_cast<float>(value) : 0.f;
}

template<typename T>
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<float>(value) - mean) / std;
return std::clamp(norm_value, lim_min, lim_max);
}
else
return 0.f;
};
};

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
20 changes: 20 additions & 0 deletions RecoTauTag/RecoTau/plugins/DeepTauId.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>, std::vector<sc::FeatureT>> 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 =
Expand Down

0 comments on commit b50ff5d

Please sign in to comment.