19 struct dnn_inputs_2017v1 {
27 neutralIsoPtSumWeight,
28 photonPtSumOutsideSignalCone,
40 leadChargedHadrCand_pt,
41 leadChargedHadrCand_dEta,
42 leadChargedHadrCand_dPhi,
43 leadChargedHadrCand_mass,
66 gsf_ele_dEta_SeedClusterTrackAtCalo,
67 gsf_ele_dPhi_SeedClusterTrackAtCalo,
68 gsf_ele_mvaIn_sigmaEtaEta,
69 gsf_ele_mvaIn_hadEnergy,
70 gsf_ele_mvaIn_deltaEta,
73 gsf_ele_GSFTrackResol,
77 leadChargedCand_etaAtEcalEntrance,
79 leadChargedHadrCand_HoP,
80 leadChargedHadrCand_EoP,
81 tau_visMass_innerSigCone,
103 muon_n_stations_with_matches_03,
104 muon_n_stations_with_hits_23,
105 signalChargedHadrCands_sum_innerSigCone_pt,
106 signalChargedHadrCands_sum_innerSigCone_dEta,
107 signalChargedHadrCands_sum_innerSigCone_dPhi,
108 signalChargedHadrCands_sum_innerSigCone_mass,
109 signalChargedHadrCands_sum_outerSigCone_pt,
110 signalChargedHadrCands_sum_outerSigCone_dEta,
111 signalChargedHadrCands_sum_outerSigCone_dPhi,
112 signalChargedHadrCands_sum_outerSigCone_mass,
113 signalChargedHadrCands_nTotal_innerSigCone,
114 signalChargedHadrCands_nTotal_outerSigCone,
115 signalNeutrHadrCands_sum_innerSigCone_pt,
116 signalNeutrHadrCands_sum_innerSigCone_dEta,
117 signalNeutrHadrCands_sum_innerSigCone_dPhi,
118 signalNeutrHadrCands_sum_innerSigCone_mass,
119 signalNeutrHadrCands_sum_outerSigCone_pt,
120 signalNeutrHadrCands_sum_outerSigCone_dEta,
121 signalNeutrHadrCands_sum_outerSigCone_dPhi,
122 signalNeutrHadrCands_sum_outerSigCone_mass,
123 signalNeutrHadrCands_nTotal_innerSigCone,
124 signalNeutrHadrCands_nTotal_outerSigCone,
125 signalGammaCands_sum_innerSigCone_pt,
126 signalGammaCands_sum_innerSigCone_dEta,
127 signalGammaCands_sum_innerSigCone_dPhi,
128 signalGammaCands_sum_innerSigCone_mass,
129 signalGammaCands_sum_outerSigCone_pt,
130 signalGammaCands_sum_outerSigCone_dEta,
131 signalGammaCands_sum_outerSigCone_dPhi,
132 signalGammaCands_sum_outerSigCone_mass,
133 signalGammaCands_nTotal_innerSigCone,
134 signalGammaCands_nTotal_outerSigCone,
135 isolationChargedHadrCands_sum_pt,
136 isolationChargedHadrCands_sum_dEta,
137 isolationChargedHadrCands_sum_dPhi,
138 isolationChargedHadrCands_sum_mass,
139 isolationChargedHadrCands_nTotal,
140 isolationNeutrHadrCands_sum_pt,
141 isolationNeutrHadrCands_sum_dEta,
142 isolationNeutrHadrCands_sum_dPhi,
143 isolationNeutrHadrCands_sum_mass,
144 isolationNeutrHadrCands_nTotal,
145 isolationGammaCands_sum_pt,
146 isolationGammaCands_sum_dEta,
147 isolationGammaCands_sum_dPhi,
148 isolationGammaCands_sum_mass,
149 isolationGammaCands_nTotal,
155 constexpr
int number_of_inner_cell = 11;
156 constexpr
int number_of_outer_cell = 21;
157 constexpr
int number_of_conv_features = 64;
158 namespace TauBlockInputs {
167 tau_n_charged_prongs,
168 tau_n_neutral_prongs,
170 chargedIsoPtSumdR03_over_dR05,
173 neutralIsoPtSumWeight_over_neutralIsoPtSum,
174 neutralIsoPtSumWeightdR03_over_neutralIsoPtSum,
175 neutralIsoPtSumdR03_over_dR05,
176 photonPtSumOutsideSignalCone,
193 tau_flightLength_sig,
194 tau_pt_weighted_deta_strip,
195 tau_pt_weighted_dphi_strip,
196 tau_pt_weighted_dr_signal,
197 tau_pt_weighted_dr_iso,
198 tau_leadingTrackNormChi2,
201 tau_gj_angle_diff_valid,
205 tau_inside_ecal_crack,
206 leadChargedCand_etaAtEcalEntrance_minus_tau_eta,
211 namespace EgammaBlockInputs {
216 tau_inside_ecal_crack,
221 pfCand_ele_pvAssociationQuality,
222 pfCand_ele_puppiWeight,
224 pfCand_ele_lostInnerHits,
225 pfCand_ele_numberOfPixelHits,
226 pfCand_ele_vertex_dx,
227 pfCand_ele_vertex_dy,
228 pfCand_ele_vertex_dz,
229 pfCand_ele_vertex_dx_tauFL,
230 pfCand_ele_vertex_dy_tauFL,
231 pfCand_ele_vertex_dz_tauFL,
232 pfCand_ele_hasTrackDetails,
237 pfCand_ele_track_chi2_ndof,
238 pfCand_ele_track_ndof,
244 ele_cc_ele_rel_energy,
245 ele_cc_gamma_rel_energy,
247 ele_rel_trackMomentumAtVtx,
248 ele_rel_trackMomentumAtCalo,
249 ele_rel_trackMomentumOut,
250 ele_rel_trackMomentumAtEleClus,
251 ele_rel_trackMomentumAtVtxWithConstraint,
254 ele_eSuperClusterOverP,
255 ele_eSeedClusterOverP,
256 ele_eSeedClusterOverPout,
257 ele_eEleClusterOverPout,
258 ele_deltaEtaSuperClusterTrackAtVtx,
259 ele_deltaEtaSeedClusterTrackAtCalo,
260 ele_deltaEtaEleClusterTrackAtCalo,
261 ele_deltaPhiEleClusterTrackAtCalo,
262 ele_deltaPhiSuperClusterTrackAtVtx,
263 ele_deltaPhiSeedClusterTrackAtCalo,
264 ele_mvaInput_earlyBrem,
265 ele_mvaInput_lateBrem,
266 ele_mvaInput_sigmaEtaEta,
267 ele_mvaInput_hadEnergy,
268 ele_mvaInput_deltaEta,
269 ele_gsfTrack_normalizedChi2,
270 ele_gsfTrack_numberOfValidHits,
273 ele_has_closestCtfTrack,
274 ele_closestCtfTrack_normalizedChi2,
275 ele_closestCtfTrack_numberOfValidHits,
280 pfCand_gamma_pvAssociationQuality,
282 pfCand_gamma_puppiWeight,
283 pfCand_gamma_puppiWeightNoLep,
284 pfCand_gamma_lostInnerHits,
285 pfCand_gamma_numberOfPixelHits,
286 pfCand_gamma_vertex_dx,
287 pfCand_gamma_vertex_dy,
288 pfCand_gamma_vertex_dz,
289 pfCand_gamma_vertex_dx_tauFL,
290 pfCand_gamma_vertex_dy_tauFL,
291 pfCand_gamma_vertex_dz_tauFL,
292 pfCand_gamma_hasTrackDetails,
294 pfCand_gamma_dxy_sig,
297 pfCand_gamma_track_chi2_ndof,
298 pfCand_gamma_track_ndof,
303 namespace MuonBlockInputs {
308 tau_inside_ecal_crack,
313 pfCand_muon_pvAssociationQuality,
315 pfCand_muon_puppiWeight,
317 pfCand_muon_lostInnerHits,
318 pfCand_muon_numberOfPixelHits,
319 pfCand_muon_vertex_dx,
320 pfCand_muon_vertex_dy,
321 pfCand_muon_vertex_dz,
322 pfCand_muon_vertex_dx_tauFL,
323 pfCand_muon_vertex_dy_tauFL,
324 pfCand_muon_vertex_dz_tauFL,
325 pfCand_muon_hasTrackDetails,
330 pfCand_muon_track_chi2_ndof,
331 pfCand_muon_track_ndof,
338 muon_normalizedChi2_valid,
340 muon_numberOfValidHits,
341 muon_segmentCompatibility,
342 muon_caloCompatibility,
343 muon_pfEcalEnergy_valid,
344 muon_rel_pfEcalEnergy,
349 muon_n_matches_CSC_1,
350 muon_n_matches_CSC_2,
351 muon_n_matches_CSC_3,
352 muon_n_matches_CSC_4,
353 muon_n_matches_RPC_1,
354 muon_n_matches_RPC_2,
355 muon_n_matches_RPC_3,
356 muon_n_matches_RPC_4,
373 namespace HadronBlockInputs {
378 tau_inside_ecal_crack,
383 pfCand_chHad_leadChargedHadrCand,
384 pfCand_chHad_pvAssociationQuality,
386 pfCand_chHad_puppiWeight,
387 pfCand_chHad_puppiWeightNoLep,
389 pfCand_chHad_lostInnerHits,
390 pfCand_chHad_numberOfPixelHits,
391 pfCand_chHad_vertex_dx,
392 pfCand_chHad_vertex_dy,
393 pfCand_chHad_vertex_dz,
394 pfCand_chHad_vertex_dx_tauFL,
395 pfCand_chHad_vertex_dy_tauFL,
396 pfCand_chHad_vertex_dz_tauFL,
397 pfCand_chHad_hasTrackDetails,
399 pfCand_chHad_dxy_sig,
402 pfCand_chHad_track_chi2_ndof,
403 pfCand_chHad_track_ndof,
404 pfCand_chHad_hcalFraction,
405 pfCand_chHad_rawCaloFraction,
410 pfCand_nHad_puppiWeight,
411 pfCand_nHad_puppiWeightNoLep,
412 pfCand_nHad_hcalFraction,
422 pfTauTransverseImpactParameters;
425 std::map<BasicDiscr, size_t> indexMap;
426 std::map<BasicDiscr, size_t> indexMapdR03;
429 return (*basicTauDiscriminatorCollection)[tau_ref].rawValues.at(indexMap.at(BasicDiscr::ChargedIsoPtSum));
432 return tau.tauID(
"chargedIsoPtSum");
435 return (*basicTauDiscriminatordR03Collection)[tau_ref].rawValues.at(indexMapdR03.at(BasicDiscr::ChargedIsoPtSum));
438 return tau.tauID(
"chargedIsoPtSumdR03");
441 return (*basicTauDiscriminatordR03Collection)[tau_ref].rawValues.at(
442 indexMapdR03.at(BasicDiscr::FootprintCorrection));
445 return tau.tauID(
"footprintCorrectiondR03");
448 return (*basicTauDiscriminatorCollection)[tau_ref].rawValues.at(indexMap.at(BasicDiscr::NeutralIsoPtSum));
451 return tau.tauID(
"neutralIsoPtSum");
454 return (*basicTauDiscriminatordR03Collection)[tau_ref].rawValues.at(indexMapdR03.at(BasicDiscr::NeutralIsoPtSum));
457 return tau.tauID(
"neutralIsoPtSumdR03");
460 return (*basicTauDiscriminatorCollection)[tau_ref].rawValues.at(indexMap.at(BasicDiscr::NeutralIsoPtSumWeight));
463 return tau.tauID(
"neutralIsoPtSumWeight");
467 return (*basicTauDiscriminatordR03Collection)[tau_ref].rawValues.at(
468 indexMapdR03.at(BasicDiscr::NeutralIsoPtSumWeight));
471 return tau.tauID(
"neutralIsoPtSumWeightdR03");
473 const float getPhotonPtSumOutsideSignalCone(
const reco::PFTau&
tau,
475 return (*basicTauDiscriminatorCollection)[tau_ref].rawValues.at(
476 indexMap.at(BasicDiscr::PhotonPtSumOutsideSignalCone));
478 const float getPhotonPtSumOutsideSignalCone(
const pat::Tau&
tau,
480 return tau.tauID(
"photonPtSumOutsideSignalCone");
482 const float getPhotonPtSumOutsideSignalConedR03(
const reco::PFTau&
tau,
484 return (*basicTauDiscriminatordR03Collection)[tau_ref].rawValues.at(
485 indexMapdR03.at(BasicDiscr::PhotonPtSumOutsideSignalCone));
487 const float getPhotonPtSumOutsideSignalConedR03(
const pat::Tau&
tau,
489 return tau.tauID(
"photonPtSumOutsideSignalConedR03");
492 return (*basicTauDiscriminatorCollection)[tau_ref].rawValues.at(indexMap.at(BasicDiscr::PUcorrPtSum));
495 return tau.tauID(
"puCorrPtSum");
498 auto getdxyPCA(
const reco::PFTau&
tau,
const size_t tau_index)
const {
499 return pfTauTransverseImpactParameters->
value(tau_index)->dxy_PCA();
501 auto getdxyPCA(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.dxy_PCA(); }
502 auto getdxy(
const reco::PFTau&
tau,
const size_t tau_index)
const {
503 return pfTauTransverseImpactParameters->
value(tau_index)->dxy();
505 auto getdxy(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.dxy(); }
506 auto getdxyError(
const reco::PFTau&
tau,
const size_t tau_index)
const {
507 return pfTauTransverseImpactParameters->
value(tau_index)->dxy_error();
509 auto getdxyError(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.dxy_error(); }
510 auto getdxySig(
const reco::PFTau&
tau,
const size_t tau_index)
const {
511 return pfTauTransverseImpactParameters->
value(tau_index)->dxy_Sig();
513 auto getdxySig(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.dxy_Sig(); }
514 auto getip3d(
const reco::PFTau&
tau,
const size_t tau_index)
const {
515 return pfTauTransverseImpactParameters->
value(tau_index)->ip3d();
517 auto getip3d(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.ip3d(); }
518 auto getip3dError(
const reco::PFTau&
tau,
const size_t tau_index)
const {
519 return pfTauTransverseImpactParameters->
value(tau_index)->ip3d_error();
521 auto getip3dError(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.ip3d_error(); }
522 auto getip3dSig(
const reco::PFTau&
tau,
const size_t tau_index)
const {
523 return pfTauTransverseImpactParameters->
value(tau_index)->ip3d_Sig();
525 auto getip3dSig(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.ip3d_Sig(); }
526 auto getHasSecondaryVertex(
const reco::PFTau&
tau,
const size_t tau_index)
const {
527 return pfTauTransverseImpactParameters->
value(tau_index)->hasSecondaryVertex();
529 auto getHasSecondaryVertex(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.hasSecondaryVertex(); }
530 auto getFlightLength(
const reco::PFTau&
tau,
const size_t tau_index)
const {
531 return pfTauTransverseImpactParameters->
value(tau_index)->flightLength();
533 auto getFlightLength(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.flightLength(); }
534 auto getFlightLengthSig(
const reco::PFTau&
tau,
const size_t tau_index)
const {
535 return pfTauTransverseImpactParameters->
value(tau_index)->flightLengthSig();
537 auto getFlightLengthSig(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.flightLengthSig(); }
540 auto getLeadingTrackNormChi2(
const pat::Tau&
tau) {
return tau.leadingTrackNormChi2(); }
541 auto getEmFraction(
const pat::Tau&
tau) {
return tau.emFraction_MVA(); }
543 auto getEtaAtEcalEntrance(
const pat::Tau&
tau) {
return tau.etaAtEcalEntranceLeadChargedCand(); }
545 return tau.leadPFChargedHadrCand()->positionAtECALEntrance().eta();
547 auto getEcalEnergyLeadingChargedHadr(
const reco::PFTau&
tau) {
return tau.leadPFChargedHadrCand()->ecalEnergy(); }
548 auto getEcalEnergyLeadingChargedHadr(
const pat::Tau&
tau) {
return tau.ecalEnergyLeadChargedHadrCand(); }
549 auto getHcalEnergyLeadingChargedHadr(
const reco::PFTau&
tau) {
return tau.leadPFChargedHadrCand()->hcalEnergy(); }
550 auto getHcalEnergyLeadingChargedHadr(
const pat::Tau&
tau) {
return tau.hcalEnergyLeadChargedHadrCand(); }
552 template <
typename PreDiscrType>
553 bool passPrediscriminants(
const PreDiscrType prediscriminants,
554 const size_t andPrediscriminants,
556 bool passesPrediscriminants = (andPrediscriminants ? 1 : 0);
558 size_t nPrediscriminants = prediscriminants.size();
559 for (
size_t iDisc = 0; iDisc < nPrediscriminants; ++iDisc) {
561 double discResult = (*prediscriminants[iDisc].handle)[tau_ref];
562 uint8_t thisPasses = (discResult > prediscriminants[iDisc].cut) ? 1 : 0;
579 if (thisPasses ^ andPrediscriminants)
581 passesPrediscriminants = (andPrediscriminants ? 0 : 1);
585 return passesPrediscriminants;
591 return cand.bestTrack() !=
nullptr ?
cand.bestTrack()->dz() : default_value;
595 return cand.bestTrack() !=
nullptr ?
cand.dzError() : default_value;
598 return cand.hasTrackDetails() ?
cand.dzError() : default_value;
601 return cand.bestTrack() !=
nullptr && std::isnormal(
cand.bestTrack()->dz()) && std::isnormal(
cand.dzError()) &&
605 return cand.hasTrackDetails() && std::isnormal(
cand.dz()) && std::isnormal(
cand.dzError()) &&
cand.dzError() > 0;
608 return cand.bestTrack() !=
nullptr ?
cand.bestTrack()->dxy() : default_value;
618 return cand.bestTrack() !=
nullptr
624 return cand.bestTrack() !=
nullptr
629 return cand.numberOfPixelHits();
638 return cand.rawHcalEnergy() / (
cand.rawHcalEnergy() +
cand.rawEcalEnergy());
641 float hcal_fraction = 0.;
642 if (
cand.pdgId() == 1 ||
cand.pdgId() == 130) {
643 hcal_fraction =
cand.hcalFraction();
644 }
else if (
cand.isIsolatedChargedHadron()) {
645 hcal_fraction =
cand.rawHcalFraction();
647 return hcal_fraction;
650 return (
cand.rawEcalEnergy() +
cand.rawHcalEnergy()) /
cand.energy();
655 template <
typename LVector1,
typename LVector2>
656 float dEta(
const LVector1&
p4,
const LVector2& tau_p4) {
657 return static_cast<float>(
p4.eta() - tau_p4.eta());
660 template <
typename LVector1,
typename LVector2>
661 float dPhi(
const LVector1& p4_1,
const LVector2& p4_2) {
662 return static_cast<float>(
reco::deltaPhi(p4_2.phi(), p4_1.phi()));
665 struct MuonHitMatchV1 {
666 static constexpr
int n_muon_stations = 4;
668 std::map<int, std::vector<UInt_t>> n_matches, n_hits;
670 const pat::Muon* best_matched_muon{
nullptr};
671 double deltaR2_best_match{-1};
683 static constexpr
int n_stations = 4;
687 if (!best_matched_muon || dR2 < deltaR2_best_match) {
688 best_matched_muon = &
muon;
689 deltaR2_best_match = dR2;
692 for (
const auto& segment :
muon.matches()) {
693 if (segment.segmentMatches.empty())
695 if (n_matches.count(segment.detector()))
696 ++n_matches.at(segment.detector()).at(segment.station() - 1);
699 if (
muon.outerTrack().isNonnull()) {
700 const auto& hit_pattern =
muon.outerTrack()->hitPattern();
707 const int station = hit_pattern.getMuonStation(hit_id) - 1;
709 std::vector<UInt_t>* muon_n_hits =
nullptr;
710 if (hit_pattern.muonDTHitFilter(hit_id))
712 else if (hit_pattern.muonCSCHitFilter(hit_id))
714 else if (hit_pattern.muonRPCHitFilter(hit_id))
725 template <
typename TauCastType>
726 static std::vector<const pat::Muon*> findMatchedMuons(
const TauCastType&
tau,
727 const std::vector<pat::Muon>*
muons,
731 if (
tau.leadPFChargedHadrCand().isNonnull() &&
tau.leadPFChargedHadrCand()->muonRef().isNonnull())
732 hadr_cand_muon =
tau.leadPFChargedHadrCand()->muonRef().get();
733 std::vector<const pat::Muon*> matched_muons;
739 if (reco_muon == hadr_cand_muon)
743 matched_muons.push_back(&
muon);
745 return matched_muons;
748 template <
typename dnn,
typename TensorElemGet,
typename TauCastType>
749 void fillTensor(
const TensorElemGet&
get,
const TauCastType&
tau,
float default_value)
const {
750 get(dnn::n_matched_muons) = n_muons;
751 get(dnn::muon_pt) = best_matched_muon !=
nullptr ? best_matched_muon->p4().pt() : default_value;
752 get(dnn::muon_dEta) = best_matched_muon !=
nullptr ?
dEta(best_matched_muon->p4(),
tau.p4()) : default_value;
753 get(dnn::muon_dPhi) = best_matched_muon !=
nullptr ?
dPhi(best_matched_muon->p4(),
tau.p4()) : default_value;
771 get(dnn::muon_n_stations_with_matches_03) = countMuonStationsWithMatches(0, 3);
772 get(dnn::muon_n_stations_with_hits_23) = countMuonStationsWithHits(2, 3);
776 unsigned countMuonStationsWithMatches(
size_t first_station,
size_t last_station)
const {
777 static const std::map<int, std::vector<bool>> masks = {
783 for (
unsigned n = first_station;
n <= last_station; ++
n) {
784 for (
const auto&
match : n_matches) {
785 if (!masks.at(
match.first).at(
n) &&
match.second.at(
n) > 0)
792 unsigned countMuonStationsWithHits(
size_t first_station,
size_t last_station)
const {
793 static const std::map<int, std::vector<bool>> masks = {
800 for (
unsigned n = first_station;
n <= last_station; ++
n) {
801 for (
const auto&
hit : n_hits) {
802 if (!masks.at(
hit.first).at(
n) &&
hit.second.at(
n) > 0)
810 struct MuonHitMatchV2 {
811 static constexpr
size_t n_muon_stations = 4;
812 static constexpr
int first_station_id = 1;
813 static constexpr
int last_station_id = first_station_id + n_muon_stations - 1;
814 using CountArray = std::array<unsigned, n_muon_stations>;
815 using CountMap = std::map<int, CountArray>;
817 const std::vector<int>& consideredSubdets() {
823 static const std::map<int, std::string> subdet_names = {
825 if (!subdet_names.count(subdet))
826 throw cms::Exception(
"MuonHitMatch") <<
"Subdet name for subdet id " << subdet <<
" not found.";
827 return subdet_names.at(subdet);
830 size_t getStationIndex(
int station,
bool throw_exception)
const {
831 if (station < first_station_id || station > last_station_id) {
833 throw cms::Exception(
"MuonHitMatch") <<
"Station id is out of range";
836 return static_cast<size_t>(
station - 1);
840 for (
int subdet : consideredSubdets()) {
841 n_matches[subdet].fill(0);
842 n_hits[subdet].fill(0);
850 for (
const auto& segment :
muon.matches()) {
851 if (segment.segmentMatches.empty() && segment.rpcMatches.empty())
853 if (n_matches.count(segment.detector())) {
854 const size_t station_index = getStationIndex(segment.station(),
true);
855 ++n_matches.at(segment.detector()).at(station_index);
861 if (
muon.outerTrack().isNonnull()) {
862 const auto& hit_pattern =
muon.outerTrack()->hitPattern();
869 const size_t station_index = getStationIndex(hit_pattern.getMuonStation(hit_id),
false);
870 if (station_index < n_muon_stations) {
871 CountArray* muon_n_hits =
nullptr;
872 if (hit_pattern.muonDTHitFilter(hit_id))
874 else if (hit_pattern.muonCSCHitFilter(hit_id))
876 else if (hit_pattern.muonRPCHitFilter(hit_id))
880 ++muon_n_hits->at(station_index);
887 unsigned nMatches(
int subdet,
int station)
const {
888 if (!n_matches.count(subdet))
889 throw cms::Exception(
"MuonHitMatch") <<
"Subdet " << subdet <<
" not found.";
890 const size_t station_index = getStationIndex(
station,
true);
891 return n_matches.at(subdet).at(station_index);
894 unsigned nHits(
int subdet,
int station)
const {
895 if (!n_hits.count(subdet))
896 throw cms::Exception(
"MuonHitMatch") <<
"Subdet " << subdet <<
" not found.";
897 const size_t station_index = getStationIndex(
station,
true);
898 return n_hits.at(subdet).at(station_index);
901 unsigned countMuonStationsWithMatches(
int first_station,
int last_station)
const {
902 static const std::map<int, std::vector<bool>> masks = {
907 const size_t first_station_index = getStationIndex(first_station,
true);
908 const size_t last_station_index = getStationIndex(last_station,
true);
910 for (
size_t n = first_station_index;
n <= last_station_index; ++
n) {
911 for (
const auto&
match : n_matches) {
912 if (!masks.at(
match.first).at(
n) &&
match.second.at(
n) > 0)
919 unsigned countMuonStationsWithHits(
int first_station,
int last_station)
const {
920 static const std::map<int, std::vector<bool>> masks = {
926 const size_t first_station_index = getStationIndex(first_station,
true);
927 const size_t last_station_index = getStationIndex(last_station,
true);
929 for (
size_t n = first_station_index;
n <= last_station_index; ++
n) {
930 for (
const auto&
hit : n_hits) {
931 if (!masks.at(
hit.first).at(
n) &&
hit.second.at(
n) > 0)
939 CountMap n_matches, n_hits;
945 PfCand_chargedHadron,
946 PfCand_neutralHadron,
953 template <
typename Object>
966 static const std::map<int, CellObjectType> obj_types = {{11, CellObjectType::PfCand_electron},
967 {13, CellObjectType::PfCand_muon},
968 {22, CellObjectType::PfCand_gamma},
969 {130, CellObjectType::PfCand_neutralHadron},
970 {211, CellObjectType::PfCand_chargedHadron}};
973 if (iter == obj_types.end())
974 return CellObjectType::Other;
978 using Cell = std::map<CellObjectType, size_t>;
991 using Map = std::map<CellIndex, Cell>;
992 using const_iterator = Map::const_iterator;
994 CellGrid(
unsigned n_cells_eta,
unsigned n_cells_phi,
double cell_size_eta,
double cell_size_phi)
995 : nCellsEta(n_cells_eta),
996 nCellsPhi(n_cells_phi),
997 nTotal(nCellsEta * nCellsPhi),
998 cellSizeEta(cell_size_eta),
999 cellSizePhi(cell_size_phi) {
1000 if (nCellsEta % 2 != 1 || nCellsEta < 1)
1001 throw cms::Exception(
"DeepTauId") <<
"Invalid number of eta cells.";
1002 if (nCellsPhi % 2 != 1 || nCellsPhi < 1)
1003 throw cms::Exception(
"DeepTauId") <<
"Invalid number of phi cells.";
1004 if (cellSizeEta <= 0 || cellSizePhi <= 0)
1008 int maxEtaIndex()
const {
return static_cast<int>((nCellsEta - 1) / 2); }
1009 int maxPhiIndex()
const {
return static_cast<int>((nCellsPhi - 1) / 2); }
1010 double maxDeltaEta()
const {
return cellSizeEta * (0.5 + maxEtaIndex()); }
1011 double maxDeltaPhi()
const {
return cellSizePhi * (0.5 + maxPhiIndex()); }
1012 int getEtaTensorIndex(
const CellIndex& cellIndex)
const {
return cellIndex.eta + maxEtaIndex(); }
1013 int getPhiTensorIndex(
const CellIndex& cellIndex)
const {
return cellIndex.phi + maxPhiIndex(); }
1015 bool tryGetCellIndex(
double deltaEta,
double deltaPhi, CellIndex& cellIndex)
const {
1016 static auto getCellIndex = [](
double x,
double maxX,
double size,
int&
index) {
1020 const double absIndex = std::floor(
std::abs(absX /
size - 0.5));
1021 index = static_cast<int>(std::copysign(absIndex,
x));
1029 size_t num_valid_cells()
const {
return cells.size(); }
1031 const Cell& at(
const CellIndex& cellIndex)
const {
return cells.at(cellIndex); }
1032 size_t count(
const CellIndex& cellIndex)
const {
return cells.count(cellIndex); }
1033 const_iterator
find(
const CellIndex& cellIndex)
const {
return cells.find(cellIndex); }
1034 const_iterator begin()
const {
return cells.begin(); }
1035 const_iterator
end()
const {
return cells.end(); }
1038 const unsigned nCellsEta, nCellsPhi, nTotal;
1039 const double cellSizeEta, cellSizePhi;
1042 std::map<CellIndex, Cell>
cells;
1049 {bd::ChargedIsoPtSum,
"ChargedIsoPtSum"},
1050 {bd::NeutralIsoPtSum,
"NeutralIsoPtSum"},
1051 {bd::NeutralIsoPtSumWeight,
"NeutralIsoPtSumWeight"},
1052 {bd::FootprintCorrection,
"TauFootprintCorrection"},
1053 {bd::PhotonPtSumOutsideSignalCone,
"PhotonPtSumOutsideSignalCone"},
1054 {bd::PUcorrPtSum,
"PUcorrPtSum"}};
1056 bd::NeutralIsoPtSum,
1057 bd::NeutralIsoPtSumWeight,
1058 bd::PhotonPtSumOutsideSignalCone,
1061 bd::NeutralIsoPtSum,
1062 bd::NeutralIsoPtSumWeight,
1063 bd::PhotonPtSumOutsideSignalCone,
1064 bd::FootprintCorrection};
1071 static constexpr
size_t e_index = 0, mu_index = 1, tau_index = 2, jet_index = 3;
1073 {
"VSe",
Output({tau_index}, {e_index, tau_index})},
1074 {
"VSmu",
Output({tau_index}, {mu_index, tau_index})},
1075 {
"VSjet",
Output({tau_index}, {jet_index, tau_index})},
1083 std::vector<BasicDiscriminator> requiredDiscr) {
1084 std::map<std::string, size_t> discrIndexMapStr;
1085 auto const aHandle =
event.getHandle(discriminatorContainerToken);
1086 auto const aProv = aHandle.provenance();
1087 if (aProv ==
nullptr)
1088 aHandle.whyFailed()->raise();
1090 auto const idlist = psetsFromProvenance.
getParameter<std::vector<edm::ParameterSet>>(
"IDdefinitions");
1091 for (
size_t j = 0;
j < idlist.size(); ++
j) {
1093 if (discrIndexMapStr.count(idname)) {
1095 <<
"basic discriminator " << idname <<
" appears more than once in the input.";
1097 discrIndexMapStr[idname] =
j;
1101 std::map<BasicDiscriminator, size_t> discrIndexMap;
1102 for (
size_t i = 0;
i < requiredDiscr.size();
i++) {
1105 <<
" was not provided in the config file.";
1109 return discrIndexMap;
1120 desc.add<std::vector<std::string>>(
"graph_file",
1121 {
"RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6.pb"});
1122 desc.add<
bool>(
"mem_mapped",
false);
1123 desc.add<
unsigned>(
"version", 2);
1124 desc.add<
int>(
"debug_level", 0);
1125 desc.add<
bool>(
"disable_dxy_pca",
false);
1126 desc.add<
bool>(
"is_online",
false);
1128 desc.add<std::vector<std::string>>(
"VSeWP");
1129 desc.add<std::vector<std::string>>(
"VSmuWP");
1130 desc.add<std::vector<std::string>>(
"VSjetWP");
1138 pset_Prediscriminants.
add<
std::string>(
"BooleanOperator",
"and");
1141 psd1.
add<
double>(
"cut");
1148 descriptions.
add(
"DeepTau",
desc);
1158 cfg.getUntrackedParameter<
edm::
InputTag>(
"basicTauDiscriminators"))),
1160 cfg.getUntrackedParameter<
edm::
InputTag>(
"basicTauDiscriminatorsdR03"))),
1163 cfg.getParameter<
edm::
InputTag>(
"pfTauTransverseImpactParameters"))),
1170 const auto& shape =
cache_->
getGraph().node(0).attr().at(
"shape").shape();
1171 if (shape.dim(1).size() != dnn_inputs_2017v1::NumberOfInputs)
1173 <<
"number of inputs does not match the expected inputs for the given version";
1176 tensorflow::DT_FLOAT, tensorflow::TensorShape{1, dnn_inputs_2017_v2::TauBlockInputs::NumberOfInputs});
1177 for (
size_t n = 0;
n < 2; ++
n) {
1178 const bool is_inner =
n == 0;
1179 const auto n_cells =
1180 is_inner ? dnn_inputs_2017_v2::number_of_inner_cell : dnn_inputs_2017_v2::number_of_outer_cell;
1181 eGammaTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1182 tensorflow::DT_FLOAT,
1183 tensorflow::TensorShape{1, 1, 1, dnn_inputs_2017_v2::EgammaBlockInputs::NumberOfInputs});
1184 muonTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1185 tensorflow::DT_FLOAT,
1186 tensorflow::TensorShape{1, 1, 1, dnn_inputs_2017_v2::MuonBlockInputs::NumberOfInputs});
1188 tensorflow::DT_FLOAT,
1189 tensorflow::TensorShape{1, 1, 1, dnn_inputs_2017_v2::HadronBlockInputs::NumberOfInputs});
1190 convTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1191 tensorflow::DT_FLOAT,
1192 tensorflow::TensorShape{1, n_cells, n_cells, dnn_inputs_2017_v2::number_of_conv_features});
1194 tensorflow::DT_FLOAT, tensorflow::TensorShape{1, 1, 1, dnn_inputs_2017_v2::number_of_conv_features});
1208 return DeepTauBase::initializeGlobalCache(
cfg);
1216 template <
typename T>
1218 return std::isnormal(
value) ? static_cast<float>(
value) : 0.f;
1221 template <
typename T>
1227 transformed_value = transformed_value * 2 - 1;
1228 return transformed_value;
1231 template <
typename T>
1234 const float norm_value = (fixed_value -
mean) / sigma;
1235 return std::clamp(norm_value, -n_sigmas_max, n_sigmas_max);
1241 float& cc_ele_energy,
1242 float& cc_gamma_energy,
1244 cc_ele_energy = cc_gamma_energy = 0;
1247 if (superCluster.isNonnull() && superCluster.isAvailable() && superCluster->clusters().isNonnull() &&
1248 superCluster->clusters().isAvailable()) {
1249 for (
auto iter = superCluster->clustersBegin(); iter != superCluster->clustersEnd(); ++iter) {
1250 const float energy = static_cast<float>((*iter)->energy());
1251 if (iter == superCluster->clustersBegin())
1254 cc_gamma_energy +=
energy;
1264 const tensorflow::Tensor&
inputs,
const char* block_name,
int n_inputs,
int n_eta = 1,
int n_phi = 1)
const {
1268 for (
int k = 0;
k < n_inputs; ++
k) {
1273 <<
"in the " << block_name <<
", input is not finite, i.e. infinite or NaN, for eta_index = " << n_eta
1274 <<
", phi_index = " << n_phi <<
", input_index = " <<
k;
1276 std::cout << block_name <<
"," <<
eta <<
"," <<
phi <<
"," <<
k <<
"," << std::setprecision(5)
1287 const std::vector<pat::Electron> electron_collection_default;
1288 const std::vector<pat::Muon> muon_collection_default;
1292 pfTauTransverseImpactParameters_default;
1294 const std::vector<pat::Electron>* electron_collection;
1295 const std::vector<pat::Muon>* muon_collection;
1299 pfTauTransverseImpactParameters;
1304 pfTauTransverseImpactParameters = &pfTauTransverseImpactParameters_default;
1305 basicTauDiscriminators = &basicTauDiscriminators_default;
1306 basicTauDiscriminatorsdR03 = &basicTauDiscriminatorsdR03_default;
1308 electron_collection = &electron_collection_default;
1309 muon_collection = &muon_collection_default;
1324 TauFunc tauIDs = {basicTauDiscriminators,
1325 basicTauDiscriminatorsdR03,
1326 pfTauTransverseImpactParameters,
1341 for (
size_t tau_index = 0; tau_index <
taus->size(); ++tau_index) {
1344 std::vector<tensorflow::Tensor> pred_vector;
1346 bool passesPrediscriminants;
1348 passesPrediscriminants = tauIDs.passPrediscriminants<std::vector<TauDiscInfo<reco::PFTauDiscriminator>>>(
1351 passesPrediscriminants = tauIDs.passPrediscriminants<std::vector<TauDiscInfo<pat::PATTauDiscriminator>>>(
1355 if (passesPrediscriminants) {
1358 getPredictionsV1<reco::PFCandidate, reco::PFTau>(
1359 taus->at(tau_index), tau_index, tauRef, electron_collection, muon_collection, pred_vector, tauIDs);
1361 getPredictionsV1<pat::PackedCandidate, pat::Tau>(
1362 taus->at(tau_index), tau_index, tauRef, electron_collection, muon_collection, pred_vector, tauIDs);
1365 getPredictionsV2<reco::PFCandidate, reco::PFTau>(
taus->at(tau_index),
1368 electron_collection,
1376 getPredictionsV2<pat::PackedCandidate, pat::Tau>(
taus->at(tau_index),
1379 electron_collection,
1391 const float pred = pred_vector[0].flat<
float>()(
k);
1392 if (!(pred >= 0 && pred <= 1))
1394 <<
"invalid prediction = " << pred <<
" for tau_index = " << tau_index <<
", pred_index = " <<
k;
1395 predictions.matrix<
float>()(tau_index,
k) = pred;
1402 template <
typename Cand
idateCastType,
typename TauCastType>
1404 const size_t tau_index,
1406 const std::vector<pat::Electron>*
electrons,
1407 const std::vector<pat::Muon>*
muons,
1408 std::vector<tensorflow::Tensor>& pred_vector,
1409 TauFunc tau_funcs) {
1410 const tensorflow::Tensor&
inputs = createInputsV1<dnn_inputs_2017v1, const CandidateCastType>(
1411 dynamic_cast<const TauCastType&>(
tau), tau_index, tau_ref,
electrons,
muons, tau_funcs);
1415 template <
typename Cand
idateCastType,
typename TauCastType>
1417 const size_t tau_index,
1419 const std::vector<pat::Electron>*
electrons,
1420 const std::vector<pat::Muon>*
muons,
1424 std::vector<tensorflow::Tensor>& pred_vector,
1425 TauFunc tau_funcs) {
1426 CellGrid inner_grid(dnn_inputs_2017_v2::number_of_inner_cell, dnn_inputs_2017_v2::number_of_inner_cell, 0.02, 0.02);
1427 CellGrid outer_grid(dnn_inputs_2017_v2::number_of_outer_cell, dnn_inputs_2017_v2::number_of_outer_cell, 0.05, 0.05);
1429 fillGrids(dynamic_cast<const TauCastType&>(
tau), *
muons, inner_grid, outer_grid);
1430 fillGrids(dynamic_cast<const TauCastType&>(
tau), pfCands, inner_grid, outer_grid);
1432 createTauBlockInputs<CandidateCastType>(
1433 dynamic_cast<const TauCastType&>(
tau), tau_index, tau_ref,
pv,
rho, tau_funcs);
1434 createConvFeatures<CandidateCastType>(dynamic_cast<const TauCastType&>(
tau),
1445 createConvFeatures<CandidateCastType>(dynamic_cast<const TauCastType&>(
tau),
1461 {
"main_output/Softmax"},
1465 template <
typename Collection,
typename TauCastType>
1466 void fillGrids(
const TauCastType&
tau,
const Collection&
objects, CellGrid& inner_grid, CellGrid& outer_grid) {
1467 static constexpr
double outer_dR2 = 0.25;
1469 const double inner_dR2 =
std::pow(inner_radius, 2);
1471 const auto addObject = [&](
size_t n,
double deta,
double dphi, CellGrid&
grid) {
1474 if (obj_type == CellObjectType::Other)
1476 CellIndex cell_index;
1477 if (
grid.tryGetCellIndex(deta, dphi, cell_index)) {
1479 auto iter = cell.find(obj_type);
1480 if (iter != cell.end()) {
1481 const auto& prev_obj =
objects.at(iter->second);
1482 if (
obj.polarP4().pt() > prev_obj.polarP4().pt())
1490 for (
size_t n = 0;
n <
objects.size(); ++
n) {
1492 const double deta =
obj.polarP4().eta() -
tau.polarP4().eta();
1495 if (dR2 < inner_dR2)
1496 addObject(
n, deta, dphi, inner_grid);
1497 if (dR2 < outer_dR2)
1498 addObject(
n, deta, dphi, outer_grid);
1503 std::vector<tensorflow::Tensor> pred_vector;
1511 {
"inner_all_dropout_4/Identity"},
1520 {
"outer_all_dropout_4/Identity"},
1523 return pred_vector.at(0);
1526 template <
typename Cand
idateCastType,
typename TauCastType>
1528 const size_t tau_index,
1532 const std::vector<pat::Electron>*
electrons,
1533 const std::vector<pat::Muon>*
muons,
1535 const CellGrid&
grid,
1538 tensorflow::Tensor& convTensor = *
convTensor_.at(is_inner);
1539 eGammaTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1540 tensorflow::DT_FLOAT,
1541 tensorflow::TensorShape{
1542 (
long long int)
grid.num_valid_cells(), 1, 1, dnn_inputs_2017_v2::EgammaBlockInputs::NumberOfInputs});
1543 muonTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1544 tensorflow::DT_FLOAT,
1545 tensorflow::TensorShape{
1546 (
long long int)
grid.num_valid_cells(), 1, 1, dnn_inputs_2017_v2::MuonBlockInputs::NumberOfInputs});
1548 tensorflow::DT_FLOAT,
1549 tensorflow::TensorShape{
1550 (
long long int)
grid.num_valid_cells(), 1, 1, dnn_inputs_2017_v2::HadronBlockInputs::NumberOfInputs});
1559 const CellIndex cell_index{
eta,
phi};
1560 const auto cell_iter =
grid.find(cell_index);
1561 if (cell_iter !=
grid.end()) {
1562 const Cell& cell = cell_iter->second;
1563 createEgammaBlockInputs<CandidateCastType>(
1564 idx,
tau, tau_index, tau_ref,
pv,
rho,
electrons, pfCands, cell, tau_funcs, is_inner);
1565 createMuonBlockInputs<CandidateCastType>(
1566 idx,
tau, tau_index, tau_ref,
pv,
rho,
muons, pfCands, cell, tau_funcs, is_inner);
1567 createHadronsBlockInputs<CandidateCastType>(
1568 idx,
tau, tau_index, tau_ref,
pv,
rho, pfCands, cell, tau_funcs, is_inner);
1578 const CellIndex cell_index{
eta,
phi};
1579 const int eta_index =
grid.getEtaTensorIndex(cell_index);
1580 const int phi_index =
grid.getPhiTensorIndex(cell_index);
1582 const auto cell_iter =
grid.find(cell_index);
1583 if (cell_iter !=
grid.end()) {
1594 const tensorflow::Tensor&
features,
1598 for (
int n = 0;
n < dnn_inputs_2017_v2::number_of_conv_features; ++
n)
1599 convTensor.tensor<
float, 4>()(0, eta_index, phi_index,
n) =
features.tensor<
float, 4>()(batch_idx, 0, 0,
n);
1602 template <
typename Cand
idateCastType,
typename TauCastType>
1604 const size_t& tau_index,
1608 TauFunc tau_funcs) {
1612 inputs.flat<
float>().setZero();
1614 const auto&
get = [&](
int var_index) ->
float& {
return inputs.matrix<
float>()(0, var_index); };
1616 auto leadChargedHadrCand = dynamic_cast<const CandidateCastType*>(
tau.leadChargedHadrCand().get());
1627 get(dnn::chargedIsoPtSum) =
getValueNorm(tau_funcs.getChargedIsoPtSum(
tau, tau_ref), 47.78f, 123.5f);
1628 get(dnn::chargedIsoPtSumdR03_over_dR05) =
1629 getValue(tau_funcs.getChargedIsoPtSumdR03(
tau, tau_ref) / tau_funcs.getChargedIsoPtSum(
tau, tau_ref));
1630 get(dnn::footprintCorrection) =
getValueNorm(tau_funcs.getFootprintCorrectiondR03(
tau, tau_ref), 9.029f, 26.42f);
1631 get(dnn::neutralIsoPtSum) =
getValueNorm(tau_funcs.getNeutralIsoPtSum(
tau, tau_ref), 57.59f, 155.3f);
1632 get(dnn::neutralIsoPtSumWeight_over_neutralIsoPtSum) =
1633 getValue(tau_funcs.getNeutralIsoPtSumWeight(
tau, tau_ref) / tau_funcs.getNeutralIsoPtSum(
tau, tau_ref));
1634 get(dnn::neutralIsoPtSumWeightdR03_over_neutralIsoPtSum) =
1635 getValue(tau_funcs.getNeutralIsoPtSumdR03Weight(
tau, tau_ref) / tau_funcs.getNeutralIsoPtSum(
tau, tau_ref));
1636 get(dnn::neutralIsoPtSumdR03_over_dR05) =
1637 getValue(tau_funcs.getNeutralIsoPtSumdR03(
tau, tau_ref) / tau_funcs.getNeutralIsoPtSum(
tau, tau_ref));
1638 get(dnn::photonPtSumOutsideSignalCone) =
1639 getValueNorm(tau_funcs.getPhotonPtSumOutsideSignalCone(
tau, tau_ref), 1.731f, 6.846f);
1640 get(dnn::puCorrPtSum) =
getValueNorm(tau_funcs.getPuCorrPtSum(
tau, tau_ref), 22.38f, 16.34f);
1646 auto const pca = tau_funcs.getdxyPCA(
tau, tau_index);
1651 get(dnn::tau_dxy_pca_x) = 0;
1652 get(dnn::tau_dxy_pca_y) = 0;
1653 get(dnn::tau_dxy_pca_z) = 0;
1655 const bool tau_dxy_valid =
1656 isAbove(tau_funcs.getdxy(
tau, tau_index), -10) &&
isAbove(tau_funcs.getdxyError(
tau, tau_index), 0);
1657 if (tau_dxy_valid) {
1658 get(dnn::tau_dxy_valid) = tau_dxy_valid;
1659 get(dnn::tau_dxy) =
getValueNorm(tau_funcs.getdxy(
tau, tau_index), 0.0018f, 0.0085f);
1661 std::abs(tau_funcs.getdxy(
tau, tau_index)) / tau_funcs.getdxyError(
tau, tau_index), 2.26f, 4.191f);
1663 const bool tau_ip3d_valid =
1664 isAbove(tau_funcs.getip3d(
tau, tau_index), -10) &&
isAbove(tau_funcs.getip3dError(
tau, tau_index), 0);
1665 if (tau_ip3d_valid) {
1666 get(dnn::tau_ip3d_valid) = tau_ip3d_valid;
1667 get(dnn::tau_ip3d) =
getValueNorm(tau_funcs.getip3d(
tau, tau_index), 0.0026f, 0.0114f);
1669 std::abs(tau_funcs.getip3d(
tau, tau_index)) / tau_funcs.getip3dError(
tau, tau_index), 2.928f, 4.466f);
1671 if (leadChargedHadrCand) {
1673 get(dnn::tau_dz_sig_valid) = candFunc::getTauDZSigValid(*leadChargedHadrCand);
1674 const double dzError = candFunc::getTauDzError(*leadChargedHadrCand,
default_value);
1675 get(dnn::tau_dz_sig) =
1678 get(dnn::tau_flightLength_x) =
getValueNorm(tau_funcs.getFlightLength(
tau, tau_index).x(), -0.0003f, 0.7362f);
1679 get(dnn::tau_flightLength_y) =
getValueNorm(tau_funcs.getFlightLength(
tau, tau_index).y(), -0.0009f, 0.7354f);
1680 get(dnn::tau_flightLength_z) =
getValueNorm(tau_funcs.getFlightLength(
tau, tau_index).z(), -0.0022f, 1.993f);
1681 get(dnn::tau_flightLength_sig) = 0.55756444;
1682 get(dnn::tau_pt_weighted_deta_strip) =
1685 get(dnn::tau_pt_weighted_dphi_strip) =
1687 get(dnn::tau_pt_weighted_dr_signal) =
1690 get(dnn::tau_leadingTrackNormChi2) =
getValueNorm(tau_funcs.getLeadingTrackNormChi2(
tau), 1.538f, 4.401f);
1692 const bool tau_e_ratio_valid = std::isnormal(
eratio) &&
eratio > 0.f;
1693 get(dnn::tau_e_ratio_valid) = tau_e_ratio_valid;
1696 const bool tau_gj_angle_diff_valid = (std::isnormal(gj_angle_diff) || gj_angle_diff == 0) && gj_angle_diff >= 0;
1697 get(dnn::tau_gj_angle_diff_valid) = tau_gj_angle_diff_valid;
1698 get(dnn::tau_gj_angle_diff) = tau_gj_angle_diff_valid ?
getValueLinear(gj_angle_diff, 0,
pi,
true) : 0;
1703 get(dnn::leadChargedCand_etaAtEcalEntrance_minus_tau_eta) =
1704 getValueNorm(tau_funcs.getEtaAtEcalEntrance(
tau) -
tau.p4().eta(), 0.0042f, 0.0323f);
1708 template <
typename Cand
idateCastType,
typename TauCastType>
1710 const TauCastType&
tau,
1711 const size_t tau_index,
1715 const std::vector<pat::Electron>*
electrons,
1717 const Cell& cell_map,
1724 const auto&
get = [&](
int var_index) ->
float& {
return inputs.tensor<
float, 4>()(
idx, 0, 0, var_index); };
1726 const bool valid_index_pf_ele = cell_map.count(CellObjectType::PfCand_electron);
1727 const bool valid_index_pf_gamma = cell_map.count(CellObjectType::PfCand_gamma);
1730 if (!cell_map.empty()) {
1736 if (valid_index_pf_ele) {
1737 size_t index_pf_ele = cell_map.at(CellObjectType::PfCand_electron);
1738 const auto& ele_cand = dynamic_cast<const CandidateCastType&>(pfCands.
at(index_pf_ele));
1740 get(dnn::pfCand_ele_valid) = valid_index_pf_ele;
1741 get(dnn::pfCand_ele_rel_pt) =
getValueNorm(pfCands.
at(index_pf_ele).polarP4().pt() /
tau.polarP4().pt(),
1742 is_inner ? 0.9792f : 0.304f,
1743 is_inner ? 0.5383f : 1.845f);
1744 get(dnn::pfCand_ele_deta) =
getValueLinear(pfCands.
at(index_pf_ele).polarP4().eta() -
tau.polarP4().eta(),
1745 is_inner ? -0.1f : -0.5f,
1746 is_inner ? 0.1f : 0.5f,
1749 is_inner ? -0.1
f : -0.5
f,
1750 is_inner ? 0.1
f : 0.5
f,
1752 get(dnn::pfCand_ele_pvAssociationQuality) =
1753 getValueLinear<int>(candFunc::getPvAssocationQuality(ele_cand), 0, 7,
true);
1754 get(dnn::pfCand_ele_puppiWeight) =
getValue(candFunc::getPuppiWeight(ele_cand));
1755 get(dnn::pfCand_ele_charge) =
getValue(ele_cand.charge());
1756 get(dnn::pfCand_ele_lostInnerHits) = getValue<int>(candFunc::getLostInnerHits(ele_cand,
default_value));
1757 get(dnn::pfCand_ele_numberOfPixelHits) =
1759 get(dnn::pfCand_ele_vertex_dx) =
1760 getValueNorm(pfCands.
at(index_pf_ele).vertex().x() -
pv.position().x(), 0.f, 0.1221f);
1761 get(dnn::pfCand_ele_vertex_dy) =
1762 getValueNorm(pfCands.
at(index_pf_ele).vertex().y() -
pv.position().y(), 0.f, 0.1226f);
1763 get(dnn::pfCand_ele_vertex_dz) =
1764 getValueNorm(pfCands.
at(index_pf_ele).vertex().z() -
pv.position().z(), 0.001f, 1.024f);
1766 pfCands.
at(index_pf_ele).vertex().x() -
pv.position().x() - tau_funcs.getFlightLength(
tau, tau_index).x(),
1770 pfCands.
at(index_pf_ele).vertex().y() -
pv.position().y() - tau_funcs.getFlightLength(
tau, tau_index).y(),
1774 pfCands.
at(index_pf_ele).vertex().z() -
pv.position().z() - tau_funcs.getFlightLength(
tau, tau_index).z(),
1778 const bool hasTrackDetails = candFunc::getHasTrackDetails(ele_cand);
1779 if (hasTrackDetails) {
1780 get(dnn::pfCand_ele_hasTrackDetails) = hasTrackDetails;
1782 get(dnn::pfCand_ele_dxy_sig) =
1792 candFunc::getPseudoTrack(ele_cand).
chi2() / candFunc::getPseudoTrack(ele_cand).
ndof(), 2.272
f, 8.439
f);
1793 get(dnn::pfCand_ele_track_ndof) =
getValueNorm(candFunc::getPseudoTrack(ele_cand).
ndof(), 15.18
f, 3.203
f);
1796 if (valid_index_pf_gamma) {
1797 size_t index_pf_gamma = cell_map.at(CellObjectType::PfCand_gamma);
1798 const auto& gamma_cand = dynamic_cast<const CandidateCastType&>(pfCands.
at(index_pf_gamma));
1800 get(dnn::pfCand_gamma_valid) = valid_index_pf_gamma;
1801 get(dnn::pfCand_gamma_rel_pt) =
getValueNorm(pfCands.
at(index_pf_gamma).polarP4().pt() /
tau.polarP4().pt(),
1802 is_inner ? 0.6048f : 0.02576f,
1803 is_inner ? 1.669f : 0.3833f);
1804 get(dnn::pfCand_gamma_deta) =
getValueLinear(pfCands.
at(index_pf_gamma).polarP4().eta() -
tau.polarP4().eta(),
1805 is_inner ? -0.1f : -0.5f,
1806 is_inner ? 0.1f : 0.5f,
1809 is_inner ? -0.1
f : -0.5
f,
1810 is_inner ? 0.1
f : 0.5
f,
1812 get(dnn::pfCand_gamma_pvAssociationQuality) =
1813 getValueLinear<int>(candFunc::getPvAssocationQuality(gamma_cand), 0, 7,
true);
1814 get(dnn::pfCand_gamma_fromPV) = getValueLinear<int>(candFunc::getFromPV(gamma_cand), 0, 3,
true);
1815 get(dnn::pfCand_gamma_puppiWeight) =
getValue(candFunc::getPuppiWeight(gamma_cand));
1816 get(dnn::pfCand_gamma_puppiWeightNoLep) =
getValue(candFunc::getPuppiWeightNoLep(gamma_cand));
1817 get(dnn::pfCand_gamma_lostInnerHits) = getValue<int>(candFunc::getLostInnerHits(gamma_cand,
default_value));
1818 get(dnn::pfCand_gamma_numberOfPixelHits) =
1820 get(dnn::pfCand_gamma_vertex_dx) =
1821 getValueNorm(pfCands.
at(index_pf_gamma).vertex().x() -
pv.position().x(), 0.f, 0.0067f);
1822 get(dnn::pfCand_gamma_vertex_dy) =
1823 getValueNorm(pfCands.
at(index_pf_gamma).vertex().y() -
pv.position().y(), 0.f, 0.0069f);
1824 get(dnn::pfCand_gamma_vertex_dz) =
1825 getValueNorm(pfCands.
at(index_pf_gamma).vertex().z() -
pv.position().z(), 0.f, 0.0578f);
1827 pfCands.
at(index_pf_gamma).vertex().x() -
pv.position().x() - tau_funcs.getFlightLength(
tau, tau_index).x(),
1831 pfCands.
at(index_pf_gamma).vertex().y() -
pv.position().y() - tau_funcs.getFlightLength(
tau, tau_index).y(),
1835 pfCands.
at(index_pf_gamma).vertex().z() -
pv.position().z() - tau_funcs.getFlightLength(
tau, tau_index).z(),
1838 const bool hasTrackDetails = candFunc::getHasTrackDetails(gamma_cand);
1839 if (hasTrackDetails) {
1840 get(dnn::pfCand_gamma_hasTrackDetails) = hasTrackDetails;
1849 get(dnn::pfCand_gamma_track_chi2_ndof) = candFunc::getPseudoTrack(gamma_cand).ndof() > 0
1851 candFunc::getPseudoTrack(gamma_cand).
ndof(),
1855 get(dnn::pfCand_gamma_track_ndof) =
1856 candFunc::getPseudoTrack(gamma_cand).ndof() > 0
1861 if (valid_index_ele) {
1864 get(dnn::ele_valid) = valid_index_ele;
1866 is_inner ? 1.067f : 0.5111f,
1867 is_inner ? 1.521f : 2.765f);
1869 is_inner ? -0.1f : -0.5f,
1870 is_inner ? 0.1f : 0.5f,
1873 is_inner ? -0.1
f : -0.5
f,
1874 is_inner ? 0.1
f : 0.5
f,
1877 float cc_ele_energy, cc_gamma_energy;
1879 const bool cc_valid =
1882 get(dnn::ele_cc_valid) = cc_valid;
1883 get(dnn::ele_cc_ele_rel_energy) =
1885 get(dnn::ele_cc_gamma_rel_energy) =
getValueNorm(cc_gamma_energy / cc_ele_energy, 0.1439
f, 0.3284
f);
1889 electrons->at(index_ele).trackMomentumAtVtx().R() /
electrons->at(index_ele).polarP4().pt(), 1.531f, 1.424f);
1891 electrons->at(index_ele).trackMomentumAtCalo().R() /
electrons->at(index_ele).polarP4().pt(), 1.531f, 1.424f);
1893 electrons->at(index_ele).trackMomentumOut().R() /
electrons->at(index_ele).polarP4().pt(), 0.7735f, 0.935f);
1894 get(dnn::ele_rel_trackMomentumAtEleClus) =
1899 electrons->at(index_ele).trackMomentumAtVtxWithConstraint().R() /
electrons->at(index_ele).polarP4().pt(),
1902 get(dnn::ele_rel_ecalEnergy) =
1905 electrons->at(index_ele).ecalEnergy() /
electrons->at(index_ele).ecalEnergyError(), 70.25f, 58.16f);
1910 get(dnn::ele_deltaEtaSuperClusterTrackAtVtx) =
1912 get(dnn::ele_deltaEtaSeedClusterTrackAtCalo) =
1914 get(dnn::ele_deltaEtaEleClusterTrackAtCalo) =
1916 get(dnn::ele_deltaPhiEleClusterTrackAtCalo) =
1918 get(dnn::ele_deltaPhiSuperClusterTrackAtVtx) =
1920 get(dnn::ele_deltaPhiSeedClusterTrackAtCalo) =
1924 get(dnn::ele_mvaInput_sigmaEtaEta) =
1928 const auto& gsfTrack =
electrons->at(index_ele).gsfTrack();
1929 if (gsfTrack.isNonnull()) {
1930 get(dnn::ele_gsfTrack_normalizedChi2) =
getValueNorm(gsfTrack->normalizedChi2(), 3.049f, 10.39f);
1931 get(dnn::ele_gsfTrack_numberOfValidHits) =
getValueNorm(gsfTrack->numberOfValidHits(), 16.52f, 2.806f);
1932 get(dnn::ele_rel_gsfTrack_pt) =
1934 get(dnn::ele_gsfTrack_pt_sig) =
getValueNorm(gsfTrack->pt() / gsfTrack->ptError(), 5.046f, 3.119f);
1936 const auto& closestCtfTrack =
electrons->at(index_ele).closestCtfTrackRef();
1937 const bool has_closestCtfTrack = closestCtfTrack.isNonnull();
1938 if (has_closestCtfTrack) {
1939 get(dnn::ele_has_closestCtfTrack) = has_closestCtfTrack;
1940 get(dnn::ele_closestCtfTrack_normalizedChi2) =
getValueNorm(closestCtfTrack->normalizedChi2(), 2.411f, 6.98f);
1941 get(dnn::ele_closestCtfTrack_numberOfValidHits) =
1942 getValueNorm(closestCtfTrack->numberOfValidHits(), 15.16f, 5.26f);
1945 if (valid_index_ele
or valid_index_pf_ele
or valid_index_pf_gamma)
1946 checkInputs(
inputs, is_inner ?
"egamma_inner_block" :
"egamma_outer_block", dnn::NumberOfInputs);
1949 template <
typename Cand
idateCastType,
typename TauCastType>
1951 const TauCastType&
tau,
1952 const size_t tau_index,
1956 const std::vector<pat::Muon>*
muons,
1958 const Cell& cell_map,
1965 const auto&
get = [&](
int var_index) ->
float& {
return inputs.tensor<
float, 4>()(
idx, 0, 0, var_index); };
1967 const bool valid_index_pf_muon = cell_map.count(CellObjectType::PfCand_muon);
1970 if (!cell_map.empty()) {
1976 if (valid_index_pf_muon) {
1977 size_t index_pf_muon = cell_map.at(CellObjectType::PfCand_muon);
1978 const auto& muon_cand = dynamic_cast<const CandidateCastType&>(pfCands.
at(index_pf_muon));
1980 get(dnn::pfCand_muon_valid) = valid_index_pf_muon;
1981 get(dnn::pfCand_muon_rel_pt) =
getValueNorm(pfCands.
at(index_pf_muon).polarP4().pt() /
tau.polarP4().pt(),
1982 is_inner ? 0.9509f : 0.0861f,
1983 is_inner ? 0.4294f : 0.4065f);
1984 get(dnn::pfCand_muon_deta) =
getValueLinear(pfCands.
at(index_pf_muon).polarP4().eta() -
tau.polarP4().eta(),
1985 is_inner ? -0.1f : -0.5f,
1986 is_inner ? 0.1f : 0.5f,
1989 is_inner ? -0.1
f : -0.5
f,
1990 is_inner ? 0.1
f : 0.5
f,
1992 get(dnn::pfCand_muon_pvAssociationQuality) =
1993 getValueLinear<int>(candFunc::getPvAssocationQuality(muon_cand), 0, 7,
true);
1994 get(dnn::pfCand_muon_fromPV) = getValueLinear<int>(candFunc::getFromPV(muon_cand), 0, 3,
true);
1995 get(dnn::pfCand_muon_puppiWeight) =
getValue(candFunc::getPuppiWeight(muon_cand));
1996 get(dnn::pfCand_muon_charge) =
getValue(muon_cand.charge());
1997 get(dnn::pfCand_muon_lostInnerHits) = getValue<int>(candFunc::getLostInnerHits(muon_cand,
default_value));
1998 get(dnn::pfCand_muon_numberOfPixelHits) =
2000 get(dnn::pfCand_muon_vertex_dx) =
2001 getValueNorm(pfCands.
at(index_pf_muon).vertex().x() -
pv.position().x(), -0.0007f, 0.6869f);
2002 get(dnn::pfCand_muon_vertex_dy) =
2003 getValueNorm(pfCands.
at(index_pf_muon).vertex().y() -
pv.position().y(), 0.0001f, 0.6784f);
2004 get(dnn::pfCand_muon_vertex_dz) =
2005 getValueNorm(pfCands.
at(index_pf_muon).vertex().z() -
pv.position().z(), -0.0117f, 4.097f);
2007 pfCands.
at(index_pf_muon).vertex().x() -
pv.position().x() - tau_funcs.getFlightLength(
tau, tau_index).x(),
2011 pfCands.
at(index_pf_muon).vertex().y() -
pv.position().y() - tau_funcs.getFlightLength(
tau, tau_index).y(),
2015 pfCands.
at(index_pf_muon).vertex().z() -
pv.position().z() - tau_funcs.getFlightLength(
tau, tau_index).z(),
2019 const bool hasTrackDetails = candFunc::getHasTrackDetails(muon_cand);
2020 if (hasTrackDetails) {
2021 get(dnn::pfCand_muon_hasTrackDetails) = hasTrackDetails;
2031 candFunc::getPseudoTrack(muon_cand).
chi2() / candFunc::getPseudoTrack(muon_cand).
ndof(), 0.69
f, 1.711
f);
2032 get(dnn::pfCand_muon_track_ndof) =
getValueNorm(candFunc::getPseudoTrack(muon_cand).
ndof(), 17.5
f, 5.11
f);
2035 if (valid_index_muon) {
2038 get(dnn::muon_valid) = valid_index_muon;
2040 is_inner ? 0.7966f : 0.2678f,
2041 is_inner ? 3.402f : 3.592f);
2043 is_inner ? -0.1f : -0.5f,
2044 is_inner ? 0.1f : 0.5f,
2047 is_inner ? -0.1
f : -0.5
f,
2048 is_inner ? 0.1
f : 0.5
f,
2051 get(dnn::muon_dxy_sig) =
2056 const bool normalizedChi2_valid =
2057 muons->at(index_muon).globalTrack().isNonnull() &&
muons->at(index_muon).normChi2() >= 0;
2058 if (normalizedChi2_valid) {
2059 get(dnn::muon_normalizedChi2_valid) = normalizedChi2_valid;
2060 get(dnn::muon_normalizedChi2) =
getValueNorm(
muons->at(index_muon).normChi2(), 21.52f, 265.8f);
2061 if (
muons->at(index_muon).innerTrack().isNonnull())
2062 get(dnn::muon_numberOfValidHits) =
getValueNorm(
muons->at(index_muon).numberOfValidHits(), 21.84f, 10.59f);
2064 get(dnn::muon_segmentCompatibility) =
getValue(
muons->at(index_muon).segmentCompatibility());
2065 get(dnn::muon_caloCompatibility) =
getValue(
muons->at(index_muon).caloCompatibility());
2067 const bool pfEcalEnergy_valid =
muons->at(index_muon).pfEcalEnergy() >= 0;
2068 if (pfEcalEnergy_valid) {
2069 get(dnn::muon_pfEcalEnergy_valid) = pfEcalEnergy_valid;
2070 get(dnn::muon_rel_pfEcalEnergy) =
2071 getValueNorm(
muons->at(index_muon).pfEcalEnergy() /
muons->at(index_muon).polarP4().pt(), 0.2273f, 0.4865f);
2074 MuonHitMatchV2 hit_match(
muons->at(index_muon));
2075 static const std::map<int, std::pair<int, int>> muonMatchHitVars = {
2080 static const std::map<int, std::vector<float>> muonMatchVarLimits = {
2081 {
MuonSubdetId::DT, {2, 2, 2, 2}}, {
MuonSubdetId::CSC, {6, 2, 2, 2}}, {
MuonSubdetId::RPC, {7, 6, 4, 4}}};
2083 static const std::map<int, std::vector<float>> muonHitVarLimits = {{
MuonSubdetId::DT, {12, 12, 12, 8}},
2087 for (
int subdet : hit_match.MuonHitMatchV2::consideredSubdets()) {
2088 const auto& matchHitVar = muonMatchHitVars.at(subdet);
2089 const auto& matchLimits = muonMatchVarLimits.at(subdet);
2090 const auto& hitLimits = muonHitVarLimits.at(subdet);
2091 for (
int station = MuonHitMatchV2::first_station_id;
station <= MuonHitMatchV2::last_station_id; ++
station) {
2092 const unsigned n_matches = hit_match.nMatches(subdet,
station);
2093 const unsigned n_hits = hit_match.nHits(subdet,
station);
2099 checkInputs(
inputs, is_inner ?
"muon_inner_block" :
"muon_outer_block", dnn::NumberOfInputs);
2102 template <
typename Cand
idateCastType,
typename TauCastType>
2104 const TauCastType&
tau,
2105 const size_t tau_index,
2110 const Cell& cell_map,
2117 const auto&
get = [&](
int var_index) ->
float& {
return inputs.tensor<
float, 4>()(
idx, 0, 0, var_index); };
2119 const bool valid_chH = cell_map.count(CellObjectType::PfCand_chargedHadron);
2120 const bool valid_nH = cell_map.count(CellObjectType::PfCand_neutralHadron);
2122 if (!cell_map.empty()) {
2129 size_t index_chH = cell_map.at(CellObjectType::PfCand_chargedHadron);
2130 const auto& chH_cand = dynamic_cast<const CandidateCastType&>(pfCands.
at(index_chH));
2132 get(dnn::pfCand_chHad_valid) = valid_chH;
2133 get(dnn::pfCand_chHad_rel_pt) =
getValueNorm(pfCands.
at(index_chH).polarP4().pt() /
tau.polarP4().pt(),
2134 is_inner ? 0.2564f : 0.0194f,
2135 is_inner ? 0.8607f : 0.1865f);
2136 get(dnn::pfCand_chHad_deta) =
getValueLinear(pfCands.
at(index_chH).polarP4().eta() -
tau.polarP4().eta(),
2137 is_inner ? -0.1f : -0.5f,
2138 is_inner ? 0.1f : 0.5f,
2141 is_inner ? -0.1
f : -0.5
f,
2142 is_inner ? 0.1
f : 0.5
f,
2144 get(dnn::pfCand_chHad_leadChargedHadrCand) =
2145 getValue(&chH_cand == dynamic_cast<const CandidateCastType*>(
tau.leadChargedHadrCand().get()));
2146 get(dnn::pfCand_chHad_pvAssociationQuality) =
2147 getValueLinear<int>(candFunc::getPvAssocationQuality(chH_cand), 0, 7,
true);
2148 get(dnn::pfCand_chHad_fromPV) = getValueLinear<int>(candFunc::getFromPV(chH_cand), 0, 3,
true);
2149 get(dnn::pfCand_chHad_puppiWeight) =
getValue(candFunc::getPuppiWeight(chH_cand));
2150 get(dnn::pfCand_chHad_puppiWeightNoLep) =
getValue(candFunc::getPuppiWeightNoLep(chH_cand));
2151 get(dnn::pfCand_chHad_charge) =
getValue(chH_cand.charge());
2152 get(dnn::pfCand_chHad_lostInnerHits) = getValue<int>(candFunc::getLostInnerHits(chH_cand,
default_value));
2153 get(dnn::pfCand_chHad_numberOfPixelHits) =
2155 get(dnn::pfCand_chHad_vertex_dx) =
2156 getValueNorm(pfCands.
at(index_chH).vertex().x() -
pv.position().x(), 0.0005f, 1.735f);
2157 get(dnn::pfCand_chHad_vertex_dy) =
2158 getValueNorm(pfCands.
at(index_chH).vertex().y() -
pv.position().y(), -0.0008f, 1.752f);
2159 get(dnn::pfCand_chHad_vertex_dz) =
2160 getValueNorm(pfCands.
at(index_chH).vertex().z() -
pv.position().z(), -0.0201f, 8.333f);
2162 pfCands.
at(index_chH).vertex().x() -
pv.position().x() - tau_funcs.getFlightLength(
tau, tau_index).x(),
2166 pfCands.
at(index_chH).vertex().y() -
pv.position().y() - tau_funcs.getFlightLength(
tau, tau_index).y(),
2170 pfCands.
at(index_chH).vertex().z() -
pv.position().z() - tau_funcs.getFlightLength(
tau, tau_index).z(),
2174 const bool hasTrackDetails = candFunc::getHasTrackDetails(chH_cand);
2175 if (hasTrackDetails) {
2176 get(dnn::pfCand_chHad_hasTrackDetails) = hasTrackDetails;
2178 get(dnn::pfCand_chHad_dxy_sig) =
2185 get(dnn::pfCand_chHad_track_chi2_ndof) =
2186 candFunc::getPseudoTrack(chH_cand).ndof() > 0
2187 ?
getValueNorm(candFunc::getPseudoTrack(chH_cand).
chi2() / candFunc::getPseudoTrack(chH_cand).
ndof(),
2191 get(dnn::pfCand_chHad_track_ndof) =
2192 candFunc::getPseudoTrack(chH_cand).ndof() > 0
2196 float hcal_fraction = candFunc::getHCalFraction(chH_cand);
2197 get(dnn::pfCand_chHad_hcalFraction) =
getValue(hcal_fraction);
2198 get(dnn::pfCand_chHad_rawCaloFraction) =
getValueLinear(candFunc::getRawCaloFraction(chH_cand), 0.
f, 2.6
f,
true);
2201 size_t index_nH = cell_map.at(CellObjectType::PfCand_neutralHadron);
2202 const auto& nH_cand = dynamic_cast<const CandidateCastType&>(pfCands.
at(index_nH));
2204 get(dnn::pfCand_nHad_valid) = valid_nH;
2205 get(dnn::pfCand_nHad_rel_pt) =
getValueNorm(pfCands.
at(index_nH).polarP4().pt() /
tau.polarP4().pt(),
2206 is_inner ? 0.3163f : 0.0502f,
2207 is_inner ? 0.2769f : 0.4266f);
2209 is_inner ? -0.1f : -0.5f,
2210 is_inner ? 0.1f : 0.5f,
2213 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);
2214 get(dnn::pfCand_nHad_puppiWeight) =
getValue(candFunc::getPuppiWeight(nH_cand));
2215 get(dnn::pfCand_nHad_puppiWeightNoLep) =
getValue(candFunc::getPuppiWeightNoLep(nH_cand));
2216 float hcal_fraction = candFunc::getHCalFraction(nH_cand);
2217 get(dnn::pfCand_nHad_hcalFraction) =
getValue(hcal_fraction);
2219 checkInputs(
inputs, is_inner ?
"hadron_inner_block" :
"hadron_outer_block", dnn::NumberOfInputs);
2222 template <
typename dnn,
typename Cand
idateCastType,
typename TauCastType>
2224 const size_t tau_index,
2226 const std::vector<pat::Electron>*
electrons,
2227 const std::vector<pat::Muon>*
muons,
2228 TauFunc tau_funcs)
const {
2229 static constexpr
bool check_all_set =
false;
2230 static constexpr
float default_value_for_set_check = -42;
2232 tensorflow::Tensor
inputs(tensorflow::DT_FLOAT, {1, dnn_inputs_2017v1::NumberOfInputs});
2233 const auto&
get = [&](
int var_index) ->
float& {
return inputs.matrix<
float>()(0, var_index); };
2234 auto leadChargedHadrCand = dynamic_cast<const CandidateCastType*>(
tau.leadChargedHadrCand().get());
2236 if (check_all_set) {
2237 for (
int var_index = 0; var_index < dnn::NumberOfInputs; ++var_index) {
2238 get(var_index) = default_value_for_set_check;
2246 get(dnn::chargedIsoPtSum) = tau_funcs.getChargedIsoPtSum(
tau, tau_ref);
2247 get(dnn::neutralIsoPtSum) = tau_funcs.getNeutralIsoPtSum(
tau, tau_ref);
2248 get(dnn::neutralIsoPtSumWeight) = tau_funcs.getNeutralIsoPtSumWeight(
tau, tau_ref);
2249 get(dnn::photonPtSumOutsideSignalCone) = tau_funcs.getPhotonPtSumOutsideSignalCone(
tau, tau_ref);
2250 get(dnn::puCorrPtSum) = tau_funcs.getPuCorrPtSum(
tau, tau_ref);
2252 get(dnn::dxy_sig) = tau_funcs.getdxySig(
tau, tau_index);
2255 get(dnn::ip3d_sig) = tau_funcs.getip3dSig(
tau, tau_index);
2256 get(dnn::hasSecondaryVertex) = tau_funcs.getHasSecondaryVertex(
tau, tau_index);
2257 get(dnn::flightLength_r) = tau_funcs.getFlightLength(
tau, tau_index).R();
2258 get(dnn::flightLength_dEta) =
dEta(tau_funcs.getFlightLength(
tau, tau_index),
tau.p4());
2259 get(dnn::flightLength_dPhi) =
dPhi(tau_funcs.getFlightLength(
tau, tau_index),
tau.p4());
2260 get(dnn::flightLength_sig) = tau_funcs.getFlightLengthSig(
tau, tau_index);
2261 get(dnn::leadChargedHadrCand_pt) = leadChargedHadrCand ? leadChargedHadrCand->p4().Pt() :
default_value;
2262 get(dnn::leadChargedHadrCand_dEta) =
2264 get(dnn::leadChargedHadrCand_dPhi) =
2266 get(dnn::leadChargedHadrCand_mass) = leadChargedHadrCand ? leadChargedHadrCand->p4().mass() :
default_value;
2271 get(dnn::leadingTrackNormChi2) = tau_funcs.getLeadingTrackNormChi2(
tau);
2275 get(dnn::emFraction) = tau_funcs.getEmFraction(
tau);
2276 get(dnn::has_gsf_track) = leadChargedHadrCand &&
std::abs(leadChargedHadrCand->pdgId()) == 11;
2279 get(dnn::gsf_ele_matched) = gsf_ele !=
nullptr;
2280 get(dnn::gsf_ele_pt) = gsf_ele !=
nullptr ? gsf_ele->p4().Pt() :
default_value;
2283 get(dnn::gsf_ele_mass) = gsf_ele !=
nullptr ? gsf_ele->p4().mass() :
default_value;
2285 get(dnn::gsf_ele_Pin) = gsf_ele !=
nullptr ? gsf_ele->trackMomentumAtVtx().R() :
default_value;
2286 get(dnn::gsf_ele_Pout) = gsf_ele !=
nullptr ? gsf_ele->trackMomentumOut().R() :
default_value;
2287 get(dnn::gsf_ele_EtotOverPin) =
get(dnn::gsf_ele_Pin) > 0
2288 ? (
get(dnn::gsf_ele_Ee) +
get(dnn::gsf_ele_Egamma)) /
get(dnn::gsf_ele_Pin)
2290 get(dnn::gsf_ele_Eecal) = gsf_ele !=
nullptr ? gsf_ele->ecalEnergy() :
default_value;
2291 get(dnn::gsf_ele_dEta_SeedClusterTrackAtCalo) =
2292 gsf_ele !=
nullptr ? gsf_ele->deltaEtaSeedClusterTrackAtCalo() :
default_value;
2293 get(dnn::gsf_ele_dPhi_SeedClusterTrackAtCalo) =
2294 gsf_ele !=
nullptr ? gsf_ele->deltaPhiSeedClusterTrackAtCalo() :
default_value;
2295 get(dnn::gsf_ele_mvaIn_sigmaEtaEta) = gsf_ele !=
nullptr ? gsf_ele->mvaInput().sigmaEtaEta :
default_value;
2296 get(dnn::gsf_ele_mvaIn_hadEnergy) = gsf_ele !=
nullptr ? gsf_ele->mvaInput().hadEnergy :
default_value;
2297 get(dnn::gsf_ele_mvaIn_deltaEta) = gsf_ele !=
nullptr ? gsf_ele->mvaInput().deltaEta :
default_value;
2303 if (gsf_ele !=
nullptr && gsf_ele->gsfTrack().isNonnull()) {
2304 get(dnn::gsf_ele_Chi2NormGSF) = gsf_ele->gsfTrack()->normalizedChi2();
2305 get(dnn::gsf_ele_GSFNumHits) = gsf_ele->gsfTrack()->numberOfValidHits();
2306 if (gsf_ele->gsfTrack()->pt() > 0) {
2307 get(dnn::gsf_ele_GSFTrackResol) = gsf_ele->gsfTrack()->ptError() / gsf_ele->gsfTrack()->pt();
2308 get(dnn::gsf_ele_GSFTracklnPt) = std::log10(gsf_ele->gsfTrack()->pt());
2314 if (gsf_ele !=
nullptr && gsf_ele->closestCtfTrackRef().isNonnull()) {
2315 get(dnn::gsf_ele_Chi2NormKF) = gsf_ele->closestCtfTrackRef()->normalizedChi2();
2316 get(dnn::gsf_ele_KFNumHits) = gsf_ele->closestCtfTrackRef()->numberOfValidHits();
2318 get(dnn::leadChargedCand_etaAtEcalEntrance) = tau_funcs.getEtaAtEcalEntrance(
tau);
2319 get(dnn::leadChargedCand_pt) = leadChargedHadrCand->pt();
2323 if (leadChargedHadrCand->pt() > 0) {
2324 get(dnn::leadChargedHadrCand_HoP) = tau_funcs.getEcalEnergyLeadingChargedHadr(
tau) / leadChargedHadrCand->pt();
2325 get(dnn::leadChargedHadrCand_EoP) = tau_funcs.getHcalEnergyLeadingChargedHadr(
tau) / leadChargedHadrCand->pt();
2328 MuonHitMatchV1 muon_hit_match;
2329 if (
tau.leadPFChargedHadrCand().isNonnull() &&
tau.leadPFChargedHadrCand()->muonRef().isNonnull())
2330 muon_hit_match.addMatchedMuon(*
tau.leadPFChargedHadrCand()->muonRef(),
tau);
2332 auto matched_muons = muon_hit_match.findMatchedMuons(
tau,
muons, 0.3, 5);
2333 for (
auto muon : matched_muons)
2334 muon_hit_match.addMatchedMuon(*
muon,
tau);
2337 LorentzVectorXYZ signalChargedHadrCands_sumIn, signalChargedHadrCands_sumOut;
2339 tau.signalChargedHadrCands(),
2340 signalChargedHadrCands_sumIn,
2341 signalChargedHadrCands_sumOut,
2342 get(dnn::signalChargedHadrCands_sum_innerSigCone_pt),
2343 get(dnn::signalChargedHadrCands_sum_innerSigCone_dEta),
2344 get(dnn::signalChargedHadrCands_sum_innerSigCone_dPhi),
2345 get(dnn::signalChargedHadrCands_sum_innerSigCone_mass),
2346 get(dnn::signalChargedHadrCands_sum_outerSigCone_pt),
2347 get(dnn::signalChargedHadrCands_sum_outerSigCone_dEta),
2348 get(dnn::signalChargedHadrCands_sum_outerSigCone_dPhi),
2349 get(dnn::signalChargedHadrCands_sum_outerSigCone_mass),
2350 get(dnn::signalChargedHadrCands_nTotal_innerSigCone),
2351 get(dnn::signalChargedHadrCands_nTotal_outerSigCone));
2355 tau.signalNeutrHadrCands(),
2356 signalNeutrHadrCands_sumIn,
2357 signalNeutrHadrCands_sumOut,
2358 get(dnn::signalNeutrHadrCands_sum_innerSigCone_pt),
2359 get(dnn::signalNeutrHadrCands_sum_innerSigCone_dEta),
2360 get(dnn::signalNeutrHadrCands_sum_innerSigCone_dPhi),
2361 get(dnn::signalNeutrHadrCands_sum_innerSigCone_mass),
2362 get(dnn::signalNeutrHadrCands_sum_outerSigCone_pt),
2363 get(dnn::signalNeutrHadrCands_sum_outerSigCone_dEta),
2364 get(dnn::signalNeutrHadrCands_sum_outerSigCone_dPhi),
2365 get(dnn::signalNeutrHadrCands_sum_outerSigCone_mass),
2366 get(dnn::signalNeutrHadrCands_nTotal_innerSigCone),
2367 get(dnn::signalNeutrHadrCands_nTotal_outerSigCone));
2371 tau.signalGammaCands(),
2372 signalGammaCands_sumIn,
2373 signalGammaCands_sumOut,
2374 get(dnn::signalGammaCands_sum_innerSigCone_pt),
2375 get(dnn::signalGammaCands_sum_innerSigCone_dEta),
2376 get(dnn::signalGammaCands_sum_innerSigCone_dPhi),
2377 get(dnn::signalGammaCands_sum_innerSigCone_mass),
2378 get(dnn::signalGammaCands_sum_outerSigCone_pt),
2379 get(dnn::signalGammaCands_sum_outerSigCone_dEta),
2380 get(dnn::signalGammaCands_sum_outerSigCone_dPhi),
2381 get(dnn::signalGammaCands_sum_outerSigCone_mass),
2382 get(dnn::signalGammaCands_nTotal_innerSigCone),
2383 get(dnn::signalGammaCands_nTotal_outerSigCone));
2387 tau.isolationChargedHadrCands(),
2388 isolationChargedHadrCands_sum,
2389 get(dnn::isolationChargedHadrCands_sum_pt),
2390 get(dnn::isolationChargedHadrCands_sum_dEta),
2391 get(dnn::isolationChargedHadrCands_sum_dPhi),
2392 get(dnn::isolationChargedHadrCands_sum_mass),
2393 get(dnn::isolationChargedHadrCands_nTotal));
2397 tau.isolationNeutrHadrCands(),
2398 isolationNeutrHadrCands_sum,
2399 get(dnn::isolationNeutrHadrCands_sum_pt),
2400 get(dnn::isolationNeutrHadrCands_sum_dEta),
2401 get(dnn::isolationNeutrHadrCands_sum_dPhi),
2402 get(dnn::isolationNeutrHadrCands_sum_mass),
2403 get(dnn::isolationNeutrHadrCands_nTotal));
2407 tau.isolationGammaCands(),
2408 isolationGammaCands_sum,
2409 get(dnn::isolationGammaCands_sum_pt),
2410 get(dnn::isolationGammaCands_sum_dEta),
2411 get(dnn::isolationGammaCands_sum_dPhi),
2412 get(dnn::isolationGammaCands_sum_mass),
2413 get(dnn::isolationGammaCands_nTotal));
2415 get(dnn::tau_visMass_innerSigCone) = (signalGammaCands_sumIn + signalChargedHadrCands_sumIn).
mass();
2417 if (check_all_set) {
2418 for (
int var_index = 0; var_index < dnn::NumberOfInputs; ++var_index) {
2419 if (
get(var_index) == default_value_for_set_check)
2420 throw cms::Exception(
"DeepTauId: variable with index = ") << var_index <<
" is not set.";
2429 elecEe = elecEgamma = 0;
2431 if (superCluster.isNonnull() && superCluster.isAvailable() && superCluster->clusters().isNonnull() &&
2432 superCluster->clusters().isAvailable()) {
2433 for (
auto iter = superCluster->clustersBegin(); iter != superCluster->clustersEnd(); ++iter) {
2434 const double energy = (*iter)->energy();
2435 if (iter == superCluster->clustersBegin())
2446 template <
typename Cand
idateCollection,
typename TauCastType>
2469 const bool isInside_innerSigCone =
dR < innerSigCone_radius;
2470 if (isInside_innerSigCone) {
2471 p4_inner +=
cand->p4();
2474 p4_outer +=
cand->p4();
2490 template <
typename Cand
idateCollection,
typename TauCastType>
2514 static constexpr
double min_pt = 30., min_radius = 0.05, cone_opening_coef = 3.;
2520 template <
typename TauCastType>
2522 const size_t tau_index,
2524 TauFunc tau_funcs) {
2525 if (tau_funcs.getHasSecondaryVertex(
tau, tau_index)) {
2526 static constexpr
double mTau = 1.77682;
2527 const double mAOne =
tau.p4().M();
2528 const double pAOneMag =
tau.p();
2529 const double argumentThetaGJmax = (
std::pow(mTau, 2) -
std::pow(mAOne, 2)) / (2 * mTau * pAOneMag);
2530 const double argumentThetaGJmeasured =
tau.p4().Vect().Dot(tau_funcs.getFlightLength(
tau, tau_index)) /
2531 (pAOneMag * tau_funcs.getFlightLength(
tau, tau_index).R());
2532 if (
std::abs(argumentThetaGJmax) <= 1. &&
std::abs(argumentThetaGJmeasured) <= 1.) {
2533 double thetaGJmax = std::asin(argumentThetaGJmax);
2534 double thetaGJmeasured = std::acos(argumentThetaGJmeasured);
2535 gj_diff = thetaGJmeasured - thetaGJmax;
2542 template <
typename TauCastType>
2544 const size_t tau_index,
2545 TauFunc tau_funcs) {
2548 return static_cast<float>(gj_diff);
2554 return abs_eta > 1.46 && abs_eta < 1.558;
2557 template <
typename TauCastType>
2559 const std::vector<pat::Electron>*
electrons,
2564 if (
reco::deltaR2(
tau.p4(), ele.p4()) < dR2 && (!matched_ele || matched_ele->
pt() < ele.pt())) {