1 #ifndef DeepTauIdBase_H 2 #define DeepTauIdBase_H 33 #include "tensorflow/core/util/memmapped_file_system.h" 35 #include <Math/VectorUtil.h> 38 #include "oneapi/tbb/concurrent_unordered_set.h" 58 constexpr int number_of_conv_features = 64;
59 namespace TauBlockInputs {
71 chargedIsoPtSumdR03_over_dR05,
74 neutralIsoPtSumWeight_over_neutralIsoPtSum,
75 neutralIsoPtSumWeightdR03_over_neutralIsoPtSum,
76 neutralIsoPtSumdR03_over_dR05,
77 photonPtSumOutsideSignalCone,
95 tau_pt_weighted_deta_strip,
96 tau_pt_weighted_dphi_strip,
97 tau_pt_weighted_dr_signal,
98 tau_pt_weighted_dr_iso,
99 tau_leadingTrackNormChi2,
102 tau_gj_angle_diff_valid,
106 tau_inside_ecal_crack,
107 leadChargedCand_etaAtEcalEntrance_minus_tau_eta,
110 inline std::vector<int> varsToDrop = {
111 tau_phi, tau_dxy_pca_x, tau_dxy_pca_y, tau_dxy_pca_z};
114 namespace EgammaBlockInputs {
119 tau_inside_ecal_crack,
124 pfCand_ele_pvAssociationQuality,
125 pfCand_ele_puppiWeight,
127 pfCand_ele_lostInnerHits,
128 pfCand_ele_numberOfPixelHits,
129 pfCand_ele_vertex_dx,
130 pfCand_ele_vertex_dy,
131 pfCand_ele_vertex_dz,
132 pfCand_ele_vertex_dx_tauFL,
133 pfCand_ele_vertex_dy_tauFL,
134 pfCand_ele_vertex_dz_tauFL,
135 pfCand_ele_hasTrackDetails,
140 pfCand_ele_track_chi2_ndof,
141 pfCand_ele_track_ndof,
147 ele_cc_ele_rel_energy,
148 ele_cc_gamma_rel_energy,
150 ele_rel_trackMomentumAtVtx,
151 ele_rel_trackMomentumAtCalo,
152 ele_rel_trackMomentumOut,
153 ele_rel_trackMomentumAtEleClus,
154 ele_rel_trackMomentumAtVtxWithConstraint,
157 ele_eSuperClusterOverP,
158 ele_eSeedClusterOverP,
159 ele_eSeedClusterOverPout,
160 ele_eEleClusterOverPout,
161 ele_deltaEtaSuperClusterTrackAtVtx,
162 ele_deltaEtaSeedClusterTrackAtCalo,
163 ele_deltaEtaEleClusterTrackAtCalo,
164 ele_deltaPhiEleClusterTrackAtCalo,
165 ele_deltaPhiSuperClusterTrackAtVtx,
166 ele_deltaPhiSeedClusterTrackAtCalo,
167 ele_mvaInput_earlyBrem,
168 ele_mvaInput_lateBrem,
169 ele_mvaInput_sigmaEtaEta,
170 ele_mvaInput_hadEnergy,
171 ele_mvaInput_deltaEta,
172 ele_gsfTrack_normalizedChi2,
173 ele_gsfTrack_numberOfValidHits,
176 ele_has_closestCtfTrack,
177 ele_closestCtfTrack_normalizedChi2,
178 ele_closestCtfTrack_numberOfValidHits,
183 pfCand_gamma_pvAssociationQuality,
185 pfCand_gamma_puppiWeight,
186 pfCand_gamma_puppiWeightNoLep,
187 pfCand_gamma_lostInnerHits,
188 pfCand_gamma_numberOfPixelHits,
189 pfCand_gamma_vertex_dx,
190 pfCand_gamma_vertex_dy,
191 pfCand_gamma_vertex_dz,
192 pfCand_gamma_vertex_dx_tauFL,
193 pfCand_gamma_vertex_dy_tauFL,
194 pfCand_gamma_vertex_dz_tauFL,
195 pfCand_gamma_hasTrackDetails,
197 pfCand_gamma_dxy_sig,
200 pfCand_gamma_track_chi2_ndof,
201 pfCand_gamma_track_ndof,
206 namespace MuonBlockInputs {
211 tau_inside_ecal_crack,
216 pfCand_muon_pvAssociationQuality,
218 pfCand_muon_puppiWeight,
220 pfCand_muon_lostInnerHits,
221 pfCand_muon_numberOfPixelHits,
222 pfCand_muon_vertex_dx,
223 pfCand_muon_vertex_dy,
224 pfCand_muon_vertex_dz,
225 pfCand_muon_vertex_dx_tauFL,
226 pfCand_muon_vertex_dy_tauFL,
227 pfCand_muon_vertex_dz_tauFL,
228 pfCand_muon_hasTrackDetails,
233 pfCand_muon_track_chi2_ndof,
234 pfCand_muon_track_ndof,
241 muon_normalizedChi2_valid,
243 muon_numberOfValidHits,
244 muon_segmentCompatibility,
245 muon_caloCompatibility,
246 muon_pfEcalEnergy_valid,
247 muon_rel_pfEcalEnergy,
252 muon_n_matches_CSC_1,
253 muon_n_matches_CSC_2,
254 muon_n_matches_CSC_3,
255 muon_n_matches_CSC_4,
256 muon_n_matches_RPC_1,
257 muon_n_matches_RPC_2,
258 muon_n_matches_RPC_3,
259 muon_n_matches_RPC_4,
276 namespace HadronBlockInputs {
281 tau_inside_ecal_crack,
286 pfCand_chHad_leadChargedHadrCand,
287 pfCand_chHad_pvAssociationQuality,
289 pfCand_chHad_puppiWeight,
290 pfCand_chHad_puppiWeightNoLep,
292 pfCand_chHad_lostInnerHits,
293 pfCand_chHad_numberOfPixelHits,
294 pfCand_chHad_vertex_dx,
295 pfCand_chHad_vertex_dy,
296 pfCand_chHad_vertex_dz,
297 pfCand_chHad_vertex_dx_tauFL,
298 pfCand_chHad_vertex_dy_tauFL,
299 pfCand_chHad_vertex_dz_tauFL,
300 pfCand_chHad_hasTrackDetails,
302 pfCand_chHad_dxy_sig,
305 pfCand_chHad_track_chi2_ndof,
306 pfCand_chHad_track_ndof,
307 pfCand_chHad_hcalFraction,
308 pfCand_chHad_rawCaloFraction,
313 pfCand_nHad_puppiWeight,
314 pfCand_nHad_puppiWeightNoLep,
315 pfCand_nHad_hcalFraction,
323 float default_value = -999.,
324 bool assert_input =
true) {
325 static tbb::concurrent_unordered_set<std::string> isFirstWarning;
331 <<
"Exception in <getTauID>: No tauID '" <<
tauID <<
"' available in pat::Tau given as function argument.";
333 if (isFirstWarning.insert(
tauID).second) {
335 <<
"' available in pat::Tau given as function argument." 336 <<
" Using default_value = " << default_value <<
" instead." << std::endl;
338 return default_value;
349 std::map<BasicDiscr, size_t> indexMap;
350 std::map<BasicDiscr, size_t> indexMapdR03;
356 return getTauID(
tau,
"chargedIsoPtSum");
362 return getTauID(
tau,
"chargedIsoPtSumdR03");
365 return (*basicTauDiscriminatordR03Collection)[tau_ref].rawValues.at(
369 return getTauID(
tau,
"footprintCorrectiondR03");
372 return getTauID(
tau,
"footprintCorrection");
378 return getTauID(
tau,
"neutralIsoPtSum");
384 return getTauID(
tau,
"neutralIsoPtSumdR03");
390 return getTauID(
tau,
"neutralIsoPtSumWeight");
394 return (*basicTauDiscriminatordR03Collection)[tau_ref].rawValues.at(
398 return getTauID(
tau,
"neutralIsoPtSumWeightdR03");
400 const float getPhotonPtSumOutsideSignalCone(
const reco::PFTau&
tau,
402 return (*basicTauDiscriminatorCollection)[tau_ref].rawValues.at(
405 const float getPhotonPtSumOutsideSignalCone(
const pat::Tau&
tau,
407 return getTauID(
tau,
"photonPtSumOutsideSignalCone");
409 const float getPhotonPtSumOutsideSignalConedR03(
const reco::PFTau&
tau,
411 return (*basicTauDiscriminatordR03Collection)[tau_ref].rawValues.at(
414 const float getPhotonPtSumOutsideSignalConedR03(
const pat::Tau&
tau,
416 return getTauID(
tau,
"photonPtSumOutsideSignalConedR03");
422 return getTauID(
tau,
"puCorrPtSum");
425 auto getdxyPCA(
const reco::PFTau&
tau,
const size_t tau_index)
const {
428 auto getdxyPCA(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.dxy_PCA(); }
429 auto getdxy(
const reco::PFTau&
tau,
const size_t tau_index)
const {
432 auto getdxy(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.dxy(); }
433 auto getdxyError(
const reco::PFTau&
tau,
const size_t tau_index)
const {
436 auto getdxyError(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.dxy_error(); }
437 auto getdxySig(
const reco::PFTau&
tau,
const size_t tau_index)
const {
440 auto getdxySig(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.dxy_Sig(); }
441 auto getip3d(
const reco::PFTau&
tau,
const size_t tau_index)
const {
444 auto getip3d(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.ip3d(); }
445 auto getip3dError(
const reco::PFTau&
tau,
const size_t tau_index)
const {
448 auto getip3dError(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.ip3d_error(); }
449 auto getip3dSig(
const reco::PFTau&
tau,
const size_t tau_index)
const {
452 auto getip3dSig(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.ip3d_Sig(); }
453 auto getHasSecondaryVertex(
const reco::PFTau&
tau,
const size_t tau_index)
const {
456 auto getHasSecondaryVertex(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.hasSecondaryVertex(); }
457 auto getFlightLength(
const reco::PFTau&
tau,
const size_t tau_index)
const {
460 auto getFlightLength(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.flightLength(); }
461 auto getFlightLengthSig(
const reco::PFTau&
tau,
const size_t tau_index)
const {
464 auto getFlightLengthSig(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.flightLengthSig(); }
467 auto getLeadingTrackNormChi2(
const pat::Tau&
tau) {
return tau.leadingTrackNormChi2(); }
468 auto getEmFraction(
const pat::Tau&
tau) {
return tau.emFraction_MVA(); }
470 auto getEtaAtEcalEntrance(
const pat::Tau&
tau) {
return tau.etaAtEcalEntranceLeadChargedCand(); }
472 return tau.leadPFChargedHadrCand()->positionAtECALEntrance().eta();
474 auto getEcalEnergyLeadingChargedHadr(
const reco::PFTau&
tau) {
return tau.leadPFChargedHadrCand()->ecalEnergy(); }
475 auto getEcalEnergyLeadingChargedHadr(
const pat::Tau&
tau) {
return tau.ecalEnergyLeadChargedHadrCand(); }
476 auto getHcalEnergyLeadingChargedHadr(
const reco::PFTau&
tau) {
return tau.leadPFChargedHadrCand()->hcalEnergy(); }
477 auto getHcalEnergyLeadingChargedHadr(
const pat::Tau&
tau) {
return tau.hcalEnergyLeadChargedHadrCand(); }
479 template <
typename PreDiscrType>
480 bool passPrediscriminants(
const PreDiscrType prediscriminants,
481 const size_t andPrediscriminants,
483 bool passesPrediscriminants = (andPrediscriminants ? 1 : 0);
485 size_t nPrediscriminants = prediscriminants.size();
486 for (
size_t iDisc = 0; iDisc < nPrediscriminants; ++iDisc) {
488 double discResult = (*prediscriminants[iDisc].handle)[tau_ref];
489 uint8_t thisPasses = (discResult > prediscriminants[iDisc].cut) ? 1 : 0;
506 if (thisPasses ^ andPrediscriminants)
508 passesPrediscriminants = (andPrediscriminants ? 0 : 1);
512 return passesPrediscriminants;
520 return cand.bestTrack() !=
nullptr && std::isnormal(
cand.bestTrack()->dz()) && std::isnormal(
cand.dzError()) &&
524 return cand.hasTrackDetails() && std::isnormal(
cand.dz()) && std::isnormal(
cand.dzError()) &&
cand.dzError() > 0;
530 inline auto getPuppiWeight(
const reco::PFCandidate&
cand,
const float aod_value) {
return aod_value; }
532 inline auto getPuppiWeightNoLep(
const reco::PFCandidate&
cand,
const float aod_value) {
return aod_value; }
534 return cand.puppiWeightNoLep();
537 return cand.bestTrack() !=
nullptr 543 return cand.bestTrack() !=
nullptr 548 return cand.numberOfPixelHits();
557 return cand.rawHcalEnergy() / (
cand.rawHcalEnergy() +
cand.rawEcalEnergy());
560 float hcal_fraction = 0.;
564 hcal_fraction =
cand.hcalFraction();
567 if (
cand.pdgId() == 1 ||
cand.pdgId() == 130) {
568 hcal_fraction =
cand.hcalFraction();
569 }
else if (
cand.isIsolatedChargedHadron()) {
570 hcal_fraction =
cand.rawHcalFraction();
573 return hcal_fraction;
576 return (
cand.rawEcalEnergy() +
cand.rawHcalEnergy()) /
cand.energy();
581 template <
typename LVector1,
typename LVector2>
582 float dEta(
const LVector1& p4,
const LVector2& tau_p4) {
583 return static_cast<float>(p4.eta() - tau_p4.eta());
586 template <
typename LVector1,
typename LVector2>
587 float dPhi(
const LVector1& p4_1,
const LVector2& p4_2) {
588 return static_cast<float>(
reco::deltaPhi(p4_2.phi(), p4_1.phi()));
591 struct MuonHitMatchV2 {
592 static constexpr size_t n_muon_stations = 4;
593 static constexpr int first_station_id = 1;
594 static constexpr int last_station_id = first_station_id + n_muon_stations - 1;
595 using CountArray = std::array<unsigned, n_muon_stations>;
596 using CountMap = std::map<int, CountArray>;
598 const std::vector<int>& consideredSubdets() {
604 static const std::map<int, std::string> subdet_names = {
606 if (!subdet_names.count(subdet))
607 throw cms::Exception(
"MuonHitMatch") <<
"Subdet name for subdet id " << subdet <<
" not found.";
608 return subdet_names.at(subdet);
611 size_t getStationIndex(
int station,
bool throw_exception)
const {
612 if (station < first_station_id || station > last_station_id) {
614 throw cms::Exception(
"MuonHitMatch") <<
"Station id is out of range";
617 return static_cast<size_t>(
station - 1);
621 for (
int subdet : consideredSubdets()) {
622 n_matches[subdet].fill(0);
623 n_hits[subdet].fill(0);
631 for (
const auto& segment :
muon.matches()) {
632 if (segment.segmentMatches.empty() && segment.rpcMatches.empty())
634 if (n_matches.count(segment.detector())) {
635 const size_t station_index = getStationIndex(segment.station(),
true);
636 ++n_matches.at(segment.detector()).at(station_index);
642 if (
muon.outerTrack().isNonnull()) {
643 const auto& hit_pattern =
muon.outerTrack()->hitPattern();
650 const size_t station_index = getStationIndex(hit_pattern.getMuonStation(hit_id),
false);
651 if (station_index < n_muon_stations) {
652 CountArray* muon_n_hits =
nullptr;
653 if (hit_pattern.muonDTHitFilter(hit_id))
655 else if (hit_pattern.muonCSCHitFilter(hit_id))
657 else if (hit_pattern.muonRPCHitFilter(hit_id))
661 ++muon_n_hits->at(station_index);
668 unsigned nMatches(
int subdet,
int station)
const {
669 if (!n_matches.count(subdet))
670 throw cms::Exception(
"MuonHitMatch") <<
"Subdet " << subdet <<
" not found.";
671 const size_t station_index = getStationIndex(
station,
true);
672 return n_matches.at(subdet).at(station_index);
676 if (!n_hits.count(subdet))
677 throw cms::Exception(
"MuonHitMatch") <<
"Subdet " << subdet <<
" not found.";
678 const size_t station_index = getStationIndex(
station,
true);
679 return n_hits.at(subdet).at(station_index);
682 unsigned countMuonStationsWithMatches(
int first_station,
int last_station)
const {
683 static const std::map<int, std::vector<bool>> masks = {
688 const size_t first_station_index = getStationIndex(first_station,
true);
689 const size_t last_station_index = getStationIndex(last_station,
true);
691 for (
size_t n = first_station_index;
n <= last_station_index; ++
n) {
692 for (
const auto&
match : n_matches) {
693 if (!masks.at(
match.first).at(
n) &&
match.second.at(
n) > 0)
700 unsigned countMuonStationsWithHits(
int first_station,
int last_station)
const {
701 static const std::map<int, std::vector<bool>> masks = {
707 const size_t first_station_index = getStationIndex(first_station,
true);
708 const size_t last_station_index = getStationIndex(last_station,
true);
710 for (
size_t n = first_station_index;
n <= last_station_index; ++
n) {
711 for (
const auto&
hit : n_hits) {
712 if (!masks.at(
hit.first).at(
n) &&
hit.second.at(
n) > 0)
720 CountMap n_matches, n_hits;
726 PfCand_chargedHadron,
727 PfCand_neutralHadron,
734 template <
typename Object>
747 static const std::map<int, CellObjectType> obj_types = {{11, CellObjectType::PfCand_electron},
748 {13, CellObjectType::PfCand_muon},
749 {22, CellObjectType::PfCand_gamma},
750 {130, CellObjectType::PfCand_neutralHadron},
751 {211, CellObjectType::PfCand_chargedHadron}};
754 if (iter == obj_types.end())
755 return CellObjectType::Other;
759 using Cell = std::map<CellObjectType, size_t>;
772 using Map = std::map<CellIndex, Cell>;
773 using const_iterator = Map::const_iterator;
775 CellGrid(
unsigned n_cells_eta,
776 unsigned n_cells_phi,
777 double cell_size_eta,
778 double cell_size_phi,
780 : nCellsEta(n_cells_eta),
781 nCellsPhi(n_cells_phi),
782 nTotal(nCellsEta * nCellsPhi),
783 cellSizeEta(cell_size_eta),
784 cellSizePhi(cell_size_phi),
786 if (nCellsEta % 2 != 1 || nCellsEta < 1)
787 throw cms::Exception(
"DeepTauId") <<
"Invalid number of eta cells.";
788 if (nCellsPhi % 2 != 1 || nCellsPhi < 1)
789 throw cms::Exception(
"DeepTauId") <<
"Invalid number of phi cells.";
790 if (cellSizeEta <= 0 || cellSizePhi <= 0)
794 int maxEtaIndex()
const {
return static_cast<int>((nCellsEta - 1) / 2); }
795 int maxPhiIndex()
const {
return static_cast<int>((nCellsPhi - 1) / 2); }
796 double maxDeltaEta()
const {
return cellSizeEta * (0.5 + maxEtaIndex()); }
797 double maxDeltaPhi()
const {
return cellSizePhi * (0.5 + maxPhiIndex()); }
798 int getEtaTensorIndex(
const CellIndex& cellIndex)
const {
return cellIndex.eta + maxEtaIndex(); }
799 int getPhiTensorIndex(
const CellIndex& cellIndex)
const {
return cellIndex.phi + maxPhiIndex(); }
801 bool tryGetCellIndex(
double deltaEta,
double deltaPhi, CellIndex& cellIndex)
const {
802 const auto getCellIndex = [
this](
double x,
double maxX,
double size,
int&
index) {
807 if (disable_CellIndex_workaround_) {
810 absIndex = std::floor(absX /
size + 0.5);
815 index =
static_cast<int>(std::copysign(absIndex,
x));
823 size_t num_valid_cells()
const {
return cells.size(); }
825 const Cell& at(
const CellIndex& cellIndex)
const {
return cells.at(cellIndex); }
826 size_t count(
const CellIndex& cellIndex)
const {
return cells.count(cellIndex); }
827 const_iterator
find(
const CellIndex& cellIndex)
const {
return cells.find(cellIndex); }
828 const_iterator
begin()
const {
return cells.begin(); }
829 const_iterator
end()
const {
return cells.end(); }
832 const unsigned nCellsEta, nCellsPhi, nTotal;
833 const double cellSizeEta, cellSizePhi;
836 std::map<CellIndex, Cell>
cells;
837 const bool disable_CellIndex_workaround_;
841 template <
class Producer>
862 float read_value(
const tensorflow::Tensor& pred,
size_t tau_index,
size_t elem)
const {
863 return pred.matrix<
float>()(tau_index, elem);
867 return pred.at(tau_index).at(elem);
870 template <
typename PredType>
872 const PredType& pred,
875 std::vector<reco::SingleTauDiscriminatorContainer> outputbuffer(
taus->size());
877 for (
size_t tau_index = 0; tau_index <
taus->size(); ++tau_index) {
879 for (
size_t num_elem :
num_)
881 if (
x != 0 && !
den_.empty()) {
883 for (
size_t den_elem :
den_)
884 den_val +=
read_value(pred, tau_index, den_elem);
887 outputbuffer[tau_index].rawValues.push_back(
x);
891 outputbuffer[tau_index].workingPoints.push_back(pass);
895 std::unique_ptr<TauDiscriminator>
output = std::make_unique<TauDiscriminator>();
897 filler.insert(
taus, outputbuffer.begin(), outputbuffer.end());
908 static constexpr size_t e_index = 0, mu_index = 1, tau_index = 2, jet_index = 3;
910 {
"VSe", IDOutput({tau_index}, {e_index, tau_index})},
911 {
"VSmu", IDOutput({tau_index}, {mu_index, tau_index})},
912 {
"VSjet", IDOutput({tau_index}, {jet_index, tau_index})},
922 std::vector<BasicDiscriminator> requiredDiscr) {
923 std::map<std::string, size_t> discrIndexMapStr;
924 auto const aHandle =
event.getHandle(discriminatorContainerToken);
925 auto const aProv = aHandle.provenance();
926 if (aProv ==
nullptr)
927 aHandle.whyFailed()->raise();
928 const auto& psetsFromProvenance =
edm::parameterSet(aProv->stable(),
event.processHistory());
929 auto const idlist = psetsFromProvenance.
getParameter<std::vector<edm::ParameterSet>>(
"IDdefinitions");
930 for (
size_t j = 0;
j < idlist.size(); ++
j) {
932 if (discrIndexMapStr.count(idname)) {
934 <<
"basic discriminator " << idname <<
" appears more than once in the input.";
936 discrIndexMapStr[idname] =
j;
940 std::map<BasicDiscriminator, size_t> discrIndexMap;
941 for (
size_t i = 0;
i < requiredDiscr.size();
i++) {
944 <<
" was not provided in the config file.";
948 return discrIndexMap;
958 desc.add<
bool>(
"mem_mapped",
false);
959 desc.add<
unsigned>(
"year", 2017);
960 desc.add<
unsigned>(
"version", 2);
961 desc.add<
unsigned>(
"sub_version", 1);
962 desc.add<
int>(
"debug_level", 0);
963 desc.add<
bool>(
"disable_dxy_pca",
false);
964 desc.add<
bool>(
"disable_hcalFraction_workaround",
false);
965 desc.add<
bool>(
"disable_CellIndex_workaround",
false);
966 desc.add<
bool>(
"save_inputs",
false);
967 desc.add<
bool>(
"is_online",
false);
969 desc.add<std::vector<std::string>>(
"VSeWP", {
"-1."});
970 desc.add<std::vector<std::string>>(
"VSmuWP", {
"-1."});
971 desc.add<std::vector<std::string>>(
"VSjetWP", {
"-1."});
982 psd1.
add<
double>(
"cut");
1003 cfg.getUntrackedParameter<
edm::
InputTag>(
"basicTauDiscriminators"))),
1005 cfg.getUntrackedParameter<
edm::
InputTag>(
"basicTauDiscriminatorsdR03"))),
1009 cfg.getParameter<
edm::
InputTag>(
"pfTauTransverseImpactParameters"))),
1010 year_(
cfg.getParameter<unsigned>(
"year")),
1021 this->
template produces<TauDiscriminator>(output_desc.first);
1022 const auto& cut_list =
cfg.getParameter<std::vector<std::string>>(output_desc.first +
"WP");
1024 workingPoints_[output_desc.first].push_back(std::make_unique<Cutter>(cut_str));
1035 transform(pdBoolOperator.begin(), pdBoolOperator.end(), pdBoolOperator.begin(), ::tolower);
1037 if (pdBoolOperator ==
"and") {
1039 }
else if (pdBoolOperator ==
"or") {
1043 <<
"PrediscriminantBooleanOperator defined incorrectly, options are: AND,OR";
1047 std::vector<std::string> prediscriminantsNames =
1050 for (
auto const& iDisc : prediscriminantsNames) {
1056 TauDiscInfo<reco::PFTauDiscriminator> thisDiscriminator;
1057 thisDiscriminator.label =
label;
1058 thisDiscriminator.cut =
cut;
1059 thisDiscriminator.disc_token = this->
template consumes<reco::PFTauDiscriminator>(
label);
1062 TauDiscInfo<pat::PATTauDiscriminator> thisDiscriminator;
1063 thisDiscriminator.label =
label;
1064 thisDiscriminator.cut =
cut;
1065 thisDiscriminator.disc_token = this->
template consumes<pat::PATTauDiscriminator>(
label);
1078 std::sort(TauBlockInputs::varsToDrop.begin(), TauBlockInputs::varsToDrop.
end());
1079 for (
auto v : TauBlockInputs::varsToDrop) {
1080 tauInputs_indices_.at(
v) = TauBlockInputs::NumberOfInputs - TauBlockInputs::varsToDrop.size();
1081 for (std::size_t
i =
v + 1;
i < TauBlockInputs::NumberOfInputs; ++
i)
1084 if (
year_ == 2026) {
1092 std::map<std::vector<bool>, std::vector<sc::FeatureT>> GridFeatureTypes_map = {
1093 {{
false}, {sc::FeatureT::TauFlat, sc::FeatureT::GridGlobal}},
1095 {sc::FeatureT::PfCand_electron,
1096 sc::FeatureT::PfCand_muon,
1097 sc::FeatureT::PfCand_chHad,
1098 sc::FeatureT::PfCand_nHad,
1099 sc::FeatureT::PfCand_gamma,
1104 for (
const auto&
p : GridFeatureTypes_map) {
1105 for (
auto is_inner :
p.first) {
1106 for (
auto featureType :
p.second) {
1107 const sc::ScalingParams& sp =
scalingParamsMap_->at(std::make_pair(featureType, is_inner));
1108 if (!(sp.mean_.size() == sp.std_.size() && sp.mean_.size() == sp.lim_min_.size() &&
1109 sp.mean_.size() == sp.lim_max_.size()))
1110 throw cms::Exception(
"DeepTauId") <<
"sizes of scaling parameter vectors do not match between each other";
1119 template <
typename ConsumeType>
1136 template <
typename PredType>
1148 template <
typename T>
1150 return std::isnormal(
value) ?
static_cast<float>(
value) : 0.
f;
1153 template <
typename T>
1159 transformed_value = transformed_value * 2 - 1;
1160 return transformed_value;
1163 template <
typename T>
1166 const float norm_value = (fixed_value -
mean) / sigma;
1167 return std::clamp(norm_value, -n_sigmas_max, n_sigmas_max);
1173 float& cc_ele_energy,
1174 float& cc_gamma_energy,
1176 cc_ele_energy = cc_gamma_energy = 0;
1179 if (superCluster.isNonnull() && superCluster.isAvailable() && superCluster->clusters().isNonnull() &&
1180 superCluster->clusters().isAvailable()) {
1181 for (
auto iter = superCluster->clustersBegin(); iter != superCluster->clustersEnd(); ++iter) {
1182 const float energy =
static_cast<float>((*iter)->energy());
1183 if (iter == superCluster->clustersBegin())
1186 cc_gamma_energy +=
energy;
1199 size_t nPrediscriminants =
1201 for (
size_t iDisc = 0; iDisc < nPrediscriminants; ++iDisc) {
1213 if (tauProductID != discKeyId) {
1215 <<
"The tau collection has product ID: " << tauProductID
1216 <<
" but the pre-discriminator is keyed with product ID: " << discKeyId << std::endl;
1221 template <
typename Collection,
typename TauCastType>
1222 void fillGrids(
const TauCastType&
tau,
const Collection&
objects, CellGrid& inner_grid, CellGrid& outer_grid) {
1223 static constexpr double outer_dR2 = 0.25;
1225 const double inner_dR2 =
std::pow(inner_radius, 2);
1227 const auto addObject = [&](
size_t n,
double deta,
double dphi, CellGrid&
grid) {
1230 if (obj_type == CellObjectType::Other)
1232 CellIndex cell_index;
1233 if (
grid.tryGetCellIndex(deta, dphi, cell_index)) {
1235 auto iter = cell.find(obj_type);
1236 if (iter != cell.end()) {
1237 const auto& prev_obj =
objects.at(iter->second);
1238 if (
obj.polarP4().pt() > prev_obj.polarP4().pt())
1246 for (
size_t n = 0;
n <
objects.size(); ++
n) {
1248 const double deta =
obj.polarP4().eta() -
tau.polarP4().eta();
1251 if (
dR2 < inner_dR2)
1252 addObject(
n, deta, dphi, inner_grid);
1253 if (
dR2 < outer_dR2)
1254 addObject(
n, deta, dphi, outer_grid);
1258 template <
typename Cand
idateCastType,
typename TauCastType,
typename TauBlockType>
1260 const size_t& tau_index,
1265 TauBlockType& tauBlockInputs) {
1272 const auto&
get = [&](
int var_index) ->
float& {
1273 if constexpr (std::is_same_v<TauBlockType, std::vector<float>::iterator>) {
1276 return ((tensorflow::Tensor)tauBlockInputs).matrix<float>()(0,
tauInputs_indices_.at(var_index));
1280 auto leadChargedHadrCand =
dynamic_cast<const CandidateCastType*
>(
tau.leadChargedHadrCand().get());
1291 get(dnn::tau_n_charged_prongs) = sp.scale(
tau.decayMode() / 5 + 1,
tauInputs_indices_[dnn::tau_n_charged_prongs]);
1292 get(dnn::tau_n_neutral_prongs) = sp.scale(
tau.decayMode() % 5,
tauInputs_indices_[dnn::tau_n_neutral_prongs]);
1293 get(dnn::chargedIsoPtSum) =
1295 get(dnn::chargedIsoPtSumdR03_over_dR05) =
1296 sp.scale(tau_funcs.getChargedIsoPtSumdR03(
tau, tau_ref) / tau_funcs.getChargedIsoPtSum(
tau, tau_ref),
1299 get(dnn::footprintCorrection) =
1300 sp.scale(tau_funcs.getFootprintCorrectiondR03(
tau, tau_ref),
tauInputs_indices_[dnn::footprintCorrection]);
1303 get(dnn::footprintCorrection) =
1304 sp.scale(tau_funcs.getFootprintCorrectiondR03(
tau, tau_ref),
tauInputs_indices_[dnn::footprintCorrection]);
1306 get(dnn::footprintCorrection) =
1307 sp.scale(tau_funcs.getFootprintCorrection(
tau, tau_ref),
tauInputs_indices_[dnn::footprintCorrection]);
1309 get(dnn::neutralIsoPtSum) =
1311 get(dnn::neutralIsoPtSumWeight_over_neutralIsoPtSum) =
1312 sp.scale(tau_funcs.getNeutralIsoPtSumWeight(
tau, tau_ref) / tau_funcs.getNeutralIsoPtSum(
tau, tau_ref),
1314 get(dnn::neutralIsoPtSumWeightdR03_over_neutralIsoPtSum) =
1315 sp.scale(tau_funcs.getNeutralIsoPtSumdR03Weight(
tau, tau_ref) / tau_funcs.getNeutralIsoPtSum(
tau, tau_ref),
1317 get(dnn::neutralIsoPtSumdR03_over_dR05) =
1318 sp.scale(tau_funcs.getNeutralIsoPtSumdR03(
tau, tau_ref) / tau_funcs.getNeutralIsoPtSum(
tau, tau_ref),
1320 get(dnn::photonPtSumOutsideSignalCone) = sp.scale(tau_funcs.getPhotonPtSumOutsideSignalCone(
tau, tau_ref),
1322 get(dnn::puCorrPtSum) = sp.scale(tau_funcs.getPuCorrPtSum(
tau, tau_ref),
tauInputs_indices_[dnn::puCorrPtSum]);
1329 auto const pca = tau_funcs.getdxyPCA(
tau, tau_index);
1334 get(dnn::tau_dxy_pca_x) = 0;
1335 get(dnn::tau_dxy_pca_y) = 0;
1336 get(dnn::tau_dxy_pca_z) = 0;
1340 const bool tau_dxy_valid =
1341 isAbove(tau_funcs.getdxy(
tau, tau_index), -10) &&
isAbove(tau_funcs.getdxyError(
tau, tau_index), 0);
1342 if (tau_dxy_valid) {
1343 get(dnn::tau_dxy_valid) = sp.scale(tau_dxy_valid,
tauInputs_indices_[dnn::tau_dxy_valid]);
1345 get(dnn::tau_dxy_sig) =
1346 sp.scale(
std::abs(tau_funcs.getdxy(
tau, tau_index)) / tau_funcs.getdxyError(
tau, tau_index),
1349 const bool tau_ip3d_valid =
1350 isAbove(tau_funcs.getip3d(
tau, tau_index), -10) &&
isAbove(tau_funcs.getip3dError(
tau, tau_index), 0);
1351 if (tau_ip3d_valid) {
1352 get(dnn::tau_ip3d_valid) = sp.scale(tau_ip3d_valid,
tauInputs_indices_[dnn::tau_ip3d_valid]);
1353 get(dnn::tau_ip3d) = sp.scale(tau_funcs.getip3d(
tau, tau_index),
tauInputs_indices_[dnn::tau_ip3d]);
1354 get(dnn::tau_ip3d_sig) =
1355 sp.scale(
std::abs(tau_funcs.getip3d(
tau, tau_index)) / tau_funcs.getip3dError(
tau, tau_index),
1358 if (leadChargedHadrCand) {
1359 const bool hasTrackDetails = candFunc::getHasTrackDetails(*leadChargedHadrCand);
1360 const float tau_dz = (
is_online_ && !hasTrackDetails) ? 0 : candFunc::getTauDz(*leadChargedHadrCand);
1362 get(dnn::tau_dz_sig_valid) =
1363 sp.scale(candFunc::getTauDZSigValid(*leadChargedHadrCand),
tauInputs_indices_[dnn::tau_dz_sig_valid]);
1364 const double dzError = hasTrackDetails ? leadChargedHadrCand->dzError() : -999.;
1367 get(dnn::tau_flightLength_x) =
1368 sp.scale(tau_funcs.getFlightLength(
tau, tau_index).x(),
tauInputs_indices_[dnn::tau_flightLength_x]);
1369 get(dnn::tau_flightLength_y) =
1370 sp.scale(tau_funcs.getFlightLength(
tau, tau_index).y(),
tauInputs_indices_[dnn::tau_flightLength_y]);
1371 get(dnn::tau_flightLength_z) =
1372 sp.scale(tau_funcs.getFlightLength(
tau, tau_index).z(),
tauInputs_indices_[dnn::tau_flightLength_z]);
1374 get(dnn::tau_flightLength_sig) = 0.55756444;
1376 get(dnn::tau_flightLength_sig) =
1377 sp.scale(tau_funcs.getFlightLengthSig(
tau, tau_index),
tauInputs_indices_[dnn::tau_flightLength_sig]);
1386 get(dnn::tau_pt_weighted_dr_iso) =
1388 get(dnn::tau_leadingTrackNormChi2) =
1389 sp.scale(tau_funcs.getLeadingTrackNormChi2(
tau),
tauInputs_indices_[dnn::tau_leadingTrackNormChi2]);
1391 const bool tau_e_ratio_valid = std::isnormal(
eratio) &&
eratio > 0.f;
1392 get(dnn::tau_e_ratio_valid) = sp.scale(tau_e_ratio_valid,
tauInputs_indices_[dnn::tau_e_ratio_valid]);
1395 const bool tau_gj_angle_diff_valid = (std::isnormal(gj_angle_diff) || gj_angle_diff == 0) && gj_angle_diff >= 0;
1396 get(dnn::tau_gj_angle_diff_valid) =
1398 get(dnn::tau_gj_angle_diff) =
1399 tau_gj_angle_diff_valid ? sp.scale(gj_angle_diff,
tauInputs_indices_[dnn::tau_gj_angle_diff]) : 0;
1401 get(dnn::tau_emFraction) = sp.scale(tau_funcs.getEmFraction(
tau),
tauInputs_indices_[dnn::tau_emFraction]);
1403 get(dnn::tau_inside_ecal_crack) =
1405 get(dnn::leadChargedCand_etaAtEcalEntrance_minus_tau_eta) =
1406 sp.scale(tau_funcs.getEtaAtEcalEntrance(
tau) -
tau.p4().eta(),
1410 template <
typename Cand
idateCastType,
typename TauCastType,
typename EgammaBlockType>
1412 const TauCastType&
tau,
1413 const size_t tau_index,
1417 const std::vector<pat::Electron>*
electrons,
1419 const Cell& cell_map,
1422 EgammaBlockType& egammaBlockInputs) {
1432 int PFe_index_offset =
scalingParamsMap_->at(std::make_pair(ft_global,
false)).mean_.size();
1433 int e_index_offset = PFe_index_offset +
scalingParamsMap_->at(std::make_pair(ft_PFe,
false)).mean_.size();
1434 int PFg_index_offset = e_index_offset +
scalingParamsMap_->at(std::make_pair(ft_e,
false)).mean_.size();
1437 int fill_index_offset_e = 0;
1438 int fill_index_offset_PFg = 0;
1440 fill_index_offset_e =
1442 fill_index_offset_PFg =
1446 const auto&
get = [&](
int var_index) ->
float& {
1447 if constexpr (std::is_same_v<EgammaBlockType, std::vector<float>::iterator>) {
1448 return *(egammaBlockInputs + var_index);
1450 return ((tensorflow::Tensor)egammaBlockInputs).tensor<float, 4>()(
idx, 0, 0, var_index);
1454 const bool valid_index_pf_ele = cell_map.count(CellObjectType::PfCand_electron);
1455 const bool valid_index_pf_gamma = cell_map.count(CellObjectType::PfCand_gamma);
1458 if (!cell_map.empty()) {
1459 const sc::ScalingParams& sp =
scalingParamsMap_->at(std::make_pair(ft_global,
false));
1463 get(dnn::tau_inside_ecal_crack) = sp.scale(
isInEcalCrack(
tau.polarP4().eta()), dnn::tau_inside_ecal_crack);
1465 if (valid_index_pf_ele) {
1466 const sc::ScalingParams& sp =
scalingParamsMap_->at(std::make_pair(ft_PFe, is_inner));
1467 size_t index_pf_ele = cell_map.at(CellObjectType::PfCand_electron);
1468 const auto& ele_cand =
dynamic_cast<const CandidateCastType&
>(pfCands.
at(index_pf_ele));
1470 get(dnn::pfCand_ele_valid) = sp.scale(valid_index_pf_ele, dnn::pfCand_ele_valid - PFe_index_offset);
1471 get(dnn::pfCand_ele_rel_pt) =
1472 sp.scale(ele_cand.polarP4().pt() /
tau.polarP4().pt(), dnn::pfCand_ele_rel_pt - PFe_index_offset);
1473 get(dnn::pfCand_ele_deta) =
1474 sp.scale(ele_cand.polarP4().eta() -
tau.polarP4().eta(), dnn::pfCand_ele_deta - PFe_index_offset);
1475 get(dnn::pfCand_ele_dphi) =
1476 sp.scale(
dPhi(
tau.polarP4(), ele_cand.polarP4()), dnn::pfCand_ele_dphi - PFe_index_offset);
1477 get(dnn::pfCand_ele_pvAssociationQuality) = sp.scale<
int>(
1478 candFunc::getPvAssocationQuality(ele_cand), dnn::pfCand_ele_pvAssociationQuality - PFe_index_offset);
1479 get(dnn::pfCand_ele_puppiWeight) = is_inner ? sp.scale(candFunc::getPuppiWeight(ele_cand, 0.9906834f),
1480 dnn::pfCand_ele_puppiWeight - PFe_index_offset)
1481 : sp.scale(candFunc::getPuppiWeight(ele_cand, 0.9669586
f),
1482 dnn::pfCand_ele_puppiWeight - PFe_index_offset);
1483 get(dnn::pfCand_ele_charge) = sp.scale(ele_cand.charge(), dnn::pfCand_ele_charge - PFe_index_offset);
1484 get(dnn::pfCand_ele_lostInnerHits) =
1485 sp.scale<
int>(candFunc::getLostInnerHits(ele_cand, 0), dnn::pfCand_ele_lostInnerHits - PFe_index_offset);
1486 get(dnn::pfCand_ele_numberOfPixelHits) =
1487 sp.scale(candFunc::getNumberOfPixelHits(ele_cand, 0), dnn::pfCand_ele_numberOfPixelHits - PFe_index_offset);
1488 get(dnn::pfCand_ele_vertex_dx) =
1489 sp.scale(ele_cand.vertex().x() -
pv.position().x(), dnn::pfCand_ele_vertex_dx - PFe_index_offset);
1490 get(dnn::pfCand_ele_vertex_dy) =
1491 sp.scale(ele_cand.vertex().y() -
pv.position().y(), dnn::pfCand_ele_vertex_dy - PFe_index_offset);
1492 get(dnn::pfCand_ele_vertex_dz) =
1493 sp.scale(ele_cand.vertex().z() -
pv.position().z(), dnn::pfCand_ele_vertex_dz - PFe_index_offset);
1494 get(dnn::pfCand_ele_vertex_dx_tauFL) =
1495 sp.scale(ele_cand.vertex().x() -
pv.position().x() - tau_funcs.getFlightLength(
tau, tau_index).x(),
1496 dnn::pfCand_ele_vertex_dx_tauFL - PFe_index_offset);
1497 get(dnn::pfCand_ele_vertex_dy_tauFL) =
1498 sp.scale(ele_cand.vertex().y() -
pv.position().y() - tau_funcs.getFlightLength(
tau, tau_index).y(),
1499 dnn::pfCand_ele_vertex_dy_tauFL - PFe_index_offset);
1500 get(dnn::pfCand_ele_vertex_dz_tauFL) =
1501 sp.scale(ele_cand.vertex().z() -
pv.position().z() - tau_funcs.getFlightLength(
tau, tau_index).z(),
1502 dnn::pfCand_ele_vertex_dz_tauFL - PFe_index_offset);
1504 const bool hasTrackDetails = candFunc::getHasTrackDetails(ele_cand);
1505 if (hasTrackDetails) {
1506 get(dnn::pfCand_ele_hasTrackDetails) =
1507 sp.scale(hasTrackDetails, dnn::pfCand_ele_hasTrackDetails - PFe_index_offset);
1508 get(dnn::pfCand_ele_dxy) = sp.scale(candFunc::getTauDxy(ele_cand), dnn::pfCand_ele_dxy - PFe_index_offset);
1509 get(dnn::pfCand_ele_dxy_sig) = sp.scale(
std::abs(candFunc::getTauDxy(ele_cand)) / ele_cand.dxyError(),
1510 dnn::pfCand_ele_dxy_sig - PFe_index_offset);
1511 get(dnn::pfCand_ele_dz) = sp.scale(candFunc::getTauDz(ele_cand), dnn::pfCand_ele_dz - PFe_index_offset);
1512 get(dnn::pfCand_ele_dz_sig) = sp.scale(
std::abs(candFunc::getTauDz(ele_cand)) / ele_cand.dzError(),
1513 dnn::pfCand_ele_dz_sig - PFe_index_offset);
1514 get(dnn::pfCand_ele_track_chi2_ndof) =
1515 candFunc::getPseudoTrack(ele_cand).ndof() > 0
1516 ? sp.scale(candFunc::getPseudoTrack(ele_cand).
chi2() / candFunc::getPseudoTrack(ele_cand).
ndof(),
1517 dnn::pfCand_ele_track_chi2_ndof - PFe_index_offset)
1519 get(dnn::pfCand_ele_track_ndof) =
1520 candFunc::getPseudoTrack(ele_cand).ndof() > 0
1521 ? sp.scale(candFunc::getPseudoTrack(ele_cand).
ndof(), dnn::pfCand_ele_track_ndof - PFe_index_offset)
1525 if (valid_index_pf_gamma) {
1526 const sc::ScalingParams& sp =
scalingParamsMap_->at(std::make_pair(ft_PFg, is_inner));
1527 size_t index_pf_gamma = cell_map.at(CellObjectType::PfCand_gamma);
1528 const auto& gamma_cand =
dynamic_cast<const CandidateCastType&
>(pfCands.
at(index_pf_gamma));
1530 get(dnn::pfCand_gamma_valid + fill_index_offset_PFg) =
1531 sp.scale(valid_index_pf_gamma, dnn::pfCand_gamma_valid - PFg_index_offset);
1532 get(dnn::pfCand_gamma_rel_pt + fill_index_offset_PFg) =
1533 sp.scale(gamma_cand.polarP4().pt() /
tau.polarP4().pt(), dnn::pfCand_gamma_rel_pt - PFg_index_offset);
1534 get(dnn::pfCand_gamma_deta + fill_index_offset_PFg) =
1535 sp.scale(gamma_cand.polarP4().eta() -
tau.polarP4().eta(), dnn::pfCand_gamma_deta - PFg_index_offset);
1536 get(dnn::pfCand_gamma_dphi + fill_index_offset_PFg) =
1537 sp.scale(
dPhi(
tau.polarP4(), gamma_cand.polarP4()), dnn::pfCand_gamma_dphi - PFg_index_offset);
1538 get(dnn::pfCand_gamma_pvAssociationQuality + fill_index_offset_PFg) = sp.scale<
int>(
1539 candFunc::getPvAssocationQuality(gamma_cand), dnn::pfCand_gamma_pvAssociationQuality - PFg_index_offset);
1540 get(dnn::pfCand_gamma_fromPV + fill_index_offset_PFg) =
1541 sp.scale<
int>(candFunc::getFromPV(gamma_cand), dnn::pfCand_gamma_fromPV - PFg_index_offset);
1542 get(dnn::pfCand_gamma_puppiWeight + fill_index_offset_PFg) =
1543 is_inner ? sp.scale(candFunc::getPuppiWeight(gamma_cand, 0.9084110f),
1544 dnn::pfCand_gamma_puppiWeight - PFg_index_offset)
1545 : sp.scale(candFunc::getPuppiWeight(gamma_cand, 0.4211567
f),
1546 dnn::pfCand_gamma_puppiWeight - PFg_index_offset);
1547 get(dnn::pfCand_gamma_puppiWeightNoLep + fill_index_offset_PFg) =
1548 is_inner ? sp.scale(candFunc::getPuppiWeightNoLep(gamma_cand, 0.8857716f),
1549 dnn::pfCand_gamma_puppiWeightNoLep - PFg_index_offset)
1550 : sp.scale(candFunc::getPuppiWeightNoLep(gamma_cand, 0.3822604
f),
1551 dnn::pfCand_gamma_puppiWeightNoLep - PFg_index_offset);
1552 get(dnn::pfCand_gamma_lostInnerHits + fill_index_offset_PFg) =
1553 sp.scale<
int>(candFunc::getLostInnerHits(gamma_cand, 0), dnn::pfCand_gamma_lostInnerHits - PFg_index_offset);
1554 get(dnn::pfCand_gamma_numberOfPixelHits + fill_index_offset_PFg) = sp.scale(
1555 candFunc::getNumberOfPixelHits(gamma_cand, 0), dnn::pfCand_gamma_numberOfPixelHits - PFg_index_offset);
1556 get(dnn::pfCand_gamma_vertex_dx + fill_index_offset_PFg) =
1557 sp.scale(gamma_cand.vertex().x() -
pv.position().x(), dnn::pfCand_gamma_vertex_dx - PFg_index_offset);
1558 get(dnn::pfCand_gamma_vertex_dy + fill_index_offset_PFg) =
1559 sp.scale(gamma_cand.vertex().y() -
pv.position().y(), dnn::pfCand_gamma_vertex_dy - PFg_index_offset);
1560 get(dnn::pfCand_gamma_vertex_dz + fill_index_offset_PFg) =
1561 sp.scale(gamma_cand.vertex().z() -
pv.position().z(), dnn::pfCand_gamma_vertex_dz - PFg_index_offset);
1562 get(dnn::pfCand_gamma_vertex_dx_tauFL + fill_index_offset_PFg) =
1563 sp.scale(gamma_cand.vertex().x() -
pv.position().x() - tau_funcs.getFlightLength(
tau, tau_index).x(),
1564 dnn::pfCand_gamma_vertex_dx_tauFL - PFg_index_offset);
1565 get(dnn::pfCand_gamma_vertex_dy_tauFL + fill_index_offset_PFg) =
1566 sp.scale(gamma_cand.vertex().y() -
pv.position().y() - tau_funcs.getFlightLength(
tau, tau_index).y(),
1567 dnn::pfCand_gamma_vertex_dy_tauFL - PFg_index_offset);
1568 get(dnn::pfCand_gamma_vertex_dz_tauFL + fill_index_offset_PFg) =
1569 sp.scale(gamma_cand.vertex().z() -
pv.position().z() - tau_funcs.getFlightLength(
tau, tau_index).z(),
1570 dnn::pfCand_gamma_vertex_dz_tauFL - PFg_index_offset);
1571 const bool hasTrackDetails = candFunc::getHasTrackDetails(gamma_cand);
1572 if (hasTrackDetails) {
1573 get(dnn::pfCand_gamma_hasTrackDetails + fill_index_offset_PFg) =
1574 sp.scale(hasTrackDetails, dnn::pfCand_gamma_hasTrackDetails - PFg_index_offset);
1575 get(dnn::pfCand_gamma_dxy + fill_index_offset_PFg) =
1576 sp.scale(candFunc::getTauDxy(gamma_cand), dnn::pfCand_gamma_dxy - PFg_index_offset);
1577 get(dnn::pfCand_gamma_dxy_sig + fill_index_offset_PFg) =
1578 sp.scale(
std::abs(candFunc::getTauDxy(gamma_cand)) / gamma_cand.dxyError(),
1579 dnn::pfCand_gamma_dxy_sig - PFg_index_offset);
1580 get(dnn::pfCand_gamma_dz + fill_index_offset_PFg) =
1581 sp.scale(candFunc::getTauDz(gamma_cand), dnn::pfCand_gamma_dz - PFg_index_offset);
1582 get(dnn::pfCand_gamma_dz_sig + fill_index_offset_PFg) =
1583 sp.scale(
std::abs(candFunc::getTauDz(gamma_cand)) / gamma_cand.dzError(),
1584 dnn::pfCand_gamma_dz_sig - PFg_index_offset);
1585 get(dnn::pfCand_gamma_track_chi2_ndof + fill_index_offset_PFg) =
1586 candFunc::getPseudoTrack(gamma_cand).ndof() > 0
1587 ? sp.scale(candFunc::getPseudoTrack(gamma_cand).
chi2() / candFunc::getPseudoTrack(gamma_cand).
ndof(),
1588 dnn::pfCand_gamma_track_chi2_ndof - PFg_index_offset)
1590 get(dnn::pfCand_gamma_track_ndof + fill_index_offset_PFg) =
1591 candFunc::getPseudoTrack(gamma_cand).ndof() > 0
1592 ? sp.scale(candFunc::getPseudoTrack(gamma_cand).
ndof(), dnn::pfCand_gamma_track_ndof - PFg_index_offset)
1596 if (valid_index_ele) {
1597 const sc::ScalingParams& sp =
scalingParamsMap_->at(std::make_pair(ft_e, is_inner));
1599 const auto& ele =
electrons->at(index_ele);
1601 get(dnn::ele_valid + fill_index_offset_e) = sp.scale(valid_index_ele, dnn::ele_valid - e_index_offset);
1602 get(dnn::ele_rel_pt + fill_index_offset_e) =
1603 sp.scale(ele.polarP4().pt() /
tau.polarP4().pt(), dnn::ele_rel_pt - e_index_offset);
1604 get(dnn::ele_deta + fill_index_offset_e) =
1605 sp.scale(ele.polarP4().eta() -
tau.polarP4().eta(), dnn::ele_deta - e_index_offset);
1606 get(dnn::ele_dphi + fill_index_offset_e) =
1607 sp.scale(
dPhi(
tau.polarP4(), ele.polarP4()), dnn::ele_dphi - e_index_offset);
1609 float cc_ele_energy, cc_gamma_energy;
1613 get(dnn::ele_cc_valid + fill_index_offset_e) = sp.scale(cc_valid, dnn::ele_cc_valid - e_index_offset);
1614 get(dnn::ele_cc_ele_rel_energy + fill_index_offset_e) =
1615 sp.scale(cc_ele_energy / ele.polarP4().pt(), dnn::ele_cc_ele_rel_energy - e_index_offset);
1616 get(dnn::ele_cc_gamma_rel_energy + fill_index_offset_e) =
1617 sp.scale(cc_gamma_energy / cc_ele_energy, dnn::ele_cc_gamma_rel_energy - e_index_offset);
1618 get(dnn::ele_cc_n_gamma + fill_index_offset_e) = sp.scale(cc_n_gamma, dnn::ele_cc_n_gamma - e_index_offset);
1620 get(dnn::ele_rel_trackMomentumAtVtx + fill_index_offset_e) =
1621 sp.scale(ele.trackMomentumAtVtx().R() / ele.polarP4().pt(), dnn::ele_rel_trackMomentumAtVtx - e_index_offset);
1622 get(dnn::ele_rel_trackMomentumAtCalo + fill_index_offset_e) = sp.scale(
1623 ele.trackMomentumAtCalo().R() / ele.polarP4().pt(), dnn::ele_rel_trackMomentumAtCalo - e_index_offset);
1624 get(dnn::ele_rel_trackMomentumOut + fill_index_offset_e) =
1625 sp.scale(ele.trackMomentumOut().R() / ele.polarP4().pt(), dnn::ele_rel_trackMomentumOut - e_index_offset);
1626 get(dnn::ele_rel_trackMomentumAtEleClus + fill_index_offset_e) = sp.scale(
1627 ele.trackMomentumAtEleClus().R() / ele.polarP4().pt(), dnn::ele_rel_trackMomentumAtEleClus - e_index_offset);
1628 get(dnn::ele_rel_trackMomentumAtVtxWithConstraint + fill_index_offset_e) =
1629 sp.scale(ele.trackMomentumAtVtxWithConstraint().R() / ele.polarP4().pt(),
1630 dnn::ele_rel_trackMomentumAtVtxWithConstraint - e_index_offset);
1631 get(dnn::ele_rel_ecalEnergy + fill_index_offset_e) =
1632 sp.scale(ele.ecalEnergy() / ele.polarP4().pt(), dnn::ele_rel_ecalEnergy - e_index_offset);
1633 get(dnn::ele_ecalEnergy_sig + fill_index_offset_e) =
1634 sp.scale(ele.ecalEnergy() / ele.ecalEnergyError(), dnn::ele_ecalEnergy_sig - e_index_offset);
1635 get(dnn::ele_eSuperClusterOverP + fill_index_offset_e) =
1636 sp.scale(ele.eSuperClusterOverP(), dnn::ele_eSuperClusterOverP - e_index_offset);
1637 get(dnn::ele_eSeedClusterOverP + fill_index_offset_e) =
1638 sp.scale(ele.eSeedClusterOverP(), dnn::ele_eSeedClusterOverP - e_index_offset);
1639 get(dnn::ele_eSeedClusterOverPout + fill_index_offset_e) =
1640 sp.scale(ele.eSeedClusterOverPout(), dnn::ele_eSeedClusterOverPout - e_index_offset);
1641 get(dnn::ele_eEleClusterOverPout + fill_index_offset_e) =
1642 sp.scale(ele.eEleClusterOverPout(), dnn::ele_eEleClusterOverPout - e_index_offset);
1643 get(dnn::ele_deltaEtaSuperClusterTrackAtVtx + fill_index_offset_e) =
1644 sp.scale(ele.deltaEtaSuperClusterTrackAtVtx(), dnn::ele_deltaEtaSuperClusterTrackAtVtx - e_index_offset);
1645 get(dnn::ele_deltaEtaSeedClusterTrackAtCalo + fill_index_offset_e) =
1646 sp.scale(ele.deltaEtaSeedClusterTrackAtCalo(), dnn::ele_deltaEtaSeedClusterTrackAtCalo - e_index_offset);
1647 get(dnn::ele_deltaEtaEleClusterTrackAtCalo + fill_index_offset_e) =
1648 sp.scale(ele.deltaEtaEleClusterTrackAtCalo(), dnn::ele_deltaEtaEleClusterTrackAtCalo - e_index_offset);
1649 get(dnn::ele_deltaPhiEleClusterTrackAtCalo + fill_index_offset_e) =
1650 sp.scale(ele.deltaPhiEleClusterTrackAtCalo(), dnn::ele_deltaPhiEleClusterTrackAtCalo - e_index_offset);
1651 get(dnn::ele_deltaPhiSuperClusterTrackAtVtx + fill_index_offset_e) =
1652 sp.scale(ele.deltaPhiSuperClusterTrackAtVtx(), dnn::ele_deltaPhiSuperClusterTrackAtVtx - e_index_offset);
1653 get(dnn::ele_deltaPhiSeedClusterTrackAtCalo + fill_index_offset_e) =
1654 sp.scale(ele.deltaPhiSeedClusterTrackAtCalo(), dnn::ele_deltaPhiSeedClusterTrackAtCalo - e_index_offset);
1655 const bool mva_valid =
1656 (ele.mvaInput().earlyBrem > -2) ||
1660 get(dnn::ele_mvaInput_earlyBrem + fill_index_offset_e) =
1661 sp.scale(ele.mvaInput().earlyBrem, dnn::ele_mvaInput_earlyBrem - e_index_offset);
1662 get(dnn::ele_mvaInput_lateBrem + fill_index_offset_e) =
1663 sp.scale(ele.mvaInput().lateBrem, dnn::ele_mvaInput_lateBrem - e_index_offset);
1664 get(dnn::ele_mvaInput_sigmaEtaEta + fill_index_offset_e) =
1665 sp.scale(ele.mvaInput().sigmaEtaEta, dnn::ele_mvaInput_sigmaEtaEta - e_index_offset);
1666 get(dnn::ele_mvaInput_hadEnergy + fill_index_offset_e) =
1667 sp.scale(ele.mvaInput().hadEnergy, dnn::ele_mvaInput_hadEnergy - e_index_offset);
1668 get(dnn::ele_mvaInput_deltaEta + fill_index_offset_e) =
1669 sp.scale(ele.mvaInput().deltaEta, dnn::ele_mvaInput_deltaEta - e_index_offset);
1671 const auto& gsfTrack = ele.gsfTrack();
1672 if (gsfTrack.isNonnull()) {
1673 get(dnn::ele_gsfTrack_normalizedChi2 + fill_index_offset_e) =
1674 sp.scale(gsfTrack->normalizedChi2(), dnn::ele_gsfTrack_normalizedChi2 - e_index_offset);
1675 get(dnn::ele_gsfTrack_numberOfValidHits + fill_index_offset_e) =
1676 sp.scale(gsfTrack->numberOfValidHits(), dnn::ele_gsfTrack_numberOfValidHits - e_index_offset);
1677 get(dnn::ele_rel_gsfTrack_pt + fill_index_offset_e) =
1678 sp.scale(gsfTrack->pt() / ele.polarP4().pt(), dnn::ele_rel_gsfTrack_pt - e_index_offset);
1679 get(dnn::ele_gsfTrack_pt_sig + fill_index_offset_e) =
1680 sp.scale(gsfTrack->pt() / gsfTrack->ptError(), dnn::ele_gsfTrack_pt_sig - e_index_offset);
1682 const auto& closestCtfTrack = ele.closestCtfTrackRef();
1683 const bool has_closestCtfTrack = closestCtfTrack.isNonnull();
1684 if (has_closestCtfTrack) {
1685 get(dnn::ele_has_closestCtfTrack + fill_index_offset_e) =
1686 sp.scale(has_closestCtfTrack, dnn::ele_has_closestCtfTrack - e_index_offset);
1687 get(dnn::ele_closestCtfTrack_normalizedChi2 + fill_index_offset_e) =
1688 sp.scale(closestCtfTrack->normalizedChi2(), dnn::ele_closestCtfTrack_normalizedChi2 - e_index_offset);
1689 get(dnn::ele_closestCtfTrack_numberOfValidHits + fill_index_offset_e) =
1690 sp.scale(closestCtfTrack->numberOfValidHits(), dnn::ele_closestCtfTrack_numberOfValidHits - e_index_offset);
1695 template <
typename Cand
idateCastType,
typename TauCastType,
typename MuonBlockType>
1697 const TauCastType&
tau,
1698 const size_t tau_index,
1702 const std::vector<pat::Muon>*
muons,
1704 const Cell& cell_map,
1707 MuonBlockType& muonBlockInputs) {
1711 using MuonHitMatchV2 = MuonHitMatchV2;
1717 int PFmu_index_offset =
scalingParamsMap_->at(std::make_pair(ft_global,
false)).mean_.size();
1718 int mu_index_offset = PFmu_index_offset +
scalingParamsMap_->at(std::make_pair(ft_PFmu,
false)).mean_.size();
1720 const auto&
get = [&](
int var_index) ->
float& {
1721 if constexpr (std::is_same_v<MuonBlockType, std::vector<float>::iterator>) {
1722 return *(muonBlockInputs + var_index);
1724 return ((tensorflow::Tensor)muonBlockInputs).tensor<float, 4>()(
idx, 0, 0, var_index);
1728 const bool valid_index_pf_muon = cell_map.count(CellObjectType::PfCand_muon);
1731 if (!cell_map.empty()) {
1732 const sc::ScalingParams& sp =
scalingParamsMap_->at(std::make_pair(ft_global,
false));
1736 get(dnn::tau_inside_ecal_crack) = sp.scale(
isInEcalCrack(
tau.polarP4().eta()), dnn::tau_inside_ecal_crack);
1738 if (valid_index_pf_muon) {
1739 const sc::ScalingParams& sp =
scalingParamsMap_->at(std::make_pair(ft_PFmu, is_inner));
1740 size_t index_pf_muon = cell_map.at(CellObjectType::PfCand_muon);
1741 const auto& muon_cand =
dynamic_cast<const CandidateCastType&
>(pfCands.
at(index_pf_muon));
1743 get(dnn::pfCand_muon_valid) = sp.scale(valid_index_pf_muon, dnn::pfCand_muon_valid - PFmu_index_offset);
1744 get(dnn::pfCand_muon_rel_pt) =
1745 sp.scale(muon_cand.polarP4().pt() /
tau.polarP4().pt(), dnn::pfCand_muon_rel_pt - PFmu_index_offset);
1746 get(dnn::pfCand_muon_deta) =
1747 sp.scale(muon_cand.polarP4().eta() -
tau.polarP4().eta(), dnn::pfCand_muon_deta - PFmu_index_offset);
1748 get(dnn::pfCand_muon_dphi) =
1749 sp.scale(
dPhi(
tau.polarP4(), muon_cand.polarP4()), dnn::pfCand_muon_dphi - PFmu_index_offset);
1750 get(dnn::pfCand_muon_pvAssociationQuality) = sp.scale<
int>(
1751 candFunc::getPvAssocationQuality(muon_cand), dnn::pfCand_muon_pvAssociationQuality - PFmu_index_offset);
1752 get(dnn::pfCand_muon_fromPV) =
1753 sp.scale<
int>(candFunc::getFromPV(muon_cand), dnn::pfCand_muon_fromPV - PFmu_index_offset);
1754 get(dnn::pfCand_muon_puppiWeight) = is_inner ? sp.scale(candFunc::getPuppiWeight(muon_cand, 0.9786588f),
1755 dnn::pfCand_muon_puppiWeight - PFmu_index_offset)
1756 : sp.scale(candFunc::getPuppiWeight(muon_cand, 0.8132477
f),
1757 dnn::pfCand_muon_puppiWeight - PFmu_index_offset);
1758 get(dnn::pfCand_muon_charge) = sp.scale(muon_cand.charge(), dnn::pfCand_muon_charge - PFmu_index_offset);
1759 get(dnn::pfCand_muon_lostInnerHits) =
1760 sp.scale<
int>(candFunc::getLostInnerHits(muon_cand, 0), dnn::pfCand_muon_lostInnerHits - PFmu_index_offset);
1761 get(dnn::pfCand_muon_numberOfPixelHits) = sp.scale(candFunc::getNumberOfPixelHits(muon_cand, 0),
1762 dnn::pfCand_muon_numberOfPixelHits - PFmu_index_offset);
1763 get(dnn::pfCand_muon_vertex_dx) =
1764 sp.scale(muon_cand.vertex().x() -
pv.position().x(), dnn::pfCand_muon_vertex_dx - PFmu_index_offset);
1765 get(dnn::pfCand_muon_vertex_dy) =
1766 sp.scale(muon_cand.vertex().y() -
pv.position().y(), dnn::pfCand_muon_vertex_dy - PFmu_index_offset);
1767 get(dnn::pfCand_muon_vertex_dz) =
1768 sp.scale(muon_cand.vertex().z() -
pv.position().z(), dnn::pfCand_muon_vertex_dz - PFmu_index_offset);
1769 get(dnn::pfCand_muon_vertex_dx_tauFL) =
1770 sp.scale(muon_cand.vertex().x() -
pv.position().x() - tau_funcs.getFlightLength(
tau, tau_index).x(),
1771 dnn::pfCand_muon_vertex_dx_tauFL - PFmu_index_offset);
1772 get(dnn::pfCand_muon_vertex_dy_tauFL) =
1773 sp.scale(muon_cand.vertex().y() -
pv.position().y() - tau_funcs.getFlightLength(
tau, tau_index).y(),
1774 dnn::pfCand_muon_vertex_dy_tauFL - PFmu_index_offset);
1775 get(dnn::pfCand_muon_vertex_dz_tauFL) =
1776 sp.scale(muon_cand.vertex().z() -
pv.position().z() - tau_funcs.getFlightLength(
tau, tau_index).z(),
1777 dnn::pfCand_muon_vertex_dz_tauFL - PFmu_index_offset);
1779 const bool hasTrackDetails = candFunc::getHasTrackDetails(muon_cand);
1780 if (hasTrackDetails) {
1781 get(dnn::pfCand_muon_hasTrackDetails) =
1782 sp.scale(hasTrackDetails, dnn::pfCand_muon_hasTrackDetails - PFmu_index_offset);
1783 get(dnn::pfCand_muon_dxy) = sp.scale(candFunc::getTauDxy(muon_cand), dnn::pfCand_muon_dxy - PFmu_index_offset);
1784 get(dnn::pfCand_muon_dxy_sig) = sp.scale(
std::abs(candFunc::getTauDxy(muon_cand)) / muon_cand.dxyError(),
1785 dnn::pfCand_muon_dxy_sig - PFmu_index_offset);
1786 get(dnn::pfCand_muon_dz) = sp.scale(candFunc::getTauDz(muon_cand), dnn::pfCand_muon_dz - PFmu_index_offset);
1787 get(dnn::pfCand_muon_dz_sig) = sp.scale(
std::abs(candFunc::getTauDz(muon_cand)) / muon_cand.dzError(),
1788 dnn::pfCand_muon_dz_sig - PFmu_index_offset);
1789 get(dnn::pfCand_muon_track_chi2_ndof) =
1790 candFunc::getPseudoTrack(muon_cand).ndof() > 0
1791 ? sp.scale(candFunc::getPseudoTrack(muon_cand).
chi2() / candFunc::getPseudoTrack(muon_cand).
ndof(),
1792 dnn::pfCand_muon_track_chi2_ndof - PFmu_index_offset)
1794 get(dnn::pfCand_muon_track_ndof) =
1795 candFunc::getPseudoTrack(muon_cand).ndof() > 0
1796 ? sp.scale(candFunc::getPseudoTrack(muon_cand).
ndof(), dnn::pfCand_muon_track_ndof - PFmu_index_offset)
1800 if (valid_index_muon) {
1801 const sc::ScalingParams& sp =
scalingParamsMap_->at(std::make_pair(ft_mu, is_inner));
1803 const auto&
muon =
muons->at(index_muon);
1805 get(dnn::muon_valid) = sp.scale(valid_index_muon, dnn::muon_valid - mu_index_offset);
1806 get(dnn::muon_rel_pt) = sp.scale(
muon.polarP4().pt() /
tau.polarP4().pt(), dnn::muon_rel_pt - mu_index_offset);
1807 get(dnn::muon_deta) = sp.scale(
muon.polarP4().eta() -
tau.polarP4().eta(), dnn::muon_deta - mu_index_offset);
1808 get(dnn::muon_dphi) = sp.scale(
dPhi(
tau.polarP4(),
muon.polarP4()), dnn::muon_dphi - mu_index_offset);
1810 get(dnn::muon_dxy_sig) =
1813 const bool normalizedChi2_valid =
muon.globalTrack().isNonnull() &&
muon.normChi2() >= 0;
1814 if (normalizedChi2_valid) {
1815 get(dnn::muon_normalizedChi2_valid) =
1816 sp.scale(normalizedChi2_valid, dnn::muon_normalizedChi2_valid - mu_index_offset);
1817 get(dnn::muon_normalizedChi2) = sp.scale(
muon.normChi2(), dnn::muon_normalizedChi2 - mu_index_offset);
1818 if (
muon.innerTrack().isNonnull())
1819 get(dnn::muon_numberOfValidHits) =
1820 sp.scale(
muon.numberOfValidHits(), dnn::muon_numberOfValidHits - mu_index_offset);
1822 get(dnn::muon_segmentCompatibility) =
1823 sp.scale(
muon.segmentCompatibility(), dnn::muon_segmentCompatibility - mu_index_offset);
1824 get(dnn::muon_caloCompatibility) =
1825 sp.scale(
muon.caloCompatibility(), dnn::muon_caloCompatibility - mu_index_offset);
1827 const bool pfEcalEnergy_valid =
muon.pfEcalEnergy() >= 0;
1828 if (pfEcalEnergy_valid) {
1829 get(dnn::muon_pfEcalEnergy_valid) =
1830 sp.scale(pfEcalEnergy_valid, dnn::muon_pfEcalEnergy_valid - mu_index_offset);
1831 get(dnn::muon_rel_pfEcalEnergy) =
1832 sp.scale(
muon.pfEcalEnergy() /
muon.polarP4().pt(), dnn::muon_rel_pfEcalEnergy - mu_index_offset);
1835 MuonHitMatchV2 hit_match(
muon);
1836 static const std::map<int, std::pair<int, int>> muonMatchHitVars = {
1841 for (
int subdet : hit_match.MuonHitMatchV2::consideredSubdets()) {
1842 const auto& matchHitVar = muonMatchHitVars.at(subdet);
1843 for (
int station = MuonHitMatchV2::first_station_id;
station <= MuonHitMatchV2::last_station_id; ++
station) {
1844 const unsigned n_matches = hit_match.nMatches(subdet,
station);
1845 const unsigned n_hits = hit_match.nHits(subdet,
station);
1846 get(matchHitVar.first +
station - 1) = sp.scale(n_matches, matchHitVar.first +
station - 1 - mu_index_offset);
1847 get(matchHitVar.second +
station - 1) = sp.scale(n_hits, matchHitVar.second +
station - 1 - mu_index_offset);
1853 template <
typename Cand
idateCastType,
typename TauCastType,
typename HadronBlockType>
1855 const TauCastType&
tau,
1856 const size_t tau_index,
1861 const Cell& cell_map,
1864 HadronBlockType& hadronBlockInputs) {
1873 int PFchH_index_offset =
scalingParamsMap_->at(std::make_pair(ft_global,
false)).mean_.size();
1874 int PFnH_index_offset = PFchH_index_offset +
scalingParamsMap_->at(std::make_pair(ft_PFchH,
false)).mean_.size();
1876 const auto&
get = [&](
int var_index) ->
float& {
1877 if constexpr (std::is_same_v<HadronBlockType, std::vector<float>::iterator>) {
1878 return *(hadronBlockInputs + var_index);
1880 return ((tensorflow::Tensor)hadronBlockInputs).tensor<float, 4>()(
idx, 0, 0, var_index);
1884 const bool valid_chH = cell_map.count(CellObjectType::PfCand_chargedHadron);
1885 const bool valid_nH = cell_map.count(CellObjectType::PfCand_neutralHadron);
1887 if (!cell_map.empty()) {
1888 const sc::ScalingParams& sp =
scalingParamsMap_->at(std::make_pair(ft_global,
false));
1892 get(dnn::tau_inside_ecal_crack) = sp.scale(
isInEcalCrack(
tau.polarP4().eta()), dnn::tau_inside_ecal_crack);
1895 const sc::ScalingParams& sp =
scalingParamsMap_->at(std::make_pair(ft_PFchH, is_inner));
1896 size_t index_chH = cell_map.at(CellObjectType::PfCand_chargedHadron);
1897 const auto& chH_cand =
dynamic_cast<const CandidateCastType&
>(pfCands.
at(index_chH));
1899 get(dnn::pfCand_chHad_valid) = sp.scale(valid_chH, dnn::pfCand_chHad_valid - PFchH_index_offset);
1900 get(dnn::pfCand_chHad_rel_pt) =
1901 sp.scale(chH_cand.polarP4().pt() /
tau.polarP4().pt(), dnn::pfCand_chHad_rel_pt - PFchH_index_offset);
1902 get(dnn::pfCand_chHad_deta) =
1903 sp.scale(chH_cand.polarP4().eta() -
tau.polarP4().eta(), dnn::pfCand_chHad_deta - PFchH_index_offset);
1904 get(dnn::pfCand_chHad_dphi) =
1905 sp.scale(
dPhi(
tau.polarP4(), chH_cand.polarP4()), dnn::pfCand_chHad_dphi - PFchH_index_offset);
1906 get(dnn::pfCand_chHad_leadChargedHadrCand) =
1907 sp.scale(&chH_cand == dynamic_cast<const CandidateCastType*>(
tau.leadChargedHadrCand().get()),
1908 dnn::pfCand_chHad_leadChargedHadrCand - PFchH_index_offset);
1909 get(dnn::pfCand_chHad_pvAssociationQuality) = sp.scale<
int>(
1910 candFunc::getPvAssocationQuality(chH_cand), dnn::pfCand_chHad_pvAssociationQuality - PFchH_index_offset);
1911 get(dnn::pfCand_chHad_fromPV) =
1912 sp.scale<
int>(candFunc::getFromPV(chH_cand), dnn::pfCand_chHad_fromPV - PFchH_index_offset);
1913 const float default_chH_pw_inner = 0.7614090f;
1914 const float default_chH_pw_outer = 0.1974930f;
1915 get(dnn::pfCand_chHad_puppiWeight) = is_inner ? sp.scale(candFunc::getPuppiWeight(chH_cand, default_chH_pw_inner),
1916 dnn::pfCand_chHad_puppiWeight - PFchH_index_offset)
1917 : sp.scale(candFunc::getPuppiWeight(chH_cand, default_chH_pw_outer),
1918 dnn::pfCand_chHad_puppiWeight - PFchH_index_offset);
1919 get(dnn::pfCand_chHad_puppiWeightNoLep) =
1920 is_inner ? sp.scale(candFunc::getPuppiWeightNoLep(chH_cand, default_chH_pw_inner),
1921 dnn::pfCand_chHad_puppiWeightNoLep - PFchH_index_offset)
1922 : sp.scale(candFunc::getPuppiWeightNoLep(chH_cand, default_chH_pw_outer),
1923 dnn::pfCand_chHad_puppiWeightNoLep - PFchH_index_offset);
1924 get(dnn::pfCand_chHad_charge) = sp.scale(chH_cand.charge(), dnn::pfCand_chHad_charge - PFchH_index_offset);
1925 get(dnn::pfCand_chHad_lostInnerHits) =
1926 sp.scale<
int>(candFunc::getLostInnerHits(chH_cand, 0), dnn::pfCand_chHad_lostInnerHits - PFchH_index_offset);
1927 get(dnn::pfCand_chHad_numberOfPixelHits) = sp.scale(candFunc::getNumberOfPixelHits(chH_cand, 0),
1928 dnn::pfCand_chHad_numberOfPixelHits - PFchH_index_offset);
1929 get(dnn::pfCand_chHad_vertex_dx) =
1930 sp.scale(chH_cand.vertex().x() -
pv.position().x(), dnn::pfCand_chHad_vertex_dx - PFchH_index_offset);
1931 get(dnn::pfCand_chHad_vertex_dy) =
1932 sp.scale(chH_cand.vertex().y() -
pv.position().y(), dnn::pfCand_chHad_vertex_dy - PFchH_index_offset);
1933 get(dnn::pfCand_chHad_vertex_dz) =
1934 sp.scale(chH_cand.vertex().z() -
pv.position().z(), dnn::pfCand_chHad_vertex_dz - PFchH_index_offset);
1935 get(dnn::pfCand_chHad_vertex_dx_tauFL) =
1936 sp.scale(chH_cand.vertex().x() -
pv.position().x() - tau_funcs.getFlightLength(
tau, tau_index).x(),
1937 dnn::pfCand_chHad_vertex_dx_tauFL - PFchH_index_offset);
1938 get(dnn::pfCand_chHad_vertex_dy_tauFL) =
1939 sp.scale(chH_cand.vertex().y() -
pv.position().y() - tau_funcs.getFlightLength(
tau, tau_index).y(),
1940 dnn::pfCand_chHad_vertex_dy_tauFL - PFchH_index_offset);
1941 get(dnn::pfCand_chHad_vertex_dz_tauFL) =
1942 sp.scale(chH_cand.vertex().z() -
pv.position().z() - tau_funcs.getFlightLength(
tau, tau_index).z(),
1943 dnn::pfCand_chHad_vertex_dz_tauFL - PFchH_index_offset);
1945 const bool hasTrackDetails = candFunc::getHasTrackDetails(chH_cand);
1946 if (hasTrackDetails) {
1947 get(dnn::pfCand_chHad_hasTrackDetails) =
1948 sp.scale(hasTrackDetails, dnn::pfCand_chHad_hasTrackDetails - PFchH_index_offset);
1949 get(dnn::pfCand_chHad_dxy) =
1950 sp.scale(candFunc::getTauDxy(chH_cand), dnn::pfCand_chHad_dxy - PFchH_index_offset);
1951 get(dnn::pfCand_chHad_dxy_sig) = sp.scale(
std::abs(candFunc::getTauDxy(chH_cand)) / chH_cand.dxyError(),
1952 dnn::pfCand_chHad_dxy_sig - PFchH_index_offset);
1953 get(dnn::pfCand_chHad_dz) = sp.scale(candFunc::getTauDz(chH_cand), dnn::pfCand_chHad_dz - PFchH_index_offset);
1954 get(dnn::pfCand_chHad_dz_sig) = sp.scale(
std::abs(candFunc::getTauDz(chH_cand)) / chH_cand.dzError(),
1955 dnn::pfCand_chHad_dz_sig - PFchH_index_offset);
1956 get(dnn::pfCand_chHad_track_chi2_ndof) =
1957 candFunc::getPseudoTrack(chH_cand).ndof() > 0
1958 ? sp.scale(candFunc::getPseudoTrack(chH_cand).
chi2() / candFunc::getPseudoTrack(chH_cand).
ndof(),
1959 dnn::pfCand_chHad_track_chi2_ndof - PFchH_index_offset)
1961 get(dnn::pfCand_chHad_track_ndof) =
1962 candFunc::getPseudoTrack(chH_cand).ndof() > 0
1963 ? sp.scale(candFunc::getPseudoTrack(chH_cand).
ndof(), dnn::pfCand_chHad_track_ndof - PFchH_index_offset)
1967 get(dnn::pfCand_chHad_hcalFraction) =
1968 sp.scale(hcal_fraction, dnn::pfCand_chHad_hcalFraction - PFchH_index_offset);
1969 get(dnn::pfCand_chHad_rawCaloFraction) =
1970 sp.scale(candFunc::getRawCaloFraction(chH_cand), dnn::pfCand_chHad_rawCaloFraction - PFchH_index_offset);
1973 const sc::ScalingParams& sp =
scalingParamsMap_->at(std::make_pair(ft_PFnH, is_inner));
1974 size_t index_nH = cell_map.at(CellObjectType::PfCand_neutralHadron);
1975 const auto& nH_cand =
dynamic_cast<const CandidateCastType&
>(pfCands.
at(index_nH));
1977 get(dnn::pfCand_nHad_valid) = sp.scale(valid_nH, dnn::pfCand_nHad_valid - PFnH_index_offset);
1978 get(dnn::pfCand_nHad_rel_pt) =
1979 sp.scale(nH_cand.polarP4().pt() /
tau.polarP4().pt(), dnn::pfCand_nHad_rel_pt - PFnH_index_offset);
1980 get(dnn::pfCand_nHad_deta) =
1981 sp.scale(nH_cand.polarP4().eta() -
tau.polarP4().eta(), dnn::pfCand_nHad_deta - PFnH_index_offset);
1982 get(dnn::pfCand_nHad_dphi) =
1983 sp.scale(
dPhi(
tau.polarP4(), nH_cand.polarP4()), dnn::pfCand_nHad_dphi - PFnH_index_offset);
1984 get(dnn::pfCand_nHad_puppiWeight) = is_inner ? sp.scale(candFunc::getPuppiWeight(nH_cand, 0.9798355f),
1985 dnn::pfCand_nHad_puppiWeight - PFnH_index_offset)
1986 : sp.scale(candFunc::getPuppiWeight(nH_cand, 0.7813260
f),
1987 dnn::pfCand_nHad_puppiWeight - PFnH_index_offset);
1988 get(dnn::pfCand_nHad_puppiWeightNoLep) = is_inner
1989 ? sp.scale(candFunc::getPuppiWeightNoLep(nH_cand, 0.9046796f),
1990 dnn::pfCand_nHad_puppiWeightNoLep - PFnH_index_offset)
1991 : sp.scale(candFunc::getPuppiWeightNoLep(nH_cand, 0.6554860
f),
1992 dnn::pfCand_nHad_puppiWeightNoLep - PFnH_index_offset);
1994 get(dnn::pfCand_nHad_hcalFraction) = sp.scale(hcal_fraction, dnn::pfCand_nHad_hcalFraction - PFnH_index_offset);
2000 elecEe = elecEgamma = 0;
2002 if (superCluster.isNonnull() && superCluster.isAvailable() && superCluster->clusters().isNonnull() &&
2003 superCluster->clusters().isAvailable()) {
2004 for (
auto iter = superCluster->clustersBegin(); iter != superCluster->clustersEnd(); ++iter) {
2005 const double energy = (*iter)->energy();
2006 if (iter == superCluster->clustersBegin())
2017 template <
typename Cand
idateCollection,
typename TauCastType>
2040 const bool isInside_innerSigCone =
dR < innerSigCone_radius;
2041 if (isInside_innerSigCone) {
2042 p4_inner +=
cand->p4();
2045 p4_outer +=
cand->p4();
2061 template <
typename Cand
idateCollection,
typename TauCastType>
2085 static constexpr double min_pt = 30., min_radius = 0.05, cone_opening_coef = 3.;
2091 template <
typename TauCastType>
2093 const size_t tau_index,
2095 TauFunc tau_funcs) {
2096 if (tau_funcs.getHasSecondaryVertex(
tau, tau_index)) {
2098 const double mAOne =
tau.p4().M();
2099 const double pAOneMag =
tau.p();
2100 const double argumentThetaGJmax = (
std::pow(mTau, 2) -
std::pow(mAOne, 2)) / (2 * mTau * pAOneMag);
2101 const double argumentThetaGJmeasured =
tau.p4().Vect().Dot(tau_funcs.getFlightLength(
tau, tau_index)) /
2102 (pAOneMag * tau_funcs.getFlightLength(
tau, tau_index).R());
2103 if (
std::abs(argumentThetaGJmax) <= 1. &&
std::abs(argumentThetaGJmeasured) <= 1.) {
2104 double thetaGJmax = std::asin(argumentThetaGJmax);
2105 double thetaGJmeasured = std::acos(argumentThetaGJmeasured);
2106 gj_diff = thetaGJmeasured - thetaGJmax;
2113 template <
typename TauCastType>
2115 const size_t tau_index,
2116 TauFunc tau_funcs) {
2119 return static_cast<float>(gj_diff);
2125 return abs_eta > 1.46 && abs_eta < 1.558;
2128 template <
typename TauCastType>
2130 const std::vector<pat::Electron>*
electrons,
edm::EDGetTokenT< std::vector< pat::Electron > > electrons_token_
std::vector< TauDiscInfo< pat::PATTauDiscriminator > > patPrediscriminants_
constexpr double deltaPhi(double phi1, double phi2)
const std::map< std::pair< deep_tau::Scaling::FeatureT, bool >, deep_tau::Scaling::ScalingParams > * scalingParamsMap_
unsigned int n_photons_total(const reco::PFTau &tau)
return total number of pf photon candidates with pT>500 MeV, which are associated to signal ...
T getParameter(std::string const &) const
std::vector< int > tauInputs_indices_
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
std::vector< size_t > num_
edm::EDGetTokenT< ConsumeType > disc_token
double pt() const final
transverse momentum
static bool isInEcalCrack(double eta)
edm::EDGetTokenT< double > rho_token_
float pt_weighted_dr_signal(const reco::PFTau &tau, int dm)
bool operator<(IOVSyncValue const &iLHS, IOVSyncValue const &iRHS)
static const IDOutputCollection & GetIDOutputs()
std::map< BasicDiscriminator, size_t > basicDiscrIndexMap_
float read_value(const std::vector< std::vector< float >> &pred, size_t tau_index, size_t elem) const
std::unique_ptr< Cutter > CutterPtr
static void processSignalPFComponents(const TauCastType &tau, const CandidateCollection &candidates, LorentzVectorXYZ &p4_inner, LorentzVectorXYZ &p4_outer, float &pt_inner, float &dEta_inner, float &dPhi_inner, float &m_inner, float &pt_outer, float &dEta_outer, float &dPhi_outer, float &m_outer, float &n_inner, float &n_outer)
disable_CellIndex_workaround
const std::vector< BasicDiscriminator > requiredBasicDiscriminators_
std::string output_layer_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
std::unique_ptr< TauDiscriminator > get_value(const edm::Handle< TauCollection > &taus, const PredType &pred, const WPList *working_points, bool is_online) const
reco::SuperClusterRef superCluster() const override
override the reco::GsfElectron::superCluster method, to access the internal storage of the superclust...
void countMatches(const reco::Muon &muon, std::vector< int > &numMatchesDT, std::vector< int > &numMatchesCSC, std::vector< int > &numMatchesRPC)
static float calculateGottfriedJacksonAngleDifference(const TauCastType &tau, const size_t tau_index, TauFunc tau_funcs)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
static bool calculateElectronClusterVarsV2(const pat::Electron &ele, float &cc_ele_energy, float &cc_gamma_energy, int &cc_n_gamma)
std::vector< Vertex > VertexCollection
edm::RefProd< PFTauCollection > PFTauRefProd
references to PFTau collection
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
const std::map< ValueQuantityType, double > min_value
ParameterSet const & parameterSet(StableProvenance const &provenance, ProcessHistory const &history)
static constexpr float default_value
void createEgammaBlockInputs(unsigned idx, const TauCastType &tau, const size_t tau_index, const edm::RefToBase< reco::BaseTau > tau_ref, const reco::Vertex &pv, double rho, const std::vector< pat::Electron > *electrons, const edm::View< reco::Candidate > &pfCands, const Cell &cell_map, TauFunc tau_funcs, bool is_inner, EgammaBlockType &egammaBlockInputs)
static float getValue(T value)
static const double deltaEta
edm::Handle< ConsumeType > handle
static bool isAbove(double value, double min)
static bool calculateGottfriedJacksonAngleDifference(const TauCastType &tau, const size_t tau_index, double &gj_diff, TauFunc tau_funcs)
static void processIsolationPFComponents(const TauCastType &tau, const CandidateCollection &candidates, LorentzVectorXYZ &p4, float &pt, float &d_eta, float &d_phi, float &m, float &n)
uint8_t andPrediscriminants_
edm::EDGetTokenT< CandidateCollection > pfcandToken_
const std::map< std::pair< FeatureT, bool >, ScalingParams > scalingParamsMap_v2p5
edm::EDGetTokenT< std::vector< pat::Muon > > muons_token_
static void fillDescriptionsHelper(edm::ParameterSetDescription &desc)
const bool disable_hcalFraction_workaround_
ALPAKA_FN_ACC static ALPAKA_FN_INLINE float dR2(Position4 pos1, Position4 pos2)
std::vector< Electron > ElectronCollection
static float getValueNorm(T value, float mean, float sigma, float n_sigmas_max=5)
float pt_weighted_deta_strip(const reco::PFTau &tau, int dm)
static double getInnerSignalConeRadius(double pt)
const std::map< BasicDiscriminator, std::string > stringFromDiscriminator_
edm::EDGetTokenT< reco::TauDiscriminatorContainer > basicTauDiscriminators_inputToken_
std::map< std::string, IDOutput > IDOutputCollection
edm::EDGetTokenT< TauCollection > tausToken_
std::map< BasicDiscriminator, size_t > basicDiscrdR03IndexMap_
void createHadronsBlockInputs(unsigned idx, const TauCastType &tau, const size_t tau_index, const edm::RefToBase< reco::BaseTau > tau_ref, const reco::Vertex &pv, double rho, const edm::View< reco::Candidate > &pfCands, const Cell &cell_map, TauFunc tau_funcs, bool is_inner, HadronBlockType &hadronBlockInputs)
void createTauBlockInputs(const TauCastType &tau, const size_t &tau_index, const edm::RefToBase< reco::BaseTau > tau_ref, const reco::Vertex &pv, double rho, TauFunc tau_funcs, TauBlockType &tauBlockInputs)
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
const std::vector< BasicDiscriminator > requiredBasicDiscriminatorsdR03_
Abs< T >::type abs(const T &t)
float pt_weighted_dr_iso(const reco::PFTau &tau, int dm)
static const pat::Electron * findMatchedElectron(const TauCastType &tau, const std::vector< pat::Electron > *electrons, double deltaR)
def template(fileName, svg, replaceme="REPLACEME")
edm::EDGetTokenT< reco::TauDiscriminatorContainer > basicTauDiscriminatorsdR03_inputToken_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
const_reference at(size_type pos) const
void createMuonBlockInputs(unsigned idx, const TauCastType &tau, const size_t tau_index, const edm::RefToBase< reco::BaseTau > tau_ref, const reco::Vertex &pv, double rho, const std::vector< pat::Muon > *muons, const edm::View< reco::Candidate > &pfCands, const Cell &cell_map, TauFunc tau_funcs, bool is_inner, MuonBlockType &muonBlockInputs)
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > LorentzVectorXYZ
std::vector< CutterPtr > WPList
Analysis-level tau class.
void fill(const edm::Event &evt)
std::vector< size_t > den_
const std::map< BasicDiscriminator, size_t > matchDiscriminatorIndices(edm::Event const &event, edm::EDGetTokenT< reco::TauDiscriminatorContainer > discriminatorContainerToken, std::vector< BasicDiscriminator > requiredDiscr)
const std::map< std::pair< FeatureT, bool >, ScalingParams > scalingParamsMap_v2p1
void createOutputs(edm::Event &event, const PredType &pred, edm::Handle< TauCollection > taus)
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
std::ofstream * json_file_
static void calculateElectronClusterVars(const pat::Electron *ele, float &elecEe, float &elecEgamma)
IDOutput(const std::vector< size_t > &num, const std::vector< size_t > &den)
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
edm::ValueMap< SingleTauDiscriminatorContainer > TauDiscriminatorContainer
const bool disable_CellIndex_workaround_
float pt_weighted_dphi_strip(const reco::PFTau &tau, int dm)
float eratio(const reco::PFTau &tau)
return ratio of energy in ECAL over sum of energy in ECAL and HCAL
void loadPrediscriminants(edm::Event const &event, edm::Handle< TauCollection > const &taus)
Analysis-level electron class.
edm::Ref< PFTauTransverseImpactParameterCollection > PFTauTransverseImpactParameterRef
presistent reference to a PFTauTransverseImpactParameter
IDOutputCollection idoutputs_
std::vector< Muon > MuonCollection
DeepTauIdBase(const edm::ParameterSet &cfg)
const bool disable_dxy_pca_
pat::MuonCollection MuonCollection
void fillGrids(const TauCastType &tau, const Collection &objects, CellGrid &inner_grid, CellGrid &outer_grid)
Particle reconstructed by the particle flow algorithm.
disable_hcalFraction_workaround
const std::map< ValueQuantityType, double > max_value
const unsigned sub_version_
pat::ElectronCollection ElectronCollection
edm::EDGetTokenT< reco::VertexCollection > vtxToken_
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
float read_value(const tensorflow::Tensor &pred, size_t tau_index, size_t elem) const
static constexpr float pi
float lead_track_chi2(const reco::PFTau &tau)
return chi2 of the leading track ==> deprecated? <==
std::vector< TauDiscInfo< reco::PFTauDiscriminator > > recoPrediscriminants_
Log< level::Warning, false > LogWarning
TupleMultiplicity< TrackerTraits > const *__restrict__ uint32_t nHits
T operator[](int i) const
static const std::string subdets[7]
const std::map< std::pair< FeatureT, bool >, ScalingParams > scalingParamsMap_PhaseIIv2p5
pfTauTransverseImpactParameters
Analysis-level muon class.
static float getValueLinear(T value, float min_value, float max_value, bool positive)
void countHits(const reco::Muon &muon, std::vector< int > &numHitsDT, std::vector< int > &numHitsCSC, std::vector< int > &numHitsRPC)
Power< A, B >::type pow(const A &a, const B &b)
std::map< std::string, WPList > workingPoints_
constexpr int NumberOfOutputs
edm::EDGetTokenT< edm::AssociationVector< reco::PFTauRefProd, std::vector< reco::PFTauTransverseImpactParameterRef > > > pfTauTransverseImpactParameters_token_