diff --git a/RecoTauTag/RecoTau/interface/DeepTauScaling.h b/RecoTauTag/RecoTau/interface/DeepTauScaling.h new file mode 100644 index 0000000000000..9c562ace9fab2 --- /dev/null +++ b/RecoTauTag/RecoTau/interface/DeepTauScaling.h @@ -0,0 +1,724 @@ +#ifndef RecoTauTag_RecoTau_DeepTauScaling_h +#define RecoTauTag_RecoTau_DeepTauScaling_h + +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 \ No newline at end of file diff --git a/RecoTauTag/RecoTau/plugins/DeepTauId.cc b/RecoTauTag/RecoTau/plugins/DeepTauId.cc index 1c2534f3784d7..3f9ef174358b7 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" @@ -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")), @@ -1215,26 +1223,67 @@ class DeepTauId : public deep_tau::DeepTauBase { 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; + 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_ = &deep_tau::Scaling::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_ = &deep_tau::Scaling::scalingParamsMap_v2p5; + } else + throw cms::Exception("DeepTauId") << "subversion " << sub_version_ << " is not supported."; + + namespace sc = deep_tau::Scaling; + std::map, std::vector> GridFeatureTypes_map = { + {{false}, {sc::FeatureT::TauFlat, sc::FeatureT::GridGlobal}}, // feature types without inner/outer grid split + {{false, true}, + {sc::FeatureT::PfCand_electron, + sc::FeatureT::PfCand_muon, // feature types with inner/outer grid split + sc::FeatureT::PfCand_chHad, + sc::FeatureT::PfCand_nHad, + sc::FeatureT::PfCand_gamma, + sc::FeatureT::Electron, + sc::FeatureT::Muon}}}; + + // check that sizes of mean/std/lim_min/lim_max vectors are equal between each other + for (const auto& p : GridFeatureTypes_map) { + for (auto is_inner : p.first) { + for (auto featureType : p.second) { + const deep_tau::Scaling::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(featureType, is_inner)); + if (!(sp.mean_.size() == sp.std_.size() && sp.mean_.size() == sp.lim_min_.size() && + sp.mean_.size() == sp.lim_max_.size())) + throw cms::Exception("DeepTauId") << "sizes of scaling parameter vectors do not match between each other"; + } + } + } + for (size_t n = 0; n < 2; ++n) { const bool is_inner = n == 0; - const auto n_cells = - is_inner ? dnn_inputs_2017_v2::number_of_inner_cell : dnn_inputs_2017_v2::number_of_outer_cell; + const auto n_cells = is_inner ? dnn_inputs_v2::number_of_inner_cell : dnn_inputs_v2::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, dnn_inputs_v2::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, dnn_inputs_v2::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, dnn_inputs_v2::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, dnn_inputs_v2::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, dnn_inputs_v2::number_of_conv_features}); eGammaTensor_[is_inner]->flat().setZero(); muonTensor_[is_inner]->flat().setZero(); @@ -1575,13 +1624,13 @@ class DeepTauId : public deep_tau::DeepTauBase { << ")>:" << 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, + CellGrid inner_grid(dnn_inputs_v2::number_of_inner_cell, + dnn_inputs_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, + CellGrid outer_grid(dnn_inputs_v2::number_of_outer_cell, + dnn_inputs_v2::number_of_outer_cell, 0.05, 0.05, disable_CellIndex_workaround_); @@ -1591,8 +1640,8 @@ class DeepTauId : public deep_tau::DeepTauBase { createTauBlockInputs( dynamic_cast(tau), tau_index, tau_ref, pv, rho, tau_funcs); - using namespace dnn_inputs_2017_v2; - checkInputs(*tauBlockTensor_, "input_tau", TauBlockInputs::NumberOfInputs); + using namespace dnn_inputs_v2; + checkInputs(*tauBlockTensor_, "input_tau", static_cast(tauBlockTensor_->shape().dim_size(1))); createConvFeatures(dynamic_cast(tau), tau_index, tau_ref, @@ -1627,27 +1676,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 +1800,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 +1868,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 +1880,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; + deep_tau::Scaling::FeatureT ft = deep_tau::Scaling::FeatureT::TauFlat; + const deep_tau::Scaling::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_.at(dnn::rho)); + get(dnn::tau_pt) = sp.scale(tau.polarP4().pt(), tauInputs_indices_.at(dnn::tau_pt)); + get(dnn::tau_eta) = sp.scale(tau.polarP4().eta(), tauInputs_indices_.at(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_.at(dnn::tau_mass)); + get(dnn::tau_E_over_pt) = sp.scale(tau.p4().energy() / tau.p4().pt(), tauInputs_indices_.at(dnn::tau_E_over_pt)); + get(dnn::tau_charge) = sp.scale(tau.charge(), tauInputs_indices_.at(dnn::tau_charge)); + get(dnn::tau_n_charged_prongs) = + sp.scale(tau.decayMode() / 5 + 1, tauInputs_indices_.at(dnn::tau_n_charged_prongs)); + get(dnn::tau_n_neutral_prongs) = sp.scale(tau.decayMode() % 5, tauInputs_indices_.at(dnn::tau_n_neutral_prongs)); + get(dnn::chargedIsoPtSum) = + sp.scale(tau_funcs.getChargedIsoPtSum(tau, tau_ref), tauInputs_indices_.at(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_.at(dnn::chargedIsoPtSumdR03_over_dR05)); + if (sub_version_ == 1) + get(dnn::footprintCorrection) = + sp.scale(tau_funcs.getFootprintCorrectiondR03(tau, tau_ref), tauInputs_indices_.at(dnn::footprintCorrection)); + else if (sub_version_ == 5) + get(dnn::footprintCorrection) = + sp.scale(tau_funcs.getFootprintCorrection(tau, tau_ref), tauInputs_indices_.at(dnn::footprintCorrection)); + + get(dnn::neutralIsoPtSum) = + sp.scale(tau_funcs.getNeutralIsoPtSum(tau, tau_ref), tauInputs_indices_.at(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_.at(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_.at(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_.at(dnn::neutralIsoPtSumdR03_over_dR05)); + get(dnn::photonPtSumOutsideSignalCone) = sp.scale(tau_funcs.getPhotonPtSumOutsideSignalCone(tau, tau_ref), + tauInputs_indices_.at(dnn::photonPtSumOutsideSignalCone)); + get(dnn::puCorrPtSum) = sp.scale(tau_funcs.getPuCorrPtSum(tau, tau_ref), tauInputs_indices_.at(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_.at(dnn::tau_dxy_pca_x)); + get(dnn::tau_dxy_pca_y) = sp.scale(pca.y(), tauInputs_indices_.at(dnn::tau_dxy_pca_y)); + get(dnn::tau_dxy_pca_z) = sp.scale(pca.z(), tauInputs_indices_.at(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_.at(dnn::tau_dxy_valid)); + get(dnn::tau_dxy) = sp.scale(tau_funcs.getdxy(tau, tau_index), tauInputs_indices_.at(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_.at(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_.at(dnn::tau_ip3d_valid)); + get(dnn::tau_ip3d) = sp.scale(tau_funcs.getip3d(tau, tau_index), tauInputs_indices_.at(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_.at(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_.at(dnn::tau_dz)); + get(dnn::tau_dz_sig_valid) = + sp.scale(candFunc::getTauDZSigValid(*leadChargedHadrCand), tauInputs_indices_.at(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_.at(dnn::tau_dz_sig)); + } + get(dnn::tau_flightLength_x) = + sp.scale(tau_funcs.getFlightLength(tau, tau_index).x(), tauInputs_indices_.at(dnn::tau_flightLength_x)); + get(dnn::tau_flightLength_y) = + sp.scale(tau_funcs.getFlightLength(tau, tau_index).y(), tauInputs_indices_.at(dnn::tau_flightLength_y)); + get(dnn::tau_flightLength_z) = + sp.scale(tau_funcs.getFlightLength(tau, tau_index).z(), tauInputs_indices_.at(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_.at(dnn::tau_flightLength_sig)); + + get(dnn::tau_pt_weighted_deta_strip) = sp.scale(reco::tau::pt_weighted_deta_strip(tau, tau.decayMode()), + tauInputs_indices_.at(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_.at(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_.at(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_.at(dnn::tau_pt_weighted_dr_iso)); + get(dnn::tau_leadingTrackNormChi2) = + sp.scale(tau_funcs.getLeadingTrackNormChi2(tau), tauInputs_indices_.at(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_.at(dnn::tau_e_ratio_valid)); + get(dnn::tau_e_ratio) = tau_e_ratio_valid ? sp.scale(eratio, tauInputs_indices_.at(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_.at(dnn::tau_gj_angle_diff_valid)); + get(dnn::tau_gj_angle_diff) = + tau_gj_angle_diff_valid ? sp.scale(gj_angle_diff, tauInputs_indices_.at(dnn::tau_gj_angle_diff)) : 0; + get(dnn::tau_n_photons) = sp.scale(reco::tau::n_photons_total(tau), tauInputs_indices_.at(dnn::tau_n_photons)); + get(dnn::tau_emFraction) = sp.scale(tau_funcs.getEmFraction(tau), tauInputs_indices_.at(dnn::tau_emFraction)); + + get(dnn::tau_inside_ecal_crack) = + sp.scale(isInEcalCrack(tau.p4().eta()), tauInputs_indices_.at(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_.at(dnn::leadChargedCand_etaAtEcalEntrance_minus_tau_eta)); } template @@ -1952,7 +2030,26 @@ 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; + deep_tau::Scaling::FeatureT ft_global = deep_tau::Scaling::FeatureT::GridGlobal; + deep_tau::Scaling::FeatureT ft_PFe = deep_tau::Scaling::FeatureT::PfCand_electron; + deep_tau::Scaling::FeatureT ft_PFg = deep_tau::Scaling::FeatureT::PfCand_gamma; + deep_tau::Scaling::FeatureT ft_e = deep_tau::Scaling::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 +2060,245 @@ 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 deep_tau::Scaling::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 deep_tau::Scaling::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_vertex_dx) = - getValueNorm(pfCands.at(index_pf_ele).vertex().x() - pv.position().x(), 0.f, 0.1221f); - get(dnn::pfCand_ele_vertex_dy) = - getValueNorm(pfCands.at(index_pf_ele).vertex().y() - pv.position().y(), 0.f, 0.1226f); - 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( + 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(pfCands.at(index_pf_ele).polarP4().pt() / tau.polarP4().pt(), + dnn::pfCand_ele_rel_pt - PFe_index_offset); + get(dnn::pfCand_ele_deta) = sp.scale(pfCands.at(index_pf_ele).polarP4().eta() - tau.polarP4().eta(), + dnn::pfCand_ele_deta - PFe_index_offset); + get(dnn::pfCand_ele_dphi) = + sp.scale(dPhi(tau.polarP4(), pfCands.at(index_pf_ele).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) = sp.scale(pfCands.at(index_pf_ele).vertex().x() - pv.position().x(), + dnn::pfCand_ele_vertex_dx - PFe_index_offset); + get(dnn::pfCand_ele_vertex_dy) = sp.scale(pfCands.at(index_pf_ele).vertex().y() - pv.position().y(), + dnn::pfCand_ele_vertex_dy - PFe_index_offset); + get(dnn::pfCand_ele_vertex_dz) = sp.scale(pfCands.at(index_pf_ele).vertex().z() - pv.position().z(), + dnn::pfCand_ele_vertex_dz - PFe_index_offset); + get(dnn::pfCand_ele_vertex_dx_tauFL) = sp.scale( 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( + dnn::pfCand_ele_vertex_dx_tauFL - PFe_index_offset); + get(dnn::pfCand_ele_vertex_dy_tauFL) = sp.scale( 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( + dnn::pfCand_ele_vertex_dy_tauFL - PFe_index_offset); + get(dnn::pfCand_ele_vertex_dz_tauFL) = sp.scale( pfCands.at(index_pf_ele).vertex().z() - pv.position().z() - tau_funcs.getFlightLength(tau, tau_index).z(), - 0.f, - 1.307f); + 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_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) = - 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); + sp.scale(std::abs(candFunc::getTauDxy(ele_cand)) / pfCands.at(index_pf_ele).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 deep_tau::Scaling::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( + 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( + pfCands.at(index_pf_gamma).polarP4().pt() / tau.polarP4().pt(), dnn::pfCand_gamma_rel_pt - PFg_index_offset); + get(dnn::pfCand_gamma_deta + fill_index_offset_PFg) = sp.scale( + pfCands.at(index_pf_gamma).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(), pfCands.at(index_pf_gamma).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( + pfCands.at(index_pf_gamma).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( + pfCands.at(index_pf_gamma).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( + pfCands.at(index_pf_gamma).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( 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( + dnn::pfCand_gamma_vertex_dx_tauFL - PFg_index_offset); + get(dnn::pfCand_gamma_vertex_dy_tauFL + fill_index_offset_PFg) = sp.scale( 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( + dnn::pfCand_gamma_vertex_dy_tauFL - PFg_index_offset); + get(dnn::pfCand_gamma_vertex_dz_tauFL + fill_index_offset_PFg) = sp.scale( pfCands.at(index_pf_gamma).vertex().z() - pv.position().z() - tau_funcs.getFlightLength(tau, tau_index).z(), - 0.0038f, - 2.154f); + 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 deep_tau::Scaling::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft_e, is_inner)); size_t index_ele = cell_map.at(CellObjectType::Electron); - 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(electrons->at(index_ele).polarP4().pt() / tau.polarP4().pt(), dnn::ele_rel_pt - e_index_offset); + get(dnn::ele_deta + fill_index_offset_e) = + sp.scale(electrons->at(index_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(), electrons->at(index_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); 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 / electrons->at(index_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( + get(dnn::ele_rel_trackMomentumAtVtx + fill_index_offset_e) = + sp.scale(electrons->at(index_ele).trackMomentumAtVtx().R() / electrons->at(index_ele).polarP4().pt(), + dnn::ele_rel_trackMomentumAtVtx - e_index_offset); + get(dnn::ele_rel_trackMomentumAtCalo + fill_index_offset_e) = + sp.scale(electrons->at(index_ele).trackMomentumAtCalo().R() / electrons->at(index_ele).polarP4().pt(), + dnn::ele_rel_trackMomentumAtCalo - e_index_offset); + get(dnn::ele_rel_trackMomentumOut + fill_index_offset_e) = + sp.scale(electrons->at(index_ele).trackMomentumOut().R() / electrons->at(index_ele).polarP4().pt(), + dnn::ele_rel_trackMomentumOut - e_index_offset); + get(dnn::ele_rel_trackMomentumAtEleClus + fill_index_offset_e) = + sp.scale(electrons->at(index_ele).trackMomentumAtEleClus().R() / electrons->at(index_ele).polarP4().pt(), + dnn::ele_rel_trackMomentumAtEleClus - e_index_offset); + get(dnn::ele_rel_trackMomentumAtVtxWithConstraint + fill_index_offset_e) = sp.scale( 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); + dnn::ele_rel_trackMomentumAtVtxWithConstraint - e_index_offset); + get(dnn::ele_rel_ecalEnergy + fill_index_offset_e) = + sp.scale(electrons->at(index_ele).ecalEnergy() / electrons->at(index_ele).polarP4().pt(), + dnn::ele_rel_ecalEnergy - e_index_offset); + get(dnn::ele_ecalEnergy_sig + fill_index_offset_e) = + sp.scale(electrons->at(index_ele).ecalEnergy() / electrons->at(index_ele).ecalEnergyError(), + dnn::ele_ecalEnergy_sig - e_index_offset); + get(dnn::ele_eSuperClusterOverP + fill_index_offset_e) = + sp.scale(electrons->at(index_ele).eSuperClusterOverP(), dnn::ele_eSuperClusterOverP - e_index_offset); + get(dnn::ele_eSeedClusterOverP + fill_index_offset_e) = + sp.scale(electrons->at(index_ele).eSeedClusterOverP(), dnn::ele_eSeedClusterOverP - e_index_offset); + get(dnn::ele_eSeedClusterOverPout + fill_index_offset_e) = + sp.scale(electrons->at(index_ele).eSeedClusterOverPout(), dnn::ele_eSeedClusterOverPout - e_index_offset); + get(dnn::ele_eEleClusterOverPout + fill_index_offset_e) = + sp.scale(electrons->at(index_ele).eEleClusterOverPout(), dnn::ele_eEleClusterOverPout - e_index_offset); + get(dnn::ele_deltaEtaSuperClusterTrackAtVtx + fill_index_offset_e) = + sp.scale(electrons->at(index_ele).deltaEtaSuperClusterTrackAtVtx(), + dnn::ele_deltaEtaSuperClusterTrackAtVtx - e_index_offset); + get(dnn::ele_deltaEtaSeedClusterTrackAtCalo + fill_index_offset_e) = + sp.scale(electrons->at(index_ele).deltaEtaSeedClusterTrackAtCalo(), + dnn::ele_deltaEtaSeedClusterTrackAtCalo - e_index_offset); + get(dnn::ele_deltaEtaEleClusterTrackAtCalo + fill_index_offset_e) = + sp.scale(electrons->at(index_ele).deltaEtaEleClusterTrackAtCalo(), + dnn::ele_deltaEtaEleClusterTrackAtCalo - e_index_offset); + get(dnn::ele_deltaPhiEleClusterTrackAtCalo + fill_index_offset_e) = + sp.scale(electrons->at(index_ele).deltaPhiEleClusterTrackAtCalo(), + dnn::ele_deltaPhiEleClusterTrackAtCalo - e_index_offset); + get(dnn::ele_deltaPhiSuperClusterTrackAtVtx + fill_index_offset_e) = + sp.scale(electrons->at(index_ele).deltaPhiSuperClusterTrackAtVtx(), + dnn::ele_deltaPhiSuperClusterTrackAtVtx - e_index_offset); + get(dnn::ele_deltaPhiSeedClusterTrackAtCalo + fill_index_offset_e) = + sp.scale(electrons->at(index_ele).deltaPhiSeedClusterTrackAtCalo(), + dnn::ele_deltaPhiSeedClusterTrackAtCalo - e_index_offset); + get(dnn::ele_mvaInput_earlyBrem + fill_index_offset_e) = + sp.scale(electrons->at(index_ele).mvaInput().earlyBrem, dnn::ele_mvaInput_earlyBrem - e_index_offset); + get(dnn::ele_mvaInput_lateBrem + fill_index_offset_e) = + sp.scale(electrons->at(index_ele).mvaInput().lateBrem, dnn::ele_mvaInput_lateBrem - e_index_offset); + get(dnn::ele_mvaInput_sigmaEtaEta + fill_index_offset_e) = + sp.scale(electrons->at(index_ele).mvaInput().sigmaEtaEta, dnn::ele_mvaInput_sigmaEtaEta - e_index_offset); + get(dnn::ele_mvaInput_hadEnergy + fill_index_offset_e) = + sp.scale(electrons->at(index_ele).mvaInput().hadEnergy, dnn::ele_mvaInput_hadEnergy - e_index_offset); + get(dnn::ele_mvaInput_deltaEta + fill_index_offset_e) = + sp.scale(electrons->at(index_ele).mvaInput().deltaEta, dnn::ele_mvaInput_deltaEta - e_index_offset); const auto& gsfTrack = electrons->at(index_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() / electrons->at(index_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 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 +2315,14 @@ 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; + deep_tau::Scaling::FeatureT ft_global = deep_tau::Scaling::FeatureT::GridGlobal; + deep_tau::Scaling::FeatureT ft_PFmu = deep_tau::Scaling::FeatureT::PfCand_muon; + deep_tau::Scaling::FeatureT ft_mu = deep_tau::Scaling::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,106 +2332,113 @@ 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 deep_tau::Scaling::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 deep_tau::Scaling::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_vertex_dx) = - getValueNorm(pfCands.at(index_pf_muon).vertex().x() - pv.position().x(), -0.0007f, 0.6869f); - get(dnn::pfCand_muon_vertex_dy) = - getValueNorm(pfCands.at(index_pf_muon).vertex().y() - pv.position().y(), 0.0001f, 0.6784f); - 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( + 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(pfCands.at(index_pf_muon).polarP4().pt() / tau.polarP4().pt(), + dnn::pfCand_muon_rel_pt - PFmu_index_offset); + get(dnn::pfCand_muon_deta) = sp.scale(pfCands.at(index_pf_muon).polarP4().eta() - tau.polarP4().eta(), + dnn::pfCand_muon_deta - PFmu_index_offset); + get(dnn::pfCand_muon_dphi) = + sp.scale(dPhi(tau.polarP4(), pfCands.at(index_pf_muon).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) = sp.scale(pfCands.at(index_pf_muon).vertex().x() - pv.position().x(), + dnn::pfCand_muon_vertex_dx - PFmu_index_offset); + get(dnn::pfCand_muon_vertex_dy) = sp.scale(pfCands.at(index_pf_muon).vertex().y() - pv.position().y(), + dnn::pfCand_muon_vertex_dy - PFmu_index_offset); + get(dnn::pfCand_muon_vertex_dz) = sp.scale(pfCands.at(index_pf_muon).vertex().z() - pv.position().z(), + dnn::pfCand_muon_vertex_dz - PFmu_index_offset); + get(dnn::pfCand_muon_vertex_dx_tauFL) = sp.scale( 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( + dnn::pfCand_muon_vertex_dx_tauFL - PFmu_index_offset); + get(dnn::pfCand_muon_vertex_dy_tauFL) = sp.scale( 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( + dnn::pfCand_muon_vertex_dy_tauFL - PFmu_index_offset); + get(dnn::pfCand_muon_vertex_dz_tauFL) = sp.scale( pfCands.at(index_pf_muon).vertex().z() - pv.position().z() - tau_funcs.getFlightLength(tau, tau_index).z(), - -0.0118f, - 4.405f); + 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 deep_tau::Scaling::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft_mu, is_inner)); size_t index_muon = cell_map.at(CellObjectType::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(muons->at(index_muon).polarP4().pt() / tau.polarP4().pt(), dnn::muon_rel_pt - mu_index_offset); + get(dnn::muon_deta) = + sp.scale(muons->at(index_muon).polarP4().eta() - tau.polarP4().eta(), dnn::muon_deta - mu_index_offset); + get(dnn::muon_dphi) = + sp.scale(dPhi(tau.polarP4(), muons->at(index_muon).polarP4()), dnn::muon_dphi - mu_index_offset); + get(dnn::muon_dxy) = sp.scale(muons->at(index_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(muons->at(index_muon).dB(pat::Muon::PV2D)) / muons->at(index_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; if (normalizedChi2_valid) { - get(dnn::muon_normalizedChi2_valid) = normalizedChi2_valid; - get(dnn::muon_normalizedChi2) = getValueNorm(muons->at(index_muon).normChi2(), 21.52f, 265.8f); + get(dnn::muon_normalizedChi2_valid) = + sp.scale(normalizedChi2_valid, dnn::muon_normalizedChi2_valid - mu_index_offset); + get(dnn::muon_normalizedChi2) = + sp.scale(muons->at(index_muon).normChi2(), dnn::muon_normalizedChi2 - mu_index_offset); if (muons->at(index_muon).innerTrack().isNonnull()) - get(dnn::muon_numberOfValidHits) = getValueNorm(muons->at(index_muon).numberOfValidHits(), 21.84f, 10.59f); + get(dnn::muon_numberOfValidHits) = + sp.scale(muons->at(index_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(muons->at(index_muon).segmentCompatibility(), dnn::muon_segmentCompatibility - mu_index_offset); + get(dnn::muon_caloCompatibility) = + sp.scale(muons->at(index_muon).caloCompatibility(), dnn::muon_caloCompatibility - mu_index_offset); const bool pfEcalEnergy_valid = muons->at(index_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(muons->at(index_muon).pfEcalEnergy() / muons->at(index_muon).polarP4().pt(), + dnn::muon_rel_pfEcalEnergy - mu_index_offset); } MuonHitMatchV2 hit_match(muons->at(index_muon)); @@ -2306,22 +2447,13 @@ class DeepTauId : public deep_tau::DeepTauBase { {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 +2470,14 @@ 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; + deep_tau::Scaling::FeatureT ft_global = deep_tau::Scaling::FeatureT::GridGlobal; + deep_tau::Scaling::FeatureT ft_PFchH = deep_tau::Scaling::FeatureT::PfCand_chHad; + deep_tau::Scaling::FeatureT ft_PFnH = deep_tau::Scaling::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 +2487,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 deep_tau::Scaling::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 deep_tau::Scaling::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(pfCands.at(index_chH).polarP4().pt() / tau.polarP4().pt(), + dnn::pfCand_chHad_rel_pt - PFchH_index_offset); + get(dnn::pfCand_chHad_deta) = sp.scale(pfCands.at(index_chH).polarP4().eta() - tau.polarP4().eta(), + dnn::pfCand_chHad_deta - PFchH_index_offset); + get(dnn::pfCand_chHad_dphi) = + sp.scale(dPhi(tau.polarP4(), pfCands.at(index_chH).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); - get(dnn::pfCand_chHad_vertex_dx) = - getValueNorm(pfCands.at(index_chH).vertex().x() - pv.position().x(), 0.0005f, 1.735f); - get(dnn::pfCand_chHad_vertex_dy) = - getValueNorm(pfCands.at(index_chH).vertex().y() - pv.position().y(), -0.0008f, 1.752f); - 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( + 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) = sp.scale(pfCands.at(index_chH).vertex().x() - pv.position().x(), + dnn::pfCand_chHad_vertex_dx - PFchH_index_offset); + get(dnn::pfCand_chHad_vertex_dy) = sp.scale(pfCands.at(index_chH).vertex().y() - pv.position().y(), + dnn::pfCand_chHad_vertex_dy - PFchH_index_offset); + get(dnn::pfCand_chHad_vertex_dz) = sp.scale(pfCands.at(index_chH).vertex().z() - pv.position().z(), + dnn::pfCand_chHad_vertex_dz - PFchH_index_offset); + get(dnn::pfCand_chHad_vertex_dx_tauFL) = sp.scale( 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( + dnn::pfCand_chHad_vertex_dx_tauFL - PFchH_index_offset); + get(dnn::pfCand_chHad_vertex_dy_tauFL) = sp.scale( 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( + dnn::pfCand_chHad_vertex_dy_tauFL - PFchH_index_offset); + get(dnn::pfCand_chHad_vertex_dz_tauFL) = sp.scale( pfCands.at(index_chH).vertex().z() - pv.position().z() - tau_funcs.getFlightLength(tau, tau_index).z(), - -0.0138f, - 8.622f); + 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 deep_tau::Scaling::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(pfCands.at(index_nH).polarP4().pt() / tau.polarP4().pt(), + dnn::pfCand_nHad_rel_pt - PFnH_index_offset); + get(dnn::pfCand_nHad_deta) = sp.scale(pfCands.at(index_nH).polarP4().eta() - tau.polarP4().eta(), + dnn::pfCand_nHad_deta - PFnH_index_offset); + get(dnn::pfCand_nHad_dphi) = + sp.scale(dPhi(tau.polarP4(), pfCands.at(index_nH).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); } } @@ -2811,6 +2956,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 +2964,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 e26e253b38008..deb7f6a294e79 100644 --- a/RecoTauTag/RecoTau/python/tools/runTauIdMVA.py +++ b/RecoTauTag/RecoTau/python/tools/runTauIdMVA.py @@ -9,7 +9,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 +20,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' : { @@ -665,6 +665,7 @@ def runTauID(self): graph_file = cms.vstring(file_names), mem_mapped = cms.bool(False), version = cms.uint32(self.getDeepTauVersion(file_names[0])[1]), + sub_version = cms.int32(0), debug_level = cms.int32(0), disable_dxy_pca = cms.bool(False) )) @@ -724,6 +725,7 @@ def runTauID(self): graph_file = cms.vstring(file_names), mem_mapped = cms.bool(False), version = cms.uint32(self.getDeepTauVersion(file_names[0])[1]), + sub_version = cms.uint32(1), debug_level = cms.int32(0), disable_dxy_pca = cms.bool(True), is_online = cms.bool(False) @@ -735,6 +737,44 @@ 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', + ] + 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]), + sub_version = cms.uint32(5), + debug_level = cms.int32(0), + disable_dxy_pca = cms.bool(True), + disable_hcalFraction_workaround = cms.bool(True), + disable_CellIndex_workaround = cms.bool(True), + is_online = cms.bool(False) + )) + + 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)") @@ -1022,8 +1062,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): @@ -1040,7 +1080,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..c2a2c15cd0388 100644 --- a/RecoTauTag/RecoTau/test/runDeepTauIDsOnMiniAOD.py +++ b/RecoTauTag/RecoTau/test/runDeepTauIDsOnMiniAOD.py @@ -18,12 +18,16 @@ process.load('Configuration.StandardSequences.EndOfProcess_cff') from Configuration.AlCa.GlobalTag import GlobalTag -process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:phase1_2018_realistic', '') +# process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:phase1_2018_realistic', '') +process.GlobalTag = GlobalTag(process.GlobalTag, '122X_mcRun3_2021_realistic_v9', '') # For Run3 DeepTau_v2p5 tests # Input source process.source = cms.Source('PoolSource', fileNames = cms.untracked.vstring( - # File from dataset TTToSemiLeptonic_TuneCP5_13TeV-powheg-pythia8 - '/store/mc/RunIISummer20UL18MiniAOD/TTToSemiLeptonic_TuneCP5_13TeV-powheg-pythia8/MINIAODSIM/106X_upgrade2018_realistic_v11_L1v1-v2/00000/009636D7-07B2-DB49-882D-C251FD62CCE7.root' +# # File from dataset TTToSemiLeptonic_TuneCP5_13TeV-powheg-pythia8 +# '/store/mc/RunIISummer20UL18MiniAOD/TTToSemiLeptonic_TuneCP5_13TeV-powheg-pythia8/MINIAODSIM/106X_upgrade2018_realistic_v11_L1v1-v2/00000/009636D7-07B2-DB49-882D-C251FD62CCE7.root' + + # For Run3 DeepTau_v2p5 tests + '/store/mc/Run3Winter22MiniAOD/QCD_Pt-170to300_EMEnriched_TuneCP5_13p6TeV_pythia8/MINIAODSIM/FlatPU0to70_122X_mcRun3_2021_realistic_v9-v2/2530000/20f60cc2-16b5-44c9-8a3e-6976938e8aff.root' )) process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(eventsToProcess) ) @@ -33,6 +37,7 @@ toKeep = [ "2017v2", "dR0p32017v2", "newDM2017v2", # "deepTau2017v1", "deepTau2017v2p1", + "deepTau2018v2p5", # "DPFTau_2016_v0", # "DPFTau_2016_v1", "againstEle2018",