diff --git a/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py b/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py index c7d3af3e20857..cb06370258b5a 100644 --- a/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py +++ b/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py @@ -382,8 +382,8 @@ def _add_deepFlavour(process): toKeep = ['deepTau2017v2p1','deepTau2018v2p5'] ) from Configuration.Eras.Modifier_phase2_common_cff import phase2_common #Phase2 Tau MVA - phase2_common.toModify(tauIdEmbedder.toKeep, func=lambda t:t.append('newDMPhase2v1')) #Phase2 Tau isolation MVA - phase2_common.toModify(tauIdEmbedder.toKeep, func=lambda t:t.append('againstElePhase2v1')) #Phase2 Tau anti-e MVA + _tauIds_phase2 = ['newDMPhase2v1','againstElePhase2v1'] + phase2_common.toModify(tauIdEmbedder.toKeep, func=lambda t:t.extend(_tauIds_phase2)) tauIdEmbedder.runTauID() addToProcessAndTask(_noUpdatedTauName, process.slimmedTaus.clone(),process,task) delattr(process, 'slimmedTaus') diff --git a/RecoTauTag/RecoTau/interface/DeepTauScaling.h b/RecoTauTag/RecoTau/interface/DeepTauScaling.h index 08ef80ec305b1..c6820d9db19b7 100644 --- a/RecoTauTag/RecoTau/interface/DeepTauScaling.h +++ b/RecoTauTag/RecoTau/interface/DeepTauScaling.h @@ -724,6 +724,343 @@ namespace deep_tau { }; // end scalingParamsMap_v2p5 + const std::map, ScalingParams> scalingParamsMap_PhaseIIv2p5 = { + {std::make_pair(FeatureT::TauFlat, false), + { + // mean_ + {100.0, 510.0, 0.0, + 0.5718, 2.181, 0, + 1, 0, 14.32, + 0, 2.243, 12.67, + 0, 0, 0, + 0.4827, 101.3, 0, + 0.001571, 3.935, 0, + 0.002075, 4.328, 0.001592, + 0, 93.74, 0.0003602, + -1.718e-05, -0.001134, -2.712, + 0.5, 0.5, 0.007457, + 0.5, 1.072, 0, + 0.5, 0, 1.5707963267948966, + 4.13, 0.0, 0, + -0.0008631}, + + // std_ + {100.0, 490.0, 3.0, + 0.5081, 1.593, 1, + 1, 1, 41.7, + 1, 6.779, 39.88, + 1, 1, 1, + 2.298, 32.93, 1, + 0.008156, 8.897, 1, + 0.01112, 8.502, 0.8673, + 1, 862.9, 0.3587, + 0.3585, 1.599, 19.88, + 0.5, 0.5, 0.01698, + 0.5, 0.5388, 1, + 0.5, 1, 1.5707963267948966, + 3.313, 1.0, 1, + 0.9046}, + + // 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_ + {100.0, 510.0, 0.0, 0}, + // std_ + {100.0, 490.0, 3.0, 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.1106, 0.0, 0.0, 0, 0, 0, 0, 7.5, -0.000121, 5.664e-06, + 0.002146, -0.001255, -0.0001182, 0.003788, 0, 0.0008399, 6.696, 0.02434, 827.1, 2.902, 11.96}, + + // std_ + {1, 1.069, 0.5, 0.5, 1, 1, 1, 1, 7.5, 0.11, 0.1115, + 5.572, 0.4267, 0.4208, 6.163, 1, 0.09652, 10.57, 5.509, 1507.0, 11.02, 6.747}, + + // 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.8424, 0.0, 0.0, 0, 0, 0, 0, 7.5, -1.594e-05, -1.615e-05, + 0.001503, -0.0001738, -0.00201, 0.008298, 0, 3.245e-05, 2.908, 0.001685, 105.5, 1.305, 11.81}, + + // std_ + {1, 0.6145, 0.1, 0.1, 1, 1, 1, 1, 7.5, 0.01716, 0.01745, + 1.209, 0.5551, 0.5364, 3.608, 1, 0.02022, 6.137, 1.189, 877.8, 5.948, 6.481}, + + // 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.01285, 0.0, 0.0, 0, 0, 0, 0, 0, 3.5, 4.308e-06, 1.919e-06, + -0.0005881, -0.0009704, 0.000131, 0.001519, 0, 0.007348, 12.2, 4.698, 3080.0, 32.8, 5.8}, + + // std + {1, 0.07524, 0.5, 0.5, 1, 1, 1, 1, 1, 3.5, 0.003429, 0.003318, + 0.5228, 0.4157, 0.4125, 2.441, 1, 0.03917, 8.802, 5.297, 4449.0, 38.05, 1.6}, + + // 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.1594, 0.0, 0.0, 0, 0, 0, 0, + 0, 3.5, 1.295e-05, -8.435e-06, -0.001344, -0.0006508, -0.0004855, 0.004292, + 0, 0.001246, 7.58, -0.4247, 1903.0, 18.11, 7.873}, + + // std + {1, 0.4276, 0.1, 0.1, 1, 1, 1, 1, 1, 3.5, 0.004268, 0.003182, + 0.6095, 0.3957, 0.394, 2.006, 1, 0.02973, 10.0, 6.273, 3515.0, 39.42, 1.51}, + + // 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.3915, 0.0, 0.0, 0, 0.978, 0.4455, 1.803, 2.508, 2.508, + 1.726, 1.726, 1.957, 2.223, 10.34, 2.985, 1.6, 1.761, 1.041, 0.0001027, + -0.0002442, -0.0002209, 5.576e-05, -0.0004276, -0.0004178, 0, 0, 0.0002244, 3.137, 0.01031, + 52.28, 8.907, 2.1, 7.053, 0, 1.288, 15.6}, + + // std + {1, 1.379, 0.5, 0.5, 1, 2.605, 0.6392, 2.079, 102.2, 102.2, 99.4, 99.4, 41.23, + 1.889, 12.54, 10.94, 9.838, 4.864, 2.771, 0.04308, 0.04422, 0.0429, 0.06296, 0.133, 0.1179, 1, + 1, 0.001352, 13.06, 0.0315, 1867.0, 1.421, 77.27, 6.956, 1, 1.081, 6.592}, + + // 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, 1.005, 0.0, 0.0, 0, 1.219, 0.1747, 2.046, 2.11, 2.11, + 1.784, 1.784, 2.07, 2.439, 45.29, 2.077, 1.602, 2.207, 1.535, 6.492e-06, + -3.824e-06, -5.448e-06, 4.593e-05, 9.523e-05, 4.193e-05, 0, 0, 0.0002632, 2.268, 0.003118, + 4.976, 9.803, 1.455, 6.346, 0, 1.241, 15.65}, + + // std + {1, 1.014, 0.1, 0.1, 1, 0.5406, 0.3296, 1.92, 20.89, 20.89, + 23.88, 23.88, 5.072, 1.783, 39.63, 3.758, 3.153, 4.36, 2.753, 0.01403, + 0.01394, 0.01382, 0.02341, 0.04605, 0.0464, 1, 1, 0.001201, 10.6, 0.004481, + 35.88, 1.185, 36.29, 3.076, 1, 0.726, 5.13}, + + // 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.06569, 0.0, 0.0, 0, 0, 0, 0, + 0, 5.5, -7.842e-05, -0.0001811, 0.0152, 1.847e-05, -0.002452, 0.01452, + 0, -0.0003077, 4.264, 0.01624, 652.1, 0.8343, 21.51}, + + // std + {1, 0.8174, 0.5, 0.5, 1, 1, 1, 1, 1, 5.5, 0.06539, 0.06323, + 6.064, 0.4649, 0.4612, 6.464, 1, 0.0908, 25.46, 6.063, 832.1, 0.8017, 5.72}, + + // 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.9535, 0.0, 0.0, 0, 0, 0, 0, + 0, 5.5, -3.664e-05, 1.199e-05, -0.001638, -0.0003709, 0.0004101, -0.0002903, + 0, 4.724e-05, 2.692, -0.0007676, 69.4, 0.4363, 18.07}, + + // std + {1, 0.6853, 0.1, 0.1, 1, 1, 1, 1, 1, 5.5, 0.02, 0.02026, + 1.248, 0.188, 0.1894, 1.374, 1, 0.02816, 17.5, 1.248, 742.1, 0.6667, 4.928}, + + // 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.1419, 0.0, 0.0, -7.344e-05, 7.819, 0, 35.42, 17.91, 0, 0, 0, 0.05448, + 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, 5.958, 0.5, 0.5, 0.1345, 49.28, 1, 274.6, 5.823, 1, 1, 1, 0.2388, + 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.153, 0.0, 0.0, -1.624e-05, 21.24, 0, 15.0, 18.63, 0, 0, 0, 0.05187, + 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, 35.54, 0.1, 0.1, 0.16, 105.2, 1, 269.2, 4.874, 1, 1, 1, 0.2431, + 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.02063, 0.0, 0.0, 0, 0, 0, 0, 0, + 0, 0, 6.0, 7.994e-06, 1.326e-05, 0.00378, -0.0005101, -2.036e-05, 0.004647, + 0, 0.0002569, 1.772, 0.004969, 695.1, 0.6393, 15.17, 0, 1.3}, + + // std + {1, 0.06009, 0.5, 0.5, 1, 1, 1, 1, 1, 1, 1, 6.0, 0.04616, 0.04631, + 5.925, 0.3523, 0.3541, 6.099, 1, 0.04398, 5.968, 5.843, 756.6, 0.8879, 6.185, 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.1902, 0.0, 0.0, 0, 0, 0, 0, 0, + 0, 0, 6.0, -3.22e-05, 1.892e-05, 0.001798, -0.0005992, 0.0003633, 0.004573, + 0, 8.158e-05, 4.518, 0.006913, 287.4, 0.5699, 16.18, 0, 1.3}, + + // std + {1, 0.3578, 0.1, 0.1, 1, 1, 1, 1, 1, 1, 1, 6.0, 0.0326, 0.03277, + 4.021, 0.413, 0.4153, 4.324, 1, 0.03025, 11.8, 3.547, 728.6, 0.8056, 5.736, 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.01414, 0.0, 0.0, 0, 0, 0}, + + // std + {1, 0.05509, 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.1149, 0.0, 0.0, 0, 0, 0}, + + // std + {1, 0.2151, 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_PhaseIIv2p5 + }; // namespace Scaling }; // namespace deep_tau diff --git a/RecoTauTag/RecoTau/plugins/DeepTauId.cc b/RecoTauTag/RecoTau/plugins/DeepTauId.cc index 88d25848d7cb1..29b52ff14f83f 100644 --- a/RecoTauTag/RecoTau/plugins/DeepTauId.cc +++ b/RecoTauTag/RecoTau/plugins/DeepTauId.cc @@ -881,6 +881,7 @@ class DeepTauId : public deep_tau::DeepTauBase { desc.add>("graph_file", {"RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6.pb"}); desc.add("mem_mapped", false); + desc.add("year", 2017); desc.add("version", 2); desc.add("sub_version", 1); desc.add("debug_level", 0); @@ -926,6 +927,7 @@ class DeepTauId : public deep_tau::DeepTauBase { pfTauTransverseImpactParameters_token_( consumes>>( cfg.getParameter("pfTauTransverseImpactParameters"))), + year_(cfg.getParameter("year")), version_(cfg.getParameter("version")), sub_version_(cfg.getParameter("sub_version")), debug_level(cfg.getParameter("debug_level")), @@ -957,7 +959,11 @@ class DeepTauId : public deep_tau::DeepTauBase { tensorflow::TensorShape{1, static_cast(TauBlockInputs::NumberOfInputs) - static_cast(TauBlockInputs::varsToDrop.size())}); - scalingParamsMap_ = &sc::scalingParamsMap_v2p5; + if (year_ == 2026) { + scalingParamsMap_ = &sc::scalingParamsMap_PhaseIIv2p5; + } else { + scalingParamsMap_ = &sc::scalingParamsMap_v2p5; + } } else throw cms::Exception("DeepTauId") << "subversion " << sub_version_ << " is not supported."; @@ -1236,6 +1242,8 @@ class DeepTauId : public deep_tau::DeepTauBase { edm::Handle rho; event.getByToken(rho_token_, rho); + auto const& eventnr = event.id().event(); + tensorflow::Tensor predictions(tensorflow::DT_FLOAT, {static_cast(taus->size()), deep_tau::NumberOfOutputs}); for (size_t tau_index = 0; tau_index < taus->size(); ++tau_index) { @@ -1263,6 +1271,7 @@ class DeepTauId : public deep_tau::DeepTauBase { *pfCands, vertices->at(0), *rho, + eventnr, pred_vector, tauIDs); } else @@ -1274,6 +1283,7 @@ class DeepTauId : public deep_tau::DeepTauBase { *pfCands, vertices->at(0), *rho, + eventnr, pred_vector, tauIDs); } else { @@ -1310,13 +1320,15 @@ class DeepTauId : public deep_tau::DeepTauBase { const edm::View& pfCands, const reco::Vertex& pv, double rho, + const edm::EventNumber_t& eventnr, std::vector& pred_vector, TauFunc tau_funcs) { using namespace dnn_inputs_v2; if (debug_level >= 2) { std::cout << ":" << std::endl; - std::cout << " tau: pT = " << tau.pt() << ", eta = " << tau.eta() << ", phi = " << tau.phi() << std::endl; + std::cout << " tau: pT = " << tau.pt() << ", eta = " << tau.eta() << ", phi = " << tau.phi() + << ", eventnr = " << eventnr << std::endl; } CellGrid inner_grid(number_of_inner_cell, number_of_inner_cell, 0.02, 0.02, disable_CellIndex_workaround_); CellGrid outer_grid(number_of_outer_cell, number_of_outer_cell, 0.05, 0.05, disable_CellIndex_workaround_); @@ -1357,7 +1369,7 @@ class DeepTauId : public deep_tau::DeepTauBase { checkInputs(*hadronsTensor_[false], "input_outer_hadrons", HadronBlockInputs::NumberOfInputs, &outer_grid); if (save_inputs_) { - std::string json_file_name = "DeepTauId_" + std::to_string(file_counter_) + ".json"; + std::string json_file_name = "DeepTauId_" + std::to_string(eventnr) + "_" + std::to_string(tau_index) + ".json"; json_file_ = new std::ofstream(json_file_name.data()); is_first_block_ = true; (*json_file_) << "{"; @@ -1942,16 +1954,22 @@ class DeepTauId : public deep_tau::DeepTauBase { sp.scale(ele.deltaPhiSuperClusterTrackAtVtx(), dnn::ele_deltaPhiSuperClusterTrackAtVtx - e_index_offset); get(dnn::ele_deltaPhiSeedClusterTrackAtCalo + fill_index_offset_e) = sp.scale(ele.deltaPhiSeedClusterTrackAtCalo(), dnn::ele_deltaPhiSeedClusterTrackAtCalo - e_index_offset); - get(dnn::ele_mvaInput_earlyBrem + fill_index_offset_e) = - sp.scale(ele.mvaInput().earlyBrem, dnn::ele_mvaInput_earlyBrem - e_index_offset); - get(dnn::ele_mvaInput_lateBrem + fill_index_offset_e) = - sp.scale(ele.mvaInput().lateBrem, dnn::ele_mvaInput_lateBrem - e_index_offset); - get(dnn::ele_mvaInput_sigmaEtaEta + fill_index_offset_e) = - sp.scale(ele.mvaInput().sigmaEtaEta, dnn::ele_mvaInput_sigmaEtaEta - e_index_offset); - get(dnn::ele_mvaInput_hadEnergy + fill_index_offset_e) = - sp.scale(ele.mvaInput().hadEnergy, dnn::ele_mvaInput_hadEnergy - e_index_offset); - get(dnn::ele_mvaInput_deltaEta + fill_index_offset_e) = - sp.scale(ele.mvaInput().deltaEta, dnn::ele_mvaInput_deltaEta - e_index_offset); + const bool mva_valid = + (ele.mvaInput().earlyBrem > -2) || + (year_ != + 2026); // Known issue that input can be invalid in Phase2 samples (early/lateBrem==-2, hadEnergy==0, sigmaEtaEta/deltaEta==3.40282e+38). Unknown if also in Run2/3, so don't change there + if (mva_valid) { + get(dnn::ele_mvaInput_earlyBrem + fill_index_offset_e) = + sp.scale(ele.mvaInput().earlyBrem, dnn::ele_mvaInput_earlyBrem - e_index_offset); + get(dnn::ele_mvaInput_lateBrem + fill_index_offset_e) = + sp.scale(ele.mvaInput().lateBrem, dnn::ele_mvaInput_lateBrem - e_index_offset); + get(dnn::ele_mvaInput_sigmaEtaEta + fill_index_offset_e) = + sp.scale(ele.mvaInput().sigmaEtaEta, dnn::ele_mvaInput_sigmaEtaEta - e_index_offset); + get(dnn::ele_mvaInput_hadEnergy + fill_index_offset_e) = + sp.scale(ele.mvaInput().hadEnergy, dnn::ele_mvaInput_hadEnergy - e_index_offset); + get(dnn::ele_mvaInput_deltaEta + fill_index_offset_e) = + sp.scale(ele.mvaInput().deltaEta, dnn::ele_mvaInput_deltaEta - e_index_offset); + } const auto& gsfTrack = ele.gsfTrack(); if (gsfTrack.isNonnull()) { get(dnn::ele_gsfTrack_normalizedChi2 + fill_index_offset_e) = @@ -2419,6 +2437,7 @@ class DeepTauId : public deep_tau::DeepTauBase { edm::EDGetTokenT>> pfTauTransverseImpactParameters_token_; std::string input_layer_, output_layer_; + const unsigned year_; const unsigned version_; const unsigned sub_version_; const int debug_level; diff --git a/RecoTauTag/RecoTau/python/PATTauDiscriminationAgainstElectronMVA6Phase2_cff.py b/RecoTauTag/RecoTau/python/PATTauDiscriminationAgainstElectronMVA6Phase2_cff.py index 162c3f3fb16f7..652ae3963ebf4 100644 --- a/RecoTauTag/RecoTau/python/PATTauDiscriminationAgainstElectronMVA6Phase2_cff.py +++ b/RecoTauTag/RecoTau/python/PATTauDiscriminationAgainstElectronMVA6Phase2_cff.py @@ -1,9 +1,8 @@ import FWCore.ParameterSet.Config as cms # Electron collection merger -mergedSlimmedElectronsForTauId = cms.EDProducer('PATElectronCollectionMerger', - src = cms.VInputTag('slimmedElectrons', 'slimmedElectronsHGC') -) +from RecoTauTag.RecoTau.mergedPhase2SlimmedElectronsForTauId_cff import mergedSlimmedElectronsForTauId + # anti-e phase-2 tauID (Raw) from RecoTauTag.RecoTau.tauDiscriminationAgainstElectronMVA6Phase2_mvaDefs_cff import mvaNames_phase2, mapping_phase2, workingPoints_phase2 from RecoTauTag.RecoTau.TauDiscriminatorTools import noPrediscriminants diff --git a/RecoTauTag/RecoTau/python/mergedPhase2SlimmedElectronsForTauId_cff.py b/RecoTauTag/RecoTau/python/mergedPhase2SlimmedElectronsForTauId_cff.py new file mode 100644 index 0000000000000..5e836c7993795 --- /dev/null +++ b/RecoTauTag/RecoTau/python/mergedPhase2SlimmedElectronsForTauId_cff.py @@ -0,0 +1,6 @@ +import FWCore.ParameterSet.Config as cms + +# Electron collection merger +mergedSlimmedElectronsForTauId = cms.EDProducer('PATElectronCollectionMerger', + src = cms.VInputTag('slimmedElectrons', 'slimmedElectronsHGC') +) diff --git a/RecoTauTag/RecoTau/python/tauIdWPsDefs.py b/RecoTauTag/RecoTau/python/tauIdWPsDefs.py index 134375939e148..e78cc00381529 100644 --- a/RecoTauTag/RecoTau/python/tauIdWPsDefs.py +++ b/RecoTauTag/RecoTau/python/tauIdWPsDefs.py @@ -55,3 +55,32 @@ "VVTight": 0.9931 } } + +WORKING_POINTS_PHASEII_v2p5 = { + "e": { + "VVVLoose": 0.2376, + "VVLoose": 0.3688, + "VLoose": 0.5336, + "Loose": 0.8116, + "Medium": 0.9268, + "Tight": 0.9781, + "VTight": 0.9915, + "VVTight": 0.9961 + }, + "mu": { + "VLoose": 0.0640, + "Loose": 0.0942, + "Medium": 0.5494, + "Tight": 0.9401 + }, + "jet": { + "VVVLoose": 0.4918, + "VVLoose": 0.6920, + "VLoose": 0.8299, + "Loose": 0.9166, + "Medium": 0.9507, + "Tight": 0.9683, + "VTight": 0.9788, + "VVTight": 0.9856 + } +} diff --git a/RecoTauTag/RecoTau/python/tools/runTauIdMVA.py b/RecoTauTag/RecoTau/python/tools/runTauIdMVA.py index b7f5785690c8e..9ee8a3828ba83 100644 --- a/RecoTauTag/RecoTau/python/tools/runTauIdMVA.py +++ b/RecoTauTag/RecoTau/python/tools/runTauIdMVA.py @@ -3,7 +3,7 @@ from RecoTauTag.RecoTau.TauDiscriminatorTools import noPrediscriminants from RecoTauTag.RecoTau.PATTauDiscriminationByMVAIsolationRun2_cff import patDiscriminationByIsolationMVArun2v1raw, patDiscriminationByIsolationMVArun2v1 from RecoTauTag.RecoTau.DeepTau_cfi import DeepTau -from RecoTauTag.RecoTau.tauIdWPsDefs import WORKING_POINTS_v2p1, WORKING_POINTS_v2p5 +from RecoTauTag.RecoTau.tauIdWPsDefs import WORKING_POINTS_v2p1, WORKING_POINTS_v2p5, WORKING_POINTS_PHASEII_v2p5 import os import re @@ -12,7 +12,7 @@ class TauIDEmbedder(object): """class to rerun the tau seq and acces trainings from the database""" availableDiscriminators = [ "2017v1", "2017v2", "newDM2017v2", "dR0p32017v2", "2016v1", "newDM2016v1", - "deepTau2017v2", "deepTau2017v2p1", "deepTau2018v2p5", + "deepTau2017v2", "deepTau2017v2p1", "deepTau2018v2p5", "deepTau2026v2p5", "againstEle2018", "newDMPhase2v1", "againstElePhase2v1" @@ -22,7 +22,7 @@ def __init__(self, process, debug = False, originalTauName = "slimmedTaus", updatedTauName = "slimmedTausNewID", postfix = "", - toKeep = ["deepTau2017v2p1", "deepTau2018v2p5"], + toKeep = ["deepTau2017v2p1", "deepTau2018v2p5", "deepTau2026v2p5"], tauIdDiscrMVA_trainings_run2_2017 = { 'tauIdMVAIsoDBoldDMwLT2017' : "tauIdMVAIsoDBoldDMwLT2017", }, tauIdDiscrMVA_WPs_run2_2017 = { 'tauIdMVAIsoDBoldDMwLT2017' : { @@ -560,7 +560,7 @@ def runTauID(self): tauIDSources.byVVTightIsolationMVArun2v1DBnewDMwLT2016 = self.tauIDMVAinputs(_byIsolationNewDMMVArun2016v1, "_WPEff40") if "deepTau2017v2" in self.toKeep: - if self.debug: print ("Adding DeepTau IDs") + if self.debug: print ("Adding DeepTau v2 IDs") _deepTauName = "deepTau2017v2" workingPoints_ = WORKING_POINTS_v2p1 @@ -575,6 +575,7 @@ def runTauID(self): Prediscriminants = noPrediscriminants, taus = self.originalTauName, graph_file = file_names, + year = full_version[0], version = full_version[1], sub_version = 1 #MB: subversion cannot be properly deduced from file names; it should be 1 also for v2 )) @@ -587,7 +588,7 @@ def runTauID(self): if "deepTau2017v2p1" in self.toKeep: - if self.debug: print ("Adding DeepTau IDs") + if self.debug: print ("Adding DeepTau v2p1 IDs") _deepTauName = "deepTau2017v2p1" workingPoints_ = WORKING_POINTS_v2p1 @@ -602,6 +603,7 @@ def runTauID(self): Prediscriminants = noPrediscriminants, taus = self.originalTauName, graph_file = file_names, + year = full_version[0], version = full_version[1], sub_version = 1, #MB: subversion cannot be properly deduced from file names disable_dxy_pca = True @@ -614,7 +616,7 @@ def runTauID(self): _rerunMvaIsolationSequence += _deepTauProducer if "deepTau2018v2p5" in self.toKeep: - if self.debug: print ("Adding DeepTau IDs") + if self.debug: print ("Adding DeepTau v2p5 IDs") _deepTauName = "deepTau2018v2p5" workingPoints_ = WORKING_POINTS_v2p5 @@ -629,6 +631,7 @@ def runTauID(self): Prediscriminants = noPrediscriminants, taus = self.originalTauName, graph_file = file_names, + year = full_version[0], version = full_version[1], sub_version = full_version[2], disable_dxy_pca = True, @@ -642,6 +645,44 @@ def runTauID(self): _rerunMvaIsolationTask.add(_deepTauProducer) _rerunMvaIsolationSequence += _deepTauProducer + if "deepTau2026v2p5" in self.toKeep: + if self.debug: print ("Adding Phase2 DeepTau v2p5 IDs") + + _deepTauName = "deepTau2026v2p5" + workingPoints_ = WORKING_POINTS_PHASEII_v2p5 + + file_names = [ + 'core:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2026v2p5_core.pb', + 'inner:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2026v2p5_inner.pb', + 'outer:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2026v2p5_outer.pb', + ] + full_version = self.getDeepTauVersion(file_names[0]) + setattr(self.process,_deepTauName+self.postfix,DeepTau.clone( + Prediscriminants = noPrediscriminants, + taus = self.originalTauName, + graph_file = file_names, + year = full_version[0], + version = full_version[1], + sub_version = full_version[2], + disable_dxy_pca = True, + disable_hcalFraction_workaround = True, + disable_CellIndex_workaround = True + )) + + from RecoTauTag.RecoTau.mergedPhase2SlimmedElectronsForTauId_cff import mergedSlimmedElectronsForTauId + if not hasattr(self.process,"mergedSlimmedElectronsForTauId"): + self.process.mergedSlimmedElectronsForTauId = mergedSlimmedElectronsForTauId + setattr(getattr(self.process, _deepTauName+self.postfix), "electrons", cms.InputTag("mergedSlimmedElectronsForTauId")) + setattr(getattr(self.process, _deepTauName+self.postfix), "vertices", cms.InputTag("offlineSlimmedPrimaryVertices4D")) + + self.processDeepProducer(_deepTauName, tauIDSources, workingPoints_) + + _deepTauProducer = getattr(self.process,_deepTauName+self.postfix) + _rerunMvaIsolationTask.add(self.process.mergedSlimmedElectronsForTauId) + _rerunMvaIsolationTask.add(_deepTauProducer) + _rerunMvaIsolationSequence += self.process.mergedSlimmedElectronsForTauId + _rerunMvaIsolationSequence += _deepTauProducer + if "againstEle2018" in self.toKeep: antiElectronDiscrMVA6_version = "MVA6v3_noeveto" ### Define new anti-e discriminants diff --git a/RecoTauTag/RecoTau/test/runDeepTauIDsOnMiniAOD.py b/RecoTauTag/RecoTau/test/runDeepTauIDsOnMiniAOD.py index 8cd959c3b4bda..3b7df0bb10ed8 100644 --- a/RecoTauTag/RecoTau/test/runDeepTauIDsOnMiniAOD.py +++ b/RecoTauTag/RecoTau/test/runDeepTauIDsOnMiniAOD.py @@ -10,20 +10,27 @@ minimalOutput = True eventsToProcess = 100 nThreads = 1 +phase2 = False process = cms.Process('TauID') process.load('Configuration.StandardSequences.MagneticField_cff') -process.load('Configuration.Geometry.GeometryRecoDB_cff') process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') process.load('Configuration.StandardSequences.EndOfProcess_cff') from Configuration.AlCa.GlobalTag import GlobalTag -process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:phase1_2018_realistic', '') +if phase2: + process.load('Configuration.Geometry.GeometryExtended2026D88Reco_cff') + process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:phase2_realistic_T25', '') + inputfile = '/store/mc/Phase2Spring21DRMiniAOD/TTbar_TuneCP5_14TeV-pythia8/MINIAODSIM/PU200Phase2D80_113X_mcRun4_realistic_T25_v1_ext1-v1/280000/04e6741c-489a-4fed-9e0c-d7703c274b5a.root' +else: + process.load('Configuration.Geometry.GeometryRecoDB_cff') + process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:phase1_2018_realistic', '') + inputfile = '/store/mc/RunIISummer20UL18MiniAOD/TTToSemiLeptonic_TuneCP5_13TeV-powheg-pythia8/MINIAODSIM/106X_upgrade2018_realistic_v11_L1v1-v2/00000/009636D7-07B2-DB49-882D-C251FD62CCE7.root' # 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' + inputfile )) process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(eventsToProcess) ) @@ -38,6 +45,12 @@ # "DPFTau_2016_v1", "againstEle2018", ] +if phase2: + toKeep = [ "newDMPhase2v1", + # "deepTau2018v2p5", + "deepTau2026v2p5", + "againstElePhase2v1", + ] tauIdEmbedder = tauIdConfig.TauIDEmbedder(process, debug = False, updatedTauName = updatedTauName, toKeep = toKeep) @@ -67,6 +80,10 @@ process.out.outputCommands.append("keep *_"+updatedTauName+"_*_*") process.out.outputCommands.append("keep *_"+updatedTauName+postfix+"_*_*") +# Adapt to old phase2 input samples where slimmedElectronsHGC are called slimmedElectronsFromMultiCl +if phase2: + process.mergedSlimmedElectronsForTauId.src = ["slimmedElectrons","slimmedElectronsFromMultiCl"] + # Path and EndPath definitions process.p = cms.Path( process.rerunMvaIsolationSequence *