16 #include "tbb/concurrent_unordered_set.h"
24 struct dnn_inputs_2017v1 {
32 neutralIsoPtSumWeight,
33 photonPtSumOutsideSignalCone,
45 leadChargedHadrCand_pt,
46 leadChargedHadrCand_dEta,
47 leadChargedHadrCand_dPhi,
48 leadChargedHadrCand_mass,
71 gsf_ele_dEta_SeedClusterTrackAtCalo,
72 gsf_ele_dPhi_SeedClusterTrackAtCalo,
73 gsf_ele_mvaIn_sigmaEtaEta,
74 gsf_ele_mvaIn_hadEnergy,
75 gsf_ele_mvaIn_deltaEta,
78 gsf_ele_GSFTrackResol,
82 leadChargedCand_etaAtEcalEntrance,
84 leadChargedHadrCand_HoP,
85 leadChargedHadrCand_EoP,
86 tau_visMass_innerSigCone,
108 muon_n_stations_with_matches_03,
109 muon_n_stations_with_hits_23,
110 signalChargedHadrCands_sum_innerSigCone_pt,
111 signalChargedHadrCands_sum_innerSigCone_dEta,
112 signalChargedHadrCands_sum_innerSigCone_dPhi,
113 signalChargedHadrCands_sum_innerSigCone_mass,
114 signalChargedHadrCands_sum_outerSigCone_pt,
115 signalChargedHadrCands_sum_outerSigCone_dEta,
116 signalChargedHadrCands_sum_outerSigCone_dPhi,
117 signalChargedHadrCands_sum_outerSigCone_mass,
118 signalChargedHadrCands_nTotal_innerSigCone,
119 signalChargedHadrCands_nTotal_outerSigCone,
120 signalNeutrHadrCands_sum_innerSigCone_pt,
121 signalNeutrHadrCands_sum_innerSigCone_dEta,
122 signalNeutrHadrCands_sum_innerSigCone_dPhi,
123 signalNeutrHadrCands_sum_innerSigCone_mass,
124 signalNeutrHadrCands_sum_outerSigCone_pt,
125 signalNeutrHadrCands_sum_outerSigCone_dEta,
126 signalNeutrHadrCands_sum_outerSigCone_dPhi,
127 signalNeutrHadrCands_sum_outerSigCone_mass,
128 signalNeutrHadrCands_nTotal_innerSigCone,
129 signalNeutrHadrCands_nTotal_outerSigCone,
130 signalGammaCands_sum_innerSigCone_pt,
131 signalGammaCands_sum_innerSigCone_dEta,
132 signalGammaCands_sum_innerSigCone_dPhi,
133 signalGammaCands_sum_innerSigCone_mass,
134 signalGammaCands_sum_outerSigCone_pt,
135 signalGammaCands_sum_outerSigCone_dEta,
136 signalGammaCands_sum_outerSigCone_dPhi,
137 signalGammaCands_sum_outerSigCone_mass,
138 signalGammaCands_nTotal_innerSigCone,
139 signalGammaCands_nTotal_outerSigCone,
140 isolationChargedHadrCands_sum_pt,
141 isolationChargedHadrCands_sum_dEta,
142 isolationChargedHadrCands_sum_dPhi,
143 isolationChargedHadrCands_sum_mass,
144 isolationChargedHadrCands_nTotal,
145 isolationNeutrHadrCands_sum_pt,
146 isolationNeutrHadrCands_sum_dEta,
147 isolationNeutrHadrCands_sum_dPhi,
148 isolationNeutrHadrCands_sum_mass,
149 isolationNeutrHadrCands_nTotal,
150 isolationGammaCands_sum_pt,
151 isolationGammaCands_sum_dEta,
152 isolationGammaCands_sum_dPhi,
153 isolationGammaCands_sum_mass,
154 isolationGammaCands_nTotal,
160 constexpr
int number_of_inner_cell = 11;
161 constexpr
int number_of_outer_cell = 21;
162 constexpr
int number_of_conv_features = 64;
163 namespace TauBlockInputs {
172 tau_n_charged_prongs,
173 tau_n_neutral_prongs,
175 chargedIsoPtSumdR03_over_dR05,
178 neutralIsoPtSumWeight_over_neutralIsoPtSum,
179 neutralIsoPtSumWeightdR03_over_neutralIsoPtSum,
180 neutralIsoPtSumdR03_over_dR05,
181 photonPtSumOutsideSignalCone,
198 tau_flightLength_sig,
199 tau_pt_weighted_deta_strip,
200 tau_pt_weighted_dphi_strip,
201 tau_pt_weighted_dr_signal,
202 tau_pt_weighted_dr_iso,
203 tau_leadingTrackNormChi2,
206 tau_gj_angle_diff_valid,
210 tau_inside_ecal_crack,
211 leadChargedCand_etaAtEcalEntrance_minus_tau_eta,
216 namespace EgammaBlockInputs {
221 tau_inside_ecal_crack,
226 pfCand_ele_pvAssociationQuality,
227 pfCand_ele_puppiWeight,
229 pfCand_ele_lostInnerHits,
230 pfCand_ele_numberOfPixelHits,
231 pfCand_ele_vertex_dx,
232 pfCand_ele_vertex_dy,
233 pfCand_ele_vertex_dz,
234 pfCand_ele_vertex_dx_tauFL,
235 pfCand_ele_vertex_dy_tauFL,
236 pfCand_ele_vertex_dz_tauFL,
237 pfCand_ele_hasTrackDetails,
242 pfCand_ele_track_chi2_ndof,
243 pfCand_ele_track_ndof,
249 ele_cc_ele_rel_energy,
250 ele_cc_gamma_rel_energy,
252 ele_rel_trackMomentumAtVtx,
253 ele_rel_trackMomentumAtCalo,
254 ele_rel_trackMomentumOut,
255 ele_rel_trackMomentumAtEleClus,
256 ele_rel_trackMomentumAtVtxWithConstraint,
259 ele_eSuperClusterOverP,
260 ele_eSeedClusterOverP,
261 ele_eSeedClusterOverPout,
262 ele_eEleClusterOverPout,
263 ele_deltaEtaSuperClusterTrackAtVtx,
264 ele_deltaEtaSeedClusterTrackAtCalo,
265 ele_deltaEtaEleClusterTrackAtCalo,
266 ele_deltaPhiEleClusterTrackAtCalo,
267 ele_deltaPhiSuperClusterTrackAtVtx,
268 ele_deltaPhiSeedClusterTrackAtCalo,
269 ele_mvaInput_earlyBrem,
270 ele_mvaInput_lateBrem,
271 ele_mvaInput_sigmaEtaEta,
272 ele_mvaInput_hadEnergy,
273 ele_mvaInput_deltaEta,
274 ele_gsfTrack_normalizedChi2,
275 ele_gsfTrack_numberOfValidHits,
278 ele_has_closestCtfTrack,
279 ele_closestCtfTrack_normalizedChi2,
280 ele_closestCtfTrack_numberOfValidHits,
285 pfCand_gamma_pvAssociationQuality,
287 pfCand_gamma_puppiWeight,
288 pfCand_gamma_puppiWeightNoLep,
289 pfCand_gamma_lostInnerHits,
290 pfCand_gamma_numberOfPixelHits,
291 pfCand_gamma_vertex_dx,
292 pfCand_gamma_vertex_dy,
293 pfCand_gamma_vertex_dz,
294 pfCand_gamma_vertex_dx_tauFL,
295 pfCand_gamma_vertex_dy_tauFL,
296 pfCand_gamma_vertex_dz_tauFL,
297 pfCand_gamma_hasTrackDetails,
299 pfCand_gamma_dxy_sig,
302 pfCand_gamma_track_chi2_ndof,
303 pfCand_gamma_track_ndof,
308 namespace MuonBlockInputs {
313 tau_inside_ecal_crack,
318 pfCand_muon_pvAssociationQuality,
320 pfCand_muon_puppiWeight,
322 pfCand_muon_lostInnerHits,
323 pfCand_muon_numberOfPixelHits,
324 pfCand_muon_vertex_dx,
325 pfCand_muon_vertex_dy,
326 pfCand_muon_vertex_dz,
327 pfCand_muon_vertex_dx_tauFL,
328 pfCand_muon_vertex_dy_tauFL,
329 pfCand_muon_vertex_dz_tauFL,
330 pfCand_muon_hasTrackDetails,
335 pfCand_muon_track_chi2_ndof,
336 pfCand_muon_track_ndof,
343 muon_normalizedChi2_valid,
345 muon_numberOfValidHits,
346 muon_segmentCompatibility,
347 muon_caloCompatibility,
348 muon_pfEcalEnergy_valid,
349 muon_rel_pfEcalEnergy,
354 muon_n_matches_CSC_1,
355 muon_n_matches_CSC_2,
356 muon_n_matches_CSC_3,
357 muon_n_matches_CSC_4,
358 muon_n_matches_RPC_1,
359 muon_n_matches_RPC_2,
360 muon_n_matches_RPC_3,
361 muon_n_matches_RPC_4,
378 namespace HadronBlockInputs {
383 tau_inside_ecal_crack,
388 pfCand_chHad_leadChargedHadrCand,
389 pfCand_chHad_pvAssociationQuality,
391 pfCand_chHad_puppiWeight,
392 pfCand_chHad_puppiWeightNoLep,
394 pfCand_chHad_lostInnerHits,
395 pfCand_chHad_numberOfPixelHits,
396 pfCand_chHad_vertex_dx,
397 pfCand_chHad_vertex_dy,
398 pfCand_chHad_vertex_dz,
399 pfCand_chHad_vertex_dx_tauFL,
400 pfCand_chHad_vertex_dy_tauFL,
401 pfCand_chHad_vertex_dz_tauFL,
402 pfCand_chHad_hasTrackDetails,
404 pfCand_chHad_dxy_sig,
407 pfCand_chHad_track_chi2_ndof,
408 pfCand_chHad_track_ndof,
409 pfCand_chHad_hcalFraction,
410 pfCand_chHad_rawCaloFraction,
415 pfCand_nHad_puppiWeight,
416 pfCand_nHad_puppiWeightNoLep,
417 pfCand_nHad_hcalFraction,
424 static tbb::concurrent_unordered_set<std::string> isFirstWarning;
430 <<
"Exception in <getTauID>: No tauID '" <<
tauID <<
"' available in pat::Tau given as function argument.";
432 if (isFirstWarning.insert(
tauID).second) {
434 <<
"' available in pat::Tau given as function argument."
435 <<
" Using default_value = " << default_value <<
" instead." << std::endl;
437 return default_value;
445 pfTauTransverseImpactParameters;
448 std::map<BasicDiscr, size_t> indexMap;
449 std::map<BasicDiscr, size_t> indexMapdR03;
452 return (*basicTauDiscriminatorCollection)[tau_ref].rawValues.at(indexMap.at(BasicDiscr::ChargedIsoPtSum));
455 return getTauID(
tau,
"chargedIsoPtSum");
458 return (*basicTauDiscriminatordR03Collection)[tau_ref].rawValues.at(indexMapdR03.at(BasicDiscr::ChargedIsoPtSum));
461 return getTauID(
tau,
"chargedIsoPtSumdR03");
464 return (*basicTauDiscriminatordR03Collection)[tau_ref].rawValues.at(
465 indexMapdR03.at(BasicDiscr::FootprintCorrection));
468 return getTauID(
tau,
"footprintCorrectiondR03");
471 return (*basicTauDiscriminatorCollection)[tau_ref].rawValues.at(indexMap.at(BasicDiscr::NeutralIsoPtSum));
474 return getTauID(
tau,
"neutralIsoPtSum");
477 return (*basicTauDiscriminatordR03Collection)[tau_ref].rawValues.at(indexMapdR03.at(BasicDiscr::NeutralIsoPtSum));
480 return getTauID(
tau,
"neutralIsoPtSumdR03");
483 return (*basicTauDiscriminatorCollection)[tau_ref].rawValues.at(indexMap.at(BasicDiscr::NeutralIsoPtSumWeight));
486 return getTauID(
tau,
"neutralIsoPtSumWeight");
490 return (*basicTauDiscriminatordR03Collection)[tau_ref].rawValues.at(
491 indexMapdR03.at(BasicDiscr::NeutralIsoPtSumWeight));
494 return getTauID(
tau,
"neutralIsoPtSumWeightdR03");
496 const float getPhotonPtSumOutsideSignalCone(
const reco::PFTau&
tau,
498 return (*basicTauDiscriminatorCollection)[tau_ref].rawValues.at(
499 indexMap.at(BasicDiscr::PhotonPtSumOutsideSignalCone));
501 const float getPhotonPtSumOutsideSignalCone(
const pat::Tau&
tau,
503 return getTauID(
tau,
"photonPtSumOutsideSignalCone");
505 const float getPhotonPtSumOutsideSignalConedR03(
const reco::PFTau&
tau,
507 return (*basicTauDiscriminatordR03Collection)[tau_ref].rawValues.at(
508 indexMapdR03.at(BasicDiscr::PhotonPtSumOutsideSignalCone));
510 const float getPhotonPtSumOutsideSignalConedR03(
const pat::Tau&
tau,
512 return getTauID(
tau,
"photonPtSumOutsideSignalConedR03");
515 return (*basicTauDiscriminatorCollection)[tau_ref].rawValues.at(indexMap.at(BasicDiscr::PUcorrPtSum));
518 return getTauID(
tau,
"puCorrPtSum");
521 auto getdxyPCA(
const reco::PFTau&
tau,
const size_t tau_index)
const {
522 return pfTauTransverseImpactParameters->
value(tau_index)->dxy_PCA();
524 auto getdxyPCA(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.dxy_PCA(); }
525 auto getdxy(
const reco::PFTau&
tau,
const size_t tau_index)
const {
526 return pfTauTransverseImpactParameters->
value(tau_index)->dxy();
528 auto getdxy(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.dxy(); }
529 auto getdxyError(
const reco::PFTau&
tau,
const size_t tau_index)
const {
530 return pfTauTransverseImpactParameters->
value(tau_index)->dxy_error();
532 auto getdxyError(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.dxy_error(); }
533 auto getdxySig(
const reco::PFTau&
tau,
const size_t tau_index)
const {
534 return pfTauTransverseImpactParameters->
value(tau_index)->dxy_Sig();
536 auto getdxySig(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.dxy_Sig(); }
537 auto getip3d(
const reco::PFTau&
tau,
const size_t tau_index)
const {
538 return pfTauTransverseImpactParameters->
value(tau_index)->ip3d();
540 auto getip3d(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.ip3d(); }
541 auto getip3dError(
const reco::PFTau&
tau,
const size_t tau_index)
const {
542 return pfTauTransverseImpactParameters->
value(tau_index)->ip3d_error();
544 auto getip3dError(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.ip3d_error(); }
545 auto getip3dSig(
const reco::PFTau&
tau,
const size_t tau_index)
const {
546 return pfTauTransverseImpactParameters->
value(tau_index)->ip3d_Sig();
548 auto getip3dSig(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.ip3d_Sig(); }
549 auto getHasSecondaryVertex(
const reco::PFTau&
tau,
const size_t tau_index)
const {
550 return pfTauTransverseImpactParameters->
value(tau_index)->hasSecondaryVertex();
552 auto getHasSecondaryVertex(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.hasSecondaryVertex(); }
553 auto getFlightLength(
const reco::PFTau&
tau,
const size_t tau_index)
const {
554 return pfTauTransverseImpactParameters->
value(tau_index)->flightLength();
556 auto getFlightLength(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.flightLength(); }
557 auto getFlightLengthSig(
const reco::PFTau&
tau,
const size_t tau_index)
const {
558 return pfTauTransverseImpactParameters->
value(tau_index)->flightLengthSig();
560 auto getFlightLengthSig(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.flightLengthSig(); }
563 auto getLeadingTrackNormChi2(
const pat::Tau&
tau) {
return tau.leadingTrackNormChi2(); }
564 auto getEmFraction(
const pat::Tau&
tau) {
return tau.emFraction_MVA(); }
566 auto getEtaAtEcalEntrance(
const pat::Tau&
tau) {
return tau.etaAtEcalEntranceLeadChargedCand(); }
568 return tau.leadPFChargedHadrCand()->positionAtECALEntrance().eta();
570 auto getEcalEnergyLeadingChargedHadr(
const reco::PFTau&
tau) {
return tau.leadPFChargedHadrCand()->ecalEnergy(); }
571 auto getEcalEnergyLeadingChargedHadr(
const pat::Tau&
tau) {
return tau.ecalEnergyLeadChargedHadrCand(); }
572 auto getHcalEnergyLeadingChargedHadr(
const reco::PFTau&
tau) {
return tau.leadPFChargedHadrCand()->hcalEnergy(); }
573 auto getHcalEnergyLeadingChargedHadr(
const pat::Tau&
tau) {
return tau.hcalEnergyLeadChargedHadrCand(); }
575 template <
typename PreDiscrType>
576 bool passPrediscriminants(
const PreDiscrType prediscriminants,
577 const size_t andPrediscriminants,
579 bool passesPrediscriminants = (andPrediscriminants ? 1 : 0);
581 size_t nPrediscriminants = prediscriminants.size();
582 for (
size_t iDisc = 0; iDisc < nPrediscriminants; ++iDisc) {
584 double discResult = (*prediscriminants[iDisc].handle)[tau_ref];
585 uint8_t thisPasses = (discResult > prediscriminants[iDisc].cut) ? 1 : 0;
602 if (thisPasses ^ andPrediscriminants)
604 passesPrediscriminants = (andPrediscriminants ? 0 : 1);
608 return passesPrediscriminants;
616 return cand.bestTrack() !=
nullptr && std::isnormal(
cand.bestTrack()->dz()) && std::isnormal(
cand.dzError()) &&
620 return cand.hasTrackDetails() && std::isnormal(
cand.dz()) && std::isnormal(
cand.dzError()) &&
cand.dzError() > 0;
630 return cand.puppiWeightNoLep();
633 return cand.bestTrack() !=
nullptr
639 return cand.bestTrack() !=
nullptr
644 return cand.numberOfPixelHits();
653 return cand.rawHcalEnergy() / (
cand.rawHcalEnergy() +
cand.rawEcalEnergy());
656 float hcal_fraction = 0.;
657 if (disable_hcalFraction_workaround) {
660 hcal_fraction =
cand.hcalFraction();
663 if (
cand.pdgId() == 1 ||
cand.pdgId() == 130) {
664 hcal_fraction =
cand.hcalFraction();
665 }
else if (
cand.isIsolatedChargedHadron()) {
666 hcal_fraction =
cand.rawHcalFraction();
669 return hcal_fraction;
672 return (
cand.rawEcalEnergy() +
cand.rawHcalEnergy()) /
cand.energy();
677 template <
typename LVector1,
typename LVector2>
678 float dEta(
const LVector1&
p4,
const LVector2& tau_p4) {
679 return static_cast<float>(
p4.eta() - tau_p4.eta());
682 template <
typename LVector1,
typename LVector2>
683 float dPhi(
const LVector1& p4_1,
const LVector2& p4_2) {
684 return static_cast<float>(
reco::deltaPhi(p4_2.phi(), p4_1.phi()));
687 struct MuonHitMatchV1 {
688 static constexpr
int n_muon_stations = 4;
690 std::map<int, std::vector<UInt_t>> n_matches, n_hits;
692 const pat::Muon* best_matched_muon{
nullptr};
693 double deltaR2_best_match{-1};
705 static constexpr
int n_stations = 4;
709 if (!best_matched_muon || dR2 < deltaR2_best_match) {
710 best_matched_muon = &
muon;
711 deltaR2_best_match = dR2;
714 for (
const auto& segment :
muon.matches()) {
715 if (segment.segmentMatches.empty())
717 if (n_matches.count(segment.detector()))
718 ++n_matches.at(segment.detector()).at(segment.station() - 1);
721 if (
muon.outerTrack().isNonnull()) {
722 const auto& hit_pattern =
muon.outerTrack()->hitPattern();
729 const int station = hit_pattern.getMuonStation(hit_id) - 1;
731 std::vector<UInt_t>* muon_n_hits =
nullptr;
732 if (hit_pattern.muonDTHitFilter(hit_id))
734 else if (hit_pattern.muonCSCHitFilter(hit_id))
736 else if (hit_pattern.muonRPCHitFilter(hit_id))
747 template <
typename TauCastType>
748 static std::vector<const pat::Muon*> findMatchedMuons(
const TauCastType&
tau,
749 const std::vector<pat::Muon>*
muons,
753 if (
tau.leadPFChargedHadrCand().isNonnull() &&
tau.leadPFChargedHadrCand()->muonRef().isNonnull())
754 hadr_cand_muon =
tau.leadPFChargedHadrCand()->muonRef().get();
755 std::vector<const pat::Muon*> matched_muons;
761 if (reco_muon == hadr_cand_muon)
765 matched_muons.push_back(&
muon);
767 return matched_muons;
770 template <
typename dnn,
typename TensorElemGet,
typename TauCastType>
771 void fillTensor(
const TensorElemGet&
get,
const TauCastType&
tau,
float default_value)
const {
772 get(dnn::n_matched_muons) = n_muons;
773 get(dnn::muon_pt) = best_matched_muon !=
nullptr ? best_matched_muon->p4().pt() : default_value;
774 get(dnn::muon_dEta) = best_matched_muon !=
nullptr ?
dEta(best_matched_muon->p4(),
tau.p4()) : default_value;
775 get(dnn::muon_dPhi) = best_matched_muon !=
nullptr ?
dPhi(best_matched_muon->p4(),
tau.p4()) : default_value;
793 get(dnn::muon_n_stations_with_matches_03) = countMuonStationsWithMatches(0, 3);
794 get(dnn::muon_n_stations_with_hits_23) = countMuonStationsWithHits(2, 3);
798 unsigned countMuonStationsWithMatches(
size_t first_station,
size_t last_station)
const {
799 static const std::map<int, std::vector<bool>> masks = {
805 for (
unsigned n = first_station;
n <= last_station; ++
n) {
806 for (
const auto&
match : n_matches) {
807 if (!masks.at(
match.first).at(
n) &&
match.second.at(
n) > 0)
814 unsigned countMuonStationsWithHits(
size_t first_station,
size_t last_station)
const {
815 static const std::map<int, std::vector<bool>> masks = {
822 for (
unsigned n = first_station;
n <= last_station; ++
n) {
823 for (
const auto&
hit : n_hits) {
824 if (!masks.at(
hit.first).at(
n) &&
hit.second.at(
n) > 0)
832 struct MuonHitMatchV2 {
833 static constexpr
size_t n_muon_stations = 4;
834 static constexpr
int first_station_id = 1;
835 static constexpr
int last_station_id = first_station_id + n_muon_stations - 1;
836 using CountArray = std::array<unsigned, n_muon_stations>;
837 using CountMap = std::map<int, CountArray>;
839 const std::vector<int>& consideredSubdets() {
845 static const std::map<int, std::string> subdet_names = {
847 if (!subdet_names.count(subdet))
848 throw cms::Exception(
"MuonHitMatch") <<
"Subdet name for subdet id " << subdet <<
" not found.";
849 return subdet_names.at(subdet);
852 size_t getStationIndex(
int station,
bool throw_exception)
const {
853 if (station < first_station_id || station > last_station_id) {
855 throw cms::Exception(
"MuonHitMatch") <<
"Station id is out of range";
858 return static_cast<size_t>(
station - 1);
862 for (
int subdet : consideredSubdets()) {
863 n_matches[subdet].fill(0);
864 n_hits[subdet].fill(0);
872 for (
const auto& segment :
muon.matches()) {
873 if (segment.segmentMatches.empty() && segment.rpcMatches.empty())
875 if (n_matches.count(segment.detector())) {
876 const size_t station_index = getStationIndex(segment.station(),
true);
877 ++n_matches.at(segment.detector()).at(station_index);
883 if (
muon.outerTrack().isNonnull()) {
884 const auto& hit_pattern =
muon.outerTrack()->hitPattern();
891 const size_t station_index = getStationIndex(hit_pattern.getMuonStation(hit_id),
false);
892 if (station_index < n_muon_stations) {
893 CountArray* muon_n_hits =
nullptr;
894 if (hit_pattern.muonDTHitFilter(hit_id))
896 else if (hit_pattern.muonCSCHitFilter(hit_id))
898 else if (hit_pattern.muonRPCHitFilter(hit_id))
902 ++muon_n_hits->at(station_index);
909 unsigned nMatches(
int subdet,
int station)
const {
910 if (!n_matches.count(subdet))
911 throw cms::Exception(
"MuonHitMatch") <<
"Subdet " << subdet <<
" not found.";
912 const size_t station_index = getStationIndex(
station,
true);
913 return n_matches.at(subdet).at(station_index);
917 if (!n_hits.count(subdet))
918 throw cms::Exception(
"MuonHitMatch") <<
"Subdet " << subdet <<
" not found.";
919 const size_t station_index = getStationIndex(
station,
true);
920 return n_hits.at(subdet).at(station_index);
923 unsigned countMuonStationsWithMatches(
int first_station,
int last_station)
const {
924 static const std::map<int, std::vector<bool>> masks = {
929 const size_t first_station_index = getStationIndex(first_station,
true);
930 const size_t last_station_index = getStationIndex(last_station,
true);
932 for (
size_t n = first_station_index;
n <= last_station_index; ++
n) {
933 for (
const auto&
match : n_matches) {
934 if (!masks.at(
match.first).at(
n) &&
match.second.at(
n) > 0)
941 unsigned countMuonStationsWithHits(
int first_station,
int last_station)
const {
942 static const std::map<int, std::vector<bool>> masks = {
948 const size_t first_station_index = getStationIndex(first_station,
true);
949 const size_t last_station_index = getStationIndex(last_station,
true);
951 for (
size_t n = first_station_index;
n <= last_station_index; ++
n) {
952 for (
const auto&
hit : n_hits) {
953 if (!masks.at(
hit.first).at(
n) &&
hit.second.at(
n) > 0)
961 CountMap n_matches, n_hits;
967 PfCand_chargedHadron,
968 PfCand_neutralHadron,
975 template <
typename Object>
988 static const std::map<int, CellObjectType> obj_types = {{11, CellObjectType::PfCand_electron},
989 {13, CellObjectType::PfCand_muon},
990 {22, CellObjectType::PfCand_gamma},
991 {130, CellObjectType::PfCand_neutralHadron},
992 {211, CellObjectType::PfCand_chargedHadron}};
995 if (iter == obj_types.end())
996 return CellObjectType::Other;
1000 using Cell = std::map<CellObjectType, size_t>;
1013 using Map = std::map<CellIndex, Cell>;
1014 using const_iterator = Map::const_iterator;
1016 CellGrid(
unsigned n_cells_eta,
1017 unsigned n_cells_phi,
1018 double cell_size_eta,
1019 double cell_size_phi,
1020 bool disable_CellIndex_workaround)
1021 : nCellsEta(n_cells_eta),
1022 nCellsPhi(n_cells_phi),
1023 nTotal(nCellsEta * nCellsPhi),
1024 cellSizeEta(cell_size_eta),
1025 cellSizePhi(cell_size_phi),
1026 disable_CellIndex_workaround_(disable_CellIndex_workaround) {
1027 if (nCellsEta % 2 != 1 || nCellsEta < 1)
1028 throw cms::Exception(
"DeepTauId") <<
"Invalid number of eta cells.";
1029 if (nCellsPhi % 2 != 1 || nCellsPhi < 1)
1030 throw cms::Exception(
"DeepTauId") <<
"Invalid number of phi cells.";
1031 if (cellSizeEta <= 0 || cellSizePhi <= 0)
1035 int maxEtaIndex()
const {
return static_cast<int>((nCellsEta - 1) / 2); }
1036 int maxPhiIndex()
const {
return static_cast<int>((nCellsPhi - 1) / 2); }
1037 double maxDeltaEta()
const {
return cellSizeEta * (0.5 + maxEtaIndex()); }
1038 double maxDeltaPhi()
const {
return cellSizePhi * (0.5 + maxPhiIndex()); }
1039 int getEtaTensorIndex(
const CellIndex& cellIndex)
const {
return cellIndex.eta + maxEtaIndex(); }
1040 int getPhiTensorIndex(
const CellIndex& cellIndex)
const {
return cellIndex.phi + maxPhiIndex(); }
1042 bool tryGetCellIndex(
double deltaEta,
double deltaPhi, CellIndex& cellIndex)
const {
1043 const auto getCellIndex = [
this](
double x,
double maxX,
double size,
int&
index) {
1048 if (disable_CellIndex_workaround_) {
1051 absIndex = std::floor(absX /
size + 0.5);
1056 index = static_cast<int>(std::copysign(absIndex,
x));
1064 size_t num_valid_cells()
const {
return cells.size(); }
1066 const Cell& at(
const CellIndex& cellIndex)
const {
return cells.at(cellIndex); }
1067 size_t count(
const CellIndex& cellIndex)
const {
return cells.count(cellIndex); }
1068 const_iterator
find(
const CellIndex& cellIndex)
const {
return cells.find(cellIndex); }
1069 const_iterator begin()
const {
return cells.begin(); }
1070 const_iterator
end()
const {
return cells.end(); }
1073 const unsigned nCellsEta, nCellsPhi, nTotal;
1074 const double cellSizeEta, cellSizePhi;
1077 std::map<CellIndex, Cell>
cells;
1078 const bool disable_CellIndex_workaround_;
1084 {bd::ChargedIsoPtSum,
"ChargedIsoPtSum"},
1085 {bd::NeutralIsoPtSum,
"NeutralIsoPtSum"},
1086 {bd::NeutralIsoPtSumWeight,
"NeutralIsoPtSumWeight"},
1087 {bd::FootprintCorrection,
"TauFootprintCorrection"},
1088 {bd::PhotonPtSumOutsideSignalCone,
"PhotonPtSumOutsideSignalCone"},
1089 {bd::PUcorrPtSum,
"PUcorrPtSum"}};
1091 bd::NeutralIsoPtSum,
1092 bd::NeutralIsoPtSumWeight,
1093 bd::PhotonPtSumOutsideSignalCone,
1096 bd::NeutralIsoPtSum,
1097 bd::NeutralIsoPtSumWeight,
1098 bd::PhotonPtSumOutsideSignalCone,
1099 bd::FootprintCorrection};
1106 static constexpr
size_t e_index = 0, mu_index = 1, tau_index = 2, jet_index = 3;
1108 {
"VSe",
Output({tau_index}, {e_index, tau_index})},
1109 {
"VSmu",
Output({tau_index}, {mu_index, tau_index})},
1110 {
"VSjet",
Output({tau_index}, {jet_index, tau_index})},
1118 std::vector<BasicDiscriminator> requiredDiscr) {
1119 std::map<std::string, size_t> discrIndexMapStr;
1120 auto const aHandle =
event.getHandle(discriminatorContainerToken);
1121 auto const aProv = aHandle.provenance();
1122 if (aProv ==
nullptr)
1123 aHandle.whyFailed()->raise();
1124 const auto& psetsFromProvenance =
edm::parameterSet(aProv->stable(),
event.processHistory());
1125 auto const idlist = psetsFromProvenance.
getParameter<std::vector<edm::ParameterSet>>(
"IDdefinitions");
1126 for (
size_t j = 0;
j < idlist.size(); ++
j) {
1128 if (discrIndexMapStr.count(idname)) {
1130 <<
"basic discriminator " << idname <<
" appears more than once in the input.";
1132 discrIndexMapStr[idname] =
j;
1136 std::map<BasicDiscriminator, size_t> discrIndexMap;
1137 for (
size_t i = 0;
i < requiredDiscr.size();
i++) {
1140 <<
" was not provided in the config file.";
1144 return discrIndexMap;
1155 desc.add<std::vector<std::string>>(
"graph_file",
1156 {
"RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6.pb"});
1157 desc.add<
bool>(
"mem_mapped",
false);
1158 desc.add<
unsigned>(
"version", 2);
1159 desc.add<
int>(
"debug_level", 0);
1160 desc.add<
bool>(
"disable_dxy_pca",
false);
1161 desc.add<
bool>(
"disable_hcalFraction_workaround",
false);
1162 desc.add<
bool>(
"disable_CellIndex_workaround",
false);
1163 desc.add<
bool>(
"save_inputs",
false);
1164 desc.add<
bool>(
"is_online",
false);
1166 desc.add<std::vector<std::string>>(
"VSeWP");
1167 desc.add<std::vector<std::string>>(
"VSmuWP");
1168 desc.add<std::vector<std::string>>(
"VSjetWP");
1176 pset_Prediscriminants.
add<
std::string>(
"BooleanOperator",
"and");
1179 psd1.
add<
double>(
"cut");
1186 descriptions.
add(
"DeepTau",
desc);
1196 cfg.getUntrackedParameter<
edm::
InputTag>(
"basicTauDiscriminators"))),
1198 cfg.getUntrackedParameter<
edm::
InputTag>(
"basicTauDiscriminatorsdR03"))),
1201 cfg.getParameter<
edm::
InputTag>(
"pfTauTransverseImpactParameters"))),
1213 const auto& shape =
cache_->
getGraph().node(0).attr().at(
"shape").shape();
1214 if (shape.dim(1).size() != dnn_inputs_2017v1::NumberOfInputs)
1216 <<
"number of inputs does not match the expected inputs for the given version";
1219 tensorflow::DT_FLOAT, tensorflow::TensorShape{1, dnn_inputs_2017_v2::TauBlockInputs::NumberOfInputs});
1220 for (
size_t n = 0;
n < 2; ++
n) {
1221 const bool is_inner =
n == 0;
1222 const auto n_cells =
1223 is_inner ? dnn_inputs_2017_v2::number_of_inner_cell : dnn_inputs_2017_v2::number_of_outer_cell;
1224 eGammaTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1225 tensorflow::DT_FLOAT,
1226 tensorflow::TensorShape{1, 1, 1, dnn_inputs_2017_v2::EgammaBlockInputs::NumberOfInputs});
1227 muonTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1228 tensorflow::DT_FLOAT,
1229 tensorflow::TensorShape{1, 1, 1, dnn_inputs_2017_v2::MuonBlockInputs::NumberOfInputs});
1231 tensorflow::DT_FLOAT,
1232 tensorflow::TensorShape{1, 1, 1, dnn_inputs_2017_v2::HadronBlockInputs::NumberOfInputs});
1233 convTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1234 tensorflow::DT_FLOAT,
1235 tensorflow::TensorShape{1, n_cells, n_cells, dnn_inputs_2017_v2::number_of_conv_features});
1237 tensorflow::DT_FLOAT, tensorflow::TensorShape{1, 1, 1, dnn_inputs_2017_v2::number_of_conv_features});
1251 return DeepTauBase::initializeGlobalCache(
cfg);
1259 template <
typename T>
1261 return std::isnormal(
value) ? static_cast<float>(
value) : 0.f;
1264 template <
typename T>
1270 transformed_value = transformed_value * 2 - 1;
1271 return transformed_value;
1274 template <
typename T>
1277 const float norm_value = (fixed_value -
mean) / sigma;
1278 return std::clamp(norm_value, -n_sigmas_max, n_sigmas_max);
1284 float& cc_ele_energy,
1285 float& cc_gamma_energy,
1287 cc_ele_energy = cc_gamma_energy = 0;
1290 if (superCluster.isNonnull() && superCluster.isAvailable() && superCluster->clusters().isNonnull() &&
1291 superCluster->clusters().isAvailable()) {
1292 for (
auto iter = superCluster->clustersBegin(); iter != superCluster->clustersEnd(); ++iter) {
1293 const float energy = static_cast<float>((*iter)->energy());
1294 if (iter == superCluster->clustersBegin())
1297 cc_gamma_energy +=
energy;
1309 const CellGrid*
grid =
nullptr)
const {
1311 std::cout <<
"<checkInputs>: block_name = " << block_name << std::endl;
1312 if (block_name ==
"input_tau") {
1313 for (
int input_index = 0; input_index < n_inputs; ++input_index) {
1314 float input =
inputs.matrix<
float>()(0, input_index);
1317 <<
"in the " << block_name
1318 <<
", input is not finite, i.e. infinite or NaN, for input_index = " << input_index;
1328 if (block_name.find(
"input_inner") != std::string::npos) {
1331 }
else if (block_name.find(
"input_outer") != std::string::npos) {
1336 int eta_phi_index = 0;
1337 for (
int eta = -n_eta;
eta <= n_eta; ++
eta) {
1338 for (
int phi = -n_phi;
phi <= n_phi; ++
phi) {
1339 const CellIndex cell_index{
eta,
phi};
1340 const auto cell_iter =
grid->find(cell_index);
1341 if (cell_iter !=
grid->end()) {
1342 for (
int input_index = 0; input_index < n_inputs; ++input_index) {
1346 <<
"in the " << block_name <<
", input is not finite, i.e. infinite or NaN, for eta = " <<
eta
1347 <<
", phi = " <<
phi <<
", input_index = " << input_index;
1350 std::cout << block_name <<
"[eta = " <<
eta <<
"][phi = " <<
phi <<
"][var = " << input_index
1351 <<
"] = " << std::setprecision(5) <<
std::fixed <<
input << std::endl;
1365 const CellGrid*
grid =
nullptr) {
1367 std::cout <<
"<saveInputs>: block_name = " << block_name << std::endl;
1370 (*json_file_) <<
", ";
1371 (*json_file_) <<
"\"" << block_name <<
"\": [";
1372 if (block_name ==
"input_tau") {
1373 for (
int input_index = 0; input_index < n_inputs; ++input_index) {
1374 float input =
inputs.matrix<
float>()(0, input_index);
1375 if (input_index != 0)
1376 (*json_file_) <<
", ";
1377 (*json_file_) <<
input;
1382 if (block_name.find(
"input_inner") != std::string::npos) {
1385 }
else if (block_name.find(
"input_outer") != std::string::npos) {
1390 int eta_phi_index = 0;
1391 for (
int eta = -n_eta;
eta <= n_eta; ++
eta) {
1393 (*json_file_) <<
", ";
1394 (*json_file_) <<
"[";
1395 for (
int phi = -n_phi;
phi <= n_phi; ++
phi) {
1397 (*json_file_) <<
", ";
1398 (*json_file_) <<
"[";
1399 const CellIndex cell_index{
eta,
phi};
1400 const auto cell_iter =
grid->find(cell_index);
1401 for (
int input_index = 0; input_index < n_inputs; ++input_index) {
1403 if (cell_iter !=
grid->end()) {
1406 if (input_index != 0)
1407 (*json_file_) <<
", ";
1408 (*json_file_) <<
input;
1410 if (cell_iter !=
grid->end()) {
1413 (*json_file_) <<
"]";
1415 (*json_file_) <<
"]";
1418 (*json_file_) <<
"]";
1425 const std::vector<pat::Electron> electron_collection_default;
1426 const std::vector<pat::Muon> muon_collection_default;
1430 pfTauTransverseImpactParameters_default;
1432 const std::vector<pat::Electron>* electron_collection;
1433 const std::vector<pat::Muon>* muon_collection;
1437 pfTauTransverseImpactParameters;
1442 pfTauTransverseImpactParameters = &pfTauTransverseImpactParameters_default;
1443 basicTauDiscriminators = &basicTauDiscriminators_default;
1444 basicTauDiscriminatorsdR03 = &basicTauDiscriminatorsdR03_default;
1446 electron_collection = &electron_collection_default;
1447 muon_collection = &muon_collection_default;
1462 TauFunc tauIDs = {basicTauDiscriminators,
1463 basicTauDiscriminatorsdR03,
1464 pfTauTransverseImpactParameters,
1479 for (
size_t tau_index = 0; tau_index <
taus->size(); ++tau_index) {
1482 std::vector<tensorflow::Tensor> pred_vector;
1484 bool passesPrediscriminants;
1486 passesPrediscriminants = tauIDs.passPrediscriminants<std::vector<TauDiscInfo<reco::PFTauDiscriminator>>>(
1489 passesPrediscriminants = tauIDs.passPrediscriminants<std::vector<TauDiscInfo<pat::PATTauDiscriminator>>>(
1493 if (passesPrediscriminants) {
1496 getPredictionsV1<reco::PFCandidate, reco::PFTau>(
1497 taus->at(tau_index), tau_index, tauRef, electron_collection, muon_collection, pred_vector, tauIDs);
1499 getPredictionsV1<pat::PackedCandidate, pat::Tau>(
1500 taus->at(tau_index), tau_index, tauRef, electron_collection, muon_collection, pred_vector, tauIDs);
1503 getPredictionsV2<reco::PFCandidate, reco::PFTau>(
taus->at(tau_index),
1506 electron_collection,
1514 getPredictionsV2<pat::PackedCandidate, pat::Tau>(
taus->at(tau_index),
1517 electron_collection,
1529 const float pred = pred_vector[0].flat<
float>()(
k);
1530 if (!(pred >= 0 && pred <= 1))
1532 <<
"invalid prediction = " << pred <<
" for tau_index = " << tau_index <<
", pred_index = " <<
k;
1533 predictions.matrix<
float>()(tau_index,
k) = pred;
1540 template <
typename Cand
idateCastType,
typename TauCastType>
1542 const size_t tau_index,
1544 const std::vector<pat::Electron>*
electrons,
1545 const std::vector<pat::Muon>*
muons,
1546 std::vector<tensorflow::Tensor>& pred_vector,
1547 TauFunc tau_funcs) {
1548 const tensorflow::Tensor&
inputs = createInputsV1<dnn_inputs_2017v1, const CandidateCastType>(
1549 dynamic_cast<const TauCastType&>(
tau), tau_index, tau_ref,
electrons,
muons, tau_funcs);
1553 template <
typename Cand
idateCastType,
typename TauCastType>
1555 const size_t tau_index,
1557 const std::vector<pat::Electron>*
electrons,
1558 const std::vector<pat::Muon>*
muons,
1562 std::vector<tensorflow::Tensor>& pred_vector,
1563 TauFunc tau_funcs) {
1565 std::cout <<
"<DeepTauId::getPredictionsV2 (moduleLabel = " << moduleDescription().moduleLabel()
1566 <<
")>:" << std::endl;
1567 std::cout <<
" tau: pT = " <<
tau.pt() <<
", eta = " <<
tau.eta() <<
", phi = " <<
tau.phi() << std::endl;
1569 CellGrid inner_grid(dnn_inputs_2017_v2::number_of_inner_cell,
1570 dnn_inputs_2017_v2::number_of_inner_cell,
1574 CellGrid outer_grid(dnn_inputs_2017_v2::number_of_outer_cell,
1575 dnn_inputs_2017_v2::number_of_outer_cell,
1580 fillGrids(dynamic_cast<const TauCastType&>(
tau), *
muons, inner_grid, outer_grid);
1581 fillGrids(dynamic_cast<const TauCastType&>(
tau), pfCands, inner_grid, outer_grid);
1583 createTauBlockInputs<CandidateCastType>(
1584 dynamic_cast<const TauCastType&>(
tau), tau_index, tau_ref,
pv,
rho, tau_funcs);
1587 createConvFeatures<CandidateCastType>(dynamic_cast<const TauCastType&>(
tau),
1601 createConvFeatures<CandidateCastType>(dynamic_cast<const TauCastType&>(
tau),
1618 json_file_ =
new std::ofstream(json_file_name.data());
1620 (*json_file_) <<
"{";
1623 "input_inner_egamma",
1624 dnn_inputs_2017_v2::EgammaBlockInputs::NumberOfInputs,
1627 *
muonTensor_[
true],
"input_inner_muon", dnn_inputs_2017_v2::MuonBlockInputs::NumberOfInputs, &inner_grid);
1629 "input_inner_hadrons",
1630 dnn_inputs_2017_v2::HadronBlockInputs::NumberOfInputs,
1633 "input_outer_egamma",
1634 dnn_inputs_2017_v2::EgammaBlockInputs::NumberOfInputs,
1637 *
muonTensor_[
false],
"input_outer_muon", dnn_inputs_2017_v2::MuonBlockInputs::NumberOfInputs, &outer_grid);
1639 "input_outer_hadrons",
1640 dnn_inputs_2017_v2::HadronBlockInputs::NumberOfInputs,
1642 (*json_file_) <<
"}";
1651 {
"main_output/Softmax"},
1675 template <
typename Collection,
typename TauCastType>
1676 void fillGrids(
const TauCastType&
tau,
const Collection&
objects, CellGrid& inner_grid, CellGrid& outer_grid) {
1677 static constexpr
double outer_dR2 = 0.25;
1679 const double inner_dR2 =
std::pow(inner_radius, 2);
1681 const auto addObject = [&](
size_t n,
double deta,
double dphi, CellGrid&
grid) {
1684 if (obj_type == CellObjectType::Other)
1686 CellIndex cell_index;
1687 if (
grid.tryGetCellIndex(deta, dphi, cell_index)) {
1689 auto iter = cell.find(obj_type);
1690 if (iter != cell.end()) {
1691 const auto& prev_obj =
objects.at(iter->second);
1692 if (
obj.polarP4().pt() > prev_obj.polarP4().pt())
1700 for (
size_t n = 0;
n <
objects.size(); ++
n) {
1702 const double deta =
obj.polarP4().eta() -
tau.polarP4().eta();
1705 if (dR2 < inner_dR2)
1706 addObject(
n, deta, dphi, inner_grid);
1707 if (dR2 < outer_dR2)
1708 addObject(
n, deta, dphi, outer_grid);
1713 std::vector<tensorflow::Tensor> pred_vector;
1721 {
"inner_all_dropout_4/Identity"},
1730 {
"outer_all_dropout_4/Identity"},
1733 return pred_vector.at(0);
1736 template <
typename Cand
idateCastType,
typename TauCastType>
1738 const size_t tau_index,
1742 const std::vector<pat::Electron>*
electrons,
1743 const std::vector<pat::Muon>*
muons,
1745 const CellGrid&
grid,
1749 std::cout <<
"<DeepTauId::createConvFeatures (is_inner = " << is_inner <<
")>:" << std::endl;
1751 tensorflow::Tensor& convTensor = *
convTensor_.at(is_inner);
1752 eGammaTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1753 tensorflow::DT_FLOAT,
1754 tensorflow::TensorShape{
1755 (
long long int)
grid.num_valid_cells(), 1, 1, dnn_inputs_2017_v2::EgammaBlockInputs::NumberOfInputs});
1756 muonTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1757 tensorflow::DT_FLOAT,
1758 tensorflow::TensorShape{
1759 (
long long int)
grid.num_valid_cells(), 1, 1, dnn_inputs_2017_v2::MuonBlockInputs::NumberOfInputs});
1761 tensorflow::DT_FLOAT,
1762 tensorflow::TensorShape{
1763 (
long long int)
grid.num_valid_cells(), 1, 1, dnn_inputs_2017_v2::HadronBlockInputs::NumberOfInputs});
1773 std::cout <<
"processing ( eta = " <<
eta <<
", phi = " <<
phi <<
" )" << std::endl;
1775 const CellIndex cell_index{
eta,
phi};
1776 const auto cell_iter =
grid.find(cell_index);
1777 if (cell_iter !=
grid.end()) {
1779 std::cout <<
" creating inputs for ( eta = " <<
eta <<
", phi = " <<
phi <<
" ): idx = " <<
idx
1782 const Cell& cell = cell_iter->second;
1783 createEgammaBlockInputs<CandidateCastType>(
1784 idx,
tau, tau_index, tau_ref,
pv,
rho,
electrons, pfCands, cell, tau_funcs, is_inner);
1785 createMuonBlockInputs<CandidateCastType>(
1786 idx,
tau, tau_index, tau_ref,
pv,
rho,
muons, pfCands, cell, tau_funcs, is_inner);
1787 createHadronsBlockInputs<CandidateCastType>(
1788 idx,
tau, tau_index, tau_ref,
pv,
rho, pfCands, cell, tau_funcs, is_inner);
1792 std::cout <<
" skipping creation of inputs, because ( eta = " <<
eta <<
", phi = " <<
phi
1793 <<
" ) is not in the grid !!" << std::endl;
1803 const CellIndex cell_index{
eta,
phi};
1804 const int eta_index =
grid.getEtaTensorIndex(cell_index);
1805 const int phi_index =
grid.getPhiTensorIndex(cell_index);
1807 const auto cell_iter =
grid.find(cell_index);
1808 if (cell_iter !=
grid.end()) {
1819 const tensorflow::Tensor&
features,
1823 for (
int n = 0;
n < dnn_inputs_2017_v2::number_of_conv_features; ++
n) {
1824 convTensor.tensor<
float, 4>()(0, eta_index, phi_index,
n) =
features.tensor<
float, 4>()(batch_idx, 0, 0,
n);
1828 template <
typename Cand
idateCastType,
typename TauCastType>
1830 const size_t& tau_index,
1834 TauFunc tau_funcs) {
1838 inputs.flat<
float>().setZero();
1840 const auto&
get = [&](
int var_index) ->
float& {
return inputs.matrix<
float>()(0, var_index); };
1842 auto leadChargedHadrCand = dynamic_cast<const CandidateCastType*>(
tau.leadChargedHadrCand().get());
1853 get(dnn::chargedIsoPtSum) =
getValueNorm(tau_funcs.getChargedIsoPtSum(
tau, tau_ref), 47.78f, 123.5f);
1854 get(dnn::chargedIsoPtSumdR03_over_dR05) =
1855 getValue(tau_funcs.getChargedIsoPtSumdR03(
tau, tau_ref) / tau_funcs.getChargedIsoPtSum(
tau, tau_ref));
1856 get(dnn::footprintCorrection) =
getValueNorm(tau_funcs.getFootprintCorrectiondR03(
tau, tau_ref), 9.029f, 26.42f);
1857 get(dnn::neutralIsoPtSum) =
getValueNorm(tau_funcs.getNeutralIsoPtSum(
tau, tau_ref), 57.59f, 155.3f);
1858 get(dnn::neutralIsoPtSumWeight_over_neutralIsoPtSum) =
1859 getValue(tau_funcs.getNeutralIsoPtSumWeight(
tau, tau_ref) / tau_funcs.getNeutralIsoPtSum(
tau, tau_ref));
1860 get(dnn::neutralIsoPtSumWeightdR03_over_neutralIsoPtSum) =
1861 getValue(tau_funcs.getNeutralIsoPtSumdR03Weight(
tau, tau_ref) / tau_funcs.getNeutralIsoPtSum(
tau, tau_ref));
1862 get(dnn::neutralIsoPtSumdR03_over_dR05) =
1863 getValue(tau_funcs.getNeutralIsoPtSumdR03(
tau, tau_ref) / tau_funcs.getNeutralIsoPtSum(
tau, tau_ref));
1864 get(dnn::photonPtSumOutsideSignalCone) =
1865 getValueNorm(tau_funcs.getPhotonPtSumOutsideSignalCone(
tau, tau_ref), 1.731f, 6.846f);
1866 get(dnn::puCorrPtSum) =
getValueNorm(tau_funcs.getPuCorrPtSum(
tau, tau_ref), 22.38f, 16.34f);
1872 auto const pca = tau_funcs.getdxyPCA(
tau, tau_index);
1877 get(dnn::tau_dxy_pca_x) = 0;
1878 get(dnn::tau_dxy_pca_y) = 0;
1879 get(dnn::tau_dxy_pca_z) = 0;
1881 const bool tau_dxy_valid =
1882 isAbove(tau_funcs.getdxy(
tau, tau_index), -10) &&
isAbove(tau_funcs.getdxyError(
tau, tau_index), 0);
1883 if (tau_dxy_valid) {
1884 get(dnn::tau_dxy_valid) = tau_dxy_valid;
1885 get(dnn::tau_dxy) =
getValueNorm(tau_funcs.getdxy(
tau, tau_index), 0.0018f, 0.0085f);
1887 std::abs(tau_funcs.getdxy(
tau, tau_index)) / tau_funcs.getdxyError(
tau, tau_index), 2.26f, 4.191f);
1889 const bool tau_ip3d_valid =
1890 isAbove(tau_funcs.getip3d(
tau, tau_index), -10) &&
isAbove(tau_funcs.getip3dError(
tau, tau_index), 0);
1891 if (tau_ip3d_valid) {
1892 get(dnn::tau_ip3d_valid) = tau_ip3d_valid;
1893 get(dnn::tau_ip3d) =
getValueNorm(tau_funcs.getip3d(
tau, tau_index), 0.0026f, 0.0114f);
1895 std::abs(tau_funcs.getip3d(
tau, tau_index)) / tau_funcs.getip3dError(
tau, tau_index), 2.928f, 4.466f);
1897 if (leadChargedHadrCand) {
1898 const bool hasTrackDetails = candFunc::getHasTrackDetails(*leadChargedHadrCand);
1899 const float tau_dz = (
is_online_ && !hasTrackDetails) ? 0 : candFunc::getTauDz(*leadChargedHadrCand);
1901 get(dnn::tau_dz_sig_valid) = candFunc::getTauDZSigValid(*leadChargedHadrCand);
1902 const double dzError = hasTrackDetails ? leadChargedHadrCand->dzError() : -999.;
1905 get(dnn::tau_flightLength_x) =
getValueNorm(tau_funcs.getFlightLength(
tau, tau_index).x(), -0.0003f, 0.7362f);
1906 get(dnn::tau_flightLength_y) =
getValueNorm(tau_funcs.getFlightLength(
tau, tau_index).y(), -0.0009f, 0.7354f);
1907 get(dnn::tau_flightLength_z) =
getValueNorm(tau_funcs.getFlightLength(
tau, tau_index).z(), -0.0022f, 1.993f);
1908 get(dnn::tau_flightLength_sig) = 0.55756444;
1909 get(dnn::tau_pt_weighted_deta_strip) =
1912 get(dnn::tau_pt_weighted_dphi_strip) =
1914 get(dnn::tau_pt_weighted_dr_signal) =
1917 get(dnn::tau_leadingTrackNormChi2) =
getValueNorm(tau_funcs.getLeadingTrackNormChi2(
tau), 1.538f, 4.401f);
1919 const bool tau_e_ratio_valid = std::isnormal(
eratio) &&
eratio > 0.f;
1920 get(dnn::tau_e_ratio_valid) = tau_e_ratio_valid;
1923 const bool tau_gj_angle_diff_valid = (std::isnormal(gj_angle_diff) || gj_angle_diff == 0) && gj_angle_diff >= 0;
1924 get(dnn::tau_gj_angle_diff_valid) = tau_gj_angle_diff_valid;
1925 get(dnn::tau_gj_angle_diff) = tau_gj_angle_diff_valid ?
getValueLinear(gj_angle_diff, 0,
pi,
true) : 0;
1930 get(dnn::leadChargedCand_etaAtEcalEntrance_minus_tau_eta) =
1931 getValueNorm(tau_funcs.getEtaAtEcalEntrance(
tau) -
tau.p4().eta(), 0.0042f, 0.0323f);
1934 template <
typename Cand
idateCastType,
typename TauCastType>
1936 const TauCastType&
tau,
1937 const size_t tau_index,
1941 const std::vector<pat::Electron>*
electrons,
1943 const Cell& cell_map,
1950 const auto&
get = [&](
int var_index) ->
float& {
return inputs.tensor<
float, 4>()(
idx, 0, 0, var_index); };
1952 const bool valid_index_pf_ele = cell_map.count(CellObjectType::PfCand_electron);
1953 const bool valid_index_pf_gamma = cell_map.count(CellObjectType::PfCand_gamma);
1956 if (!cell_map.empty()) {
1962 if (valid_index_pf_ele) {
1963 size_t index_pf_ele = cell_map.at(CellObjectType::PfCand_electron);
1964 const auto& ele_cand = dynamic_cast<const CandidateCastType&>(pfCands.
at(index_pf_ele));
1966 get(dnn::pfCand_ele_valid) = valid_index_pf_ele;
1967 get(dnn::pfCand_ele_rel_pt) =
getValueNorm(pfCands.
at(index_pf_ele).polarP4().pt() /
tau.polarP4().pt(),
1968 is_inner ? 0.9792f : 0.304f,
1969 is_inner ? 0.5383f : 1.845f);
1970 get(dnn::pfCand_ele_deta) =
getValueLinear(pfCands.
at(index_pf_ele).polarP4().eta() -
tau.polarP4().eta(),
1971 is_inner ? -0.1f : -0.5f,
1972 is_inner ? 0.1f : 0.5f,
1975 is_inner ? -0.1
f : -0.5
f,
1976 is_inner ? 0.1
f : 0.5
f,
1978 get(dnn::pfCand_ele_pvAssociationQuality) =
1979 getValueLinear<int>(candFunc::getPvAssocationQuality(ele_cand), 0, 7,
true);
1980 get(dnn::pfCand_ele_puppiWeight) = is_inner ?
getValue(candFunc::getPuppiWeight(ele_cand, 0.9906834
f))
1981 :
getValue(candFunc::getPuppiWeight(ele_cand, 0.9669586
f));
1982 get(dnn::pfCand_ele_charge) =
getValue(ele_cand.charge());
1983 get(dnn::pfCand_ele_lostInnerHits) = getValue<int>(candFunc::getLostInnerHits(ele_cand, 0));
1984 get(dnn::pfCand_ele_numberOfPixelHits) =
getValueLinear(candFunc::getNumberOfPixelHits(ele_cand, 0), 0, 10,
true);
1985 get(dnn::pfCand_ele_vertex_dx) =
1986 getValueNorm(pfCands.
at(index_pf_ele).vertex().x() -
pv.position().x(), 0.f, 0.1221f);
1987 get(dnn::pfCand_ele_vertex_dy) =
1988 getValueNorm(pfCands.
at(index_pf_ele).vertex().y() -
pv.position().y(), 0.f, 0.1226f);
1989 get(dnn::pfCand_ele_vertex_dz) =
1990 getValueNorm(pfCands.
at(index_pf_ele).vertex().z() -
pv.position().z(), 0.001f, 1.024f);
1992 pfCands.
at(index_pf_ele).vertex().x() -
pv.position().x() - tau_funcs.getFlightLength(
tau, tau_index).x(),
1996 pfCands.
at(index_pf_ele).vertex().y() -
pv.position().y() - tau_funcs.getFlightLength(
tau, tau_index).y(),
2000 pfCands.
at(index_pf_ele).vertex().z() -
pv.position().z() - tau_funcs.getFlightLength(
tau, tau_index).z(),
2004 const bool hasTrackDetails = candFunc::getHasTrackDetails(ele_cand);
2005 if (hasTrackDetails) {
2006 get(dnn::pfCand_ele_hasTrackDetails) = hasTrackDetails;
2007 get(dnn::pfCand_ele_dxy) =
getValueNorm(candFunc::getTauDxy(ele_cand), 0.
f, 0.171
f);
2008 get(dnn::pfCand_ele_dxy_sig) =
2009 getValueNorm(
std::abs(candFunc::getTauDxy(ele_cand)) / pfCands.
at(index_pf_ele).dxyError(), 1.634f, 6.45f);
2010 get(dnn::pfCand_ele_dz) =
getValueNorm(candFunc::getTauDz(ele_cand), 0.001
f, 1.02
f);
2011 get(dnn::pfCand_ele_dz_sig) =
2014 candFunc::getPseudoTrack(ele_cand).
chi2() / candFunc::getPseudoTrack(ele_cand).
ndof(), 2.272
f, 8.439
f);
2015 get(dnn::pfCand_ele_track_ndof) =
getValueNorm(candFunc::getPseudoTrack(ele_cand).
ndof(), 15.18
f, 3.203
f);
2018 if (valid_index_pf_gamma) {
2019 size_t index_pf_gamma = cell_map.at(CellObjectType::PfCand_gamma);
2020 const auto& gamma_cand = dynamic_cast<const CandidateCastType&>(pfCands.
at(index_pf_gamma));
2022 get(dnn::pfCand_gamma_valid) = valid_index_pf_gamma;
2023 get(dnn::pfCand_gamma_rel_pt) =
getValueNorm(pfCands.
at(index_pf_gamma).polarP4().pt() /
tau.polarP4().pt(),
2024 is_inner ? 0.6048f : 0.02576f,
2025 is_inner ? 1.669f : 0.3833f);
2026 get(dnn::pfCand_gamma_deta) =
getValueLinear(pfCands.
at(index_pf_gamma).polarP4().eta() -
tau.polarP4().eta(),
2027 is_inner ? -0.1f : -0.5f,
2028 is_inner ? 0.1f : 0.5f,
2031 is_inner ? -0.1
f : -0.5
f,
2032 is_inner ? 0.1
f : 0.5
f,
2034 get(dnn::pfCand_gamma_pvAssociationQuality) =
2035 getValueLinear<int>(candFunc::getPvAssocationQuality(gamma_cand), 0, 7,
true);
2036 get(dnn::pfCand_gamma_fromPV) = getValueLinear<int>(candFunc::getFromPV(gamma_cand), 0, 3,
true);
2037 get(dnn::pfCand_gamma_puppiWeight) = is_inner ?
getValue(candFunc::getPuppiWeight(gamma_cand, 0.9084110
f))
2038 :
getValue(candFunc::getPuppiWeight(gamma_cand, 0.4211567
f));
2039 get(dnn::pfCand_gamma_puppiWeightNoLep) = is_inner
2040 ?
getValue(candFunc::getPuppiWeightNoLep(gamma_cand, 0.8857716
f))
2041 :
getValue(candFunc::getPuppiWeightNoLep(gamma_cand, 0.3822604
f));
2042 get(dnn::pfCand_gamma_lostInnerHits) = getValue<int>(candFunc::getLostInnerHits(gamma_cand, 0));
2043 get(dnn::pfCand_gamma_numberOfPixelHits) =
2044 getValueLinear(candFunc::getNumberOfPixelHits(gamma_cand, 0), 0, 7,
true);
2045 get(dnn::pfCand_gamma_vertex_dx) =
2046 getValueNorm(pfCands.
at(index_pf_gamma).vertex().x() -
pv.position().x(), 0.f, 0.0067f);
2047 get(dnn::pfCand_gamma_vertex_dy) =
2048 getValueNorm(pfCands.
at(index_pf_gamma).vertex().y() -
pv.position().y(), 0.f, 0.0069f);
2049 get(dnn::pfCand_gamma_vertex_dz) =
2050 getValueNorm(pfCands.
at(index_pf_gamma).vertex().z() -
pv.position().z(), 0.f, 0.0578f);
2052 pfCands.
at(index_pf_gamma).vertex().x() -
pv.position().x() - tau_funcs.getFlightLength(
tau, tau_index).x(),
2056 pfCands.
at(index_pf_gamma).vertex().y() -
pv.position().y() - tau_funcs.getFlightLength(
tau, tau_index).y(),
2060 pfCands.
at(index_pf_gamma).vertex().z() -
pv.position().z() - tau_funcs.getFlightLength(
tau, tau_index).z(),
2063 const bool hasTrackDetails = candFunc::getHasTrackDetails(gamma_cand);
2064 if (hasTrackDetails) {
2065 get(dnn::pfCand_gamma_hasTrackDetails) = hasTrackDetails;
2066 get(dnn::pfCand_gamma_dxy) =
getValueNorm(candFunc::getTauDxy(gamma_cand), 0.0004
f, 0.882
f);
2067 get(dnn::pfCand_gamma_dxy_sig) =
2068 getValueNorm(
std::abs(candFunc::getTauDxy(gamma_cand)) / gamma_cand.dxyError(), 4.271f, 63.78f);
2069 get(dnn::pfCand_gamma_dz) =
getValueNorm(candFunc::getTauDz(gamma_cand), 0.0071
f, 5.285
f);
2070 get(dnn::pfCand_gamma_dz_sig) =
2072 get(dnn::pfCand_gamma_track_chi2_ndof) = candFunc::getPseudoTrack(gamma_cand).ndof() > 0
2074 candFunc::getPseudoTrack(gamma_cand).
ndof(),
2078 get(dnn::pfCand_gamma_track_ndof) =
2079 candFunc::getPseudoTrack(gamma_cand).ndof() > 0
2084 if (valid_index_ele) {
2087 get(dnn::ele_valid) = valid_index_ele;
2089 is_inner ? 1.067f : 0.5111f,
2090 is_inner ? 1.521f : 2.765f);
2092 is_inner ? -0.1f : -0.5f,
2093 is_inner ? 0.1f : 0.5f,
2096 is_inner ? -0.1
f : -0.5
f,
2097 is_inner ? 0.1
f : 0.5
f,
2100 float cc_ele_energy, cc_gamma_energy;
2102 const bool cc_valid =
2105 get(dnn::ele_cc_valid) = cc_valid;
2106 get(dnn::ele_cc_ele_rel_energy) =
2108 get(dnn::ele_cc_gamma_rel_energy) =
getValueNorm(cc_gamma_energy / cc_ele_energy, 0.1439
f, 0.3284
f);
2112 electrons->at(index_ele).trackMomentumAtVtx().R() /
electrons->at(index_ele).polarP4().pt(), 1.531f, 1.424f);
2114 electrons->at(index_ele).trackMomentumAtCalo().R() /
electrons->at(index_ele).polarP4().pt(), 1.531f, 1.424f);
2116 electrons->at(index_ele).trackMomentumOut().R() /
electrons->at(index_ele).polarP4().pt(), 0.7735f, 0.935f);
2117 get(dnn::ele_rel_trackMomentumAtEleClus) =
2122 electrons->at(index_ele).trackMomentumAtVtxWithConstraint().R() /
electrons->at(index_ele).polarP4().pt(),
2125 get(dnn::ele_rel_ecalEnergy) =
2128 electrons->at(index_ele).ecalEnergy() /
electrons->at(index_ele).ecalEnergyError(), 70.25f, 58.16f);
2133 get(dnn::ele_deltaEtaSuperClusterTrackAtVtx) =
2135 get(dnn::ele_deltaEtaSeedClusterTrackAtCalo) =
2137 get(dnn::ele_deltaEtaEleClusterTrackAtCalo) =
2139 get(dnn::ele_deltaPhiEleClusterTrackAtCalo) =
2141 get(dnn::ele_deltaPhiSuperClusterTrackAtVtx) =
2143 get(dnn::ele_deltaPhiSeedClusterTrackAtCalo) =
2147 get(dnn::ele_mvaInput_sigmaEtaEta) =
2151 const auto& gsfTrack =
electrons->at(index_ele).gsfTrack();
2152 if (gsfTrack.isNonnull()) {
2153 get(dnn::ele_gsfTrack_normalizedChi2) =
getValueNorm(gsfTrack->normalizedChi2(), 3.049f, 10.39f);
2154 get(dnn::ele_gsfTrack_numberOfValidHits) =
getValueNorm(gsfTrack->numberOfValidHits(), 16.52f, 2.806f);
2155 get(dnn::ele_rel_gsfTrack_pt) =
2157 get(dnn::ele_gsfTrack_pt_sig) =
getValueNorm(gsfTrack->pt() / gsfTrack->ptError(), 5.046f, 3.119f);
2159 const auto& closestCtfTrack =
electrons->at(index_ele).closestCtfTrackRef();
2160 const bool has_closestCtfTrack = closestCtfTrack.isNonnull();
2161 if (has_closestCtfTrack) {
2162 get(dnn::ele_has_closestCtfTrack) = has_closestCtfTrack;
2163 get(dnn::ele_closestCtfTrack_normalizedChi2) =
getValueNorm(closestCtfTrack->normalizedChi2(), 2.411f, 6.98f);
2164 get(dnn::ele_closestCtfTrack_numberOfValidHits) =
2165 getValueNorm(closestCtfTrack->numberOfValidHits(), 15.16f, 5.26f);
2170 template <
typename Cand
idateCastType,
typename TauCastType>
2172 const TauCastType&
tau,
2173 const size_t tau_index,
2177 const std::vector<pat::Muon>*
muons,
2179 const Cell& cell_map,
2186 const auto&
get = [&](
int var_index) ->
float& {
return inputs.tensor<
float, 4>()(
idx, 0, 0, var_index); };
2188 const bool valid_index_pf_muon = cell_map.count(CellObjectType::PfCand_muon);
2191 if (!cell_map.empty()) {
2197 if (valid_index_pf_muon) {
2198 size_t index_pf_muon = cell_map.at(CellObjectType::PfCand_muon);
2199 const auto& muon_cand = dynamic_cast<const CandidateCastType&>(pfCands.
at(index_pf_muon));
2201 get(dnn::pfCand_muon_valid) = valid_index_pf_muon;
2202 get(dnn::pfCand_muon_rel_pt) =
getValueNorm(pfCands.
at(index_pf_muon).polarP4().pt() /
tau.polarP4().pt(),
2203 is_inner ? 0.9509f : 0.0861f,
2204 is_inner ? 0.4294f : 0.4065f);
2205 get(dnn::pfCand_muon_deta) =
getValueLinear(pfCands.
at(index_pf_muon).polarP4().eta() -
tau.polarP4().eta(),
2206 is_inner ? -0.1f : -0.5f,
2207 is_inner ? 0.1f : 0.5f,
2210 is_inner ? -0.1
f : -0.5
f,
2211 is_inner ? 0.1
f : 0.5
f,
2213 get(dnn::pfCand_muon_pvAssociationQuality) =
2214 getValueLinear<int>(candFunc::getPvAssocationQuality(muon_cand), 0, 7,
true);
2215 get(dnn::pfCand_muon_fromPV) = getValueLinear<int>(candFunc::getFromPV(muon_cand), 0, 3,
true);
2216 get(dnn::pfCand_muon_puppiWeight) = is_inner ?
getValue(candFunc::getPuppiWeight(muon_cand, 0.9786588
f))
2217 :
getValue(candFunc::getPuppiWeight(muon_cand, 0.8132477
f));
2218 get(dnn::pfCand_muon_charge) =
getValue(muon_cand.charge());
2219 get(dnn::pfCand_muon_lostInnerHits) = getValue<int>(candFunc::getLostInnerHits(muon_cand, 0));
2220 get(dnn::pfCand_muon_numberOfPixelHits) =
2221 getValueLinear(candFunc::getNumberOfPixelHits(muon_cand, 0), 0, 11,
true);
2222 get(dnn::pfCand_muon_vertex_dx) =
2223 getValueNorm(pfCands.
at(index_pf_muon).vertex().x() -
pv.position().x(), -0.0007f, 0.6869f);
2224 get(dnn::pfCand_muon_vertex_dy) =
2225 getValueNorm(pfCands.
at(index_pf_muon).vertex().y() -
pv.position().y(), 0.0001f, 0.6784f);
2226 get(dnn::pfCand_muon_vertex_dz) =
2227 getValueNorm(pfCands.
at(index_pf_muon).vertex().z() -
pv.position().z(), -0.0117f, 4.097f);
2229 pfCands.
at(index_pf_muon).vertex().x() -
pv.position().x() - tau_funcs.getFlightLength(
tau, tau_index).x(),
2233 pfCands.
at(index_pf_muon).vertex().y() -
pv.position().y() - tau_funcs.getFlightLength(
tau, tau_index).y(),
2237 pfCands.
at(index_pf_muon).vertex().z() -
pv.position().z() - tau_funcs.getFlightLength(
tau, tau_index).z(),
2241 const bool hasTrackDetails = candFunc::getHasTrackDetails(muon_cand);
2242 if (hasTrackDetails) {
2243 get(dnn::pfCand_muon_hasTrackDetails) = hasTrackDetails;
2244 get(dnn::pfCand_muon_dxy) =
getValueNorm(candFunc::getTauDxy(muon_cand), -0.0045
f, 0.9655
f);
2245 get(dnn::pfCand_muon_dxy_sig) =
2247 get(dnn::pfCand_muon_dz) =
getValueNorm(candFunc::getTauDz(muon_cand), -0.0117
f, 4.097
f);
2248 get(dnn::pfCand_muon_dz_sig) =
2251 candFunc::getPseudoTrack(muon_cand).
chi2() / candFunc::getPseudoTrack(muon_cand).
ndof(), 0.69
f, 1.711
f);
2252 get(dnn::pfCand_muon_track_ndof) =
getValueNorm(candFunc::getPseudoTrack(muon_cand).
ndof(), 17.5
f, 5.11
f);
2255 if (valid_index_muon) {
2258 get(dnn::muon_valid) = valid_index_muon;
2260 is_inner ? 0.7966f : 0.2678f,
2261 is_inner ? 3.402f : 3.592f);
2263 is_inner ? -0.1f : -0.5f,
2264 is_inner ? 0.1f : 0.5f,
2267 is_inner ? -0.1
f : -0.5
f,
2268 is_inner ? 0.1
f : 0.5
f,
2271 get(dnn::muon_dxy_sig) =
2276 const bool normalizedChi2_valid =
2277 muons->at(index_muon).globalTrack().isNonnull() &&
muons->at(index_muon).normChi2() >= 0;
2278 if (normalizedChi2_valid) {
2279 get(dnn::muon_normalizedChi2_valid) = normalizedChi2_valid;
2280 get(dnn::muon_normalizedChi2) =
getValueNorm(
muons->at(index_muon).normChi2(), 21.52f, 265.8f);
2281 if (
muons->at(index_muon).innerTrack().isNonnull())
2282 get(dnn::muon_numberOfValidHits) =
getValueNorm(
muons->at(index_muon).numberOfValidHits(), 21.84f, 10.59f);
2284 get(dnn::muon_segmentCompatibility) =
getValue(
muons->at(index_muon).segmentCompatibility());
2285 get(dnn::muon_caloCompatibility) =
getValue(
muons->at(index_muon).caloCompatibility());
2287 const bool pfEcalEnergy_valid =
muons->at(index_muon).pfEcalEnergy() >= 0;
2288 if (pfEcalEnergy_valid) {
2289 get(dnn::muon_pfEcalEnergy_valid) = pfEcalEnergy_valid;
2290 get(dnn::muon_rel_pfEcalEnergy) =
2291 getValueNorm(
muons->at(index_muon).pfEcalEnergy() /
muons->at(index_muon).polarP4().pt(), 0.2273f, 0.4865f);
2294 MuonHitMatchV2 hit_match(
muons->at(index_muon));
2295 static const std::map<int, std::pair<int, int>> muonMatchHitVars = {
2300 static const std::map<int, std::vector<float>> muonMatchVarLimits = {
2301 {
MuonSubdetId::DT, {2, 2, 2, 2}}, {
MuonSubdetId::CSC, {6, 2, 2, 2}}, {
MuonSubdetId::RPC, {7, 6, 4, 4}}};
2303 static const std::map<int, std::vector<float>> muonHitVarLimits = {{
MuonSubdetId::DT, {12, 12, 12, 8}},
2307 for (
int subdet : hit_match.MuonHitMatchV2::consideredSubdets()) {
2308 const auto& matchHitVar = muonMatchHitVars.at(subdet);
2309 const auto& matchLimits = muonMatchVarLimits.at(subdet);
2310 const auto& hitLimits = muonHitVarLimits.at(subdet);
2311 for (
int station = MuonHitMatchV2::first_station_id;
station <= MuonHitMatchV2::last_station_id; ++
station) {
2312 const unsigned n_matches = hit_match.nMatches(subdet,
station);
2313 const unsigned n_hits = hit_match.nHits(subdet,
station);
2321 template <
typename Cand
idateCastType,
typename TauCastType>
2323 const TauCastType&
tau,
2324 const size_t tau_index,
2329 const Cell& cell_map,
2336 const auto&
get = [&](
int var_index) ->
float& {
return inputs.tensor<
float, 4>()(
idx, 0, 0, var_index); };
2338 const bool valid_chH = cell_map.count(CellObjectType::PfCand_chargedHadron);
2339 const bool valid_nH = cell_map.count(CellObjectType::PfCand_neutralHadron);
2341 if (!cell_map.empty()) {
2348 size_t index_chH = cell_map.at(CellObjectType::PfCand_chargedHadron);
2349 const auto& chH_cand = dynamic_cast<const CandidateCastType&>(pfCands.
at(index_chH));
2351 get(dnn::pfCand_chHad_valid) = valid_chH;
2352 get(dnn::pfCand_chHad_rel_pt) =
getValueNorm(pfCands.
at(index_chH).polarP4().pt() /
tau.polarP4().pt(),
2353 is_inner ? 0.2564f : 0.0194f,
2354 is_inner ? 0.8607f : 0.1865f);
2355 get(dnn::pfCand_chHad_deta) =
getValueLinear(pfCands.
at(index_chH).polarP4().eta() -
tau.polarP4().eta(),
2356 is_inner ? -0.1f : -0.5f,
2357 is_inner ? 0.1f : 0.5f,
2360 is_inner ? -0.1
f : -0.5
f,
2361 is_inner ? 0.1
f : 0.5
f,
2363 get(dnn::pfCand_chHad_leadChargedHadrCand) =
2364 getValue(&chH_cand == dynamic_cast<const CandidateCastType*>(
tau.leadChargedHadrCand().get()));
2365 get(dnn::pfCand_chHad_pvAssociationQuality) =
2366 getValueLinear<int>(candFunc::getPvAssocationQuality(chH_cand), 0, 7,
true);
2367 get(dnn::pfCand_chHad_fromPV) = getValueLinear<int>(candFunc::getFromPV(chH_cand), 0, 3,
true);
2368 const float default_chH_pw_inner = 0.7614090f;
2369 const float default_chH_pw_outer = 0.1974930f;
2370 get(dnn::pfCand_chHad_puppiWeight) = is_inner
2371 ?
getValue(candFunc::getPuppiWeight(chH_cand, default_chH_pw_inner))
2372 :
getValue(candFunc::getPuppiWeight(chH_cand, default_chH_pw_outer));
2373 get(dnn::pfCand_chHad_puppiWeightNoLep) =
2374 is_inner ?
getValue(candFunc::getPuppiWeightNoLep(chH_cand, default_chH_pw_inner))
2375 :
getValue(candFunc::getPuppiWeightNoLep(chH_cand, default_chH_pw_outer));
2376 get(dnn::pfCand_chHad_charge) =
getValue(chH_cand.charge());
2377 get(dnn::pfCand_chHad_lostInnerHits) = getValue<int>(candFunc::getLostInnerHits(chH_cand, 0));
2378 get(dnn::pfCand_chHad_numberOfPixelHits) =
2379 getValueLinear(candFunc::getNumberOfPixelHits(chH_cand, 0), 0, 12,
true);
2380 get(dnn::pfCand_chHad_vertex_dx) =
2381 getValueNorm(pfCands.
at(index_chH).vertex().x() -
pv.position().x(), 0.0005f, 1.735f);
2382 get(dnn::pfCand_chHad_vertex_dy) =
2383 getValueNorm(pfCands.
at(index_chH).vertex().y() -
pv.position().y(), -0.0008f, 1.752f);
2384 get(dnn::pfCand_chHad_vertex_dz) =
2385 getValueNorm(pfCands.
at(index_chH).vertex().z() -
pv.position().z(), -0.0201f, 8.333f);
2387 pfCands.
at(index_chH).vertex().x() -
pv.position().x() - tau_funcs.getFlightLength(
tau, tau_index).x(),
2391 pfCands.
at(index_chH).vertex().y() -
pv.position().y() - tau_funcs.getFlightLength(
tau, tau_index).y(),
2395 pfCands.
at(index_chH).vertex().z() -
pv.position().z() - tau_funcs.getFlightLength(
tau, tau_index).z(),
2399 const bool hasTrackDetails = candFunc::getHasTrackDetails(chH_cand);
2400 if (hasTrackDetails) {
2401 get(dnn::pfCand_chHad_hasTrackDetails) = hasTrackDetails;
2402 get(dnn::pfCand_chHad_dxy) =
getValueNorm(candFunc::getTauDxy(chH_cand), -0.012
f, 2.386
f);
2403 get(dnn::pfCand_chHad_dxy_sig) =
2405 get(dnn::pfCand_chHad_dz) =
getValueNorm(candFunc::getTauDz(chH_cand), -0.0246
f, 7.618
f);
2406 get(dnn::pfCand_chHad_dz_sig) =
2408 get(dnn::pfCand_chHad_track_chi2_ndof) =
2409 candFunc::getPseudoTrack(chH_cand).ndof() > 0
2410 ?
getValueNorm(candFunc::getPseudoTrack(chH_cand).
chi2() / candFunc::getPseudoTrack(chH_cand).
ndof(),
2414 get(dnn::pfCand_chHad_track_ndof) =
2415 candFunc::getPseudoTrack(chH_cand).ndof() > 0
2420 get(dnn::pfCand_chHad_hcalFraction) =
getValue(hcal_fraction);
2421 get(dnn::pfCand_chHad_rawCaloFraction) =
getValueLinear(candFunc::getRawCaloFraction(chH_cand), 0.
f, 2.6
f,
true);
2424 size_t index_nH = cell_map.at(CellObjectType::PfCand_neutralHadron);
2425 const auto& nH_cand = dynamic_cast<const CandidateCastType&>(pfCands.
at(index_nH));
2427 get(dnn::pfCand_nHad_valid) = valid_nH;
2428 get(dnn::pfCand_nHad_rel_pt) =
getValueNorm(pfCands.
at(index_nH).polarP4().pt() /
tau.polarP4().pt(),
2429 is_inner ? 0.3163f : 0.0502f,
2430 is_inner ? 0.2769f : 0.4266f);
2432 is_inner ? -0.1f : -0.5f,
2433 is_inner ? 0.1f : 0.5f,
2436 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);
2437 get(dnn::pfCand_nHad_puppiWeight) = is_inner ?
getValue(candFunc::getPuppiWeight(nH_cand, 0.9798355
f))
2438 :
getValue(candFunc::getPuppiWeight(nH_cand, 0.7813260
f));
2439 get(dnn::pfCand_nHad_puppiWeightNoLep) = is_inner ?
getValue(candFunc::getPuppiWeightNoLep(nH_cand, 0.9046796
f))
2440 :
getValue(candFunc::getPuppiWeightNoLep(nH_cand, 0.6554860
f));
2442 get(dnn::pfCand_nHad_hcalFraction) =
getValue(hcal_fraction);
2446 template <
typename dnn,
typename Cand
idateCastType,
typename TauCastType>
2448 const size_t tau_index,
2450 const std::vector<pat::Electron>*
electrons,
2451 const std::vector<pat::Muon>*
muons,
2452 TauFunc tau_funcs)
const {
2453 static constexpr
bool check_all_set =
false;
2454 static constexpr
float default_value_for_set_check = -42;
2456 tensorflow::Tensor
inputs(tensorflow::DT_FLOAT, {1, dnn_inputs_2017v1::NumberOfInputs});
2457 const auto&
get = [&](
int var_index) ->
float& {
return inputs.matrix<
float>()(0, var_index); };
2458 auto leadChargedHadrCand = dynamic_cast<const CandidateCastType*>(
tau.leadChargedHadrCand().get());
2460 if (check_all_set) {
2461 for (
int var_index = 0; var_index < dnn::NumberOfInputs; ++var_index) {
2462 get(var_index) = default_value_for_set_check;
2470 get(dnn::chargedIsoPtSum) = tau_funcs.getChargedIsoPtSum(
tau, tau_ref);
2471 get(dnn::neutralIsoPtSum) = tau_funcs.getNeutralIsoPtSum(
tau, tau_ref);
2472 get(dnn::neutralIsoPtSumWeight) = tau_funcs.getNeutralIsoPtSumWeight(
tau, tau_ref);
2473 get(dnn::photonPtSumOutsideSignalCone) = tau_funcs.getPhotonPtSumOutsideSignalCone(
tau, tau_ref);
2474 get(dnn::puCorrPtSum) = tau_funcs.getPuCorrPtSum(
tau, tau_ref);
2476 get(dnn::dxy_sig) = tau_funcs.getdxySig(
tau, tau_index);
2479 get(dnn::ip3d_sig) = tau_funcs.getip3dSig(
tau, tau_index);
2480 get(dnn::hasSecondaryVertex) = tau_funcs.getHasSecondaryVertex(
tau, tau_index);
2481 get(dnn::flightLength_r) = tau_funcs.getFlightLength(
tau, tau_index).R();
2482 get(dnn::flightLength_dEta) =
dEta(tau_funcs.getFlightLength(
tau, tau_index),
tau.p4());
2483 get(dnn::flightLength_dPhi) =
dPhi(tau_funcs.getFlightLength(
tau, tau_index),
tau.p4());
2484 get(dnn::flightLength_sig) = tau_funcs.getFlightLengthSig(
tau, tau_index);
2485 get(dnn::leadChargedHadrCand_pt) = leadChargedHadrCand ? leadChargedHadrCand->p4().Pt() :
default_value;
2486 get(dnn::leadChargedHadrCand_dEta) =
2488 get(dnn::leadChargedHadrCand_dPhi) =
2490 get(dnn::leadChargedHadrCand_mass) = leadChargedHadrCand ? leadChargedHadrCand->p4().mass() :
default_value;
2495 get(dnn::leadingTrackNormChi2) = tau_funcs.getLeadingTrackNormChi2(
tau);
2499 get(dnn::emFraction) = tau_funcs.getEmFraction(
tau);
2500 get(dnn::has_gsf_track) = leadChargedHadrCand &&
std::abs(leadChargedHadrCand->pdgId()) == 11;
2503 get(dnn::gsf_ele_matched) = gsf_ele !=
nullptr;
2504 get(dnn::gsf_ele_pt) = gsf_ele !=
nullptr ? gsf_ele->p4().Pt() :
default_value;
2507 get(dnn::gsf_ele_mass) = gsf_ele !=
nullptr ? gsf_ele->p4().mass() :
default_value;
2509 get(dnn::gsf_ele_Pin) = gsf_ele !=
nullptr ? gsf_ele->trackMomentumAtVtx().R() :
default_value;
2510 get(dnn::gsf_ele_Pout) = gsf_ele !=
nullptr ? gsf_ele->trackMomentumOut().R() :
default_value;
2511 get(dnn::gsf_ele_EtotOverPin) =
get(dnn::gsf_ele_Pin) > 0
2512 ? (
get(dnn::gsf_ele_Ee) +
get(dnn::gsf_ele_Egamma)) /
get(dnn::gsf_ele_Pin)
2514 get(dnn::gsf_ele_Eecal) = gsf_ele !=
nullptr ? gsf_ele->ecalEnergy() :
default_value;
2515 get(dnn::gsf_ele_dEta_SeedClusterTrackAtCalo) =
2516 gsf_ele !=
nullptr ? gsf_ele->deltaEtaSeedClusterTrackAtCalo() :
default_value;
2517 get(dnn::gsf_ele_dPhi_SeedClusterTrackAtCalo) =
2518 gsf_ele !=
nullptr ? gsf_ele->deltaPhiSeedClusterTrackAtCalo() :
default_value;
2519 get(dnn::gsf_ele_mvaIn_sigmaEtaEta) = gsf_ele !=
nullptr ? gsf_ele->mvaInput().sigmaEtaEta :
default_value;
2520 get(dnn::gsf_ele_mvaIn_hadEnergy) = gsf_ele !=
nullptr ? gsf_ele->mvaInput().hadEnergy :
default_value;
2521 get(dnn::gsf_ele_mvaIn_deltaEta) = gsf_ele !=
nullptr ? gsf_ele->mvaInput().deltaEta :
default_value;
2527 if (gsf_ele !=
nullptr && gsf_ele->gsfTrack().isNonnull()) {
2528 get(dnn::gsf_ele_Chi2NormGSF) = gsf_ele->gsfTrack()->normalizedChi2();
2529 get(dnn::gsf_ele_GSFNumHits) = gsf_ele->gsfTrack()->numberOfValidHits();
2530 if (gsf_ele->gsfTrack()->pt() > 0) {
2531 get(dnn::gsf_ele_GSFTrackResol) = gsf_ele->gsfTrack()->ptError() / gsf_ele->gsfTrack()->pt();
2532 get(dnn::gsf_ele_GSFTracklnPt) = std::log10(gsf_ele->gsfTrack()->pt());
2538 if (gsf_ele !=
nullptr && gsf_ele->closestCtfTrackRef().isNonnull()) {
2539 get(dnn::gsf_ele_Chi2NormKF) = gsf_ele->closestCtfTrackRef()->normalizedChi2();
2540 get(dnn::gsf_ele_KFNumHits) = gsf_ele->closestCtfTrackRef()->numberOfValidHits();
2542 get(dnn::leadChargedCand_etaAtEcalEntrance) = tau_funcs.getEtaAtEcalEntrance(
tau);
2543 get(dnn::leadChargedCand_pt) = leadChargedHadrCand->pt();
2547 if (leadChargedHadrCand->pt() > 0) {
2548 get(dnn::leadChargedHadrCand_HoP) = tau_funcs.getEcalEnergyLeadingChargedHadr(
tau) / leadChargedHadrCand->pt();
2549 get(dnn::leadChargedHadrCand_EoP) = tau_funcs.getHcalEnergyLeadingChargedHadr(
tau) / leadChargedHadrCand->pt();
2552 MuonHitMatchV1 muon_hit_match;
2553 if (
tau.leadPFChargedHadrCand().isNonnull() &&
tau.leadPFChargedHadrCand()->muonRef().isNonnull())
2554 muon_hit_match.addMatchedMuon(*
tau.leadPFChargedHadrCand()->muonRef(),
tau);
2556 auto matched_muons = muon_hit_match.findMatchedMuons(
tau,
muons, 0.3, 5);
2557 for (
auto muon : matched_muons)
2558 muon_hit_match.addMatchedMuon(*
muon,
tau);
2561 LorentzVectorXYZ signalChargedHadrCands_sumIn, signalChargedHadrCands_sumOut;
2563 tau.signalChargedHadrCands(),
2564 signalChargedHadrCands_sumIn,
2565 signalChargedHadrCands_sumOut,
2566 get(dnn::signalChargedHadrCands_sum_innerSigCone_pt),
2567 get(dnn::signalChargedHadrCands_sum_innerSigCone_dEta),
2568 get(dnn::signalChargedHadrCands_sum_innerSigCone_dPhi),
2569 get(dnn::signalChargedHadrCands_sum_innerSigCone_mass),
2570 get(dnn::signalChargedHadrCands_sum_outerSigCone_pt),
2571 get(dnn::signalChargedHadrCands_sum_outerSigCone_dEta),
2572 get(dnn::signalChargedHadrCands_sum_outerSigCone_dPhi),
2573 get(dnn::signalChargedHadrCands_sum_outerSigCone_mass),
2574 get(dnn::signalChargedHadrCands_nTotal_innerSigCone),
2575 get(dnn::signalChargedHadrCands_nTotal_outerSigCone));
2579 tau.signalNeutrHadrCands(),
2580 signalNeutrHadrCands_sumIn,
2581 signalNeutrHadrCands_sumOut,
2582 get(dnn::signalNeutrHadrCands_sum_innerSigCone_pt),
2583 get(dnn::signalNeutrHadrCands_sum_innerSigCone_dEta),
2584 get(dnn::signalNeutrHadrCands_sum_innerSigCone_dPhi),
2585 get(dnn::signalNeutrHadrCands_sum_innerSigCone_mass),
2586 get(dnn::signalNeutrHadrCands_sum_outerSigCone_pt),
2587 get(dnn::signalNeutrHadrCands_sum_outerSigCone_dEta),
2588 get(dnn::signalNeutrHadrCands_sum_outerSigCone_dPhi),
2589 get(dnn::signalNeutrHadrCands_sum_outerSigCone_mass),
2590 get(dnn::signalNeutrHadrCands_nTotal_innerSigCone),
2591 get(dnn::signalNeutrHadrCands_nTotal_outerSigCone));
2595 tau.signalGammaCands(),
2596 signalGammaCands_sumIn,
2597 signalGammaCands_sumOut,
2598 get(dnn::signalGammaCands_sum_innerSigCone_pt),
2599 get(dnn::signalGammaCands_sum_innerSigCone_dEta),
2600 get(dnn::signalGammaCands_sum_innerSigCone_dPhi),
2601 get(dnn::signalGammaCands_sum_innerSigCone_mass),
2602 get(dnn::signalGammaCands_sum_outerSigCone_pt),
2603 get(dnn::signalGammaCands_sum_outerSigCone_dEta),
2604 get(dnn::signalGammaCands_sum_outerSigCone_dPhi),
2605 get(dnn::signalGammaCands_sum_outerSigCone_mass),
2606 get(dnn::signalGammaCands_nTotal_innerSigCone),
2607 get(dnn::signalGammaCands_nTotal_outerSigCone));
2611 tau.isolationChargedHadrCands(),
2612 isolationChargedHadrCands_sum,
2613 get(dnn::isolationChargedHadrCands_sum_pt),
2614 get(dnn::isolationChargedHadrCands_sum_dEta),
2615 get(dnn::isolationChargedHadrCands_sum_dPhi),
2616 get(dnn::isolationChargedHadrCands_sum_mass),
2617 get(dnn::isolationChargedHadrCands_nTotal));
2621 tau.isolationNeutrHadrCands(),
2622 isolationNeutrHadrCands_sum,
2623 get(dnn::isolationNeutrHadrCands_sum_pt),
2624 get(dnn::isolationNeutrHadrCands_sum_dEta),
2625 get(dnn::isolationNeutrHadrCands_sum_dPhi),
2626 get(dnn::isolationNeutrHadrCands_sum_mass),
2627 get(dnn::isolationNeutrHadrCands_nTotal));
2631 tau.isolationGammaCands(),
2632 isolationGammaCands_sum,
2633 get(dnn::isolationGammaCands_sum_pt),
2634 get(dnn::isolationGammaCands_sum_dEta),
2635 get(dnn::isolationGammaCands_sum_dPhi),
2636 get(dnn::isolationGammaCands_sum_mass),
2637 get(dnn::isolationGammaCands_nTotal));
2639 get(dnn::tau_visMass_innerSigCone) = (signalGammaCands_sumIn + signalChargedHadrCands_sumIn).
mass();
2641 if (check_all_set) {
2642 for (
int var_index = 0; var_index < dnn::NumberOfInputs; ++var_index) {
2643 if (
get(var_index) == default_value_for_set_check)
2644 throw cms::Exception(
"DeepTauId: variable with index = ") << var_index <<
" is not set.";
2653 elecEe = elecEgamma = 0;
2655 if (superCluster.isNonnull() && superCluster.isAvailable() && superCluster->clusters().isNonnull() &&
2656 superCluster->clusters().isAvailable()) {
2657 for (
auto iter = superCluster->clustersBegin(); iter != superCluster->clustersEnd(); ++iter) {
2658 const double energy = (*iter)->energy();
2659 if (iter == superCluster->clustersBegin())
2670 template <
typename Cand
idateCollection,
typename TauCastType>
2693 const bool isInside_innerSigCone =
dR < innerSigCone_radius;
2694 if (isInside_innerSigCone) {
2695 p4_inner +=
cand->p4();
2698 p4_outer +=
cand->p4();
2714 template <
typename Cand
idateCollection,
typename TauCastType>
2738 static constexpr
double min_pt = 30., min_radius = 0.05, cone_opening_coef = 3.;
2744 template <
typename TauCastType>
2746 const size_t tau_index,
2748 TauFunc tau_funcs) {
2749 if (tau_funcs.getHasSecondaryVertex(
tau, tau_index)) {
2750 static constexpr
double mTau = 1.77682;
2751 const double mAOne =
tau.p4().M();
2752 const double pAOneMag =
tau.p();
2753 const double argumentThetaGJmax = (
std::pow(mTau, 2) -
std::pow(mAOne, 2)) / (2 * mTau * pAOneMag);
2754 const double argumentThetaGJmeasured =
tau.p4().Vect().Dot(tau_funcs.getFlightLength(
tau, tau_index)) /
2755 (pAOneMag * tau_funcs.getFlightLength(
tau, tau_index).R());
2756 if (
std::abs(argumentThetaGJmax) <= 1. &&
std::abs(argumentThetaGJmeasured) <= 1.) {
2757 double thetaGJmax = std::asin(argumentThetaGJmax);
2758 double thetaGJmeasured = std::acos(argumentThetaGJmeasured);
2759 gj_diff = thetaGJmeasured - thetaGJmax;
2766 template <
typename TauCastType>
2768 const size_t tau_index,
2769 TauFunc tau_funcs) {
2772 return static_cast<float>(gj_diff);
2778 return abs_eta > 1.46 && abs_eta < 1.558;
2781 template <
typename TauCastType>
2783 const std::vector<pat::Electron>*
electrons,
2788 if (
reco::deltaR2(
tau.p4(), ele.p4()) < dR2 && (!matched_ele || matched_ele->
pt() < ele.pt())) {