15 #include "tbb/concurrent_unordered_set.h"
23 struct dnn_inputs_2017v1 {
31 neutralIsoPtSumWeight,
32 photonPtSumOutsideSignalCone,
44 leadChargedHadrCand_pt,
45 leadChargedHadrCand_dEta,
46 leadChargedHadrCand_dPhi,
47 leadChargedHadrCand_mass,
70 gsf_ele_dEta_SeedClusterTrackAtCalo,
71 gsf_ele_dPhi_SeedClusterTrackAtCalo,
72 gsf_ele_mvaIn_sigmaEtaEta,
73 gsf_ele_mvaIn_hadEnergy,
74 gsf_ele_mvaIn_deltaEta,
77 gsf_ele_GSFTrackResol,
81 leadChargedCand_etaAtEcalEntrance,
83 leadChargedHadrCand_HoP,
84 leadChargedHadrCand_EoP,
85 tau_visMass_innerSigCone,
107 muon_n_stations_with_matches_03,
108 muon_n_stations_with_hits_23,
109 signalChargedHadrCands_sum_innerSigCone_pt,
110 signalChargedHadrCands_sum_innerSigCone_dEta,
111 signalChargedHadrCands_sum_innerSigCone_dPhi,
112 signalChargedHadrCands_sum_innerSigCone_mass,
113 signalChargedHadrCands_sum_outerSigCone_pt,
114 signalChargedHadrCands_sum_outerSigCone_dEta,
115 signalChargedHadrCands_sum_outerSigCone_dPhi,
116 signalChargedHadrCands_sum_outerSigCone_mass,
117 signalChargedHadrCands_nTotal_innerSigCone,
118 signalChargedHadrCands_nTotal_outerSigCone,
119 signalNeutrHadrCands_sum_innerSigCone_pt,
120 signalNeutrHadrCands_sum_innerSigCone_dEta,
121 signalNeutrHadrCands_sum_innerSigCone_dPhi,
122 signalNeutrHadrCands_sum_innerSigCone_mass,
123 signalNeutrHadrCands_sum_outerSigCone_pt,
124 signalNeutrHadrCands_sum_outerSigCone_dEta,
125 signalNeutrHadrCands_sum_outerSigCone_dPhi,
126 signalNeutrHadrCands_sum_outerSigCone_mass,
127 signalNeutrHadrCands_nTotal_innerSigCone,
128 signalNeutrHadrCands_nTotal_outerSigCone,
129 signalGammaCands_sum_innerSigCone_pt,
130 signalGammaCands_sum_innerSigCone_dEta,
131 signalGammaCands_sum_innerSigCone_dPhi,
132 signalGammaCands_sum_innerSigCone_mass,
133 signalGammaCands_sum_outerSigCone_pt,
134 signalGammaCands_sum_outerSigCone_dEta,
135 signalGammaCands_sum_outerSigCone_dPhi,
136 signalGammaCands_sum_outerSigCone_mass,
137 signalGammaCands_nTotal_innerSigCone,
138 signalGammaCands_nTotal_outerSigCone,
139 isolationChargedHadrCands_sum_pt,
140 isolationChargedHadrCands_sum_dEta,
141 isolationChargedHadrCands_sum_dPhi,
142 isolationChargedHadrCands_sum_mass,
143 isolationChargedHadrCands_nTotal,
144 isolationNeutrHadrCands_sum_pt,
145 isolationNeutrHadrCands_sum_dEta,
146 isolationNeutrHadrCands_sum_dPhi,
147 isolationNeutrHadrCands_sum_mass,
148 isolationNeutrHadrCands_nTotal,
149 isolationGammaCands_sum_pt,
150 isolationGammaCands_sum_dEta,
151 isolationGammaCands_sum_dPhi,
152 isolationGammaCands_sum_mass,
153 isolationGammaCands_nTotal,
159 constexpr
int number_of_inner_cell = 11;
160 constexpr
int number_of_outer_cell = 21;
161 constexpr
int number_of_conv_features = 64;
162 namespace TauBlockInputs {
171 tau_n_charged_prongs,
172 tau_n_neutral_prongs,
174 chargedIsoPtSumdR03_over_dR05,
177 neutralIsoPtSumWeight_over_neutralIsoPtSum,
178 neutralIsoPtSumWeightdR03_over_neutralIsoPtSum,
179 neutralIsoPtSumdR03_over_dR05,
180 photonPtSumOutsideSignalCone,
197 tau_flightLength_sig,
198 tau_pt_weighted_deta_strip,
199 tau_pt_weighted_dphi_strip,
200 tau_pt_weighted_dr_signal,
201 tau_pt_weighted_dr_iso,
202 tau_leadingTrackNormChi2,
205 tau_gj_angle_diff_valid,
209 tau_inside_ecal_crack,
210 leadChargedCand_etaAtEcalEntrance_minus_tau_eta,
215 namespace EgammaBlockInputs {
220 tau_inside_ecal_crack,
225 pfCand_ele_pvAssociationQuality,
226 pfCand_ele_puppiWeight,
228 pfCand_ele_lostInnerHits,
229 pfCand_ele_numberOfPixelHits,
230 pfCand_ele_vertex_dx,
231 pfCand_ele_vertex_dy,
232 pfCand_ele_vertex_dz,
233 pfCand_ele_vertex_dx_tauFL,
234 pfCand_ele_vertex_dy_tauFL,
235 pfCand_ele_vertex_dz_tauFL,
236 pfCand_ele_hasTrackDetails,
241 pfCand_ele_track_chi2_ndof,
242 pfCand_ele_track_ndof,
248 ele_cc_ele_rel_energy,
249 ele_cc_gamma_rel_energy,
251 ele_rel_trackMomentumAtVtx,
252 ele_rel_trackMomentumAtCalo,
253 ele_rel_trackMomentumOut,
254 ele_rel_trackMomentumAtEleClus,
255 ele_rel_trackMomentumAtVtxWithConstraint,
258 ele_eSuperClusterOverP,
259 ele_eSeedClusterOverP,
260 ele_eSeedClusterOverPout,
261 ele_eEleClusterOverPout,
262 ele_deltaEtaSuperClusterTrackAtVtx,
263 ele_deltaEtaSeedClusterTrackAtCalo,
264 ele_deltaEtaEleClusterTrackAtCalo,
265 ele_deltaPhiEleClusterTrackAtCalo,
266 ele_deltaPhiSuperClusterTrackAtVtx,
267 ele_deltaPhiSeedClusterTrackAtCalo,
268 ele_mvaInput_earlyBrem,
269 ele_mvaInput_lateBrem,
270 ele_mvaInput_sigmaEtaEta,
271 ele_mvaInput_hadEnergy,
272 ele_mvaInput_deltaEta,
273 ele_gsfTrack_normalizedChi2,
274 ele_gsfTrack_numberOfValidHits,
277 ele_has_closestCtfTrack,
278 ele_closestCtfTrack_normalizedChi2,
279 ele_closestCtfTrack_numberOfValidHits,
284 pfCand_gamma_pvAssociationQuality,
286 pfCand_gamma_puppiWeight,
287 pfCand_gamma_puppiWeightNoLep,
288 pfCand_gamma_lostInnerHits,
289 pfCand_gamma_numberOfPixelHits,
290 pfCand_gamma_vertex_dx,
291 pfCand_gamma_vertex_dy,
292 pfCand_gamma_vertex_dz,
293 pfCand_gamma_vertex_dx_tauFL,
294 pfCand_gamma_vertex_dy_tauFL,
295 pfCand_gamma_vertex_dz_tauFL,
296 pfCand_gamma_hasTrackDetails,
298 pfCand_gamma_dxy_sig,
301 pfCand_gamma_track_chi2_ndof,
302 pfCand_gamma_track_ndof,
307 namespace MuonBlockInputs {
312 tau_inside_ecal_crack,
317 pfCand_muon_pvAssociationQuality,
319 pfCand_muon_puppiWeight,
321 pfCand_muon_lostInnerHits,
322 pfCand_muon_numberOfPixelHits,
323 pfCand_muon_vertex_dx,
324 pfCand_muon_vertex_dy,
325 pfCand_muon_vertex_dz,
326 pfCand_muon_vertex_dx_tauFL,
327 pfCand_muon_vertex_dy_tauFL,
328 pfCand_muon_vertex_dz_tauFL,
329 pfCand_muon_hasTrackDetails,
334 pfCand_muon_track_chi2_ndof,
335 pfCand_muon_track_ndof,
342 muon_normalizedChi2_valid,
344 muon_numberOfValidHits,
345 muon_segmentCompatibility,
346 muon_caloCompatibility,
347 muon_pfEcalEnergy_valid,
348 muon_rel_pfEcalEnergy,
353 muon_n_matches_CSC_1,
354 muon_n_matches_CSC_2,
355 muon_n_matches_CSC_3,
356 muon_n_matches_CSC_4,
357 muon_n_matches_RPC_1,
358 muon_n_matches_RPC_2,
359 muon_n_matches_RPC_3,
360 muon_n_matches_RPC_4,
377 namespace HadronBlockInputs {
382 tau_inside_ecal_crack,
387 pfCand_chHad_leadChargedHadrCand,
388 pfCand_chHad_pvAssociationQuality,
390 pfCand_chHad_puppiWeight,
391 pfCand_chHad_puppiWeightNoLep,
393 pfCand_chHad_lostInnerHits,
394 pfCand_chHad_numberOfPixelHits,
395 pfCand_chHad_vertex_dx,
396 pfCand_chHad_vertex_dy,
397 pfCand_chHad_vertex_dz,
398 pfCand_chHad_vertex_dx_tauFL,
399 pfCand_chHad_vertex_dy_tauFL,
400 pfCand_chHad_vertex_dz_tauFL,
401 pfCand_chHad_hasTrackDetails,
403 pfCand_chHad_dxy_sig,
406 pfCand_chHad_track_chi2_ndof,
407 pfCand_chHad_track_ndof,
408 pfCand_chHad_hcalFraction,
409 pfCand_chHad_rawCaloFraction,
414 pfCand_nHad_puppiWeight,
415 pfCand_nHad_puppiWeightNoLep,
416 pfCand_nHad_hcalFraction,
423 static tbb::concurrent_unordered_set<std::string> isFirstWarning;
429 <<
"Exception in <getTauID>: No tauID '" <<
tauID <<
"' available in pat::Tau given as function argument.";
431 if (isFirstWarning.insert(
tauID).second) {
433 <<
"' available in pat::Tau given as function argument."
434 <<
" Using default_value = " << default_value <<
" instead." << std::endl;
436 return default_value;
444 pfTauTransverseImpactParameters;
447 std::map<BasicDiscr, size_t> indexMap;
448 std::map<BasicDiscr, size_t> indexMapdR03;
451 return (*basicTauDiscriminatorCollection)[tau_ref].rawValues.at(indexMap.at(BasicDiscr::ChargedIsoPtSum));
454 return getTauID(
tau,
"chargedIsoPtSum");
457 return (*basicTauDiscriminatordR03Collection)[tau_ref].rawValues.at(indexMapdR03.at(BasicDiscr::ChargedIsoPtSum));
460 return getTauID(
tau,
"chargedIsoPtSumdR03");
463 return (*basicTauDiscriminatordR03Collection)[tau_ref].rawValues.at(
464 indexMapdR03.at(BasicDiscr::FootprintCorrection));
467 return getTauID(
tau,
"footprintCorrectiondR03");
470 return (*basicTauDiscriminatorCollection)[tau_ref].rawValues.at(indexMap.at(BasicDiscr::NeutralIsoPtSum));
473 return getTauID(
tau,
"neutralIsoPtSum");
476 return (*basicTauDiscriminatordR03Collection)[tau_ref].rawValues.at(indexMapdR03.at(BasicDiscr::NeutralIsoPtSum));
479 return getTauID(
tau,
"neutralIsoPtSumdR03");
482 return (*basicTauDiscriminatorCollection)[tau_ref].rawValues.at(indexMap.at(BasicDiscr::NeutralIsoPtSumWeight));
485 return getTauID(
tau,
"neutralIsoPtSumWeight");
489 return (*basicTauDiscriminatordR03Collection)[tau_ref].rawValues.at(
490 indexMapdR03.at(BasicDiscr::NeutralIsoPtSumWeight));
493 return getTauID(
tau,
"neutralIsoPtSumWeightdR03");
495 const float getPhotonPtSumOutsideSignalCone(
const reco::PFTau&
tau,
497 return (*basicTauDiscriminatorCollection)[tau_ref].rawValues.at(
498 indexMap.at(BasicDiscr::PhotonPtSumOutsideSignalCone));
500 const float getPhotonPtSumOutsideSignalCone(
const pat::Tau&
tau,
502 return getTauID(
tau,
"photonPtSumOutsideSignalCone");
504 const float getPhotonPtSumOutsideSignalConedR03(
const reco::PFTau&
tau,
506 return (*basicTauDiscriminatordR03Collection)[tau_ref].rawValues.at(
507 indexMapdR03.at(BasicDiscr::PhotonPtSumOutsideSignalCone));
509 const float getPhotonPtSumOutsideSignalConedR03(
const pat::Tau&
tau,
511 return getTauID(
tau,
"photonPtSumOutsideSignalConedR03");
514 return (*basicTauDiscriminatorCollection)[tau_ref].rawValues.at(indexMap.at(BasicDiscr::PUcorrPtSum));
517 return getTauID(
tau,
"puCorrPtSum");
520 auto getdxyPCA(
const reco::PFTau&
tau,
const size_t tau_index)
const {
521 return pfTauTransverseImpactParameters->
value(tau_index)->dxy_PCA();
523 auto getdxyPCA(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.dxy_PCA(); }
524 auto getdxy(
const reco::PFTau&
tau,
const size_t tau_index)
const {
525 return pfTauTransverseImpactParameters->
value(tau_index)->dxy();
527 auto getdxy(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.dxy(); }
528 auto getdxyError(
const reco::PFTau&
tau,
const size_t tau_index)
const {
529 return pfTauTransverseImpactParameters->
value(tau_index)->dxy_error();
531 auto getdxyError(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.dxy_error(); }
532 auto getdxySig(
const reco::PFTau&
tau,
const size_t tau_index)
const {
533 return pfTauTransverseImpactParameters->
value(tau_index)->dxy_Sig();
535 auto getdxySig(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.dxy_Sig(); }
536 auto getip3d(
const reco::PFTau&
tau,
const size_t tau_index)
const {
537 return pfTauTransverseImpactParameters->
value(tau_index)->ip3d();
539 auto getip3d(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.ip3d(); }
540 auto getip3dError(
const reco::PFTau&
tau,
const size_t tau_index)
const {
541 return pfTauTransverseImpactParameters->
value(tau_index)->ip3d_error();
543 auto getip3dError(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.ip3d_error(); }
544 auto getip3dSig(
const reco::PFTau&
tau,
const size_t tau_index)
const {
545 return pfTauTransverseImpactParameters->
value(tau_index)->ip3d_Sig();
547 auto getip3dSig(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.ip3d_Sig(); }
548 auto getHasSecondaryVertex(
const reco::PFTau&
tau,
const size_t tau_index)
const {
549 return pfTauTransverseImpactParameters->
value(tau_index)->hasSecondaryVertex();
551 auto getHasSecondaryVertex(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.hasSecondaryVertex(); }
552 auto getFlightLength(
const reco::PFTau&
tau,
const size_t tau_index)
const {
553 return pfTauTransverseImpactParameters->
value(tau_index)->flightLength();
555 auto getFlightLength(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.flightLength(); }
556 auto getFlightLengthSig(
const reco::PFTau&
tau,
const size_t tau_index)
const {
557 return pfTauTransverseImpactParameters->
value(tau_index)->flightLengthSig();
559 auto getFlightLengthSig(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.flightLengthSig(); }
562 auto getLeadingTrackNormChi2(
const pat::Tau&
tau) {
return tau.leadingTrackNormChi2(); }
563 auto getEmFraction(
const pat::Tau&
tau) {
return tau.emFraction_MVA(); }
565 auto getEtaAtEcalEntrance(
const pat::Tau&
tau) {
return tau.etaAtEcalEntranceLeadChargedCand(); }
567 return tau.leadPFChargedHadrCand()->positionAtECALEntrance().eta();
569 auto getEcalEnergyLeadingChargedHadr(
const reco::PFTau&
tau) {
return tau.leadPFChargedHadrCand()->ecalEnergy(); }
570 auto getEcalEnergyLeadingChargedHadr(
const pat::Tau&
tau) {
return tau.ecalEnergyLeadChargedHadrCand(); }
571 auto getHcalEnergyLeadingChargedHadr(
const reco::PFTau&
tau) {
return tau.leadPFChargedHadrCand()->hcalEnergy(); }
572 auto getHcalEnergyLeadingChargedHadr(
const pat::Tau&
tau) {
return tau.hcalEnergyLeadChargedHadrCand(); }
574 template <
typename PreDiscrType>
575 bool passPrediscriminants(
const PreDiscrType prediscriminants,
576 const size_t andPrediscriminants,
578 bool passesPrediscriminants = (andPrediscriminants ? 1 : 0);
580 size_t nPrediscriminants = prediscriminants.size();
581 for (
size_t iDisc = 0; iDisc < nPrediscriminants; ++iDisc) {
583 double discResult = (*prediscriminants[iDisc].handle)[tau_ref];
584 uint8_t thisPasses = (discResult > prediscriminants[iDisc].cut) ? 1 : 0;
601 if (thisPasses ^ andPrediscriminants)
603 passesPrediscriminants = (andPrediscriminants ? 0 : 1);
607 return passesPrediscriminants;
615 return cand.bestTrack() !=
nullptr && std::isnormal(
cand.bestTrack()->dz()) && std::isnormal(
cand.dzError()) &&
619 return cand.hasTrackDetails() && std::isnormal(
cand.dz()) && std::isnormal(
cand.dzError()) &&
cand.dzError() > 0;
629 return cand.puppiWeightNoLep();
632 return cand.bestTrack() !=
nullptr
638 return cand.bestTrack() !=
nullptr
643 return cand.numberOfPixelHits();
652 return cand.rawHcalEnergy() / (
cand.rawHcalEnergy() +
cand.rawEcalEnergy());
655 float hcal_fraction = 0.;
656 if (disable_hcalFraction_workaround) {
659 hcal_fraction =
cand.hcalFraction();
662 if (
cand.pdgId() == 1 ||
cand.pdgId() == 130) {
663 hcal_fraction =
cand.hcalFraction();
664 }
else if (
cand.isIsolatedChargedHadron()) {
665 hcal_fraction =
cand.rawHcalFraction();
668 return hcal_fraction;
671 return (
cand.rawEcalEnergy() +
cand.rawHcalEnergy()) /
cand.energy();
676 template <
typename LVector1,
typename LVector2>
677 float dEta(
const LVector1&
p4,
const LVector2& tau_p4) {
678 return static_cast<float>(
p4.eta() - tau_p4.eta());
681 template <
typename LVector1,
typename LVector2>
682 float dPhi(
const LVector1& p4_1,
const LVector2& p4_2) {
683 return static_cast<float>(
reco::deltaPhi(p4_2.phi(), p4_1.phi()));
686 struct MuonHitMatchV1 {
687 static constexpr
int n_muon_stations = 4;
689 std::map<int, std::vector<UInt_t>> n_matches, n_hits;
691 const pat::Muon* best_matched_muon{
nullptr};
692 double deltaR2_best_match{-1};
704 static constexpr
int n_stations = 4;
708 if (!best_matched_muon || dR2 < deltaR2_best_match) {
709 best_matched_muon = &
muon;
710 deltaR2_best_match = dR2;
713 for (
const auto& segment :
muon.matches()) {
714 if (segment.segmentMatches.empty())
716 if (n_matches.count(segment.detector()))
717 ++n_matches.at(segment.detector()).at(segment.station() - 1);
720 if (
muon.outerTrack().isNonnull()) {
721 const auto& hit_pattern =
muon.outerTrack()->hitPattern();
728 const int station = hit_pattern.getMuonStation(hit_id) - 1;
730 std::vector<UInt_t>* muon_n_hits =
nullptr;
731 if (hit_pattern.muonDTHitFilter(hit_id))
733 else if (hit_pattern.muonCSCHitFilter(hit_id))
735 else if (hit_pattern.muonRPCHitFilter(hit_id))
746 template <
typename TauCastType>
747 static std::vector<const pat::Muon*> findMatchedMuons(
const TauCastType&
tau,
748 const std::vector<pat::Muon>*
muons,
752 if (
tau.leadPFChargedHadrCand().isNonnull() &&
tau.leadPFChargedHadrCand()->muonRef().isNonnull())
753 hadr_cand_muon =
tau.leadPFChargedHadrCand()->muonRef().get();
754 std::vector<const pat::Muon*> matched_muons;
760 if (reco_muon == hadr_cand_muon)
764 matched_muons.push_back(&
muon);
766 return matched_muons;
769 template <
typename dnn,
typename TensorElemGet,
typename TauCastType>
770 void fillTensor(
const TensorElemGet&
get,
const TauCastType&
tau,
float default_value)
const {
771 get(dnn::n_matched_muons) = n_muons;
772 get(dnn::muon_pt) = best_matched_muon !=
nullptr ? best_matched_muon->p4().pt() : default_value;
773 get(dnn::muon_dEta) = best_matched_muon !=
nullptr ?
dEta(best_matched_muon->p4(),
tau.p4()) : default_value;
774 get(dnn::muon_dPhi) = best_matched_muon !=
nullptr ?
dPhi(best_matched_muon->p4(),
tau.p4()) : default_value;
792 get(dnn::muon_n_stations_with_matches_03) = countMuonStationsWithMatches(0, 3);
793 get(dnn::muon_n_stations_with_hits_23) = countMuonStationsWithHits(2, 3);
797 unsigned countMuonStationsWithMatches(
size_t first_station,
size_t last_station)
const {
798 static const std::map<int, std::vector<bool>> masks = {
804 for (
unsigned n = first_station;
n <= last_station; ++
n) {
805 for (
const auto&
match : n_matches) {
806 if (!masks.at(
match.first).at(
n) &&
match.second.at(
n) > 0)
813 unsigned countMuonStationsWithHits(
size_t first_station,
size_t last_station)
const {
814 static const std::map<int, std::vector<bool>> masks = {
821 for (
unsigned n = first_station;
n <= last_station; ++
n) {
822 for (
const auto&
hit : n_hits) {
823 if (!masks.at(
hit.first).at(
n) &&
hit.second.at(
n) > 0)
831 struct MuonHitMatchV2 {
832 static constexpr
size_t n_muon_stations = 4;
833 static constexpr
int first_station_id = 1;
834 static constexpr
int last_station_id = first_station_id + n_muon_stations - 1;
835 using CountArray = std::array<unsigned, n_muon_stations>;
836 using CountMap = std::map<int, CountArray>;
838 const std::vector<int>& consideredSubdets() {
844 static const std::map<int, std::string> subdet_names = {
846 if (!subdet_names.count(subdet))
847 throw cms::Exception(
"MuonHitMatch") <<
"Subdet name for subdet id " << subdet <<
" not found.";
848 return subdet_names.at(subdet);
851 size_t getStationIndex(
int station,
bool throw_exception)
const {
852 if (station < first_station_id || station > last_station_id) {
854 throw cms::Exception(
"MuonHitMatch") <<
"Station id is out of range";
857 return static_cast<size_t>(
station - 1);
861 for (
int subdet : consideredSubdets()) {
862 n_matches[subdet].fill(0);
863 n_hits[subdet].fill(0);
871 for (
const auto& segment :
muon.matches()) {
872 if (segment.segmentMatches.empty() && segment.rpcMatches.empty())
874 if (n_matches.count(segment.detector())) {
875 const size_t station_index = getStationIndex(segment.station(),
true);
876 ++n_matches.at(segment.detector()).at(station_index);
882 if (
muon.outerTrack().isNonnull()) {
883 const auto& hit_pattern =
muon.outerTrack()->hitPattern();
890 const size_t station_index = getStationIndex(hit_pattern.getMuonStation(hit_id),
false);
891 if (station_index < n_muon_stations) {
892 CountArray* muon_n_hits =
nullptr;
893 if (hit_pattern.muonDTHitFilter(hit_id))
895 else if (hit_pattern.muonCSCHitFilter(hit_id))
897 else if (hit_pattern.muonRPCHitFilter(hit_id))
901 ++muon_n_hits->at(station_index);
908 unsigned nMatches(
int subdet,
int station)
const {
909 if (!n_matches.count(subdet))
910 throw cms::Exception(
"MuonHitMatch") <<
"Subdet " << subdet <<
" not found.";
911 const size_t station_index = getStationIndex(
station,
true);
912 return n_matches.at(subdet).at(station_index);
915 unsigned nHits(
int subdet,
int station)
const {
916 if (!n_hits.count(subdet))
917 throw cms::Exception(
"MuonHitMatch") <<
"Subdet " << subdet <<
" not found.";
918 const size_t station_index = getStationIndex(
station,
true);
919 return n_hits.at(subdet).at(station_index);
922 unsigned countMuonStationsWithMatches(
int first_station,
int last_station)
const {
923 static const std::map<int, std::vector<bool>> masks = {
928 const size_t first_station_index = getStationIndex(first_station,
true);
929 const size_t last_station_index = getStationIndex(last_station,
true);
931 for (
size_t n = first_station_index;
n <= last_station_index; ++
n) {
932 for (
const auto&
match : n_matches) {
933 if (!masks.at(
match.first).at(
n) &&
match.second.at(
n) > 0)
940 unsigned countMuonStationsWithHits(
int first_station,
int last_station)
const {
941 static const std::map<int, std::vector<bool>> masks = {
947 const size_t first_station_index = getStationIndex(first_station,
true);
948 const size_t last_station_index = getStationIndex(last_station,
true);
950 for (
size_t n = first_station_index;
n <= last_station_index; ++
n) {
951 for (
const auto&
hit : n_hits) {
952 if (!masks.at(
hit.first).at(
n) &&
hit.second.at(
n) > 0)
960 CountMap n_matches, n_hits;
966 PfCand_chargedHadron,
967 PfCand_neutralHadron,
974 template <
typename Object>
987 static const std::map<int, CellObjectType> obj_types = {{11, CellObjectType::PfCand_electron},
988 {13, CellObjectType::PfCand_muon},
989 {22, CellObjectType::PfCand_gamma},
990 {130, CellObjectType::PfCand_neutralHadron},
991 {211, CellObjectType::PfCand_chargedHadron}};
994 if (iter == obj_types.end())
995 return CellObjectType::Other;
999 using Cell = std::map<CellObjectType, size_t>;
1012 using Map = std::map<CellIndex, Cell>;
1013 using const_iterator = Map::const_iterator;
1015 CellGrid(
unsigned n_cells_eta,
1016 unsigned n_cells_phi,
1017 double cell_size_eta,
1018 double cell_size_phi,
1019 bool disable_CellIndex_workaround)
1020 : nCellsEta(n_cells_eta),
1021 nCellsPhi(n_cells_phi),
1022 nTotal(nCellsEta * nCellsPhi),
1023 cellSizeEta(cell_size_eta),
1024 cellSizePhi(cell_size_phi),
1025 disable_CellIndex_workaround_(disable_CellIndex_workaround) {
1026 if (nCellsEta % 2 != 1 || nCellsEta < 1)
1027 throw cms::Exception(
"DeepTauId") <<
"Invalid number of eta cells.";
1028 if (nCellsPhi % 2 != 1 || nCellsPhi < 1)
1029 throw cms::Exception(
"DeepTauId") <<
"Invalid number of phi cells.";
1030 if (cellSizeEta <= 0 || cellSizePhi <= 0)
1034 int maxEtaIndex()
const {
return static_cast<int>((nCellsEta - 1) / 2); }
1035 int maxPhiIndex()
const {
return static_cast<int>((nCellsPhi - 1) / 2); }
1036 double maxDeltaEta()
const {
return cellSizeEta * (0.5 + maxEtaIndex()); }
1037 double maxDeltaPhi()
const {
return cellSizePhi * (0.5 + maxPhiIndex()); }
1038 int getEtaTensorIndex(
const CellIndex& cellIndex)
const {
return cellIndex.eta + maxEtaIndex(); }
1039 int getPhiTensorIndex(
const CellIndex& cellIndex)
const {
return cellIndex.phi + maxPhiIndex(); }
1041 bool tryGetCellIndex(
double deltaEta,
double deltaPhi, CellIndex& cellIndex)
const {
1042 const auto getCellIndex = [
this](
double x,
double maxX,
double size,
int&
index) {
1047 if (disable_CellIndex_workaround_) {
1050 absIndex = std::floor(absX /
size + 0.5);
1055 index = static_cast<int>(std::copysign(absIndex,
x));
1063 size_t num_valid_cells()
const {
return cells.size(); }
1065 const Cell& at(
const CellIndex& cellIndex)
const {
return cells.at(cellIndex); }
1066 size_t count(
const CellIndex& cellIndex)
const {
return cells.count(cellIndex); }
1067 const_iterator
find(
const CellIndex& cellIndex)
const {
return cells.find(cellIndex); }
1068 const_iterator begin()
const {
return cells.begin(); }
1069 const_iterator
end()
const {
return cells.end(); }
1072 const unsigned nCellsEta, nCellsPhi, nTotal;
1073 const double cellSizeEta, cellSizePhi;
1076 std::map<CellIndex, Cell>
cells;
1077 const bool disable_CellIndex_workaround_;
1083 {bd::ChargedIsoPtSum,
"ChargedIsoPtSum"},
1084 {bd::NeutralIsoPtSum,
"NeutralIsoPtSum"},
1085 {bd::NeutralIsoPtSumWeight,
"NeutralIsoPtSumWeight"},
1086 {bd::FootprintCorrection,
"TauFootprintCorrection"},
1087 {bd::PhotonPtSumOutsideSignalCone,
"PhotonPtSumOutsideSignalCone"},
1088 {bd::PUcorrPtSum,
"PUcorrPtSum"}};
1090 bd::NeutralIsoPtSum,
1091 bd::NeutralIsoPtSumWeight,
1092 bd::PhotonPtSumOutsideSignalCone,
1095 bd::NeutralIsoPtSum,
1096 bd::NeutralIsoPtSumWeight,
1097 bd::PhotonPtSumOutsideSignalCone,
1098 bd::FootprintCorrection};
1105 static constexpr
size_t e_index = 0, mu_index = 1, tau_index = 2, jet_index = 3;
1107 {
"VSe",
Output({tau_index}, {e_index, tau_index})},
1108 {
"VSmu",
Output({tau_index}, {mu_index, tau_index})},
1109 {
"VSjet",
Output({tau_index}, {jet_index, tau_index})},
1117 std::vector<BasicDiscriminator> requiredDiscr) {
1118 std::map<std::string, size_t> discrIndexMapStr;
1119 auto const aHandle =
event.getHandle(discriminatorContainerToken);
1120 auto const aProv = aHandle.provenance();
1121 if (aProv ==
nullptr)
1122 aHandle.whyFailed()->raise();
1124 auto const idlist = psetsFromProvenance.
getParameter<std::vector<edm::ParameterSet>>(
"IDdefinitions");
1125 for (
size_t j = 0;
j < idlist.size(); ++
j) {
1127 if (discrIndexMapStr.count(idname)) {
1129 <<
"basic discriminator " << idname <<
" appears more than once in the input.";
1131 discrIndexMapStr[idname] =
j;
1135 std::map<BasicDiscriminator, size_t> discrIndexMap;
1136 for (
size_t i = 0;
i < requiredDiscr.size();
i++) {
1139 <<
" was not provided in the config file.";
1143 return discrIndexMap;
1154 desc.add<std::vector<std::string>>(
"graph_file",
1155 {
"RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6.pb"});
1156 desc.add<
bool>(
"mem_mapped",
false);
1157 desc.add<
unsigned>(
"version", 2);
1158 desc.add<
int>(
"debug_level", 0);
1159 desc.add<
bool>(
"disable_dxy_pca",
false);
1160 desc.add<
bool>(
"disable_hcalFraction_workaround",
false);
1161 desc.add<
bool>(
"disable_CellIndex_workaround",
false);
1162 desc.add<
bool>(
"save_inputs",
false);
1163 desc.add<
bool>(
"is_online",
false);
1165 desc.add<std::vector<std::string>>(
"VSeWP");
1166 desc.add<std::vector<std::string>>(
"VSmuWP");
1167 desc.add<std::vector<std::string>>(
"VSjetWP");
1175 pset_Prediscriminants.
add<
std::string>(
"BooleanOperator",
"and");
1178 psd1.
add<
double>(
"cut");
1185 descriptions.
add(
"DeepTau",
desc);
1195 cfg.getUntrackedParameter<
edm::
InputTag>(
"basicTauDiscriminators"))),
1197 cfg.getUntrackedParameter<
edm::
InputTag>(
"basicTauDiscriminatorsdR03"))),
1200 cfg.getParameter<
edm::
InputTag>(
"pfTauTransverseImpactParameters"))),
1212 const auto& shape =
cache_->
getGraph().node(0).attr().at(
"shape").shape();
1213 if (shape.dim(1).size() != dnn_inputs_2017v1::NumberOfInputs)
1215 <<
"number of inputs does not match the expected inputs for the given version";
1218 tensorflow::DT_FLOAT, tensorflow::TensorShape{1, dnn_inputs_2017_v2::TauBlockInputs::NumberOfInputs});
1219 for (
size_t n = 0;
n < 2; ++
n) {
1220 const bool is_inner =
n == 0;
1221 const auto n_cells =
1222 is_inner ? dnn_inputs_2017_v2::number_of_inner_cell : dnn_inputs_2017_v2::number_of_outer_cell;
1223 eGammaTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1224 tensorflow::DT_FLOAT,
1225 tensorflow::TensorShape{1, 1, 1, dnn_inputs_2017_v2::EgammaBlockInputs::NumberOfInputs});
1226 muonTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1227 tensorflow::DT_FLOAT,
1228 tensorflow::TensorShape{1, 1, 1, dnn_inputs_2017_v2::MuonBlockInputs::NumberOfInputs});
1230 tensorflow::DT_FLOAT,
1231 tensorflow::TensorShape{1, 1, 1, dnn_inputs_2017_v2::HadronBlockInputs::NumberOfInputs});
1232 convTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1233 tensorflow::DT_FLOAT,
1234 tensorflow::TensorShape{1, n_cells, n_cells, dnn_inputs_2017_v2::number_of_conv_features});
1236 tensorflow::DT_FLOAT, tensorflow::TensorShape{1, 1, 1, dnn_inputs_2017_v2::number_of_conv_features});
1250 return DeepTauBase::initializeGlobalCache(
cfg);
1258 template <
typename T>
1260 return std::isnormal(
value) ? static_cast<float>(
value) : 0.f;
1263 template <
typename T>
1269 transformed_value = transformed_value * 2 - 1;
1270 return transformed_value;
1273 template <
typename T>
1276 const float norm_value = (fixed_value -
mean) / sigma;
1277 return std::clamp(norm_value, -n_sigmas_max, n_sigmas_max);
1283 float& cc_ele_energy,
1284 float& cc_gamma_energy,
1286 cc_ele_energy = cc_gamma_energy = 0;
1289 if (superCluster.isNonnull() && superCluster.isAvailable() && superCluster->clusters().isNonnull() &&
1290 superCluster->clusters().isAvailable()) {
1291 for (
auto iter = superCluster->clustersBegin(); iter != superCluster->clustersEnd(); ++iter) {
1292 const float energy = static_cast<float>((*iter)->energy());
1293 if (iter == superCluster->clustersBegin())
1296 cc_gamma_energy +=
energy;
1308 const CellGrid*
grid =
nullptr)
const {
1310 std::cout <<
"<checkInputs>: block_name = " << block_name << std::endl;
1311 if (block_name ==
"input_tau") {
1312 for (
int input_index = 0; input_index < n_inputs; ++input_index) {
1313 float input =
inputs.matrix<
float>()(0, input_index);
1316 <<
"in the " << block_name
1317 <<
", input is not finite, i.e. infinite or NaN, for input_index = " << input_index;
1327 if (block_name.find(
"input_inner") != std::string::npos) {
1330 }
else if (block_name.find(
"input_outer") != std::string::npos) {
1335 int eta_phi_index = 0;
1336 for (
int eta = -n_eta;
eta <= n_eta; ++
eta) {
1337 for (
int phi = -n_phi;
phi <= n_phi; ++
phi) {
1338 const CellIndex cell_index{
eta,
phi};
1339 const auto cell_iter =
grid->find(cell_index);
1340 if (cell_iter !=
grid->end()) {
1341 for (
int input_index = 0; input_index < n_inputs; ++input_index) {
1345 <<
"in the " << block_name <<
", input is not finite, i.e. infinite or NaN, for eta = " <<
eta
1346 <<
", phi = " <<
phi <<
", input_index = " << input_index;
1349 std::cout << block_name <<
"[eta = " <<
eta <<
"][phi = " <<
phi <<
"][var = " << input_index
1350 <<
"] = " << std::setprecision(5) <<
std::fixed <<
input << std::endl;
1364 const CellGrid*
grid =
nullptr) {
1366 std::cout <<
"<saveInputs>: block_name = " << block_name << std::endl;
1369 (*json_file_) <<
", ";
1370 (*json_file_) <<
"\"" << block_name <<
"\": [";
1371 if (block_name ==
"input_tau") {
1372 for (
int input_index = 0; input_index < n_inputs; ++input_index) {
1373 float input =
inputs.matrix<
float>()(0, input_index);
1374 if (input_index != 0)
1375 (*json_file_) <<
", ";
1376 (*json_file_) <<
input;
1381 if (block_name.find(
"input_inner") != std::string::npos) {
1384 }
else if (block_name.find(
"input_outer") != std::string::npos) {
1389 int eta_phi_index = 0;
1390 for (
int eta = -n_eta;
eta <= n_eta; ++
eta) {
1392 (*json_file_) <<
", ";
1393 (*json_file_) <<
"[";
1394 for (
int phi = -n_phi;
phi <= n_phi; ++
phi) {
1396 (*json_file_) <<
", ";
1397 (*json_file_) <<
"[";
1398 const CellIndex cell_index{
eta,
phi};
1399 const auto cell_iter =
grid->find(cell_index);
1400 for (
int input_index = 0; input_index < n_inputs; ++input_index) {
1402 if (cell_iter !=
grid->end()) {
1405 if (input_index != 0)
1406 (*json_file_) <<
", ";
1407 (*json_file_) <<
input;
1409 if (cell_iter !=
grid->end()) {
1412 (*json_file_) <<
"]";
1414 (*json_file_) <<
"]";
1417 (*json_file_) <<
"]";
1424 const std::vector<pat::Electron> electron_collection_default;
1425 const std::vector<pat::Muon> muon_collection_default;
1429 pfTauTransverseImpactParameters_default;
1431 const std::vector<pat::Electron>* electron_collection;
1432 const std::vector<pat::Muon>* muon_collection;
1436 pfTauTransverseImpactParameters;
1441 pfTauTransverseImpactParameters = &pfTauTransverseImpactParameters_default;
1442 basicTauDiscriminators = &basicTauDiscriminators_default;
1443 basicTauDiscriminatorsdR03 = &basicTauDiscriminatorsdR03_default;
1445 electron_collection = &electron_collection_default;
1446 muon_collection = &muon_collection_default;
1461 TauFunc tauIDs = {basicTauDiscriminators,
1462 basicTauDiscriminatorsdR03,
1463 pfTauTransverseImpactParameters,
1478 for (
size_t tau_index = 0; tau_index <
taus->size(); ++tau_index) {
1481 std::vector<tensorflow::Tensor> pred_vector;
1483 bool passesPrediscriminants;
1485 passesPrediscriminants = tauIDs.passPrediscriminants<std::vector<TauDiscInfo<reco::PFTauDiscriminator>>>(
1488 passesPrediscriminants = tauIDs.passPrediscriminants<std::vector<TauDiscInfo<pat::PATTauDiscriminator>>>(
1492 if (passesPrediscriminants) {
1495 getPredictionsV1<reco::PFCandidate, reco::PFTau>(
1496 taus->at(tau_index), tau_index, tauRef, electron_collection, muon_collection, pred_vector, tauIDs);
1498 getPredictionsV1<pat::PackedCandidate, pat::Tau>(
1499 taus->at(tau_index), tau_index, tauRef, electron_collection, muon_collection, pred_vector, tauIDs);
1502 getPredictionsV2<reco::PFCandidate, reco::PFTau>(
taus->at(tau_index),
1505 electron_collection,
1513 getPredictionsV2<pat::PackedCandidate, pat::Tau>(
taus->at(tau_index),
1516 electron_collection,
1528 const float pred = pred_vector[0].flat<
float>()(
k);
1529 if (!(pred >= 0 && pred <= 1))
1531 <<
"invalid prediction = " << pred <<
" for tau_index = " << tau_index <<
", pred_index = " <<
k;
1532 predictions.matrix<
float>()(tau_index,
k) = pred;
1539 template <
typename Cand
idateCastType,
typename TauCastType>
1541 const size_t tau_index,
1543 const std::vector<pat::Electron>*
electrons,
1544 const std::vector<pat::Muon>*
muons,
1545 std::vector<tensorflow::Tensor>& pred_vector,
1546 TauFunc tau_funcs) {
1547 const tensorflow::Tensor&
inputs = createInputsV1<dnn_inputs_2017v1, const CandidateCastType>(
1548 dynamic_cast<const TauCastType&>(
tau), tau_index, tau_ref,
electrons,
muons, tau_funcs);
1552 template <
typename Cand
idateCastType,
typename TauCastType>
1554 const size_t tau_index,
1556 const std::vector<pat::Electron>*
electrons,
1557 const std::vector<pat::Muon>*
muons,
1561 std::vector<tensorflow::Tensor>& pred_vector,
1562 TauFunc tau_funcs) {
1564 std::cout <<
"<DeepTauId::getPredictionsV2 (moduleLabel = " << moduleDescription().moduleLabel()
1565 <<
")>:" << std::endl;
1566 std::cout <<
" tau: pT = " <<
tau.pt() <<
", eta = " <<
tau.eta() <<
", phi = " <<
tau.phi() << std::endl;
1568 CellGrid inner_grid(dnn_inputs_2017_v2::number_of_inner_cell,
1569 dnn_inputs_2017_v2::number_of_inner_cell,
1573 CellGrid outer_grid(dnn_inputs_2017_v2::number_of_outer_cell,
1574 dnn_inputs_2017_v2::number_of_outer_cell,
1579 fillGrids(dynamic_cast<const TauCastType&>(
tau), *
muons, inner_grid, outer_grid);
1580 fillGrids(dynamic_cast<const TauCastType&>(
tau), pfCands, inner_grid, outer_grid);
1582 createTauBlockInputs<CandidateCastType>(
1583 dynamic_cast<const TauCastType&>(
tau), tau_index, tau_ref,
pv,
rho, tau_funcs);
1586 createConvFeatures<CandidateCastType>(dynamic_cast<const TauCastType&>(
tau),
1600 createConvFeatures<CandidateCastType>(dynamic_cast<const TauCastType&>(
tau),
1617 json_file_ =
new std::ofstream(json_file_name.data());
1619 (*json_file_) <<
"{";
1622 "input_inner_egamma",
1623 dnn_inputs_2017_v2::EgammaBlockInputs::NumberOfInputs,
1626 *
muonTensor_[
true],
"input_inner_muon", dnn_inputs_2017_v2::MuonBlockInputs::NumberOfInputs, &inner_grid);
1628 "input_inner_hadrons",
1629 dnn_inputs_2017_v2::HadronBlockInputs::NumberOfInputs,
1632 "input_outer_egamma",
1633 dnn_inputs_2017_v2::EgammaBlockInputs::NumberOfInputs,
1636 *
muonTensor_[
false],
"input_outer_muon", dnn_inputs_2017_v2::MuonBlockInputs::NumberOfInputs, &outer_grid);
1638 "input_outer_hadrons",
1639 dnn_inputs_2017_v2::HadronBlockInputs::NumberOfInputs,
1641 (*json_file_) <<
"}";
1650 {
"main_output/Softmax"},
1674 template <
typename Collection,
typename TauCastType>
1675 void fillGrids(
const TauCastType&
tau,
const Collection&
objects, CellGrid& inner_grid, CellGrid& outer_grid) {
1676 static constexpr
double outer_dR2 = 0.25;
1678 const double inner_dR2 =
std::pow(inner_radius, 2);
1680 const auto addObject = [&](
size_t n,
double deta,
double dphi, CellGrid&
grid) {
1683 if (obj_type == CellObjectType::Other)
1685 CellIndex cell_index;
1686 if (
grid.tryGetCellIndex(deta, dphi, cell_index)) {
1688 auto iter = cell.find(obj_type);
1689 if (iter != cell.end()) {
1690 const auto& prev_obj =
objects.at(iter->second);
1691 if (
obj.polarP4().pt() > prev_obj.polarP4().pt())
1699 for (
size_t n = 0;
n <
objects.size(); ++
n) {
1701 const double deta =
obj.polarP4().eta() -
tau.polarP4().eta();
1704 if (dR2 < inner_dR2)
1705 addObject(
n, deta, dphi, inner_grid);
1706 if (dR2 < outer_dR2)
1707 addObject(
n, deta, dphi, outer_grid);
1712 std::vector<tensorflow::Tensor> pred_vector;
1720 {
"inner_all_dropout_4/Identity"},
1729 {
"outer_all_dropout_4/Identity"},
1732 return pred_vector.at(0);
1735 template <
typename Cand
idateCastType,
typename TauCastType>
1737 const size_t tau_index,
1741 const std::vector<pat::Electron>*
electrons,
1742 const std::vector<pat::Muon>*
muons,
1744 const CellGrid&
grid,
1748 std::cout <<
"<DeepTauId::createConvFeatures (is_inner = " << is_inner <<
")>:" << std::endl;
1750 tensorflow::Tensor& convTensor = *
convTensor_.at(is_inner);
1751 eGammaTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1752 tensorflow::DT_FLOAT,
1753 tensorflow::TensorShape{
1754 (
long long int)
grid.num_valid_cells(), 1, 1, dnn_inputs_2017_v2::EgammaBlockInputs::NumberOfInputs});
1755 muonTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1756 tensorflow::DT_FLOAT,
1757 tensorflow::TensorShape{
1758 (
long long int)
grid.num_valid_cells(), 1, 1, dnn_inputs_2017_v2::MuonBlockInputs::NumberOfInputs});
1760 tensorflow::DT_FLOAT,
1761 tensorflow::TensorShape{
1762 (
long long int)
grid.num_valid_cells(), 1, 1, dnn_inputs_2017_v2::HadronBlockInputs::NumberOfInputs});
1772 std::cout <<
"processing ( eta = " <<
eta <<
", phi = " <<
phi <<
" )" << std::endl;
1774 const CellIndex cell_index{
eta,
phi};
1775 const auto cell_iter =
grid.find(cell_index);
1776 if (cell_iter !=
grid.end()) {
1778 std::cout <<
" creating inputs for ( eta = " <<
eta <<
", phi = " <<
phi <<
" ): idx = " <<
idx
1781 const Cell& cell = cell_iter->second;
1782 createEgammaBlockInputs<CandidateCastType>(
1783 idx,
tau, tau_index, tau_ref,
pv,
rho,
electrons, pfCands, cell, tau_funcs, is_inner);
1784 createMuonBlockInputs<CandidateCastType>(
1785 idx,
tau, tau_index, tau_ref,
pv,
rho,
muons, pfCands, cell, tau_funcs, is_inner);
1786 createHadronsBlockInputs<CandidateCastType>(
1787 idx,
tau, tau_index, tau_ref,
pv,
rho, pfCands, cell, tau_funcs, is_inner);
1791 std::cout <<
" skipping creation of inputs, because ( eta = " <<
eta <<
", phi = " <<
phi
1792 <<
" ) is not in the grid !!" << std::endl;
1802 const CellIndex cell_index{
eta,
phi};
1803 const int eta_index =
grid.getEtaTensorIndex(cell_index);
1804 const int phi_index =
grid.getPhiTensorIndex(cell_index);
1806 const auto cell_iter =
grid.find(cell_index);
1807 if (cell_iter !=
grid.end()) {
1818 const tensorflow::Tensor&
features,
1822 for (
int n = 0;
n < dnn_inputs_2017_v2::number_of_conv_features; ++
n) {
1823 convTensor.tensor<
float, 4>()(0, eta_index, phi_index,
n) =
features.tensor<
float, 4>()(batch_idx, 0, 0,
n);
1827 template <
typename Cand
idateCastType,
typename TauCastType>
1829 const size_t& tau_index,
1833 TauFunc tau_funcs) {
1837 inputs.flat<
float>().setZero();
1839 const auto&
get = [&](
int var_index) ->
float& {
return inputs.matrix<
float>()(0, var_index); };
1841 auto leadChargedHadrCand = dynamic_cast<const CandidateCastType*>(
tau.leadChargedHadrCand().get());
1852 get(dnn::chargedIsoPtSum) =
getValueNorm(tau_funcs.getChargedIsoPtSum(
tau, tau_ref), 47.78f, 123.5f);
1853 get(dnn::chargedIsoPtSumdR03_over_dR05) =
1854 getValue(tau_funcs.getChargedIsoPtSumdR03(
tau, tau_ref) / tau_funcs.getChargedIsoPtSum(
tau, tau_ref));
1855 get(dnn::footprintCorrection) =
getValueNorm(tau_funcs.getFootprintCorrectiondR03(
tau, tau_ref), 9.029f, 26.42f);
1856 get(dnn::neutralIsoPtSum) =
getValueNorm(tau_funcs.getNeutralIsoPtSum(
tau, tau_ref), 57.59f, 155.3f);
1857 get(dnn::neutralIsoPtSumWeight_over_neutralIsoPtSum) =
1858 getValue(tau_funcs.getNeutralIsoPtSumWeight(
tau, tau_ref) / tau_funcs.getNeutralIsoPtSum(
tau, tau_ref));
1859 get(dnn::neutralIsoPtSumWeightdR03_over_neutralIsoPtSum) =
1860 getValue(tau_funcs.getNeutralIsoPtSumdR03Weight(
tau, tau_ref) / tau_funcs.getNeutralIsoPtSum(
tau, tau_ref));
1861 get(dnn::neutralIsoPtSumdR03_over_dR05) =
1862 getValue(tau_funcs.getNeutralIsoPtSumdR03(
tau, tau_ref) / tau_funcs.getNeutralIsoPtSum(
tau, tau_ref));
1863 get(dnn::photonPtSumOutsideSignalCone) =
1864 getValueNorm(tau_funcs.getPhotonPtSumOutsideSignalCone(
tau, tau_ref), 1.731f, 6.846f);
1865 get(dnn::puCorrPtSum) =
getValueNorm(tau_funcs.getPuCorrPtSum(
tau, tau_ref), 22.38f, 16.34f);
1871 auto const pca = tau_funcs.getdxyPCA(
tau, tau_index);
1876 get(dnn::tau_dxy_pca_x) = 0;
1877 get(dnn::tau_dxy_pca_y) = 0;
1878 get(dnn::tau_dxy_pca_z) = 0;
1880 const bool tau_dxy_valid =
1881 isAbove(tau_funcs.getdxy(
tau, tau_index), -10) &&
isAbove(tau_funcs.getdxyError(
tau, tau_index), 0);
1882 if (tau_dxy_valid) {
1883 get(dnn::tau_dxy_valid) = tau_dxy_valid;
1884 get(dnn::tau_dxy) =
getValueNorm(tau_funcs.getdxy(
tau, tau_index), 0.0018f, 0.0085f);
1886 std::abs(tau_funcs.getdxy(
tau, tau_index)) / tau_funcs.getdxyError(
tau, tau_index), 2.26f, 4.191f);
1888 const bool tau_ip3d_valid =
1889 isAbove(tau_funcs.getip3d(
tau, tau_index), -10) &&
isAbove(tau_funcs.getip3dError(
tau, tau_index), 0);
1890 if (tau_ip3d_valid) {
1891 get(dnn::tau_ip3d_valid) = tau_ip3d_valid;
1892 get(dnn::tau_ip3d) =
getValueNorm(tau_funcs.getip3d(
tau, tau_index), 0.0026f, 0.0114f);
1894 std::abs(tau_funcs.getip3d(
tau, tau_index)) / tau_funcs.getip3dError(
tau, tau_index), 2.928f, 4.466f);
1896 if (leadChargedHadrCand) {
1897 const bool hasTrackDetails = candFunc::getHasTrackDetails(*leadChargedHadrCand);
1898 const float tau_dz = (
is_online_ && !hasTrackDetails) ? 0 : candFunc::getTauDz(*leadChargedHadrCand);
1900 get(dnn::tau_dz_sig_valid) = candFunc::getTauDZSigValid(*leadChargedHadrCand);
1901 const double dzError = hasTrackDetails ? leadChargedHadrCand->dzError() : -999.;
1904 get(dnn::tau_flightLength_x) =
getValueNorm(tau_funcs.getFlightLength(
tau, tau_index).x(), -0.0003f, 0.7362f);
1905 get(dnn::tau_flightLength_y) =
getValueNorm(tau_funcs.getFlightLength(
tau, tau_index).y(), -0.0009f, 0.7354f);
1906 get(dnn::tau_flightLength_z) =
getValueNorm(tau_funcs.getFlightLength(
tau, tau_index).z(), -0.0022f, 1.993f);
1907 get(dnn::tau_flightLength_sig) = 0.55756444;
1908 get(dnn::tau_pt_weighted_deta_strip) =
1911 get(dnn::tau_pt_weighted_dphi_strip) =
1913 get(dnn::tau_pt_weighted_dr_signal) =
1916 get(dnn::tau_leadingTrackNormChi2) =
getValueNorm(tau_funcs.getLeadingTrackNormChi2(
tau), 1.538f, 4.401f);
1918 const bool tau_e_ratio_valid = std::isnormal(
eratio) &&
eratio > 0.f;
1919 get(dnn::tau_e_ratio_valid) = tau_e_ratio_valid;
1922 const bool tau_gj_angle_diff_valid = (std::isnormal(gj_angle_diff) || gj_angle_diff == 0) && gj_angle_diff >= 0;
1923 get(dnn::tau_gj_angle_diff_valid) = tau_gj_angle_diff_valid;
1924 get(dnn::tau_gj_angle_diff) = tau_gj_angle_diff_valid ?
getValueLinear(gj_angle_diff, 0,
pi,
true) : 0;
1929 get(dnn::leadChargedCand_etaAtEcalEntrance_minus_tau_eta) =
1930 getValueNorm(tau_funcs.getEtaAtEcalEntrance(
tau) -
tau.p4().eta(), 0.0042f, 0.0323f);
1933 template <
typename Cand
idateCastType,
typename TauCastType>
1935 const TauCastType&
tau,
1936 const size_t tau_index,
1940 const std::vector<pat::Electron>*
electrons,
1942 const Cell& cell_map,
1949 const auto&
get = [&](
int var_index) ->
float& {
return inputs.tensor<
float, 4>()(
idx, 0, 0, var_index); };
1951 const bool valid_index_pf_ele = cell_map.count(CellObjectType::PfCand_electron);
1952 const bool valid_index_pf_gamma = cell_map.count(CellObjectType::PfCand_gamma);
1955 if (!cell_map.empty()) {
1961 if (valid_index_pf_ele) {
1962 size_t index_pf_ele = cell_map.at(CellObjectType::PfCand_electron);
1963 const auto& ele_cand = dynamic_cast<const CandidateCastType&>(pfCands.
at(index_pf_ele));
1965 get(dnn::pfCand_ele_valid) = valid_index_pf_ele;
1966 get(dnn::pfCand_ele_rel_pt) =
getValueNorm(pfCands.
at(index_pf_ele).polarP4().pt() /
tau.polarP4().pt(),
1967 is_inner ? 0.9792f : 0.304f,
1968 is_inner ? 0.5383f : 1.845f);
1969 get(dnn::pfCand_ele_deta) =
getValueLinear(pfCands.
at(index_pf_ele).polarP4().eta() -
tau.polarP4().eta(),
1970 is_inner ? -0.1f : -0.5f,
1971 is_inner ? 0.1f : 0.5f,
1974 is_inner ? -0.1
f : -0.5
f,
1975 is_inner ? 0.1
f : 0.5
f,
1977 get(dnn::pfCand_ele_pvAssociationQuality) =
1978 getValueLinear<int>(candFunc::getPvAssocationQuality(ele_cand), 0, 7,
true);
1979 get(dnn::pfCand_ele_puppiWeight) = is_inner ?
getValue(candFunc::getPuppiWeight(ele_cand, 0.9906834
f))
1980 :
getValue(candFunc::getPuppiWeight(ele_cand, 0.9669586
f));
1981 get(dnn::pfCand_ele_charge) =
getValue(ele_cand.charge());
1982 get(dnn::pfCand_ele_lostInnerHits) = getValue<int>(candFunc::getLostInnerHits(ele_cand, 0));
1983 get(dnn::pfCand_ele_numberOfPixelHits) =
getValueLinear(candFunc::getNumberOfPixelHits(ele_cand, 0), 0, 10,
true);
1984 get(dnn::pfCand_ele_vertex_dx) =
1985 getValueNorm(pfCands.
at(index_pf_ele).vertex().x() -
pv.position().x(), 0.f, 0.1221f);
1986 get(dnn::pfCand_ele_vertex_dy) =
1987 getValueNorm(pfCands.
at(index_pf_ele).vertex().y() -
pv.position().y(), 0.f, 0.1226f);
1988 get(dnn::pfCand_ele_vertex_dz) =
1989 getValueNorm(pfCands.
at(index_pf_ele).vertex().z() -
pv.position().z(), 0.001f, 1.024f);
1991 pfCands.
at(index_pf_ele).vertex().x() -
pv.position().x() - tau_funcs.getFlightLength(
tau, tau_index).x(),
1995 pfCands.
at(index_pf_ele).vertex().y() -
pv.position().y() - tau_funcs.getFlightLength(
tau, tau_index).y(),
1999 pfCands.
at(index_pf_ele).vertex().z() -
pv.position().z() - tau_funcs.getFlightLength(
tau, tau_index).z(),
2003 const bool hasTrackDetails = candFunc::getHasTrackDetails(ele_cand);
2004 if (hasTrackDetails) {
2005 get(dnn::pfCand_ele_hasTrackDetails) = hasTrackDetails;
2006 get(dnn::pfCand_ele_dxy) =
getValueNorm(candFunc::getTauDxy(ele_cand), 0.
f, 0.171
f);
2007 get(dnn::pfCand_ele_dxy_sig) =
2008 getValueNorm(
std::abs(candFunc::getTauDxy(ele_cand)) / pfCands.
at(index_pf_ele).dxyError(), 1.634f, 6.45f);
2009 get(dnn::pfCand_ele_dz) =
getValueNorm(candFunc::getTauDz(ele_cand), 0.001
f, 1.02
f);
2010 get(dnn::pfCand_ele_dz_sig) =
2013 candFunc::getPseudoTrack(ele_cand).
chi2() / candFunc::getPseudoTrack(ele_cand).
ndof(), 2.272
f, 8.439
f);
2014 get(dnn::pfCand_ele_track_ndof) =
getValueNorm(candFunc::getPseudoTrack(ele_cand).
ndof(), 15.18
f, 3.203
f);
2017 if (valid_index_pf_gamma) {
2018 size_t index_pf_gamma = cell_map.at(CellObjectType::PfCand_gamma);
2019 const auto& gamma_cand = dynamic_cast<const CandidateCastType&>(pfCands.
at(index_pf_gamma));
2021 get(dnn::pfCand_gamma_valid) = valid_index_pf_gamma;
2022 get(dnn::pfCand_gamma_rel_pt) =
getValueNorm(pfCands.
at(index_pf_gamma).polarP4().pt() /
tau.polarP4().pt(),
2023 is_inner ? 0.6048f : 0.02576f,
2024 is_inner ? 1.669f : 0.3833f);
2025 get(dnn::pfCand_gamma_deta) =
getValueLinear(pfCands.
at(index_pf_gamma).polarP4().eta() -
tau.polarP4().eta(),
2026 is_inner ? -0.1f : -0.5f,
2027 is_inner ? 0.1f : 0.5f,
2030 is_inner ? -0.1
f : -0.5
f,
2031 is_inner ? 0.1
f : 0.5
f,
2033 get(dnn::pfCand_gamma_pvAssociationQuality) =
2034 getValueLinear<int>(candFunc::getPvAssocationQuality(gamma_cand), 0, 7,
true);
2035 get(dnn::pfCand_gamma_fromPV) = getValueLinear<int>(candFunc::getFromPV(gamma_cand), 0, 3,
true);
2036 get(dnn::pfCand_gamma_puppiWeight) = is_inner ?
getValue(candFunc::getPuppiWeight(gamma_cand, 0.9084110
f))
2037 :
getValue(candFunc::getPuppiWeight(gamma_cand, 0.4211567
f));
2038 get(dnn::pfCand_gamma_puppiWeightNoLep) = is_inner
2039 ?
getValue(candFunc::getPuppiWeightNoLep(gamma_cand, 0.8857716
f))
2040 :
getValue(candFunc::getPuppiWeightNoLep(gamma_cand, 0.3822604
f));
2041 get(dnn::pfCand_gamma_lostInnerHits) = getValue<int>(candFunc::getLostInnerHits(gamma_cand, 0));
2042 get(dnn::pfCand_gamma_numberOfPixelHits) =
2043 getValueLinear(candFunc::getNumberOfPixelHits(gamma_cand, 0), 0, 7,
true);
2044 get(dnn::pfCand_gamma_vertex_dx) =
2045 getValueNorm(pfCands.
at(index_pf_gamma).vertex().x() -
pv.position().x(), 0.f, 0.0067f);
2046 get(dnn::pfCand_gamma_vertex_dy) =
2047 getValueNorm(pfCands.
at(index_pf_gamma).vertex().y() -
pv.position().y(), 0.f, 0.0069f);
2048 get(dnn::pfCand_gamma_vertex_dz) =
2049 getValueNorm(pfCands.
at(index_pf_gamma).vertex().z() -
pv.position().z(), 0.f, 0.0578f);
2051 pfCands.
at(index_pf_gamma).vertex().x() -
pv.position().x() - tau_funcs.getFlightLength(
tau, tau_index).x(),
2055 pfCands.
at(index_pf_gamma).vertex().y() -
pv.position().y() - tau_funcs.getFlightLength(
tau, tau_index).y(),
2059 pfCands.
at(index_pf_gamma).vertex().z() -
pv.position().z() - tau_funcs.getFlightLength(
tau, tau_index).z(),
2062 const bool hasTrackDetails = candFunc::getHasTrackDetails(gamma_cand);
2063 if (hasTrackDetails) {
2064 get(dnn::pfCand_gamma_hasTrackDetails) = hasTrackDetails;
2065 get(dnn::pfCand_gamma_dxy) =
getValueNorm(candFunc::getTauDxy(gamma_cand), 0.0004
f, 0.882
f);
2066 get(dnn::pfCand_gamma_dxy_sig) =
2067 getValueNorm(
std::abs(candFunc::getTauDxy(gamma_cand)) / gamma_cand.dxyError(), 4.271f, 63.78f);
2068 get(dnn::pfCand_gamma_dz) =
getValueNorm(candFunc::getTauDz(gamma_cand), 0.0071
f, 5.285
f);
2069 get(dnn::pfCand_gamma_dz_sig) =
2071 get(dnn::pfCand_gamma_track_chi2_ndof) = candFunc::getPseudoTrack(gamma_cand).ndof() > 0
2073 candFunc::getPseudoTrack(gamma_cand).
ndof(),
2077 get(dnn::pfCand_gamma_track_ndof) =
2078 candFunc::getPseudoTrack(gamma_cand).ndof() > 0
2083 if (valid_index_ele) {
2086 get(dnn::ele_valid) = valid_index_ele;
2088 is_inner ? 1.067f : 0.5111f,
2089 is_inner ? 1.521f : 2.765f);
2091 is_inner ? -0.1f : -0.5f,
2092 is_inner ? 0.1f : 0.5f,
2095 is_inner ? -0.1
f : -0.5
f,
2096 is_inner ? 0.1
f : 0.5
f,
2099 float cc_ele_energy, cc_gamma_energy;
2101 const bool cc_valid =
2104 get(dnn::ele_cc_valid) = cc_valid;
2105 get(dnn::ele_cc_ele_rel_energy) =
2107 get(dnn::ele_cc_gamma_rel_energy) =
getValueNorm(cc_gamma_energy / cc_ele_energy, 0.1439
f, 0.3284
f);
2111 electrons->at(index_ele).trackMomentumAtVtx().R() /
electrons->at(index_ele).polarP4().pt(), 1.531f, 1.424f);
2113 electrons->at(index_ele).trackMomentumAtCalo().R() /
electrons->at(index_ele).polarP4().pt(), 1.531f, 1.424f);
2115 electrons->at(index_ele).trackMomentumOut().R() /
electrons->at(index_ele).polarP4().pt(), 0.7735f, 0.935f);
2116 get(dnn::ele_rel_trackMomentumAtEleClus) =
2121 electrons->at(index_ele).trackMomentumAtVtxWithConstraint().R() /
electrons->at(index_ele).polarP4().pt(),
2124 get(dnn::ele_rel_ecalEnergy) =
2127 electrons->at(index_ele).ecalEnergy() /
electrons->at(index_ele).ecalEnergyError(), 70.25f, 58.16f);
2132 get(dnn::ele_deltaEtaSuperClusterTrackAtVtx) =
2134 get(dnn::ele_deltaEtaSeedClusterTrackAtCalo) =
2136 get(dnn::ele_deltaEtaEleClusterTrackAtCalo) =
2138 get(dnn::ele_deltaPhiEleClusterTrackAtCalo) =
2140 get(dnn::ele_deltaPhiSuperClusterTrackAtVtx) =
2142 get(dnn::ele_deltaPhiSeedClusterTrackAtCalo) =
2146 get(dnn::ele_mvaInput_sigmaEtaEta) =
2150 const auto& gsfTrack =
electrons->at(index_ele).gsfTrack();
2151 if (gsfTrack.isNonnull()) {
2152 get(dnn::ele_gsfTrack_normalizedChi2) =
getValueNorm(gsfTrack->normalizedChi2(), 3.049f, 10.39f);
2153 get(dnn::ele_gsfTrack_numberOfValidHits) =
getValueNorm(gsfTrack->numberOfValidHits(), 16.52f, 2.806f);
2154 get(dnn::ele_rel_gsfTrack_pt) =
2156 get(dnn::ele_gsfTrack_pt_sig) =
getValueNorm(gsfTrack->pt() / gsfTrack->ptError(), 5.046f, 3.119f);
2158 const auto& closestCtfTrack =
electrons->at(index_ele).closestCtfTrackRef();
2159 const bool has_closestCtfTrack = closestCtfTrack.isNonnull();
2160 if (has_closestCtfTrack) {
2161 get(dnn::ele_has_closestCtfTrack) = has_closestCtfTrack;
2162 get(dnn::ele_closestCtfTrack_normalizedChi2) =
getValueNorm(closestCtfTrack->normalizedChi2(), 2.411f, 6.98f);
2163 get(dnn::ele_closestCtfTrack_numberOfValidHits) =
2164 getValueNorm(closestCtfTrack->numberOfValidHits(), 15.16f, 5.26f);
2169 template <
typename Cand
idateCastType,
typename TauCastType>
2171 const TauCastType&
tau,
2172 const size_t tau_index,
2176 const std::vector<pat::Muon>*
muons,
2178 const Cell& cell_map,
2185 const auto&
get = [&](
int var_index) ->
float& {
return inputs.tensor<
float, 4>()(
idx, 0, 0, var_index); };
2187 const bool valid_index_pf_muon = cell_map.count(CellObjectType::PfCand_muon);
2190 if (!cell_map.empty()) {
2196 if (valid_index_pf_muon) {
2197 size_t index_pf_muon = cell_map.at(CellObjectType::PfCand_muon);
2198 const auto& muon_cand = dynamic_cast<const CandidateCastType&>(pfCands.
at(index_pf_muon));
2200 get(dnn::pfCand_muon_valid) = valid_index_pf_muon;
2201 get(dnn::pfCand_muon_rel_pt) =
getValueNorm(pfCands.
at(index_pf_muon).polarP4().pt() /
tau.polarP4().pt(),
2202 is_inner ? 0.9509f : 0.0861f,
2203 is_inner ? 0.4294f : 0.4065f);
2204 get(dnn::pfCand_muon_deta) =
getValueLinear(pfCands.
at(index_pf_muon).polarP4().eta() -
tau.polarP4().eta(),
2205 is_inner ? -0.1f : -0.5f,
2206 is_inner ? 0.1f : 0.5f,
2209 is_inner ? -0.1
f : -0.5
f,
2210 is_inner ? 0.1
f : 0.5
f,
2212 get(dnn::pfCand_muon_pvAssociationQuality) =
2213 getValueLinear<int>(candFunc::getPvAssocationQuality(muon_cand), 0, 7,
true);
2214 get(dnn::pfCand_muon_fromPV) = getValueLinear<int>(candFunc::getFromPV(muon_cand), 0, 3,
true);
2215 get(dnn::pfCand_muon_puppiWeight) = is_inner ?
getValue(candFunc::getPuppiWeight(muon_cand, 0.9786588
f))
2216 :
getValue(candFunc::getPuppiWeight(muon_cand, 0.8132477
f));
2217 get(dnn::pfCand_muon_charge) =
getValue(muon_cand.charge());
2218 get(dnn::pfCand_muon_lostInnerHits) = getValue<int>(candFunc::getLostInnerHits(muon_cand, 0));
2219 get(dnn::pfCand_muon_numberOfPixelHits) =
2220 getValueLinear(candFunc::getNumberOfPixelHits(muon_cand, 0), 0, 11,
true);
2221 get(dnn::pfCand_muon_vertex_dx) =
2222 getValueNorm(pfCands.
at(index_pf_muon).vertex().x() -
pv.position().x(), -0.0007f, 0.6869f);
2223 get(dnn::pfCand_muon_vertex_dy) =
2224 getValueNorm(pfCands.
at(index_pf_muon).vertex().y() -
pv.position().y(), 0.0001f, 0.6784f);
2225 get(dnn::pfCand_muon_vertex_dz) =
2226 getValueNorm(pfCands.
at(index_pf_muon).vertex().z() -
pv.position().z(), -0.0117f, 4.097f);
2228 pfCands.
at(index_pf_muon).vertex().x() -
pv.position().x() - tau_funcs.getFlightLength(
tau, tau_index).x(),
2232 pfCands.
at(index_pf_muon).vertex().y() -
pv.position().y() - tau_funcs.getFlightLength(
tau, tau_index).y(),
2236 pfCands.
at(index_pf_muon).vertex().z() -
pv.position().z() - tau_funcs.getFlightLength(
tau, tau_index).z(),
2240 const bool hasTrackDetails = candFunc::getHasTrackDetails(muon_cand);
2241 if (hasTrackDetails) {
2242 get(dnn::pfCand_muon_hasTrackDetails) = hasTrackDetails;
2243 get(dnn::pfCand_muon_dxy) =
getValueNorm(candFunc::getTauDxy(muon_cand), -0.0045
f, 0.9655
f);
2244 get(dnn::pfCand_muon_dxy_sig) =
2246 get(dnn::pfCand_muon_dz) =
getValueNorm(candFunc::getTauDz(muon_cand), -0.0117
f, 4.097
f);
2247 get(dnn::pfCand_muon_dz_sig) =
2250 candFunc::getPseudoTrack(muon_cand).
chi2() / candFunc::getPseudoTrack(muon_cand).
ndof(), 0.69
f, 1.711
f);
2251 get(dnn::pfCand_muon_track_ndof) =
getValueNorm(candFunc::getPseudoTrack(muon_cand).
ndof(), 17.5
f, 5.11
f);
2254 if (valid_index_muon) {
2257 get(dnn::muon_valid) = valid_index_muon;
2259 is_inner ? 0.7966f : 0.2678f,
2260 is_inner ? 3.402f : 3.592f);
2262 is_inner ? -0.1f : -0.5f,
2263 is_inner ? 0.1f : 0.5f,
2266 is_inner ? -0.1
f : -0.5
f,
2267 is_inner ? 0.1
f : 0.5
f,
2270 get(dnn::muon_dxy_sig) =
2275 const bool normalizedChi2_valid =
2276 muons->at(index_muon).globalTrack().isNonnull() &&
muons->at(index_muon).normChi2() >= 0;
2277 if (normalizedChi2_valid) {
2278 get(dnn::muon_normalizedChi2_valid) = normalizedChi2_valid;
2279 get(dnn::muon_normalizedChi2) =
getValueNorm(
muons->at(index_muon).normChi2(), 21.52f, 265.8f);
2280 if (
muons->at(index_muon).innerTrack().isNonnull())
2281 get(dnn::muon_numberOfValidHits) =
getValueNorm(
muons->at(index_muon).numberOfValidHits(), 21.84f, 10.59f);
2283 get(dnn::muon_segmentCompatibility) =
getValue(
muons->at(index_muon).segmentCompatibility());
2284 get(dnn::muon_caloCompatibility) =
getValue(
muons->at(index_muon).caloCompatibility());
2286 const bool pfEcalEnergy_valid =
muons->at(index_muon).pfEcalEnergy() >= 0;
2287 if (pfEcalEnergy_valid) {
2288 get(dnn::muon_pfEcalEnergy_valid) = pfEcalEnergy_valid;
2289 get(dnn::muon_rel_pfEcalEnergy) =
2290 getValueNorm(
muons->at(index_muon).pfEcalEnergy() /
muons->at(index_muon).polarP4().pt(), 0.2273f, 0.4865f);
2293 MuonHitMatchV2 hit_match(
muons->at(index_muon));
2294 static const std::map<int, std::pair<int, int>> muonMatchHitVars = {
2299 static const std::map<int, std::vector<float>> muonMatchVarLimits = {
2300 {
MuonSubdetId::DT, {2, 2, 2, 2}}, {
MuonSubdetId::CSC, {6, 2, 2, 2}}, {
MuonSubdetId::RPC, {7, 6, 4, 4}}};
2302 static const std::map<int, std::vector<float>> muonHitVarLimits = {{
MuonSubdetId::DT, {12, 12, 12, 8}},
2306 for (
int subdet : hit_match.MuonHitMatchV2::consideredSubdets()) {
2307 const auto& matchHitVar = muonMatchHitVars.at(subdet);
2308 const auto& matchLimits = muonMatchVarLimits.at(subdet);
2309 const auto& hitLimits = muonHitVarLimits.at(subdet);
2310 for (
int station = MuonHitMatchV2::first_station_id;
station <= MuonHitMatchV2::last_station_id; ++
station) {
2311 const unsigned n_matches = hit_match.nMatches(subdet,
station);
2312 const unsigned n_hits = hit_match.nHits(subdet,
station);
2320 template <
typename Cand
idateCastType,
typename TauCastType>
2322 const TauCastType&
tau,
2323 const size_t tau_index,
2328 const Cell& cell_map,
2335 const auto&
get = [&](
int var_index) ->
float& {
return inputs.tensor<
float, 4>()(
idx, 0, 0, var_index); };
2337 const bool valid_chH = cell_map.count(CellObjectType::PfCand_chargedHadron);
2338 const bool valid_nH = cell_map.count(CellObjectType::PfCand_neutralHadron);
2340 if (!cell_map.empty()) {
2347 size_t index_chH = cell_map.at(CellObjectType::PfCand_chargedHadron);
2348 const auto& chH_cand = dynamic_cast<const CandidateCastType&>(pfCands.
at(index_chH));
2350 get(dnn::pfCand_chHad_valid) = valid_chH;
2351 get(dnn::pfCand_chHad_rel_pt) =
getValueNorm(pfCands.
at(index_chH).polarP4().pt() /
tau.polarP4().pt(),
2352 is_inner ? 0.2564f : 0.0194f,
2353 is_inner ? 0.8607f : 0.1865f);
2354 get(dnn::pfCand_chHad_deta) =
getValueLinear(pfCands.
at(index_chH).polarP4().eta() -
tau.polarP4().eta(),
2355 is_inner ? -0.1f : -0.5f,
2356 is_inner ? 0.1f : 0.5f,
2359 is_inner ? -0.1
f : -0.5
f,
2360 is_inner ? 0.1
f : 0.5
f,
2362 get(dnn::pfCand_chHad_leadChargedHadrCand) =
2363 getValue(&chH_cand == dynamic_cast<const CandidateCastType*>(
tau.leadChargedHadrCand().get()));
2364 get(dnn::pfCand_chHad_pvAssociationQuality) =
2365 getValueLinear<int>(candFunc::getPvAssocationQuality(chH_cand), 0, 7,
true);
2366 get(dnn::pfCand_chHad_fromPV) = getValueLinear<int>(candFunc::getFromPV(chH_cand), 0, 3,
true);
2367 const float default_chH_pw_inner = 0.7614090f;
2368 const float default_chH_pw_outer = 0.1974930f;
2369 get(dnn::pfCand_chHad_puppiWeight) = is_inner
2370 ?
getValue(candFunc::getPuppiWeight(chH_cand, default_chH_pw_inner))
2371 :
getValue(candFunc::getPuppiWeight(chH_cand, default_chH_pw_outer));
2372 get(dnn::pfCand_chHad_puppiWeightNoLep) =
2373 is_inner ?
getValue(candFunc::getPuppiWeightNoLep(chH_cand, default_chH_pw_inner))
2374 :
getValue(candFunc::getPuppiWeightNoLep(chH_cand, default_chH_pw_outer));
2375 get(dnn::pfCand_chHad_charge) =
getValue(chH_cand.charge());
2376 get(dnn::pfCand_chHad_lostInnerHits) = getValue<int>(candFunc::getLostInnerHits(chH_cand, 0));
2377 get(dnn::pfCand_chHad_numberOfPixelHits) =
2378 getValueLinear(candFunc::getNumberOfPixelHits(chH_cand, 0), 0, 12,
true);
2379 get(dnn::pfCand_chHad_vertex_dx) =
2380 getValueNorm(pfCands.
at(index_chH).vertex().x() -
pv.position().x(), 0.0005f, 1.735f);
2381 get(dnn::pfCand_chHad_vertex_dy) =
2382 getValueNorm(pfCands.
at(index_chH).vertex().y() -
pv.position().y(), -0.0008f, 1.752f);
2383 get(dnn::pfCand_chHad_vertex_dz) =
2384 getValueNorm(pfCands.
at(index_chH).vertex().z() -
pv.position().z(), -0.0201f, 8.333f);
2386 pfCands.
at(index_chH).vertex().x() -
pv.position().x() - tau_funcs.getFlightLength(
tau, tau_index).x(),
2390 pfCands.
at(index_chH).vertex().y() -
pv.position().y() - tau_funcs.getFlightLength(
tau, tau_index).y(),
2394 pfCands.
at(index_chH).vertex().z() -
pv.position().z() - tau_funcs.getFlightLength(
tau, tau_index).z(),
2398 const bool hasTrackDetails = candFunc::getHasTrackDetails(chH_cand);
2399 if (hasTrackDetails) {
2400 get(dnn::pfCand_chHad_hasTrackDetails) = hasTrackDetails;
2401 get(dnn::pfCand_chHad_dxy) =
getValueNorm(candFunc::getTauDxy(chH_cand), -0.012
f, 2.386
f);
2402 get(dnn::pfCand_chHad_dxy_sig) =
2404 get(dnn::pfCand_chHad_dz) =
getValueNorm(candFunc::getTauDz(chH_cand), -0.0246
f, 7.618
f);
2405 get(dnn::pfCand_chHad_dz_sig) =
2407 get(dnn::pfCand_chHad_track_chi2_ndof) =
2408 candFunc::getPseudoTrack(chH_cand).ndof() > 0
2409 ?
getValueNorm(candFunc::getPseudoTrack(chH_cand).
chi2() / candFunc::getPseudoTrack(chH_cand).
ndof(),
2413 get(dnn::pfCand_chHad_track_ndof) =
2414 candFunc::getPseudoTrack(chH_cand).ndof() > 0
2419 get(dnn::pfCand_chHad_hcalFraction) =
getValue(hcal_fraction);
2420 get(dnn::pfCand_chHad_rawCaloFraction) =
getValueLinear(candFunc::getRawCaloFraction(chH_cand), 0.
f, 2.6
f,
true);
2423 size_t index_nH = cell_map.at(CellObjectType::PfCand_neutralHadron);
2424 const auto& nH_cand = dynamic_cast<const CandidateCastType&>(pfCands.
at(index_nH));
2426 get(dnn::pfCand_nHad_valid) = valid_nH;
2427 get(dnn::pfCand_nHad_rel_pt) =
getValueNorm(pfCands.
at(index_nH).polarP4().pt() /
tau.polarP4().pt(),
2428 is_inner ? 0.3163f : 0.0502f,
2429 is_inner ? 0.2769f : 0.4266f);
2431 is_inner ? -0.1f : -0.5f,
2432 is_inner ? 0.1f : 0.5f,
2435 dPhi(
tau.polarP4(), pfCands.
at(index_nH).polarP4()), is_inner ? -0.1
f : -0.5
f, is_inner ? 0.1
f : 0.5
f,
false);
2436 get(dnn::pfCand_nHad_puppiWeight) = is_inner ?
getValue(candFunc::getPuppiWeight(nH_cand, 0.9798355
f))
2437 :
getValue(candFunc::getPuppiWeight(nH_cand, 0.7813260
f));
2438 get(dnn::pfCand_nHad_puppiWeightNoLep) = is_inner ?
getValue(candFunc::getPuppiWeightNoLep(nH_cand, 0.9046796
f))
2439 :
getValue(candFunc::getPuppiWeightNoLep(nH_cand, 0.6554860
f));
2441 get(dnn::pfCand_nHad_hcalFraction) =
getValue(hcal_fraction);
2445 template <
typename dnn,
typename Cand
idateCastType,
typename TauCastType>
2447 const size_t tau_index,
2449 const std::vector<pat::Electron>*
electrons,
2450 const std::vector<pat::Muon>*
muons,
2451 TauFunc tau_funcs)
const {
2452 static constexpr
bool check_all_set =
false;
2453 static constexpr
float default_value_for_set_check = -42;
2455 tensorflow::Tensor
inputs(tensorflow::DT_FLOAT, {1, dnn_inputs_2017v1::NumberOfInputs});
2456 const auto&
get = [&](
int var_index) ->
float& {
return inputs.matrix<
float>()(0, var_index); };
2457 auto leadChargedHadrCand = dynamic_cast<const CandidateCastType*>(
tau.leadChargedHadrCand().get());
2459 if (check_all_set) {
2460 for (
int var_index = 0; var_index < dnn::NumberOfInputs; ++var_index) {
2461 get(var_index) = default_value_for_set_check;
2469 get(dnn::chargedIsoPtSum) = tau_funcs.getChargedIsoPtSum(
tau, tau_ref);
2470 get(dnn::neutralIsoPtSum) = tau_funcs.getNeutralIsoPtSum(
tau, tau_ref);
2471 get(dnn::neutralIsoPtSumWeight) = tau_funcs.getNeutralIsoPtSumWeight(
tau, tau_ref);
2472 get(dnn::photonPtSumOutsideSignalCone) = tau_funcs.getPhotonPtSumOutsideSignalCone(
tau, tau_ref);
2473 get(dnn::puCorrPtSum) = tau_funcs.getPuCorrPtSum(
tau, tau_ref);
2475 get(dnn::dxy_sig) = tau_funcs.getdxySig(
tau, tau_index);
2478 get(dnn::ip3d_sig) = tau_funcs.getip3dSig(
tau, tau_index);
2479 get(dnn::hasSecondaryVertex) = tau_funcs.getHasSecondaryVertex(
tau, tau_index);
2480 get(dnn::flightLength_r) = tau_funcs.getFlightLength(
tau, tau_index).R();
2481 get(dnn::flightLength_dEta) =
dEta(tau_funcs.getFlightLength(
tau, tau_index),
tau.p4());
2482 get(dnn::flightLength_dPhi) =
dPhi(tau_funcs.getFlightLength(
tau, tau_index),
tau.p4());
2483 get(dnn::flightLength_sig) = tau_funcs.getFlightLengthSig(
tau, tau_index);
2484 get(dnn::leadChargedHadrCand_pt) = leadChargedHadrCand ? leadChargedHadrCand->p4().Pt() :
default_value;
2485 get(dnn::leadChargedHadrCand_dEta) =
2487 get(dnn::leadChargedHadrCand_dPhi) =
2489 get(dnn::leadChargedHadrCand_mass) = leadChargedHadrCand ? leadChargedHadrCand->p4().mass() :
default_value;
2494 get(dnn::leadingTrackNormChi2) = tau_funcs.getLeadingTrackNormChi2(
tau);
2498 get(dnn::emFraction) = tau_funcs.getEmFraction(
tau);
2499 get(dnn::has_gsf_track) = leadChargedHadrCand &&
std::abs(leadChargedHadrCand->pdgId()) == 11;
2502 get(dnn::gsf_ele_matched) = gsf_ele !=
nullptr;
2503 get(dnn::gsf_ele_pt) = gsf_ele !=
nullptr ? gsf_ele->p4().Pt() :
default_value;
2506 get(dnn::gsf_ele_mass) = gsf_ele !=
nullptr ? gsf_ele->p4().mass() :
default_value;
2508 get(dnn::gsf_ele_Pin) = gsf_ele !=
nullptr ? gsf_ele->trackMomentumAtVtx().R() :
default_value;
2509 get(dnn::gsf_ele_Pout) = gsf_ele !=
nullptr ? gsf_ele->trackMomentumOut().R() :
default_value;
2510 get(dnn::gsf_ele_EtotOverPin) =
get(dnn::gsf_ele_Pin) > 0
2511 ? (
get(dnn::gsf_ele_Ee) +
get(dnn::gsf_ele_Egamma)) /
get(dnn::gsf_ele_Pin)
2513 get(dnn::gsf_ele_Eecal) = gsf_ele !=
nullptr ? gsf_ele->ecalEnergy() :
default_value;
2514 get(dnn::gsf_ele_dEta_SeedClusterTrackAtCalo) =
2515 gsf_ele !=
nullptr ? gsf_ele->deltaEtaSeedClusterTrackAtCalo() :
default_value;
2516 get(dnn::gsf_ele_dPhi_SeedClusterTrackAtCalo) =
2517 gsf_ele !=
nullptr ? gsf_ele->deltaPhiSeedClusterTrackAtCalo() :
default_value;
2518 get(dnn::gsf_ele_mvaIn_sigmaEtaEta) = gsf_ele !=
nullptr ? gsf_ele->mvaInput().sigmaEtaEta :
default_value;
2519 get(dnn::gsf_ele_mvaIn_hadEnergy) = gsf_ele !=
nullptr ? gsf_ele->mvaInput().hadEnergy :
default_value;
2520 get(dnn::gsf_ele_mvaIn_deltaEta) = gsf_ele !=
nullptr ? gsf_ele->mvaInput().deltaEta :
default_value;
2526 if (gsf_ele !=
nullptr && gsf_ele->gsfTrack().isNonnull()) {
2527 get(dnn::gsf_ele_Chi2NormGSF) = gsf_ele->gsfTrack()->normalizedChi2();
2528 get(dnn::gsf_ele_GSFNumHits) = gsf_ele->gsfTrack()->numberOfValidHits();
2529 if (gsf_ele->gsfTrack()->pt() > 0) {
2530 get(dnn::gsf_ele_GSFTrackResol) = gsf_ele->gsfTrack()->ptError() / gsf_ele->gsfTrack()->pt();
2531 get(dnn::gsf_ele_GSFTracklnPt) = std::log10(gsf_ele->gsfTrack()->pt());
2537 if (gsf_ele !=
nullptr && gsf_ele->closestCtfTrackRef().isNonnull()) {
2538 get(dnn::gsf_ele_Chi2NormKF) = gsf_ele->closestCtfTrackRef()->normalizedChi2();
2539 get(dnn::gsf_ele_KFNumHits) = gsf_ele->closestCtfTrackRef()->numberOfValidHits();
2541 get(dnn::leadChargedCand_etaAtEcalEntrance) = tau_funcs.getEtaAtEcalEntrance(
tau);
2542 get(dnn::leadChargedCand_pt) = leadChargedHadrCand->pt();
2546 if (leadChargedHadrCand->pt() > 0) {
2547 get(dnn::leadChargedHadrCand_HoP) = tau_funcs.getEcalEnergyLeadingChargedHadr(
tau) / leadChargedHadrCand->pt();
2548 get(dnn::leadChargedHadrCand_EoP) = tau_funcs.getHcalEnergyLeadingChargedHadr(
tau) / leadChargedHadrCand->pt();
2551 MuonHitMatchV1 muon_hit_match;
2552 if (
tau.leadPFChargedHadrCand().isNonnull() &&
tau.leadPFChargedHadrCand()->muonRef().isNonnull())
2553 muon_hit_match.addMatchedMuon(*
tau.leadPFChargedHadrCand()->muonRef(),
tau);
2555 auto matched_muons = muon_hit_match.findMatchedMuons(
tau,
muons, 0.3, 5);
2556 for (
auto muon : matched_muons)
2557 muon_hit_match.addMatchedMuon(*
muon,
tau);
2560 LorentzVectorXYZ signalChargedHadrCands_sumIn, signalChargedHadrCands_sumOut;
2562 tau.signalChargedHadrCands(),
2563 signalChargedHadrCands_sumIn,
2564 signalChargedHadrCands_sumOut,
2565 get(dnn::signalChargedHadrCands_sum_innerSigCone_pt),
2566 get(dnn::signalChargedHadrCands_sum_innerSigCone_dEta),
2567 get(dnn::signalChargedHadrCands_sum_innerSigCone_dPhi),
2568 get(dnn::signalChargedHadrCands_sum_innerSigCone_mass),
2569 get(dnn::signalChargedHadrCands_sum_outerSigCone_pt),
2570 get(dnn::signalChargedHadrCands_sum_outerSigCone_dEta),
2571 get(dnn::signalChargedHadrCands_sum_outerSigCone_dPhi),
2572 get(dnn::signalChargedHadrCands_sum_outerSigCone_mass),
2573 get(dnn::signalChargedHadrCands_nTotal_innerSigCone),
2574 get(dnn::signalChargedHadrCands_nTotal_outerSigCone));
2578 tau.signalNeutrHadrCands(),
2579 signalNeutrHadrCands_sumIn,
2580 signalNeutrHadrCands_sumOut,
2581 get(dnn::signalNeutrHadrCands_sum_innerSigCone_pt),
2582 get(dnn::signalNeutrHadrCands_sum_innerSigCone_dEta),
2583 get(dnn::signalNeutrHadrCands_sum_innerSigCone_dPhi),
2584 get(dnn::signalNeutrHadrCands_sum_innerSigCone_mass),
2585 get(dnn::signalNeutrHadrCands_sum_outerSigCone_pt),
2586 get(dnn::signalNeutrHadrCands_sum_outerSigCone_dEta),
2587 get(dnn::signalNeutrHadrCands_sum_outerSigCone_dPhi),
2588 get(dnn::signalNeutrHadrCands_sum_outerSigCone_mass),
2589 get(dnn::signalNeutrHadrCands_nTotal_innerSigCone),
2590 get(dnn::signalNeutrHadrCands_nTotal_outerSigCone));
2594 tau.signalGammaCands(),
2595 signalGammaCands_sumIn,
2596 signalGammaCands_sumOut,
2597 get(dnn::signalGammaCands_sum_innerSigCone_pt),
2598 get(dnn::signalGammaCands_sum_innerSigCone_dEta),
2599 get(dnn::signalGammaCands_sum_innerSigCone_dPhi),
2600 get(dnn::signalGammaCands_sum_innerSigCone_mass),
2601 get(dnn::signalGammaCands_sum_outerSigCone_pt),
2602 get(dnn::signalGammaCands_sum_outerSigCone_dEta),
2603 get(dnn::signalGammaCands_sum_outerSigCone_dPhi),
2604 get(dnn::signalGammaCands_sum_outerSigCone_mass),
2605 get(dnn::signalGammaCands_nTotal_innerSigCone),
2606 get(dnn::signalGammaCands_nTotal_outerSigCone));
2610 tau.isolationChargedHadrCands(),
2611 isolationChargedHadrCands_sum,
2612 get(dnn::isolationChargedHadrCands_sum_pt),
2613 get(dnn::isolationChargedHadrCands_sum_dEta),
2614 get(dnn::isolationChargedHadrCands_sum_dPhi),
2615 get(dnn::isolationChargedHadrCands_sum_mass),
2616 get(dnn::isolationChargedHadrCands_nTotal));
2620 tau.isolationNeutrHadrCands(),
2621 isolationNeutrHadrCands_sum,
2622 get(dnn::isolationNeutrHadrCands_sum_pt),
2623 get(dnn::isolationNeutrHadrCands_sum_dEta),
2624 get(dnn::isolationNeutrHadrCands_sum_dPhi),
2625 get(dnn::isolationNeutrHadrCands_sum_mass),
2626 get(dnn::isolationNeutrHadrCands_nTotal));
2630 tau.isolationGammaCands(),
2631 isolationGammaCands_sum,
2632 get(dnn::isolationGammaCands_sum_pt),
2633 get(dnn::isolationGammaCands_sum_dEta),
2634 get(dnn::isolationGammaCands_sum_dPhi),
2635 get(dnn::isolationGammaCands_sum_mass),
2636 get(dnn::isolationGammaCands_nTotal));
2638 get(dnn::tau_visMass_innerSigCone) = (signalGammaCands_sumIn + signalChargedHadrCands_sumIn).
mass();
2640 if (check_all_set) {
2641 for (
int var_index = 0; var_index < dnn::NumberOfInputs; ++var_index) {
2642 if (
get(var_index) == default_value_for_set_check)
2643 throw cms::Exception(
"DeepTauId: variable with index = ") << var_index <<
" is not set.";
2652 elecEe = elecEgamma = 0;
2654 if (superCluster.isNonnull() && superCluster.isAvailable() && superCluster->clusters().isNonnull() &&
2655 superCluster->clusters().isAvailable()) {
2656 for (
auto iter = superCluster->clustersBegin(); iter != superCluster->clustersEnd(); ++iter) {
2657 const double energy = (*iter)->energy();
2658 if (iter == superCluster->clustersBegin())
2669 template <
typename Cand
idateCollection,
typename TauCastType>
2692 const bool isInside_innerSigCone =
dR < innerSigCone_radius;
2693 if (isInside_innerSigCone) {
2694 p4_inner +=
cand->p4();
2697 p4_outer +=
cand->p4();
2713 template <
typename Cand
idateCollection,
typename TauCastType>
2737 static constexpr
double min_pt = 30., min_radius = 0.05, cone_opening_coef = 3.;
2743 template <
typename TauCastType>
2745 const size_t tau_index,
2747 TauFunc tau_funcs) {
2748 if (tau_funcs.getHasSecondaryVertex(
tau, tau_index)) {
2749 static constexpr
double mTau = 1.77682;
2750 const double mAOne =
tau.p4().M();
2751 const double pAOneMag =
tau.p();
2752 const double argumentThetaGJmax = (
std::pow(mTau, 2) -
std::pow(mAOne, 2)) / (2 * mTau * pAOneMag);
2753 const double argumentThetaGJmeasured =
tau.p4().Vect().Dot(tau_funcs.getFlightLength(
tau, tau_index)) /
2754 (pAOneMag * tau_funcs.getFlightLength(
tau, tau_index).R());
2755 if (
std::abs(argumentThetaGJmax) <= 1. &&
std::abs(argumentThetaGJmeasured) <= 1.) {
2756 double thetaGJmax = std::asin(argumentThetaGJmax);
2757 double thetaGJmeasured = std::acos(argumentThetaGJmeasured);
2758 gj_diff = thetaGJmeasured - thetaGJmax;
2765 template <
typename TauCastType>
2767 const size_t tau_index,
2768 TauFunc tau_funcs) {
2771 return static_cast<float>(gj_diff);
2777 return abs_eta > 1.46 && abs_eta < 1.558;
2780 template <
typename TauCastType>
2782 const std::vector<pat::Electron>*
electrons,
2787 if (
reco::deltaR2(
tau.p4(), ele.p4()) < dR2 && (!matched_ele || matched_ele->
pt() < ele.pt())) {