diff --git a/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py b/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py index 217bcdc40e351..e29c2f0e1824e 100644 --- a/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py +++ b/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py @@ -366,7 +366,7 @@ def _add_deepFlavour(process): process.makePatTausTask, _makePatTausTaskWithRetrainedMVATauID ) #-- Adding DeepTauID - # deepTau v2p1 + # deepTau v2p1 and v2p5 _updatedTauName = 'slimmedTausDeepIDsv2p1' _noUpdatedTauName = 'slimmedTausNoDeepIDs' import RecoTauTag.RecoTau.tools.runTauIdMVA as tauIdConfig @@ -374,7 +374,7 @@ def _add_deepFlavour(process): process, debug = False, originalTauName = _noUpdatedTauName, updatedTauName = _updatedTauName, - toKeep = ['deepTau2017v2p1'] + toKeep = ['deepTau2017v2p1','deepTau2018v2p5'] ) from Configuration.Eras.Modifier_phase2_common_cff import phase2_common #Phase2 Tau MVA phase2_common.toModify(tauIdEmbedder.toKeep, func=lambda t:t.append('newDMPhase2v1')) #Phase2 Tau isolation MVA diff --git a/RecoTauTag/RecoTau/interface/DeepTauScaling.h b/RecoTauTag/RecoTau/interface/DeepTauScaling.h new file mode 100644 index 0000000000000..08ef80ec305b1 --- /dev/null +++ b/RecoTauTag/RecoTau/interface/DeepTauScaling.h @@ -0,0 +1,730 @@ +#ifndef RecoTauTag_RecoTau_DeepTauScaling_h +#define RecoTauTag_RecoTau_DeepTauScaling_h + +#include +#include +#include +#include +#include + +namespace deep_tau { + namespace Scaling { + constexpr float inf = std::numeric_limits::infinity(); + enum class FeatureT { + TauFlat, + GridGlobal, + PfCand_electron, + PfCand_muon, + PfCand_chHad, + PfCand_nHad, + PfCand_gamma, + Electron, + Muon + }; + + struct ScalingParams { + std::vector mean_; + std::vector std_; + std::vector lim_min_; + std::vector lim_max_; + + template + float scale(T value, int var_index) const { + 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; + }; + }; + + const std::map, ScalingParams> scalingParamsMap_v2p1 = { + {std::make_pair(FeatureT::TauFlat, false), + { + // mean_ + {21.49, 20.0, 0.0, 0., 0.6669, 1., 0, 1, 0, 47.78, 0, 9.029, + 57.59, 0, 0, 0, 1.731, 22.38, -0.0241, 0.0675, 0.7973, 0, 0.0018, 2.26, + 0, 0.0026, 2.928, 0., 0, 4.717, -0.0003, -0.0009, -0.0022, 0., 0., 0., + 0.0052, 0., 1.538, 0, 0., 0, 0., 2.95, 0.0, 0, 0.0042}, + + // std_ + {9.713, + 980.0, + 2.3, + 3.141592653589793, + 0.6553, + 4.2, + 1, + 2, + 2, + 123.5, + 1, + 26.42, + 155.3, + 1, + 1, + 1, + 6.846, + 16.34, + 0.0074, + 0.0128, + 3.456, + 1, + 0.0085, + 4.191, + 1, + 0.0114, + 4.466, + 0.0190, + 1, + 11.78, + 0.7362, + 0.7354, + 1.993, + 1, + 1., + 1, + 0.01433, + 1., + 4.401, + 1, + 1, + 1, + 3.141592653589793, + 3.927, + 1., + 1.0, + 0.0323}, + + // lim_min_ + {-5, 0., -1.0, -1., -5, 0, -inf, 0, 0, -5, -inf, -5, -5, -inf, -inf, -inf, + -5, -5, -5, -5, -5, -inf, -5, -5, -inf, -5, -5, -5, -inf, -5, -5, -5, + -5, -inf, 0, 0, -5, 0, -5, -inf, 0, -inf, 0, -5, -1.0, -inf, -5}, + + // lim_max_ + {5, 1., 1.0, 1., 5, 1, inf, 1, 1, 5, inf, 5, 5, inf, inf, inf, 5, 5, 5, 5, 5, inf, 5, 5, + inf, 5, 5, 5, inf, 5, 5, 5, 5, inf, 1, 1, 5, 1, 5, inf, 1, inf, 1, 5, 1.0, inf, 5}, + }}, // end TauFlat + + {std::make_pair(FeatureT::GridGlobal, false), + { + // mean_ + {21.49, 20.0, 0.0, 0}, + // std_ + {9.713, 980.0, 2.3, 1}, + // lim_min_ + {-5, 0., -1.0, -inf}, + // lim_max_ + {5., 1., 1.0, inf}, + }}, // end GridGlobal + + {std::make_pair(FeatureT::PfCand_electron, false), + {// mean_ + {0, 0.304, 0.0, 0.0, 0, 0, 0, 0, 0, 0, 0, 0.001, 0, 0.0003, 0, 0, 0., 1.634, 0.001, 24.56, 2.272, 15.18}, + + // std_ + {1, 1.845, 0.5, 0.5, 7., 1, 1, 1, 10.0, 0.1221, 0.1226, + 1.024, 0.3411, 0.3385, 1.307, 1, 0.171, 6.45, 1.02, 210.4, 8.439, 3.203}, + + // lim_min_ + {-inf, -5, -1.0, -1.0, 0., -inf, -inf, -inf, 0., -5, -5, -5, -5, -5, -5, -inf, -5, -5, -5, -5, -5, -5}, + + // lim_max_ + {inf, 5, 1.0, 1.0, 1., inf, inf, inf, 1., 5, 5, + 5, 5, 5, 5, inf, 5, 5, 5, 5, 5, 5}}}, // end PfCand_electron, is_innner=false + + {std::make_pair(FeatureT::PfCand_electron, true), + {// mean_ + {0, 0.9792, 0.0, 0.0, 0, 0, 0, 0, 0, 0, 0, 0.001, 0, 0.0003, 0, 0, 0., 1.634, 0.001, 24.56, 2.272, 15.18}, + + // std_ + {1, 0.5383, 0.1, 0.1, 7., 1, 1, 1, 10.0, 0.1221, 0.1226, + 1.024, 0.3411, 0.3385, 1.307, 1, 0.171, 6.45, 1.02, 210.4, 8.439, 3.203}, + + // lim_min_ + {-inf, -5, -1.0, -1.0, 0., -inf, -inf, -inf, 0., -5, -5, -5, -5, -5, -5, -inf, -5, -5, -5, -5, -5, -5}, + + // lim_max_ + {inf, 5, 1.0, 1.0, 1., inf, inf, inf, 1., 5, 5, + 5, 5, 5, 5, inf, 5, 5, 5, 5, 5, 5}}}, // end PfCand_electron, is_innner=true + + {std::make_pair(FeatureT::PfCand_gamma, false), + { + // mean + {0, 0.02576, 0.0, 0.0, 0, 0, 0, 0, 0, 0., 0., 0., + 0., 0.001, 0.0008, 0.0038, 0, 0.0004, 4.271, 0.0071, 162.1, 4.268, 12.25}, + + // std + {1, 0.3833, 0.5, 0.5, 7., 3., 1, 1, 1, 7., 0.0067, 0.0069, + 0.0578, 0.9565, 0.9592, 2.154, 1, 0.882, 63.78, 5.285, 622.4, 15.47, 4.774}, + + // lim_min + {-inf, -5, -1.0, -1.0, 0., 0., -inf, -inf, -inf, 0., -5, -5, -5, -5, -5, -5, -inf, -5, -5, -5, -5, -5, -5}, + + // lim_max + {inf, 5, 1.0, 1.0, 1., 1., inf, inf, inf, 1., 5, 5, 5, 5, 5, 5, inf, 5, 5, 5, 5, 5, 5}, + + }}, // end PfCand_gamma, is_innner=false + + {std::make_pair(FeatureT::PfCand_gamma, true), + { + // mean + {0, 0.6048, 0.0, 0.0, 0, 0, 0, 0, 0, 0., 0., 0., + 0., 0.001, 0.0008, 0.0038, 0, 0.0004, 4.271, 0.0071, 162.1, 4.268, 12.25}, + + // std + {1, 1.669, 0.1, 0.1, 7., 3., 1, 1, 1, 7., 0.0067, 0.0069, + 0.0578, 0.9565, 0.9592, 2.154, 1, 0.882, 63.78, 5.285, 622.4, 15.47, 4.774}, + + // lim_min + {-inf, -5, -1.0, -1.0, 0., 0., -inf, -inf, -inf, 0., -5, -5, -5, -5, -5, -5, -inf, -5, -5, -5, -5, -5, -5}, + + // lim_max + {inf, 5, 1.0, 1.0, 1., 1., inf, inf, inf, 1., 5, 5, 5, 5, 5, 5, inf, 5, 5, 5, 5, 5, 5}, + + }}, // end PfCand_gamma, is_innner=true + + {std::make_pair(FeatureT::Electron, false), + { + // mean + {0, 0.5111, 0.0, 0.0, 0, 1.729, 0.1439, 1.794, 1.531, 1.531, 0.7735, 0.7735, 1.625, + 1.993, 70.25, 2.432, 2.034, 6.64, 4.183, 0., -0.0001, -0.0001, 0.0002, 0.0001, 0.0004, 0, + 0, 0.0008, 14.04, 0.0099, 3.049, 16.52, 1.355, 5.046, 0, 2.411, 15.16}, + + // std + {1, 2.765, 0.5, 0.5, 1, 1.644, 0.3284, 2.079, 1.424, 1.424, 0.935, 0.935, 1.581, + 1.308, 58.16, 15.13, 13.96, 36.8, 20.63, 0.0363, 0.0512, 0.0541, 0.0553, 0.0523, 0.0777, 1, + 1, 0.0052, 69.48, 0.0851, 10.39, 2.806, 16.81, 3.119, 1, 6.98, 5.26}, + + // lim_min + {-inf, -5, -1.0, -1.0, -inf, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, + -5, -5, -5, -5, -5, -5, -inf, -inf, -5, -5, -5, -5, -5, -5, -5, -inf, -5, -5}, + + // lim_max + {inf, 5, 1.0, 1.0, inf, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, inf, inf, 5, 5, 5, 5, 5, 5, 5, inf, 5, 5}, + }}, // end Electron, is_innner=false + + {std::make_pair(FeatureT::Electron, true), + { + // mean + {0, 1.067, 0.0, 0.0, 0, 1.729, 0.1439, 1.794, 1.531, 1.531, 0.7735, 0.7735, 1.625, + 1.993, 70.25, 2.432, 2.034, 6.64, 4.183, 0., -0.0001, -0.0001, 0.0002, 0.0001, 0.0004, 0, + 0, 0.0008, 14.04, 0.0099, 3.049, 16.52, 1.355, 5.046, 0, 2.411, 15.16}, + + // std + {1, 1.521, 0.1, 0.1, 1, 1.644, 0.3284, 2.079, 1.424, 1.424, 0.935, 0.935, 1.581, + 1.308, 58.16, 15.13, 13.96, 36.8, 20.63, 0.0363, 0.0512, 0.0541, 0.0553, 0.0523, 0.0777, 1, + 1, 0.0052, 69.48, 0.0851, 10.39, 2.806, 16.81, 3.119, 1, 6.98, 5.26}, + + // lim_min + {-inf, -5, -1.0, -1.0, -inf, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, + -5, -5, -5, -5, -5, -5, -inf, -inf, -5, -5, -5, -5, -5, -5, -5, -inf, -5, -5}, + + // lim_max + {inf, 5, 1.0, 1.0, inf, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, inf, inf, 5, 5, 5, 5, 5, 5, 5, inf, 5, 5}, + }}, // end Electron, is_innner=true + + {std::make_pair(FeatureT::PfCand_muon, false), + { + // mean + {0, 0.0861, 0.0, 0.0, 0, 0, 0, 0, 0, 0., -0.0007, 0.0001, + -0.0117, -0.0001, 0.0004, -0.0118, 0, -0.0045, 4.575, -0.0117, 80.37, 0.69, 17.5}, + + // std + {1, 0.4065, 0.5, 0.5, 7., 3., 1., 1., 1., 11., 0.6869, 0.6784, + 4.097, 0.8642, 0.8561, 4.405, 1, 0.9655, 42.36, 4.097, 343.3, 1.711, 5.11}, + + // lim_min + {-inf, -5, -1.0, -1.0, 0., 0., -inf, -inf, -inf, 0., -5, -5, -5, -5, -5, -5, -inf, -5, -5, -5, -5, -5, -5}, + + // lim_max + {inf, 5, 1.0, 1.0, 1., 1., inf, inf, inf, 1.0, 5, 5, 5, 5, 5, 5, inf, 5, 5, 5, 5, 5, 5}, + + }}, // end PfCand_muon, is_innner=false + + {std::make_pair(FeatureT::PfCand_muon, true), + { + // mean + {0, 0.9509, 0.0, 0.0, 0, 0, 0, 0, 0, 0., -0.0007, 0.0001, + -0.0117, -0.0001, 0.0004, -0.0118, 0, -0.0045, 4.575, -0.0117, 80.37, 0.69, 17.5}, + + // std + {1, 0.4294, 0.1, 0.1, 7., 3., 1., 1., 1., 11., 0.6869, 0.6784, + 4.097, 0.8642, 0.8561, 4.405, 1, 0.9655, 42.36, 4.097, 343.3, 1.711, 5.11}, + + // lim_min + {-inf, -5, -1.0, -1.0, 0., 0., -inf, -inf, -inf, 0., -5, -5, -5, -5, -5, -5, -inf, -5, -5, -5, -5, -5, -5}, + + // lim_max + {inf, 5, 1.0, 1.0, 1., 1., inf, inf, inf, 1.0, 5, 5, 5, 5, 5, 5, inf, 5, 5, 5, 5, 5, 5}, + + }}, // end PfCand_muon, is_innner=true + + {std::make_pair(FeatureT::Muon, false), + { + // mean + {0, 0.2678, 0.0, 0.0, 0.0019, 8.98, 0, 21.52, 21.84, 0, 0, 0, 0.2273, 0., 0., 0., 0., 0., 0., + 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.}, + + // std + {1, 3.592, 0.5, 0.5, 1.039, 71.17, 1, 265.8, 10.59, 1, 1, 1, 0.4865, + 2.0, 2.0, 2.0, 2.0, 6.0, 2.0, 2.0, 2.0, 7., 6.0, 4.0, 4.0, 12.0, + 12.0, 12.0, 8.0, 24.0, 12.0, 12.0, 12.0, 4.0, 4.0, 2.0, 2.0}, + + // lim_min + {-inf, -5, -1.0, -1.0, -5, -5, -inf, -5, -5, -inf, -inf, -inf, -5, 0., 0., 0., 0., 0., 0., + 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.}, + + // lim_max + {inf, 5, 1.0, 1.0, 5, 5, inf, 5, 5, inf, inf, inf, 5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}, + + }}, // end Muon, is_innner=false + + {std::make_pair(FeatureT::Muon, true), + { + // mean + {0, 0.7966, 0.0, 0.0, 0.0019, 8.98, 0, 21.52, 21.84, 0, 0, 0, 0.2273, 0., 0., 0., 0., 0., 0., + 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.}, + + // std + {1, 3.402, 0.1, 0.1, 1.039, 71.17, 1, 265.8, 10.59, 1, 1, 1, 0.4865, + 2.0, 2.0, 2.0, 2.0, 6.0, 2.0, 2.0, 2.0, 7., 6.0, 4.0, 4.0, 12.0, + 12.0, 12.0, 8.0, 24.0, 12.0, 12.0, 12.0, 4.0, 4.0, 2.0, 2.0}, + + // lim_min + {-inf, -5, -1.0, -1.0, -5, -5, -inf, -5, -5, -inf, -inf, -inf, -5, 0., 0., 0., 0., 0., 0., + 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.}, + + // lim_max + {inf, 5, 1.0, 1.0, 5, 5, inf, 5, 5, inf, inf, inf, 5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}, + + }}, // end Muon, is_innner=true + + {std::make_pair(FeatureT::PfCand_chHad, false), + { + // mean + {0, 0.0194, 0.0, 0.0, 0, 0, 0, 0, 0, 0, 0, 0., 0.0005, -0.0008, + -0.0201, -0.0014, 0.0022, -0.0138, 0, -0.012, 6.417, -0.0246, 301.3, 0.7876, 13.92, 0, 0.}, + + // std + {1, 0.1865, 0.5, 0.5, 1, 7, 3, 1, 1, 1, 1, 12.0, 1.735, 1.752, + 8.333, 1.93, 1.948, 8.622, 1, 2.386, 36.28, 7.618, 491.1, 3.694, 6.581, 1, 2.6}, + + // lim_min + {-inf, -5, -1.0, -1.0, -inf, 0., 0., -inf, -inf, -inf, -inf, 0., -5, -5, + -5, -5, -5, -5, -inf, -5, -5, -5, -5, -5, -5, -inf, 0.}, + + // lim_max + {inf, 5, 1.0, 1.0, inf, 1., 1., inf, inf, inf, inf, 1.0, 5, 5, + 5, 5, 5, 5, inf, 5, 5, 5, 5, 5, 5, inf, 1.0}, + }}, // end PfCand_chHad, is_innner=false + + {std::make_pair(FeatureT::PfCand_chHad, true), + { + // mean + {0, 0.2564, 0.0, 0.0, 0, 0, 0, 0, 0, 0, 0, 0., 0.0005, -0.0008, + -0.0201, -0.0014, 0.0022, -0.0138, 0, -0.012, 6.417, -0.0246, 301.3, 0.7876, 13.92, 0, 0.}, + + // std + {1, 0.8607, 0.1, 0.1, 1, 7, 3, 1, 1, 1, 1, 12.0, 1.735, 1.752, + 8.333, 1.93, 1.948, 8.622, 1, 2.386, 36.28, 7.618, 491.1, 3.694, 6.581, 1, 2.6}, + + // lim_min + {-inf, -5, -1.0, -1.0, -inf, 0., 0., -inf, -inf, -inf, -inf, 0., -5, -5, + -5, -5, -5, -5, -inf, -5, -5, -5, -5, -5, -5, -inf, 0.}, + + // lim_max + {inf, 5, 1.0, 1.0, inf, 1., 1., inf, inf, inf, inf, 1.0, 5, 5, + 5, 5, 5, 5, inf, 5, 5, 5, 5, 5, 5, inf, 1.0}, + }}, // end PfCand_chHad, is_innner=true + + {std::make_pair(FeatureT::PfCand_nHad, false), + { + // mean + {0, 0.0502, 0.0, 0.0, 0, 0, 0}, + + // std + {1, 0.4266, 0.5, 0.5, 1, 1, 1}, + + // lim_min + {-inf, -5, -1.0, -1.0, -inf, -inf, -inf}, + + // lim_max + {inf, 5, 1.0, 1.0, inf, inf, inf}, + + }}, // end PfCand_nHad, is_innner=false + + {std::make_pair(FeatureT::PfCand_nHad, true), + { + // mean + {0, 0.3163, 0.0, 0.0, 0, 0, 0}, + + // std + {1, 0.2769, 0.1, 0.1, 1, 1, 1}, + + // lim_min + {-inf, -5, -1.0, -1.0, -inf, -inf, -inf}, + + // lim_max + {inf, 5, 1.0, 1.0, inf, inf, inf}, + + }}, // end PfCand_nHad, is_innner=true + + }; // end scalingParamsMap_v2p1 + + const std::map, ScalingParams> scalingParamsMap_v2p5 = { + {std::make_pair(FeatureT::TauFlat, false), + { + // mean_ + {25.0, 510.0, 0.0, + 0.5762, 1.967, 0, + 1, 0, 14.32, + 0, 2.213, 11.36, + 0, 0, 0, + 1.202, 22.17, 0, + 0.002281, 2.392, 0, + 0.00318, 2.991, 3.212e-05, + 0, 16.75, -0.0008515, + -0.0001629, -0.0007875, -5.564, + 0.5, 0.5, 0.007766, + 0.5, 1.672, 0, + 0.5, 0, 1.5707963267948966, + 2.256, 0.0, 0, + 0.0002029}, + + // std_ + {25.0, 490.0, 2.3, + 0.5293, 1.133, 1, + 1, 1, 44.8, + 1, 6.783, 48.09, + 1, 1, 1, + 3.739, 13.68, 1, + 0.009705, 4.187, 1, + 0.01452, 4.527, 0.4518, + 1, 191.7, 0.4016, + 0.4041, 1.157, 8.72, + 0.5, 0.5, 0.01834, + 0.5, 5.058, 1, + 0.5, 1, 1.5707963267948966, + 2.943, 1.0, 1, + 0.03612}, + + // lim_min_ + {-1.0, -1.0, -1.0, -5, -5, -inf, -inf, -inf, -5, -inf, -5, -5, -inf, -inf, -inf, + -5, -5, -inf, -5, -5, -inf, -5, -5, -5, -inf, -5, -5, -5, -5, -5, + -1.0, -1.0, -5, -1.0, -5, -inf, -1.0, -inf, -1.0, -5, -1.0, -inf, -5}, + + // lim_max_ + {1.0, 1.0, 1.0, 5, 5, inf, inf, inf, 5, inf, 5, 5, inf, inf, inf, 5, 5, inf, 5, 5, inf, 5, + 5, 5, inf, 5, 5, 5, 5, 5, 1.0, 1.0, 5, 1.0, 5, inf, 1.0, inf, 1.0, 5, 1.0, inf, 5}, + }}, // end TauFlat + + {std::make_pair(FeatureT::GridGlobal, false), + { + // mean_ + { + 25.0, + 510.0, + 0.0, + 0, + }, + // std_ + { + 25.0, + 490.0, + 2.3, + 1, + }, + // lim_min_ + {-1.0, -1.0, -1.0, -inf}, + // lim_max_ + {1.0, 1.0, 1.0, inf}, + }}, // end GridGlobal + + {std::make_pair(FeatureT::PfCand_electron, false), + {// mean_ + {0, 0.3457, 0.0, 0.0, 0, 0, 0, 0, 5.0, -0.0008022, -2.653e-05, + 0.00382, 0.002371, 0.0003833, 0.0004431, 0, 0.000397, 3.409, 0.003507, 169.6, 4.561, 12.6}, + + // std_ + {1, 1.164, 0.5, 0.5, 1, 1, 1, 1, 5.0, 0.4081, 0.4056, + 3.329, 0.6623, 0.6648, 3.548, 1, 0.5572, 16.07, 3.3, 486.1, 14.8, 3.729}, + + // lim_min_ + {-inf, -5, -1.0, -1.0, -inf, -inf, -inf, -inf, -1.0, -5, -5, -5, -5, -5, -5, -inf, -5, -5, -5, -5, -5, -5}, + + // lim_max_ + {inf, 5, 1.0, 1.0, inf, inf, inf, inf, 1.0, 5, 5, + 5, 5, 5, 5, inf, 5, 5, 5, 5, 5, 5}}}, // end PfCand_electron, is_inner=false + + {std::make_pair(FeatureT::PfCand_electron, true), + {// mean_ + {0, 0.9558, 0.0, 0.0, 0, 0, 0, 0, 5.0, -2.888e-06, 7.215e-06, + 0.0002156, 0.0002385, 6.221e-05, 0.0003546, 0, 3.333e-05, 1.412, 0.0002181, 21.72, 2.387, 14.73}, + + // std_ + {1, 0.2323, 0.1, 0.1, 1, 1, 1, 1, 5.0, 0.03703, 0.03682, + 0.5552, 0.1855, 0.1867, 0.749, 1, 0.05183, 3.111, 0.5551, 230.5, 8.818, 3.125}, + + // lim_min_ + {-inf, -5, -1.0, -1.0, -inf, -inf, -inf, -inf, -1.0, -5, -5, -5, -5, -5, -5, -inf, -5, -5, -5, -5, -5, -5}, + + // lim_max_ + {inf, 5, 1.0, 1.0, inf, inf, inf, inf, 1.0, 5, 5, + 5, 5, 5, 5, inf, 5, 5, 5, 5, 5, 5}}}, // end PfCand_electron, is_inner=true + + {std::make_pair(FeatureT::PfCand_gamma, false), + { + // mean + {0, 0.02024, 0.0, 0.0, 0, 0, 0, 0, 0, 3.5, 2.364e-08, -1.355e-07, + 5.947e-07, 0.001155, -3.88e-05, 0.001081, 0, 0.003532, 4.09, 0.02207, 175.0, 4.798, 12.18}, + + // std + {1, 0.1801, 0.5, 0.5, 1, 1, 1, 1, 1, 3.5, 0.003674, 0.00371, + 0.02345, 0.4628, 0.4667, 1.057, 1, 1.006, 11.45, 4.517, 546.1, 16.85, 4.741}, + + // lim_min + {-inf, -5, -1.0, -1.0, -inf, -inf, -inf, -inf, -inf, -1.0, -5, -5, + -5, -5, -5, -5, -inf, -5, -5, -5, -5, -5, -5}, + + // lim_max + {inf, 5, 1.0, 1.0, inf, inf, inf, inf, inf, 1.0, 5, 5, 5, 5, 5, 5, inf, 5, 5, 5, 5, 5, 5}, + + }}, // end PfCand_gamma, is_inner=false + + {std::make_pair(FeatureT::PfCand_gamma, true), + { + // mean + {0, 0.2681, 0.0, 0.0, 0, 0, 0, 0, + 0, 3.5, -6.701e-06, 4.799e-06, 3.08e-05, 0.0009319, -0.0001133, 0.0007838, + 0, -0.0003009, 3.826, 0.01115, 114.2, 4.218, 12.27}, + + // std + {1, 0.5467, 0.1, 0.1, 1, 1, 1, 1, 1, 3.5, 0.02348, 0.02357, + 0.2203, 0.4899, 0.4941, 1.284, 1, 0.633, 20.83, 4.191, 439.3, 15.84, 4.562}, + + // lim_min + {-inf, -5, -1.0, -1.0, -inf, -inf, -inf, -inf, -inf, -1.0, -5, -5, + -5, -5, -5, -5, -inf, -5, -5, -5, -5, -5, -5}, + + // lim_max + {inf, 5, 1.0, 1.0, inf, inf, inf, inf, inf, 1.0, 5, 5, 5, 5, 5, 5, inf, 5, 5, 5, 5, 5, 5}, + + }}, // end PfCand_gamma, is_inner=true + + {std::make_pair(FeatureT::Electron, false), + { + // mean + {0, 0.3827, 0.0, 0.0, 0, 1.37, 0.3215, 1.793, 1.093, 1.093, + 1.013, 1.013, 1.063, 1.445, 13.07, 3.797, 2.624, 5.68, 2.231, -0.0001921, + -0.0009969, -0.0008593, -0.0008999, -0.001147, -0.001182, 0, 0, 0.001218, 31.5, 0.05644, + 6.344, 14.65, 1.917, 6.866, 0, 1.862, 12.15}, + + // std + {1, 1.272, 0.5, 0.5, 1, 8.381, 0.5275, 2.419, 82.69, 82.69, 673.8, 673.8, 5.614, + 2.021, 27.8, 21.65, 19.0, 41.93, 21.58, 0.1324, 0.1474, 0.1548, 0.1514, 0.1452, 0.1966, 1, + 1, 0.00775, 82.72, 0.2343, 292.7, 3.103, 229.2, 5.051, 1, 5.64, 5.557}, + + // lim_min + {-inf, -5, -1.0, -1.0, -inf, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, + -5, -5, -5, -5, -5, -5, -inf, -inf, -5, -5, -5, -5, -5, -5, -5, -inf, -5, -5}, + + // lim_max + {inf, 5, 1.0, 1.0, inf, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, inf, inf, 5, 5, 5, 5, 5, 5, 5, inf, 5, 5}, + }}, // end Electron, is_inner=false + + {std::make_pair(FeatureT::Electron, true), + { + // mean + {0, 0.9372, 0.0, 0.0, 0, 1.654, 0.1878, 2.055, 2.593, 2.593, + 1.006, 1.006, 1.749, 2.0, 59.55, 1.748, 1.404, 5.054, 3.078, -4.413e-06, + -1.477e-05, 9.209e-07, 0.0001262, 8.781e-05, 0.0003861, 0, 0, 0.000632, 15.88, 0.005635, + 3.163, 16.15, 1.669, 5.276, 0, 2.813, 14.46}, + + // std + {1, 0.4817, 0.1, 0.1, 1, 1.104, 0.3595, 2.141, 1183.0, 1183.0, 233.5, 233.5, 88.75, + 1.278, 44.9, 2.591, 2.199, 14.8, 10.23, 0.0119, 0.02151, 0.02331, 0.03042, 0.03347, 0.05816, 1, + 1, 0.004139, 50.36, 0.05148, 15.01, 2.752, 431.6, 2.463, 1, 8.186, 5.149}, + + // lim_min + {-inf, -5, -1.0, -1.0, -inf, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, + -5, -5, -5, -5, -5, -5, -inf, -inf, -5, -5, -5, -5, -5, -5, -5, -inf, -5, -5}, + + // lim_max + {inf, 5, 1.0, 1.0, inf, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, inf, inf, 5, 5, 5, 5, 5, 5, 5, inf, 5, 5}, + }}, // end Electron, is_inner=true + + {std::make_pair(FeatureT::PfCand_muon, false), + { + // mean + {0, 0.142, 0.0, 0.0, 0, 0, 0, 0, + 0, 5.5, -9.307e-05, -0.0008956, -0.01717, 0.001419, -0.0001845, -0.01638, + 0, -0.008642, 10.87, -0.01718, 296.6, 0.7838, 17.99}, + + // std + {1, 0.618, 0.5, 0.5, 1, 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, 2.933, 6.317}, + + // lim_min + {-inf, -5, -1.0, -1.0, -inf, -inf, -inf, -inf, -inf, -1.0, -5, -5, + -5, -5, -5, -5, -inf, -5, -5, -5, -5, -5, -5}, + + // lim_max + {inf, 5, 1.0, 1.0, inf, inf, inf, inf, inf, 1.0, 5, 5, 5, 5, 5, 5, inf, 5, 5, 5, 5, 5, 5}, + + }}, // end PfCand_muon, is_inner=false + + {std::make_pair(FeatureT::PfCand_muon, true), + { + // mean + {0, 0.9561, 0.0, 0.0, 0, 0, 0, 0, + 0, 5.5, -9.493e-06, 2.109e-06, -0.005042, 0.0001233, -1.605e-06, -0.004842, + 0, -2.842e-05, 1.391, -0.005043, 10.48, 0.5868, 17.11}, + + // std + {1, 0.1959, 0.1, 0.1, 1, 1, 1, 1, 1, 5.5, 0.0752, 0.07712, + 0.8103, 0.2137, 0.2138, 0.9617, 1, 0.1077, 7.796, 0.8103, 155.9, 1.003, 4.29}, + + // lim_min + {-inf, -5, -1.0, -1.0, -inf, -inf, -inf, -inf, -inf, -1.0, -5, -5, + -5, -5, -5, -5, -inf, -5, -5, -5, -5, -5, -5}, + + // lim_max + {inf, 5, 1.0, 1.0, inf, inf, inf, inf, inf, 1.0, 5, 5, 5, 5, 5, 5, inf, 5, 5, 5, 5, 5, 5}, + + }}, // end PfCand_muon, is_inner=true + + {std::make_pair(FeatureT::Muon, false), + { + // mean + {0, 0.3645, 0.0, 0.0, 0.00344, 17.54, 0, 24.78, 17.92, 0, 0, 0, 0.3221, + 1.0, 1.0, 1.0, 1.0, 3.0, 1.0, 1.0, 1.0, 3.5, 3.0, 2.0, 2.0, 6.0, + 6.0, 6.0, 4.0, 12.0, 6.0, 6.0, 6.0, 2.0, 2.0, 1.0, 1.0}, + + // std + {1, 85.0, 0.5, 0.5, 1.557, 97.45, 1, 2022.0, 6.573, 1, 1, 1, 0.6166, + 1.0, 1.0, 1.0, 1.0, 3.0, 1.0, 1.0, 1.0, 3.5, 3.0, 2.0, 2.0, 6.0, + 6.0, 6.0, 4.0, 12.0, 6.0, 6.0, 6.0, 2.0, 2.0, 1.0, 1.0}, + + // lim_min + {-inf, -5, -1.0, -1.0, -5, -5, -inf, -5, -5, -inf, -inf, -inf, -5, + -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, + -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}, + + // lim_max + {inf, 5, 1.0, 1.0, 5, 5, inf, 5, 5, inf, inf, inf, 5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}, + + }}, // end Muon, is_inner=false + + {std::make_pair(FeatureT::Muon, true), + { + // mean + {0, 1.033, 0.0, 0.0, 0.001217, 5.403, 0, 7.2, 18.58, 0, 0, 0, 0.09762, + 1.0, 1.0, 1.0, 1.0, 3.0, 1.0, 1.0, 1.0, 3.5, 3.0, 2.0, 2.0, 6.0, + 6.0, 6.0, 4.0, 12.0, 6.0, 6.0, 6.0, 2.0, 2.0, 1.0, 1.0}, + + // std + {1, 65.51, 0.1, 0.1, 0.2033, 36.07, 1, 263.3, 5.019, 1, 1, 1, 0.3956, + 1.0, 1.0, 1.0, 1.0, 3.0, 1.0, 1.0, 1.0, 3.5, 3.0, 2.0, 2.0, 6.0, + 6.0, 6.0, 4.0, 12.0, 6.0, 6.0, 6.0, 2.0, 2.0, 1.0, 1.0}, + + // lim_min + {-inf, -5, -1.0, -1.0, -5, -5, -inf, -5, -5, -inf, -inf, -inf, -5, + -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, + -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}, + + // lim_max + {inf, 5, 1.0, 1.0, 5, 5, inf, 5, 5, inf, inf, inf, 5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}, + + }}, // end Muon, is_inner=true + + {std::make_pair(FeatureT::PfCand_chHad, false), + { + // mean + {0, 0.02191, 0.0, 0.0, 0, 0, 0, 0, 0, + 0, 0, 6.0, 0.00106, -0.001523, -0.008181, 0.004498, 4.287e-06, -0.007022, + 0, -0.01495, 6.04, -0.01381, 323.5, 0.753, 13.6, 0, 1.3}, + + // std + {1, 0.08964, 0.5, 0.5, 1, 1, 1, 1, 1, 1, 1, 6.0, 1.732, 1.741, + 8.372, 1.783, 1.792, 8.447, 1, 2.481, 33.16, 8.026, 443.9, 3.439, 6.624, 1, 1.3}, + + // lim_min + {-inf, -5, -1.0, -1.0, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -1.0, -5, -5, + -5, -5, -5, -5, -inf, -5, -5, -5, -5, -5, -5, -inf, -1.0}, + + // lim_max + {inf, 5, 1.0, 1.0, inf, inf, inf, inf, inf, inf, inf, 1.0, 5, 5, + 5, 5, 5, 5, inf, 5, 5, 5, 5, 5, 5, inf, 1.0}, + }}, // end PfCand_chHad, is_inner=false + + {std::make_pair(FeatureT::PfCand_chHad, true), + { + // mean + {0, 0.2482, 0.0, 0.0, 0, 0, 0, 0, 0, + 0, 0, 6.0, 0.0003524, -0.0003693, -0.002133, 0.003532, 0.000612, -0.0003197, + 0, -0.001701, 4.04, -0.002282, 61.12, 0.9004, 14.73, 0, 1.3}, + + // std + {1, 0.3601, 0.1, 0.1, 1, 1, 1, 1, 1, 1, 1, 6.0, 0.8533, 0.8569, + 4.132, 1.033, 1.039, 4.436, 1, 1.001, 16.62, 3.254, 244.4, 4.37, 5.599, 1, 1.3}, + + // lim_min + {-inf, -5, -1.0, -1.0, -inf, -inf, -inf, -inf, -inf, -inf, -inf, -1.0, -5, -5, + -5, -5, -5, -5, -inf, -5, -5, -5, -5, -5, -5, -inf, -1.0}, + + // lim_max + {inf, 5, 1.0, 1.0, inf, inf, inf, inf, inf, inf, inf, 1.0, 5, 5, + 5, 5, 5, 5, inf, 5, 5, 5, 5, 5, 5, inf, 1.0}, + }}, // end PfCand_chHad, is_inner=true + + {std::make_pair(FeatureT::PfCand_nHad, false), + { + // mean + {0, 0.05398, 0.0, 0.0, 0, 0, 0}, + + // std + {1, 0.2929, 0.5, 0.5, 1, 1, 1}, + + // lim_min + {-inf, -5, -1.0, -1.0, -inf, -inf, -inf}, + + // lim_max + {inf, 5, 1.0, 1.0, inf, inf, inf}, + + }}, // end PfCand_nHad, is_inner=false + + {std::make_pair(FeatureT::PfCand_nHad, true), + { + // mean + {0, 0.2553, 0.0, 0.0, 0, 0, 0}, + + // std + {1, 0.2687, 0.1, 0.1, 1, 1, 1}, + + // lim_min + {-inf, -5, -1.0, -1.0, -inf, -inf, -inf}, + + // lim_max + {inf, 5, 1.0, 1.0, inf, inf, inf}, + + }}, // end PfCand_nHad, is_inner=true + + }; // end scalingParamsMap_v2p5 + + }; // namespace Scaling +}; // namespace deep_tau + +#endif diff --git a/RecoTauTag/RecoTau/plugins/DPFIsolation.cc b/RecoTauTag/RecoTau/plugins/DPFIsolation.cc index 256be8a1ecded..517767af3a31a 100644 --- a/RecoTauTag/RecoTau/plugins/DPFIsolation.cc +++ b/RecoTauTag/RecoTau/plugins/DPFIsolation.cc @@ -9,7 +9,7 @@ #include "RecoTauTag/RecoTau/interface/DeepTauBase.h" namespace { - inline int getPFCandidateIndex(const edm::Handle& pfcands, + inline int getPFCandidateIndex(const edm::Handle>& pfcands, const reco::CandidatePtr& cptr) { for (unsigned int i = 0; i < pfcands->size(); ++i) { if (reco::CandidatePtr(pfcands, i) == cptr) @@ -42,21 +42,22 @@ class DPFIsolation : public deep_tau::DeepTauBase { desc.add("pfcands", edm::InputTag("packedPFCandidates")); desc.add("taus", edm::InputTag("slimmedTaus")); desc.add("vertices", edm::InputTag("offlineSlimmedPrimaryVertices")); - desc.add("graph_file", "RecoTauTag/TrainingFiles/data/DPFTauId/DPFIsolation_2017v0_quantized.pb"); + desc.add>("graph_file", + {"RecoTauTag/TrainingFiles/data/DPFTauId/DPFIsolation_2017v0_quantized.pb"}); desc.add("version", 0); desc.add("mem_mapped", false); - - edm::ParameterSetDescription descWP; - descWP.add("VVVLoose", "0"); - descWP.add("VVLoose", "0"); - descWP.add("VLoose", "0"); - descWP.add("Loose", "0"); - descWP.add("Medium", "0"); - descWP.add("Tight", "0"); - descWP.add("VTight", "0"); - descWP.add("VVTight", "0"); - descWP.add("VVVTight", "0"); - desc.add("VSallWP", descWP); + desc.add("is_online", false); + + //pre-discriminants + edm::ParameterSetDescription pset_Prediscriminants; + pset_Prediscriminants.add("BooleanOperator", "and"); + edm::ParameterSetDescription psd1; + psd1.add("cut"); + psd1.add("Producer"); + pset_Prediscriminants.addOptional("decayMode", psd1); + desc.add("Prediscriminants", pset_Prediscriminants); + + desc.add>("VSallWP", {"0"}); descriptions.add("DPFTau2016v0", desc); } @@ -71,11 +72,16 @@ class DPFIsolation : public deep_tau::DeepTauBase { shape.dim(2).size() == GetNumberOfFeatures(graphVersion))) throw cms::Exception("DPFIsolation") << "number of inputs does not match the expected inputs for the given version"; + + if (is_online_) { + throw cms::Exception("DPFIsolation") << "Online version based on reco objects in not implemented. Use offline " + "version on top of miniAOD with pat objects."; + } } private: tensorflow::Tensor getPredictions(edm::Event& event, edm::Handle taus) override { - edm::Handle pfcands; + edm::Handle> pfcands; event.getByToken(pfcandToken_, pfcands); edm::Handle vertices; @@ -161,7 +167,7 @@ class DPFIsolation : public deep_tau::DeepTauBase { }); for (size_t pf_index = 0; pf_index < pfcands->size() && iPF < max_iPF; pf_index++) { - pat::PackedCandidate p = pfcands->at(sorted_inds.at(pf_index)); + const pat::PackedCandidate& p = static_cast(pfcands->at(sorted_inds.at(pf_index))); float deltaR_tau_p = deltaR(p.p4(), tau.p4()); if (p.pt() < 0.5) diff --git a/RecoTauTag/RecoTau/plugins/DeepTauId.cc b/RecoTauTag/RecoTau/plugins/DeepTauId.cc index 1c2534f3784d7..86482ce914463 100644 --- a/RecoTauTag/RecoTau/plugins/DeepTauId.cc +++ b/RecoTauTag/RecoTau/plugins/DeepTauId.cc @@ -8,6 +8,7 @@ */ #include "RecoTauTag/RecoTau/interface/DeepTauBase.h" +#include "RecoTauTag/RecoTau/interface/DeepTauScaling.h" #include "FWCore/Utilities/interface/isFinite.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "DataFormats/TauReco/interface/PFTauTransverseImpactParameterAssociation.h" @@ -21,7 +22,7 @@ namespace deep_tau { namespace { - struct dnn_inputs_2017v1 { + struct dnn_inputs_v1 { enum vars { pt = 0, eta, @@ -156,7 +157,7 @@ namespace { }; }; - namespace dnn_inputs_2017_v2 { + namespace dnn_inputs_v2 { constexpr int number_of_inner_cell = 11; constexpr int number_of_outer_cell = 21; constexpr int number_of_conv_features = 64; @@ -211,7 +212,9 @@ namespace { leadChargedCand_etaAtEcalEntrance_minus_tau_eta, NumberOfInputs }; - } + std::vector 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 EgammaBlockInputs { enum vars { @@ -418,7 +421,7 @@ namespace { NumberOfInputs }; } - } // namespace dnn_inputs_2017_v2 + } // namespace dnn_inputs_v2 float getTauID(const pat::Tau& tau, const std::string& tauID, float default_value = -999., bool assert_input = true) { static tbb::concurrent_unordered_set isFirstWarning; @@ -467,6 +470,9 @@ namespace { const float getFootprintCorrectiondR03(const pat::Tau& tau, const edm::RefToBase tau_ref) const { return getTauID(tau, "footprintCorrectiondR03"); } + const float getFootprintCorrection(const pat::Tau& tau, const edm::RefToBase tau_ref) const { + return getTauID(tau, "footprintCorrection"); + } const float getNeutralIsoPtSum(const reco::PFTau& tau, const edm::RefToBase tau_ref) const { return (*basicTauDiscriminatorCollection)[tau_ref].rawValues.at(indexMap.at(BasicDiscr::NeutralIsoPtSum)); } @@ -1156,6 +1162,7 @@ class DeepTauId : public deep_tau::DeepTauBase { {"RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6.pb"}); desc.add("mem_mapped", false); desc.add("version", 2); + desc.add("sub_version", 1); desc.add("debug_level", 0); desc.add("disable_dxy_pca", false); desc.add("disable_hcalFraction_workaround", false); @@ -1200,6 +1207,7 @@ class DeepTauId : public deep_tau::DeepTauBase { consumes>>( cfg.getParameter("pfTauTransverseImpactParameters"))), version_(cfg.getParameter("version")), + sub_version_(cfg.getParameter("sub_version")), debug_level(cfg.getParameter("debug_level")), disable_dxy_pca_(cfg.getParameter("disable_dxy_pca")), disable_hcalFraction_workaround_(cfg.getParameter("disable_hcalFraction_workaround")), @@ -1211,30 +1219,71 @@ class DeepTauId : public deep_tau::DeepTauBase { input_layer_ = cache_->getGraph().node(0).name(); output_layer_ = cache_->getGraph().node(cache_->getGraph().node_size() - 1).name(); const auto& shape = cache_->getGraph().node(0).attr().at("shape").shape(); - if (shape.dim(1).size() != dnn_inputs_2017v1::NumberOfInputs) + if (shape.dim(1).size() != dnn_inputs_v1::NumberOfInputs) throw cms::Exception("DeepTauId") << "number of inputs does not match the expected inputs for the given version"; } else if (version_ == 2) { - tauBlockTensor_ = std::make_unique( - tensorflow::DT_FLOAT, tensorflow::TensorShape{1, dnn_inputs_2017_v2::TauBlockInputs::NumberOfInputs}); + using namespace dnn_inputs_v2; + namespace sc = deep_tau::Scaling; + tauInputs_indices_.resize(TauBlockInputs::NumberOfInputs); + std::iota(std::begin(tauInputs_indices_), std::end(tauInputs_indices_), 0); + + if (sub_version_ == 1) { + tauBlockTensor_ = std::make_unique( + tensorflow::DT_FLOAT, tensorflow::TensorShape{1, TauBlockInputs::NumberOfInputs}); + scalingParamsMap_ = &sc::scalingParamsMap_v2p1; + } else if (sub_version_ == 5) { + std::sort(TauBlockInputs::varsToDrop.begin(), TauBlockInputs::varsToDrop.end()); + for (auto v : TauBlockInputs::varsToDrop) { + tauInputs_indices_.at(v) = -1; // set index to -1 + for (std::size_t i = v + 1; i < TauBlockInputs::NumberOfInputs; ++i) + tauInputs_indices_.at(i) -= 1; // shift all the following indices by 1 + } + tauBlockTensor_ = std::make_unique( + tensorflow::DT_FLOAT, + tensorflow::TensorShape{1, + static_cast(TauBlockInputs::NumberOfInputs) - + static_cast(TauBlockInputs::varsToDrop.size())}); + scalingParamsMap_ = &sc::scalingParamsMap_v2p5; + } else + throw cms::Exception("DeepTauId") << "subversion " << sub_version_ << " is not supported."; + + 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 (const auto& p : GridFeatureTypes_map) { + for (auto is_inner : p.first) { + for (auto featureType : p.second) { + const sc::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 = - is_inner ? dnn_inputs_2017_v2::number_of_inner_cell : dnn_inputs_2017_v2::number_of_outer_cell; + const auto n_cells = is_inner ? number_of_inner_cell : number_of_outer_cell; eGammaTensor_[is_inner] = std::make_unique( - tensorflow::DT_FLOAT, - tensorflow::TensorShape{1, 1, 1, dnn_inputs_2017_v2::EgammaBlockInputs::NumberOfInputs}); + tensorflow::DT_FLOAT, tensorflow::TensorShape{1, 1, 1, EgammaBlockInputs::NumberOfInputs}); muonTensor_[is_inner] = std::make_unique( - tensorflow::DT_FLOAT, - tensorflow::TensorShape{1, 1, 1, dnn_inputs_2017_v2::MuonBlockInputs::NumberOfInputs}); + tensorflow::DT_FLOAT, tensorflow::TensorShape{1, 1, 1, MuonBlockInputs::NumberOfInputs}); hadronsTensor_[is_inner] = std::make_unique( - tensorflow::DT_FLOAT, - tensorflow::TensorShape{1, 1, 1, dnn_inputs_2017_v2::HadronBlockInputs::NumberOfInputs}); + tensorflow::DT_FLOAT, tensorflow::TensorShape{1, 1, 1, HadronBlockInputs::NumberOfInputs}); convTensor_[is_inner] = std::make_unique( - tensorflow::DT_FLOAT, - tensorflow::TensorShape{1, n_cells, n_cells, dnn_inputs_2017_v2::number_of_conv_features}); + tensorflow::DT_FLOAT, tensorflow::TensorShape{1, n_cells, n_cells, number_of_conv_features}); zeroOutputTensor_[is_inner] = std::make_unique( - tensorflow::DT_FLOAT, tensorflow::TensorShape{1, 1, 1, dnn_inputs_2017_v2::number_of_conv_features}); + tensorflow::DT_FLOAT, tensorflow::TensorShape{1, 1, 1, number_of_conv_features}); eGammaTensor_[is_inner]->flat().setZero(); muonTensor_[is_inner]->flat().setZero(); @@ -1554,7 +1603,7 @@ class DeepTauId : public deep_tau::DeepTauBase { const std::vector* muons, std::vector& pred_vector, TauFunc tau_funcs) { - const tensorflow::Tensor& inputs = createInputsV1( + const tensorflow::Tensor& inputs = createInputsV1( dynamic_cast(tau), tau_index, tau_ref, electrons, muons, tau_funcs); tensorflow::run(&(cache_->getSession()), {{input_layer_, inputs}}, {output_layer_}, &pred_vector); } @@ -1570,29 +1619,21 @@ class DeepTauId : public deep_tau::DeepTauBase { double rho, std::vector& pred_vector, TauFunc tau_funcs) { + using namespace dnn_inputs_v2; if (debug_level >= 2) { std::cout << ":" << std::endl; std::cout << " tau: pT = " << tau.pt() << ", eta = " << tau.eta() << ", phi = " << tau.phi() << std::endl; } - CellGrid inner_grid(dnn_inputs_2017_v2::number_of_inner_cell, - dnn_inputs_2017_v2::number_of_inner_cell, - 0.02, - 0.02, - disable_CellIndex_workaround_); - CellGrid outer_grid(dnn_inputs_2017_v2::number_of_outer_cell, - dnn_inputs_2017_v2::number_of_outer_cell, - 0.05, - 0.05, - disable_CellIndex_workaround_); + CellGrid inner_grid(number_of_inner_cell, number_of_inner_cell, 0.02, 0.02, disable_CellIndex_workaround_); + CellGrid outer_grid(number_of_outer_cell, number_of_outer_cell, 0.05, 0.05, disable_CellIndex_workaround_); fillGrids(dynamic_cast(tau), *electrons, inner_grid, outer_grid); fillGrids(dynamic_cast(tau), *muons, inner_grid, outer_grid); fillGrids(dynamic_cast(tau), pfCands, inner_grid, outer_grid); createTauBlockInputs( dynamic_cast(tau), tau_index, tau_ref, pv, rho, tau_funcs); - using namespace dnn_inputs_2017_v2; - checkInputs(*tauBlockTensor_, "input_tau", TauBlockInputs::NumberOfInputs); + checkInputs(*tauBlockTensor_, "input_tau", static_cast(tauBlockTensor_->shape().dim_size(1))); createConvFeatures(dynamic_cast(tau), tau_index, tau_ref, @@ -1627,27 +1668,17 @@ class DeepTauId : public deep_tau::DeepTauBase { json_file_ = new std::ofstream(json_file_name.data()); is_first_block_ = true; (*json_file_) << "{"; - saveInputs(*tauBlockTensor_, "input_tau", dnn_inputs_2017_v2::TauBlockInputs::NumberOfInputs); - saveInputs(*eGammaTensor_[true], - "input_inner_egamma", - dnn_inputs_2017_v2::EgammaBlockInputs::NumberOfInputs, - &inner_grid); + saveInputs(*tauBlockTensor_, "input_tau", static_cast(tauBlockTensor_->shape().dim_size(1))); + saveInputs( + *eGammaTensor_[true], "input_inner_egamma", dnn_inputs_v2::EgammaBlockInputs::NumberOfInputs, &inner_grid); + saveInputs(*muonTensor_[true], "input_inner_muon", dnn_inputs_v2::MuonBlockInputs::NumberOfInputs, &inner_grid); saveInputs( - *muonTensor_[true], "input_inner_muon", dnn_inputs_2017_v2::MuonBlockInputs::NumberOfInputs, &inner_grid); - saveInputs(*hadronsTensor_[true], - "input_inner_hadrons", - dnn_inputs_2017_v2::HadronBlockInputs::NumberOfInputs, - &inner_grid); - saveInputs(*eGammaTensor_[false], - "input_outer_egamma", - dnn_inputs_2017_v2::EgammaBlockInputs::NumberOfInputs, - &outer_grid); + *hadronsTensor_[true], "input_inner_hadrons", dnn_inputs_v2::HadronBlockInputs::NumberOfInputs, &inner_grid); saveInputs( - *muonTensor_[false], "input_outer_muon", dnn_inputs_2017_v2::MuonBlockInputs::NumberOfInputs, &outer_grid); - saveInputs(*hadronsTensor_[false], - "input_outer_hadrons", - dnn_inputs_2017_v2::HadronBlockInputs::NumberOfInputs, - &outer_grid); + *eGammaTensor_[false], "input_outer_egamma", dnn_inputs_v2::EgammaBlockInputs::NumberOfInputs, &outer_grid); + saveInputs(*muonTensor_[false], "input_outer_muon", dnn_inputs_v2::MuonBlockInputs::NumberOfInputs, &outer_grid); + saveInputs( + *hadronsTensor_[false], "input_outer_hadrons", dnn_inputs_v2::HadronBlockInputs::NumberOfInputs, &outer_grid); (*json_file_) << "}"; delete json_file_; ++file_counter_; @@ -1761,15 +1792,15 @@ class DeepTauId : public deep_tau::DeepTauBase { eGammaTensor_[is_inner] = std::make_unique( tensorflow::DT_FLOAT, tensorflow::TensorShape{ - (long long int)grid.num_valid_cells(), 1, 1, dnn_inputs_2017_v2::EgammaBlockInputs::NumberOfInputs}); + (long long int)grid.num_valid_cells(), 1, 1, dnn_inputs_v2::EgammaBlockInputs::NumberOfInputs}); muonTensor_[is_inner] = std::make_unique( tensorflow::DT_FLOAT, tensorflow::TensorShape{ - (long long int)grid.num_valid_cells(), 1, 1, dnn_inputs_2017_v2::MuonBlockInputs::NumberOfInputs}); + (long long int)grid.num_valid_cells(), 1, 1, dnn_inputs_v2::MuonBlockInputs::NumberOfInputs}); hadronsTensor_[is_inner] = std::make_unique( tensorflow::DT_FLOAT, tensorflow::TensorShape{ - (long long int)grid.num_valid_cells(), 1, 1, dnn_inputs_2017_v2::HadronBlockInputs::NumberOfInputs}); + (long long int)grid.num_valid_cells(), 1, 1, dnn_inputs_v2::HadronBlockInputs::NumberOfInputs}); eGammaTensor_[is_inner]->flat().setZero(); muonTensor_[is_inner]->flat().setZero(); @@ -1829,7 +1860,7 @@ class DeepTauId : public deep_tau::DeepTauBase { unsigned batch_idx, int eta_index, int phi_index) { - for (int n = 0; n < dnn_inputs_2017_v2::number_of_conv_features; ++n) { + for (int n = 0; n < dnn_inputs_v2::number_of_conv_features; ++n) { convTensor.tensor()(0, eta_index, phi_index, n) = features.tensor()(batch_idx, 0, 0, n); } } @@ -1841,103 +1872,142 @@ class DeepTauId : public deep_tau::DeepTauBase { const reco::Vertex& pv, double rho, TauFunc tau_funcs) { - namespace dnn = dnn_inputs_2017_v2::TauBlockInputs; + namespace dnn = dnn_inputs_v2::TauBlockInputs; + namespace sc = deep_tau::Scaling; + sc::FeatureT ft = sc::FeatureT::TauFlat; + const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft, false)); tensorflow::Tensor& inputs = *tauBlockTensor_; inputs.flat().setZero(); - const auto& get = [&](int var_index) -> float& { return inputs.matrix()(0, var_index); }; + const auto& get = [&](int var_index) -> float& { + return inputs.matrix()(0, tauInputs_indices_.at(var_index)); + }; auto leadChargedHadrCand = dynamic_cast(tau.leadChargedHadrCand().get()); - get(dnn::rho) = getValueNorm(rho, 21.49f, 9.713f); - get(dnn::tau_pt) = getValueLinear(tau.polarP4().pt(), 20.f, 1000.f, true); - get(dnn::tau_eta) = getValueLinear(tau.polarP4().eta(), -2.3f, 2.3f, false); - get(dnn::tau_phi) = getValueLinear(tau.polarP4().phi(), -pi, pi, false); - get(dnn::tau_mass) = getValueNorm(tau.polarP4().mass(), 0.6669f, 0.6553f); - get(dnn::tau_E_over_pt) = getValueLinear(tau.p4().energy() / tau.p4().pt(), 1.f, 5.2f, true); - get(dnn::tau_charge) = getValue(tau.charge()); - get(dnn::tau_n_charged_prongs) = getValueLinear(tau.decayMode() / 5 + 1, 1, 3, true); - get(dnn::tau_n_neutral_prongs) = getValueLinear(tau.decayMode() % 5, 0, 2, true); - get(dnn::chargedIsoPtSum) = getValueNorm(tau_funcs.getChargedIsoPtSum(tau, tau_ref), 47.78f, 123.5f); + get(dnn::rho) = sp.scale(rho, tauInputs_indices_[dnn::rho]); + get(dnn::tau_pt) = sp.scale(tau.polarP4().pt(), tauInputs_indices_[dnn::tau_pt]); + get(dnn::tau_eta) = sp.scale(tau.polarP4().eta(), tauInputs_indices_[dnn::tau_eta]); + if (sub_version_ == 1) { + get(dnn::tau_phi) = getValueLinear(tau.polarP4().phi(), -pi, pi, false); + } + get(dnn::tau_mass) = sp.scale(tau.polarP4().mass(), tauInputs_indices_[dnn::tau_mass]); + get(dnn::tau_E_over_pt) = sp.scale(tau.p4().energy() / tau.p4().pt(), tauInputs_indices_[dnn::tau_E_over_pt]); + get(dnn::tau_charge) = sp.scale(tau.charge(), tauInputs_indices_[dnn::tau_charge]); + get(dnn::tau_n_charged_prongs) = sp.scale(tau.decayMode() / 5 + 1, tauInputs_indices_[dnn::tau_n_charged_prongs]); + get(dnn::tau_n_neutral_prongs) = sp.scale(tau.decayMode() % 5, tauInputs_indices_[dnn::tau_n_neutral_prongs]); + get(dnn::chargedIsoPtSum) = + sp.scale(tau_funcs.getChargedIsoPtSum(tau, tau_ref), tauInputs_indices_[dnn::chargedIsoPtSum]); get(dnn::chargedIsoPtSumdR03_over_dR05) = - getValue(tau_funcs.getChargedIsoPtSumdR03(tau, tau_ref) / tau_funcs.getChargedIsoPtSum(tau, tau_ref)); - get(dnn::footprintCorrection) = getValueNorm(tau_funcs.getFootprintCorrectiondR03(tau, tau_ref), 9.029f, 26.42f); - get(dnn::neutralIsoPtSum) = getValueNorm(tau_funcs.getNeutralIsoPtSum(tau, tau_ref), 57.59f, 155.3f); + sp.scale(tau_funcs.getChargedIsoPtSumdR03(tau, tau_ref) / tau_funcs.getChargedIsoPtSum(tau, tau_ref), + tauInputs_indices_[dnn::chargedIsoPtSumdR03_over_dR05]); + if (sub_version_ == 1) + get(dnn::footprintCorrection) = + sp.scale(tau_funcs.getFootprintCorrectiondR03(tau, tau_ref), tauInputs_indices_[dnn::footprintCorrection]); + else if (sub_version_ == 5) + get(dnn::footprintCorrection) = + sp.scale(tau_funcs.getFootprintCorrection(tau, tau_ref), tauInputs_indices_[dnn::footprintCorrection]); + + get(dnn::neutralIsoPtSum) = + sp.scale(tau_funcs.getNeutralIsoPtSum(tau, tau_ref), tauInputs_indices_[dnn::neutralIsoPtSum]); get(dnn::neutralIsoPtSumWeight_over_neutralIsoPtSum) = - getValue(tau_funcs.getNeutralIsoPtSumWeight(tau, tau_ref) / tau_funcs.getNeutralIsoPtSum(tau, tau_ref)); + sp.scale(tau_funcs.getNeutralIsoPtSumWeight(tau, tau_ref) / tau_funcs.getNeutralIsoPtSum(tau, tau_ref), + tauInputs_indices_[dnn::neutralIsoPtSumWeight_over_neutralIsoPtSum]); get(dnn::neutralIsoPtSumWeightdR03_over_neutralIsoPtSum) = - getValue(tau_funcs.getNeutralIsoPtSumdR03Weight(tau, tau_ref) / tau_funcs.getNeutralIsoPtSum(tau, tau_ref)); + sp.scale(tau_funcs.getNeutralIsoPtSumdR03Weight(tau, tau_ref) / tau_funcs.getNeutralIsoPtSum(tau, tau_ref), + tauInputs_indices_[dnn::neutralIsoPtSumWeightdR03_over_neutralIsoPtSum]); get(dnn::neutralIsoPtSumdR03_over_dR05) = - getValue(tau_funcs.getNeutralIsoPtSumdR03(tau, tau_ref) / tau_funcs.getNeutralIsoPtSum(tau, tau_ref)); - get(dnn::photonPtSumOutsideSignalCone) = - getValueNorm(tau_funcs.getPhotonPtSumOutsideSignalCone(tau, tau_ref), 1.731f, 6.846f); - get(dnn::puCorrPtSum) = getValueNorm(tau_funcs.getPuCorrPtSum(tau, tau_ref), 22.38f, 16.34f); + sp.scale(tau_funcs.getNeutralIsoPtSumdR03(tau, tau_ref) / tau_funcs.getNeutralIsoPtSum(tau, tau_ref), + tauInputs_indices_[dnn::neutralIsoPtSumdR03_over_dR05]); + get(dnn::photonPtSumOutsideSignalCone) = sp.scale(tau_funcs.getPhotonPtSumOutsideSignalCone(tau, tau_ref), + tauInputs_indices_[dnn::photonPtSumOutsideSignalCone]); + get(dnn::puCorrPtSum) = sp.scale(tau_funcs.getPuCorrPtSum(tau, tau_ref), tauInputs_indices_[dnn::puCorrPtSum]); // 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_) { - auto const pca = tau_funcs.getdxyPCA(tau, tau_index); - get(dnn::tau_dxy_pca_x) = getValueNorm(pca.x(), -0.0241f, 0.0074f); - get(dnn::tau_dxy_pca_y) = getValueNorm(pca.y(), 0.0675f, 0.0128f); - get(dnn::tau_dxy_pca_z) = getValueNorm(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; + if (sub_version_ == 1) { + if (!disable_dxy_pca_) { + auto const pca = tau_funcs.getdxyPCA(tau, tau_index); + get(dnn::tau_dxy_pca_x) = sp.scale(pca.x(), tauInputs_indices_[dnn::tau_dxy_pca_x]); + get(dnn::tau_dxy_pca_y) = sp.scale(pca.y(), tauInputs_indices_[dnn::tau_dxy_pca_y]); + get(dnn::tau_dxy_pca_z) = sp.scale(pca.z(), tauInputs_indices_[dnn::tau_dxy_pca_z]); + } 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 = isAbove(tau_funcs.getdxy(tau, tau_index), -10) && isAbove(tau_funcs.getdxyError(tau, tau_index), 0); if (tau_dxy_valid) { - get(dnn::tau_dxy_valid) = tau_dxy_valid; - get(dnn::tau_dxy) = getValueNorm(tau_funcs.getdxy(tau, tau_index), 0.0018f, 0.0085f); - get(dnn::tau_dxy_sig) = getValueNorm( - std::abs(tau_funcs.getdxy(tau, tau_index)) / tau_funcs.getdxyError(tau, tau_index), 2.26f, 4.191f); + get(dnn::tau_dxy_valid) = sp.scale(tau_dxy_valid, tauInputs_indices_[dnn::tau_dxy_valid]); + get(dnn::tau_dxy) = sp.scale(tau_funcs.getdxy(tau, tau_index), tauInputs_indices_[dnn::tau_dxy]); + get(dnn::tau_dxy_sig) = + sp.scale(std::abs(tau_funcs.getdxy(tau, tau_index)) / tau_funcs.getdxyError(tau, tau_index), + tauInputs_indices_[dnn::tau_dxy_sig]); } const bool tau_ip3d_valid = isAbove(tau_funcs.getip3d(tau, tau_index), -10) && isAbove(tau_funcs.getip3dError(tau, tau_index), 0); if (tau_ip3d_valid) { - get(dnn::tau_ip3d_valid) = tau_ip3d_valid; - get(dnn::tau_ip3d) = getValueNorm(tau_funcs.getip3d(tau, tau_index), 0.0026f, 0.0114f); - get(dnn::tau_ip3d_sig) = getValueNorm( - std::abs(tau_funcs.getip3d(tau, tau_index)) / tau_funcs.getip3dError(tau, tau_index), 2.928f, 4.466f); + get(dnn::tau_ip3d_valid) = sp.scale(tau_ip3d_valid, tauInputs_indices_[dnn::tau_ip3d_valid]); + get(dnn::tau_ip3d) = sp.scale(tau_funcs.getip3d(tau, tau_index), tauInputs_indices_[dnn::tau_ip3d]); + get(dnn::tau_ip3d_sig) = + sp.scale(std::abs(tau_funcs.getip3d(tau, tau_index)) / tau_funcs.getip3dError(tau, tau_index), + tauInputs_indices_[dnn::tau_ip3d_sig]); } if (leadChargedHadrCand) { const bool hasTrackDetails = candFunc::getHasTrackDetails(*leadChargedHadrCand); const float tau_dz = (is_online_ && !hasTrackDetails) ? 0 : candFunc::getTauDz(*leadChargedHadrCand); - get(dnn::tau_dz) = getValueNorm(tau_dz, 0.f, 0.0190f); - get(dnn::tau_dz_sig_valid) = candFunc::getTauDZSigValid(*leadChargedHadrCand); + get(dnn::tau_dz) = sp.scale(tau_dz, tauInputs_indices_[dnn::tau_dz]); + get(dnn::tau_dz_sig_valid) = + sp.scale(candFunc::getTauDZSigValid(*leadChargedHadrCand), tauInputs_indices_[dnn::tau_dz_sig_valid]); const double dzError = hasTrackDetails ? leadChargedHadrCand->dzError() : -999.; - get(dnn::tau_dz_sig) = getValueNorm(std::abs(tau_dz) / dzError, 4.717f, 11.78f); - } - get(dnn::tau_flightLength_x) = getValueNorm(tau_funcs.getFlightLength(tau, tau_index).x(), -0.0003f, 0.7362f); - get(dnn::tau_flightLength_y) = getValueNorm(tau_funcs.getFlightLength(tau, tau_index).y(), -0.0009f, 0.7354f); - get(dnn::tau_flightLength_z) = getValueNorm(tau_funcs.getFlightLength(tau, tau_index).z(), -0.0022f, 1.993f); - get(dnn::tau_flightLength_sig) = 0.55756444; //This value is set due to a bug in the training - get(dnn::tau_pt_weighted_deta_strip) = - getValueLinear(reco::tau::pt_weighted_deta_strip(tau, tau.decayMode()), 0, 1, true); - - get(dnn::tau_pt_weighted_dphi_strip) = - getValueLinear(reco::tau::pt_weighted_dphi_strip(tau, tau.decayMode()), 0, 1, true); - get(dnn::tau_pt_weighted_dr_signal) = - getValueNorm(reco::tau::pt_weighted_dr_signal(tau, tau.decayMode()), 0.0052f, 0.01433f); - get(dnn::tau_pt_weighted_dr_iso) = getValueLinear(reco::tau::pt_weighted_dr_iso(tau, tau.decayMode()), 0, 1, true); - get(dnn::tau_leadingTrackNormChi2) = getValueNorm(tau_funcs.getLeadingTrackNormChi2(tau), 1.538f, 4.401f); + get(dnn::tau_dz_sig) = sp.scale(std::abs(tau_dz) / dzError, tauInputs_indices_[dnn::tau_dz_sig]); + } + get(dnn::tau_flightLength_x) = + sp.scale(tau_funcs.getFlightLength(tau, tau_index).x(), tauInputs_indices_[dnn::tau_flightLength_x]); + get(dnn::tau_flightLength_y) = + sp.scale(tau_funcs.getFlightLength(tau, tau_index).y(), tauInputs_indices_[dnn::tau_flightLength_y]); + get(dnn::tau_flightLength_z) = + 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) + get(dnn::tau_flightLength_sig) = + sp.scale(tau_funcs.getFlightLengthSig(tau, tau_index), tauInputs_indices_[dnn::tau_flightLength_sig]); + + get(dnn::tau_pt_weighted_deta_strip) = sp.scale(reco::tau::pt_weighted_deta_strip(tau, tau.decayMode()), + tauInputs_indices_[dnn::tau_pt_weighted_deta_strip]); + + get(dnn::tau_pt_weighted_dphi_strip) = sp.scale(reco::tau::pt_weighted_dphi_strip(tau, tau.decayMode()), + tauInputs_indices_[dnn::tau_pt_weighted_dphi_strip]); + get(dnn::tau_pt_weighted_dr_signal) = sp.scale(reco::tau::pt_weighted_dr_signal(tau, tau.decayMode()), + tauInputs_indices_[dnn::tau_pt_weighted_dr_signal]); + get(dnn::tau_pt_weighted_dr_iso) = + sp.scale(reco::tau::pt_weighted_dr_iso(tau, tau.decayMode()), tauInputs_indices_[dnn::tau_pt_weighted_dr_iso]); + get(dnn::tau_leadingTrackNormChi2) = + sp.scale(tau_funcs.getLeadingTrackNormChi2(tau), tauInputs_indices_[dnn::tau_leadingTrackNormChi2]); const auto eratio = reco::tau::eratio(tau); const bool tau_e_ratio_valid = std::isnormal(eratio) && eratio > 0.f; - get(dnn::tau_e_ratio_valid) = tau_e_ratio_valid; - get(dnn::tau_e_ratio) = tau_e_ratio_valid ? getValueLinear(eratio, 0, 1, true) : 0.f; + get(dnn::tau_e_ratio_valid) = sp.scale(tau_e_ratio_valid, tauInputs_indices_[dnn::tau_e_ratio_valid]); + get(dnn::tau_e_ratio) = tau_e_ratio_valid ? sp.scale(eratio, tauInputs_indices_[dnn::tau_e_ratio]) : 0.f; const double gj_angle_diff = calculateGottfriedJacksonAngleDifference(tau, tau_index, tau_funcs); const bool tau_gj_angle_diff_valid = (std::isnormal(gj_angle_diff) || gj_angle_diff == 0) && gj_angle_diff >= 0; - get(dnn::tau_gj_angle_diff_valid) = tau_gj_angle_diff_valid; - get(dnn::tau_gj_angle_diff) = tau_gj_angle_diff_valid ? getValueLinear(gj_angle_diff, 0, pi, true) : 0; - get(dnn::tau_n_photons) = getValueNorm(reco::tau::n_photons_total(tau), 2.95f, 3.927f); - get(dnn::tau_emFraction) = getValueLinear(tau_funcs.getEmFraction(tau), -1, 1, false); - - get(dnn::tau_inside_ecal_crack) = getValue(isInEcalCrack(tau.p4().eta())); + get(dnn::tau_gj_angle_diff_valid) = + sp.scale(tau_gj_angle_diff_valid, tauInputs_indices_[dnn::tau_gj_angle_diff_valid]); + get(dnn::tau_gj_angle_diff) = + tau_gj_angle_diff_valid ? sp.scale(gj_angle_diff, tauInputs_indices_[dnn::tau_gj_angle_diff]) : 0; + get(dnn::tau_n_photons) = sp.scale(reco::tau::n_photons_total(tau), tauInputs_indices_[dnn::tau_n_photons]); + get(dnn::tau_emFraction) = sp.scale(tau_funcs.getEmFraction(tau), tauInputs_indices_[dnn::tau_emFraction]); + + get(dnn::tau_inside_ecal_crack) = + sp.scale(isInEcalCrack(tau.p4().eta()), tauInputs_indices_[dnn::tau_inside_ecal_crack]); get(dnn::leadChargedCand_etaAtEcalEntrance_minus_tau_eta) = - getValueNorm(tau_funcs.getEtaAtEcalEntrance(tau) - tau.p4().eta(), 0.0042f, 0.0323f); + sp.scale(tau_funcs.getEtaAtEcalEntrance(tau) - tau.p4().eta(), + tauInputs_indices_[dnn::leadChargedCand_etaAtEcalEntrance_minus_tau_eta]); } template @@ -1952,7 +2022,27 @@ class DeepTauId : public deep_tau::DeepTauBase { const Cell& cell_map, TauFunc tau_funcs, bool is_inner) { - namespace dnn = dnn_inputs_2017_v2::EgammaBlockInputs; + namespace dnn = dnn_inputs_v2::EgammaBlockInputs; + namespace sc = deep_tau::Scaling; + sc::FeatureT ft_global = sc::FeatureT::GridGlobal; + sc::FeatureT ft_PFe = sc::FeatureT::PfCand_electron; + sc::FeatureT ft_PFg = sc::FeatureT::PfCand_gamma; + sc::FeatureT ft_e = sc::FeatureT::Electron; + + // needed to remap indices from scaling vectors to those from dnn_inputs_v2::EgammaBlockInputs + int PFe_index_offset = scalingParamsMap_->at(std::make_pair(ft_global, false)).mean_.size(); + int e_index_offset = PFe_index_offset + scalingParamsMap_->at(std::make_pair(ft_PFe, false)).mean_.size(); + int PFg_index_offset = e_index_offset + scalingParamsMap_->at(std::make_pair(ft_e, false)).mean_.size(); + + // 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) { + fill_index_offset_e = + scalingParamsMap_->at(std::make_pair(ft_PFg, false)).mean_.size(); // size of PF gamma features + fill_index_offset_PFg = + -scalingParamsMap_->at(std::make_pair(ft_e, false)).mean_.size(); // size of Electron features + } tensorflow::Tensor& inputs = *eGammaTensor_.at(is_inner); @@ -1963,215 +2053,232 @@ class DeepTauId : public deep_tau::DeepTauBase { const bool valid_index_ele = cell_map.count(CellObjectType::Electron); if (!cell_map.empty()) { - get(dnn::rho) = getValueNorm(rho, 21.49f, 9.713f); - get(dnn::tau_pt) = getValueLinear(tau.polarP4().pt(), 20.f, 1000.f, true); - get(dnn::tau_eta) = getValueLinear(tau.polarP4().eta(), -2.3f, 2.3f, false); - get(dnn::tau_inside_ecal_crack) = getValue(isInEcalCrack(tau.polarP4().eta())); + const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft_global, false)); + get(dnn::rho) = sp.scale(rho, dnn::rho); + get(dnn::tau_pt) = sp.scale(tau.polarP4().pt(), dnn::tau_pt); + get(dnn::tau_eta) = sp.scale(tau.polarP4().eta(), dnn::tau_eta); + get(dnn::tau_inside_ecal_crack) = sp.scale(isInEcalCrack(tau.polarP4().eta()), dnn::tau_inside_ecal_crack); } if (valid_index_pf_ele) { + const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft_PFe, is_inner)); size_t index_pf_ele = cell_map.at(CellObjectType::PfCand_electron); const auto& ele_cand = dynamic_cast(pfCands.at(index_pf_ele)); - get(dnn::pfCand_ele_valid) = valid_index_pf_ele; - get(dnn::pfCand_ele_rel_pt) = getValueNorm(pfCands.at(index_pf_ele).polarP4().pt() / tau.polarP4().pt(), - is_inner ? 0.9792f : 0.304f, - is_inner ? 0.5383f : 1.845f); - get(dnn::pfCand_ele_deta) = getValueLinear(pfCands.at(index_pf_ele).polarP4().eta() - tau.polarP4().eta(), - is_inner ? -0.1f : -0.5f, - is_inner ? 0.1f : 0.5f, - false); - get(dnn::pfCand_ele_dphi) = getValueLinear(dPhi(tau.polarP4(), pfCands.at(index_pf_ele).polarP4()), - is_inner ? -0.1f : -0.5f, - is_inner ? 0.1f : 0.5f, - false); - get(dnn::pfCand_ele_pvAssociationQuality) = - getValueLinear(candFunc::getPvAssocationQuality(ele_cand), 0, 7, true); - get(dnn::pfCand_ele_puppiWeight) = is_inner ? getValue(candFunc::getPuppiWeight(ele_cand, 0.9906834f)) - : getValue(candFunc::getPuppiWeight(ele_cand, 0.9669586f)); - get(dnn::pfCand_ele_charge) = getValue(ele_cand.charge()); - get(dnn::pfCand_ele_lostInnerHits) = getValue(candFunc::getLostInnerHits(ele_cand, 0)); - get(dnn::pfCand_ele_numberOfPixelHits) = getValueLinear(candFunc::getNumberOfPixelHits(ele_cand, 0), 0, 10, true); + get(dnn::pfCand_ele_valid) = sp.scale(valid_index_pf_ele, dnn::pfCand_ele_valid - PFe_index_offset); + get(dnn::pfCand_ele_rel_pt) = + sp.scale(ele_cand.polarP4().pt() / tau.polarP4().pt(), dnn::pfCand_ele_rel_pt - PFe_index_offset); + get(dnn::pfCand_ele_deta) = + sp.scale(ele_cand.polarP4().eta() - tau.polarP4().eta(), dnn::pfCand_ele_deta - PFe_index_offset); + get(dnn::pfCand_ele_dphi) = + sp.scale(dPhi(tau.polarP4(), ele_cand.polarP4()), dnn::pfCand_ele_dphi - PFe_index_offset); + get(dnn::pfCand_ele_pvAssociationQuality) = sp.scale( + candFunc::getPvAssocationQuality(ele_cand), dnn::pfCand_ele_pvAssociationQuality - PFe_index_offset); + get(dnn::pfCand_ele_puppiWeight) = is_inner ? sp.scale(candFunc::getPuppiWeight(ele_cand, 0.9906834f), + dnn::pfCand_ele_puppiWeight - PFe_index_offset) + : sp.scale(candFunc::getPuppiWeight(ele_cand, 0.9669586f), + dnn::pfCand_ele_puppiWeight - PFe_index_offset); + get(dnn::pfCand_ele_charge) = sp.scale(ele_cand.charge(), dnn::pfCand_ele_charge - PFe_index_offset); + get(dnn::pfCand_ele_lostInnerHits) = + sp.scale(candFunc::getLostInnerHits(ele_cand, 0), dnn::pfCand_ele_lostInnerHits - PFe_index_offset); + get(dnn::pfCand_ele_numberOfPixelHits) = + sp.scale(candFunc::getNumberOfPixelHits(ele_cand, 0), dnn::pfCand_ele_numberOfPixelHits - PFe_index_offset); get(dnn::pfCand_ele_vertex_dx) = - getValueNorm(pfCands.at(index_pf_ele).vertex().x() - pv.position().x(), 0.f, 0.1221f); + sp.scale(ele_cand.vertex().x() - pv.position().x(), dnn::pfCand_ele_vertex_dx - PFe_index_offset); get(dnn::pfCand_ele_vertex_dy) = - getValueNorm(pfCands.at(index_pf_ele).vertex().y() - pv.position().y(), 0.f, 0.1226f); + sp.scale(ele_cand.vertex().y() - pv.position().y(), dnn::pfCand_ele_vertex_dy - PFe_index_offset); get(dnn::pfCand_ele_vertex_dz) = - getValueNorm(pfCands.at(index_pf_ele).vertex().z() - pv.position().z(), 0.001f, 1.024f); - get(dnn::pfCand_ele_vertex_dx_tauFL) = getValueNorm( - pfCands.at(index_pf_ele).vertex().x() - pv.position().x() - tau_funcs.getFlightLength(tau, tau_index).x(), - 0.f, - 0.3411f); - get(dnn::pfCand_ele_vertex_dy_tauFL) = getValueNorm( - pfCands.at(index_pf_ele).vertex().y() - pv.position().y() - tau_funcs.getFlightLength(tau, tau_index).y(), - 0.0003f, - 0.3385f); - get(dnn::pfCand_ele_vertex_dz_tauFL) = getValueNorm( - pfCands.at(index_pf_ele).vertex().z() - pv.position().z() - tau_funcs.getFlightLength(tau, tau_index).z(), - 0.f, - 1.307f); + sp.scale(ele_cand.vertex().z() - pv.position().z(), dnn::pfCand_ele_vertex_dz - PFe_index_offset); + get(dnn::pfCand_ele_vertex_dx_tauFL) = + sp.scale(ele_cand.vertex().x() - pv.position().x() - tau_funcs.getFlightLength(tau, tau_index).x(), + dnn::pfCand_ele_vertex_dx_tauFL - PFe_index_offset); + get(dnn::pfCand_ele_vertex_dy_tauFL) = + sp.scale(ele_cand.vertex().y() - pv.position().y() - tau_funcs.getFlightLength(tau, tau_index).y(), + dnn::pfCand_ele_vertex_dy_tauFL - PFe_index_offset); + get(dnn::pfCand_ele_vertex_dz_tauFL) = + sp.scale(ele_cand.vertex().z() - pv.position().z() - tau_funcs.getFlightLength(tau, tau_index).z(), + dnn::pfCand_ele_vertex_dz_tauFL - PFe_index_offset); const bool hasTrackDetails = candFunc::getHasTrackDetails(ele_cand); if (hasTrackDetails) { - get(dnn::pfCand_ele_hasTrackDetails) = hasTrackDetails; - get(dnn::pfCand_ele_dxy) = getValueNorm(candFunc::getTauDxy(ele_cand), 0.f, 0.171f); - get(dnn::pfCand_ele_dxy_sig) = - getValueNorm(std::abs(candFunc::getTauDxy(ele_cand)) / pfCands.at(index_pf_ele).dxyError(), 1.634f, 6.45f); - get(dnn::pfCand_ele_dz) = getValueNorm(candFunc::getTauDz(ele_cand), 0.001f, 1.02f); - get(dnn::pfCand_ele_dz_sig) = - getValueNorm(std::abs(candFunc::getTauDz(ele_cand)) / ele_cand.dzError(), 24.56f, 210.4f); - get(dnn::pfCand_ele_track_chi2_ndof) = getValueNorm( - candFunc::getPseudoTrack(ele_cand).chi2() / candFunc::getPseudoTrack(ele_cand).ndof(), 2.272f, 8.439f); - get(dnn::pfCand_ele_track_ndof) = getValueNorm(candFunc::getPseudoTrack(ele_cand).ndof(), 15.18f, 3.203f); + get(dnn::pfCand_ele_hasTrackDetails) = + sp.scale(hasTrackDetails, dnn::pfCand_ele_hasTrackDetails - PFe_index_offset); + get(dnn::pfCand_ele_dxy) = sp.scale(candFunc::getTauDxy(ele_cand), dnn::pfCand_ele_dxy - PFe_index_offset); + get(dnn::pfCand_ele_dxy_sig) = sp.scale(std::abs(candFunc::getTauDxy(ele_cand)) / ele_cand.dxyError(), + dnn::pfCand_ele_dxy_sig - PFe_index_offset); + get(dnn::pfCand_ele_dz) = sp.scale(candFunc::getTauDz(ele_cand), dnn::pfCand_ele_dz - PFe_index_offset); + get(dnn::pfCand_ele_dz_sig) = sp.scale(std::abs(candFunc::getTauDz(ele_cand)) / ele_cand.dzError(), + dnn::pfCand_ele_dz_sig - PFe_index_offset); + get(dnn::pfCand_ele_track_chi2_ndof) = + candFunc::getPseudoTrack(ele_cand).ndof() > 0 + ? sp.scale(candFunc::getPseudoTrack(ele_cand).chi2() / candFunc::getPseudoTrack(ele_cand).ndof(), + dnn::pfCand_ele_track_chi2_ndof - PFe_index_offset) + : 0; + get(dnn::pfCand_ele_track_ndof) = + candFunc::getPseudoTrack(ele_cand).ndof() > 0 + ? sp.scale(candFunc::getPseudoTrack(ele_cand).ndof(), dnn::pfCand_ele_track_ndof - PFe_index_offset) + : 0; } } if (valid_index_pf_gamma) { + const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft_PFg, is_inner)); size_t index_pf_gamma = cell_map.at(CellObjectType::PfCand_gamma); const auto& gamma_cand = dynamic_cast(pfCands.at(index_pf_gamma)); - get(dnn::pfCand_gamma_valid) = valid_index_pf_gamma; - get(dnn::pfCand_gamma_rel_pt) = getValueNorm(pfCands.at(index_pf_gamma).polarP4().pt() / tau.polarP4().pt(), - is_inner ? 0.6048f : 0.02576f, - is_inner ? 1.669f : 0.3833f); - get(dnn::pfCand_gamma_deta) = getValueLinear(pfCands.at(index_pf_gamma).polarP4().eta() - tau.polarP4().eta(), - is_inner ? -0.1f : -0.5f, - is_inner ? 0.1f : 0.5f, - false); - get(dnn::pfCand_gamma_dphi) = getValueLinear(dPhi(tau.polarP4(), pfCands.at(index_pf_gamma).polarP4()), - is_inner ? -0.1f : -0.5f, - is_inner ? 0.1f : 0.5f, - false); - get(dnn::pfCand_gamma_pvAssociationQuality) = - getValueLinear(candFunc::getPvAssocationQuality(gamma_cand), 0, 7, true); - get(dnn::pfCand_gamma_fromPV) = getValueLinear(candFunc::getFromPV(gamma_cand), 0, 3, true); - get(dnn::pfCand_gamma_puppiWeight) = is_inner ? getValue(candFunc::getPuppiWeight(gamma_cand, 0.9084110f)) - : getValue(candFunc::getPuppiWeight(gamma_cand, 0.4211567f)); - get(dnn::pfCand_gamma_puppiWeightNoLep) = is_inner - ? getValue(candFunc::getPuppiWeightNoLep(gamma_cand, 0.8857716f)) - : getValue(candFunc::getPuppiWeightNoLep(gamma_cand, 0.3822604f)); - get(dnn::pfCand_gamma_lostInnerHits) = getValue(candFunc::getLostInnerHits(gamma_cand, 0)); - get(dnn::pfCand_gamma_numberOfPixelHits) = - getValueLinear(candFunc::getNumberOfPixelHits(gamma_cand, 0), 0, 7, true); - get(dnn::pfCand_gamma_vertex_dx) = - getValueNorm(pfCands.at(index_pf_gamma).vertex().x() - pv.position().x(), 0.f, 0.0067f); - get(dnn::pfCand_gamma_vertex_dy) = - getValueNorm(pfCands.at(index_pf_gamma).vertex().y() - pv.position().y(), 0.f, 0.0069f); - get(dnn::pfCand_gamma_vertex_dz) = - getValueNorm(pfCands.at(index_pf_gamma).vertex().z() - pv.position().z(), 0.f, 0.0578f); - get(dnn::pfCand_gamma_vertex_dx_tauFL) = getValueNorm( - pfCands.at(index_pf_gamma).vertex().x() - pv.position().x() - tau_funcs.getFlightLength(tau, tau_index).x(), - 0.001f, - 0.9565f); - get(dnn::pfCand_gamma_vertex_dy_tauFL) = getValueNorm( - pfCands.at(index_pf_gamma).vertex().y() - pv.position().y() - tau_funcs.getFlightLength(tau, tau_index).y(), - 0.0008f, - 0.9592f); - get(dnn::pfCand_gamma_vertex_dz_tauFL) = getValueNorm( - pfCands.at(index_pf_gamma).vertex().z() - pv.position().z() - tau_funcs.getFlightLength(tau, tau_index).z(), - 0.0038f, - 2.154f); + get(dnn::pfCand_gamma_valid + fill_index_offset_PFg) = + sp.scale(valid_index_pf_gamma, dnn::pfCand_gamma_valid - PFg_index_offset); + get(dnn::pfCand_gamma_rel_pt + fill_index_offset_PFg) = + sp.scale(gamma_cand.polarP4().pt() / tau.polarP4().pt(), dnn::pfCand_gamma_rel_pt - PFg_index_offset); + get(dnn::pfCand_gamma_deta + fill_index_offset_PFg) = + sp.scale(gamma_cand.polarP4().eta() - tau.polarP4().eta(), dnn::pfCand_gamma_deta - PFg_index_offset); + get(dnn::pfCand_gamma_dphi + fill_index_offset_PFg) = + sp.scale(dPhi(tau.polarP4(), gamma_cand.polarP4()), dnn::pfCand_gamma_dphi - PFg_index_offset); + get(dnn::pfCand_gamma_pvAssociationQuality + fill_index_offset_PFg) = sp.scale( + candFunc::getPvAssocationQuality(gamma_cand), dnn::pfCand_gamma_pvAssociationQuality - PFg_index_offset); + get(dnn::pfCand_gamma_fromPV + fill_index_offset_PFg) = + sp.scale(candFunc::getFromPV(gamma_cand), dnn::pfCand_gamma_fromPV - PFg_index_offset); + get(dnn::pfCand_gamma_puppiWeight + fill_index_offset_PFg) = + is_inner ? sp.scale(candFunc::getPuppiWeight(gamma_cand, 0.9084110f), + dnn::pfCand_gamma_puppiWeight - PFg_index_offset) + : sp.scale(candFunc::getPuppiWeight(gamma_cand, 0.4211567f), + dnn::pfCand_gamma_puppiWeight - PFg_index_offset); + get(dnn::pfCand_gamma_puppiWeightNoLep + fill_index_offset_PFg) = + is_inner ? sp.scale(candFunc::getPuppiWeightNoLep(gamma_cand, 0.8857716f), + dnn::pfCand_gamma_puppiWeightNoLep - PFg_index_offset) + : sp.scale(candFunc::getPuppiWeightNoLep(gamma_cand, 0.3822604f), + dnn::pfCand_gamma_puppiWeightNoLep - PFg_index_offset); + get(dnn::pfCand_gamma_lostInnerHits + fill_index_offset_PFg) = + sp.scale(candFunc::getLostInnerHits(gamma_cand, 0), dnn::pfCand_gamma_lostInnerHits - PFg_index_offset); + get(dnn::pfCand_gamma_numberOfPixelHits + fill_index_offset_PFg) = sp.scale( + candFunc::getNumberOfPixelHits(gamma_cand, 0), dnn::pfCand_gamma_numberOfPixelHits - PFg_index_offset); + get(dnn::pfCand_gamma_vertex_dx + fill_index_offset_PFg) = + sp.scale(gamma_cand.vertex().x() - pv.position().x(), dnn::pfCand_gamma_vertex_dx - PFg_index_offset); + get(dnn::pfCand_gamma_vertex_dy + fill_index_offset_PFg) = + sp.scale(gamma_cand.vertex().y() - pv.position().y(), dnn::pfCand_gamma_vertex_dy - PFg_index_offset); + get(dnn::pfCand_gamma_vertex_dz + fill_index_offset_PFg) = + sp.scale(gamma_cand.vertex().z() - pv.position().z(), dnn::pfCand_gamma_vertex_dz - PFg_index_offset); + get(dnn::pfCand_gamma_vertex_dx_tauFL + fill_index_offset_PFg) = + sp.scale(gamma_cand.vertex().x() - pv.position().x() - tau_funcs.getFlightLength(tau, tau_index).x(), + dnn::pfCand_gamma_vertex_dx_tauFL - PFg_index_offset); + get(dnn::pfCand_gamma_vertex_dy_tauFL + fill_index_offset_PFg) = + sp.scale(gamma_cand.vertex().y() - pv.position().y() - tau_funcs.getFlightLength(tau, tau_index).y(), + dnn::pfCand_gamma_vertex_dy_tauFL - PFg_index_offset); + get(dnn::pfCand_gamma_vertex_dz_tauFL + fill_index_offset_PFg) = + sp.scale(gamma_cand.vertex().z() - pv.position().z() - tau_funcs.getFlightLength(tau, tau_index).z(), + dnn::pfCand_gamma_vertex_dz_tauFL - PFg_index_offset); const bool hasTrackDetails = candFunc::getHasTrackDetails(gamma_cand); if (hasTrackDetails) { - get(dnn::pfCand_gamma_hasTrackDetails) = hasTrackDetails; - get(dnn::pfCand_gamma_dxy) = getValueNorm(candFunc::getTauDxy(gamma_cand), 0.0004f, 0.882f); - get(dnn::pfCand_gamma_dxy_sig) = - getValueNorm(std::abs(candFunc::getTauDxy(gamma_cand)) / gamma_cand.dxyError(), 4.271f, 63.78f); - get(dnn::pfCand_gamma_dz) = getValueNorm(candFunc::getTauDz(gamma_cand), 0.0071f, 5.285f); - get(dnn::pfCand_gamma_dz_sig) = - getValueNorm(std::abs(candFunc::getTauDz(gamma_cand)) / gamma_cand.dzError(), 162.1f, 622.4f); - get(dnn::pfCand_gamma_track_chi2_ndof) = candFunc::getPseudoTrack(gamma_cand).ndof() > 0 - ? getValueNorm(candFunc::getPseudoTrack(gamma_cand).chi2() / - candFunc::getPseudoTrack(gamma_cand).ndof(), - 4.268f, - 15.47f) - : 0; - get(dnn::pfCand_gamma_track_ndof) = + get(dnn::pfCand_gamma_hasTrackDetails + fill_index_offset_PFg) = + sp.scale(hasTrackDetails, dnn::pfCand_gamma_hasTrackDetails - PFg_index_offset); + get(dnn::pfCand_gamma_dxy + fill_index_offset_PFg) = + sp.scale(candFunc::getTauDxy(gamma_cand), dnn::pfCand_gamma_dxy - PFg_index_offset); + get(dnn::pfCand_gamma_dxy_sig + fill_index_offset_PFg) = + sp.scale(std::abs(candFunc::getTauDxy(gamma_cand)) / gamma_cand.dxyError(), + dnn::pfCand_gamma_dxy_sig - PFg_index_offset); + get(dnn::pfCand_gamma_dz + fill_index_offset_PFg) = + sp.scale(candFunc::getTauDz(gamma_cand), dnn::pfCand_gamma_dz - PFg_index_offset); + get(dnn::pfCand_gamma_dz_sig + fill_index_offset_PFg) = + sp.scale(std::abs(candFunc::getTauDz(gamma_cand)) / gamma_cand.dzError(), + dnn::pfCand_gamma_dz_sig - PFg_index_offset); + get(dnn::pfCand_gamma_track_chi2_ndof + fill_index_offset_PFg) = + candFunc::getPseudoTrack(gamma_cand).ndof() > 0 + ? sp.scale(candFunc::getPseudoTrack(gamma_cand).chi2() / candFunc::getPseudoTrack(gamma_cand).ndof(), + dnn::pfCand_gamma_track_chi2_ndof - PFg_index_offset) + : 0; + get(dnn::pfCand_gamma_track_ndof + fill_index_offset_PFg) = candFunc::getPseudoTrack(gamma_cand).ndof() > 0 - ? getValueNorm(candFunc::getPseudoTrack(gamma_cand).ndof(), 12.25f, 4.774f) + ? sp.scale(candFunc::getPseudoTrack(gamma_cand).ndof(), dnn::pfCand_gamma_track_ndof - PFg_index_offset) : 0; } } if (valid_index_ele) { + const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft_e, is_inner)); size_t index_ele = cell_map.at(CellObjectType::Electron); + const auto& ele = electrons->at(index_ele); - get(dnn::ele_valid) = valid_index_ele; - get(dnn::ele_rel_pt) = getValueNorm(electrons->at(index_ele).polarP4().pt() / tau.polarP4().pt(), - is_inner ? 1.067f : 0.5111f, - is_inner ? 1.521f : 2.765f); - get(dnn::ele_deta) = getValueLinear(electrons->at(index_ele).polarP4().eta() - tau.polarP4().eta(), - is_inner ? -0.1f : -0.5f, - is_inner ? 0.1f : 0.5f, - false); - get(dnn::ele_dphi) = getValueLinear(dPhi(tau.polarP4(), electrons->at(index_ele).polarP4()), - is_inner ? -0.1f : -0.5f, - is_inner ? 0.1f : 0.5f, - false); + get(dnn::ele_valid + fill_index_offset_e) = sp.scale(valid_index_ele, dnn::ele_valid - e_index_offset); + get(dnn::ele_rel_pt + fill_index_offset_e) = + sp.scale(ele.polarP4().pt() / tau.polarP4().pt(), dnn::ele_rel_pt - e_index_offset); + get(dnn::ele_deta + fill_index_offset_e) = + sp.scale(ele.polarP4().eta() - tau.polarP4().eta(), dnn::ele_deta - e_index_offset); + get(dnn::ele_dphi + fill_index_offset_e) = + sp.scale(dPhi(tau.polarP4(), ele.polarP4()), dnn::ele_dphi - e_index_offset); float cc_ele_energy, cc_gamma_energy; int cc_n_gamma; - const bool cc_valid = - calculateElectronClusterVarsV2(electrons->at(index_ele), cc_ele_energy, cc_gamma_energy, cc_n_gamma); + const bool cc_valid = calculateElectronClusterVarsV2(ele, cc_ele_energy, cc_gamma_energy, cc_n_gamma); if (cc_valid) { - get(dnn::ele_cc_valid) = cc_valid; - get(dnn::ele_cc_ele_rel_energy) = - getValueNorm(cc_ele_energy / electrons->at(index_ele).polarP4().pt(), 1.729f, 1.644f); - get(dnn::ele_cc_gamma_rel_energy) = getValueNorm(cc_gamma_energy / cc_ele_energy, 0.1439f, 0.3284f); - get(dnn::ele_cc_n_gamma) = getValueNorm(cc_n_gamma, 1.794f, 2.079f); + get(dnn::ele_cc_valid + fill_index_offset_e) = sp.scale(cc_valid, dnn::ele_cc_valid - e_index_offset); + get(dnn::ele_cc_ele_rel_energy + fill_index_offset_e) = + sp.scale(cc_ele_energy / ele.polarP4().pt(), dnn::ele_cc_ele_rel_energy - e_index_offset); + get(dnn::ele_cc_gamma_rel_energy + fill_index_offset_e) = + sp.scale(cc_gamma_energy / cc_ele_energy, dnn::ele_cc_gamma_rel_energy - e_index_offset); + get(dnn::ele_cc_n_gamma + fill_index_offset_e) = sp.scale(cc_n_gamma, dnn::ele_cc_n_gamma - e_index_offset); } - get(dnn::ele_rel_trackMomentumAtVtx) = getValueNorm( - electrons->at(index_ele).trackMomentumAtVtx().R() / electrons->at(index_ele).polarP4().pt(), 1.531f, 1.424f); - get(dnn::ele_rel_trackMomentumAtCalo) = getValueNorm( - electrons->at(index_ele).trackMomentumAtCalo().R() / electrons->at(index_ele).polarP4().pt(), 1.531f, 1.424f); - get(dnn::ele_rel_trackMomentumOut) = getValueNorm( - electrons->at(index_ele).trackMomentumOut().R() / electrons->at(index_ele).polarP4().pt(), 0.7735f, 0.935f); - get(dnn::ele_rel_trackMomentumAtEleClus) = - getValueNorm(electrons->at(index_ele).trackMomentumAtEleClus().R() / electrons->at(index_ele).polarP4().pt(), - 0.7735f, - 0.935f); - get(dnn::ele_rel_trackMomentumAtVtxWithConstraint) = getValueNorm( - electrons->at(index_ele).trackMomentumAtVtxWithConstraint().R() / electrons->at(index_ele).polarP4().pt(), - 1.625f, - 1.581f); - get(dnn::ele_rel_ecalEnergy) = - getValueNorm(electrons->at(index_ele).ecalEnergy() / electrons->at(index_ele).polarP4().pt(), 1.993f, 1.308f); - get(dnn::ele_ecalEnergy_sig) = getValueNorm( - electrons->at(index_ele).ecalEnergy() / electrons->at(index_ele).ecalEnergyError(), 70.25f, 58.16f); - get(dnn::ele_eSuperClusterOverP) = getValueNorm(electrons->at(index_ele).eSuperClusterOverP(), 2.432f, 15.13f); - get(dnn::ele_eSeedClusterOverP) = getValueNorm(electrons->at(index_ele).eSeedClusterOverP(), 2.034f, 13.96f); - get(dnn::ele_eSeedClusterOverPout) = getValueNorm(electrons->at(index_ele).eSeedClusterOverPout(), 6.64f, 36.8f); - get(dnn::ele_eEleClusterOverPout) = getValueNorm(electrons->at(index_ele).eEleClusterOverPout(), 4.183f, 20.63f); - get(dnn::ele_deltaEtaSuperClusterTrackAtVtx) = - getValueNorm(electrons->at(index_ele).deltaEtaSuperClusterTrackAtVtx(), 0.f, 0.0363f); - get(dnn::ele_deltaEtaSeedClusterTrackAtCalo) = - getValueNorm(electrons->at(index_ele).deltaEtaSeedClusterTrackAtCalo(), -0.0001f, 0.0512f); - get(dnn::ele_deltaEtaEleClusterTrackAtCalo) = - getValueNorm(electrons->at(index_ele).deltaEtaEleClusterTrackAtCalo(), -0.0001f, 0.0541f); - get(dnn::ele_deltaPhiEleClusterTrackAtCalo) = - getValueNorm(electrons->at(index_ele).deltaPhiEleClusterTrackAtCalo(), 0.0002f, 0.0553f); - get(dnn::ele_deltaPhiSuperClusterTrackAtVtx) = - getValueNorm(electrons->at(index_ele).deltaPhiSuperClusterTrackAtVtx(), 0.0001f, 0.0523f); - get(dnn::ele_deltaPhiSeedClusterTrackAtCalo) = - getValueNorm(electrons->at(index_ele).deltaPhiSeedClusterTrackAtCalo(), 0.0004f, 0.0777f); - get(dnn::ele_mvaInput_earlyBrem) = getValue(electrons->at(index_ele).mvaInput().earlyBrem); - get(dnn::ele_mvaInput_lateBrem) = getValue(electrons->at(index_ele).mvaInput().lateBrem); - get(dnn::ele_mvaInput_sigmaEtaEta) = - getValueNorm(electrons->at(index_ele).mvaInput().sigmaEtaEta, 0.0008f, 0.0052f); - get(dnn::ele_mvaInput_hadEnergy) = getValueNorm(electrons->at(index_ele).mvaInput().hadEnergy, 14.04f, 69.48f); - get(dnn::ele_mvaInput_deltaEta) = getValueNorm(electrons->at(index_ele).mvaInput().deltaEta, 0.0099f, 0.0851f); - const auto& gsfTrack = electrons->at(index_ele).gsfTrack(); + get(dnn::ele_rel_trackMomentumAtVtx + fill_index_offset_e) = + sp.scale(ele.trackMomentumAtVtx().R() / ele.polarP4().pt(), dnn::ele_rel_trackMomentumAtVtx - e_index_offset); + get(dnn::ele_rel_trackMomentumAtCalo + fill_index_offset_e) = sp.scale( + ele.trackMomentumAtCalo().R() / ele.polarP4().pt(), dnn::ele_rel_trackMomentumAtCalo - e_index_offset); + get(dnn::ele_rel_trackMomentumOut + fill_index_offset_e) = + sp.scale(ele.trackMomentumOut().R() / ele.polarP4().pt(), dnn::ele_rel_trackMomentumOut - e_index_offset); + get(dnn::ele_rel_trackMomentumAtEleClus + fill_index_offset_e) = sp.scale( + ele.trackMomentumAtEleClus().R() / ele.polarP4().pt(), dnn::ele_rel_trackMomentumAtEleClus - e_index_offset); + get(dnn::ele_rel_trackMomentumAtVtxWithConstraint + fill_index_offset_e) = + sp.scale(ele.trackMomentumAtVtxWithConstraint().R() / ele.polarP4().pt(), + dnn::ele_rel_trackMomentumAtVtxWithConstraint - e_index_offset); + get(dnn::ele_rel_ecalEnergy + fill_index_offset_e) = + sp.scale(ele.ecalEnergy() / ele.polarP4().pt(), dnn::ele_rel_ecalEnergy - e_index_offset); + get(dnn::ele_ecalEnergy_sig + fill_index_offset_e) = + sp.scale(ele.ecalEnergy() / ele.ecalEnergyError(), dnn::ele_ecalEnergy_sig - e_index_offset); + get(dnn::ele_eSuperClusterOverP + fill_index_offset_e) = + sp.scale(ele.eSuperClusterOverP(), dnn::ele_eSuperClusterOverP - e_index_offset); + get(dnn::ele_eSeedClusterOverP + fill_index_offset_e) = + sp.scale(ele.eSeedClusterOverP(), dnn::ele_eSeedClusterOverP - e_index_offset); + get(dnn::ele_eSeedClusterOverPout + fill_index_offset_e) = + sp.scale(ele.eSeedClusterOverPout(), dnn::ele_eSeedClusterOverPout - e_index_offset); + get(dnn::ele_eEleClusterOverPout + fill_index_offset_e) = + sp.scale(ele.eEleClusterOverPout(), dnn::ele_eEleClusterOverPout - e_index_offset); + get(dnn::ele_deltaEtaSuperClusterTrackAtVtx + fill_index_offset_e) = + sp.scale(ele.deltaEtaSuperClusterTrackAtVtx(), dnn::ele_deltaEtaSuperClusterTrackAtVtx - e_index_offset); + get(dnn::ele_deltaEtaSeedClusterTrackAtCalo + fill_index_offset_e) = + sp.scale(ele.deltaEtaSeedClusterTrackAtCalo(), dnn::ele_deltaEtaSeedClusterTrackAtCalo - e_index_offset); + get(dnn::ele_deltaEtaEleClusterTrackAtCalo + fill_index_offset_e) = + sp.scale(ele.deltaEtaEleClusterTrackAtCalo(), dnn::ele_deltaEtaEleClusterTrackAtCalo - e_index_offset); + get(dnn::ele_deltaPhiEleClusterTrackAtCalo + fill_index_offset_e) = + sp.scale(ele.deltaPhiEleClusterTrackAtCalo(), dnn::ele_deltaPhiEleClusterTrackAtCalo - e_index_offset); + get(dnn::ele_deltaPhiSuperClusterTrackAtVtx + fill_index_offset_e) = + sp.scale(ele.deltaPhiSuperClusterTrackAtVtx(), dnn::ele_deltaPhiSuperClusterTrackAtVtx - e_index_offset); + get(dnn::ele_deltaPhiSeedClusterTrackAtCalo + fill_index_offset_e) = + sp.scale(ele.deltaPhiSeedClusterTrackAtCalo(), dnn::ele_deltaPhiSeedClusterTrackAtCalo - e_index_offset); + get(dnn::ele_mvaInput_earlyBrem + fill_index_offset_e) = + sp.scale(ele.mvaInput().earlyBrem, dnn::ele_mvaInput_earlyBrem - e_index_offset); + get(dnn::ele_mvaInput_lateBrem + fill_index_offset_e) = + sp.scale(ele.mvaInput().lateBrem, dnn::ele_mvaInput_lateBrem - e_index_offset); + get(dnn::ele_mvaInput_sigmaEtaEta + fill_index_offset_e) = + sp.scale(ele.mvaInput().sigmaEtaEta, dnn::ele_mvaInput_sigmaEtaEta - e_index_offset); + get(dnn::ele_mvaInput_hadEnergy + fill_index_offset_e) = + sp.scale(ele.mvaInput().hadEnergy, dnn::ele_mvaInput_hadEnergy - e_index_offset); + get(dnn::ele_mvaInput_deltaEta + fill_index_offset_e) = + sp.scale(ele.mvaInput().deltaEta, dnn::ele_mvaInput_deltaEta - e_index_offset); + const auto& gsfTrack = ele.gsfTrack(); if (gsfTrack.isNonnull()) { - get(dnn::ele_gsfTrack_normalizedChi2) = getValueNorm(gsfTrack->normalizedChi2(), 3.049f, 10.39f); - get(dnn::ele_gsfTrack_numberOfValidHits) = getValueNorm(gsfTrack->numberOfValidHits(), 16.52f, 2.806f); - get(dnn::ele_rel_gsfTrack_pt) = - getValueNorm(gsfTrack->pt() / electrons->at(index_ele).polarP4().pt(), 1.355f, 16.81f); - get(dnn::ele_gsfTrack_pt_sig) = getValueNorm(gsfTrack->pt() / gsfTrack->ptError(), 5.046f, 3.119f); + get(dnn::ele_gsfTrack_normalizedChi2 + fill_index_offset_e) = + sp.scale(gsfTrack->normalizedChi2(), dnn::ele_gsfTrack_normalizedChi2 - e_index_offset); + get(dnn::ele_gsfTrack_numberOfValidHits + fill_index_offset_e) = + sp.scale(gsfTrack->numberOfValidHits(), dnn::ele_gsfTrack_numberOfValidHits - e_index_offset); + get(dnn::ele_rel_gsfTrack_pt + fill_index_offset_e) = + sp.scale(gsfTrack->pt() / ele.polarP4().pt(), dnn::ele_rel_gsfTrack_pt - e_index_offset); + get(dnn::ele_gsfTrack_pt_sig + fill_index_offset_e) = + sp.scale(gsfTrack->pt() / gsfTrack->ptError(), dnn::ele_gsfTrack_pt_sig - e_index_offset); } - const auto& closestCtfTrack = electrons->at(index_ele).closestCtfTrackRef(); + const auto& closestCtfTrack = ele.closestCtfTrackRef(); const bool has_closestCtfTrack = closestCtfTrack.isNonnull(); if (has_closestCtfTrack) { - get(dnn::ele_has_closestCtfTrack) = has_closestCtfTrack; - get(dnn::ele_closestCtfTrack_normalizedChi2) = getValueNorm(closestCtfTrack->normalizedChi2(), 2.411f, 6.98f); - get(dnn::ele_closestCtfTrack_numberOfValidHits) = - getValueNorm(closestCtfTrack->numberOfValidHits(), 15.16f, 5.26f); + get(dnn::ele_has_closestCtfTrack + fill_index_offset_e) = + sp.scale(has_closestCtfTrack, dnn::ele_has_closestCtfTrack - e_index_offset); + get(dnn::ele_closestCtfTrack_normalizedChi2 + fill_index_offset_e) = + sp.scale(closestCtfTrack->normalizedChi2(), dnn::ele_closestCtfTrack_normalizedChi2 - e_index_offset); + get(dnn::ele_closestCtfTrack_numberOfValidHits + fill_index_offset_e) = + sp.scale(closestCtfTrack->numberOfValidHits(), dnn::ele_closestCtfTrack_numberOfValidHits - e_index_offset); } } } @@ -2188,7 +2295,15 @@ class DeepTauId : public deep_tau::DeepTauBase { const Cell& cell_map, TauFunc tau_funcs, bool is_inner) { - namespace dnn = dnn_inputs_2017_v2::MuonBlockInputs; + namespace dnn = dnn_inputs_v2::MuonBlockInputs; + namespace sc = deep_tau::Scaling; + sc::FeatureT ft_global = sc::FeatureT::GridGlobal; + sc::FeatureT ft_PFmu = sc::FeatureT::PfCand_muon; + sc::FeatureT ft_mu = sc::FeatureT::Muon; + + // needed to remap indices from scaling vectors to those from dnn_inputs_v2::MuonBlockInputs + int PFmu_index_offset = scalingParamsMap_->at(std::make_pair(ft_global, false)).mean_.size(); + int mu_index_offset = PFmu_index_offset + scalingParamsMap_->at(std::make_pair(ft_PFmu, false)).mean_.size(); tensorflow::Tensor& inputs = *muonTensor_.at(is_inner); @@ -2198,130 +2313,122 @@ class DeepTauId : public deep_tau::DeepTauBase { const bool valid_index_muon = cell_map.count(CellObjectType::Muon); if (!cell_map.empty()) { - get(dnn::rho) = getValueNorm(rho, 21.49f, 9.713f); - get(dnn::tau_pt) = getValueLinear(tau.polarP4().pt(), 20.f, 1000.f, true); - get(dnn::tau_eta) = getValueLinear(tau.polarP4().eta(), -2.3f, 2.3f, false); - get(dnn::tau_inside_ecal_crack) = getValue(isInEcalCrack(tau.polarP4().eta())); + const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft_global, false)); + get(dnn::rho) = sp.scale(rho, dnn::rho); + get(dnn::tau_pt) = sp.scale(tau.polarP4().pt(), dnn::tau_pt); + get(dnn::tau_eta) = sp.scale(tau.polarP4().eta(), dnn::tau_eta); + get(dnn::tau_inside_ecal_crack) = sp.scale(isInEcalCrack(tau.polarP4().eta()), dnn::tau_inside_ecal_crack); } if (valid_index_pf_muon) { + const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft_PFmu, is_inner)); size_t index_pf_muon = cell_map.at(CellObjectType::PfCand_muon); const auto& muon_cand = dynamic_cast(pfCands.at(index_pf_muon)); - get(dnn::pfCand_muon_valid) = valid_index_pf_muon; - get(dnn::pfCand_muon_rel_pt) = getValueNorm(pfCands.at(index_pf_muon).polarP4().pt() / tau.polarP4().pt(), - is_inner ? 0.9509f : 0.0861f, - is_inner ? 0.4294f : 0.4065f); - get(dnn::pfCand_muon_deta) = getValueLinear(pfCands.at(index_pf_muon).polarP4().eta() - tau.polarP4().eta(), - is_inner ? -0.1f : -0.5f, - is_inner ? 0.1f : 0.5f, - false); - get(dnn::pfCand_muon_dphi) = getValueLinear(dPhi(tau.polarP4(), pfCands.at(index_pf_muon).polarP4()), - is_inner ? -0.1f : -0.5f, - is_inner ? 0.1f : 0.5f, - false); - get(dnn::pfCand_muon_pvAssociationQuality) = - getValueLinear(candFunc::getPvAssocationQuality(muon_cand), 0, 7, true); - get(dnn::pfCand_muon_fromPV) = getValueLinear(candFunc::getFromPV(muon_cand), 0, 3, true); - get(dnn::pfCand_muon_puppiWeight) = is_inner ? getValue(candFunc::getPuppiWeight(muon_cand, 0.9786588f)) - : getValue(candFunc::getPuppiWeight(muon_cand, 0.8132477f)); - get(dnn::pfCand_muon_charge) = getValue(muon_cand.charge()); - get(dnn::pfCand_muon_lostInnerHits) = getValue(candFunc::getLostInnerHits(muon_cand, 0)); - get(dnn::pfCand_muon_numberOfPixelHits) = - getValueLinear(candFunc::getNumberOfPixelHits(muon_cand, 0), 0, 11, true); + get(dnn::pfCand_muon_valid) = sp.scale(valid_index_pf_muon, dnn::pfCand_muon_valid - PFmu_index_offset); + get(dnn::pfCand_muon_rel_pt) = + sp.scale(muon_cand.polarP4().pt() / tau.polarP4().pt(), dnn::pfCand_muon_rel_pt - PFmu_index_offset); + get(dnn::pfCand_muon_deta) = + sp.scale(muon_cand.polarP4().eta() - tau.polarP4().eta(), dnn::pfCand_muon_deta - PFmu_index_offset); + get(dnn::pfCand_muon_dphi) = + sp.scale(dPhi(tau.polarP4(), muon_cand.polarP4()), dnn::pfCand_muon_dphi - PFmu_index_offset); + get(dnn::pfCand_muon_pvAssociationQuality) = sp.scale( + candFunc::getPvAssocationQuality(muon_cand), dnn::pfCand_muon_pvAssociationQuality - PFmu_index_offset); + get(dnn::pfCand_muon_fromPV) = + sp.scale(candFunc::getFromPV(muon_cand), dnn::pfCand_muon_fromPV - PFmu_index_offset); + get(dnn::pfCand_muon_puppiWeight) = is_inner ? sp.scale(candFunc::getPuppiWeight(muon_cand, 0.9786588f), + dnn::pfCand_muon_puppiWeight - PFmu_index_offset) + : sp.scale(candFunc::getPuppiWeight(muon_cand, 0.8132477f), + dnn::pfCand_muon_puppiWeight - PFmu_index_offset); + get(dnn::pfCand_muon_charge) = sp.scale(muon_cand.charge(), dnn::pfCand_muon_charge - PFmu_index_offset); + get(dnn::pfCand_muon_lostInnerHits) = + sp.scale(candFunc::getLostInnerHits(muon_cand, 0), dnn::pfCand_muon_lostInnerHits - PFmu_index_offset); + get(dnn::pfCand_muon_numberOfPixelHits) = sp.scale(candFunc::getNumberOfPixelHits(muon_cand, 0), + dnn::pfCand_muon_numberOfPixelHits - PFmu_index_offset); get(dnn::pfCand_muon_vertex_dx) = - getValueNorm(pfCands.at(index_pf_muon).vertex().x() - pv.position().x(), -0.0007f, 0.6869f); + sp.scale(muon_cand.vertex().x() - pv.position().x(), dnn::pfCand_muon_vertex_dx - PFmu_index_offset); get(dnn::pfCand_muon_vertex_dy) = - getValueNorm(pfCands.at(index_pf_muon).vertex().y() - pv.position().y(), 0.0001f, 0.6784f); + sp.scale(muon_cand.vertex().y() - pv.position().y(), dnn::pfCand_muon_vertex_dy - PFmu_index_offset); get(dnn::pfCand_muon_vertex_dz) = - getValueNorm(pfCands.at(index_pf_muon).vertex().z() - pv.position().z(), -0.0117f, 4.097f); - get(dnn::pfCand_muon_vertex_dx_tauFL) = getValueNorm( - pfCands.at(index_pf_muon).vertex().x() - pv.position().x() - tau_funcs.getFlightLength(tau, tau_index).x(), - -0.0001f, - 0.8642f); - get(dnn::pfCand_muon_vertex_dy_tauFL) = getValueNorm( - pfCands.at(index_pf_muon).vertex().y() - pv.position().y() - tau_funcs.getFlightLength(tau, tau_index).y(), - 0.0004f, - 0.8561f); - get(dnn::pfCand_muon_vertex_dz_tauFL) = getValueNorm( - pfCands.at(index_pf_muon).vertex().z() - pv.position().z() - tau_funcs.getFlightLength(tau, tau_index).z(), - -0.0118f, - 4.405f); + sp.scale(muon_cand.vertex().z() - pv.position().z(), dnn::pfCand_muon_vertex_dz - PFmu_index_offset); + get(dnn::pfCand_muon_vertex_dx_tauFL) = + sp.scale(muon_cand.vertex().x() - pv.position().x() - tau_funcs.getFlightLength(tau, tau_index).x(), + dnn::pfCand_muon_vertex_dx_tauFL - PFmu_index_offset); + get(dnn::pfCand_muon_vertex_dy_tauFL) = + sp.scale(muon_cand.vertex().y() - pv.position().y() - tau_funcs.getFlightLength(tau, tau_index).y(), + dnn::pfCand_muon_vertex_dy_tauFL - PFmu_index_offset); + get(dnn::pfCand_muon_vertex_dz_tauFL) = + sp.scale(muon_cand.vertex().z() - pv.position().z() - tau_funcs.getFlightLength(tau, tau_index).z(), + dnn::pfCand_muon_vertex_dz_tauFL - PFmu_index_offset); const bool hasTrackDetails = candFunc::getHasTrackDetails(muon_cand); if (hasTrackDetails) { - get(dnn::pfCand_muon_hasTrackDetails) = hasTrackDetails; - get(dnn::pfCand_muon_dxy) = getValueNorm(candFunc::getTauDxy(muon_cand), -0.0045f, 0.9655f); - get(dnn::pfCand_muon_dxy_sig) = - getValueNorm(std::abs(candFunc::getTauDxy(muon_cand)) / muon_cand.dxyError(), 4.575f, 42.36f); - get(dnn::pfCand_muon_dz) = getValueNorm(candFunc::getTauDz(muon_cand), -0.0117f, 4.097f); - get(dnn::pfCand_muon_dz_sig) = - getValueNorm(std::abs(candFunc::getTauDz(muon_cand)) / muon_cand.dzError(), 80.37f, 343.3f); - get(dnn::pfCand_muon_track_chi2_ndof) = getValueNorm( - candFunc::getPseudoTrack(muon_cand).chi2() / candFunc::getPseudoTrack(muon_cand).ndof(), 0.69f, 1.711f); - get(dnn::pfCand_muon_track_ndof) = getValueNorm(candFunc::getPseudoTrack(muon_cand).ndof(), 17.5f, 5.11f); + get(dnn::pfCand_muon_hasTrackDetails) = + sp.scale(hasTrackDetails, dnn::pfCand_muon_hasTrackDetails - PFmu_index_offset); + get(dnn::pfCand_muon_dxy) = sp.scale(candFunc::getTauDxy(muon_cand), dnn::pfCand_muon_dxy - PFmu_index_offset); + get(dnn::pfCand_muon_dxy_sig) = sp.scale(std::abs(candFunc::getTauDxy(muon_cand)) / muon_cand.dxyError(), + dnn::pfCand_muon_dxy_sig - PFmu_index_offset); + get(dnn::pfCand_muon_dz) = sp.scale(candFunc::getTauDz(muon_cand), dnn::pfCand_muon_dz - PFmu_index_offset); + get(dnn::pfCand_muon_dz_sig) = sp.scale(std::abs(candFunc::getTauDz(muon_cand)) / muon_cand.dzError(), + dnn::pfCand_muon_dz_sig - PFmu_index_offset); + get(dnn::pfCand_muon_track_chi2_ndof) = + candFunc::getPseudoTrack(muon_cand).ndof() > 0 + ? sp.scale(candFunc::getPseudoTrack(muon_cand).chi2() / candFunc::getPseudoTrack(muon_cand).ndof(), + dnn::pfCand_muon_track_chi2_ndof - PFmu_index_offset) + : 0; + get(dnn::pfCand_muon_track_ndof) = + candFunc::getPseudoTrack(muon_cand).ndof() > 0 + ? sp.scale(candFunc::getPseudoTrack(muon_cand).ndof(), dnn::pfCand_muon_track_ndof - PFmu_index_offset) + : 0; } } if (valid_index_muon) { + const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft_mu, is_inner)); size_t index_muon = cell_map.at(CellObjectType::Muon); + const auto& muon = muons->at(index_muon); - get(dnn::muon_valid) = valid_index_muon; - get(dnn::muon_rel_pt) = getValueNorm(muons->at(index_muon).polarP4().pt() / tau.polarP4().pt(), - is_inner ? 0.7966f : 0.2678f, - is_inner ? 3.402f : 3.592f); - get(dnn::muon_deta) = getValueLinear(muons->at(index_muon).polarP4().eta() - tau.polarP4().eta(), - is_inner ? -0.1f : -0.5f, - is_inner ? 0.1f : 0.5f, - false); - get(dnn::muon_dphi) = getValueLinear(dPhi(tau.polarP4(), muons->at(index_muon).polarP4()), - is_inner ? -0.1f : -0.5f, - is_inner ? 0.1f : 0.5f, - false); - get(dnn::muon_dxy) = getValueNorm(muons->at(index_muon).dB(pat::Muon::PV2D), 0.0019f, 1.039f); + get(dnn::muon_valid) = sp.scale(valid_index_muon, dnn::muon_valid - mu_index_offset); + get(dnn::muon_rel_pt) = sp.scale(muon.polarP4().pt() / tau.polarP4().pt(), dnn::muon_rel_pt - mu_index_offset); + get(dnn::muon_deta) = sp.scale(muon.polarP4().eta() - tau.polarP4().eta(), dnn::muon_deta - mu_index_offset); + get(dnn::muon_dphi) = sp.scale(dPhi(tau.polarP4(), muon.polarP4()), dnn::muon_dphi - mu_index_offset); + get(dnn::muon_dxy) = sp.scale(muon.dB(pat::Muon::PV2D), dnn::muon_dxy - mu_index_offset); get(dnn::muon_dxy_sig) = - getValueNorm(std::abs(muons->at(index_muon).dB(pat::Muon::PV2D)) / muons->at(index_muon).edB(pat::Muon::PV2D), - 8.98f, - 71.17f); + sp.scale(std::abs(muon.dB(pat::Muon::PV2D)) / muon.edB(pat::Muon::PV2D), dnn::muon_dxy_sig - mu_index_offset); - const bool normalizedChi2_valid = - muons->at(index_muon).globalTrack().isNonnull() && muons->at(index_muon).normChi2() >= 0; + const bool normalizedChi2_valid = muon.globalTrack().isNonnull() && muon.normChi2() >= 0; if (normalizedChi2_valid) { - get(dnn::muon_normalizedChi2_valid) = normalizedChi2_valid; - get(dnn::muon_normalizedChi2) = getValueNorm(muons->at(index_muon).normChi2(), 21.52f, 265.8f); - if (muons->at(index_muon).innerTrack().isNonnull()) - get(dnn::muon_numberOfValidHits) = getValueNorm(muons->at(index_muon).numberOfValidHits(), 21.84f, 10.59f); + get(dnn::muon_normalizedChi2_valid) = + sp.scale(normalizedChi2_valid, dnn::muon_normalizedChi2_valid - mu_index_offset); + get(dnn::muon_normalizedChi2) = sp.scale(muon.normChi2(), dnn::muon_normalizedChi2 - mu_index_offset); + if (muon.innerTrack().isNonnull()) + get(dnn::muon_numberOfValidHits) = + sp.scale(muon.numberOfValidHits(), dnn::muon_numberOfValidHits - mu_index_offset); } - get(dnn::muon_segmentCompatibility) = getValue(muons->at(index_muon).segmentCompatibility()); - get(dnn::muon_caloCompatibility) = getValue(muons->at(index_muon).caloCompatibility()); + get(dnn::muon_segmentCompatibility) = + sp.scale(muon.segmentCompatibility(), dnn::muon_segmentCompatibility - mu_index_offset); + get(dnn::muon_caloCompatibility) = + sp.scale(muon.caloCompatibility(), dnn::muon_caloCompatibility - mu_index_offset); - const bool pfEcalEnergy_valid = muons->at(index_muon).pfEcalEnergy() >= 0; + const bool pfEcalEnergy_valid = muon.pfEcalEnergy() >= 0; if (pfEcalEnergy_valid) { - get(dnn::muon_pfEcalEnergy_valid) = pfEcalEnergy_valid; + get(dnn::muon_pfEcalEnergy_valid) = + sp.scale(pfEcalEnergy_valid, dnn::muon_pfEcalEnergy_valid - mu_index_offset); get(dnn::muon_rel_pfEcalEnergy) = - getValueNorm(muons->at(index_muon).pfEcalEnergy() / muons->at(index_muon).polarP4().pt(), 0.2273f, 0.4865f); + sp.scale(muon.pfEcalEnergy() / muon.polarP4().pt(), dnn::muon_rel_pfEcalEnergy - mu_index_offset); } - MuonHitMatchV2 hit_match(muons->at(index_muon)); + MuonHitMatchV2 hit_match(muon); static const std::map> muonMatchHitVars = { {MuonSubdetId::DT, {dnn::muon_n_matches_DT_1, dnn::muon_n_hits_DT_1}}, {MuonSubdetId::CSC, {dnn::muon_n_matches_CSC_1, dnn::muon_n_hits_CSC_1}}, {MuonSubdetId::RPC, {dnn::muon_n_matches_RPC_1, dnn::muon_n_hits_RPC_1}}}; - static const std::map> muonMatchVarLimits = { - {MuonSubdetId::DT, {2, 2, 2, 2}}, {MuonSubdetId::CSC, {6, 2, 2, 2}}, {MuonSubdetId::RPC, {7, 6, 4, 4}}}; - - static const std::map> muonHitVarLimits = {{MuonSubdetId::DT, {12, 12, 12, 8}}, - {MuonSubdetId::CSC, {24, 12, 12, 12}}, - {MuonSubdetId::RPC, {4, 4, 2, 2}}}; - for (int subdet : hit_match.MuonHitMatchV2::consideredSubdets()) { const auto& matchHitVar = muonMatchHitVars.at(subdet); - const auto& matchLimits = muonMatchVarLimits.at(subdet); - const auto& hitLimits = muonHitVarLimits.at(subdet); for (int station = MuonHitMatchV2::first_station_id; station <= MuonHitMatchV2::last_station_id; ++station) { const unsigned n_matches = hit_match.nMatches(subdet, station); const unsigned n_hits = hit_match.nHits(subdet, station); - get(matchHitVar.first + station - 1) = getValueLinear(n_matches, 0, matchLimits.at(station - 1), true); - get(matchHitVar.second + station - 1) = getValueLinear(n_hits, 0, hitLimits.at(station - 1), true); + get(matchHitVar.first + station - 1) = sp.scale(n_matches, matchHitVar.first + station - 1 - mu_index_offset); + get(matchHitVar.second + station - 1) = sp.scale(n_hits, matchHitVar.second + station - 1 - mu_index_offset); } } } @@ -2338,7 +2445,15 @@ class DeepTauId : public deep_tau::DeepTauBase { const Cell& cell_map, TauFunc tau_funcs, bool is_inner) { - namespace dnn = dnn_inputs_2017_v2::HadronBlockInputs; + namespace dnn = dnn_inputs_v2::HadronBlockInputs; + namespace sc = deep_tau::Scaling; + sc::FeatureT ft_global = sc::FeatureT::GridGlobal; + sc::FeatureT ft_PFchH = sc::FeatureT::PfCand_chHad; + sc::FeatureT ft_PFnH = sc::FeatureT::PfCand_nHad; + + // needed to remap indices from scaling vectors to those from dnn_inputs_v2::HadronBlockInputs + int PFchH_index_offset = scalingParamsMap_->at(std::make_pair(ft_global, false)).mean_.size(); + int PFnH_index_offset = PFchH_index_offset + scalingParamsMap_->at(std::make_pair(ft_PFchH, false)).mean_.size(); tensorflow::Tensor& inputs = *hadronsTensor_.at(is_inner); @@ -2348,107 +2463,113 @@ class DeepTauId : public deep_tau::DeepTauBase { const bool valid_nH = cell_map.count(CellObjectType::PfCand_neutralHadron); if (!cell_map.empty()) { - get(dnn::rho) = getValueNorm(rho, 21.49f, 9.713f); - get(dnn::tau_pt) = getValueLinear(tau.polarP4().pt(), 20.f, 1000.f, true); - get(dnn::tau_eta) = getValueLinear(tau.polarP4().eta(), -2.3f, 2.3f, false); - get(dnn::tau_inside_ecal_crack) = getValue(isInEcalCrack(tau.polarP4().eta())); + const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft_global, false)); + get(dnn::rho) = sp.scale(rho, dnn::rho); + get(dnn::tau_pt) = sp.scale(tau.polarP4().pt(), dnn::tau_pt); + get(dnn::tau_eta) = sp.scale(tau.polarP4().eta(), dnn::tau_eta); + get(dnn::tau_inside_ecal_crack) = sp.scale(isInEcalCrack(tau.polarP4().eta()), dnn::tau_inside_ecal_crack); } if (valid_chH) { + const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft_PFchH, is_inner)); size_t index_chH = cell_map.at(CellObjectType::PfCand_chargedHadron); const auto& chH_cand = dynamic_cast(pfCands.at(index_chH)); - get(dnn::pfCand_chHad_valid) = valid_chH; - get(dnn::pfCand_chHad_rel_pt) = getValueNorm(pfCands.at(index_chH).polarP4().pt() / tau.polarP4().pt(), - is_inner ? 0.2564f : 0.0194f, - is_inner ? 0.8607f : 0.1865f); - get(dnn::pfCand_chHad_deta) = getValueLinear(pfCands.at(index_chH).polarP4().eta() - tau.polarP4().eta(), - is_inner ? -0.1f : -0.5f, - is_inner ? 0.1f : 0.5f, - false); - get(dnn::pfCand_chHad_dphi) = getValueLinear(dPhi(tau.polarP4(), pfCands.at(index_chH).polarP4()), - is_inner ? -0.1f : -0.5f, - is_inner ? 0.1f : 0.5f, - false); + get(dnn::pfCand_chHad_valid) = sp.scale(valid_chH, dnn::pfCand_chHad_valid - PFchH_index_offset); + get(dnn::pfCand_chHad_rel_pt) = + sp.scale(chH_cand.polarP4().pt() / tau.polarP4().pt(), dnn::pfCand_chHad_rel_pt - PFchH_index_offset); + get(dnn::pfCand_chHad_deta) = + sp.scale(chH_cand.polarP4().eta() - tau.polarP4().eta(), dnn::pfCand_chHad_deta - PFchH_index_offset); + get(dnn::pfCand_chHad_dphi) = + sp.scale(dPhi(tau.polarP4(), chH_cand.polarP4()), dnn::pfCand_chHad_dphi - PFchH_index_offset); get(dnn::pfCand_chHad_leadChargedHadrCand) = - getValue(&chH_cand == dynamic_cast(tau.leadChargedHadrCand().get())); - get(dnn::pfCand_chHad_pvAssociationQuality) = - getValueLinear(candFunc::getPvAssocationQuality(chH_cand), 0, 7, true); - get(dnn::pfCand_chHad_fromPV) = getValueLinear(candFunc::getFromPV(chH_cand), 0, 3, true); + sp.scale(&chH_cand == dynamic_cast(tau.leadChargedHadrCand().get()), + dnn::pfCand_chHad_leadChargedHadrCand - PFchH_index_offset); + get(dnn::pfCand_chHad_pvAssociationQuality) = sp.scale( + candFunc::getPvAssocationQuality(chH_cand), dnn::pfCand_chHad_pvAssociationQuality - PFchH_index_offset); + get(dnn::pfCand_chHad_fromPV) = + sp.scale(candFunc::getFromPV(chH_cand), dnn::pfCand_chHad_fromPV - PFchH_index_offset); const float default_chH_pw_inner = 0.7614090f; const float default_chH_pw_outer = 0.1974930f; - get(dnn::pfCand_chHad_puppiWeight) = is_inner - ? getValue(candFunc::getPuppiWeight(chH_cand, default_chH_pw_inner)) - : getValue(candFunc::getPuppiWeight(chH_cand, default_chH_pw_outer)); + get(dnn::pfCand_chHad_puppiWeight) = is_inner ? sp.scale(candFunc::getPuppiWeight(chH_cand, default_chH_pw_inner), + dnn::pfCand_chHad_puppiWeight - PFchH_index_offset) + : sp.scale(candFunc::getPuppiWeight(chH_cand, default_chH_pw_outer), + dnn::pfCand_chHad_puppiWeight - PFchH_index_offset); get(dnn::pfCand_chHad_puppiWeightNoLep) = - is_inner ? getValue(candFunc::getPuppiWeightNoLep(chH_cand, default_chH_pw_inner)) - : getValue(candFunc::getPuppiWeightNoLep(chH_cand, default_chH_pw_outer)); - get(dnn::pfCand_chHad_charge) = getValue(chH_cand.charge()); - get(dnn::pfCand_chHad_lostInnerHits) = getValue(candFunc::getLostInnerHits(chH_cand, 0)); - get(dnn::pfCand_chHad_numberOfPixelHits) = - getValueLinear(candFunc::getNumberOfPixelHits(chH_cand, 0), 0, 12, true); + is_inner ? sp.scale(candFunc::getPuppiWeightNoLep(chH_cand, default_chH_pw_inner), + dnn::pfCand_chHad_puppiWeightNoLep - PFchH_index_offset) + : sp.scale(candFunc::getPuppiWeightNoLep(chH_cand, default_chH_pw_outer), + dnn::pfCand_chHad_puppiWeightNoLep - PFchH_index_offset); + get(dnn::pfCand_chHad_charge) = sp.scale(chH_cand.charge(), dnn::pfCand_chHad_charge - PFchH_index_offset); + get(dnn::pfCand_chHad_lostInnerHits) = + sp.scale(candFunc::getLostInnerHits(chH_cand, 0), dnn::pfCand_chHad_lostInnerHits - PFchH_index_offset); + get(dnn::pfCand_chHad_numberOfPixelHits) = sp.scale(candFunc::getNumberOfPixelHits(chH_cand, 0), + dnn::pfCand_chHad_numberOfPixelHits - PFchH_index_offset); get(dnn::pfCand_chHad_vertex_dx) = - getValueNorm(pfCands.at(index_chH).vertex().x() - pv.position().x(), 0.0005f, 1.735f); + sp.scale(chH_cand.vertex().x() - pv.position().x(), dnn::pfCand_chHad_vertex_dx - PFchH_index_offset); get(dnn::pfCand_chHad_vertex_dy) = - getValueNorm(pfCands.at(index_chH).vertex().y() - pv.position().y(), -0.0008f, 1.752f); + sp.scale(chH_cand.vertex().y() - pv.position().y(), dnn::pfCand_chHad_vertex_dy - PFchH_index_offset); get(dnn::pfCand_chHad_vertex_dz) = - getValueNorm(pfCands.at(index_chH).vertex().z() - pv.position().z(), -0.0201f, 8.333f); - get(dnn::pfCand_chHad_vertex_dx_tauFL) = getValueNorm( - pfCands.at(index_chH).vertex().x() - pv.position().x() - tau_funcs.getFlightLength(tau, tau_index).x(), - -0.0014f, - 1.93f); - get(dnn::pfCand_chHad_vertex_dy_tauFL) = getValueNorm( - pfCands.at(index_chH).vertex().y() - pv.position().y() - tau_funcs.getFlightLength(tau, tau_index).y(), - 0.0022f, - 1.948f); - get(dnn::pfCand_chHad_vertex_dz_tauFL) = getValueNorm( - pfCands.at(index_chH).vertex().z() - pv.position().z() - tau_funcs.getFlightLength(tau, tau_index).z(), - -0.0138f, - 8.622f); + sp.scale(chH_cand.vertex().z() - pv.position().z(), dnn::pfCand_chHad_vertex_dz - PFchH_index_offset); + get(dnn::pfCand_chHad_vertex_dx_tauFL) = + sp.scale(chH_cand.vertex().x() - pv.position().x() - tau_funcs.getFlightLength(tau, tau_index).x(), + dnn::pfCand_chHad_vertex_dx_tauFL - PFchH_index_offset); + get(dnn::pfCand_chHad_vertex_dy_tauFL) = + sp.scale(chH_cand.vertex().y() - pv.position().y() - tau_funcs.getFlightLength(tau, tau_index).y(), + dnn::pfCand_chHad_vertex_dy_tauFL - PFchH_index_offset); + get(dnn::pfCand_chHad_vertex_dz_tauFL) = + sp.scale(chH_cand.vertex().z() - pv.position().z() - tau_funcs.getFlightLength(tau, tau_index).z(), + dnn::pfCand_chHad_vertex_dz_tauFL - PFchH_index_offset); const bool hasTrackDetails = candFunc::getHasTrackDetails(chH_cand); if (hasTrackDetails) { - get(dnn::pfCand_chHad_hasTrackDetails) = hasTrackDetails; - get(dnn::pfCand_chHad_dxy) = getValueNorm(candFunc::getTauDxy(chH_cand), -0.012f, 2.386f); - get(dnn::pfCand_chHad_dxy_sig) = - getValueNorm(std::abs(candFunc::getTauDxy(chH_cand)) / chH_cand.dxyError(), 6.417f, 36.28f); - get(dnn::pfCand_chHad_dz) = getValueNorm(candFunc::getTauDz(chH_cand), -0.0246f, 7.618f); - get(dnn::pfCand_chHad_dz_sig) = - getValueNorm(std::abs(candFunc::getTauDz(chH_cand)) / chH_cand.dzError(), 301.3f, 491.1f); + get(dnn::pfCand_chHad_hasTrackDetails) = + sp.scale(hasTrackDetails, dnn::pfCand_chHad_hasTrackDetails - PFchH_index_offset); + get(dnn::pfCand_chHad_dxy) = + sp.scale(candFunc::getTauDxy(chH_cand), dnn::pfCand_chHad_dxy - PFchH_index_offset); + get(dnn::pfCand_chHad_dxy_sig) = sp.scale(std::abs(candFunc::getTauDxy(chH_cand)) / chH_cand.dxyError(), + dnn::pfCand_chHad_dxy_sig - PFchH_index_offset); + get(dnn::pfCand_chHad_dz) = sp.scale(candFunc::getTauDz(chH_cand), dnn::pfCand_chHad_dz - PFchH_index_offset); + get(dnn::pfCand_chHad_dz_sig) = sp.scale(std::abs(candFunc::getTauDz(chH_cand)) / chH_cand.dzError(), + dnn::pfCand_chHad_dz_sig - PFchH_index_offset); get(dnn::pfCand_chHad_track_chi2_ndof) = candFunc::getPseudoTrack(chH_cand).ndof() > 0 - ? getValueNorm(candFunc::getPseudoTrack(chH_cand).chi2() / candFunc::getPseudoTrack(chH_cand).ndof(), - 0.7876f, - 3.694f) + ? sp.scale(candFunc::getPseudoTrack(chH_cand).chi2() / candFunc::getPseudoTrack(chH_cand).ndof(), + dnn::pfCand_chHad_track_chi2_ndof - PFchH_index_offset) : 0; get(dnn::pfCand_chHad_track_ndof) = candFunc::getPseudoTrack(chH_cand).ndof() > 0 - ? getValueNorm(candFunc::getPseudoTrack(chH_cand).ndof(), 13.92f, 6.581f) + ? sp.scale(candFunc::getPseudoTrack(chH_cand).ndof(), dnn::pfCand_chHad_track_ndof - PFchH_index_offset) : 0; } float hcal_fraction = candFunc::getHCalFraction(chH_cand, disable_hcalFraction_workaround_); - get(dnn::pfCand_chHad_hcalFraction) = getValue(hcal_fraction); - get(dnn::pfCand_chHad_rawCaloFraction) = getValueLinear(candFunc::getRawCaloFraction(chH_cand), 0.f, 2.6f, true); + get(dnn::pfCand_chHad_hcalFraction) = + sp.scale(hcal_fraction, dnn::pfCand_chHad_hcalFraction - PFchH_index_offset); + get(dnn::pfCand_chHad_rawCaloFraction) = + sp.scale(candFunc::getRawCaloFraction(chH_cand), dnn::pfCand_chHad_rawCaloFraction - PFchH_index_offset); } if (valid_nH) { + const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft_PFnH, is_inner)); size_t index_nH = cell_map.at(CellObjectType::PfCand_neutralHadron); const auto& nH_cand = dynamic_cast(pfCands.at(index_nH)); - get(dnn::pfCand_nHad_valid) = valid_nH; - get(dnn::pfCand_nHad_rel_pt) = getValueNorm(pfCands.at(index_nH).polarP4().pt() / tau.polarP4().pt(), - is_inner ? 0.3163f : 0.0502f, - is_inner ? 0.2769f : 0.4266f); - get(dnn::pfCand_nHad_deta) = getValueLinear(pfCands.at(index_nH).polarP4().eta() - tau.polarP4().eta(), - is_inner ? -0.1f : -0.5f, - is_inner ? 0.1f : 0.5f, - false); - get(dnn::pfCand_nHad_dphi) = getValueLinear( - dPhi(tau.polarP4(), pfCands.at(index_nH).polarP4()), is_inner ? -0.1f : -0.5f, is_inner ? 0.1f : 0.5f, false); - get(dnn::pfCand_nHad_puppiWeight) = is_inner ? getValue(candFunc::getPuppiWeight(nH_cand, 0.9798355f)) - : getValue(candFunc::getPuppiWeight(nH_cand, 0.7813260f)); - get(dnn::pfCand_nHad_puppiWeightNoLep) = is_inner ? getValue(candFunc::getPuppiWeightNoLep(nH_cand, 0.9046796f)) - : getValue(candFunc::getPuppiWeightNoLep(nH_cand, 0.6554860f)); + get(dnn::pfCand_nHad_valid) = sp.scale(valid_nH, dnn::pfCand_nHad_valid - PFnH_index_offset); + get(dnn::pfCand_nHad_rel_pt) = + sp.scale(nH_cand.polarP4().pt() / tau.polarP4().pt(), dnn::pfCand_nHad_rel_pt - PFnH_index_offset); + get(dnn::pfCand_nHad_deta) = + sp.scale(nH_cand.polarP4().eta() - tau.polarP4().eta(), dnn::pfCand_nHad_deta - PFnH_index_offset); + get(dnn::pfCand_nHad_dphi) = + sp.scale(dPhi(tau.polarP4(), nH_cand.polarP4()), dnn::pfCand_nHad_dphi - PFnH_index_offset); + get(dnn::pfCand_nHad_puppiWeight) = is_inner ? sp.scale(candFunc::getPuppiWeight(nH_cand, 0.9798355f), + dnn::pfCand_nHad_puppiWeight - PFnH_index_offset) + : sp.scale(candFunc::getPuppiWeight(nH_cand, 0.7813260f), + dnn::pfCand_nHad_puppiWeight - PFnH_index_offset); + get(dnn::pfCand_nHad_puppiWeightNoLep) = is_inner + ? sp.scale(candFunc::getPuppiWeightNoLep(nH_cand, 0.9046796f), + dnn::pfCand_nHad_puppiWeightNoLep - PFnH_index_offset) + : sp.scale(candFunc::getPuppiWeightNoLep(nH_cand, 0.6554860f), + dnn::pfCand_nHad_puppiWeightNoLep - PFnH_index_offset); float hcal_fraction = candFunc::getHCalFraction(nH_cand, disable_hcalFraction_workaround_); - get(dnn::pfCand_nHad_hcalFraction) = getValue(hcal_fraction); + get(dnn::pfCand_nHad_hcalFraction) = sp.scale(hcal_fraction, dnn::pfCand_nHad_hcalFraction - PFnH_index_offset); } } @@ -2462,7 +2583,7 @@ class DeepTauId : public deep_tau::DeepTauBase { static constexpr bool check_all_set = false; static constexpr float default_value_for_set_check = -42; - tensorflow::Tensor inputs(tensorflow::DT_FLOAT, {1, dnn_inputs_2017v1::NumberOfInputs}); + tensorflow::Tensor inputs(tensorflow::DT_FLOAT, {1, dnn_inputs_v1::NumberOfInputs}); const auto& get = [&](int var_index) -> float& { return inputs.matrix()(0, var_index); }; auto leadChargedHadrCand = dynamic_cast(tau.leadChargedHadrCand().get()); @@ -2811,6 +2932,7 @@ class DeepTauId : public deep_tau::DeepTauBase { pfTauTransverseImpactParameters_token_; std::string input_layer_, output_layer_; const unsigned version_; + const unsigned sub_version_; const int debug_level; const bool disable_dxy_pca_; const bool disable_hcalFraction_workaround_; @@ -2818,10 +2940,12 @@ class DeepTauId : public deep_tau::DeepTauBase { std::unique_ptr tauBlockTensor_; std::array, 2> eGammaTensor_, muonTensor_, hadronsTensor_, convTensor_, zeroOutputTensor_; + const std::map, deep_tau::Scaling::ScalingParams>* scalingParamsMap_; const bool save_inputs_; std::ofstream* json_file_; bool is_first_block_; int file_counter_; + std::vector tauInputs_indices_; //boolean to check if discriminator indices are already mapped bool discrIndicesMapped_ = false; diff --git a/RecoTauTag/RecoTau/python/tools/runTauIdMVA.py b/RecoTauTag/RecoTau/python/tools/runTauIdMVA.py index 166354a86d80b..192c823619dfb 100644 --- a/RecoTauTag/RecoTau/python/tools/runTauIdMVA.py +++ b/RecoTauTag/RecoTau/python/tools/runTauIdMVA.py @@ -2,6 +2,8 @@ import FWCore.ParameterSet.Config as cms from RecoTauTag.RecoTau.TauDiscriminatorTools import noPrediscriminants from RecoTauTag.RecoTau.PATTauDiscriminationByMVAIsolationRun2_cff import patDiscriminationByIsolationMVArun2v1raw, patDiscriminationByIsolationMVArun2v1 +from RecoTauTag.RecoTau.DPFTau2016v0_cfi import DPFTau2016v0 +from RecoTauTag.RecoTau.DeepTau_cfi import DeepTau import os import re @@ -9,7 +11,7 @@ class TauIDEmbedder(object): """class to rerun the tau seq and acces trainings from the database""" availableDiscriminators = [ "2017v1", "2017v2", "newDM2017v2", "dR0p32017v2", "2016v1", "newDM2016v1", - "deepTau2017v1", "deepTau2017v2", "deepTau2017v2p1", + "deepTau2017v1", "deepTau2017v2", "deepTau2017v2p1", "deepTau2018v2p5", "DPFTau_2016_v0", "DPFTau_2016_v1", "againstEle2018", "newDMPhase2v1", @@ -20,7 +22,7 @@ def __init__(self, process, debug = False, originalTauName = "slimmedTaus", updatedTauName = "slimmedTausNewID", postfix = "", - toKeep = ["deepTau2017v2p1"], + toKeep = ["deepTau2017v2p1", "deepTau2018v2p5"], tauIdDiscrMVA_trainings_run2_2017 = { 'tauIdMVAIsoDBoldDMwLT2017' : "tauIdMVAIsoDBoldDMwLT2017", }, tauIdDiscrMVA_WPs_run2_2017 = { 'tauIdMVAIsoDBoldDMwLT2017' : { @@ -596,18 +598,13 @@ def runTauID(self): } } file_names = ['RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v1_20L1024N_quantized.pb'] - setattr(self.process,_deepTauName+self.postfix,cms.EDProducer("DeepTauId", - electrons = cms.InputTag('slimmedElectrons'), - muons = cms.InputTag('slimmedMuons'), - taus = cms.InputTag(self.originalTauName), - pfcands = cms.InputTag('packedPFCandidates'), - vertices = cms.InputTag('offlineSlimmedPrimaryVertices'), - rho = cms.InputTag('fixedGridRhoAll'), - graph_file = cms.vstring(file_names), - mem_mapped = cms.bool(False), - version = cms.uint32(self.getDeepTauVersion(file_names[0])[1]), - debug_level = cms.int32(0), - disable_dxy_pca = cms.bool(False) + full_version = self.getDeepTauVersion(file_names[0]) + setattr(self.process,_deepTauName+self.postfix,DeepTau.clone( + Prediscriminants = noPrediscriminants, + taus = self.originalTauName, + graph_file = file_names, + version = full_version[1], + sub_version = full_version[2] )) self.processDeepProducer(_deepTauName, tauIDSources, workingPoints_) @@ -655,18 +652,13 @@ def runTauID(self): 'inner:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_inner.pb', 'outer:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_outer.pb', ] - setattr(self.process,_deepTauName+self.postfix,cms.EDProducer("DeepTauId", - electrons = cms.InputTag('slimmedElectrons'), - muons = cms.InputTag('slimmedMuons'), - taus = cms.InputTag(self.originalTauName), - pfcands = cms.InputTag('packedPFCandidates'), - vertices = cms.InputTag('offlineSlimmedPrimaryVertices'), - rho = cms.InputTag('fixedGridRhoAll'), - graph_file = cms.vstring(file_names), - mem_mapped = cms.bool(False), - version = cms.uint32(self.getDeepTauVersion(file_names[0])[1]), - debug_level = cms.int32(0), - disable_dxy_pca = cms.bool(False) + full_version = self.getDeepTauVersion(file_names[0]) + setattr(self.process,_deepTauName+self.postfix,DeepTau.clone( + Prediscriminants = noPrediscriminants, + taus = self.originalTauName, + graph_file = file_names, + version = full_version[1], + sub_version = 0 #MB: subversion cannot be properly deduced from file names )) self.processDeepProducer(_deepTauName, tauIDSources, workingPoints_) @@ -714,19 +706,14 @@ def runTauID(self): 'inner:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_inner.pb', 'outer:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_outer.pb', ] - setattr(self.process,_deepTauName+self.postfix,cms.EDProducer("DeepTauId", - electrons = cms.InputTag('slimmedElectrons'), - muons = cms.InputTag('slimmedMuons'), - taus = cms.InputTag(self.originalTauName), - pfcands = cms.InputTag('packedPFCandidates'), - vertices = cms.InputTag('offlineSlimmedPrimaryVertices'), - rho = cms.InputTag('fixedGridRhoAll'), - graph_file = cms.vstring(file_names), - mem_mapped = cms.bool(False), - version = cms.uint32(self.getDeepTauVersion(file_names[0])[1]), - debug_level = cms.int32(0), - disable_dxy_pca = cms.bool(True), - is_online = cms.bool(False) + full_version = self.getDeepTauVersion(file_names[0]) + setattr(self.process,_deepTauName+self.postfix,DeepTau.clone( + Prediscriminants = noPrediscriminants, + taus = self.originalTauName, + graph_file = file_names, + version = full_version[1], + sub_version = 1, #MB: subversion cannot be properly deduced from file names + disable_dxy_pca = True )) self.processDeepProducer(_deepTauName, tauIDSources, workingPoints_) @@ -735,11 +722,43 @@ def runTauID(self): _rerunMvaIsolationTask.add(_deepTauProducer) _rerunMvaIsolationSequence += _deepTauProducer + if "deepTau2018v2p5" in self.toKeep: + if self.debug: print ("Adding DeepTau IDs") + + _deepTauName = "deepTau2018v2p5" + workingPoints_ = { + "e": {}, + "mu": {}, + "jet": {}, + } + + file_names = [ + 'core:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2018v2p5_core.pb', + 'inner:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2018v2p5_inner.pb', + 'outer:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2018v2p5_outer.pb', + ] + full_version = self.getDeepTauVersion(file_names[0]) + setattr(self.process,_deepTauName+self.postfix,DeepTau.clone( + Prediscriminants = noPrediscriminants, + taus = self.originalTauName, + graph_file = file_names, + version = full_version[1], + sub_version = full_version[2], + disable_dxy_pca = True, + disable_hcalFraction_workaround = True, + disable_CellIndex_workaround = True + )) + + self.processDeepProducer(_deepTauName, tauIDSources, workingPoints_) + + _deepTauProducer = getattr(self.process,_deepTauName+self.postfix) + _rerunMvaIsolationTask.add(_deepTauProducer) + _rerunMvaIsolationSequence += _deepTauProducer if "DPFTau_2016_v0" in self.toKeep: if self.debug: print ("Adding DPFTau isolation (v0)") - _deepTauName = "DPFTau_2016_v0" + _deepTauName = "DPFTau2016v0" workingPoints_ = { "all": { "Tight" : "if(decayMode == 0) return (0.898328 - 0.000160992 * pt);" + \ @@ -755,13 +774,11 @@ def runTauID(self): } } file_names = [ 'RecoTauTag/TrainingFiles/data/DPFTauId/DPFIsolation_2017v0_quantized.pb' ] - setattr(self.process,_deepTauName+self.postfix,cms.EDProducer("DPFIsolation", - pfcands = cms.InputTag('packedPFCandidates'), - taus = cms.InputTag(self.originalTauName), - vertices = cms.InputTag('offlineSlimmedPrimaryVertices'), - graph_file = cms.vstring(file_names), - version = cms.uint32(self.getDpfTauVersion(file_names[0])), - mem_mapped = cms.bool(False) + setattr(self.process,_deepTauName+self.postfix,DPFTau2016v0.clone( + Prediscriminants = noPrediscriminants, + taus = self.originalTauName, + graph_file = file_names, + version = self.getDpfTauVersion(file_names[0]) )) self.processDeepProducer(_deepTauName, tauIDSources, workingPoints_) @@ -776,19 +793,17 @@ def runTauID(self): print ("WARNING: WPs are not defined for DPFTau_2016_v1") print ("WARNING: The score of DPFTau_2016_v1 is inverted: i.e. for Sig->0, for Bkg->1 with -1 for undefined input (preselection not passed).") - _deepTauName = "DPFTau_2016_v1" + _deepTauName = "DPFTau2016v1" workingPoints_ = { "all": {"Tight" : 0.123} #FIXME: define WP } file_names = [ 'RecoTauTag/TrainingFiles/data/DPFTauId/DPFIsolation_2017v1_quantized.pb' ] - setattr(self.process,_deepTauName+self.postfix,cms.EDProducer("DPFIsolation", - pfcands = cms.InputTag('packedPFCandidates'), - taus = cms.InputTag(self.originalTauName), - vertices = cms.InputTag('offlineSlimmedPrimaryVertices'), - graph_file = cms.vstring(file_names), - version = cms.uint32(self.getDpfTauVersion(file_names[0])), - mem_mapped = cms.bool(False) + setattr(self.process,_deepTauName+self.postfix,DPFTau2016v0.clone( + Prediscriminants = noPrediscriminants, + taus = self.originalTauName, + graph_file = file_names, + version = self.getDpfTauVersion(file_names[0]) )) self.processDeepProducer(_deepTauName, tauIDSources, workingPoints_) @@ -1032,8 +1047,8 @@ def processDeepProducer(self, producer_name, tauIDSources, workingPoints_): setattr(tauIDSources, 'by{}{}VS{}'.format(point, producer_name[0].upper()+producer_name[1:], target), cms.PSet(inputTag = cms.InputTag(producer_name+self.postfix, 'VS{}'.format(target)), workingPointIndex = cms.int32(index))) - - setattr(getattr(self.process, producer_name+self.postfix), 'VS{}WP'.format(target), cms.vstring(*cut_expressions)) + if len(cut_expressions) > 0: + setattr(getattr(self.process, producer_name+self.postfix), 'VS{}WP'.format(target), cms.vstring(*cut_expressions)) def getDpfTauVersion(self, file_name): @@ -1050,7 +1065,7 @@ def getDeepTauVersion(self, file_name): """returns the DeepTau year, version, subversion. File name should contain a version label with data takig year \ (2011-2, 2015-8), version number (vX) and subversion (pX), e.g. 2017v0p6, in general the following format: \ {year}v{version}p{subversion}""" - version_search = re.search('(201[125678])v([0-9]+)(p[0-9]+|)[\._]', file_name) + version_search = re.search('(20[1,2][125678])v([0-9]+)(p[0-9]+|)[\._]', file_name) if not version_search: raise RuntimeError('File "{}" has an invalid name pattern, should be in the format "{year}v{version}p{subversion}". \ Unable to extract version number.'.format(file_name)) diff --git a/RecoTauTag/RecoTau/test/runDeepTauIDsOnMiniAOD.py b/RecoTauTag/RecoTau/test/runDeepTauIDsOnMiniAOD.py index 96a4cd280660f..8cd959c3b4bda 100644 --- a/RecoTauTag/RecoTau/test/runDeepTauIDsOnMiniAOD.py +++ b/RecoTauTag/RecoTau/test/runDeepTauIDsOnMiniAOD.py @@ -33,6 +33,7 @@ toKeep = [ "2017v2", "dR0p32017v2", "newDM2017v2", # "deepTau2017v1", "deepTau2017v2p1", + "deepTau2018v2p5", # "DPFTau_2016_v0", # "DPFTau_2016_v1", "againstEle2018",