CMS 3D CMS Logo

DeepTauId.cc
Go to the documentation of this file.
1 /*
2  * \class DeepTauId
3  *
4  * Tau identification using Deep NN.
5  *
6  * \author Konstantin Androsov, INFN Pisa
7  */
8 
12 
13 namespace deep_tau {
14  constexpr int NumberOfOutputs = 4;
15 }
16 
17 namespace {
18 
19  struct dnn_inputs_2017v1 {
20  enum vars {
21  pt = 0,
22  eta,
23  mass,
24  decayMode,
25  chargedIsoPtSum,
26  neutralIsoPtSum,
27  neutralIsoPtSumWeight,
28  photonPtSumOutsideSignalCone,
29  puCorrPtSum,
30  dxy,
31  dxy_sig,
32  dz,
33  ip3d,
34  ip3d_sig,
35  hasSecondaryVertex,
36  flightLength_r,
37  flightLength_dEta,
38  flightLength_dPhi,
39  flightLength_sig,
40  leadChargedHadrCand_pt,
41  leadChargedHadrCand_dEta,
42  leadChargedHadrCand_dPhi,
43  leadChargedHadrCand_mass,
48  leadingTrackNormChi2,
49  e_ratio,
50  gj_angle_diff,
51  n_photons,
52  emFraction,
53  has_gsf_track,
54  inside_ecal_crack,
55  gsf_ele_matched,
56  gsf_ele_pt,
57  gsf_ele_dEta,
58  gsf_ele_dPhi,
59  gsf_ele_mass,
60  gsf_ele_Ee,
61  gsf_ele_Egamma,
62  gsf_ele_Pin,
63  gsf_ele_Pout,
64  gsf_ele_EtotOverPin,
65  gsf_ele_Eecal,
66  gsf_ele_dEta_SeedClusterTrackAtCalo,
67  gsf_ele_dPhi_SeedClusterTrackAtCalo,
68  gsf_ele_mvaIn_sigmaEtaEta,
69  gsf_ele_mvaIn_hadEnergy,
70  gsf_ele_mvaIn_deltaEta,
71  gsf_ele_Chi2NormGSF,
72  gsf_ele_GSFNumHits,
73  gsf_ele_GSFTrackResol,
74  gsf_ele_GSFTracklnPt,
75  gsf_ele_Chi2NormKF,
76  gsf_ele_KFNumHits,
77  leadChargedCand_etaAtEcalEntrance,
78  leadChargedCand_pt,
79  leadChargedHadrCand_HoP,
80  leadChargedHadrCand_EoP,
81  tau_visMass_innerSigCone,
82  n_matched_muons,
83  muon_pt,
84  muon_dEta,
85  muon_dPhi,
86  muon_n_matches_DT_1,
87  muon_n_matches_DT_2,
88  muon_n_matches_DT_3,
89  muon_n_matches_DT_4,
90  muon_n_matches_CSC_1,
91  muon_n_matches_CSC_2,
92  muon_n_matches_CSC_3,
93  muon_n_matches_CSC_4,
94  muon_n_hits_DT_2,
95  muon_n_hits_DT_3,
96  muon_n_hits_DT_4,
97  muon_n_hits_CSC_2,
98  muon_n_hits_CSC_3,
99  muon_n_hits_CSC_4,
100  muon_n_hits_RPC_2,
101  muon_n_hits_RPC_3,
102  muon_n_hits_RPC_4,
103  muon_n_stations_with_matches_03,
104  muon_n_stations_with_hits_23,
105  signalChargedHadrCands_sum_innerSigCone_pt,
106  signalChargedHadrCands_sum_innerSigCone_dEta,
107  signalChargedHadrCands_sum_innerSigCone_dPhi,
108  signalChargedHadrCands_sum_innerSigCone_mass,
109  signalChargedHadrCands_sum_outerSigCone_pt,
110  signalChargedHadrCands_sum_outerSigCone_dEta,
111  signalChargedHadrCands_sum_outerSigCone_dPhi,
112  signalChargedHadrCands_sum_outerSigCone_mass,
113  signalChargedHadrCands_nTotal_innerSigCone,
114  signalChargedHadrCands_nTotal_outerSigCone,
115  signalNeutrHadrCands_sum_innerSigCone_pt,
116  signalNeutrHadrCands_sum_innerSigCone_dEta,
117  signalNeutrHadrCands_sum_innerSigCone_dPhi,
118  signalNeutrHadrCands_sum_innerSigCone_mass,
119  signalNeutrHadrCands_sum_outerSigCone_pt,
120  signalNeutrHadrCands_sum_outerSigCone_dEta,
121  signalNeutrHadrCands_sum_outerSigCone_dPhi,
122  signalNeutrHadrCands_sum_outerSigCone_mass,
123  signalNeutrHadrCands_nTotal_innerSigCone,
124  signalNeutrHadrCands_nTotal_outerSigCone,
125  signalGammaCands_sum_innerSigCone_pt,
126  signalGammaCands_sum_innerSigCone_dEta,
127  signalGammaCands_sum_innerSigCone_dPhi,
128  signalGammaCands_sum_innerSigCone_mass,
129  signalGammaCands_sum_outerSigCone_pt,
130  signalGammaCands_sum_outerSigCone_dEta,
131  signalGammaCands_sum_outerSigCone_dPhi,
132  signalGammaCands_sum_outerSigCone_mass,
133  signalGammaCands_nTotal_innerSigCone,
134  signalGammaCands_nTotal_outerSigCone,
135  isolationChargedHadrCands_sum_pt,
136  isolationChargedHadrCands_sum_dEta,
137  isolationChargedHadrCands_sum_dPhi,
138  isolationChargedHadrCands_sum_mass,
139  isolationChargedHadrCands_nTotal,
140  isolationNeutrHadrCands_sum_pt,
141  isolationNeutrHadrCands_sum_dEta,
142  isolationNeutrHadrCands_sum_dPhi,
143  isolationNeutrHadrCands_sum_mass,
144  isolationNeutrHadrCands_nTotal,
145  isolationGammaCands_sum_pt,
146  isolationGammaCands_sum_dEta,
147  isolationGammaCands_sum_dPhi,
148  isolationGammaCands_sum_mass,
149  isolationGammaCands_nTotal,
150  NumberOfInputs
151  };
152  };
153 
154  namespace dnn_inputs_2017_v2 {
155  constexpr int number_of_inner_cell = 11;
156  constexpr int number_of_outer_cell = 21;
157  constexpr int number_of_conv_features = 64;
158  namespace TauBlockInputs {
159  enum vars {
160  rho = 0,
161  tau_pt,
162  tau_eta,
163  tau_phi,
164  tau_mass,
165  tau_E_over_pt,
166  tau_charge,
167  tau_n_charged_prongs,
168  tau_n_neutral_prongs,
169  chargedIsoPtSum,
170  chargedIsoPtSumdR03_over_dR05,
171  footprintCorrection,
172  neutralIsoPtSum,
173  neutralIsoPtSumWeight_over_neutralIsoPtSum,
174  neutralIsoPtSumWeightdR03_over_neutralIsoPtSum,
175  neutralIsoPtSumdR03_over_dR05,
176  photonPtSumOutsideSignalCone,
177  puCorrPtSum,
178  tau_dxy_pca_x,
179  tau_dxy_pca_y,
180  tau_dxy_pca_z,
181  tau_dxy_valid,
182  tau_dxy,
183  tau_dxy_sig,
184  tau_ip3d_valid,
185  tau_ip3d,
186  tau_ip3d_sig,
187  tau_dz,
188  tau_dz_sig_valid,
189  tau_dz_sig,
190  tau_flightLength_x,
191  tau_flightLength_y,
192  tau_flightLength_z,
193  tau_flightLength_sig,
194  tau_pt_weighted_deta_strip,
195  tau_pt_weighted_dphi_strip,
196  tau_pt_weighted_dr_signal,
197  tau_pt_weighted_dr_iso,
198  tau_leadingTrackNormChi2,
199  tau_e_ratio_valid,
200  tau_e_ratio,
201  tau_gj_angle_diff_valid,
202  tau_gj_angle_diff,
203  tau_n_photons,
204  tau_emFraction,
205  tau_inside_ecal_crack,
206  leadChargedCand_etaAtEcalEntrance_minus_tau_eta,
207  NumberOfInputs
208  };
209  }
210 
211  namespace EgammaBlockInputs {
212  enum vars {
213  rho = 0,
214  tau_pt,
215  tau_eta,
216  tau_inside_ecal_crack,
217  pfCand_ele_valid,
218  pfCand_ele_rel_pt,
219  pfCand_ele_deta,
220  pfCand_ele_dphi,
221  pfCand_ele_pvAssociationQuality,
222  pfCand_ele_puppiWeight,
223  pfCand_ele_charge,
224  pfCand_ele_lostInnerHits,
225  pfCand_ele_numberOfPixelHits,
226  pfCand_ele_vertex_dx,
227  pfCand_ele_vertex_dy,
228  pfCand_ele_vertex_dz,
229  pfCand_ele_vertex_dx_tauFL,
230  pfCand_ele_vertex_dy_tauFL,
231  pfCand_ele_vertex_dz_tauFL,
232  pfCand_ele_hasTrackDetails,
233  pfCand_ele_dxy,
234  pfCand_ele_dxy_sig,
235  pfCand_ele_dz,
236  pfCand_ele_dz_sig,
237  pfCand_ele_track_chi2_ndof,
238  pfCand_ele_track_ndof,
239  ele_valid,
240  ele_rel_pt,
241  ele_deta,
242  ele_dphi,
243  ele_cc_valid,
244  ele_cc_ele_rel_energy,
245  ele_cc_gamma_rel_energy,
246  ele_cc_n_gamma,
247  ele_rel_trackMomentumAtVtx,
248  ele_rel_trackMomentumAtCalo,
249  ele_rel_trackMomentumOut,
250  ele_rel_trackMomentumAtEleClus,
251  ele_rel_trackMomentumAtVtxWithConstraint,
252  ele_rel_ecalEnergy,
253  ele_ecalEnergy_sig,
254  ele_eSuperClusterOverP,
255  ele_eSeedClusterOverP,
256  ele_eSeedClusterOverPout,
257  ele_eEleClusterOverPout,
258  ele_deltaEtaSuperClusterTrackAtVtx,
259  ele_deltaEtaSeedClusterTrackAtCalo,
260  ele_deltaEtaEleClusterTrackAtCalo,
261  ele_deltaPhiEleClusterTrackAtCalo,
262  ele_deltaPhiSuperClusterTrackAtVtx,
263  ele_deltaPhiSeedClusterTrackAtCalo,
264  ele_mvaInput_earlyBrem,
265  ele_mvaInput_lateBrem,
266  ele_mvaInput_sigmaEtaEta,
267  ele_mvaInput_hadEnergy,
268  ele_mvaInput_deltaEta,
269  ele_gsfTrack_normalizedChi2,
270  ele_gsfTrack_numberOfValidHits,
271  ele_rel_gsfTrack_pt,
272  ele_gsfTrack_pt_sig,
273  ele_has_closestCtfTrack,
274  ele_closestCtfTrack_normalizedChi2,
275  ele_closestCtfTrack_numberOfValidHits,
276  pfCand_gamma_valid,
277  pfCand_gamma_rel_pt,
278  pfCand_gamma_deta,
279  pfCand_gamma_dphi,
280  pfCand_gamma_pvAssociationQuality,
281  pfCand_gamma_fromPV,
282  pfCand_gamma_puppiWeight,
283  pfCand_gamma_puppiWeightNoLep,
284  pfCand_gamma_lostInnerHits,
285  pfCand_gamma_numberOfPixelHits,
286  pfCand_gamma_vertex_dx,
287  pfCand_gamma_vertex_dy,
288  pfCand_gamma_vertex_dz,
289  pfCand_gamma_vertex_dx_tauFL,
290  pfCand_gamma_vertex_dy_tauFL,
291  pfCand_gamma_vertex_dz_tauFL,
292  pfCand_gamma_hasTrackDetails,
293  pfCand_gamma_dxy,
294  pfCand_gamma_dxy_sig,
295  pfCand_gamma_dz,
296  pfCand_gamma_dz_sig,
297  pfCand_gamma_track_chi2_ndof,
298  pfCand_gamma_track_ndof,
299  NumberOfInputs
300  };
301  }
302 
303  namespace MuonBlockInputs {
304  enum vars {
305  rho = 0,
306  tau_pt,
307  tau_eta,
308  tau_inside_ecal_crack,
309  pfCand_muon_valid,
310  pfCand_muon_rel_pt,
311  pfCand_muon_deta,
312  pfCand_muon_dphi,
313  pfCand_muon_pvAssociationQuality,
314  pfCand_muon_fromPV,
315  pfCand_muon_puppiWeight,
316  pfCand_muon_charge,
317  pfCand_muon_lostInnerHits,
318  pfCand_muon_numberOfPixelHits,
319  pfCand_muon_vertex_dx,
320  pfCand_muon_vertex_dy,
321  pfCand_muon_vertex_dz,
322  pfCand_muon_vertex_dx_tauFL,
323  pfCand_muon_vertex_dy_tauFL,
324  pfCand_muon_vertex_dz_tauFL,
325  pfCand_muon_hasTrackDetails,
326  pfCand_muon_dxy,
327  pfCand_muon_dxy_sig,
328  pfCand_muon_dz,
329  pfCand_muon_dz_sig,
330  pfCand_muon_track_chi2_ndof,
331  pfCand_muon_track_ndof,
332  muon_valid,
333  muon_rel_pt,
334  muon_deta,
335  muon_dphi,
336  muon_dxy,
337  muon_dxy_sig,
338  muon_normalizedChi2_valid,
339  muon_normalizedChi2,
340  muon_numberOfValidHits,
341  muon_segmentCompatibility,
342  muon_caloCompatibility,
343  muon_pfEcalEnergy_valid,
344  muon_rel_pfEcalEnergy,
345  muon_n_matches_DT_1,
346  muon_n_matches_DT_2,
347  muon_n_matches_DT_3,
348  muon_n_matches_DT_4,
349  muon_n_matches_CSC_1,
350  muon_n_matches_CSC_2,
351  muon_n_matches_CSC_3,
352  muon_n_matches_CSC_4,
353  muon_n_matches_RPC_1,
354  muon_n_matches_RPC_2,
355  muon_n_matches_RPC_3,
356  muon_n_matches_RPC_4,
357  muon_n_hits_DT_1,
358  muon_n_hits_DT_2,
359  muon_n_hits_DT_3,
360  muon_n_hits_DT_4,
361  muon_n_hits_CSC_1,
362  muon_n_hits_CSC_2,
363  muon_n_hits_CSC_3,
364  muon_n_hits_CSC_4,
365  muon_n_hits_RPC_1,
366  muon_n_hits_RPC_2,
367  muon_n_hits_RPC_3,
368  muon_n_hits_RPC_4,
369  NumberOfInputs
370  };
371  }
372 
373  namespace HadronBlockInputs {
374  enum vars {
375  rho = 0,
376  tau_pt,
377  tau_eta,
378  tau_inside_ecal_crack,
379  pfCand_chHad_valid,
380  pfCand_chHad_rel_pt,
381  pfCand_chHad_deta,
382  pfCand_chHad_dphi,
383  pfCand_chHad_leadChargedHadrCand,
384  pfCand_chHad_pvAssociationQuality,
385  pfCand_chHad_fromPV,
386  pfCand_chHad_puppiWeight,
387  pfCand_chHad_puppiWeightNoLep,
388  pfCand_chHad_charge,
389  pfCand_chHad_lostInnerHits,
390  pfCand_chHad_numberOfPixelHits,
391  pfCand_chHad_vertex_dx,
392  pfCand_chHad_vertex_dy,
393  pfCand_chHad_vertex_dz,
394  pfCand_chHad_vertex_dx_tauFL,
395  pfCand_chHad_vertex_dy_tauFL,
396  pfCand_chHad_vertex_dz_tauFL,
397  pfCand_chHad_hasTrackDetails,
398  pfCand_chHad_dxy,
399  pfCand_chHad_dxy_sig,
400  pfCand_chHad_dz,
401  pfCand_chHad_dz_sig,
402  pfCand_chHad_track_chi2_ndof,
403  pfCand_chHad_track_ndof,
404  pfCand_chHad_hcalFraction,
405  pfCand_chHad_rawCaloFraction,
406  pfCand_nHad_valid,
407  pfCand_nHad_rel_pt,
408  pfCand_nHad_deta,
409  pfCand_nHad_dphi,
410  pfCand_nHad_puppiWeight,
411  pfCand_nHad_puppiWeightNoLep,
412  pfCand_nHad_hcalFraction,
413  NumberOfInputs
414  };
415  }
416  } // namespace dnn_inputs_2017_v2
417 
418  struct TauFunc {
419  const reco::TauDiscriminatorContainer* basicTauDiscriminatorCollection;
420  const reco::TauDiscriminatorContainer* basicTauDiscriminatordR03Collection;
422  pfTauTransverseImpactParameters;
423 
425  std::map<BasicDiscr, size_t> indexMap;
426  std::map<BasicDiscr, size_t> indexMapdR03;
427 
428  const float getChargedIsoPtSum(const reco::PFTau& tau, const edm::RefToBase<reco::BaseTau> tau_ref) const {
429  return (*basicTauDiscriminatorCollection)[tau_ref].rawValues.at(indexMap.at(BasicDiscr::ChargedIsoPtSum));
430  }
431  const float getChargedIsoPtSum(const pat::Tau& tau, const edm::RefToBase<reco::BaseTau> tau_ref) const {
432  return tau.tauID("chargedIsoPtSum");
433  }
434  const float getChargedIsoPtSumdR03(const reco::PFTau& tau, const edm::RefToBase<reco::BaseTau> tau_ref) const {
435  return (*basicTauDiscriminatordR03Collection)[tau_ref].rawValues.at(indexMapdR03.at(BasicDiscr::ChargedIsoPtSum));
436  }
437  const float getChargedIsoPtSumdR03(const pat::Tau& tau, const edm::RefToBase<reco::BaseTau> tau_ref) const {
438  return tau.tauID("chargedIsoPtSumdR03");
439  }
440  const float getFootprintCorrectiondR03(const reco::PFTau& tau, const edm::RefToBase<reco::BaseTau> tau_ref) const {
441  return (*basicTauDiscriminatordR03Collection)[tau_ref].rawValues.at(
442  indexMapdR03.at(BasicDiscr::FootprintCorrection));
443  }
444  const float getFootprintCorrectiondR03(const pat::Tau& tau, const edm::RefToBase<reco::BaseTau> tau_ref) const {
445  return tau.tauID("footprintCorrectiondR03");
446  }
447  const float getNeutralIsoPtSum(const reco::PFTau& tau, const edm::RefToBase<reco::BaseTau> tau_ref) const {
448  return (*basicTauDiscriminatorCollection)[tau_ref].rawValues.at(indexMap.at(BasicDiscr::NeutralIsoPtSum));
449  }
450  const float getNeutralIsoPtSum(const pat::Tau& tau, const edm::RefToBase<reco::BaseTau> tau_ref) const {
451  return tau.tauID("neutralIsoPtSum");
452  }
453  const float getNeutralIsoPtSumdR03(const reco::PFTau& tau, const edm::RefToBase<reco::BaseTau> tau_ref) const {
454  return (*basicTauDiscriminatordR03Collection)[tau_ref].rawValues.at(indexMapdR03.at(BasicDiscr::NeutralIsoPtSum));
455  }
456  const float getNeutralIsoPtSumdR03(const pat::Tau& tau, const edm::RefToBase<reco::BaseTau> tau_ref) const {
457  return tau.tauID("neutralIsoPtSumdR03");
458  }
459  const float getNeutralIsoPtSumWeight(const reco::PFTau& tau, const edm::RefToBase<reco::BaseTau> tau_ref) const {
460  return (*basicTauDiscriminatorCollection)[tau_ref].rawValues.at(indexMap.at(BasicDiscr::NeutralIsoPtSumWeight));
461  }
462  const float getNeutralIsoPtSumWeight(const pat::Tau& tau, const edm::RefToBase<reco::BaseTau> tau_ref) const {
463  return tau.tauID("neutralIsoPtSumWeight");
464  }
465  const float getNeutralIsoPtSumdR03Weight(const reco::PFTau& tau,
466  const edm::RefToBase<reco::BaseTau> tau_ref) const {
467  return (*basicTauDiscriminatordR03Collection)[tau_ref].rawValues.at(
468  indexMapdR03.at(BasicDiscr::NeutralIsoPtSumWeight));
469  }
470  const float getNeutralIsoPtSumdR03Weight(const pat::Tau& tau, const edm::RefToBase<reco::BaseTau> tau_ref) const {
471  return tau.tauID("neutralIsoPtSumWeightdR03");
472  }
473  const float getPhotonPtSumOutsideSignalCone(const reco::PFTau& tau,
474  const edm::RefToBase<reco::BaseTau> tau_ref) const {
475  return (*basicTauDiscriminatorCollection)[tau_ref].rawValues.at(
476  indexMap.at(BasicDiscr::PhotonPtSumOutsideSignalCone));
477  }
478  const float getPhotonPtSumOutsideSignalCone(const pat::Tau& tau,
479  const edm::RefToBase<reco::BaseTau> tau_ref) const {
480  return tau.tauID("photonPtSumOutsideSignalCone");
481  }
482  const float getPhotonPtSumOutsideSignalConedR03(const reco::PFTau& tau,
483  const edm::RefToBase<reco::BaseTau> tau_ref) const {
484  return (*basicTauDiscriminatordR03Collection)[tau_ref].rawValues.at(
485  indexMapdR03.at(BasicDiscr::PhotonPtSumOutsideSignalCone));
486  }
487  const float getPhotonPtSumOutsideSignalConedR03(const pat::Tau& tau,
488  const edm::RefToBase<reco::BaseTau> tau_ref) const {
489  return tau.tauID("photonPtSumOutsideSignalConedR03");
490  }
491  const float getPuCorrPtSum(const reco::PFTau& tau, const edm::RefToBase<reco::BaseTau> tau_ref) const {
492  return (*basicTauDiscriminatorCollection)[tau_ref].rawValues.at(indexMap.at(BasicDiscr::PUcorrPtSum));
493  }
494  const float getPuCorrPtSum(const pat::Tau& tau, const edm::RefToBase<reco::BaseTau> tau_ref) const {
495  return tau.tauID("puCorrPtSum");
496  }
497 
498  auto getdxyPCA(const reco::PFTau& tau, const size_t tau_index) const {
499  return pfTauTransverseImpactParameters->value(tau_index)->dxy_PCA();
500  }
501  auto getdxyPCA(const pat::Tau& tau, const size_t tau_index) const { return tau.dxy_PCA(); }
502  auto getdxy(const reco::PFTau& tau, const size_t tau_index) const {
503  return pfTauTransverseImpactParameters->value(tau_index)->dxy();
504  }
505  auto getdxy(const pat::Tau& tau, const size_t tau_index) const { return tau.dxy(); }
506  auto getdxyError(const reco::PFTau& tau, const size_t tau_index) const {
507  return pfTauTransverseImpactParameters->value(tau_index)->dxy_error();
508  }
509  auto getdxyError(const pat::Tau& tau, const size_t tau_index) const { return tau.dxy_error(); }
510  auto getdxySig(const reco::PFTau& tau, const size_t tau_index) const {
511  return pfTauTransverseImpactParameters->value(tau_index)->dxy_Sig();
512  }
513  auto getdxySig(const pat::Tau& tau, const size_t tau_index) const { return tau.dxy_Sig(); }
514  auto getip3d(const reco::PFTau& tau, const size_t tau_index) const {
515  return pfTauTransverseImpactParameters->value(tau_index)->ip3d();
516  }
517  auto getip3d(const pat::Tau& tau, const size_t tau_index) const { return tau.ip3d(); }
518  auto getip3dError(const reco::PFTau& tau, const size_t tau_index) const {
519  return pfTauTransverseImpactParameters->value(tau_index)->ip3d_error();
520  }
521  auto getip3dError(const pat::Tau& tau, const size_t tau_index) const { return tau.ip3d_error(); }
522  auto getip3dSig(const reco::PFTau& tau, const size_t tau_index) const {
523  return pfTauTransverseImpactParameters->value(tau_index)->ip3d_Sig();
524  }
525  auto getip3dSig(const pat::Tau& tau, const size_t tau_index) const { return tau.ip3d_Sig(); }
526  auto getHasSecondaryVertex(const reco::PFTau& tau, const size_t tau_index) const {
527  return pfTauTransverseImpactParameters->value(tau_index)->hasSecondaryVertex();
528  }
529  auto getHasSecondaryVertex(const pat::Tau& tau, const size_t tau_index) const { return tau.hasSecondaryVertex(); }
530  auto getFlightLength(const reco::PFTau& tau, const size_t tau_index) const {
531  return pfTauTransverseImpactParameters->value(tau_index)->flightLength();
532  }
533  auto getFlightLength(const pat::Tau& tau, const size_t tau_index) const { return tau.flightLength(); }
534  auto getFlightLengthSig(const reco::PFTau& tau, const size_t tau_index) const {
535  return pfTauTransverseImpactParameters->value(tau_index)->flightLengthSig();
536  }
537  auto getFlightLengthSig(const pat::Tau& tau, const size_t tau_index) const { return tau.flightLengthSig(); }
538 
539  auto getLeadingTrackNormChi2(const reco::PFTau& tau) { return reco::tau::lead_track_chi2(tau); }
540  auto getLeadingTrackNormChi2(const pat::Tau& tau) { return tau.leadingTrackNormChi2(); }
541  auto getEmFraction(const pat::Tau& tau) { return tau.emFraction_MVA(); }
542  auto getEmFraction(const reco::PFTau& tau) { return tau.emFraction(); }
543  auto getEtaAtEcalEntrance(const pat::Tau& tau) { return tau.etaAtEcalEntranceLeadChargedCand(); }
544  auto getEtaAtEcalEntrance(const reco::PFTau& tau) {
545  return tau.leadPFChargedHadrCand()->positionAtECALEntrance().eta();
546  }
547  auto getEcalEnergyLeadingChargedHadr(const reco::PFTau& tau) { return tau.leadPFChargedHadrCand()->ecalEnergy(); }
548  auto getEcalEnergyLeadingChargedHadr(const pat::Tau& tau) { return tau.ecalEnergyLeadChargedHadrCand(); }
549  auto getHcalEnergyLeadingChargedHadr(const reco::PFTau& tau) { return tau.leadPFChargedHadrCand()->hcalEnergy(); }
550  auto getHcalEnergyLeadingChargedHadr(const pat::Tau& tau) { return tau.hcalEnergyLeadChargedHadrCand(); }
551 
552  template <typename PreDiscrType>
553  bool passPrediscriminants(const PreDiscrType prediscriminants,
554  const size_t andPrediscriminants,
555  const edm::RefToBase<reco::BaseTau> tau_ref) {
556  bool passesPrediscriminants = (andPrediscriminants ? 1 : 0);
557  // check tau passes prediscriminants
558  size_t nPrediscriminants = prediscriminants.size();
559  for (size_t iDisc = 0; iDisc < nPrediscriminants; ++iDisc) {
560  // current discriminant result for this tau
561  double discResult = (*prediscriminants[iDisc].handle)[tau_ref];
562  uint8_t thisPasses = (discResult > prediscriminants[iDisc].cut) ? 1 : 0;
563 
564  // if we are using the AND option, as soon as one fails,
565  // the result is FAIL and we can quit looping.
566  // if we are using the OR option as soon as one passes,
567  // the result is pass and we can quit looping
568 
569  // truth table
570  // | result (thisPasses)
571  // | F | T
572  //-----------------------------------
573  // AND(T) | res=fails | continue
574  // | break |
575  //-----------------------------------
576  // OR (F) | continue | res=passes
577  // | | break
578 
579  if (thisPasses ^ andPrediscriminants) //XOR
580  {
581  passesPrediscriminants = (andPrediscriminants ? 0 : 1); //NOR
582  break;
583  }
584  }
585  return passesPrediscriminants;
586  }
587  };
588 
589  namespace candFunc {
590  auto getTauDz(const reco::PFCandidate& cand, float default_value) {
591  return cand.bestTrack() != nullptr ? cand.bestTrack()->dz() : default_value;
592  }
593  auto getTauDz(const pat::PackedCandidate& cand, float default_value) { return cand.dz(); }
594  auto getTauDzError(const reco::PFCandidate& cand, float default_value) {
595  return cand.bestTrack() != nullptr ? cand.dzError() : default_value;
596  }
597  auto getTauDzError(const pat::PackedCandidate& cand, float default_value) {
598  return cand.hasTrackDetails() ? cand.dzError() : default_value;
599  }
600  auto getTauDZSigValid(const reco::PFCandidate& cand) {
601  return cand.bestTrack() != nullptr && std::isnormal(cand.bestTrack()->dz()) && std::isnormal(cand.dzError()) &&
602  cand.dzError() > 0;
603  }
604  auto getTauDZSigValid(const pat::PackedCandidate& cand) {
605  return cand.hasTrackDetails() && std::isnormal(cand.dz()) && std::isnormal(cand.dzError()) && cand.dzError() > 0;
606  }
607  auto getTauDxy(const reco::PFCandidate& cand, float default_value) {
608  return cand.bestTrack() != nullptr ? cand.bestTrack()->dxy() : default_value;
609  }
610  auto getTauDxy(const pat::PackedCandidate& cand, float default_value) { return cand.dxy(); }
611  auto getPvAssocationQuality(const reco::PFCandidate& cand) { return 0.7013f; }
612  auto getPvAssocationQuality(const pat::PackedCandidate& cand) { return cand.pvAssociationQuality(); }
613  auto getPuppiWeight(const reco::PFCandidate& cand) { return 0.9907f; }
614  auto getPuppiWeight(const pat::PackedCandidate& cand) { return cand.puppiWeight(); }
615  auto getPuppiWeightNoLep(const reco::PFCandidate& cand) { return 0.8858f; }
616  auto getPuppiWeightNoLep(const pat::PackedCandidate& cand) { return cand.puppiWeightNoLep(); }
617  auto getLostInnerHits(const reco::PFCandidate& cand, float default_value) {
618  return cand.bestTrack() != nullptr
619  ? cand.bestTrack()->hitPattern().numberOfLostHits(reco::HitPattern::MISSING_INNER_HITS)
620  : default_value;
621  }
622  auto getLostInnerHits(const pat::PackedCandidate& cand, float default_value) { return cand.lostInnerHits(); }
623  auto getNumberOfPixelHits(const reco::PFCandidate& cand, float default_value) {
624  return cand.bestTrack() != nullptr
625  ? cand.bestTrack()->hitPattern().numberOfLostHits(reco::HitPattern::MISSING_INNER_HITS)
626  : default_value;
627  }
628  auto getNumberOfPixelHits(const pat::PackedCandidate& cand, float default_value) {
629  return cand.numberOfPixelHits();
630  }
631  auto getHasTrackDetails(const reco::PFCandidate& cand) { return cand.bestTrack() != nullptr; }
632  auto getHasTrackDetails(const pat::PackedCandidate& cand) { return cand.hasTrackDetails(); }
633  auto getPseudoTrack(const reco::PFCandidate& cand) { return *cand.bestTrack(); }
634  auto getPseudoTrack(const pat::PackedCandidate& cand) { return cand.pseudoTrack(); }
635  auto getFromPV(const reco::PFCandidate& cand) { return 0.9994f; }
636  auto getFromPV(const pat::PackedCandidate& cand) { return cand.fromPV(); }
637  auto getHCalFraction(const reco::PFCandidate& cand) {
638  return cand.rawHcalEnergy() / (cand.rawHcalEnergy() + cand.rawEcalEnergy());
639  }
640  auto getHCalFraction(const pat::PackedCandidate& cand) {
641  float hcal_fraction = 0.;
642  if (cand.pdgId() == 1 || cand.pdgId() == 130) {
643  hcal_fraction = cand.hcalFraction();
644  } else if (cand.isIsolatedChargedHadron()) {
645  hcal_fraction = cand.rawHcalFraction();
646  }
647  return hcal_fraction;
648  }
649  auto getRawCaloFraction(const reco::PFCandidate& cand) {
650  return (cand.rawEcalEnergy() + cand.rawHcalEnergy()) / cand.energy();
651  }
652  auto getRawCaloFraction(const pat::PackedCandidate& cand) { return cand.rawCaloFraction(); }
653  }; // namespace candFunc
654 
655  template <typename LVector1, typename LVector2>
656  float dEta(const LVector1& p4, const LVector2& tau_p4) {
657  return static_cast<float>(p4.eta() - tau_p4.eta());
658  }
659 
660  template <typename LVector1, typename LVector2>
661  float dPhi(const LVector1& p4_1, const LVector2& p4_2) {
662  return static_cast<float>(reco::deltaPhi(p4_2.phi(), p4_1.phi()));
663  }
664 
665  struct MuonHitMatchV1 {
666  static constexpr int n_muon_stations = 4;
667 
668  std::map<int, std::vector<UInt_t>> n_matches, n_hits;
669  unsigned n_muons{0};
670  const pat::Muon* best_matched_muon{nullptr};
671  double deltaR2_best_match{-1};
672 
673  MuonHitMatchV1() {
674  n_matches[MuonSubdetId::DT].assign(n_muon_stations, 0);
675  n_matches[MuonSubdetId::CSC].assign(n_muon_stations, 0);
676  n_matches[MuonSubdetId::RPC].assign(n_muon_stations, 0);
677  n_hits[MuonSubdetId::DT].assign(n_muon_stations, 0);
678  n_hits[MuonSubdetId::CSC].assign(n_muon_stations, 0);
679  n_hits[MuonSubdetId::RPC].assign(n_muon_stations, 0);
680  }
681 
682  void addMatchedMuon(const pat::Muon& muon, reco::BaseTau const& tau) {
683  static constexpr int n_stations = 4;
684 
685  ++n_muons;
686  const double dR2 = reco::deltaR2(tau.p4(), muon.p4());
687  if (!best_matched_muon || dR2 < deltaR2_best_match) {
688  best_matched_muon = &muon;
689  deltaR2_best_match = dR2;
690  }
691 
692  for (const auto& segment : muon.matches()) {
693  if (segment.segmentMatches.empty())
694  continue;
695  if (n_matches.count(segment.detector()))
696  ++n_matches.at(segment.detector()).at(segment.station() - 1);
697  }
698 
699  if (muon.outerTrack().isNonnull()) {
700  const auto& hit_pattern = muon.outerTrack()->hitPattern();
701  for (int hit_index = 0; hit_index < hit_pattern.numberOfAllHits(reco::HitPattern::TRACK_HITS); ++hit_index) {
702  auto hit_id = hit_pattern.getHitPattern(reco::HitPattern::TRACK_HITS, hit_index);
703  if (hit_id == 0)
704  break;
705  if (hit_pattern.muonHitFilter(hit_id) && (hit_pattern.getHitType(hit_id) == TrackingRecHit::valid ||
706  hit_pattern.getHitType(hit_id == TrackingRecHit::bad))) {
707  const int station = hit_pattern.getMuonStation(hit_id) - 1;
708  if (station > 0 && station < n_stations) {
709  std::vector<UInt_t>* muon_n_hits = nullptr;
710  if (hit_pattern.muonDTHitFilter(hit_id))
711  muon_n_hits = &n_hits.at(MuonSubdetId::DT);
712  else if (hit_pattern.muonCSCHitFilter(hit_id))
713  muon_n_hits = &n_hits.at(MuonSubdetId::CSC);
714  else if (hit_pattern.muonRPCHitFilter(hit_id))
715  muon_n_hits = &n_hits.at(MuonSubdetId::RPC);
716 
717  if (muon_n_hits)
718  ++muon_n_hits->at(station);
719  }
720  }
721  }
722  }
723  }
724 
725  template <typename TauCastType>
726  static std::vector<const pat::Muon*> findMatchedMuons(const TauCastType& tau,
727  const std::vector<pat::Muon>* muons,
728  double deltaR,
729  double minPt) {
730  const reco::Muon* hadr_cand_muon = nullptr;
731  if (tau.leadPFChargedHadrCand().isNonnull() && tau.leadPFChargedHadrCand()->muonRef().isNonnull())
732  hadr_cand_muon = tau.leadPFChargedHadrCand()->muonRef().get();
733  std::vector<const pat::Muon*> matched_muons;
734  const double dR2 = deltaR * deltaR;
735  for (const pat::Muon& muon : *muons) {
736  const reco::Muon* reco_muon = &muon;
737  if (muon.pt() <= minPt)
738  continue;
739  if (reco_muon == hadr_cand_muon)
740  continue;
741  if (reco::deltaR2(tau.p4(), muon.p4()) >= dR2)
742  continue;
743  matched_muons.push_back(&muon);
744  }
745  return matched_muons;
746  }
747 
748  template <typename dnn, typename TensorElemGet, typename TauCastType>
749  void fillTensor(const TensorElemGet& get, const TauCastType& tau, float default_value) const {
750  get(dnn::n_matched_muons) = n_muons;
751  get(dnn::muon_pt) = best_matched_muon != nullptr ? best_matched_muon->p4().pt() : default_value;
752  get(dnn::muon_dEta) = best_matched_muon != nullptr ? dEta(best_matched_muon->p4(), tau.p4()) : default_value;
753  get(dnn::muon_dPhi) = best_matched_muon != nullptr ? dPhi(best_matched_muon->p4(), tau.p4()) : default_value;
754  get(dnn::muon_n_matches_DT_1) = n_matches.at(MuonSubdetId::DT).at(0);
755  get(dnn::muon_n_matches_DT_2) = n_matches.at(MuonSubdetId::DT).at(1);
756  get(dnn::muon_n_matches_DT_3) = n_matches.at(MuonSubdetId::DT).at(2);
757  get(dnn::muon_n_matches_DT_4) = n_matches.at(MuonSubdetId::DT).at(3);
758  get(dnn::muon_n_matches_CSC_1) = n_matches.at(MuonSubdetId::CSC).at(0);
759  get(dnn::muon_n_matches_CSC_2) = n_matches.at(MuonSubdetId::CSC).at(1);
760  get(dnn::muon_n_matches_CSC_3) = n_matches.at(MuonSubdetId::CSC).at(2);
761  get(dnn::muon_n_matches_CSC_4) = n_matches.at(MuonSubdetId::CSC).at(3);
762  get(dnn::muon_n_hits_DT_2) = n_hits.at(MuonSubdetId::DT).at(1);
763  get(dnn::muon_n_hits_DT_3) = n_hits.at(MuonSubdetId::DT).at(2);
764  get(dnn::muon_n_hits_DT_4) = n_hits.at(MuonSubdetId::DT).at(3);
765  get(dnn::muon_n_hits_CSC_2) = n_hits.at(MuonSubdetId::CSC).at(1);
766  get(dnn::muon_n_hits_CSC_3) = n_hits.at(MuonSubdetId::CSC).at(2);
767  get(dnn::muon_n_hits_CSC_4) = n_hits.at(MuonSubdetId::CSC).at(3);
768  get(dnn::muon_n_hits_RPC_2) = n_hits.at(MuonSubdetId::RPC).at(1);
769  get(dnn::muon_n_hits_RPC_3) = n_hits.at(MuonSubdetId::RPC).at(2);
770  get(dnn::muon_n_hits_RPC_4) = n_hits.at(MuonSubdetId::RPC).at(3);
771  get(dnn::muon_n_stations_with_matches_03) = countMuonStationsWithMatches(0, 3);
772  get(dnn::muon_n_stations_with_hits_23) = countMuonStationsWithHits(2, 3);
773  }
774 
775  private:
776  unsigned countMuonStationsWithMatches(size_t first_station, size_t last_station) const {
777  static const std::map<int, std::vector<bool>> masks = {
778  {MuonSubdetId::DT, {false, false, false, false}},
779  {MuonSubdetId::CSC, {true, false, false, false}},
780  {MuonSubdetId::RPC, {false, false, false, false}},
781  };
782  unsigned cnt = 0;
783  for (unsigned n = first_station; n <= last_station; ++n) {
784  for (const auto& match : n_matches) {
785  if (!masks.at(match.first).at(n) && match.second.at(n) > 0)
786  ++cnt;
787  }
788  }
789  return cnt;
790  }
791 
792  unsigned countMuonStationsWithHits(size_t first_station, size_t last_station) const {
793  static const std::map<int, std::vector<bool>> masks = {
794  {MuonSubdetId::DT, {false, false, false, false}},
795  {MuonSubdetId::CSC, {false, false, false, false}},
796  {MuonSubdetId::RPC, {false, false, false, false}},
797  };
798 
799  unsigned cnt = 0;
800  for (unsigned n = first_station; n <= last_station; ++n) {
801  for (const auto& hit : n_hits) {
802  if (!masks.at(hit.first).at(n) && hit.second.at(n) > 0)
803  ++cnt;
804  }
805  }
806  return cnt;
807  }
808  };
809 
810  struct MuonHitMatchV2 {
811  static constexpr size_t n_muon_stations = 4;
812  static constexpr int first_station_id = 1;
813  static constexpr int last_station_id = first_station_id + n_muon_stations - 1;
814  using CountArray = std::array<unsigned, n_muon_stations>;
815  using CountMap = std::map<int, CountArray>;
816 
817  const std::vector<int>& consideredSubdets() {
818  static const std::vector<int> subdets = {MuonSubdetId::DT, MuonSubdetId::CSC, MuonSubdetId::RPC};
819  return subdets;
820  }
821 
822  const std::string& subdetName(int subdet) {
823  static const std::map<int, std::string> subdet_names = {
824  {MuonSubdetId::DT, "DT"}, {MuonSubdetId::CSC, "CSC"}, {MuonSubdetId::RPC, "RPC"}};
825  if (!subdet_names.count(subdet))
826  throw cms::Exception("MuonHitMatch") << "Subdet name for subdet id " << subdet << " not found.";
827  return subdet_names.at(subdet);
828  }
829 
830  size_t getStationIndex(int station, bool throw_exception) const {
831  if (station < first_station_id || station > last_station_id) {
832  if (throw_exception)
833  throw cms::Exception("MuonHitMatch") << "Station id is out of range";
835  }
836  return static_cast<size_t>(station - 1);
837  }
838 
839  MuonHitMatchV2(const pat::Muon& muon) {
840  for (int subdet : consideredSubdets()) {
841  n_matches[subdet].fill(0);
842  n_hits[subdet].fill(0);
843  }
844 
845  countMatches(muon, n_matches);
846  countHits(muon, n_hits);
847  }
848 
849  void countMatches(const pat::Muon& muon, CountMap& n_matches) {
850  for (const auto& segment : muon.matches()) {
851  if (segment.segmentMatches.empty() && segment.rpcMatches.empty())
852  continue;
853  if (n_matches.count(segment.detector())) {
854  const size_t station_index = getStationIndex(segment.station(), true);
855  ++n_matches.at(segment.detector()).at(station_index);
856  }
857  }
858  }
859 
860  void countHits(const pat::Muon& muon, CountMap& n_hits) {
861  if (muon.outerTrack().isNonnull()) {
862  const auto& hit_pattern = muon.outerTrack()->hitPattern();
863  for (int hit_index = 0; hit_index < hit_pattern.numberOfAllHits(reco::HitPattern::TRACK_HITS); ++hit_index) {
864  auto hit_id = hit_pattern.getHitPattern(reco::HitPattern::TRACK_HITS, hit_index);
865  if (hit_id == 0)
866  break;
867  if (hit_pattern.muonHitFilter(hit_id) && (hit_pattern.getHitType(hit_id) == TrackingRecHit::valid ||
868  hit_pattern.getHitType(hit_id) == TrackingRecHit::bad)) {
869  const size_t station_index = getStationIndex(hit_pattern.getMuonStation(hit_id), false);
870  if (station_index < n_muon_stations) {
871  CountArray* muon_n_hits = nullptr;
872  if (hit_pattern.muonDTHitFilter(hit_id))
873  muon_n_hits = &n_hits.at(MuonSubdetId::DT);
874  else if (hit_pattern.muonCSCHitFilter(hit_id))
875  muon_n_hits = &n_hits.at(MuonSubdetId::CSC);
876  else if (hit_pattern.muonRPCHitFilter(hit_id))
877  muon_n_hits = &n_hits.at(MuonSubdetId::RPC);
878 
879  if (muon_n_hits)
880  ++muon_n_hits->at(station_index);
881  }
882  }
883  }
884  }
885  }
886 
887  unsigned nMatches(int subdet, int station) const {
888  if (!n_matches.count(subdet))
889  throw cms::Exception("MuonHitMatch") << "Subdet " << subdet << " not found.";
890  const size_t station_index = getStationIndex(station, true);
891  return n_matches.at(subdet).at(station_index);
892  }
893 
894  unsigned nHits(int subdet, int station) const {
895  if (!n_hits.count(subdet))
896  throw cms::Exception("MuonHitMatch") << "Subdet " << subdet << " not found.";
897  const size_t station_index = getStationIndex(station, true);
898  return n_hits.at(subdet).at(station_index);
899  }
900 
901  unsigned countMuonStationsWithMatches(int first_station, int last_station) const {
902  static const std::map<int, std::vector<bool>> masks = {
903  {MuonSubdetId::DT, {false, false, false, false}},
904  {MuonSubdetId::CSC, {true, false, false, false}},
905  {MuonSubdetId::RPC, {false, false, false, false}},
906  };
907  const size_t first_station_index = getStationIndex(first_station, true);
908  const size_t last_station_index = getStationIndex(last_station, true);
909  unsigned cnt = 0;
910  for (size_t n = first_station_index; n <= last_station_index; ++n) {
911  for (const auto& match : n_matches) {
912  if (!masks.at(match.first).at(n) && match.second.at(n) > 0)
913  ++cnt;
914  }
915  }
916  return cnt;
917  }
918 
919  unsigned countMuonStationsWithHits(int first_station, int last_station) const {
920  static const std::map<int, std::vector<bool>> masks = {
921  {MuonSubdetId::DT, {false, false, false, false}},
922  {MuonSubdetId::CSC, {false, false, false, false}},
923  {MuonSubdetId::RPC, {false, false, false, false}},
924  };
925 
926  const size_t first_station_index = getStationIndex(first_station, true);
927  const size_t last_station_index = getStationIndex(last_station, true);
928  unsigned cnt = 0;
929  for (size_t n = first_station_index; n <= last_station_index; ++n) {
930  for (const auto& hit : n_hits) {
931  if (!masks.at(hit.first).at(n) && hit.second.at(n) > 0)
932  ++cnt;
933  }
934  }
935  return cnt;
936  }
937 
938  private:
939  CountMap n_matches, n_hits;
940  };
941 
942  enum class CellObjectType {
943  PfCand_electron,
944  PfCand_muon,
945  PfCand_chargedHadron,
946  PfCand_neutralHadron,
947  PfCand_gamma,
948  Electron,
949  Muon,
950  Other
951  };
952 
953  template <typename Object>
954  CellObjectType GetCellObjectType(const Object&);
955  template <>
956  CellObjectType GetCellObjectType(const pat::Electron&) {
958  }
959  template <>
960  CellObjectType GetCellObjectType(const pat::Muon&) {
961  return CellObjectType::Muon;
962  }
963 
964  template <>
965  CellObjectType GetCellObjectType(reco::Candidate const& cand) {
966  static const std::map<int, CellObjectType> obj_types = {{11, CellObjectType::PfCand_electron},
967  {13, CellObjectType::PfCand_muon},
968  {22, CellObjectType::PfCand_gamma},
969  {130, CellObjectType::PfCand_neutralHadron},
970  {211, CellObjectType::PfCand_chargedHadron}};
971 
972  auto iter = obj_types.find(std::abs(cand.pdgId()));
973  if (iter == obj_types.end())
974  return CellObjectType::Other;
975  return iter->second;
976  }
977 
978  using Cell = std::map<CellObjectType, size_t>;
979  struct CellIndex {
980  int eta, phi;
981 
982  bool operator<(const CellIndex& other) const {
983  if (eta != other.eta)
984  return eta < other.eta;
985  return phi < other.phi;
986  }
987  };
988 
989  class CellGrid {
990  public:
991  using Map = std::map<CellIndex, Cell>;
992  using const_iterator = Map::const_iterator;
993 
994  CellGrid(unsigned n_cells_eta, unsigned n_cells_phi, double cell_size_eta, double cell_size_phi)
995  : nCellsEta(n_cells_eta),
996  nCellsPhi(n_cells_phi),
997  nTotal(nCellsEta * nCellsPhi),
998  cellSizeEta(cell_size_eta),
999  cellSizePhi(cell_size_phi) {
1000  if (nCellsEta % 2 != 1 || nCellsEta < 1)
1001  throw cms::Exception("DeepTauId") << "Invalid number of eta cells.";
1002  if (nCellsPhi % 2 != 1 || nCellsPhi < 1)
1003  throw cms::Exception("DeepTauId") << "Invalid number of phi cells.";
1004  if (cellSizeEta <= 0 || cellSizePhi <= 0)
1005  throw cms::Exception("DeepTauId") << "Invalid cell size.";
1006  }
1007 
1008  int maxEtaIndex() const { return static_cast<int>((nCellsEta - 1) / 2); }
1009  int maxPhiIndex() const { return static_cast<int>((nCellsPhi - 1) / 2); }
1010  double maxDeltaEta() const { return cellSizeEta * (0.5 + maxEtaIndex()); }
1011  double maxDeltaPhi() const { return cellSizePhi * (0.5 + maxPhiIndex()); }
1012  int getEtaTensorIndex(const CellIndex& cellIndex) const { return cellIndex.eta + maxEtaIndex(); }
1013  int getPhiTensorIndex(const CellIndex& cellIndex) const { return cellIndex.phi + maxPhiIndex(); }
1014 
1015  bool tryGetCellIndex(double deltaEta, double deltaPhi, CellIndex& cellIndex) const {
1016  static auto getCellIndex = [](double x, double maxX, double size, int& index) {
1017  const double absX = std::abs(x);
1018  if (absX > maxX)
1019  return false;
1020  const double absIndex = std::floor(std::abs(absX / size - 0.5));
1021  index = static_cast<int>(std::copysign(absIndex, x));
1022  return true;
1023  };
1024 
1025  return getCellIndex(deltaEta, maxDeltaEta(), cellSizeEta, cellIndex.eta) &&
1026  getCellIndex(deltaPhi, maxDeltaPhi(), cellSizePhi, cellIndex.phi);
1027  }
1028 
1029  size_t num_valid_cells() const { return cells.size(); }
1030  Cell& operator[](const CellIndex& cellIndex) { return cells[cellIndex]; }
1031  const Cell& at(const CellIndex& cellIndex) const { return cells.at(cellIndex); }
1032  size_t count(const CellIndex& cellIndex) const { return cells.count(cellIndex); }
1033  const_iterator find(const CellIndex& cellIndex) const { return cells.find(cellIndex); }
1034  const_iterator begin() const { return cells.begin(); }
1035  const_iterator end() const { return cells.end(); }
1036 
1037  public:
1038  const unsigned nCellsEta, nCellsPhi, nTotal;
1039  const double cellSizeEta, cellSizePhi;
1040 
1041  private:
1042  std::map<CellIndex, Cell> cells;
1043  };
1044 
1045 } // anonymous namespace
1046 
1048 const std::map<bd, std::string> deep_tau::DeepTauBase::stringFromDiscriminator_{
1049  {bd::ChargedIsoPtSum, "ChargedIsoPtSum"},
1050  {bd::NeutralIsoPtSum, "NeutralIsoPtSum"},
1051  {bd::NeutralIsoPtSumWeight, "NeutralIsoPtSumWeight"},
1052  {bd::FootprintCorrection, "TauFootprintCorrection"},
1053  {bd::PhotonPtSumOutsideSignalCone, "PhotonPtSumOutsideSignalCone"},
1054  {bd::PUcorrPtSum, "PUcorrPtSum"}};
1055 const std::vector<bd> deep_tau::DeepTauBase::requiredBasicDiscriminators_ = {bd::ChargedIsoPtSum,
1056  bd::NeutralIsoPtSum,
1057  bd::NeutralIsoPtSumWeight,
1058  bd::PhotonPtSumOutsideSignalCone,
1059  bd::PUcorrPtSum};
1060 const std::vector<bd> deep_tau::DeepTauBase::requiredBasicDiscriminatorsdR03_ = {bd::ChargedIsoPtSum,
1061  bd::NeutralIsoPtSum,
1062  bd::NeutralIsoPtSumWeight,
1063  bd::PhotonPtSumOutsideSignalCone,
1064  bd::FootprintCorrection};
1065 
1067 public:
1068  static constexpr float default_value = -999.;
1069 
1070  static const OutputCollection& GetOutputs() {
1071  static constexpr size_t e_index = 0, mu_index = 1, tau_index = 2, jet_index = 3;
1072  static const OutputCollection outputs_ = {
1073  {"VSe", Output({tau_index}, {e_index, tau_index})},
1074  {"VSmu", Output({tau_index}, {mu_index, tau_index})},
1075  {"VSjet", Output({tau_index}, {jet_index, tau_index})},
1076  };
1077  return outputs_;
1078  }
1079 
1080  const std::map<BasicDiscriminator, size_t> matchDiscriminatorIndices(
1081  edm::Event& event,
1082  edm::EDGetTokenT<reco::TauDiscriminatorContainer> discriminatorContainerToken,
1083  std::vector<BasicDiscriminator> requiredDiscr) {
1084  std::map<std::string, size_t> discrIndexMapStr;
1085  auto const aHandle = event.getHandle(discriminatorContainerToken);
1086  auto const aProv = aHandle.provenance();
1087  if (aProv == nullptr)
1088  aHandle.whyFailed()->raise();
1089  const auto& psetsFromProvenance = edm::parameterSet(*aProv, event.processHistory());
1090  auto const idlist = psetsFromProvenance.getParameter<std::vector<edm::ParameterSet>>("IDdefinitions");
1091  for (size_t j = 0; j < idlist.size(); ++j) {
1092  std::string idname = idlist[j].getParameter<std::string>("IDname");
1093  if (discrIndexMapStr.count(idname)) {
1094  throw cms::Exception("DeepTauId")
1095  << "basic discriminator " << idname << " appears more than once in the input.";
1096  }
1097  discrIndexMapStr[idname] = j;
1098  }
1099 
1100  //translate to a map of <BasicDiscriminator, index> and check if all discriminators are present
1101  std::map<BasicDiscriminator, size_t> discrIndexMap;
1102  for (size_t i = 0; i < requiredDiscr.size(); i++) {
1103  if (discrIndexMapStr.find(stringFromDiscriminator_.at(requiredDiscr[i])) == discrIndexMapStr.end())
1104  throw cms::Exception("DeepTauId") << "Basic Discriminator " << stringFromDiscriminator_.at(requiredDiscr[i])
1105  << " was not provided in the config file.";
1106  else
1107  discrIndexMap[requiredDiscr[i]] = discrIndexMapStr[stringFromDiscriminator_.at(requiredDiscr[i])];
1108  }
1109  return discrIndexMap;
1110  }
1111 
1114  desc.add<edm::InputTag>("electrons", edm::InputTag("slimmedElectrons"));
1115  desc.add<edm::InputTag>("muons", edm::InputTag("slimmedMuons"));
1116  desc.add<edm::InputTag>("taus", edm::InputTag("slimmedTaus"));
1117  desc.add<edm::InputTag>("pfcands", edm::InputTag("packedPFCandidates"));
1118  desc.add<edm::InputTag>("vertices", edm::InputTag("offlineSlimmedPrimaryVertices"));
1119  desc.add<edm::InputTag>("rho", edm::InputTag("fixedGridRhoAll"));
1120  desc.add<std::vector<std::string>>("graph_file",
1121  {"RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6.pb"});
1122  desc.add<bool>("mem_mapped", false);
1123  desc.add<unsigned>("version", 2);
1124  desc.add<int>("debug_level", 0);
1125  desc.add<bool>("disable_dxy_pca", false);
1126  desc.add<bool>("is_online", false);
1127 
1128  desc.add<std::vector<std::string>>("VSeWP");
1129  desc.add<std::vector<std::string>>("VSmuWP");
1130  desc.add<std::vector<std::string>>("VSjetWP");
1131 
1132  desc.addUntracked<edm::InputTag>("basicTauDiscriminators", edm::InputTag("basicTauDiscriminators"));
1133  desc.addUntracked<edm::InputTag>("basicTauDiscriminatorsdR03", edm::InputTag("basicTauDiscriminatorsdR03"));
1134  desc.add<edm::InputTag>("pfTauTransverseImpactParameters", edm::InputTag("hpsPFTauTransverseImpactParameters"));
1135 
1136  {
1137  edm::ParameterSetDescription pset_Prediscriminants;
1138  pset_Prediscriminants.add<std::string>("BooleanOperator", "and");
1139  {
1141  psd1.add<double>("cut");
1142  psd1.add<edm::InputTag>("Producer");
1143  pset_Prediscriminants.addOptional<edm::ParameterSetDescription>("decayMode", psd1);
1144  }
1145  desc.add<edm::ParameterSetDescription>("Prediscriminants", pset_Prediscriminants);
1146  }
1147 
1148  descriptions.add("DeepTau", desc);
1149  }
1150 
1151 public:
1154  electrons_token_(consumes<std::vector<pat::Electron>>(cfg.getParameter<edm::InputTag>("electrons"))),
1155  muons_token_(consumes<std::vector<pat::Muon>>(cfg.getParameter<edm::InputTag>("muons"))),
1156  rho_token_(consumes<double>(cfg.getParameter<edm::InputTag>("rho"))),
1158  cfg.getUntrackedParameter<edm::InputTag>("basicTauDiscriminators"))),
1160  cfg.getUntrackedParameter<edm::InputTag>("basicTauDiscriminatorsdR03"))),
1162  consumes<edm::AssociationVector<reco::PFTauRefProd, std::vector<reco::PFTauTransverseImpactParameterRef>>>(
1163  cfg.getParameter<edm::InputTag>("pfTauTransverseImpactParameters"))),
1164  version_(cfg.getParameter<unsigned>("version")),
1165  debug_level(cfg.getParameter<int>("debug_level")),
1166  disable_dxy_pca_(cfg.getParameter<bool>("disable_dxy_pca")) {
1167  if (version_ == 1) {
1168  input_layer_ = cache_->getGraph().node(0).name();
1169  output_layer_ = cache_->getGraph().node(cache_->getGraph().node_size() - 1).name();
1170  const auto& shape = cache_->getGraph().node(0).attr().at("shape").shape();
1171  if (shape.dim(1).size() != dnn_inputs_2017v1::NumberOfInputs)
1172  throw cms::Exception("DeepTauId")
1173  << "number of inputs does not match the expected inputs for the given version";
1174  } else if (version_ == 2) {
1175  tauBlockTensor_ = std::make_unique<tensorflow::Tensor>(
1176  tensorflow::DT_FLOAT, tensorflow::TensorShape{1, dnn_inputs_2017_v2::TauBlockInputs::NumberOfInputs});
1177  for (size_t n = 0; n < 2; ++n) {
1178  const bool is_inner = n == 0;
1179  const auto n_cells =
1180  is_inner ? dnn_inputs_2017_v2::number_of_inner_cell : dnn_inputs_2017_v2::number_of_outer_cell;
1181  eGammaTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1182  tensorflow::DT_FLOAT,
1183  tensorflow::TensorShape{1, 1, 1, dnn_inputs_2017_v2::EgammaBlockInputs::NumberOfInputs});
1184  muonTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1185  tensorflow::DT_FLOAT,
1186  tensorflow::TensorShape{1, 1, 1, dnn_inputs_2017_v2::MuonBlockInputs::NumberOfInputs});
1187  hadronsTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1188  tensorflow::DT_FLOAT,
1189  tensorflow::TensorShape{1, 1, 1, dnn_inputs_2017_v2::HadronBlockInputs::NumberOfInputs});
1190  convTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1191  tensorflow::DT_FLOAT,
1192  tensorflow::TensorShape{1, n_cells, n_cells, dnn_inputs_2017_v2::number_of_conv_features});
1193  zeroOutputTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1194  tensorflow::DT_FLOAT, tensorflow::TensorShape{1, 1, 1, dnn_inputs_2017_v2::number_of_conv_features});
1195 
1196  eGammaTensor_[is_inner]->flat<float>().setZero();
1197  muonTensor_[is_inner]->flat<float>().setZero();
1198  hadronsTensor_[is_inner]->flat<float>().setZero();
1199 
1200  setCellConvFeatures(*zeroOutputTensor_[is_inner], getPartialPredictions(is_inner), 0, 0, 0);
1201  }
1202  } else {
1203  throw cms::Exception("DeepTauId") << "version " << version_ << " is not supported.";
1204  }
1205  }
1206 
1207  static std::unique_ptr<deep_tau::DeepTauCache> initializeGlobalCache(const edm::ParameterSet& cfg) {
1208  return DeepTauBase::initializeGlobalCache(cfg);
1209  }
1210 
1211  static void globalEndJob(const deep_tau::DeepTauCache* cache_) { return DeepTauBase::globalEndJob(cache_); }
1212 
1213 private:
1214  static constexpr float pi = M_PI;
1215 
1216  template <typename T>
1217  static float getValue(T value) {
1218  return std::isnormal(value) ? static_cast<float>(value) : 0.f;
1219  }
1220 
1221  template <typename T>
1222  static float getValueLinear(T value, float min_value, float max_value, bool positive) {
1223  const float fixed_value = getValue(value);
1224  const float clamped_value = std::clamp(fixed_value, min_value, max_value);
1225  float transformed_value = (clamped_value - min_value) / (max_value - min_value);
1226  if (!positive)
1227  transformed_value = transformed_value * 2 - 1;
1228  return transformed_value;
1229  }
1230 
1231  template <typename T>
1232  static float getValueNorm(T value, float mean, float sigma, float n_sigmas_max = 5) {
1233  const float fixed_value = getValue(value);
1234  const float norm_value = (fixed_value - mean) / sigma;
1235  return std::clamp(norm_value, -n_sigmas_max, n_sigmas_max);
1236  }
1237 
1238  static bool isAbove(double value, double min) { return std::isnormal(value) && value > min; }
1239 
1241  float& cc_ele_energy,
1242  float& cc_gamma_energy,
1243  int& cc_n_gamma) {
1244  cc_ele_energy = cc_gamma_energy = 0;
1245  cc_n_gamma = 0;
1246  const auto& superCluster = ele.superCluster();
1247  if (superCluster.isNonnull() && superCluster.isAvailable() && superCluster->clusters().isNonnull() &&
1248  superCluster->clusters().isAvailable()) {
1249  for (auto iter = superCluster->clustersBegin(); iter != superCluster->clustersEnd(); ++iter) {
1250  const float energy = static_cast<float>((*iter)->energy());
1251  if (iter == superCluster->clustersBegin())
1252  cc_ele_energy += energy;
1253  else {
1254  cc_gamma_energy += energy;
1255  ++cc_n_gamma;
1256  }
1257  }
1258  return true;
1259  } else
1260  return false;
1261  }
1262 
1263  inline void checkInputs(
1264  const tensorflow::Tensor& inputs, const char* block_name, int n_inputs, int n_eta = 1, int n_phi = 1) const {
1265  if (debug_level >= 1) {
1266  for (int eta = 0; eta < n_eta; ++eta) {
1267  for (int phi = 0; phi < n_phi; phi++) {
1268  for (int k = 0; k < n_inputs; ++k) {
1269  const float input =
1270  n_eta == 1 && n_phi == 1 ? inputs.matrix<float>()(0, k) : inputs.tensor<float, 4>()(0, eta, phi, k);
1271  if (edm::isNotFinite(input))
1272  throw cms::Exception("DeepTauId")
1273  << "in the " << block_name << ", input is not finite, i.e. infinite or NaN, for eta_index = " << n_eta
1274  << ", phi_index = " << n_phi << ", input_index = " << k;
1275  if (debug_level >= 2)
1276  std::cout << block_name << "," << eta << "," << phi << "," << k << "," << std::setprecision(5)
1277  << std::fixed << input << '\n';
1278  }
1279  }
1280  }
1281  }
1282  }
1283 
1284 private:
1286  // Empty dummy vectors
1287  const std::vector<pat::Electron> electron_collection_default;
1288  const std::vector<pat::Muon> muon_collection_default;
1289  const reco::TauDiscriminatorContainer basicTauDiscriminators_default;
1290  const reco::TauDiscriminatorContainer basicTauDiscriminatorsdR03_default;
1292  pfTauTransverseImpactParameters_default;
1293 
1294  const std::vector<pat::Electron>* electron_collection;
1295  const std::vector<pat::Muon>* muon_collection;
1296  const reco::TauDiscriminatorContainer* basicTauDiscriminators;
1297  const reco::TauDiscriminatorContainer* basicTauDiscriminatorsdR03;
1299  pfTauTransverseImpactParameters;
1300 
1301  if (!is_online_) {
1302  electron_collection = &event.get(electrons_token_);
1303  muon_collection = &event.get(muons_token_);
1304  pfTauTransverseImpactParameters = &pfTauTransverseImpactParameters_default;
1305  basicTauDiscriminators = &basicTauDiscriminators_default;
1306  basicTauDiscriminatorsdR03 = &basicTauDiscriminatorsdR03_default;
1307  } else {
1308  electron_collection = &electron_collection_default;
1309  muon_collection = &muon_collection_default;
1310  pfTauTransverseImpactParameters = &event.get(pfTauTransverseImpactParameters_token_);
1311  basicTauDiscriminators = &event.get(basicTauDiscriminators_inputToken_);
1312  basicTauDiscriminatorsdR03 = &event.get(basicTauDiscriminatorsdR03_inputToken_);
1313 
1314  // Get indices for discriminators
1315  if (!discrIndicesMapped_) {
1320  discrIndicesMapped_ = true;
1321  }
1322  }
1323 
1324  TauFunc tauIDs = {basicTauDiscriminators,
1325  basicTauDiscriminatorsdR03,
1326  pfTauTransverseImpactParameters,
1329 
1331  event.getByToken(pfcandToken_, pfCands);
1332 
1334  event.getByToken(vtxToken_, vertices);
1335 
1337  event.getByToken(rho_token_, rho);
1338 
1339  tensorflow::Tensor predictions(tensorflow::DT_FLOAT, {static_cast<int>(taus->size()), deep_tau::NumberOfOutputs});
1340 
1341  for (size_t tau_index = 0; tau_index < taus->size(); ++tau_index) {
1342  const edm::RefToBase<reco::BaseTau> tauRef = taus->refAt(tau_index);
1343 
1344  std::vector<tensorflow::Tensor> pred_vector;
1345 
1346  bool passesPrediscriminants;
1347  if (is_online_) {
1348  passesPrediscriminants = tauIDs.passPrediscriminants<std::vector<TauDiscInfo<reco::PFTauDiscriminator>>>(
1350  } else {
1351  passesPrediscriminants = tauIDs.passPrediscriminants<std::vector<TauDiscInfo<pat::PATTauDiscriminator>>>(
1353  }
1354 
1355  if (passesPrediscriminants) {
1356  if (version_ == 1) {
1357  if (is_online_)
1358  getPredictionsV1<reco::PFCandidate, reco::PFTau>(
1359  taus->at(tau_index), tau_index, tauRef, electron_collection, muon_collection, pred_vector, tauIDs);
1360  else
1361  getPredictionsV1<pat::PackedCandidate, pat::Tau>(
1362  taus->at(tau_index), tau_index, tauRef, electron_collection, muon_collection, pred_vector, tauIDs);
1363  } else if (version_ == 2) {
1364  if (is_online_) {
1365  getPredictionsV2<reco::PFCandidate, reco::PFTau>(taus->at(tau_index),
1366  tau_index,
1367  tauRef,
1368  electron_collection,
1369  muon_collection,
1370  *pfCands,
1371  vertices->at(0),
1372  *rho,
1373  pred_vector,
1374  tauIDs);
1375  } else
1376  getPredictionsV2<pat::PackedCandidate, pat::Tau>(taus->at(tau_index),
1377  tau_index,
1378  tauRef,
1379  electron_collection,
1380  muon_collection,
1381  *pfCands,
1382  vertices->at(0),
1383  *rho,
1384  pred_vector,
1385  tauIDs);
1386  } else {
1387  throw cms::Exception("DeepTauId") << "version " << version_ << " is not supported.";
1388  }
1389 
1390  for (int k = 0; k < deep_tau::NumberOfOutputs; ++k) {
1391  const float pred = pred_vector[0].flat<float>()(k);
1392  if (!(pred >= 0 && pred <= 1))
1393  throw cms::Exception("DeepTauId")
1394  << "invalid prediction = " << pred << " for tau_index = " << tau_index << ", pred_index = " << k;
1395  predictions.matrix<float>()(tau_index, k) = pred;
1396  }
1397  }
1398  }
1399  return predictions;
1400  }
1401 
1402  template <typename CandidateCastType, typename TauCastType>
1404  const size_t tau_index,
1405  const edm::RefToBase<reco::BaseTau> tau_ref,
1406  const std::vector<pat::Electron>* electrons,
1407  const std::vector<pat::Muon>* muons,
1408  std::vector<tensorflow::Tensor>& pred_vector,
1409  TauFunc tau_funcs) {
1410  const tensorflow::Tensor& inputs = createInputsV1<dnn_inputs_2017v1, const CandidateCastType>(
1411  dynamic_cast<const TauCastType&>(tau), tau_index, tau_ref, electrons, muons, tau_funcs);
1412  tensorflow::run(&(cache_->getSession()), {{input_layer_, inputs}}, {output_layer_}, &pred_vector);
1413  }
1414 
1415  template <typename CandidateCastType, typename TauCastType>
1417  const size_t tau_index,
1418  const edm::RefToBase<reco::BaseTau> tau_ref,
1419  const std::vector<pat::Electron>* electrons,
1420  const std::vector<pat::Muon>* muons,
1421  const edm::View<reco::Candidate>& pfCands,
1422  const reco::Vertex& pv,
1423  double rho,
1424  std::vector<tensorflow::Tensor>& pred_vector,
1425  TauFunc tau_funcs) {
1426  CellGrid inner_grid(dnn_inputs_2017_v2::number_of_inner_cell, dnn_inputs_2017_v2::number_of_inner_cell, 0.02, 0.02);
1427  CellGrid outer_grid(dnn_inputs_2017_v2::number_of_outer_cell, dnn_inputs_2017_v2::number_of_outer_cell, 0.05, 0.05);
1428  fillGrids(dynamic_cast<const TauCastType&>(tau), *electrons, inner_grid, outer_grid);
1429  fillGrids(dynamic_cast<const TauCastType&>(tau), *muons, inner_grid, outer_grid);
1430  fillGrids(dynamic_cast<const TauCastType&>(tau), pfCands, inner_grid, outer_grid);
1431 
1432  createTauBlockInputs<CandidateCastType>(
1433  dynamic_cast<const TauCastType&>(tau), tau_index, tau_ref, pv, rho, tau_funcs);
1434  createConvFeatures<CandidateCastType>(dynamic_cast<const TauCastType&>(tau),
1435  tau_index,
1436  tau_ref,
1437  pv,
1438  rho,
1439  electrons,
1440  muons,
1441  pfCands,
1442  inner_grid,
1443  tau_funcs,
1444  true);
1445  createConvFeatures<CandidateCastType>(dynamic_cast<const TauCastType&>(tau),
1446  tau_index,
1447  tau_ref,
1448  pv,
1449  rho,
1450  electrons,
1451  muons,
1452  pfCands,
1453  outer_grid,
1454  tau_funcs,
1455  false);
1456 
1457  tensorflow::run(&(cache_->getSession("core")),
1458  {{"input_tau", *tauBlockTensor_},
1459  {"input_inner", *convTensor_.at(true)},
1460  {"input_outer", *convTensor_.at(false)}},
1461  {"main_output/Softmax"},
1462  &pred_vector);
1463  }
1464 
1465  template <typename Collection, typename TauCastType>
1466  void fillGrids(const TauCastType& tau, const Collection& objects, CellGrid& inner_grid, CellGrid& outer_grid) {
1467  static constexpr double outer_dR2 = 0.25; //0.5^2
1468  const double inner_radius = getInnerSignalConeRadius(tau.polarP4().pt());
1469  const double inner_dR2 = std::pow(inner_radius, 2);
1470 
1471  const auto addObject = [&](size_t n, double deta, double dphi, CellGrid& grid) {
1472  const auto& obj = objects.at(n);
1473  const CellObjectType obj_type = GetCellObjectType(obj);
1474  if (obj_type == CellObjectType::Other)
1475  return;
1476  CellIndex cell_index;
1477  if (grid.tryGetCellIndex(deta, dphi, cell_index)) {
1478  Cell& cell = grid[cell_index];
1479  auto iter = cell.find(obj_type);
1480  if (iter != cell.end()) {
1481  const auto& prev_obj = objects.at(iter->second);
1482  if (obj.polarP4().pt() > prev_obj.polarP4().pt())
1483  iter->second = n;
1484  } else {
1485  cell[obj_type] = n;
1486  }
1487  }
1488  };
1489 
1490  for (size_t n = 0; n < objects.size(); ++n) {
1491  const auto& obj = objects.at(n);
1492  const double deta = obj.polarP4().eta() - tau.polarP4().eta();
1493  const double dphi = reco::deltaPhi(obj.polarP4().phi(), tau.polarP4().phi());
1494  const double dR2 = std::pow(deta, 2) + std::pow(dphi, 2);
1495  if (dR2 < inner_dR2)
1496  addObject(n, deta, dphi, inner_grid);
1497  if (dR2 < outer_dR2)
1498  addObject(n, deta, dphi, outer_grid);
1499  }
1500  }
1501 
1502  tensorflow::Tensor getPartialPredictions(bool is_inner) {
1503  std::vector<tensorflow::Tensor> pred_vector;
1504  if (is_inner) {
1505  tensorflow::run(&(cache_->getSession("inner")),
1506  {
1507  {"input_inner_egamma", *eGammaTensor_.at(is_inner)},
1508  {"input_inner_muon", *muonTensor_.at(is_inner)},
1509  {"input_inner_hadrons", *hadronsTensor_.at(is_inner)},
1510  },
1511  {"inner_all_dropout_4/Identity"},
1512  &pred_vector);
1513  } else {
1514  tensorflow::run(&(cache_->getSession("outer")),
1515  {
1516  {"input_outer_egamma", *eGammaTensor_.at(is_inner)},
1517  {"input_outer_muon", *muonTensor_.at(is_inner)},
1518  {"input_outer_hadrons", *hadronsTensor_.at(is_inner)},
1519  },
1520  {"outer_all_dropout_4/Identity"},
1521  &pred_vector);
1522  }
1523  return pred_vector.at(0);
1524  }
1525 
1526  template <typename CandidateCastType, typename TauCastType>
1527  void createConvFeatures(const TauCastType& tau,
1528  const size_t tau_index,
1529  const edm::RefToBase<reco::BaseTau> tau_ref,
1530  const reco::Vertex& pv,
1531  double rho,
1532  const std::vector<pat::Electron>* electrons,
1533  const std::vector<pat::Muon>* muons,
1534  const edm::View<reco::Candidate>& pfCands,
1535  const CellGrid& grid,
1536  TauFunc tau_funcs,
1537  bool is_inner) {
1538  tensorflow::Tensor& convTensor = *convTensor_.at(is_inner);
1539  eGammaTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1540  tensorflow::DT_FLOAT,
1541  tensorflow::TensorShape{
1542  (long long int)grid.num_valid_cells(), 1, 1, dnn_inputs_2017_v2::EgammaBlockInputs::NumberOfInputs});
1543  muonTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1544  tensorflow::DT_FLOAT,
1545  tensorflow::TensorShape{
1546  (long long int)grid.num_valid_cells(), 1, 1, dnn_inputs_2017_v2::MuonBlockInputs::NumberOfInputs});
1547  hadronsTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1548  tensorflow::DT_FLOAT,
1549  tensorflow::TensorShape{
1550  (long long int)grid.num_valid_cells(), 1, 1, dnn_inputs_2017_v2::HadronBlockInputs::NumberOfInputs});
1551 
1552  eGammaTensor_[is_inner]->flat<float>().setZero();
1553  muonTensor_[is_inner]->flat<float>().setZero();
1554  hadronsTensor_[is_inner]->flat<float>().setZero();
1555 
1556  unsigned idx = 0;
1557  for (int eta = -grid.maxEtaIndex(); eta <= grid.maxEtaIndex(); ++eta) {
1558  for (int phi = -grid.maxPhiIndex(); phi <= grid.maxPhiIndex(); ++phi) {
1559  const CellIndex cell_index{eta, phi};
1560  const auto cell_iter = grid.find(cell_index);
1561  if (cell_iter != grid.end()) {
1562  const Cell& cell = cell_iter->second;
1563  createEgammaBlockInputs<CandidateCastType>(
1564  idx, tau, tau_index, tau_ref, pv, rho, electrons, pfCands, cell, tau_funcs, is_inner);
1565  createMuonBlockInputs<CandidateCastType>(
1566  idx, tau, tau_index, tau_ref, pv, rho, muons, pfCands, cell, tau_funcs, is_inner);
1567  createHadronsBlockInputs<CandidateCastType>(
1568  idx, tau, tau_index, tau_ref, pv, rho, pfCands, cell, tau_funcs, is_inner);
1569  idx += 1;
1570  }
1571  }
1572  }
1573 
1574  const auto predTensor = getPartialPredictions(is_inner);
1575  idx = 0;
1576  for (int eta = -grid.maxEtaIndex(); eta <= grid.maxEtaIndex(); ++eta) {
1577  for (int phi = -grid.maxPhiIndex(); phi <= grid.maxPhiIndex(); ++phi) {
1578  const CellIndex cell_index{eta, phi};
1579  const int eta_index = grid.getEtaTensorIndex(cell_index);
1580  const int phi_index = grid.getPhiTensorIndex(cell_index);
1581 
1582  const auto cell_iter = grid.find(cell_index);
1583  if (cell_iter != grid.end()) {
1584  setCellConvFeatures(convTensor, predTensor, idx, eta_index, phi_index);
1585  idx += 1;
1586  } else {
1587  setCellConvFeatures(convTensor, *zeroOutputTensor_[is_inner], 0, eta_index, phi_index);
1588  }
1589  }
1590  }
1591  }
1592 
1593  void setCellConvFeatures(tensorflow::Tensor& convTensor,
1594  const tensorflow::Tensor& features,
1595  unsigned batch_idx,
1596  int eta_index,
1597  int phi_index) {
1598  for (int n = 0; n < dnn_inputs_2017_v2::number_of_conv_features; ++n)
1599  convTensor.tensor<float, 4>()(0, eta_index, phi_index, n) = features.tensor<float, 4>()(batch_idx, 0, 0, n);
1600  }
1601 
1602  template <typename CandidateCastType, typename TauCastType>
1603  void createTauBlockInputs(const TauCastType& tau,
1604  const size_t& tau_index,
1605  const edm::RefToBase<reco::BaseTau> tau_ref,
1606  const reco::Vertex& pv,
1607  double rho,
1608  TauFunc tau_funcs) {
1609  namespace dnn = dnn_inputs_2017_v2::TauBlockInputs;
1610 
1611  tensorflow::Tensor& inputs = *tauBlockTensor_;
1612  inputs.flat<float>().setZero();
1613 
1614  const auto& get = [&](int var_index) -> float& { return inputs.matrix<float>()(0, var_index); };
1615 
1616  auto leadChargedHadrCand = dynamic_cast<const CandidateCastType*>(tau.leadChargedHadrCand().get());
1617 
1618  get(dnn::rho) = getValueNorm(rho, 21.49f, 9.713f);
1619  get(dnn::tau_pt) = getValueLinear(tau.polarP4().pt(), 20.f, 1000.f, true);
1620  get(dnn::tau_eta) = getValueLinear(tau.polarP4().eta(), -2.3f, 2.3f, false);
1621  get(dnn::tau_phi) = getValueLinear(tau.polarP4().phi(), -pi, pi, false);
1622  get(dnn::tau_mass) = getValueNorm(tau.polarP4().mass(), 0.6669f, 0.6553f);
1623  get(dnn::tau_E_over_pt) = getValueLinear(tau.p4().energy() / tau.p4().pt(), 1.f, 5.2f, true);
1624  get(dnn::tau_charge) = getValue(tau.charge());
1625  get(dnn::tau_n_charged_prongs) = getValueLinear(tau.decayMode() / 5 + 1, 1, 3, true);
1626  get(dnn::tau_n_neutral_prongs) = getValueLinear(tau.decayMode() % 5, 0, 2, true);
1627  get(dnn::chargedIsoPtSum) = getValueNorm(tau_funcs.getChargedIsoPtSum(tau, tau_ref), 47.78f, 123.5f);
1628  get(dnn::chargedIsoPtSumdR03_over_dR05) =
1629  getValue(tau_funcs.getChargedIsoPtSumdR03(tau, tau_ref) / tau_funcs.getChargedIsoPtSum(tau, tau_ref));
1630  get(dnn::footprintCorrection) = getValueNorm(tau_funcs.getFootprintCorrectiondR03(tau, tau_ref), 9.029f, 26.42f);
1631  get(dnn::neutralIsoPtSum) = getValueNorm(tau_funcs.getNeutralIsoPtSum(tau, tau_ref), 57.59f, 155.3f);
1632  get(dnn::neutralIsoPtSumWeight_over_neutralIsoPtSum) =
1633  getValue(tau_funcs.getNeutralIsoPtSumWeight(tau, tau_ref) / tau_funcs.getNeutralIsoPtSum(tau, tau_ref));
1634  get(dnn::neutralIsoPtSumWeightdR03_over_neutralIsoPtSum) =
1635  getValue(tau_funcs.getNeutralIsoPtSumdR03Weight(tau, tau_ref) / tau_funcs.getNeutralIsoPtSum(tau, tau_ref));
1636  get(dnn::neutralIsoPtSumdR03_over_dR05) =
1637  getValue(tau_funcs.getNeutralIsoPtSumdR03(tau, tau_ref) / tau_funcs.getNeutralIsoPtSum(tau, tau_ref));
1638  get(dnn::photonPtSumOutsideSignalCone) =
1639  getValueNorm(tau_funcs.getPhotonPtSumOutsideSignalCone(tau, tau_ref), 1.731f, 6.846f);
1640  get(dnn::puCorrPtSum) = getValueNorm(tau_funcs.getPuCorrPtSum(tau, tau_ref), 22.38f, 16.34f);
1641  // The global PCA coordinates were used as inputs during the NN training, but it was decided to disable
1642  // them for the inference, because modeling of dxy_PCA in MC poorly describes the data, and x and y coordinates
1643  // in data results outside of the expected 5 std. dev. input validity range. On the other hand,
1644  // these coordinates are strongly era-dependent. Kept as comment to document what NN expects.
1645  if (!disable_dxy_pca_) {
1646  auto const pca = tau_funcs.getdxyPCA(tau, tau_index);
1647  get(dnn::tau_dxy_pca_x) = getValueNorm(pca.x(), -0.0241f, 0.0074f);
1648  get(dnn::tau_dxy_pca_y) = getValueNorm(pca.y(), 0.0675f, 0.0128f);
1649  get(dnn::tau_dxy_pca_z) = getValueNorm(pca.z(), 0.7973f, 3.456f);
1650  } else {
1651  get(dnn::tau_dxy_pca_x) = 0;
1652  get(dnn::tau_dxy_pca_y) = 0;
1653  get(dnn::tau_dxy_pca_z) = 0;
1654  }
1655  const bool tau_dxy_valid =
1656  isAbove(tau_funcs.getdxy(tau, tau_index), -10) && isAbove(tau_funcs.getdxyError(tau, tau_index), 0);
1657  if (tau_dxy_valid) {
1658  get(dnn::tau_dxy_valid) = tau_dxy_valid;
1659  get(dnn::tau_dxy) = getValueNorm(tau_funcs.getdxy(tau, tau_index), 0.0018f, 0.0085f);
1660  get(dnn::tau_dxy_sig) = getValueNorm(
1661  std::abs(tau_funcs.getdxy(tau, tau_index)) / tau_funcs.getdxyError(tau, tau_index), 2.26f, 4.191f);
1662  }
1663  const bool tau_ip3d_valid =
1664  isAbove(tau_funcs.getip3d(tau, tau_index), -10) && isAbove(tau_funcs.getip3dError(tau, tau_index), 0);
1665  if (tau_ip3d_valid) {
1666  get(dnn::tau_ip3d_valid) = tau_ip3d_valid;
1667  get(dnn::tau_ip3d) = getValueNorm(tau_funcs.getip3d(tau, tau_index), 0.0026f, 0.0114f);
1668  get(dnn::tau_ip3d_sig) = getValueNorm(
1669  std::abs(tau_funcs.getip3d(tau, tau_index)) / tau_funcs.getip3dError(tau, tau_index), 2.928f, 4.466f);
1670  }
1671  if (leadChargedHadrCand) {
1672  get(dnn::tau_dz) = getValueNorm(candFunc::getTauDz(*leadChargedHadrCand, default_value), 0.f, 0.0190f);
1673  get(dnn::tau_dz_sig_valid) = candFunc::getTauDZSigValid(*leadChargedHadrCand);
1674  const double dzError = candFunc::getTauDzError(*leadChargedHadrCand, default_value);
1675  get(dnn::tau_dz_sig) =
1676  getValueNorm(std::abs(candFunc::getTauDz(*leadChargedHadrCand, default_value)) / dzError, 4.717f, 11.78f);
1677  }
1678  get(dnn::tau_flightLength_x) = getValueNorm(tau_funcs.getFlightLength(tau, tau_index).x(), -0.0003f, 0.7362f);
1679  get(dnn::tau_flightLength_y) = getValueNorm(tau_funcs.getFlightLength(tau, tau_index).y(), -0.0009f, 0.7354f);
1680  get(dnn::tau_flightLength_z) = getValueNorm(tau_funcs.getFlightLength(tau, tau_index).z(), -0.0022f, 1.993f);
1681  get(dnn::tau_flightLength_sig) = 0.55756444; //This value is set due to a bug in the training
1682  get(dnn::tau_pt_weighted_deta_strip) =
1683  getValueLinear(reco::tau::pt_weighted_deta_strip(tau, tau.decayMode()), 0, 1, true);
1684 
1685  get(dnn::tau_pt_weighted_dphi_strip) =
1686  getValueLinear(reco::tau::pt_weighted_dphi_strip(tau, tau.decayMode()), 0, 1, true);
1687  get(dnn::tau_pt_weighted_dr_signal) =
1688  getValueNorm(reco::tau::pt_weighted_dr_signal(tau, tau.decayMode()), 0.0052f, 0.01433f);
1689  get(dnn::tau_pt_weighted_dr_iso) = getValueLinear(reco::tau::pt_weighted_dr_iso(tau, tau.decayMode()), 0, 1, true);
1690  get(dnn::tau_leadingTrackNormChi2) = getValueNorm(tau_funcs.getLeadingTrackNormChi2(tau), 1.538f, 4.401f);
1691  const auto eratio = reco::tau::eratio(tau);
1692  const bool tau_e_ratio_valid = std::isnormal(eratio) && eratio > 0.f;
1693  get(dnn::tau_e_ratio_valid) = tau_e_ratio_valid;
1694  get(dnn::tau_e_ratio) = tau_e_ratio_valid ? getValueLinear(eratio, 0, 1, true) : 0.f;
1695  const double gj_angle_diff = calculateGottfriedJacksonAngleDifference(tau, tau_index, tau_funcs);
1696  const bool tau_gj_angle_diff_valid = (std::isnormal(gj_angle_diff) || gj_angle_diff == 0) && gj_angle_diff >= 0;
1697  get(dnn::tau_gj_angle_diff_valid) = tau_gj_angle_diff_valid;
1698  get(dnn::tau_gj_angle_diff) = tau_gj_angle_diff_valid ? getValueLinear(gj_angle_diff, 0, pi, true) : 0;
1699  get(dnn::tau_n_photons) = getValueNorm(reco::tau::n_photons_total(tau), 2.95f, 3.927f);
1700  get(dnn::tau_emFraction) = getValueLinear(tau_funcs.getEmFraction(tau), -1, 1, false);
1701 
1702  get(dnn::tau_inside_ecal_crack) = getValue(isInEcalCrack(tau.p4().eta()));
1703  get(dnn::leadChargedCand_etaAtEcalEntrance_minus_tau_eta) =
1704  getValueNorm(tau_funcs.getEtaAtEcalEntrance(tau) - tau.p4().eta(), 0.0042f, 0.0323f);
1705  checkInputs(inputs, "tau_block", dnn::NumberOfInputs);
1706  }
1707 
1708  template <typename CandidateCastType, typename TauCastType>
1710  const TauCastType& tau,
1711  const size_t tau_index,
1712  const edm::RefToBase<reco::BaseTau> tau_ref,
1713  const reco::Vertex& pv,
1714  double rho,
1715  const std::vector<pat::Electron>* electrons,
1716  const edm::View<reco::Candidate>& pfCands,
1717  const Cell& cell_map,
1718  TauFunc tau_funcs,
1719  bool is_inner) {
1720  namespace dnn = dnn_inputs_2017_v2::EgammaBlockInputs;
1721 
1722  tensorflow::Tensor& inputs = *eGammaTensor_.at(is_inner);
1723 
1724  const auto& get = [&](int var_index) -> float& { return inputs.tensor<float, 4>()(idx, 0, 0, var_index); };
1725 
1726  const bool valid_index_pf_ele = cell_map.count(CellObjectType::PfCand_electron);
1727  const bool valid_index_pf_gamma = cell_map.count(CellObjectType::PfCand_gamma);
1728  const bool valid_index_ele = cell_map.count(CellObjectType::Electron);
1729 
1730  if (!cell_map.empty()) {
1731  get(dnn::rho) = getValueNorm(rho, 21.49f, 9.713f);
1732  get(dnn::tau_pt) = getValueLinear(tau.polarP4().pt(), 20.f, 1000.f, true);
1733  get(dnn::tau_eta) = getValueLinear(tau.polarP4().eta(), -2.3f, 2.3f, false);
1734  get(dnn::tau_inside_ecal_crack) = getValue(isInEcalCrack(tau.polarP4().eta()));
1735  }
1736  if (valid_index_pf_ele) {
1737  size_t index_pf_ele = cell_map.at(CellObjectType::PfCand_electron);
1738  const auto& ele_cand = dynamic_cast<const CandidateCastType&>(pfCands.at(index_pf_ele));
1739 
1740  get(dnn::pfCand_ele_valid) = valid_index_pf_ele;
1741  get(dnn::pfCand_ele_rel_pt) = getValueNorm(pfCands.at(index_pf_ele).polarP4().pt() / tau.polarP4().pt(),
1742  is_inner ? 0.9792f : 0.304f,
1743  is_inner ? 0.5383f : 1.845f);
1744  get(dnn::pfCand_ele_deta) = getValueLinear(pfCands.at(index_pf_ele).polarP4().eta() - tau.polarP4().eta(),
1745  is_inner ? -0.1f : -0.5f,
1746  is_inner ? 0.1f : 0.5f,
1747  false);
1748  get(dnn::pfCand_ele_dphi) = getValueLinear(dPhi(tau.polarP4(), pfCands.at(index_pf_ele).polarP4()),
1749  is_inner ? -0.1f : -0.5f,
1750  is_inner ? 0.1f : 0.5f,
1751  false);
1752  get(dnn::pfCand_ele_pvAssociationQuality) =
1753  getValueLinear<int>(candFunc::getPvAssocationQuality(ele_cand), 0, 7, true);
1754  get(dnn::pfCand_ele_puppiWeight) = getValue(candFunc::getPuppiWeight(ele_cand));
1755  get(dnn::pfCand_ele_charge) = getValue(ele_cand.charge());
1756  get(dnn::pfCand_ele_lostInnerHits) = getValue<int>(candFunc::getLostInnerHits(ele_cand, default_value));
1757  get(dnn::pfCand_ele_numberOfPixelHits) =
1758  getValueLinear(candFunc::getNumberOfPixelHits(ele_cand, default_value), 0, 10, true);
1759  get(dnn::pfCand_ele_vertex_dx) =
1760  getValueNorm(pfCands.at(index_pf_ele).vertex().x() - pv.position().x(), 0.f, 0.1221f);
1761  get(dnn::pfCand_ele_vertex_dy) =
1762  getValueNorm(pfCands.at(index_pf_ele).vertex().y() - pv.position().y(), 0.f, 0.1226f);
1763  get(dnn::pfCand_ele_vertex_dz) =
1764  getValueNorm(pfCands.at(index_pf_ele).vertex().z() - pv.position().z(), 0.001f, 1.024f);
1765  get(dnn::pfCand_ele_vertex_dx_tauFL) = getValueNorm(
1766  pfCands.at(index_pf_ele).vertex().x() - pv.position().x() - tau_funcs.getFlightLength(tau, tau_index).x(),
1767  0.f,
1768  0.3411f);
1769  get(dnn::pfCand_ele_vertex_dy_tauFL) = getValueNorm(
1770  pfCands.at(index_pf_ele).vertex().y() - pv.position().y() - tau_funcs.getFlightLength(tau, tau_index).y(),
1771  0.0003f,
1772  0.3385f);
1773  get(dnn::pfCand_ele_vertex_dz_tauFL) = getValueNorm(
1774  pfCands.at(index_pf_ele).vertex().z() - pv.position().z() - tau_funcs.getFlightLength(tau, tau_index).z(),
1775  0.f,
1776  1.307f);
1777 
1778  const bool hasTrackDetails = candFunc::getHasTrackDetails(ele_cand);
1779  if (hasTrackDetails) {
1780  get(dnn::pfCand_ele_hasTrackDetails) = hasTrackDetails;
1781  get(dnn::pfCand_ele_dxy) = getValueNorm(candFunc::getTauDxy(ele_cand, default_value), 0.f, 0.171f);
1782  get(dnn::pfCand_ele_dxy_sig) =
1783  getValueNorm(std::abs(candFunc::getTauDxy(ele_cand, default_value)) / pfCands.at(index_pf_ele).dxyError(),
1784  1.634f,
1785  6.45f);
1786  get(dnn::pfCand_ele_dz) = getValueNorm(candFunc::getTauDz(ele_cand, default_value), 0.001f, 1.02f);
1787  get(dnn::pfCand_ele_dz_sig) = getValueNorm(
1788  std::abs(candFunc::getTauDz(ele_cand, default_value)) / candFunc::getTauDzError(ele_cand, default_value),
1789  24.56f,
1790  210.4f);
1791  get(dnn::pfCand_ele_track_chi2_ndof) = getValueNorm(
1792  candFunc::getPseudoTrack(ele_cand).chi2() / candFunc::getPseudoTrack(ele_cand).ndof(), 2.272f, 8.439f);
1793  get(dnn::pfCand_ele_track_ndof) = getValueNorm(candFunc::getPseudoTrack(ele_cand).ndof(), 15.18f, 3.203f);
1794  }
1795  }
1796  if (valid_index_pf_gamma) {
1797  size_t index_pf_gamma = cell_map.at(CellObjectType::PfCand_gamma);
1798  const auto& gamma_cand = dynamic_cast<const CandidateCastType&>(pfCands.at(index_pf_gamma));
1799 
1800  get(dnn::pfCand_gamma_valid) = valid_index_pf_gamma;
1801  get(dnn::pfCand_gamma_rel_pt) = getValueNorm(pfCands.at(index_pf_gamma).polarP4().pt() / tau.polarP4().pt(),
1802  is_inner ? 0.6048f : 0.02576f,
1803  is_inner ? 1.669f : 0.3833f);
1804  get(dnn::pfCand_gamma_deta) = getValueLinear(pfCands.at(index_pf_gamma).polarP4().eta() - tau.polarP4().eta(),
1805  is_inner ? -0.1f : -0.5f,
1806  is_inner ? 0.1f : 0.5f,
1807  false);
1808  get(dnn::pfCand_gamma_dphi) = getValueLinear(dPhi(tau.polarP4(), pfCands.at(index_pf_gamma).polarP4()),
1809  is_inner ? -0.1f : -0.5f,
1810  is_inner ? 0.1f : 0.5f,
1811  false);
1812  get(dnn::pfCand_gamma_pvAssociationQuality) =
1813  getValueLinear<int>(candFunc::getPvAssocationQuality(gamma_cand), 0, 7, true);
1814  get(dnn::pfCand_gamma_fromPV) = getValueLinear<int>(candFunc::getFromPV(gamma_cand), 0, 3, true);
1815  get(dnn::pfCand_gamma_puppiWeight) = getValue(candFunc::getPuppiWeight(gamma_cand));
1816  get(dnn::pfCand_gamma_puppiWeightNoLep) = getValue(candFunc::getPuppiWeightNoLep(gamma_cand));
1817  get(dnn::pfCand_gamma_lostInnerHits) = getValue<int>(candFunc::getLostInnerHits(gamma_cand, default_value));
1818  get(dnn::pfCand_gamma_numberOfPixelHits) =
1819  getValueLinear(candFunc::getNumberOfPixelHits(gamma_cand, default_value), 0, 7, true);
1820  get(dnn::pfCand_gamma_vertex_dx) =
1821  getValueNorm(pfCands.at(index_pf_gamma).vertex().x() - pv.position().x(), 0.f, 0.0067f);
1822  get(dnn::pfCand_gamma_vertex_dy) =
1823  getValueNorm(pfCands.at(index_pf_gamma).vertex().y() - pv.position().y(), 0.f, 0.0069f);
1824  get(dnn::pfCand_gamma_vertex_dz) =
1825  getValueNorm(pfCands.at(index_pf_gamma).vertex().z() - pv.position().z(), 0.f, 0.0578f);
1826  get(dnn::pfCand_gamma_vertex_dx_tauFL) = getValueNorm(
1827  pfCands.at(index_pf_gamma).vertex().x() - pv.position().x() - tau_funcs.getFlightLength(tau, tau_index).x(),
1828  0.001f,
1829  0.9565f);
1830  get(dnn::pfCand_gamma_vertex_dy_tauFL) = getValueNorm(
1831  pfCands.at(index_pf_gamma).vertex().y() - pv.position().y() - tau_funcs.getFlightLength(tau, tau_index).y(),
1832  0.0008f,
1833  0.9592f);
1834  get(dnn::pfCand_gamma_vertex_dz_tauFL) = getValueNorm(
1835  pfCands.at(index_pf_gamma).vertex().z() - pv.position().z() - tau_funcs.getFlightLength(tau, tau_index).z(),
1836  0.0038f,
1837  2.154f);
1838  const bool hasTrackDetails = candFunc::getHasTrackDetails(gamma_cand);
1839  if (hasTrackDetails) {
1840  get(dnn::pfCand_gamma_hasTrackDetails) = hasTrackDetails;
1841  get(dnn::pfCand_gamma_dxy) = getValueNorm(candFunc::getTauDxy(gamma_cand, default_value), 0.0004f, 0.882f);
1842  get(dnn::pfCand_gamma_dxy_sig) = getValueNorm(
1843  std::abs(candFunc::getTauDxy(gamma_cand, default_value)) / gamma_cand.dxyError(), 4.271f, 63.78f);
1844  get(dnn::pfCand_gamma_dz) = getValueNorm(candFunc::getTauDz(gamma_cand, default_value), 0.0071f, 5.285f);
1845  get(dnn::pfCand_gamma_dz_sig) = getValueNorm(std::abs(candFunc::getTauDz(gamma_cand, default_value)) /
1846  candFunc::getTauDzError(gamma_cand, default_value),
1847  162.1f,
1848  622.4f);
1849  get(dnn::pfCand_gamma_track_chi2_ndof) = candFunc::getPseudoTrack(gamma_cand).ndof() > 0
1850  ? getValueNorm(candFunc::getPseudoTrack(gamma_cand).chi2() /
1851  candFunc::getPseudoTrack(gamma_cand).ndof(),
1852  4.268f,
1853  15.47f)
1854  : 0;
1855  get(dnn::pfCand_gamma_track_ndof) =
1856  candFunc::getPseudoTrack(gamma_cand).ndof() > 0
1857  ? getValueNorm(candFunc::getPseudoTrack(gamma_cand).ndof(), 12.25f, 4.774f)
1858  : 0;
1859  }
1860  }
1861  if (valid_index_ele) {
1862  size_t index_ele = cell_map.at(CellObjectType::Electron);
1863 
1864  get(dnn::ele_valid) = valid_index_ele;
1865  get(dnn::ele_rel_pt) = getValueNorm(electrons->at(index_ele).polarP4().pt() / tau.polarP4().pt(),
1866  is_inner ? 1.067f : 0.5111f,
1867  is_inner ? 1.521f : 2.765f);
1868  get(dnn::ele_deta) = getValueLinear(electrons->at(index_ele).polarP4().eta() - tau.polarP4().eta(),
1869  is_inner ? -0.1f : -0.5f,
1870  is_inner ? 0.1f : 0.5f,
1871  false);
1872  get(dnn::ele_dphi) = getValueLinear(dPhi(tau.polarP4(), electrons->at(index_ele).polarP4()),
1873  is_inner ? -0.1f : -0.5f,
1874  is_inner ? 0.1f : 0.5f,
1875  false);
1876 
1877  float cc_ele_energy, cc_gamma_energy;
1878  int cc_n_gamma;
1879  const bool cc_valid =
1880  calculateElectronClusterVarsV2(electrons->at(index_ele), cc_ele_energy, cc_gamma_energy, cc_n_gamma);
1881  if (cc_valid) {
1882  get(dnn::ele_cc_valid) = cc_valid;
1883  get(dnn::ele_cc_ele_rel_energy) =
1884  getValueNorm(cc_ele_energy / electrons->at(index_ele).polarP4().pt(), 1.729f, 1.644f);
1885  get(dnn::ele_cc_gamma_rel_energy) = getValueNorm(cc_gamma_energy / cc_ele_energy, 0.1439f, 0.3284f);
1886  get(dnn::ele_cc_n_gamma) = getValueNorm(cc_n_gamma, 1.794f, 2.079f);
1887  }
1888  get(dnn::ele_rel_trackMomentumAtVtx) = getValueNorm(
1889  electrons->at(index_ele).trackMomentumAtVtx().R() / electrons->at(index_ele).polarP4().pt(), 1.531f, 1.424f);
1890  get(dnn::ele_rel_trackMomentumAtCalo) = getValueNorm(
1891  electrons->at(index_ele).trackMomentumAtCalo().R() / electrons->at(index_ele).polarP4().pt(), 1.531f, 1.424f);
1892  get(dnn::ele_rel_trackMomentumOut) = getValueNorm(
1893  electrons->at(index_ele).trackMomentumOut().R() / electrons->at(index_ele).polarP4().pt(), 0.7735f, 0.935f);
1894  get(dnn::ele_rel_trackMomentumAtEleClus) =
1895  getValueNorm(electrons->at(index_ele).trackMomentumAtEleClus().R() / electrons->at(index_ele).polarP4().pt(),
1896  0.7735f,
1897  0.935f);
1898  get(dnn::ele_rel_trackMomentumAtVtxWithConstraint) = getValueNorm(
1899  electrons->at(index_ele).trackMomentumAtVtxWithConstraint().R() / electrons->at(index_ele).polarP4().pt(),
1900  1.625f,
1901  1.581f);
1902  get(dnn::ele_rel_ecalEnergy) =
1903  getValueNorm(electrons->at(index_ele).ecalEnergy() / electrons->at(index_ele).polarP4().pt(), 1.993f, 1.308f);
1904  get(dnn::ele_ecalEnergy_sig) = getValueNorm(
1905  electrons->at(index_ele).ecalEnergy() / electrons->at(index_ele).ecalEnergyError(), 70.25f, 58.16f);
1906  get(dnn::ele_eSuperClusterOverP) = getValueNorm(electrons->at(index_ele).eSuperClusterOverP(), 2.432f, 15.13f);
1907  get(dnn::ele_eSeedClusterOverP) = getValueNorm(electrons->at(index_ele).eSeedClusterOverP(), 2.034f, 13.96f);
1908  get(dnn::ele_eSeedClusterOverPout) = getValueNorm(electrons->at(index_ele).eSeedClusterOverPout(), 6.64f, 36.8f);
1909  get(dnn::ele_eEleClusterOverPout) = getValueNorm(electrons->at(index_ele).eEleClusterOverPout(), 4.183f, 20.63f);
1910  get(dnn::ele_deltaEtaSuperClusterTrackAtVtx) =
1911  getValueNorm(electrons->at(index_ele).deltaEtaSuperClusterTrackAtVtx(), 0.f, 0.0363f);
1912  get(dnn::ele_deltaEtaSeedClusterTrackAtCalo) =
1913  getValueNorm(electrons->at(index_ele).deltaEtaSeedClusterTrackAtCalo(), -0.0001f, 0.0512f);
1914  get(dnn::ele_deltaEtaEleClusterTrackAtCalo) =
1915  getValueNorm(electrons->at(index_ele).deltaEtaEleClusterTrackAtCalo(), -0.0001f, 0.0541f);
1916  get(dnn::ele_deltaPhiEleClusterTrackAtCalo) =
1917  getValueNorm(electrons->at(index_ele).deltaPhiEleClusterTrackAtCalo(), 0.0002f, 0.0553f);
1918  get(dnn::ele_deltaPhiSuperClusterTrackAtVtx) =
1919  getValueNorm(electrons->at(index_ele).deltaPhiSuperClusterTrackAtVtx(), 0.0001f, 0.0523f);
1920  get(dnn::ele_deltaPhiSeedClusterTrackAtCalo) =
1921  getValueNorm(electrons->at(index_ele).deltaPhiSeedClusterTrackAtCalo(), 0.0004f, 0.0777f);
1922  get(dnn::ele_mvaInput_earlyBrem) = getValue(electrons->at(index_ele).mvaInput().earlyBrem);
1923  get(dnn::ele_mvaInput_lateBrem) = getValue(electrons->at(index_ele).mvaInput().lateBrem);
1924  get(dnn::ele_mvaInput_sigmaEtaEta) =
1925  getValueNorm(electrons->at(index_ele).mvaInput().sigmaEtaEta, 0.0008f, 0.0052f);
1926  get(dnn::ele_mvaInput_hadEnergy) = getValueNorm(electrons->at(index_ele).mvaInput().hadEnergy, 14.04f, 69.48f);
1927  get(dnn::ele_mvaInput_deltaEta) = getValueNorm(electrons->at(index_ele).mvaInput().deltaEta, 0.0099f, 0.0851f);
1928  const auto& gsfTrack = electrons->at(index_ele).gsfTrack();
1929  if (gsfTrack.isNonnull()) {
1930  get(dnn::ele_gsfTrack_normalizedChi2) = getValueNorm(gsfTrack->normalizedChi2(), 3.049f, 10.39f);
1931  get(dnn::ele_gsfTrack_numberOfValidHits) = getValueNorm(gsfTrack->numberOfValidHits(), 16.52f, 2.806f);
1932  get(dnn::ele_rel_gsfTrack_pt) =
1933  getValueNorm(gsfTrack->pt() / electrons->at(index_ele).polarP4().pt(), 1.355f, 16.81f);
1934  get(dnn::ele_gsfTrack_pt_sig) = getValueNorm(gsfTrack->pt() / gsfTrack->ptError(), 5.046f, 3.119f);
1935  }
1936  const auto& closestCtfTrack = electrons->at(index_ele).closestCtfTrackRef();
1937  const bool has_closestCtfTrack = closestCtfTrack.isNonnull();
1938  if (has_closestCtfTrack) {
1939  get(dnn::ele_has_closestCtfTrack) = has_closestCtfTrack;
1940  get(dnn::ele_closestCtfTrack_normalizedChi2) = getValueNorm(closestCtfTrack->normalizedChi2(), 2.411f, 6.98f);
1941  get(dnn::ele_closestCtfTrack_numberOfValidHits) =
1942  getValueNorm(closestCtfTrack->numberOfValidHits(), 15.16f, 5.26f);
1943  }
1944  }
1945  if (valid_index_ele or valid_index_pf_ele or valid_index_pf_gamma)
1946  checkInputs(inputs, is_inner ? "egamma_inner_block" : "egamma_outer_block", dnn::NumberOfInputs);
1947  }
1948 
1949  template <typename CandidateCastType, typename TauCastType>
1951  const TauCastType& tau,
1952  const size_t tau_index,
1953  const edm::RefToBase<reco::BaseTau> tau_ref,
1954  const reco::Vertex& pv,
1955  double rho,
1956  const std::vector<pat::Muon>* muons,
1957  const edm::View<reco::Candidate>& pfCands,
1958  const Cell& cell_map,
1959  TauFunc tau_funcs,
1960  bool is_inner) {
1961  namespace dnn = dnn_inputs_2017_v2::MuonBlockInputs;
1962 
1963  tensorflow::Tensor& inputs = *muonTensor_.at(is_inner);
1964 
1965  const auto& get = [&](int var_index) -> float& { return inputs.tensor<float, 4>()(idx, 0, 0, var_index); };
1966 
1967  const bool valid_index_pf_muon = cell_map.count(CellObjectType::PfCand_muon);
1968  const bool valid_index_muon = cell_map.count(CellObjectType::Muon);
1969 
1970  if (!cell_map.empty()) {
1971  get(dnn::rho) = getValueNorm(rho, 21.49f, 9.713f);
1972  get(dnn::tau_pt) = getValueLinear(tau.polarP4().pt(), 20.f, 1000.f, true);
1973  get(dnn::tau_eta) = getValueLinear(tau.polarP4().eta(), -2.3f, 2.3f, false);
1974  get(dnn::tau_inside_ecal_crack) = getValue(isInEcalCrack(tau.polarP4().eta()));
1975  }
1976  if (valid_index_pf_muon) {
1977  size_t index_pf_muon = cell_map.at(CellObjectType::PfCand_muon);
1978  const auto& muon_cand = dynamic_cast<const CandidateCastType&>(pfCands.at(index_pf_muon));
1979 
1980  get(dnn::pfCand_muon_valid) = valid_index_pf_muon;
1981  get(dnn::pfCand_muon_rel_pt) = getValueNorm(pfCands.at(index_pf_muon).polarP4().pt() / tau.polarP4().pt(),
1982  is_inner ? 0.9509f : 0.0861f,
1983  is_inner ? 0.4294f : 0.4065f);
1984  get(dnn::pfCand_muon_deta) = getValueLinear(pfCands.at(index_pf_muon).polarP4().eta() - tau.polarP4().eta(),
1985  is_inner ? -0.1f : -0.5f,
1986  is_inner ? 0.1f : 0.5f,
1987  false);
1988  get(dnn::pfCand_muon_dphi) = getValueLinear(dPhi(tau.polarP4(), pfCands.at(index_pf_muon).polarP4()),
1989  is_inner ? -0.1f : -0.5f,
1990  is_inner ? 0.1f : 0.5f,
1991  false);
1992  get(dnn::pfCand_muon_pvAssociationQuality) =
1993  getValueLinear<int>(candFunc::getPvAssocationQuality(muon_cand), 0, 7, true);
1994  get(dnn::pfCand_muon_fromPV) = getValueLinear<int>(candFunc::getFromPV(muon_cand), 0, 3, true);
1995  get(dnn::pfCand_muon_puppiWeight) = getValue(candFunc::getPuppiWeight(muon_cand));
1996  get(dnn::pfCand_muon_charge) = getValue(muon_cand.charge());
1997  get(dnn::pfCand_muon_lostInnerHits) = getValue<int>(candFunc::getLostInnerHits(muon_cand, default_value));
1998  get(dnn::pfCand_muon_numberOfPixelHits) =
1999  getValueLinear(candFunc::getNumberOfPixelHits(muon_cand, default_value), 0, 11, true);
2000  get(dnn::pfCand_muon_vertex_dx) =
2001  getValueNorm(pfCands.at(index_pf_muon).vertex().x() - pv.position().x(), -0.0007f, 0.6869f);
2002  get(dnn::pfCand_muon_vertex_dy) =
2003  getValueNorm(pfCands.at(index_pf_muon).vertex().y() - pv.position().y(), 0.0001f, 0.6784f);
2004  get(dnn::pfCand_muon_vertex_dz) =
2005  getValueNorm(pfCands.at(index_pf_muon).vertex().z() - pv.position().z(), -0.0117f, 4.097f);
2006  get(dnn::pfCand_muon_vertex_dx_tauFL) = getValueNorm(
2007  pfCands.at(index_pf_muon).vertex().x() - pv.position().x() - tau_funcs.getFlightLength(tau, tau_index).x(),
2008  -0.0001f,
2009  0.8642f);
2010  get(dnn::pfCand_muon_vertex_dy_tauFL) = getValueNorm(
2011  pfCands.at(index_pf_muon).vertex().y() - pv.position().y() - tau_funcs.getFlightLength(tau, tau_index).y(),
2012  0.0004f,
2013  0.8561f);
2014  get(dnn::pfCand_muon_vertex_dz_tauFL) = getValueNorm(
2015  pfCands.at(index_pf_muon).vertex().z() - pv.position().z() - tau_funcs.getFlightLength(tau, tau_index).z(),
2016  -0.0118f,
2017  4.405f);
2018 
2019  const bool hasTrackDetails = candFunc::getHasTrackDetails(muon_cand);
2020  if (hasTrackDetails) {
2021  get(dnn::pfCand_muon_hasTrackDetails) = hasTrackDetails;
2022  get(dnn::pfCand_muon_dxy) = getValueNorm(candFunc::getTauDxy(muon_cand, default_value), -0.0045f, 0.9655f);
2023  get(dnn::pfCand_muon_dxy_sig) = getValueNorm(
2024  std::abs(candFunc::getTauDxy(muon_cand, default_value)) / muon_cand.dxyError(), 4.575f, 42.36f);
2025  get(dnn::pfCand_muon_dz) = getValueNorm(candFunc::getTauDz(muon_cand, default_value), -0.0117f, 4.097f);
2026  get(dnn::pfCand_muon_dz_sig) = getValueNorm(
2027  std::abs(candFunc::getTauDz(muon_cand, default_value)) / candFunc::getTauDzError(muon_cand, default_value),
2028  80.37f,
2029  343.3f);
2030  get(dnn::pfCand_muon_track_chi2_ndof) = getValueNorm(
2031  candFunc::getPseudoTrack(muon_cand).chi2() / candFunc::getPseudoTrack(muon_cand).ndof(), 0.69f, 1.711f);
2032  get(dnn::pfCand_muon_track_ndof) = getValueNorm(candFunc::getPseudoTrack(muon_cand).ndof(), 17.5f, 5.11f);
2033  }
2034  }
2035  if (valid_index_muon) {
2036  size_t index_muon = cell_map.at(CellObjectType::Muon);
2037 
2038  get(dnn::muon_valid) = valid_index_muon;
2039  get(dnn::muon_rel_pt) = getValueNorm(muons->at(index_muon).polarP4().pt() / tau.polarP4().pt(),
2040  is_inner ? 0.7966f : 0.2678f,
2041  is_inner ? 3.402f : 3.592f);
2042  get(dnn::muon_deta) = getValueLinear(muons->at(index_muon).polarP4().eta() - tau.polarP4().eta(),
2043  is_inner ? -0.1f : -0.5f,
2044  is_inner ? 0.1f : 0.5f,
2045  false);
2046  get(dnn::muon_dphi) = getValueLinear(dPhi(tau.polarP4(), muons->at(index_muon).polarP4()),
2047  is_inner ? -0.1f : -0.5f,
2048  is_inner ? 0.1f : 0.5f,
2049  false);
2050  get(dnn::muon_dxy) = getValueNorm(muons->at(index_muon).dB(pat::Muon::PV2D), 0.0019f, 1.039f);
2051  get(dnn::muon_dxy_sig) =
2052  getValueNorm(std::abs(muons->at(index_muon).dB(pat::Muon::PV2D)) / muons->at(index_muon).edB(pat::Muon::PV2D),
2053  8.98f,
2054  71.17f);
2055 
2056  const bool normalizedChi2_valid =
2057  muons->at(index_muon).globalTrack().isNonnull() && muons->at(index_muon).normChi2() >= 0;
2058  if (normalizedChi2_valid) {
2059  get(dnn::muon_normalizedChi2_valid) = normalizedChi2_valid;
2060  get(dnn::muon_normalizedChi2) = getValueNorm(muons->at(index_muon).normChi2(), 21.52f, 265.8f);
2061  if (muons->at(index_muon).innerTrack().isNonnull())
2062  get(dnn::muon_numberOfValidHits) = getValueNorm(muons->at(index_muon).numberOfValidHits(), 21.84f, 10.59f);
2063  }
2064  get(dnn::muon_segmentCompatibility) = getValue(muons->at(index_muon).segmentCompatibility());
2065  get(dnn::muon_caloCompatibility) = getValue(muons->at(index_muon).caloCompatibility());
2066 
2067  const bool pfEcalEnergy_valid = muons->at(index_muon).pfEcalEnergy() >= 0;
2068  if (pfEcalEnergy_valid) {
2069  get(dnn::muon_pfEcalEnergy_valid) = pfEcalEnergy_valid;
2070  get(dnn::muon_rel_pfEcalEnergy) =
2071  getValueNorm(muons->at(index_muon).pfEcalEnergy() / muons->at(index_muon).polarP4().pt(), 0.2273f, 0.4865f);
2072  }
2073 
2074  MuonHitMatchV2 hit_match(muons->at(index_muon));
2075  static const std::map<int, std::pair<int, int>> muonMatchHitVars = {
2076  {MuonSubdetId::DT, {dnn::muon_n_matches_DT_1, dnn::muon_n_hits_DT_1}},
2077  {MuonSubdetId::CSC, {dnn::muon_n_matches_CSC_1, dnn::muon_n_hits_CSC_1}},
2078  {MuonSubdetId::RPC, {dnn::muon_n_matches_RPC_1, dnn::muon_n_hits_RPC_1}}};
2079 
2080  static const std::map<int, std::vector<float>> muonMatchVarLimits = {
2081  {MuonSubdetId::DT, {2, 2, 2, 2}}, {MuonSubdetId::CSC, {6, 2, 2, 2}}, {MuonSubdetId::RPC, {7, 6, 4, 4}}};
2082 
2083  static const std::map<int, std::vector<float>> muonHitVarLimits = {{MuonSubdetId::DT, {12, 12, 12, 8}},
2084  {MuonSubdetId::CSC, {24, 12, 12, 12}},
2085  {MuonSubdetId::RPC, {4, 4, 2, 2}}};
2086 
2087  for (int subdet : hit_match.MuonHitMatchV2::consideredSubdets()) {
2088  const auto& matchHitVar = muonMatchHitVars.at(subdet);
2089  const auto& matchLimits = muonMatchVarLimits.at(subdet);
2090  const auto& hitLimits = muonHitVarLimits.at(subdet);
2091  for (int station = MuonHitMatchV2::first_station_id; station <= MuonHitMatchV2::last_station_id; ++station) {
2092  const unsigned n_matches = hit_match.nMatches(subdet, station);
2093  const unsigned n_hits = hit_match.nHits(subdet, station);
2094  get(matchHitVar.first + station - 1) = getValueLinear(n_matches, 0, matchLimits.at(station - 1), true);
2095  get(matchHitVar.second + station - 1) = getValueLinear(n_hits, 0, hitLimits.at(station - 1), true);
2096  }
2097  }
2098  }
2099  checkInputs(inputs, is_inner ? "muon_inner_block" : "muon_outer_block", dnn::NumberOfInputs);
2100  }
2101 
2102  template <typename CandidateCastType, typename TauCastType>
2104  const TauCastType& tau,
2105  const size_t tau_index,
2106  const edm::RefToBase<reco::BaseTau> tau_ref,
2107  const reco::Vertex& pv,
2108  double rho,
2109  const edm::View<reco::Candidate>& pfCands,
2110  const Cell& cell_map,
2111  TauFunc tau_funcs,
2112  bool is_inner) {
2113  namespace dnn = dnn_inputs_2017_v2::HadronBlockInputs;
2114 
2115  tensorflow::Tensor& inputs = *hadronsTensor_.at(is_inner);
2116 
2117  const auto& get = [&](int var_index) -> float& { return inputs.tensor<float, 4>()(idx, 0, 0, var_index); };
2118 
2119  const bool valid_chH = cell_map.count(CellObjectType::PfCand_chargedHadron);
2120  const bool valid_nH = cell_map.count(CellObjectType::PfCand_neutralHadron);
2121 
2122  if (!cell_map.empty()) {
2123  get(dnn::rho) = getValueNorm(rho, 21.49f, 9.713f);
2124  get(dnn::tau_pt) = getValueLinear(tau.polarP4().pt(), 20.f, 1000.f, true);
2125  get(dnn::tau_eta) = getValueLinear(tau.polarP4().eta(), -2.3f, 2.3f, false);
2126  get(dnn::tau_inside_ecal_crack) = getValue(isInEcalCrack(tau.polarP4().eta()));
2127  }
2128  if (valid_chH) {
2129  size_t index_chH = cell_map.at(CellObjectType::PfCand_chargedHadron);
2130  const auto& chH_cand = dynamic_cast<const CandidateCastType&>(pfCands.at(index_chH));
2131 
2132  get(dnn::pfCand_chHad_valid) = valid_chH;
2133  get(dnn::pfCand_chHad_rel_pt) = getValueNorm(pfCands.at(index_chH).polarP4().pt() / tau.polarP4().pt(),
2134  is_inner ? 0.2564f : 0.0194f,
2135  is_inner ? 0.8607f : 0.1865f);
2136  get(dnn::pfCand_chHad_deta) = getValueLinear(pfCands.at(index_chH).polarP4().eta() - tau.polarP4().eta(),
2137  is_inner ? -0.1f : -0.5f,
2138  is_inner ? 0.1f : 0.5f,
2139  false);
2140  get(dnn::pfCand_chHad_dphi) = getValueLinear(dPhi(tau.polarP4(), pfCands.at(index_chH).polarP4()),
2141  is_inner ? -0.1f : -0.5f,
2142  is_inner ? 0.1f : 0.5f,
2143  false);
2144  get(dnn::pfCand_chHad_leadChargedHadrCand) =
2145  getValue(&chH_cand == dynamic_cast<const CandidateCastType*>(tau.leadChargedHadrCand().get()));
2146  get(dnn::pfCand_chHad_pvAssociationQuality) =
2147  getValueLinear<int>(candFunc::getPvAssocationQuality(chH_cand), 0, 7, true);
2148  get(dnn::pfCand_chHad_fromPV) = getValueLinear<int>(candFunc::getFromPV(chH_cand), 0, 3, true);
2149  get(dnn::pfCand_chHad_puppiWeight) = getValue(candFunc::getPuppiWeight(chH_cand));
2150  get(dnn::pfCand_chHad_puppiWeightNoLep) = getValue(candFunc::getPuppiWeightNoLep(chH_cand));
2151  get(dnn::pfCand_chHad_charge) = getValue(chH_cand.charge());
2152  get(dnn::pfCand_chHad_lostInnerHits) = getValue<int>(candFunc::getLostInnerHits(chH_cand, default_value));
2153  get(dnn::pfCand_chHad_numberOfPixelHits) =
2154  getValueLinear(candFunc::getNumberOfPixelHits(chH_cand, default_value), 0, 12, true);
2155  get(dnn::pfCand_chHad_vertex_dx) =
2156  getValueNorm(pfCands.at(index_chH).vertex().x() - pv.position().x(), 0.0005f, 1.735f);
2157  get(dnn::pfCand_chHad_vertex_dy) =
2158  getValueNorm(pfCands.at(index_chH).vertex().y() - pv.position().y(), -0.0008f, 1.752f);
2159  get(dnn::pfCand_chHad_vertex_dz) =
2160  getValueNorm(pfCands.at(index_chH).vertex().z() - pv.position().z(), -0.0201f, 8.333f);
2161  get(dnn::pfCand_chHad_vertex_dx_tauFL) = getValueNorm(
2162  pfCands.at(index_chH).vertex().x() - pv.position().x() - tau_funcs.getFlightLength(tau, tau_index).x(),
2163  -0.0014f,
2164  1.93f);
2165  get(dnn::pfCand_chHad_vertex_dy_tauFL) = getValueNorm(
2166  pfCands.at(index_chH).vertex().y() - pv.position().y() - tau_funcs.getFlightLength(tau, tau_index).y(),
2167  0.0022f,
2168  1.948f);
2169  get(dnn::pfCand_chHad_vertex_dz_tauFL) = getValueNorm(
2170  pfCands.at(index_chH).vertex().z() - pv.position().z() - tau_funcs.getFlightLength(tau, tau_index).z(),
2171  -0.0138f,
2172  8.622f);
2173 
2174  const bool hasTrackDetails = candFunc::getHasTrackDetails(chH_cand);
2175  if (hasTrackDetails) {
2176  get(dnn::pfCand_chHad_hasTrackDetails) = hasTrackDetails;
2177  get(dnn::pfCand_chHad_dxy) = getValueNorm(candFunc::getTauDxy(chH_cand, default_value), -0.012f, 2.386f);
2178  get(dnn::pfCand_chHad_dxy_sig) =
2179  getValueNorm(std::abs(candFunc::getTauDxy(chH_cand, default_value)) / chH_cand.dxyError(), 6.417f, 36.28f);
2180  get(dnn::pfCand_chHad_dz) = getValueNorm(candFunc::getTauDz(chH_cand, default_value), -0.0246f, 7.618f);
2181  get(dnn::pfCand_chHad_dz_sig) = getValueNorm(
2182  std::abs(candFunc::getTauDz(chH_cand, default_value)) / candFunc::getTauDzError(chH_cand, default_value),
2183  301.3f,
2184  491.1f);
2185  get(dnn::pfCand_chHad_track_chi2_ndof) =
2186  candFunc::getPseudoTrack(chH_cand).ndof() > 0
2187  ? getValueNorm(candFunc::getPseudoTrack(chH_cand).chi2() / candFunc::getPseudoTrack(chH_cand).ndof(),
2188  0.7876f,
2189  3.694f)
2190  : 0;
2191  get(dnn::pfCand_chHad_track_ndof) =
2192  candFunc::getPseudoTrack(chH_cand).ndof() > 0
2193  ? getValueNorm(candFunc::getPseudoTrack(chH_cand).ndof(), 13.92f, 6.581f)
2194  : 0;
2195  }
2196  float hcal_fraction = candFunc::getHCalFraction(chH_cand);
2197  get(dnn::pfCand_chHad_hcalFraction) = getValue(hcal_fraction);
2198  get(dnn::pfCand_chHad_rawCaloFraction) = getValueLinear(candFunc::getRawCaloFraction(chH_cand), 0.f, 2.6f, true);
2199  }
2200  if (valid_nH) {
2201  size_t index_nH = cell_map.at(CellObjectType::PfCand_neutralHadron);
2202  const auto& nH_cand = dynamic_cast<const CandidateCastType&>(pfCands.at(index_nH));
2203 
2204  get(dnn::pfCand_nHad_valid) = valid_nH;
2205  get(dnn::pfCand_nHad_rel_pt) = getValueNorm(pfCands.at(index_nH).polarP4().pt() / tau.polarP4().pt(),
2206  is_inner ? 0.3163f : 0.0502f,
2207  is_inner ? 0.2769f : 0.4266f);
2208  get(dnn::pfCand_nHad_deta) = getValueLinear(pfCands.at(index_nH).polarP4().eta() - tau.polarP4().eta(),
2209  is_inner ? -0.1f : -0.5f,
2210  is_inner ? 0.1f : 0.5f,
2211  false);
2212  get(dnn::pfCand_nHad_dphi) = getValueLinear(
2213  dPhi(tau.polarP4(), pfCands.at(index_nH).polarP4()), is_inner ? -0.1f : -0.5f, is_inner ? 0.1f : 0.5f, false);
2214  get(dnn::pfCand_nHad_puppiWeight) = getValue(candFunc::getPuppiWeight(nH_cand));
2215  get(dnn::pfCand_nHad_puppiWeightNoLep) = getValue(candFunc::getPuppiWeightNoLep(nH_cand));
2216  float hcal_fraction = candFunc::getHCalFraction(nH_cand);
2217  get(dnn::pfCand_nHad_hcalFraction) = getValue(hcal_fraction);
2218  }
2219  checkInputs(inputs, is_inner ? "hadron_inner_block" : "hadron_outer_block", dnn::NumberOfInputs);
2220  }
2221 
2222  template <typename dnn, typename CandidateCastType, typename TauCastType>
2223  tensorflow::Tensor createInputsV1(const TauCastType& tau,
2224  const size_t tau_index,
2225  const edm::RefToBase<reco::BaseTau> tau_ref,
2226  const std::vector<pat::Electron>* electrons,
2227  const std::vector<pat::Muon>* muons,
2228  TauFunc tau_funcs) const {
2229  static constexpr bool check_all_set = false;
2230  static constexpr float default_value_for_set_check = -42;
2231 
2232  tensorflow::Tensor inputs(tensorflow::DT_FLOAT, {1, dnn_inputs_2017v1::NumberOfInputs});
2233  const auto& get = [&](int var_index) -> float& { return inputs.matrix<float>()(0, var_index); };
2234  auto leadChargedHadrCand = dynamic_cast<const CandidateCastType*>(tau.leadChargedHadrCand().get());
2235 
2236  if (check_all_set) {
2237  for (int var_index = 0; var_index < dnn::NumberOfInputs; ++var_index) {
2238  get(var_index) = default_value_for_set_check;
2239  }
2240  }
2241 
2242  get(dnn::pt) = tau.p4().pt();
2243  get(dnn::eta) = tau.p4().eta();
2244  get(dnn::mass) = tau.p4().mass();
2245  get(dnn::decayMode) = tau.decayMode();
2246  get(dnn::chargedIsoPtSum) = tau_funcs.getChargedIsoPtSum(tau, tau_ref);
2247  get(dnn::neutralIsoPtSum) = tau_funcs.getNeutralIsoPtSum(tau, tau_ref);
2248  get(dnn::neutralIsoPtSumWeight) = tau_funcs.getNeutralIsoPtSumWeight(tau, tau_ref);
2249  get(dnn::photonPtSumOutsideSignalCone) = tau_funcs.getPhotonPtSumOutsideSignalCone(tau, tau_ref);
2250  get(dnn::puCorrPtSum) = tau_funcs.getPuCorrPtSum(tau, tau_ref);
2251  get(dnn::dxy) = tau_funcs.getdxy(tau, tau_index);
2252  get(dnn::dxy_sig) = tau_funcs.getdxySig(tau, tau_index);
2253  get(dnn::dz) = leadChargedHadrCand ? candFunc::getTauDz(*leadChargedHadrCand, default_value) : default_value;
2254  get(dnn::ip3d) = tau_funcs.getip3d(tau, tau_index);
2255  get(dnn::ip3d_sig) = tau_funcs.getip3dSig(tau, tau_index);
2256  get(dnn::hasSecondaryVertex) = tau_funcs.getHasSecondaryVertex(tau, tau_index);
2257  get(dnn::flightLength_r) = tau_funcs.getFlightLength(tau, tau_index).R();
2258  get(dnn::flightLength_dEta) = dEta(tau_funcs.getFlightLength(tau, tau_index), tau.p4());
2259  get(dnn::flightLength_dPhi) = dPhi(tau_funcs.getFlightLength(tau, tau_index), tau.p4());
2260  get(dnn::flightLength_sig) = tau_funcs.getFlightLengthSig(tau, tau_index);
2261  get(dnn::leadChargedHadrCand_pt) = leadChargedHadrCand ? leadChargedHadrCand->p4().Pt() : default_value;
2262  get(dnn::leadChargedHadrCand_dEta) =
2263  leadChargedHadrCand ? dEta(leadChargedHadrCand->p4(), tau.p4()) : default_value;
2264  get(dnn::leadChargedHadrCand_dPhi) =
2265  leadChargedHadrCand ? dPhi(leadChargedHadrCand->p4(), tau.p4()) : default_value;
2266  get(dnn::leadChargedHadrCand_mass) = leadChargedHadrCand ? leadChargedHadrCand->p4().mass() : default_value;
2271  get(dnn::leadingTrackNormChi2) = tau_funcs.getLeadingTrackNormChi2(tau);
2272  get(dnn::e_ratio) = reco::tau::eratio(tau);
2273  get(dnn::gj_angle_diff) = calculateGottfriedJacksonAngleDifference(tau, tau_index, tau_funcs);
2274  get(dnn::n_photons) = reco::tau::n_photons_total(tau);
2275  get(dnn::emFraction) = tau_funcs.getEmFraction(tau);
2276  get(dnn::has_gsf_track) = leadChargedHadrCand && std::abs(leadChargedHadrCand->pdgId()) == 11;
2277  get(dnn::inside_ecal_crack) = isInEcalCrack(tau.p4().Eta());
2278  auto gsf_ele = findMatchedElectron(tau, electrons, 0.3);
2279  get(dnn::gsf_ele_matched) = gsf_ele != nullptr;
2280  get(dnn::gsf_ele_pt) = gsf_ele != nullptr ? gsf_ele->p4().Pt() : default_value;
2281  get(dnn::gsf_ele_dEta) = gsf_ele != nullptr ? dEta(gsf_ele->p4(), tau.p4()) : default_value;
2282  get(dnn::gsf_ele_dPhi) = gsf_ele != nullptr ? dPhi(gsf_ele->p4(), tau.p4()) : default_value;
2283  get(dnn::gsf_ele_mass) = gsf_ele != nullptr ? gsf_ele->p4().mass() : default_value;
2284  calculateElectronClusterVars(gsf_ele, get(dnn::gsf_ele_Ee), get(dnn::gsf_ele_Egamma));
2285  get(dnn::gsf_ele_Pin) = gsf_ele != nullptr ? gsf_ele->trackMomentumAtVtx().R() : default_value;
2286  get(dnn::gsf_ele_Pout) = gsf_ele != nullptr ? gsf_ele->trackMomentumOut().R() : default_value;
2287  get(dnn::gsf_ele_EtotOverPin) = get(dnn::gsf_ele_Pin) > 0
2288  ? (get(dnn::gsf_ele_Ee) + get(dnn::gsf_ele_Egamma)) / get(dnn::gsf_ele_Pin)
2289  : default_value;
2290  get(dnn::gsf_ele_Eecal) = gsf_ele != nullptr ? gsf_ele->ecalEnergy() : default_value;
2291  get(dnn::gsf_ele_dEta_SeedClusterTrackAtCalo) =
2292  gsf_ele != nullptr ? gsf_ele->deltaEtaSeedClusterTrackAtCalo() : default_value;
2293  get(dnn::gsf_ele_dPhi_SeedClusterTrackAtCalo) =
2294  gsf_ele != nullptr ? gsf_ele->deltaPhiSeedClusterTrackAtCalo() : default_value;
2295  get(dnn::gsf_ele_mvaIn_sigmaEtaEta) = gsf_ele != nullptr ? gsf_ele->mvaInput().sigmaEtaEta : default_value;
2296  get(dnn::gsf_ele_mvaIn_hadEnergy) = gsf_ele != nullptr ? gsf_ele->mvaInput().hadEnergy : default_value;
2297  get(dnn::gsf_ele_mvaIn_deltaEta) = gsf_ele != nullptr ? gsf_ele->mvaInput().deltaEta : default_value;
2298 
2299  get(dnn::gsf_ele_Chi2NormGSF) = default_value;
2300  get(dnn::gsf_ele_GSFNumHits) = default_value;
2301  get(dnn::gsf_ele_GSFTrackResol) = default_value;
2302  get(dnn::gsf_ele_GSFTracklnPt) = default_value;
2303  if (gsf_ele != nullptr && gsf_ele->gsfTrack().isNonnull()) {
2304  get(dnn::gsf_ele_Chi2NormGSF) = gsf_ele->gsfTrack()->normalizedChi2();
2305  get(dnn::gsf_ele_GSFNumHits) = gsf_ele->gsfTrack()->numberOfValidHits();
2306  if (gsf_ele->gsfTrack()->pt() > 0) {
2307  get(dnn::gsf_ele_GSFTrackResol) = gsf_ele->gsfTrack()->ptError() / gsf_ele->gsfTrack()->pt();
2308  get(dnn::gsf_ele_GSFTracklnPt) = std::log10(gsf_ele->gsfTrack()->pt());
2309  }
2310  }
2311 
2312  get(dnn::gsf_ele_Chi2NormKF) = default_value;
2313  get(dnn::gsf_ele_KFNumHits) = default_value;
2314  if (gsf_ele != nullptr && gsf_ele->closestCtfTrackRef().isNonnull()) {
2315  get(dnn::gsf_ele_Chi2NormKF) = gsf_ele->closestCtfTrackRef()->normalizedChi2();
2316  get(dnn::gsf_ele_KFNumHits) = gsf_ele->closestCtfTrackRef()->numberOfValidHits();
2317  }
2318  get(dnn::leadChargedCand_etaAtEcalEntrance) = tau_funcs.getEtaAtEcalEntrance(tau);
2319  get(dnn::leadChargedCand_pt) = leadChargedHadrCand->pt();
2320 
2321  get(dnn::leadChargedHadrCand_HoP) = default_value;
2322  get(dnn::leadChargedHadrCand_EoP) = default_value;
2323  if (leadChargedHadrCand->pt() > 0) {
2324  get(dnn::leadChargedHadrCand_HoP) = tau_funcs.getEcalEnergyLeadingChargedHadr(tau) / leadChargedHadrCand->pt();
2325  get(dnn::leadChargedHadrCand_EoP) = tau_funcs.getHcalEnergyLeadingChargedHadr(tau) / leadChargedHadrCand->pt();
2326  }
2327 
2328  MuonHitMatchV1 muon_hit_match;
2329  if (tau.leadPFChargedHadrCand().isNonnull() && tau.leadPFChargedHadrCand()->muonRef().isNonnull())
2330  muon_hit_match.addMatchedMuon(*tau.leadPFChargedHadrCand()->muonRef(), tau);
2331 
2332  auto matched_muons = muon_hit_match.findMatchedMuons(tau, muons, 0.3, 5);
2333  for (auto muon : matched_muons)
2334  muon_hit_match.addMatchedMuon(*muon, tau);
2335  muon_hit_match.fillTensor<dnn>(get, tau, default_value);
2336 
2337  LorentzVectorXYZ signalChargedHadrCands_sumIn, signalChargedHadrCands_sumOut;
2339  tau.signalChargedHadrCands(),
2340  signalChargedHadrCands_sumIn,
2341  signalChargedHadrCands_sumOut,
2342  get(dnn::signalChargedHadrCands_sum_innerSigCone_pt),
2343  get(dnn::signalChargedHadrCands_sum_innerSigCone_dEta),
2344  get(dnn::signalChargedHadrCands_sum_innerSigCone_dPhi),
2345  get(dnn::signalChargedHadrCands_sum_innerSigCone_mass),
2346  get(dnn::signalChargedHadrCands_sum_outerSigCone_pt),
2347  get(dnn::signalChargedHadrCands_sum_outerSigCone_dEta),
2348  get(dnn::signalChargedHadrCands_sum_outerSigCone_dPhi),
2349  get(dnn::signalChargedHadrCands_sum_outerSigCone_mass),
2350  get(dnn::signalChargedHadrCands_nTotal_innerSigCone),
2351  get(dnn::signalChargedHadrCands_nTotal_outerSigCone));
2352 
2353  LorentzVectorXYZ signalNeutrHadrCands_sumIn, signalNeutrHadrCands_sumOut;
2355  tau.signalNeutrHadrCands(),
2356  signalNeutrHadrCands_sumIn,
2357  signalNeutrHadrCands_sumOut,
2358  get(dnn::signalNeutrHadrCands_sum_innerSigCone_pt),
2359  get(dnn::signalNeutrHadrCands_sum_innerSigCone_dEta),
2360  get(dnn::signalNeutrHadrCands_sum_innerSigCone_dPhi),
2361  get(dnn::signalNeutrHadrCands_sum_innerSigCone_mass),
2362  get(dnn::signalNeutrHadrCands_sum_outerSigCone_pt),
2363  get(dnn::signalNeutrHadrCands_sum_outerSigCone_dEta),
2364  get(dnn::signalNeutrHadrCands_sum_outerSigCone_dPhi),
2365  get(dnn::signalNeutrHadrCands_sum_outerSigCone_mass),
2366  get(dnn::signalNeutrHadrCands_nTotal_innerSigCone),
2367  get(dnn::signalNeutrHadrCands_nTotal_outerSigCone));
2368 
2369  LorentzVectorXYZ signalGammaCands_sumIn, signalGammaCands_sumOut;
2371  tau.signalGammaCands(),
2372  signalGammaCands_sumIn,
2373  signalGammaCands_sumOut,
2374  get(dnn::signalGammaCands_sum_innerSigCone_pt),
2375  get(dnn::signalGammaCands_sum_innerSigCone_dEta),
2376  get(dnn::signalGammaCands_sum_innerSigCone_dPhi),
2377  get(dnn::signalGammaCands_sum_innerSigCone_mass),
2378  get(dnn::signalGammaCands_sum_outerSigCone_pt),
2379  get(dnn::signalGammaCands_sum_outerSigCone_dEta),
2380  get(dnn::signalGammaCands_sum_outerSigCone_dPhi),
2381  get(dnn::signalGammaCands_sum_outerSigCone_mass),
2382  get(dnn::signalGammaCands_nTotal_innerSigCone),
2383  get(dnn::signalGammaCands_nTotal_outerSigCone));
2384 
2385  LorentzVectorXYZ isolationChargedHadrCands_sum;
2387  tau.isolationChargedHadrCands(),
2388  isolationChargedHadrCands_sum,
2389  get(dnn::isolationChargedHadrCands_sum_pt),
2390  get(dnn::isolationChargedHadrCands_sum_dEta),
2391  get(dnn::isolationChargedHadrCands_sum_dPhi),
2392  get(dnn::isolationChargedHadrCands_sum_mass),
2393  get(dnn::isolationChargedHadrCands_nTotal));
2394 
2395  LorentzVectorXYZ isolationNeutrHadrCands_sum;
2397  tau.isolationNeutrHadrCands(),
2398  isolationNeutrHadrCands_sum,
2399  get(dnn::isolationNeutrHadrCands_sum_pt),
2400  get(dnn::isolationNeutrHadrCands_sum_dEta),
2401  get(dnn::isolationNeutrHadrCands_sum_dPhi),
2402  get(dnn::isolationNeutrHadrCands_sum_mass),
2403  get(dnn::isolationNeutrHadrCands_nTotal));
2404 
2405  LorentzVectorXYZ isolationGammaCands_sum;
2407  tau.isolationGammaCands(),
2408  isolationGammaCands_sum,
2409  get(dnn::isolationGammaCands_sum_pt),
2410  get(dnn::isolationGammaCands_sum_dEta),
2411  get(dnn::isolationGammaCands_sum_dPhi),
2412  get(dnn::isolationGammaCands_sum_mass),
2413  get(dnn::isolationGammaCands_nTotal));
2414 
2415  get(dnn::tau_visMass_innerSigCone) = (signalGammaCands_sumIn + signalChargedHadrCands_sumIn).mass();
2416 
2417  if (check_all_set) {
2418  for (int var_index = 0; var_index < dnn::NumberOfInputs; ++var_index) {
2419  if (get(var_index) == default_value_for_set_check)
2420  throw cms::Exception("DeepTauId: variable with index = ") << var_index << " is not set.";
2421  }
2422  }
2423 
2424  return inputs;
2425  }
2426 
2427  static void calculateElectronClusterVars(const pat::Electron* ele, float& elecEe, float& elecEgamma) {
2428  if (ele) {
2429  elecEe = elecEgamma = 0;
2430  auto superCluster = ele->superCluster();
2431  if (superCluster.isNonnull() && superCluster.isAvailable() && superCluster->clusters().isNonnull() &&
2432  superCluster->clusters().isAvailable()) {
2433  for (auto iter = superCluster->clustersBegin(); iter != superCluster->clustersEnd(); ++iter) {
2434  const double energy = (*iter)->energy();
2435  if (iter == superCluster->clustersBegin())
2436  elecEe += energy;
2437  else
2438  elecEgamma += energy;
2439  }
2440  }
2441  } else {
2442  elecEe = elecEgamma = default_value;
2443  }
2444  }
2445 
2446  template <typename CandidateCollection, typename TauCastType>
2447  static void processSignalPFComponents(const TauCastType& tau,
2449  LorentzVectorXYZ& p4_inner,
2450  LorentzVectorXYZ& p4_outer,
2451  float& pt_inner,
2452  float& dEta_inner,
2453  float& dPhi_inner,
2454  float& m_inner,
2455  float& pt_outer,
2456  float& dEta_outer,
2457  float& dPhi_outer,
2458  float& m_outer,
2459  float& n_inner,
2460  float& n_outer) {
2461  p4_inner = LorentzVectorXYZ(0, 0, 0, 0);
2462  p4_outer = LorentzVectorXYZ(0, 0, 0, 0);
2463  n_inner = 0;
2464  n_outer = 0;
2465 
2466  const double innerSigCone_radius = getInnerSignalConeRadius(tau.pt());
2467  for (const auto& cand : candidates) {
2468  const double dR = reco::deltaR(cand->p4(), tau.leadChargedHadrCand()->p4());
2469  const bool isInside_innerSigCone = dR < innerSigCone_radius;
2470  if (isInside_innerSigCone) {
2471  p4_inner += cand->p4();
2472  ++n_inner;
2473  } else {
2474  p4_outer += cand->p4();
2475  ++n_outer;
2476  }
2477  }
2478 
2479  pt_inner = n_inner != 0 ? p4_inner.Pt() : default_value;
2480  dEta_inner = n_inner != 0 ? dEta(p4_inner, tau.p4()) : default_value;
2481  dPhi_inner = n_inner != 0 ? dPhi(p4_inner, tau.p4()) : default_value;
2482  m_inner = n_inner != 0 ? p4_inner.mass() : default_value;
2483 
2484  pt_outer = n_outer != 0 ? p4_outer.Pt() : default_value;
2485  dEta_outer = n_outer != 0 ? dEta(p4_outer, tau.p4()) : default_value;
2486  dPhi_outer = n_outer != 0 ? dPhi(p4_outer, tau.p4()) : default_value;
2487  m_outer = n_outer != 0 ? p4_outer.mass() : default_value;
2488  }
2489 
2490  template <typename CandidateCollection, typename TauCastType>
2491  static void processIsolationPFComponents(const TauCastType& tau,
2494  float& pt,
2495  float& d_eta,
2496  float& d_phi,
2497  float& m,
2498  float& n) {
2499  p4 = LorentzVectorXYZ(0, 0, 0, 0);
2500  n = 0;
2501 
2502  for (const auto& cand : candidates) {
2503  p4 += cand->p4();
2504  ++n;
2505  }
2506 
2507  pt = n != 0 ? p4.Pt() : default_value;
2508  d_eta = n != 0 ? dEta(p4, tau.p4()) : default_value;
2509  d_phi = n != 0 ? dPhi(p4, tau.p4()) : default_value;
2510  m = n != 0 ? p4.mass() : default_value;
2511  }
2512 
2513  static double getInnerSignalConeRadius(double pt) {
2514  static constexpr double min_pt = 30., min_radius = 0.05, cone_opening_coef = 3.;
2515  // This is equivalent of the original formula (std::max(std::min(0.1, 3.0/pt), 0.05)
2516  return std::max(cone_opening_coef / std::max(pt, min_pt), min_radius);
2517  }
2518 
2519  // Copied from https://github.com/cms-sw/cmssw/blob/CMSSW_9_4_X/RecoTauTag/RecoTau/plugins/PATTauDiscriminationByMVAIsolationRun2.cc#L218
2520  template <typename TauCastType>
2521  static bool calculateGottfriedJacksonAngleDifference(const TauCastType& tau,
2522  const size_t tau_index,
2523  double& gj_diff,
2524  TauFunc tau_funcs) {
2525  if (tau_funcs.getHasSecondaryVertex(tau, tau_index)) {
2526  static constexpr double mTau = 1.77682;
2527  const double mAOne = tau.p4().M();
2528  const double pAOneMag = tau.p();
2529  const double argumentThetaGJmax = (std::pow(mTau, 2) - std::pow(mAOne, 2)) / (2 * mTau * pAOneMag);
2530  const double argumentThetaGJmeasured = tau.p4().Vect().Dot(tau_funcs.getFlightLength(tau, tau_index)) /
2531  (pAOneMag * tau_funcs.getFlightLength(tau, tau_index).R());
2532  if (std::abs(argumentThetaGJmax) <= 1. && std::abs(argumentThetaGJmeasured) <= 1.) {
2533  double thetaGJmax = std::asin(argumentThetaGJmax);
2534  double thetaGJmeasured = std::acos(argumentThetaGJmeasured);
2535  gj_diff = thetaGJmeasured - thetaGJmax;
2536  return true;
2537  }
2538  }
2539  return false;
2540  }
2541 
2542  template <typename TauCastType>
2543  static float calculateGottfriedJacksonAngleDifference(const TauCastType& tau,
2544  const size_t tau_index,
2545  TauFunc tau_funcs) {
2546  double gj_diff;
2547  if (calculateGottfriedJacksonAngleDifference(tau, tau_index, gj_diff, tau_funcs))
2548  return static_cast<float>(gj_diff);
2549  return default_value;
2550  }
2551 
2552  static bool isInEcalCrack(double eta) {
2553  const double abs_eta = std::abs(eta);
2554  return abs_eta > 1.46 && abs_eta < 1.558;
2555  }
2556 
2557  template <typename TauCastType>
2558  static const pat::Electron* findMatchedElectron(const TauCastType& tau,
2559  const std::vector<pat::Electron>* electrons,
2560  double deltaR) {
2561  const double dR2 = deltaR * deltaR;
2562  const pat::Electron* matched_ele = nullptr;
2563  for (const auto& ele : *electrons) {
2564  if (reco::deltaR2(tau.p4(), ele.p4()) < dR2 && (!matched_ele || matched_ele->pt() < ele.pt())) {
2565  matched_ele = &ele;
2566  }
2567  }
2568  return matched_ele;
2569  }
2570 
2571 private:
2580  const unsigned version_;
2581  const int debug_level;
2582  const bool disable_dxy_pca_;
2583  std::unique_ptr<tensorflow::Tensor> tauBlockTensor_;
2584  std::array<std::unique_ptr<tensorflow::Tensor>, 2> eGammaTensor_, muonTensor_, hadronsTensor_, convTensor_,
2586 
2587  //boolean to check if discriminator indices are already mapped
2588  bool discrIndicesMapped_ = false;
2589  std::map<BasicDiscriminator, size_t> basicDiscrIndexMap_;
2590  std::map<BasicDiscriminator, size_t> basicDiscrdR03IndexMap_;
2591 };
2592 
reco::tau::pt_weighted_deta_strip
float pt_weighted_deta_strip(const reco::PFTau &tau, int dm)
Definition: PFRecoTauClusterVariables.h:36
deep_tau::DeepTauBase::cache_
const DeepTauCache * cache_
Definition: DeepTauBase.h:135
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
deep_tau::DeepTauBase::patPrediscriminants_
std::vector< TauDiscInfo< pat::PATTauDiscriminator > > patPrediscriminants_
Definition: DeepTauBase.h:112
alignBH_cfg.fixed
fixed
Definition: alignBH_cfg.py:54
MuonSubdetId::CSC
static constexpr int CSC
Definition: MuonSubdetId.h:12
DeepTauId::rho_token_
edm::EDGetTokenT< double > rho_token_
Definition: DeepTauId.cc:2574
dnn_inputs_2017_v2
Definition: DeepTauId.cc:154
DeepTauId::calculateElectronClusterVars
static void calculateElectronClusterVars(const pat::Electron *ele, float &elecEe, float &elecEgamma)
Definition: DeepTauId.cc:2427
DeepTauBase.h
DeepTauId::DeepTauId
DeepTauId(const edm::ParameterSet &cfg, const deep_tau::DeepTauCache *cache)
Definition: DeepTauId.cc:1152
electrons_cff.bool
bool
Definition: electrons_cff.py:393
mps_fire.i
i
Definition: mps_fire.py:428
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
DeepTauId::getInnerSignalConeRadius
static double getInnerSignalConeRadius(double pt)
Definition: DeepTauId.cc:2513
input
static const std::string input
Definition: EdmProvDump.cc:48
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
deep_tau::DeepTauCache::getSession
tensorflow::Session & getSession(const std::string &name="") const
Definition: DeepTauBase.h:57
SiStripPI::mean
Definition: SiStripPayloadInspectorHelper.h:169
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
edm::View::const_reference
T const & const_reference
Definition: View.h:82
deep_tau::DeepTauBase::pfcandToken_
edm::EDGetTokenT< CandidateCollection > pfcandToken_
Definition: DeepTauBase.h:130
runTauDisplay.tau_eta
tau_eta
Definition: runTauDisplay.py:126
reco::PFTauTransverseImpactParameterRef
edm::Ref< PFTauTransverseImpactParameterCollection > PFTauTransverseImpactParameterRef
presistent reference to a PFTauTransverseImpactParameter
Definition: PFTauTransverseImpactParameterFwd.h:13
dnn_inputs_2017_v2::MuonBlockInputs
Definition: DeepTauId.cc:303
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
metsig::tau
Definition: SignAlgoResolutions.h:49
muon
Definition: MuonCocktails.h:17
edm::isNotFinite
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
DeepTauId::isInEcalCrack
static bool isInEcalCrack(double eta)
Definition: DeepTauId.cc:2552
DeepTauId::pi
static constexpr float pi
Definition: DeepTauId.cc:1214
DeepTauId::getValue
static float getValue(T value)
Definition: DeepTauId.cc:1217
DeepTauId::setCellConvFeatures
void setCellConvFeatures(tensorflow::Tensor &convTensor, const tensorflow::Tensor &features, unsigned batch_idx, int eta_index, int phi_index)
Definition: DeepTauId.cc:1593
DeepTauId::version_
const unsigned version_
Definition: DeepTauId.cc:2580
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
min
T min(T a, T b)
Definition: MathUtil.h:58
reco::deltaPhi
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
postprocess-scan-build.features
features
Definition: postprocess-scan-build.py:8
edm::EDGetTokenT
Definition: EDGetToken.h:33
Tau3MuMonitor_cff.taus
taus
Definition: Tau3MuMonitor_cff.py:7
Electron
Definition: Electron.py:1
relativeConstraints.station
station
Definition: relativeConstraints.py:67
edm
HLT enums.
Definition: AlignableModifier.h:19
reco::tau::eratio
float eratio(const reco::PFTau &tau)
return ratio of energy in ECAL over sum of energy in ECAL and HCAL
Definition: PFRecoTauClusterVariables.cc:78
PFTauTransverseImpactParameterAssociation.h
deep_tau::DeepTauBase::BasicDiscriminator
BasicDiscriminator
Definition: DeepTauBase.h:115
fireworks::subdets
static const std::string subdets[7]
Definition: TrackUtils.cc:60
pat::Tau
Analysis-level tau class.
Definition: Tau.h:53
deep_tau::DeepTauBase::OutputCollection
std::map< std::string, Output > OutputCollection
Definition: DeepTauBase.h:91
gather_cfg.cout
cout
Definition: gather_cfg.py:144
DeepTauId::matchDiscriminatorIndices
const std::map< BasicDiscriminator, size_t > matchDiscriminatorIndices(edm::Event &event, edm::EDGetTokenT< reco::TauDiscriminatorContainer > discriminatorContainerToken, std::vector< BasicDiscriminator > requiredDiscr)
Definition: DeepTauId.cc:1080
objects
Definition: __init__.py:1
ZElectronSkim_cff.rho
rho
Definition: ZElectronSkim_cff.py:38
DeepTauId::hadronsTensor_
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > hadronsTensor_
Definition: DeepTauId.cc:2584
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89353
reco::PFTauRefProd
edm::RefProd< PFTauCollection > PFTauRefProd
references to PFTau collection
Definition: PFTauFwd.h:15
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
DeepTauId::debug_level
const int debug_level
Definition: DeepTauId.cc:2581
deep_tau::DeepTauBase::requiredBasicDiscriminatorsdR03_
static const std::vector< BasicDiscriminator > requiredBasicDiscriminatorsdR03_
Definition: DeepTauBase.h:139
DeepTauId::getValueNorm
static float getValueNorm(T value, float mean, float sigma, float n_sigmas_max=5)
Definition: DeepTauId.cc:1232
getRunAppsInfo.grid
grid
Definition: getRunAppsInfo.py:92
deep_tau::DeepTauBase::vtxToken_
edm::EDGetTokenT< reco::VertexCollection > vtxToken_
Definition: DeepTauBase.h:131
DeepTauId::initializeGlobalCache
static std::unique_ptr< deep_tau::DeepTauCache > initializeGlobalCache(const edm::ParameterSet &cfg)
Definition: DeepTauId.cc:1207
deep_tau
Definition: DeepTauBase.h:36
reco::PFTau
Definition: PFTau.h:36
DeepTauId::createEgammaBlockInputs
void createEgammaBlockInputs(unsigned idx, const TauCastType &tau, const size_t tau_index, const edm::RefToBase< reco::BaseTau > tau_ref, const reco::Vertex &pv, double rho, const std::vector< pat::Electron > *electrons, const edm::View< reco::Candidate > &pfCands, const Cell &cell_map, TauFunc tau_funcs, bool is_inner)
Definition: DeepTauId.cc:1709
DeepTauId::muons_token_
edm::EDGetTokenT< std::vector< pat::Muon > > muons_token_
Definition: DeepTauId.cc:2573
DDAxes::x
deep_tau::DeepTauBase::LorentzVectorXYZ
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > LorentzVectorXYZ
Definition: DeepTauBase.h:75
reco::LeafCandidate::pt
double pt() const final
transverse momentum
Definition: LeafCandidate.h:146
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
pat::Muon
Analysis-level muon class.
Definition: Muon.h:51
hltPixelTracks_cff.chi2
chi2
Definition: hltPixelTracks_cff.py:25
HLT_FULL_cff.dPhi
dPhi
Definition: HLT_FULL_cff.py:13768
DeepTauId::disable_dxy_pca_
const bool disable_dxy_pca_
Definition: DeepTauId.cc:2582
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
edm::Handle< TauCollection >
edm::ParameterSetDescription::addOptional
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:105
DeepTauId::zeroOutputTensor_
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > zeroOutputTensor_
Definition: DeepTauId.cc:2584
DeepTauId::basicDiscrIndexMap_
std::map< BasicDiscriminator, size_t > basicDiscrIndexMap_
Definition: DeepTauId.cc:2589
deep_tau::NumberOfOutputs
constexpr int NumberOfOutputs
Definition: DeepTauId.cc:14
cosmictrackSelector_cfi.min_pt
min_pt
Definition: cosmictrackSelector_cfi.py:18
GetRecoTauVFromDQM_MC_cff.Output
Output
Definition: GetRecoTauVFromDQM_MC_cff.py:12
Muon
Definition: Muon.py:1
reco::Muon
Definition: Muon.h:27
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
DeepTauId::default_value
static constexpr float default_value
Definition: DeepTauId.cc:1068
ndof
Definition: HIMultiTrackSelector.h:49
deep_tau::DeepTauBase
Definition: DeepTauBase.h:66
deep_tau::DeepTauBase::DeepTauBase
DeepTauBase(const edm::ParameterSet &cfg, const OutputCollection &outputs, const DeepTauCache *cache)
Definition: DeepTauBase.cc:84
MakerMacros.h
reco::tau::pt_weighted_dphi_strip
float pt_weighted_dphi_strip(const reco::PFTau &tau, int dm)
Definition: PFRecoTauClusterVariables.h:44
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
spr::deltaEta
static const double deltaEta
Definition: CaloConstants.h:8
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
DeepTauId::processIsolationPFComponents
static void processIsolationPFComponents(const TauCastType &tau, const CandidateCollection &candidates, LorentzVectorXYZ &p4, float &pt, float &d_eta, float &d_phi, float &m, float &n)
Definition: DeepTauId.cc:2491
reco::BaseTau
Definition: BaseTau.h:18
SiPixelRawToDigiRegional_cfi.deltaPhi
deltaPhi
Definition: SiPixelRawToDigiRegional_cfi.py:9
deep_tau::DeepTauBase::requiredBasicDiscriminators_
static const std::vector< BasicDiscriminator > requiredBasicDiscriminators_
Definition: DeepTauBase.h:138
reco::tau::countMatches
void countMatches(const reco::Muon &muon, std::vector< int > &numMatchesDT, std::vector< int > &numMatchesCSC, std::vector< int > &numMatchesRPC)
Definition: RecoTauMuonTools.cc:46
vars
vars
Definition: DeepTauId.cc:159
HLT_FULL_cff.muon
muon
Definition: HLT_FULL_cff.py:11776
PVValHelper::eta
Definition: PVValidationHelpers.h:69
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
mps_fire.end
end
Definition: mps_fire.py:242
DeepTauId::basicTauDiscriminators_inputToken_
edm::EDGetTokenT< reco::TauDiscriminatorContainer > basicTauDiscriminators_inputToken_
Definition: DeepTauId.cc:2575
dnn_inputs_2017_v2::HadronBlockInputs
Definition: DeepTauId.cc:373
deep_tau::DeepTauBase::is_online_
const bool is_online_
Definition: DeepTauBase.h:133
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
trackingPlots.other
other
Definition: trackingPlots.py:1467
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
DeepTauId::getValueLinear
static float getValueLinear(T value, float min_value, float max_value, bool positive)
Definition: DeepTauId.cc:1222
MuonSubdetId::DT
static constexpr int DT
Definition: MuonSubdetId.h:11
DeepTauId::findMatchedElectron
static const pat::Electron * findMatchedElectron(const TauCastType &tau, const std::vector< pat::Electron > *electrons, double deltaR)
Definition: DeepTauId.cc:2558
DeepTauId::createHadronsBlockInputs
void createHadronsBlockInputs(unsigned idx, const TauCastType &tau, const size_t tau_index, const edm::RefToBase< reco::BaseTau > tau_ref, const reco::Vertex &pv, double rho, const edm::View< reco::Candidate > &pfCands, const Cell &cell_map, TauFunc tau_funcs, bool is_inner)
Definition: DeepTauId.cc:2103
dqmdumpme.k
k
Definition: dqmdumpme.py:60
hcaldqm::quantity::min_value
const std::map< ValueQuantityType, double > min_value
Definition: ValueQuantity.h:130
CommPDSkim_cfg.maxDeltaEta
maxDeltaEta
Definition: CommPDSkim_cfg.py:75
DeepTauId::convTensor_
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > convTensor_
Definition: DeepTauId.cc:2584
DeepTauId::calculateElectronClusterVarsV2
static bool calculateElectronClusterVarsV2(const pat::Electron &ele, float &cc_ele_energy, float &cc_gamma_energy, int &cc_n_gamma)
Definition: DeepTauId.cc:1240
taus_cff.decayMode
decayMode
Definition: taus_cff.py:58
utilities.cache
def cache(function)
Definition: utilities.py:3
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
PbPb_ZMuSkimMuonDPG_cff.deltaR
deltaR
Definition: PbPb_ZMuSkimMuonDPG_cff.py:63
runTauDisplay.tau_phi
tau_phi
Definition: runTauDisplay.py:127
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
DDAxes::rho
edm::AssociationVector::value
const CVal::value_type value(size_type i) const
Definition: AssociationVector.h:102
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
TrackingRecHit::bad
Definition: TrackingRecHit.h:49
DeepTauId::basicTauDiscriminatorsdR03_inputToken_
edm::EDGetTokenT< reco::TauDiscriminatorContainer > basicTauDiscriminatorsdR03_inputToken_
Definition: DeepTauId.cc:2576
edm::AssociationVector
Definition: AssociationVector.h:67
deep_tau::DeepTauBase::outputs_
OutputCollection outputs_
Definition: DeepTauBase.h:134
edm::View
Definition: CaloClusterFwd.h:14
edm::View::at
const_reference at(size_type pos) const
DeepTauId::calculateGottfriedJacksonAngleDifference
static bool calculateGottfriedJacksonAngleDifference(const TauCastType &tau, const size_t tau_index, double &gj_diff, TauFunc tau_funcs)
Definition: DeepTauId.cc:2521
DeepTauId::pfTauTransverseImpactParameters_token_
edm::EDGetTokenT< edm::AssociationVector< reco::PFTauRefProd, std::vector< reco::PFTauTransverseImpactParameterRef > > > pfTauTransverseImpactParameters_token_
Definition: DeepTauId.cc:2578
candFunc
Definition: DeepTauId.cc:589
DeepTauId::isAbove
static bool isAbove(double value, double min)
Definition: DeepTauId.cc:1238
DeepTauId::output_layer_
std::string output_layer_
Definition: DeepTauId.cc:2579
edm::ParameterSet
Definition: ParameterSet.h:47
Cell
Definition: LogEleMapdb.h:8
reco::tau::lead_track_chi2
float lead_track_chi2(const reco::PFTau &tau)
return chi2 of the leading track ==> deprecated? <==
Definition: PFRecoTauClusterVariables.cc:58
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
pat::PackedCandidate
Definition: PackedCandidate.h:22
reco::deltaR2
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
dnn_inputs_2017_v2::EgammaBlockInputs
Definition: DeepTauId.cc:211
deep_tau::DeepTauBase::stringFromDiscriminator_
static const std::map< BasicDiscriminator, std::string > stringFromDiscriminator_
Definition: DeepTauBase.h:137
DeepTauId
Definition: DeepTauId.cc:1066
match
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
reco::tau::n_photons_total
unsigned int n_photons_total(const reco::PFTau &tau)
return total number of pf photon candidates with pT>500 MeV, which are associated to signal
Definition: PFRecoTauClusterVariables.cc:157
cand
Definition: decayParser.h:32
electrons_cff.ip3d
ip3d
Definition: electrons_cff.py:384
runTauDisplay.tau_mass
tau_mass
Definition: runTauDisplay.py:128
createfilelist.int
int
Definition: createfilelist.py:10
MetAnalyzer.pv
def pv(vc)
Definition: MetAnalyzer.py:7
dumpRecoGeometry_cfg.Muon
Muon
Definition: dumpRecoGeometry_cfg.py:190
p4
double p4[4]
Definition: TauolaWrapper.h:92
value
Definition: value.py:1
pat::Muon::PV2D
Definition: Muon.h:237
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:49
PixelMapPlotter.inputs
inputs
Definition: PixelMapPlotter.py:490
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
DeepTauId::GetOutputs
static const OutputCollection & GetOutputs()
Definition: DeepTauId.cc:1070
DeepTauId::checkInputs
void checkInputs(const tensorflow::Tensor &inputs, const char *block_name, int n_inputs, int n_eta=1, int n_phi=1) const
Definition: DeepTauId.cc:1263
pat
Definition: HeavyIon.h:7
DeepTauId::globalEndJob
static void globalEndJob(const deep_tau::DeepTauCache *cache_)
Definition: DeepTauId.cc:1211
beam_dqm_sourceclient-live_cfg.minPt
minPt
Definition: beam_dqm_sourceclient-live_cfg.py:321
DeepTauId::eGammaTensor_
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > eGammaTensor_
Definition: DeepTauId.cc:2584
get
#define get
DeepTauId::tauBlockTensor_
std::unique_ptr< tensorflow::Tensor > tauBlockTensor_
Definition: DeepTauId.cc:2583
TrackingRecHit::valid
Definition: TrackingRecHit.h:46
reco::HitPattern::TRACK_HITS
Definition: HitPattern.h:155
looper.cfg
cfg
Definition: looper.py:297
reco::Candidate
Definition: Candidate.h:27
DeepTauId::createMuonBlockInputs
void createMuonBlockInputs(unsigned idx, const TauCastType &tau, const size_t tau_index, const edm::RefToBase< reco::BaseTau > tau_ref, const reco::Vertex &pv, double rho, const std::vector< pat::Muon > *muons, const edm::View< reco::Candidate > &pfCands, const Cell &cell_map, TauFunc tau_funcs, bool is_inner)
Definition: DeepTauId.cc:1950
nanoDQM_cff.Electron
Electron
Definition: nanoDQM_cff.py:62
DDAxes::phi
edm::ValueMap::get
const_reference_type get(ProductID id, size_t idx) const
Definition: ValueMap.h:144
DeepTauId::getPredictions
tensorflow::Tensor getPredictions(edm::Event &event, edm::Handle< TauCollection > taus) override
Definition: DeepTauId.cc:1285
DeepTauId::basicDiscrdR03IndexMap_
std::map< BasicDiscriminator, size_t > basicDiscrdR03IndexMap_
Definition: DeepTauId.cc:2590
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
std
Definition: JetResolutionObject.h:76
hcaldqm::quantity::max_value
const std::map< ValueQuantityType, double > max_value
Definition: ValueQuantity.h:190
PVValHelper::dxy
Definition: PVValidationHelpers.h:47
pat::Electron::superCluster
reco::SuperClusterRef superCluster() const override
override the reco::GsfElectron::superCluster method, to access the internal storage of the superclust...
isFinite.h
pwdgSkimBPark_cfi.electrons
electrons
Definition: pwdgSkimBPark_cfi.py:6
DeepTauId::muonTensor_
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > muonTensor_
Definition: DeepTauId.cc:2584
DeepTauId::electrons_token_
edm::EDGetTokenT< std::vector< pat::Electron > > electrons_token_
Definition: DeepTauId.cc:2572
PVValHelper::dz
Definition: PVValidationHelpers.h:50
HLT_FULL_cff.dEta
dEta
Definition: HLT_FULL_cff.py:13767
MuonSubdetId::RPC
static constexpr int RPC
Definition: MuonSubdetId.h:13
deep_tau::DeepTauBase::recoPrediscriminants_
std::vector< TauDiscInfo< reco::PFTauDiscriminator > > recoPrediscriminants_
Definition: DeepTauBase.h:113
T
long double T
Definition: Basic3DVectorLD.h:48
CellObjectType
CellObjectType
Definition: DeepTauId.cc:942
HLT_FULL_cff.candidates
candidates
Definition: HLT_FULL_cff.py:55051
edm::ValueMap
Definition: ValueMap.h:107
runTauDisplay.tau_pt
tau_pt
Definition: runTauDisplay.py:125
Exception
Definition: hltDiff.cc:246
DeepTauId::createTauBlockInputs
void createTauBlockInputs(const TauCastType &tau, const size_t &tau_index, const edm::RefToBase< reco::BaseTau > tau_ref, const reco::Vertex &pv, double rho, TauFunc tau_funcs)
Definition: DeepTauId.cc:1603
postprocess-scan-build.cells
cells
Definition: postprocess-scan-build.py:13
reco::HitPattern::MISSING_INNER_HITS
Definition: HitPattern.h:155
DeepTauId::getPredictionsV2
void getPredictionsV2(TauCollection::const_reference &tau, const size_t tau_index, const edm::RefToBase< reco::BaseTau > tau_ref, const std::vector< pat::Electron > *electrons, const std::vector< pat::Muon > *muons, const edm::View< reco::Candidate > &pfCands, const reco::Vertex &pv, double rho, std::vector< tensorflow::Tensor > &pred_vector, TauFunc tau_funcs)
Definition: DeepTauId.cc:1416
reco::tau::pt_weighted_dr_signal
float pt_weighted_dr_signal(const reco::PFTau &tau, int dm)
Definition: PFRecoTauClusterVariables.h:32
tensorflow::run
void run(Session *session, const NamedTensorList &inputs, const std::vector< std::string > &outputNames, std::vector< Tensor > *outputs, const thread::ThreadPoolOptions &threadPoolOptions)
Definition: TensorFlow.cc:211
edm::parameterSet
ParameterSet const & parameterSet(Provenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:11
DeepTauId::getPredictionsV1
void getPredictionsV1(TauCollection::const_reference &tau, const size_t tau_index, const edm::RefToBase< reco::BaseTau > tau_ref, const std::vector< pat::Electron > *electrons, const std::vector< pat::Muon > *muons, std::vector< tensorflow::Tensor > &pred_vector, TauFunc tau_funcs)
Definition: DeepTauId.cc:1403
EgHLTOffHistBins_cfi.mass
mass
Definition: EgHLTOffHistBins_cfi.py:34
CommPDSkim_cfg.maxDeltaPhi
maxDeltaPhi
Definition: CommPDSkim_cfg.py:74
DeepTauId::input_layer_
std::string input_layer_
Definition: DeepTauId.cc:2579
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
reco::tau::countHits
void countHits(const reco::Muon &muon, std::vector< int > &numHitsDT, std::vector< int > &numHitsCSC, std::vector< int > &numHitsRPC)
Definition: RecoTauMuonTools.cc:7
reco::tau::pt_weighted_dr_iso
float pt_weighted_dr_iso(const reco::PFTau &tau, int dm)
Definition: PFRecoTauClusterVariables.h:52
or
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
reco::deltaR
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::RefToBase
Definition: AssociativeIterator.h:54
DeepTauId::fillGrids
void fillGrids(const TauCastType &tau, const Collection &objects, CellGrid &inner_grid, CellGrid &outer_grid)
Definition: DeepTauId.cc:1466
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
reco::PFCandidate
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
deep_tau::DeepTauBase::andPrediscriminants_
uint8_t andPrediscriminants_
Definition: DeepTauBase.h:111
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
cms::Exception
Definition: Exception.h:70
pat::Electron
Analysis-level electron class.
Definition: Electron.h:51
deep_tau::DeepTauCache
Definition: DeepTauBase.h:48
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
DeepTauId::createConvFeatures
void createConvFeatures(const TauCastType &tau, const size_t tau_index, const edm::RefToBase< reco::BaseTau > tau_ref, const reco::Vertex &pv, double rho, const std::vector< pat::Electron > *electrons, const std::vector< pat::Muon > *muons, const edm::View< reco::Candidate > &pfCands, const CellGrid &grid, TauFunc tau_funcs, bool is_inner)
Definition: DeepTauId.cc:1527
operator<
bool operator<(DTCELinkId const &lhs, DTCELinkId const &rhs)
Definition: DTCELinkId.h:70
HGC3DClusterGenMatchSelector_cfi.dR
dR
Definition: HGC3DClusterGenMatchSelector_cfi.py:7
operator[]
T operator[](int i) const
Definition: extBasic3DVector.h:222
DeepTauId::calculateGottfriedJacksonAngleDifference
static float calculateGottfriedJacksonAngleDifference(const TauCastType &tau, const size_t tau_index, TauFunc tau_funcs)
Definition: DeepTauId.cc:2543
DeepTauId::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: DeepTauId.cc:1112
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
DeepTauId::createInputsV1
tensorflow::Tensor createInputsV1(const TauCastType &tau, const size_t tau_index, const edm::RefToBase< reco::BaseTau > tau_ref, const std::vector< pat::Electron > *electrons, const std::vector< pat::Muon > *muons, TauFunc tau_funcs) const
Definition: DeepTauId.cc:2223
event
Definition: event.py:1
reco::TauDiscriminatorContainer
edm::ValueMap< SingleTauDiscriminatorContainer > TauDiscriminatorContainer
Definition: TauDiscriminatorContainer.h:17
edm::Event
Definition: Event.h:73
dnn_inputs_2017_v2::TauBlockInputs
Definition: DeepTauId.cc:158
edm::InputTag
Definition: InputTag.h:15
DeepTauId::getPartialPredictions
tensorflow::Tensor getPartialPredictions(bool is_inner)
Definition: DeepTauId.cc:1502
deep_tau::DeepTauCache::getGraph
const tensorflow::GraphDef & getGraph(const std::string &name="") const
Definition: DeepTauBase.h:58
reco::Vertex
Definition: Vertex.h:35
hit
Definition: SiStripHitEffFromCalibTree.cc:88
DeepTauId::discrIndicesMapped_
bool discrIndicesMapped_
Definition: DeepTauId.cc:2588
HGVHistoProducerAlgoBlock_cfi.maxX
maxX
Definition: HGVHistoProducerAlgoBlock_cfi.py:154
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
pwdgSkimBPark_cfi.vertices
vertices
Definition: pwdgSkimBPark_cfi.py:7
DeepTauId::processSignalPFComponents
static void processSignalPFComponents(const TauCastType &tau, const CandidateCollection &candidates, LorentzVectorXYZ &p4_inner, LorentzVectorXYZ &p4_outer, float &pt_inner, float &dEta_inner, float &dPhi_inner, float &m_inner, float &pt_outer, float &dEta_outer, float &dPhi_outer, float &m_outer, float &n_inner, float &n_outer)
Definition: DeepTauId.cc:2447