10 #include <Math/VectorUtil.h> 14 #include "tensorflow/core/util/memmapped_file_system.h" 38 #include "oneapi/tbb/concurrent_unordered_set.h" 53 bool simple_value =
false;
57 simple_value = (
pos == cut_str.size());
58 }
catch (std::invalid_argument&) {
59 }
catch (std::out_of_range&) {
63 "[&](double *x, double *p) { const int decayMode = p[0];" 64 "const double pt = p[1]; const double eta = p[2];";
65 static const int n_params = 3;
66 static const auto handler = [](
int, Bool_t,
const char*,
const char*) ->
void {};
69 if (cut_str.find(
"return") == std::string::npos)
70 fn_str +=
" return " + cut_str +
";}";
72 fn_str += cut_str +
"}";
73 auto old_handler = SetErrorHandler(handler);
74 fn_ = std::make_unique<TF1>(
"fn_", fn_str.c_str(), 0, 1, n_params);
75 SetErrorHandler(old_handler);
77 throw cms::Exception(
"TauWPThreshold: invalid formula") <<
"Invalid WP cut formula = '" << cut_str <<
"'.";
86 fn_->SetParameter(0, dynamic_cast<const reco::PFTau&>(
tau).
decayMode());
89 fn_->SetParameter(1,
tau.pt());
90 fn_->SetParameter(2,
tau.eta());
95 std::unique_ptr<TF1>
fn_;
101 using GraphPtr = std::shared_ptr<tensorflow::GraphDef>;
104 for (
const auto& graph_entry : graph_names) {
113 if (!mmap_status.ok()) {
114 throw cms::Exception(
"DeepTauCache: unable to initalize memmapped environment for ")
116 << mmap_status.ToString();
119 graphs_[entry_name] = std::make_unique<tensorflow::GraphDef>();
122 tensorflow::MemmappedFileSystem::kMemmappedPackageDefaultGraphDef,
124 if (!load_graph_status.ok())
126 << load_graph_status.ToString();
128 options.getSessionOptions().config.mutable_graph_options()->mutable_optimizer_options()->set_opt_level(
129 ::tensorflow::OptimizerOptions::L0);
153 std::map<std::string, std::unique_ptr<tensorflow::MemmappedEnv>>
memmappedEnv_;
162 constexpr
int number_of_inner_cell = 11;
163 constexpr
int number_of_outer_cell = 21;
164 constexpr
int number_of_conv_features = 64;
165 namespace TauBlockInputs {
174 tau_n_charged_prongs,
175 tau_n_neutral_prongs,
177 chargedIsoPtSumdR03_over_dR05,
180 neutralIsoPtSumWeight_over_neutralIsoPtSum,
181 neutralIsoPtSumWeightdR03_over_neutralIsoPtSum,
182 neutralIsoPtSumdR03_over_dR05,
183 photonPtSumOutsideSignalCone,
200 tau_flightLength_sig,
201 tau_pt_weighted_deta_strip,
202 tau_pt_weighted_dphi_strip,
203 tau_pt_weighted_dr_signal,
204 tau_pt_weighted_dr_iso,
205 tau_leadingTrackNormChi2,
208 tau_gj_angle_diff_valid,
212 tau_inside_ecal_crack,
213 leadChargedCand_etaAtEcalEntrance_minus_tau_eta,
216 std::vector<int> varsToDrop = {
217 tau_phi, tau_dxy_pca_x, tau_dxy_pca_y, tau_dxy_pca_z};
220 namespace EgammaBlockInputs {
225 tau_inside_ecal_crack,
230 pfCand_ele_pvAssociationQuality,
231 pfCand_ele_puppiWeight,
233 pfCand_ele_lostInnerHits,
234 pfCand_ele_numberOfPixelHits,
235 pfCand_ele_vertex_dx,
236 pfCand_ele_vertex_dy,
237 pfCand_ele_vertex_dz,
238 pfCand_ele_vertex_dx_tauFL,
239 pfCand_ele_vertex_dy_tauFL,
240 pfCand_ele_vertex_dz_tauFL,
241 pfCand_ele_hasTrackDetails,
246 pfCand_ele_track_chi2_ndof,
247 pfCand_ele_track_ndof,
253 ele_cc_ele_rel_energy,
254 ele_cc_gamma_rel_energy,
256 ele_rel_trackMomentumAtVtx,
257 ele_rel_trackMomentumAtCalo,
258 ele_rel_trackMomentumOut,
259 ele_rel_trackMomentumAtEleClus,
260 ele_rel_trackMomentumAtVtxWithConstraint,
263 ele_eSuperClusterOverP,
264 ele_eSeedClusterOverP,
265 ele_eSeedClusterOverPout,
266 ele_eEleClusterOverPout,
267 ele_deltaEtaSuperClusterTrackAtVtx,
268 ele_deltaEtaSeedClusterTrackAtCalo,
269 ele_deltaEtaEleClusterTrackAtCalo,
270 ele_deltaPhiEleClusterTrackAtCalo,
271 ele_deltaPhiSuperClusterTrackAtVtx,
272 ele_deltaPhiSeedClusterTrackAtCalo,
273 ele_mvaInput_earlyBrem,
274 ele_mvaInput_lateBrem,
275 ele_mvaInput_sigmaEtaEta,
276 ele_mvaInput_hadEnergy,
277 ele_mvaInput_deltaEta,
278 ele_gsfTrack_normalizedChi2,
279 ele_gsfTrack_numberOfValidHits,
282 ele_has_closestCtfTrack,
283 ele_closestCtfTrack_normalizedChi2,
284 ele_closestCtfTrack_numberOfValidHits,
289 pfCand_gamma_pvAssociationQuality,
291 pfCand_gamma_puppiWeight,
292 pfCand_gamma_puppiWeightNoLep,
293 pfCand_gamma_lostInnerHits,
294 pfCand_gamma_numberOfPixelHits,
295 pfCand_gamma_vertex_dx,
296 pfCand_gamma_vertex_dy,
297 pfCand_gamma_vertex_dz,
298 pfCand_gamma_vertex_dx_tauFL,
299 pfCand_gamma_vertex_dy_tauFL,
300 pfCand_gamma_vertex_dz_tauFL,
301 pfCand_gamma_hasTrackDetails,
303 pfCand_gamma_dxy_sig,
306 pfCand_gamma_track_chi2_ndof,
307 pfCand_gamma_track_ndof,
312 namespace MuonBlockInputs {
317 tau_inside_ecal_crack,
322 pfCand_muon_pvAssociationQuality,
324 pfCand_muon_puppiWeight,
326 pfCand_muon_lostInnerHits,
327 pfCand_muon_numberOfPixelHits,
328 pfCand_muon_vertex_dx,
329 pfCand_muon_vertex_dy,
330 pfCand_muon_vertex_dz,
331 pfCand_muon_vertex_dx_tauFL,
332 pfCand_muon_vertex_dy_tauFL,
333 pfCand_muon_vertex_dz_tauFL,
334 pfCand_muon_hasTrackDetails,
339 pfCand_muon_track_chi2_ndof,
340 pfCand_muon_track_ndof,
347 muon_normalizedChi2_valid,
349 muon_numberOfValidHits,
350 muon_segmentCompatibility,
351 muon_caloCompatibility,
352 muon_pfEcalEnergy_valid,
353 muon_rel_pfEcalEnergy,
358 muon_n_matches_CSC_1,
359 muon_n_matches_CSC_2,
360 muon_n_matches_CSC_3,
361 muon_n_matches_CSC_4,
362 muon_n_matches_RPC_1,
363 muon_n_matches_RPC_2,
364 muon_n_matches_RPC_3,
365 muon_n_matches_RPC_4,
382 namespace HadronBlockInputs {
387 tau_inside_ecal_crack,
392 pfCand_chHad_leadChargedHadrCand,
393 pfCand_chHad_pvAssociationQuality,
395 pfCand_chHad_puppiWeight,
396 pfCand_chHad_puppiWeightNoLep,
398 pfCand_chHad_lostInnerHits,
399 pfCand_chHad_numberOfPixelHits,
400 pfCand_chHad_vertex_dx,
401 pfCand_chHad_vertex_dy,
402 pfCand_chHad_vertex_dz,
403 pfCand_chHad_vertex_dx_tauFL,
404 pfCand_chHad_vertex_dy_tauFL,
405 pfCand_chHad_vertex_dz_tauFL,
406 pfCand_chHad_hasTrackDetails,
408 pfCand_chHad_dxy_sig,
411 pfCand_chHad_track_chi2_ndof,
412 pfCand_chHad_track_ndof,
413 pfCand_chHad_hcalFraction,
414 pfCand_chHad_rawCaloFraction,
419 pfCand_nHad_puppiWeight,
420 pfCand_nHad_puppiWeightNoLep,
421 pfCand_nHad_hcalFraction,
428 static tbb::concurrent_unordered_set<std::string> isFirstWarning;
434 <<
"Exception in <getTauID>: No tauID '" <<
tauID <<
"' available in pat::Tau given as function argument.";
436 if (isFirstWarning.insert(
tauID).second) {
438 <<
"' available in pat::Tau given as function argument." 439 <<
" Using default_value = " << default_value <<
" instead." << std::endl;
441 return default_value;
452 std::map<BasicDiscr, size_t> indexMap;
453 std::map<BasicDiscr, size_t> indexMapdR03;
459 return getTauID(
tau,
"chargedIsoPtSum");
465 return getTauID(
tau,
"chargedIsoPtSumdR03");
468 return (*basicTauDiscriminatordR03Collection)[tau_ref].rawValues.at(
472 return getTauID(
tau,
"footprintCorrectiondR03");
475 return getTauID(
tau,
"footprintCorrection");
481 return getTauID(
tau,
"neutralIsoPtSum");
487 return getTauID(
tau,
"neutralIsoPtSumdR03");
493 return getTauID(
tau,
"neutralIsoPtSumWeight");
497 return (*basicTauDiscriminatordR03Collection)[tau_ref].rawValues.at(
501 return getTauID(
tau,
"neutralIsoPtSumWeightdR03");
503 const float getPhotonPtSumOutsideSignalCone(
const reco::PFTau&
tau,
505 return (*basicTauDiscriminatorCollection)[tau_ref].rawValues.at(
508 const float getPhotonPtSumOutsideSignalCone(
const pat::Tau&
tau,
510 return getTauID(
tau,
"photonPtSumOutsideSignalCone");
512 const float getPhotonPtSumOutsideSignalConedR03(
const reco::PFTau&
tau,
514 return (*basicTauDiscriminatordR03Collection)[tau_ref].rawValues.at(
517 const float getPhotonPtSumOutsideSignalConedR03(
const pat::Tau&
tau,
519 return getTauID(
tau,
"photonPtSumOutsideSignalConedR03");
525 return getTauID(
tau,
"puCorrPtSum");
528 auto getdxyPCA(
const reco::PFTau&
tau,
const size_t tau_index)
const {
531 auto getdxyPCA(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.dxy_PCA(); }
532 auto getdxy(
const reco::PFTau&
tau,
const size_t tau_index)
const {
535 auto getdxy(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.dxy(); }
536 auto getdxyError(
const reco::PFTau&
tau,
const size_t tau_index)
const {
539 auto getdxyError(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.dxy_error(); }
540 auto getdxySig(
const reco::PFTau&
tau,
const size_t tau_index)
const {
543 auto getdxySig(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.dxy_Sig(); }
544 auto getip3d(
const reco::PFTau&
tau,
const size_t tau_index)
const {
547 auto getip3d(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.ip3d(); }
548 auto getip3dError(
const reco::PFTau&
tau,
const size_t tau_index)
const {
551 auto getip3dError(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.ip3d_error(); }
552 auto getip3dSig(
const reco::PFTau&
tau,
const size_t tau_index)
const {
555 auto getip3dSig(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.ip3d_Sig(); }
556 auto getHasSecondaryVertex(
const reco::PFTau&
tau,
const size_t tau_index)
const {
559 auto getHasSecondaryVertex(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.hasSecondaryVertex(); }
560 auto getFlightLength(
const reco::PFTau&
tau,
const size_t tau_index)
const {
563 auto getFlightLength(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.flightLength(); }
564 auto getFlightLengthSig(
const reco::PFTau&
tau,
const size_t tau_index)
const {
567 auto getFlightLengthSig(
const pat::Tau&
tau,
const size_t tau_index)
const {
return tau.flightLengthSig(); }
570 auto getLeadingTrackNormChi2(
const pat::Tau&
tau) {
return tau.leadingTrackNormChi2(); }
571 auto getEmFraction(
const pat::Tau&
tau) {
return tau.emFraction_MVA(); }
573 auto getEtaAtEcalEntrance(
const pat::Tau&
tau) {
return tau.etaAtEcalEntranceLeadChargedCand(); }
575 return tau.leadPFChargedHadrCand()->positionAtECALEntrance().eta();
577 auto getEcalEnergyLeadingChargedHadr(
const reco::PFTau&
tau) {
return tau.leadPFChargedHadrCand()->ecalEnergy(); }
578 auto getEcalEnergyLeadingChargedHadr(
const pat::Tau&
tau) {
return tau.ecalEnergyLeadChargedHadrCand(); }
579 auto getHcalEnergyLeadingChargedHadr(
const reco::PFTau&
tau) {
return tau.leadPFChargedHadrCand()->hcalEnergy(); }
580 auto getHcalEnergyLeadingChargedHadr(
const pat::Tau&
tau) {
return tau.hcalEnergyLeadChargedHadrCand(); }
582 template <
typename PreDiscrType>
583 bool passPrediscriminants(
const PreDiscrType prediscriminants,
584 const size_t andPrediscriminants,
586 bool passesPrediscriminants = (andPrediscriminants ? 1 : 0);
588 size_t nPrediscriminants = prediscriminants.size();
589 for (
size_t iDisc = 0; iDisc < nPrediscriminants; ++iDisc) {
591 double discResult = (*prediscriminants[iDisc].handle)[tau_ref];
592 uint8_t thisPasses = (discResult > prediscriminants[iDisc].cut) ? 1 : 0;
609 if (thisPasses ^ andPrediscriminants)
611 passesPrediscriminants = (andPrediscriminants ? 0 : 1);
615 return passesPrediscriminants;
623 return cand.bestTrack() !=
nullptr && std::isnormal(
cand.bestTrack()->dz()) && std::isnormal(
cand.dzError()) &&
627 return cand.hasTrackDetails() && std::isnormal(
cand.dz()) && std::isnormal(
cand.dzError()) &&
cand.dzError() > 0;
637 return cand.puppiWeightNoLep();
640 return cand.bestTrack() !=
nullptr 646 return cand.bestTrack() !=
nullptr 651 return cand.numberOfPixelHits();
660 return cand.rawHcalEnergy() / (
cand.rawHcalEnergy() +
cand.rawEcalEnergy());
663 float hcal_fraction = 0.;
667 hcal_fraction =
cand.hcalFraction();
670 if (
cand.pdgId() == 1 ||
cand.pdgId() == 130) {
671 hcal_fraction =
cand.hcalFraction();
672 }
else if (
cand.isIsolatedChargedHadron()) {
673 hcal_fraction =
cand.rawHcalFraction();
676 return hcal_fraction;
679 return (
cand.rawEcalEnergy() +
cand.rawHcalEnergy()) /
cand.energy();
684 template <
typename LVector1,
typename LVector2>
685 float dEta(
const LVector1& p4,
const LVector2& tau_p4) {
686 return static_cast<float>(p4.eta() - tau_p4.eta());
689 template <
typename LVector1,
typename LVector2>
690 float dPhi(
const LVector1& p4_1,
const LVector2& p4_2) {
691 return static_cast<float>(
reco::deltaPhi(p4_2.phi(), p4_1.phi()));
694 struct MuonHitMatchV2 {
695 static constexpr
size_t n_muon_stations = 4;
696 static constexpr
int first_station_id = 1;
697 static constexpr
int last_station_id = first_station_id + n_muon_stations - 1;
698 using CountArray = std::array<unsigned, n_muon_stations>;
699 using CountMap = std::map<int, CountArray>;
701 const std::vector<int>& consideredSubdets() {
707 static const std::map<int, std::string> subdet_names = {
709 if (!subdet_names.count(subdet))
710 throw cms::Exception(
"MuonHitMatch") <<
"Subdet name for subdet id " << subdet <<
" not found.";
711 return subdet_names.at(subdet);
714 size_t getStationIndex(
int station,
bool throw_exception)
const {
715 if (station < first_station_id || station > last_station_id) {
717 throw cms::Exception(
"MuonHitMatch") <<
"Station id is out of range";
720 return static_cast<size_t>(
station - 1);
724 for (
int subdet : consideredSubdets()) {
725 n_matches[subdet].fill(0);
726 n_hits[subdet].fill(0);
734 for (
const auto& segment :
muon.matches()) {
735 if (segment.segmentMatches.empty() && segment.rpcMatches.empty())
737 if (n_matches.count(segment.detector())) {
738 const size_t station_index = getStationIndex(segment.station(),
true);
739 ++n_matches.at(segment.detector()).at(station_index);
745 if (
muon.outerTrack().isNonnull()) {
746 const auto& hit_pattern =
muon.outerTrack()->hitPattern();
753 const size_t station_index = getStationIndex(hit_pattern.getMuonStation(hit_id),
false);
754 if (station_index < n_muon_stations) {
755 CountArray* muon_n_hits =
nullptr;
756 if (hit_pattern.muonDTHitFilter(hit_id))
758 else if (hit_pattern.muonCSCHitFilter(hit_id))
760 else if (hit_pattern.muonRPCHitFilter(hit_id))
764 ++muon_n_hits->at(station_index);
771 unsigned nMatches(
int subdet,
int station)
const {
772 if (!n_matches.count(subdet))
773 throw cms::Exception(
"MuonHitMatch") <<
"Subdet " << subdet <<
" not found.";
774 const size_t station_index = getStationIndex(
station,
true);
775 return n_matches.at(subdet).at(station_index);
779 if (!n_hits.count(subdet))
780 throw cms::Exception(
"MuonHitMatch") <<
"Subdet " << subdet <<
" not found.";
781 const size_t station_index = getStationIndex(
station,
true);
782 return n_hits.at(subdet).at(station_index);
785 unsigned countMuonStationsWithMatches(
int first_station,
int last_station)
const {
786 static const std::map<int, std::vector<bool>> masks = {
791 const size_t first_station_index = getStationIndex(first_station,
true);
792 const size_t last_station_index = getStationIndex(last_station,
true);
794 for (
size_t n = first_station_index;
n <= last_station_index; ++
n) {
795 for (
const auto&
match : n_matches) {
796 if (!masks.at(
match.first).at(
n) &&
match.second.at(
n) > 0)
803 unsigned countMuonStationsWithHits(
int first_station,
int last_station)
const {
804 static const std::map<int, std::vector<bool>> masks = {
810 const size_t first_station_index = getStationIndex(first_station,
true);
811 const size_t last_station_index = getStationIndex(last_station,
true);
813 for (
size_t n = first_station_index;
n <= last_station_index; ++
n) {
814 for (
const auto&
hit : n_hits) {
815 if (!masks.at(
hit.first).at(
n) &&
hit.second.at(
n) > 0)
823 CountMap n_matches, n_hits;
829 PfCand_chargedHadron,
830 PfCand_neutralHadron,
837 template <
typename Object>
850 static const std::map<int, CellObjectType> obj_types = {{11, CellObjectType::PfCand_electron},
851 {13, CellObjectType::PfCand_muon},
852 {22, CellObjectType::PfCand_gamma},
853 {130, CellObjectType::PfCand_neutralHadron},
854 {211, CellObjectType::PfCand_chargedHadron}};
857 if (iter == obj_types.end())
858 return CellObjectType::Other;
862 using Cell = std::map<CellObjectType, size_t>;
875 using Map = std::map<CellIndex, Cell>;
876 using const_iterator = Map::const_iterator;
878 CellGrid(
unsigned n_cells_eta,
879 unsigned n_cells_phi,
880 double cell_size_eta,
881 double cell_size_phi,
883 : nCellsEta(n_cells_eta),
884 nCellsPhi(n_cells_phi),
885 nTotal(nCellsEta * nCellsPhi),
886 cellSizeEta(cell_size_eta),
887 cellSizePhi(cell_size_phi),
889 if (nCellsEta % 2 != 1 || nCellsEta < 1)
890 throw cms::Exception(
"DeepTauId") <<
"Invalid number of eta cells.";
891 if (nCellsPhi % 2 != 1 || nCellsPhi < 1)
892 throw cms::Exception(
"DeepTauId") <<
"Invalid number of phi cells.";
893 if (cellSizeEta <= 0 || cellSizePhi <= 0)
897 int maxEtaIndex()
const {
return static_cast<int>((nCellsEta - 1) / 2); }
898 int maxPhiIndex()
const {
return static_cast<int>((nCellsPhi - 1) / 2); }
899 double maxDeltaEta()
const {
return cellSizeEta * (0.5 + maxEtaIndex()); }
900 double maxDeltaPhi()
const {
return cellSizePhi * (0.5 + maxPhiIndex()); }
901 int getEtaTensorIndex(
const CellIndex& cellIndex)
const {
return cellIndex.eta + maxEtaIndex(); }
902 int getPhiTensorIndex(
const CellIndex& cellIndex)
const {
return cellIndex.phi + maxPhiIndex(); }
904 bool tryGetCellIndex(
double deltaEta,
double deltaPhi, CellIndex& cellIndex)
const {
905 const auto getCellIndex = [
this](
double x,
double maxX,
double size,
int&
index) {
910 if (disable_CellIndex_workaround_) {
913 absIndex = std::floor(absX /
size + 0.5);
918 index =
static_cast<int>(std::copysign(absIndex,
x));
926 size_t num_valid_cells()
const {
return cells.size(); }
928 const Cell& at(
const CellIndex& cellIndex)
const {
return cells.at(cellIndex); }
929 size_t count(
const CellIndex& cellIndex)
const {
return cells.count(cellIndex); }
930 const_iterator
find(
const CellIndex& cellIndex)
const {
return cells.find(cellIndex); }
931 const_iterator
begin()
const {
return cells.begin(); }
932 const_iterator
end()
const {
return cells.end(); }
935 const unsigned nCellsEta, nCellsPhi, nTotal;
936 const double cellSizeEta, cellSizePhi;
939 std::map<CellIndex, Cell>
cells;
940 const bool disable_CellIndex_workaround_;
964 const tensorflow::Tensor& pred,
967 std::vector<reco::SingleTauDiscriminatorContainer> outputbuffer(
taus->size());
969 for (
size_t tau_index = 0; tau_index <
taus->size(); ++tau_index) {
971 for (
size_t num_elem :
num_)
972 x += pred.matrix<
float>()(tau_index, num_elem);
973 if (
x != 0 && !
den_.empty()) {
975 for (
size_t den_elem :
den_)
976 den_val += pred.matrix<
float>()(tau_index, den_elem);
979 outputbuffer[tau_index].rawValues.push_back(
x);
983 outputbuffer[tau_index].workingPoints.push_back(pass);
987 std::unique_ptr<TauDiscriminator>
output = std::make_unique<TauDiscriminator>();
989 filler.insert(
taus, outputbuffer.begin(), outputbuffer.end());
1000 static constexpr
size_t e_index = 0, mu_index = 1, tau_index = 2, jet_index = 3;
1002 {
"VSe",
Output({tau_index}, {e_index, tau_index})},
1003 {
"VSmu",
Output({tau_index}, {mu_index, tau_index})},
1004 {
"VSjet",
Output({tau_index}, {jet_index, tau_index})},
1014 std::vector<BasicDiscriminator> requiredDiscr) {
1015 std::map<std::string, size_t> discrIndexMapStr;
1016 auto const aHandle =
event.getHandle(discriminatorContainerToken);
1017 auto const aProv = aHandle.provenance();
1018 if (aProv ==
nullptr)
1019 aHandle.whyFailed()->raise();
1020 const auto& psetsFromProvenance =
edm::parameterSet(aProv->stable(),
event.processHistory());
1021 auto const idlist = psetsFromProvenance.
getParameter<std::vector<edm::ParameterSet>>(
"IDdefinitions");
1022 for (
size_t j = 0;
j < idlist.size(); ++
j) {
1024 if (discrIndexMapStr.count(idname)) {
1026 <<
"basic discriminator " << idname <<
" appears more than once in the input.";
1028 discrIndexMapStr[idname] =
j;
1032 std::map<BasicDiscriminator, size_t> discrIndexMap;
1033 for (
size_t i = 0;
i < requiredDiscr.size();
i++) {
1036 <<
" was not provided in the config file.";
1040 return discrIndexMap;
1051 desc.add<std::vector<std::string>>(
"graph_file",
1052 {
"RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6.pb"});
1053 desc.add<
bool>(
"mem_mapped",
false);
1054 desc.add<
unsigned>(
"year", 2017);
1055 desc.add<
unsigned>(
"version", 2);
1056 desc.add<
unsigned>(
"sub_version", 1);
1057 desc.add<
int>(
"debug_level", 0);
1058 desc.add<
bool>(
"disable_dxy_pca",
false);
1059 desc.add<
bool>(
"disable_hcalFraction_workaround",
false);
1060 desc.add<
bool>(
"disable_CellIndex_workaround",
false);
1061 desc.add<
bool>(
"save_inputs",
false);
1062 desc.add<
bool>(
"is_online",
false);
1064 desc.add<std::vector<std::string>>(
"VSeWP", {
"-1."});
1065 desc.add<std::vector<std::string>>(
"VSmuWP", {
"-1."});
1066 desc.add<std::vector<std::string>>(
"VSjetWP", {
"-1."});
1074 pset_Prediscriminants.
add<
std::string>(
"BooleanOperator",
"and");
1077 psd1.
add<
double>(
"cut");
1084 descriptions.
add(
"DeepTau",
desc);
1099 cfg.getUntrackedParameter<
edm::
InputTag>(
"basicTauDiscriminators"))),
1101 cfg.getUntrackedParameter<
edm::
InputTag>(
"basicTauDiscriminatorsdR03"))),
1104 cfg.getParameter<
edm::
InputTag>(
"pfTauTransverseImpactParameters"))),
1105 year_(
cfg.getParameter<unsigned>(
"year")),
1115 for (
const auto& output_desc :
outputs_) {
1116 produces<TauDiscriminator>(output_desc.first);
1117 const auto& cut_list =
cfg.getParameter<std::vector<std::string>>(output_desc.first +
"WP");
1119 workingPoints_[output_desc.first].push_back(std::make_unique<Cutter>(cut_str));
1130 transform(pdBoolOperator.begin(), pdBoolOperator.end(), pdBoolOperator.begin(), ::tolower);
1132 if (pdBoolOperator ==
"and") {
1134 }
else if (pdBoolOperator ==
"or") {
1138 <<
"PrediscriminantBooleanOperator defined incorrectly, options are: AND,OR";
1142 std::vector<std::string> prediscriminantsNames =
1145 for (
auto const& iDisc : prediscriminantsNames) {
1153 thisDiscriminator.
cut =
cut;
1154 thisDiscriminator.
disc_token = consumes<reco::PFTauDiscriminator>(
label);
1159 thisDiscriminator.
cut =
cut;
1160 thisDiscriminator.
disc_token = consumes<pat::PATTauDiscriminator>(
label);
1172 tensorflow::DT_FLOAT, tensorflow::TensorShape{1, TauBlockInputs::NumberOfInputs});
1175 std::sort(TauBlockInputs::varsToDrop.begin(), TauBlockInputs::varsToDrop.
end());
1176 for (
auto v : TauBlockInputs::varsToDrop) {
1178 for (std::size_t
i =
v + 1;
i < TauBlockInputs::NumberOfInputs; ++
i)
1182 tensorflow::DT_FLOAT,
1183 tensorflow::TensorShape{1,
1184 static_cast<int>(TauBlockInputs::NumberOfInputs) -
1185 static_cast<int>(TauBlockInputs::varsToDrop.
size())});
1186 if (
year_ == 2026) {
1194 std::map<std::vector<bool>, std::vector<sc::FeatureT>> GridFeatureTypes_map = {
1195 {{
false}, {sc::FeatureT::TauFlat, sc::FeatureT::GridGlobal}},
1197 {sc::FeatureT::PfCand_electron,
1198 sc::FeatureT::PfCand_muon,
1199 sc::FeatureT::PfCand_chHad,
1200 sc::FeatureT::PfCand_nHad,
1201 sc::FeatureT::PfCand_gamma,
1206 for (
const auto&
p : GridFeatureTypes_map) {
1207 for (
auto is_inner :
p.first) {
1208 for (
auto featureType :
p.second) {
1209 const sc::ScalingParams& sp =
scalingParamsMap_->at(std::make_pair(featureType, is_inner));
1210 if (!(sp.mean_.size() == sp.std_.size() && sp.mean_.size() == sp.lim_min_.size() &&
1211 sp.mean_.size() == sp.lim_max_.size()))
1212 throw cms::Exception(
"DeepTauId") <<
"sizes of scaling parameter vectors do not match between each other";
1217 for (
size_t n = 0;
n < 2; ++
n) {
1218 const bool is_inner =
n == 0;
1219 const auto n_cells = is_inner ? number_of_inner_cell : number_of_outer_cell;
1220 eGammaTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1221 tensorflow::DT_FLOAT, tensorflow::TensorShape{1, 1, 1, EgammaBlockInputs::NumberOfInputs});
1222 muonTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1223 tensorflow::DT_FLOAT, tensorflow::TensorShape{1, 1, 1, MuonBlockInputs::NumberOfInputs});
1225 tensorflow::DT_FLOAT, tensorflow::TensorShape{1, 1, 1, HadronBlockInputs::NumberOfInputs});
1226 convTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1227 tensorflow::DT_FLOAT, tensorflow::TensorShape{1, n_cells, n_cells, number_of_conv_features});
1229 tensorflow::DT_FLOAT, tensorflow::TensorShape{1, 1, 1, number_of_conv_features});
1248 size_t nPrediscriminants =
1250 for (
size_t iDisc = 0; iDisc < nPrediscriminants; ++iDisc) {
1262 if (tauProductID != discKeyId) {
1264 <<
"The tau collection has product ID: " << tauProductID
1265 <<
" but the pre-discriminator is keyed with product ID: " << discKeyId << std::endl;
1274 const auto graph_name_vector =
cfg.getParameter<std::vector<std::string>>(
"graph_file");
1275 std::map<std::string, std::string> graph_names;
1276 for (
const auto&
entry : graph_name_vector) {
1277 const size_t sep_pos =
entry.find(
':');
1279 if (sep_pos != std::string::npos) {
1280 entry_name =
entry.substr(0, sep_pos);
1287 if (graph_names.count(entry_name))
1288 throw cms::Exception(
"DeepTauCache") <<
"Duplicated graph entries";
1292 return std::make_unique<deep_tau::DeepTauCache>(graph_names,
mem_mapped);
1297 template <
typename ConsumeType>
1315 for (
const auto& output_desc :
outputs_) {
1325 template <
typename T>
1327 return std::isnormal(
value) ?
static_cast<float>(
value) : 0.
f;
1330 template <
typename T>
1336 transformed_value = transformed_value * 2 - 1;
1337 return transformed_value;
1340 template <
typename T>
1343 const float norm_value = (fixed_value -
mean) / sigma;
1344 return std::clamp(norm_value, -n_sigmas_max, n_sigmas_max);
1350 float& cc_ele_energy,
1351 float& cc_gamma_energy,
1353 cc_ele_energy = cc_gamma_energy = 0;
1356 if (superCluster.isNonnull() && superCluster.isAvailable() && superCluster->clusters().isNonnull() &&
1357 superCluster->clusters().isAvailable()) {
1358 for (
auto iter = superCluster->clustersBegin(); iter != superCluster->clustersEnd(); ++iter) {
1359 const float energy =
static_cast<float>((*iter)->energy());
1360 if (iter == superCluster->clustersBegin())
1363 cc_gamma_energy +=
energy;
1375 const CellGrid*
grid =
nullptr)
const {
1377 std::cout <<
"<checkInputs>: block_name = " << block_name << std::endl;
1378 if (block_name ==
"input_tau") {
1379 for (
int input_index = 0; input_index < n_inputs; ++input_index) {
1380 float input =
inputs.matrix<
float>()(0, input_index);
1383 <<
"in the " << block_name
1384 <<
", input is not finite, i.e. infinite or NaN, for input_index = " << input_index;
1394 if (block_name.find(
"input_inner") != std::string::npos) {
1397 }
else if (block_name.find(
"input_outer") != std::string::npos) {
1402 int eta_phi_index = 0;
1403 for (
int eta = -n_eta;
eta <= n_eta; ++
eta) {
1404 for (
int phi = -n_phi;
phi <= n_phi; ++
phi) {
1405 const CellIndex cell_index{
eta,
phi};
1406 const auto cell_iter =
grid->find(cell_index);
1407 if (cell_iter !=
grid->end()) {
1408 for (
int input_index = 0; input_index < n_inputs; ++input_index) {
1412 <<
"in the " << block_name <<
", input is not finite, i.e. infinite or NaN, for eta = " <<
eta 1413 <<
", phi = " <<
phi <<
", input_index = " << input_index;
1416 std::cout << block_name <<
"[eta = " <<
eta <<
"][phi = " <<
phi <<
"][var = " << input_index
1417 <<
"] = " << std::setprecision(5) <<
std::fixed <<
input << std::endl;
1431 const CellGrid*
grid =
nullptr) {
1433 std::cout <<
"<saveInputs>: block_name = " << block_name << std::endl;
1436 (*json_file_) <<
", ";
1437 (*json_file_) <<
"\"" << block_name <<
"\": [";
1438 if (block_name ==
"input_tau") {
1439 for (
int input_index = 0; input_index < n_inputs; ++input_index) {
1440 float input =
inputs.matrix<
float>()(0, input_index);
1441 if (input_index != 0)
1442 (*json_file_) <<
", ";
1443 (*json_file_) <<
input;
1448 if (block_name.find(
"input_inner") != std::string::npos) {
1451 }
else if (block_name.find(
"input_outer") != std::string::npos) {
1456 int eta_phi_index = 0;
1457 for (
int eta = -n_eta;
eta <= n_eta; ++
eta) {
1459 (*json_file_) <<
", ";
1460 (*json_file_) <<
"[";
1461 for (
int phi = -n_phi;
phi <= n_phi; ++
phi) {
1463 (*json_file_) <<
", ";
1464 (*json_file_) <<
"[";
1465 const CellIndex cell_index{
eta,
phi};
1466 const auto cell_iter =
grid->find(cell_index);
1467 for (
int input_index = 0; input_index < n_inputs; ++input_index) {
1469 if (cell_iter !=
grid->end()) {
1472 if (input_index != 0)
1473 (*json_file_) <<
", ";
1474 (*json_file_) <<
input;
1476 if (cell_iter !=
grid->end()) {
1479 (*json_file_) <<
"]";
1481 (*json_file_) <<
"]";
1484 (*json_file_) <<
"]";
1491 const std::vector<pat::Electron> electron_collection_default;
1492 const std::vector<pat::Muon> muon_collection_default;
1496 pfTauTransverseImpactParameters_default;
1498 const std::vector<pat::Electron>* electron_collection;
1499 const std::vector<pat::Muon>* muon_collection;
1512 electron_collection = &electron_collection_default;
1513 muon_collection = &muon_collection_default;
1543 auto const& eventnr =
event.id().event();
1547 for (
size_t tau_index = 0; tau_index <
taus->size(); ++tau_index) {
1550 std::vector<tensorflow::Tensor> pred_vector;
1552 bool passesPrediscriminants;
1554 passesPrediscriminants = tauIDs.passPrediscriminants<std::vector<TauDiscInfo<reco::PFTauDiscriminator>>>(
1557 passesPrediscriminants = tauIDs.passPrediscriminants<std::vector<TauDiscInfo<pat::PATTauDiscriminator>>>(
1561 if (passesPrediscriminants) {
1564 getPredictionsV2<reco::PFCandidate, reco::PFTau>(
taus->at(tau_index),
1567 electron_collection,
1576 getPredictionsV2<pat::PackedCandidate, pat::Tau>(
taus->at(tau_index),
1579 electron_collection,
1592 const float pred = pred_vector[0].flat<
float>()(
k);
1593 if (!(pred >= 0 && pred <= 1))
1595 <<
"invalid prediction = " << pred <<
" for tau_index = " << tau_index <<
", pred_index = " <<
k;
1596 predictions.matrix<
float>()(tau_index,
k) = pred;
1605 predictions.matrix<
float>()(tau_index,
k) = (
k == 2) ? -1.
f : 2.
f;
1612 template <
typename Cand
idateCastType,
typename TauCastType>
1614 const size_t tau_index,
1616 const std::vector<pat::Electron>*
electrons,
1617 const std::vector<pat::Muon>*
muons,
1622 std::vector<tensorflow::Tensor>& pred_vector,
1623 TauFunc tau_funcs) {
1626 std::cout <<
"<DeepTauId::getPredictionsV2 (moduleLabel = " << moduleDescription().moduleLabel()
1627 <<
")>:" << std::endl;
1628 std::cout <<
" tau: pT = " <<
tau.pt() <<
", eta = " <<
tau.eta() <<
", phi = " <<
tau.phi()
1629 <<
", eventnr = " << eventnr << std::endl;
1634 fillGrids(dynamic_cast<const TauCastType&>(
tau), *
muons, inner_grid, outer_grid);
1635 fillGrids(dynamic_cast<const TauCastType&>(
tau), pfCands, inner_grid, outer_grid);
1637 createTauBlockInputs<CandidateCastType>(
1638 dynamic_cast<const TauCastType&
>(
tau), tau_index, tau_ref,
pv,
rho, tau_funcs);
1640 createConvFeatures<CandidateCastType>(
dynamic_cast<const TauCastType&
>(
tau),
1654 createConvFeatures<CandidateCastType>(
dynamic_cast<const TauCastType&
>(
tau),
1671 json_file_ =
new std::ofstream(json_file_name.data());
1673 (*json_file_) <<
"{";
1676 *
eGammaTensor_[
true],
"input_inner_egamma", dnn_inputs_v2::EgammaBlockInputs::NumberOfInputs, &inner_grid);
1677 saveInputs(*
muonTensor_[
true],
"input_inner_muon", dnn_inputs_v2::MuonBlockInputs::NumberOfInputs, &inner_grid);
1679 *
hadronsTensor_[
true],
"input_inner_hadrons", dnn_inputs_v2::HadronBlockInputs::NumberOfInputs, &inner_grid);
1681 *
eGammaTensor_[
false],
"input_outer_egamma", dnn_inputs_v2::EgammaBlockInputs::NumberOfInputs, &outer_grid);
1682 saveInputs(*
muonTensor_[
false],
"input_outer_muon", dnn_inputs_v2::MuonBlockInputs::NumberOfInputs, &outer_grid);
1684 *
hadronsTensor_[
false],
"input_outer_hadrons", dnn_inputs_v2::HadronBlockInputs::NumberOfInputs, &outer_grid);
1685 (*json_file_) <<
"}";
1694 {
"main_output/Softmax"},
1718 template <
typename Collection,
typename TauCastType>
1719 void fillGrids(
const TauCastType&
tau,
const Collection&
objects, CellGrid& inner_grid, CellGrid& outer_grid) {
1720 static constexpr
double outer_dR2 = 0.25;
1722 const double inner_dR2 =
std::pow(inner_radius, 2);
1724 const auto addObject = [&](
size_t n,
double deta,
double dphi, CellGrid&
grid) {
1727 if (obj_type == CellObjectType::Other)
1729 CellIndex cell_index;
1730 if (
grid.tryGetCellIndex(deta, dphi, cell_index)) {
1732 auto iter = cell.find(obj_type);
1733 if (iter != cell.end()) {
1734 const auto& prev_obj =
objects.at(iter->second);
1735 if (
obj.polarP4().pt() > prev_obj.polarP4().pt())
1743 for (
size_t n = 0;
n <
objects.size(); ++
n) {
1745 const double deta =
obj.polarP4().eta() -
tau.polarP4().eta();
1748 if (dR2 < inner_dR2)
1749 addObject(
n, deta, dphi, inner_grid);
1750 if (dR2 < outer_dR2)
1751 addObject(
n, deta, dphi, outer_grid);
1756 std::vector<tensorflow::Tensor> pred_vector;
1764 {
"inner_all_dropout_4/Identity"},
1773 {
"outer_all_dropout_4/Identity"},
1776 return pred_vector.at(0);
1779 template <
typename Cand
idateCastType,
typename TauCastType>
1781 const size_t tau_index,
1785 const std::vector<pat::Electron>*
electrons,
1786 const std::vector<pat::Muon>*
muons,
1788 const CellGrid&
grid,
1792 std::cout <<
"<DeepTauId::createConvFeatures (is_inner = " << is_inner <<
")>:" << std::endl;
1794 tensorflow::Tensor& convTensor = *
convTensor_.at(is_inner);
1795 eGammaTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1796 tensorflow::DT_FLOAT,
1797 tensorflow::TensorShape{
1798 (
long long int)
grid.num_valid_cells(), 1, 1, dnn_inputs_v2::EgammaBlockInputs::NumberOfInputs});
1799 muonTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1800 tensorflow::DT_FLOAT,
1801 tensorflow::TensorShape{
1802 (
long long int)
grid.num_valid_cells(), 1, 1, dnn_inputs_v2::MuonBlockInputs::NumberOfInputs});
1804 tensorflow::DT_FLOAT,
1805 tensorflow::TensorShape{
1806 (
long long int)
grid.num_valid_cells(), 1, 1, dnn_inputs_v2::HadronBlockInputs::NumberOfInputs});
1816 std::cout <<
"processing ( eta = " <<
eta <<
", phi = " <<
phi <<
" )" << std::endl;
1818 const CellIndex cell_index{
eta,
phi};
1819 const auto cell_iter =
grid.find(cell_index);
1820 if (cell_iter !=
grid.end()) {
1822 std::cout <<
" creating inputs for ( eta = " <<
eta <<
", phi = " <<
phi <<
" ): idx = " <<
idx 1825 const Cell& cell = cell_iter->second;
1826 createEgammaBlockInputs<CandidateCastType>(
1827 idx,
tau, tau_index, tau_ref,
pv,
rho,
electrons, pfCands, cell, tau_funcs, is_inner);
1828 createMuonBlockInputs<CandidateCastType>(
1829 idx,
tau, tau_index, tau_ref,
pv,
rho,
muons, pfCands, cell, tau_funcs, is_inner);
1830 createHadronsBlockInputs<CandidateCastType>(
1831 idx,
tau, tau_index, tau_ref,
pv,
rho, pfCands, cell, tau_funcs, is_inner);
1835 std::cout <<
" skipping creation of inputs, because ( eta = " <<
eta <<
", phi = " <<
phi 1836 <<
" ) is not in the grid !!" << std::endl;
1846 const CellIndex cell_index{
eta,
phi};
1847 const int eta_index =
grid.getEtaTensorIndex(cell_index);
1848 const int phi_index =
grid.getPhiTensorIndex(cell_index);
1850 const auto cell_iter =
grid.find(cell_index);
1851 if (cell_iter !=
grid.end()) {
1862 const tensorflow::Tensor&
features,
1866 for (
int n = 0;
n < dnn_inputs_v2::number_of_conv_features; ++
n) {
1867 convTensor.tensor<
float, 4>()(0, eta_index, phi_index,
n) =
features.tensor<
float, 4>()(batch_idx, 0, 0,
n);
1871 template <
typename Cand
idateCastType,
typename TauCastType>
1873 const size_t& tau_index,
1877 TauFunc tau_funcs) {
1884 inputs.flat<
float>().setZero();
1886 const auto&
get = [&](
int var_index) ->
float& {
1890 auto leadChargedHadrCand =
dynamic_cast<const CandidateCastType*
>(
tau.leadChargedHadrCand().get());
1901 get(dnn::tau_n_charged_prongs) = sp.scale(
tau.decayMode() / 5 + 1,
tauInputs_indices_[dnn::tau_n_charged_prongs]);
1902 get(dnn::tau_n_neutral_prongs) = sp.scale(
tau.decayMode() % 5,
tauInputs_indices_[dnn::tau_n_neutral_prongs]);
1903 get(dnn::chargedIsoPtSum) =
1905 get(dnn::chargedIsoPtSumdR03_over_dR05) =
1906 sp.scale(tau_funcs.getChargedIsoPtSumdR03(
tau, tau_ref) / tau_funcs.getChargedIsoPtSum(
tau, tau_ref),
1909 get(dnn::footprintCorrection) =
1910 sp.scale(tau_funcs.getFootprintCorrectiondR03(
tau, tau_ref),
tauInputs_indices_[dnn::footprintCorrection]);
1912 get(dnn::footprintCorrection) =
1913 sp.scale(tau_funcs.getFootprintCorrection(
tau, tau_ref),
tauInputs_indices_[dnn::footprintCorrection]);
1915 get(dnn::neutralIsoPtSum) =
1917 get(dnn::neutralIsoPtSumWeight_over_neutralIsoPtSum) =
1918 sp.scale(tau_funcs.getNeutralIsoPtSumWeight(
tau, tau_ref) / tau_funcs.getNeutralIsoPtSum(
tau, tau_ref),
1920 get(dnn::neutralIsoPtSumWeightdR03_over_neutralIsoPtSum) =
1921 sp.scale(tau_funcs.getNeutralIsoPtSumdR03Weight(
tau, tau_ref) / tau_funcs.getNeutralIsoPtSum(
tau, tau_ref),
1923 get(dnn::neutralIsoPtSumdR03_over_dR05) =
1924 sp.scale(tau_funcs.getNeutralIsoPtSumdR03(
tau, tau_ref) / tau_funcs.getNeutralIsoPtSum(
tau, tau_ref),
1926 get(dnn::photonPtSumOutsideSignalCone) = sp.scale(tau_funcs.getPhotonPtSumOutsideSignalCone(
tau, tau_ref),
1928 get(dnn::puCorrPtSum) = sp.scale(tau_funcs.getPuCorrPtSum(
tau, tau_ref),
tauInputs_indices_[dnn::puCorrPtSum]);
1935 auto const pca = tau_funcs.getdxyPCA(
tau, tau_index);
1940 get(dnn::tau_dxy_pca_x) = 0;
1941 get(dnn::tau_dxy_pca_y) = 0;
1942 get(dnn::tau_dxy_pca_z) = 0;
1946 const bool tau_dxy_valid =
1947 isAbove(tau_funcs.getdxy(
tau, tau_index), -10) &&
isAbove(tau_funcs.getdxyError(
tau, tau_index), 0);
1948 if (tau_dxy_valid) {
1949 get(dnn::tau_dxy_valid) = sp.scale(tau_dxy_valid,
tauInputs_indices_[dnn::tau_dxy_valid]);
1951 get(dnn::tau_dxy_sig) =
1952 sp.scale(
std::abs(tau_funcs.getdxy(
tau, tau_index)) / tau_funcs.getdxyError(
tau, tau_index),
1955 const bool tau_ip3d_valid =
1956 isAbove(tau_funcs.getip3d(
tau, tau_index), -10) &&
isAbove(tau_funcs.getip3dError(
tau, tau_index), 0);
1957 if (tau_ip3d_valid) {
1958 get(dnn::tau_ip3d_valid) = sp.scale(tau_ip3d_valid,
tauInputs_indices_[dnn::tau_ip3d_valid]);
1959 get(dnn::tau_ip3d) = sp.scale(tau_funcs.getip3d(
tau, tau_index),
tauInputs_indices_[dnn::tau_ip3d]);
1960 get(dnn::tau_ip3d_sig) =
1961 sp.scale(
std::abs(tau_funcs.getip3d(
tau, tau_index)) / tau_funcs.getip3dError(
tau, tau_index),
1964 if (leadChargedHadrCand) {
1965 const bool hasTrackDetails = candFunc::getHasTrackDetails(*leadChargedHadrCand);
1966 const float tau_dz = (
is_online_ && !hasTrackDetails) ? 0 : candFunc::getTauDz(*leadChargedHadrCand);
1968 get(dnn::tau_dz_sig_valid) =
1969 sp.scale(candFunc::getTauDZSigValid(*leadChargedHadrCand),
tauInputs_indices_[dnn::tau_dz_sig_valid]);
1970 const double dzError = hasTrackDetails ? leadChargedHadrCand->dzError() : -999.;
1973 get(dnn::tau_flightLength_x) =
1974 sp.scale(tau_funcs.getFlightLength(
tau, tau_index).x(),
tauInputs_indices_[dnn::tau_flightLength_x]);
1975 get(dnn::tau_flightLength_y) =
1976 sp.scale(tau_funcs.getFlightLength(
tau, tau_index).y(),
tauInputs_indices_[dnn::tau_flightLength_y]);
1977 get(dnn::tau_flightLength_z) =
1978 sp.scale(tau_funcs.getFlightLength(
tau, tau_index).z(),
tauInputs_indices_[dnn::tau_flightLength_z]);
1980 get(dnn::tau_flightLength_sig) = 0.55756444;
1982 get(dnn::tau_flightLength_sig) =
1983 sp.scale(tau_funcs.getFlightLengthSig(
tau, tau_index),
tauInputs_indices_[dnn::tau_flightLength_sig]);
1992 get(dnn::tau_pt_weighted_dr_iso) =
1994 get(dnn::tau_leadingTrackNormChi2) =
1995 sp.scale(tau_funcs.getLeadingTrackNormChi2(
tau),
tauInputs_indices_[dnn::tau_leadingTrackNormChi2]);
1997 const bool tau_e_ratio_valid = std::isnormal(
eratio) &&
eratio > 0.f;
1998 get(dnn::tau_e_ratio_valid) = sp.scale(tau_e_ratio_valid,
tauInputs_indices_[dnn::tau_e_ratio_valid]);
2001 const bool tau_gj_angle_diff_valid = (std::isnormal(gj_angle_diff) || gj_angle_diff == 0) && gj_angle_diff >= 0;
2002 get(dnn::tau_gj_angle_diff_valid) =
2004 get(dnn::tau_gj_angle_diff) =
2005 tau_gj_angle_diff_valid ? sp.scale(gj_angle_diff,
tauInputs_indices_[dnn::tau_gj_angle_diff]) : 0;
2007 get(dnn::tau_emFraction) = sp.scale(tau_funcs.getEmFraction(
tau),
tauInputs_indices_[dnn::tau_emFraction]);
2009 get(dnn::tau_inside_ecal_crack) =
2011 get(dnn::leadChargedCand_etaAtEcalEntrance_minus_tau_eta) =
2012 sp.scale(tau_funcs.getEtaAtEcalEntrance(
tau) -
tau.p4().eta(),
2016 template <
typename Cand
idateCastType,
typename TauCastType>
2018 const TauCastType&
tau,
2019 const size_t tau_index,
2023 const std::vector<pat::Electron>*
electrons,
2025 const Cell& cell_map,
2036 int PFe_index_offset =
scalingParamsMap_->at(std::make_pair(ft_global,
false)).mean_.size();
2037 int e_index_offset = PFe_index_offset +
scalingParamsMap_->at(std::make_pair(ft_PFe,
false)).mean_.size();
2038 int PFg_index_offset = e_index_offset +
scalingParamsMap_->at(std::make_pair(ft_e,
false)).mean_.size();
2041 int fill_index_offset_e = 0;
2042 int fill_index_offset_PFg = 0;
2044 fill_index_offset_e =
2046 fill_index_offset_PFg =
2052 const auto&
get = [&](
int var_index) ->
float& {
return inputs.tensor<
float, 4>()(
idx, 0, 0, var_index); };
2054 const bool valid_index_pf_ele = cell_map.count(CellObjectType::PfCand_electron);
2055 const bool valid_index_pf_gamma = cell_map.count(CellObjectType::PfCand_gamma);
2058 if (!cell_map.empty()) {
2059 const sc::ScalingParams& sp =
scalingParamsMap_->at(std::make_pair(ft_global,
false));
2063 get(dnn::tau_inside_ecal_crack) = sp.scale(
isInEcalCrack(
tau.polarP4().eta()), dnn::tau_inside_ecal_crack);
2065 if (valid_index_pf_ele) {
2066 const sc::ScalingParams& sp =
scalingParamsMap_->at(std::make_pair(ft_PFe, is_inner));
2067 size_t index_pf_ele = cell_map.at(CellObjectType::PfCand_electron);
2068 const auto& ele_cand =
dynamic_cast<const CandidateCastType&
>(pfCands.
at(index_pf_ele));
2070 get(dnn::pfCand_ele_valid) = sp.scale(valid_index_pf_ele, dnn::pfCand_ele_valid - PFe_index_offset);
2071 get(dnn::pfCand_ele_rel_pt) =
2072 sp.scale(ele_cand.polarP4().pt() /
tau.polarP4().pt(), dnn::pfCand_ele_rel_pt - PFe_index_offset);
2073 get(dnn::pfCand_ele_deta) =
2074 sp.scale(ele_cand.polarP4().eta() -
tau.polarP4().eta(), dnn::pfCand_ele_deta - PFe_index_offset);
2075 get(dnn::pfCand_ele_dphi) =
2076 sp.scale(
dPhi(
tau.polarP4(), ele_cand.polarP4()), dnn::pfCand_ele_dphi - PFe_index_offset);
2077 get(dnn::pfCand_ele_pvAssociationQuality) = sp.scale<
int>(
2078 candFunc::getPvAssocationQuality(ele_cand), dnn::pfCand_ele_pvAssociationQuality - PFe_index_offset);
2079 get(dnn::pfCand_ele_puppiWeight) = is_inner ? sp.scale(candFunc::getPuppiWeight(ele_cand, 0.9906834f),
2080 dnn::pfCand_ele_puppiWeight - PFe_index_offset)
2081 : sp.scale(candFunc::getPuppiWeight(ele_cand, 0.9669586
f),
2082 dnn::pfCand_ele_puppiWeight - PFe_index_offset);
2083 get(dnn::pfCand_ele_charge) = sp.scale(ele_cand.charge(), dnn::pfCand_ele_charge - PFe_index_offset);
2084 get(dnn::pfCand_ele_lostInnerHits) =
2085 sp.scale<
int>(candFunc::getLostInnerHits(ele_cand, 0), dnn::pfCand_ele_lostInnerHits - PFe_index_offset);
2086 get(dnn::pfCand_ele_numberOfPixelHits) =
2087 sp.scale(candFunc::getNumberOfPixelHits(ele_cand, 0), dnn::pfCand_ele_numberOfPixelHits - PFe_index_offset);
2088 get(dnn::pfCand_ele_vertex_dx) =
2089 sp.scale(ele_cand.vertex().x() -
pv.position().x(), dnn::pfCand_ele_vertex_dx - PFe_index_offset);
2090 get(dnn::pfCand_ele_vertex_dy) =
2091 sp.scale(ele_cand.vertex().y() -
pv.position().y(), dnn::pfCand_ele_vertex_dy - PFe_index_offset);
2092 get(dnn::pfCand_ele_vertex_dz) =
2093 sp.scale(ele_cand.vertex().z() -
pv.position().z(), dnn::pfCand_ele_vertex_dz - PFe_index_offset);
2094 get(dnn::pfCand_ele_vertex_dx_tauFL) =
2095 sp.scale(ele_cand.vertex().x() -
pv.position().x() - tau_funcs.getFlightLength(
tau, tau_index).x(),
2096 dnn::pfCand_ele_vertex_dx_tauFL - PFe_index_offset);
2097 get(dnn::pfCand_ele_vertex_dy_tauFL) =
2098 sp.scale(ele_cand.vertex().y() -
pv.position().y() - tau_funcs.getFlightLength(
tau, tau_index).y(),
2099 dnn::pfCand_ele_vertex_dy_tauFL - PFe_index_offset);
2100 get(dnn::pfCand_ele_vertex_dz_tauFL) =
2101 sp.scale(ele_cand.vertex().z() -
pv.position().z() - tau_funcs.getFlightLength(
tau, tau_index).z(),
2102 dnn::pfCand_ele_vertex_dz_tauFL - PFe_index_offset);
2104 const bool hasTrackDetails = candFunc::getHasTrackDetails(ele_cand);
2105 if (hasTrackDetails) {
2106 get(dnn::pfCand_ele_hasTrackDetails) =
2107 sp.scale(hasTrackDetails, dnn::pfCand_ele_hasTrackDetails - PFe_index_offset);
2108 get(dnn::pfCand_ele_dxy) = sp.scale(candFunc::getTauDxy(ele_cand), dnn::pfCand_ele_dxy - PFe_index_offset);
2109 get(dnn::pfCand_ele_dxy_sig) = sp.scale(
std::abs(candFunc::getTauDxy(ele_cand)) / ele_cand.dxyError(),
2110 dnn::pfCand_ele_dxy_sig - PFe_index_offset);
2111 get(dnn::pfCand_ele_dz) = sp.scale(candFunc::getTauDz(ele_cand), dnn::pfCand_ele_dz - PFe_index_offset);
2112 get(dnn::pfCand_ele_dz_sig) = sp.scale(
std::abs(candFunc::getTauDz(ele_cand)) / ele_cand.dzError(),
2113 dnn::pfCand_ele_dz_sig - PFe_index_offset);
2114 get(dnn::pfCand_ele_track_chi2_ndof) =
2115 candFunc::getPseudoTrack(ele_cand).ndof() > 0
2116 ? sp.scale(candFunc::getPseudoTrack(ele_cand).
chi2() / candFunc::getPseudoTrack(ele_cand).
ndof(),
2117 dnn::pfCand_ele_track_chi2_ndof - PFe_index_offset)
2119 get(dnn::pfCand_ele_track_ndof) =
2120 candFunc::getPseudoTrack(ele_cand).ndof() > 0
2121 ? sp.scale(candFunc::getPseudoTrack(ele_cand).
ndof(), dnn::pfCand_ele_track_ndof - PFe_index_offset)
2125 if (valid_index_pf_gamma) {
2126 const sc::ScalingParams& sp =
scalingParamsMap_->at(std::make_pair(ft_PFg, is_inner));
2127 size_t index_pf_gamma = cell_map.at(CellObjectType::PfCand_gamma);
2128 const auto& gamma_cand =
dynamic_cast<const CandidateCastType&
>(pfCands.
at(index_pf_gamma));
2130 get(dnn::pfCand_gamma_valid + fill_index_offset_PFg) =
2131 sp.scale(valid_index_pf_gamma, dnn::pfCand_gamma_valid - PFg_index_offset);
2132 get(dnn::pfCand_gamma_rel_pt + fill_index_offset_PFg) =
2133 sp.scale(gamma_cand.polarP4().pt() /
tau.polarP4().pt(), dnn::pfCand_gamma_rel_pt - PFg_index_offset);
2134 get(dnn::pfCand_gamma_deta + fill_index_offset_PFg) =
2135 sp.scale(gamma_cand.polarP4().eta() -
tau.polarP4().eta(), dnn::pfCand_gamma_deta - PFg_index_offset);
2136 get(dnn::pfCand_gamma_dphi + fill_index_offset_PFg) =
2137 sp.scale(
dPhi(
tau.polarP4(), gamma_cand.polarP4()), dnn::pfCand_gamma_dphi - PFg_index_offset);
2138 get(dnn::pfCand_gamma_pvAssociationQuality + fill_index_offset_PFg) = sp.scale<
int>(
2139 candFunc::getPvAssocationQuality(gamma_cand), dnn::pfCand_gamma_pvAssociationQuality - PFg_index_offset);
2140 get(dnn::pfCand_gamma_fromPV + fill_index_offset_PFg) =
2141 sp.scale<
int>(candFunc::getFromPV(gamma_cand), dnn::pfCand_gamma_fromPV - PFg_index_offset);
2142 get(dnn::pfCand_gamma_puppiWeight + fill_index_offset_PFg) =
2143 is_inner ? sp.scale(candFunc::getPuppiWeight(gamma_cand, 0.9084110f),
2144 dnn::pfCand_gamma_puppiWeight - PFg_index_offset)
2145 : sp.scale(candFunc::getPuppiWeight(gamma_cand, 0.4211567
f),
2146 dnn::pfCand_gamma_puppiWeight - PFg_index_offset);
2147 get(dnn::pfCand_gamma_puppiWeightNoLep + fill_index_offset_PFg) =
2148 is_inner ? sp.scale(candFunc::getPuppiWeightNoLep(gamma_cand, 0.8857716f),
2149 dnn::pfCand_gamma_puppiWeightNoLep - PFg_index_offset)
2150 : sp.scale(candFunc::getPuppiWeightNoLep(gamma_cand, 0.3822604
f),
2151 dnn::pfCand_gamma_puppiWeightNoLep - PFg_index_offset);
2152 get(dnn::pfCand_gamma_lostInnerHits + fill_index_offset_PFg) =
2153 sp.scale<
int>(candFunc::getLostInnerHits(gamma_cand, 0), dnn::pfCand_gamma_lostInnerHits - PFg_index_offset);
2154 get(dnn::pfCand_gamma_numberOfPixelHits + fill_index_offset_PFg) = sp.scale(
2155 candFunc::getNumberOfPixelHits(gamma_cand, 0), dnn::pfCand_gamma_numberOfPixelHits - PFg_index_offset);
2156 get(dnn::pfCand_gamma_vertex_dx + fill_index_offset_PFg) =
2157 sp.scale(gamma_cand.vertex().x() -
pv.position().x(), dnn::pfCand_gamma_vertex_dx - PFg_index_offset);
2158 get(dnn::pfCand_gamma_vertex_dy + fill_index_offset_PFg) =
2159 sp.scale(gamma_cand.vertex().y() -
pv.position().y(), dnn::pfCand_gamma_vertex_dy - PFg_index_offset);
2160 get(dnn::pfCand_gamma_vertex_dz + fill_index_offset_PFg) =
2161 sp.scale(gamma_cand.vertex().z() -
pv.position().z(), dnn::pfCand_gamma_vertex_dz - PFg_index_offset);
2162 get(dnn::pfCand_gamma_vertex_dx_tauFL + fill_index_offset_PFg) =
2163 sp.scale(gamma_cand.vertex().x() -
pv.position().x() - tau_funcs.getFlightLength(
tau, tau_index).x(),
2164 dnn::pfCand_gamma_vertex_dx_tauFL - PFg_index_offset);
2165 get(dnn::pfCand_gamma_vertex_dy_tauFL + fill_index_offset_PFg) =
2166 sp.scale(gamma_cand.vertex().y() -
pv.position().y() - tau_funcs.getFlightLength(
tau, tau_index).y(),
2167 dnn::pfCand_gamma_vertex_dy_tauFL - PFg_index_offset);
2168 get(dnn::pfCand_gamma_vertex_dz_tauFL + fill_index_offset_PFg) =
2169 sp.scale(gamma_cand.vertex().z() -
pv.position().z() - tau_funcs.getFlightLength(
tau, tau_index).z(),
2170 dnn::pfCand_gamma_vertex_dz_tauFL - PFg_index_offset);
2171 const bool hasTrackDetails = candFunc::getHasTrackDetails(gamma_cand);
2172 if (hasTrackDetails) {
2173 get(dnn::pfCand_gamma_hasTrackDetails + fill_index_offset_PFg) =
2174 sp.scale(hasTrackDetails, dnn::pfCand_gamma_hasTrackDetails - PFg_index_offset);
2175 get(dnn::pfCand_gamma_dxy + fill_index_offset_PFg) =
2176 sp.scale(candFunc::getTauDxy(gamma_cand), dnn::pfCand_gamma_dxy - PFg_index_offset);
2177 get(dnn::pfCand_gamma_dxy_sig + fill_index_offset_PFg) =
2178 sp.scale(
std::abs(candFunc::getTauDxy(gamma_cand)) / gamma_cand.dxyError(),
2179 dnn::pfCand_gamma_dxy_sig - PFg_index_offset);
2180 get(dnn::pfCand_gamma_dz + fill_index_offset_PFg) =
2181 sp.scale(candFunc::getTauDz(gamma_cand), dnn::pfCand_gamma_dz - PFg_index_offset);
2182 get(dnn::pfCand_gamma_dz_sig + fill_index_offset_PFg) =
2183 sp.scale(
std::abs(candFunc::getTauDz(gamma_cand)) / gamma_cand.dzError(),
2184 dnn::pfCand_gamma_dz_sig - PFg_index_offset);
2185 get(dnn::pfCand_gamma_track_chi2_ndof + fill_index_offset_PFg) =
2186 candFunc::getPseudoTrack(gamma_cand).ndof() > 0
2187 ? sp.scale(candFunc::getPseudoTrack(gamma_cand).
chi2() / candFunc::getPseudoTrack(gamma_cand).
ndof(),
2188 dnn::pfCand_gamma_track_chi2_ndof - PFg_index_offset)
2190 get(dnn::pfCand_gamma_track_ndof + fill_index_offset_PFg) =
2191 candFunc::getPseudoTrack(gamma_cand).ndof() > 0
2192 ? sp.scale(candFunc::getPseudoTrack(gamma_cand).
ndof(), dnn::pfCand_gamma_track_ndof - PFg_index_offset)
2196 if (valid_index_ele) {
2197 const sc::ScalingParams& sp =
scalingParamsMap_->at(std::make_pair(ft_e, is_inner));
2199 const auto& ele =
electrons->at(index_ele);
2201 get(dnn::ele_valid + fill_index_offset_e) = sp.scale(valid_index_ele, dnn::ele_valid - e_index_offset);
2202 get(dnn::ele_rel_pt + fill_index_offset_e) =
2203 sp.scale(ele.polarP4().pt() /
tau.polarP4().pt(), dnn::ele_rel_pt - e_index_offset);
2204 get(dnn::ele_deta + fill_index_offset_e) =
2205 sp.scale(ele.polarP4().eta() -
tau.polarP4().eta(), dnn::ele_deta - e_index_offset);
2206 get(dnn::ele_dphi + fill_index_offset_e) =
2207 sp.scale(
dPhi(
tau.polarP4(), ele.polarP4()), dnn::ele_dphi - e_index_offset);
2209 float cc_ele_energy, cc_gamma_energy;
2213 get(dnn::ele_cc_valid + fill_index_offset_e) = sp.scale(cc_valid, dnn::ele_cc_valid - e_index_offset);
2214 get(dnn::ele_cc_ele_rel_energy + fill_index_offset_e) =
2215 sp.scale(cc_ele_energy / ele.polarP4().pt(), dnn::ele_cc_ele_rel_energy - e_index_offset);
2216 get(dnn::ele_cc_gamma_rel_energy + fill_index_offset_e) =
2217 sp.scale(cc_gamma_energy / cc_ele_energy, dnn::ele_cc_gamma_rel_energy - e_index_offset);
2218 get(dnn::ele_cc_n_gamma + fill_index_offset_e) = sp.scale(cc_n_gamma, dnn::ele_cc_n_gamma - e_index_offset);
2220 get(dnn::ele_rel_trackMomentumAtVtx + fill_index_offset_e) =
2221 sp.scale(ele.trackMomentumAtVtx().R() / ele.polarP4().pt(), dnn::ele_rel_trackMomentumAtVtx - e_index_offset);
2222 get(dnn::ele_rel_trackMomentumAtCalo + fill_index_offset_e) = sp.scale(
2223 ele.trackMomentumAtCalo().R() / ele.polarP4().pt(), dnn::ele_rel_trackMomentumAtCalo - e_index_offset);
2224 get(dnn::ele_rel_trackMomentumOut + fill_index_offset_e) =
2225 sp.scale(ele.trackMomentumOut().R() / ele.polarP4().pt(), dnn::ele_rel_trackMomentumOut - e_index_offset);
2226 get(dnn::ele_rel_trackMomentumAtEleClus + fill_index_offset_e) = sp.scale(
2227 ele.trackMomentumAtEleClus().R() / ele.polarP4().pt(), dnn::ele_rel_trackMomentumAtEleClus - e_index_offset);
2228 get(dnn::ele_rel_trackMomentumAtVtxWithConstraint + fill_index_offset_e) =
2229 sp.scale(ele.trackMomentumAtVtxWithConstraint().R() / ele.polarP4().pt(),
2230 dnn::ele_rel_trackMomentumAtVtxWithConstraint - e_index_offset);
2231 get(dnn::ele_rel_ecalEnergy + fill_index_offset_e) =
2232 sp.scale(ele.ecalEnergy() / ele.polarP4().pt(), dnn::ele_rel_ecalEnergy - e_index_offset);
2233 get(dnn::ele_ecalEnergy_sig + fill_index_offset_e) =
2234 sp.scale(ele.ecalEnergy() / ele.ecalEnergyError(), dnn::ele_ecalEnergy_sig - e_index_offset);
2235 get(dnn::ele_eSuperClusterOverP + fill_index_offset_e) =
2236 sp.scale(ele.eSuperClusterOverP(), dnn::ele_eSuperClusterOverP - e_index_offset);
2237 get(dnn::ele_eSeedClusterOverP + fill_index_offset_e) =
2238 sp.scale(ele.eSeedClusterOverP(), dnn::ele_eSeedClusterOverP - e_index_offset);
2239 get(dnn::ele_eSeedClusterOverPout + fill_index_offset_e) =
2240 sp.scale(ele.eSeedClusterOverPout(), dnn::ele_eSeedClusterOverPout - e_index_offset);
2241 get(dnn::ele_eEleClusterOverPout + fill_index_offset_e) =
2242 sp.scale(ele.eEleClusterOverPout(), dnn::ele_eEleClusterOverPout - e_index_offset);
2243 get(dnn::ele_deltaEtaSuperClusterTrackAtVtx + fill_index_offset_e) =
2244 sp.scale(ele.deltaEtaSuperClusterTrackAtVtx(), dnn::ele_deltaEtaSuperClusterTrackAtVtx - e_index_offset);
2245 get(dnn::ele_deltaEtaSeedClusterTrackAtCalo + fill_index_offset_e) =
2246 sp.scale(ele.deltaEtaSeedClusterTrackAtCalo(), dnn::ele_deltaEtaSeedClusterTrackAtCalo - e_index_offset);
2247 get(dnn::ele_deltaEtaEleClusterTrackAtCalo + fill_index_offset_e) =
2248 sp.scale(ele.deltaEtaEleClusterTrackAtCalo(), dnn::ele_deltaEtaEleClusterTrackAtCalo - e_index_offset);
2249 get(dnn::ele_deltaPhiEleClusterTrackAtCalo + fill_index_offset_e) =
2250 sp.scale(ele.deltaPhiEleClusterTrackAtCalo(), dnn::ele_deltaPhiEleClusterTrackAtCalo - e_index_offset);
2251 get(dnn::ele_deltaPhiSuperClusterTrackAtVtx + fill_index_offset_e) =
2252 sp.scale(ele.deltaPhiSuperClusterTrackAtVtx(), dnn::ele_deltaPhiSuperClusterTrackAtVtx - e_index_offset);
2253 get(dnn::ele_deltaPhiSeedClusterTrackAtCalo + fill_index_offset_e) =
2254 sp.scale(ele.deltaPhiSeedClusterTrackAtCalo(), dnn::ele_deltaPhiSeedClusterTrackAtCalo - e_index_offset);
2255 const bool mva_valid =
2256 (ele.mvaInput().earlyBrem > -2) ||
2260 get(dnn::ele_mvaInput_earlyBrem + fill_index_offset_e) =
2261 sp.scale(ele.mvaInput().earlyBrem, dnn::ele_mvaInput_earlyBrem - e_index_offset);
2262 get(dnn::ele_mvaInput_lateBrem + fill_index_offset_e) =
2263 sp.scale(ele.mvaInput().lateBrem, dnn::ele_mvaInput_lateBrem - e_index_offset);
2264 get(dnn::ele_mvaInput_sigmaEtaEta + fill_index_offset_e) =
2265 sp.scale(ele.mvaInput().sigmaEtaEta, dnn::ele_mvaInput_sigmaEtaEta - e_index_offset);
2266 get(dnn::ele_mvaInput_hadEnergy + fill_index_offset_e) =
2267 sp.scale(ele.mvaInput().hadEnergy, dnn::ele_mvaInput_hadEnergy - e_index_offset);
2268 get(dnn::ele_mvaInput_deltaEta + fill_index_offset_e) =
2269 sp.scale(ele.mvaInput().deltaEta, dnn::ele_mvaInput_deltaEta - e_index_offset);
2271 const auto& gsfTrack = ele.gsfTrack();
2272 if (gsfTrack.isNonnull()) {
2273 get(dnn::ele_gsfTrack_normalizedChi2 + fill_index_offset_e) =
2274 sp.scale(gsfTrack->normalizedChi2(), dnn::ele_gsfTrack_normalizedChi2 - e_index_offset);
2275 get(dnn::ele_gsfTrack_numberOfValidHits + fill_index_offset_e) =
2276 sp.scale(gsfTrack->numberOfValidHits(), dnn::ele_gsfTrack_numberOfValidHits - e_index_offset);
2277 get(dnn::ele_rel_gsfTrack_pt + fill_index_offset_e) =
2278 sp.scale(gsfTrack->pt() / ele.polarP4().pt(), dnn::ele_rel_gsfTrack_pt - e_index_offset);
2279 get(dnn::ele_gsfTrack_pt_sig + fill_index_offset_e) =
2280 sp.scale(gsfTrack->pt() / gsfTrack->ptError(), dnn::ele_gsfTrack_pt_sig - e_index_offset);
2282 const auto& closestCtfTrack = ele.closestCtfTrackRef();
2283 const bool has_closestCtfTrack = closestCtfTrack.isNonnull();
2284 if (has_closestCtfTrack) {
2285 get(dnn::ele_has_closestCtfTrack + fill_index_offset_e) =
2286 sp.scale(has_closestCtfTrack, dnn::ele_has_closestCtfTrack - e_index_offset);
2287 get(dnn::ele_closestCtfTrack_normalizedChi2 + fill_index_offset_e) =
2288 sp.scale(closestCtfTrack->normalizedChi2(), dnn::ele_closestCtfTrack_normalizedChi2 - e_index_offset);
2289 get(dnn::ele_closestCtfTrack_numberOfValidHits + fill_index_offset_e) =
2290 sp.scale(closestCtfTrack->numberOfValidHits(), dnn::ele_closestCtfTrack_numberOfValidHits - e_index_offset);
2295 template <
typename Cand
idateCastType,
typename TauCastType>
2297 const TauCastType&
tau,
2298 const size_t tau_index,
2302 const std::vector<pat::Muon>*
muons,
2304 const Cell& cell_map,
2314 int PFmu_index_offset =
scalingParamsMap_->at(std::make_pair(ft_global,
false)).mean_.size();
2315 int mu_index_offset = PFmu_index_offset +
scalingParamsMap_->at(std::make_pair(ft_PFmu,
false)).mean_.size();
2319 const auto&
get = [&](
int var_index) ->
float& {
return inputs.tensor<
float, 4>()(
idx, 0, 0, var_index); };
2321 const bool valid_index_pf_muon = cell_map.count(CellObjectType::PfCand_muon);
2324 if (!cell_map.empty()) {
2325 const sc::ScalingParams& sp =
scalingParamsMap_->at(std::make_pair(ft_global,
false));
2329 get(dnn::tau_inside_ecal_crack) = sp.scale(
isInEcalCrack(
tau.polarP4().eta()), dnn::tau_inside_ecal_crack);
2331 if (valid_index_pf_muon) {
2332 const sc::ScalingParams& sp =
scalingParamsMap_->at(std::make_pair(ft_PFmu, is_inner));
2333 size_t index_pf_muon = cell_map.at(CellObjectType::PfCand_muon);
2334 const auto& muon_cand =
dynamic_cast<const CandidateCastType&
>(pfCands.
at(index_pf_muon));
2336 get(dnn::pfCand_muon_valid) = sp.scale(valid_index_pf_muon, dnn::pfCand_muon_valid - PFmu_index_offset);
2337 get(dnn::pfCand_muon_rel_pt) =
2338 sp.scale(muon_cand.polarP4().pt() /
tau.polarP4().pt(), dnn::pfCand_muon_rel_pt - PFmu_index_offset);
2339 get(dnn::pfCand_muon_deta) =
2340 sp.scale(muon_cand.polarP4().eta() -
tau.polarP4().eta(), dnn::pfCand_muon_deta - PFmu_index_offset);
2341 get(dnn::pfCand_muon_dphi) =
2342 sp.scale(
dPhi(
tau.polarP4(), muon_cand.polarP4()), dnn::pfCand_muon_dphi - PFmu_index_offset);
2343 get(dnn::pfCand_muon_pvAssociationQuality) = sp.scale<
int>(
2344 candFunc::getPvAssocationQuality(muon_cand), dnn::pfCand_muon_pvAssociationQuality - PFmu_index_offset);
2345 get(dnn::pfCand_muon_fromPV) =
2346 sp.scale<
int>(candFunc::getFromPV(muon_cand), dnn::pfCand_muon_fromPV - PFmu_index_offset);
2347 get(dnn::pfCand_muon_puppiWeight) = is_inner ? sp.scale(candFunc::getPuppiWeight(muon_cand, 0.9786588f),
2348 dnn::pfCand_muon_puppiWeight - PFmu_index_offset)
2349 : sp.scale(candFunc::getPuppiWeight(muon_cand, 0.8132477
f),
2350 dnn::pfCand_muon_puppiWeight - PFmu_index_offset);
2351 get(dnn::pfCand_muon_charge) = sp.scale(muon_cand.charge(), dnn::pfCand_muon_charge - PFmu_index_offset);
2352 get(dnn::pfCand_muon_lostInnerHits) =
2353 sp.scale<
int>(candFunc::getLostInnerHits(muon_cand, 0), dnn::pfCand_muon_lostInnerHits - PFmu_index_offset);
2354 get(dnn::pfCand_muon_numberOfPixelHits) = sp.scale(candFunc::getNumberOfPixelHits(muon_cand, 0),
2355 dnn::pfCand_muon_numberOfPixelHits - PFmu_index_offset);
2356 get(dnn::pfCand_muon_vertex_dx) =
2357 sp.scale(muon_cand.vertex().x() -
pv.position().x(), dnn::pfCand_muon_vertex_dx - PFmu_index_offset);
2358 get(dnn::pfCand_muon_vertex_dy) =
2359 sp.scale(muon_cand.vertex().y() -
pv.position().y(), dnn::pfCand_muon_vertex_dy - PFmu_index_offset);
2360 get(dnn::pfCand_muon_vertex_dz) =
2361 sp.scale(muon_cand.vertex().z() -
pv.position().z(), dnn::pfCand_muon_vertex_dz - PFmu_index_offset);
2362 get(dnn::pfCand_muon_vertex_dx_tauFL) =
2363 sp.scale(muon_cand.vertex().x() -
pv.position().x() - tau_funcs.getFlightLength(
tau, tau_index).x(),
2364 dnn::pfCand_muon_vertex_dx_tauFL - PFmu_index_offset);
2365 get(dnn::pfCand_muon_vertex_dy_tauFL) =
2366 sp.scale(muon_cand.vertex().y() -
pv.position().y() - tau_funcs.getFlightLength(
tau, tau_index).y(),
2367 dnn::pfCand_muon_vertex_dy_tauFL - PFmu_index_offset);
2368 get(dnn::pfCand_muon_vertex_dz_tauFL) =
2369 sp.scale(muon_cand.vertex().z() -
pv.position().z() - tau_funcs.getFlightLength(
tau, tau_index).z(),
2370 dnn::pfCand_muon_vertex_dz_tauFL - PFmu_index_offset);
2372 const bool hasTrackDetails = candFunc::getHasTrackDetails(muon_cand);
2373 if (hasTrackDetails) {
2374 get(dnn::pfCand_muon_hasTrackDetails) =
2375 sp.scale(hasTrackDetails, dnn::pfCand_muon_hasTrackDetails - PFmu_index_offset);
2376 get(dnn::pfCand_muon_dxy) = sp.scale(candFunc::getTauDxy(muon_cand), dnn::pfCand_muon_dxy - PFmu_index_offset);
2377 get(dnn::pfCand_muon_dxy_sig) = sp.scale(
std::abs(candFunc::getTauDxy(muon_cand)) / muon_cand.dxyError(),
2378 dnn::pfCand_muon_dxy_sig - PFmu_index_offset);
2379 get(dnn::pfCand_muon_dz) = sp.scale(candFunc::getTauDz(muon_cand), dnn::pfCand_muon_dz - PFmu_index_offset);
2380 get(dnn::pfCand_muon_dz_sig) = sp.scale(
std::abs(candFunc::getTauDz(muon_cand)) / muon_cand.dzError(),
2381 dnn::pfCand_muon_dz_sig - PFmu_index_offset);
2382 get(dnn::pfCand_muon_track_chi2_ndof) =
2383 candFunc::getPseudoTrack(muon_cand).ndof() > 0
2384 ? sp.scale(candFunc::getPseudoTrack(muon_cand).
chi2() / candFunc::getPseudoTrack(muon_cand).
ndof(),
2385 dnn::pfCand_muon_track_chi2_ndof - PFmu_index_offset)
2387 get(dnn::pfCand_muon_track_ndof) =
2388 candFunc::getPseudoTrack(muon_cand).ndof() > 0
2389 ? sp.scale(candFunc::getPseudoTrack(muon_cand).
ndof(), dnn::pfCand_muon_track_ndof - PFmu_index_offset)
2393 if (valid_index_muon) {
2394 const sc::ScalingParams& sp =
scalingParamsMap_->at(std::make_pair(ft_mu, is_inner));
2396 const auto&
muon =
muons->at(index_muon);
2398 get(dnn::muon_valid) = sp.scale(valid_index_muon, dnn::muon_valid - mu_index_offset);
2399 get(dnn::muon_rel_pt) = sp.scale(
muon.polarP4().pt() /
tau.polarP4().pt(), dnn::muon_rel_pt - mu_index_offset);
2400 get(dnn::muon_deta) = sp.scale(
muon.polarP4().eta() -
tau.polarP4().eta(), dnn::muon_deta - mu_index_offset);
2401 get(dnn::muon_dphi) = sp.scale(
dPhi(
tau.polarP4(),
muon.polarP4()), dnn::muon_dphi - mu_index_offset);
2403 get(dnn::muon_dxy_sig) =
2406 const bool normalizedChi2_valid =
muon.globalTrack().isNonnull() &&
muon.normChi2() >= 0;
2407 if (normalizedChi2_valid) {
2408 get(dnn::muon_normalizedChi2_valid) =
2409 sp.scale(normalizedChi2_valid, dnn::muon_normalizedChi2_valid - mu_index_offset);
2410 get(dnn::muon_normalizedChi2) = sp.scale(
muon.normChi2(), dnn::muon_normalizedChi2 - mu_index_offset);
2411 if (
muon.innerTrack().isNonnull())
2412 get(dnn::muon_numberOfValidHits) =
2413 sp.scale(
muon.numberOfValidHits(), dnn::muon_numberOfValidHits - mu_index_offset);
2415 get(dnn::muon_segmentCompatibility) =
2416 sp.scale(
muon.segmentCompatibility(), dnn::muon_segmentCompatibility - mu_index_offset);
2417 get(dnn::muon_caloCompatibility) =
2418 sp.scale(
muon.caloCompatibility(), dnn::muon_caloCompatibility - mu_index_offset);
2420 const bool pfEcalEnergy_valid =
muon.pfEcalEnergy() >= 0;
2421 if (pfEcalEnergy_valid) {
2422 get(dnn::muon_pfEcalEnergy_valid) =
2423 sp.scale(pfEcalEnergy_valid, dnn::muon_pfEcalEnergy_valid - mu_index_offset);
2424 get(dnn::muon_rel_pfEcalEnergy) =
2425 sp.scale(
muon.pfEcalEnergy() /
muon.polarP4().pt(), dnn::muon_rel_pfEcalEnergy - mu_index_offset);
2428 MuonHitMatchV2 hit_match(
muon);
2429 static const std::map<int, std::pair<int, int>> muonMatchHitVars = {
2434 for (
int subdet : hit_match.MuonHitMatchV2::consideredSubdets()) {
2435 const auto& matchHitVar = muonMatchHitVars.at(subdet);
2436 for (
int station = MuonHitMatchV2::first_station_id;
station <= MuonHitMatchV2::last_station_id; ++
station) {
2437 const unsigned n_matches = hit_match.nMatches(subdet,
station);
2438 const unsigned n_hits = hit_match.nHits(subdet,
station);
2439 get(matchHitVar.first +
station - 1) = sp.scale(n_matches, matchHitVar.first +
station - 1 - mu_index_offset);
2440 get(matchHitVar.second +
station - 1) = sp.scale(n_hits, matchHitVar.second +
station - 1 - mu_index_offset);
2446 template <
typename Cand
idateCastType,
typename TauCastType>
2448 const TauCastType&
tau,
2449 const size_t tau_index,
2454 const Cell& cell_map,
2464 int PFchH_index_offset =
scalingParamsMap_->at(std::make_pair(ft_global,
false)).mean_.size();
2465 int PFnH_index_offset = PFchH_index_offset +
scalingParamsMap_->at(std::make_pair(ft_PFchH,
false)).mean_.size();
2469 const auto&
get = [&](
int var_index) ->
float& {
return inputs.tensor<
float, 4>()(
idx, 0, 0, var_index); };
2471 const bool valid_chH = cell_map.count(CellObjectType::PfCand_chargedHadron);
2472 const bool valid_nH = cell_map.count(CellObjectType::PfCand_neutralHadron);
2474 if (!cell_map.empty()) {
2475 const sc::ScalingParams& sp =
scalingParamsMap_->at(std::make_pair(ft_global,
false));
2479 get(dnn::tau_inside_ecal_crack) = sp.scale(
isInEcalCrack(
tau.polarP4().eta()), dnn::tau_inside_ecal_crack);
2482 const sc::ScalingParams& sp =
scalingParamsMap_->at(std::make_pair(ft_PFchH, is_inner));
2483 size_t index_chH = cell_map.at(CellObjectType::PfCand_chargedHadron);
2484 const auto& chH_cand =
dynamic_cast<const CandidateCastType&
>(pfCands.
at(index_chH));
2486 get(dnn::pfCand_chHad_valid) = sp.scale(valid_chH, dnn::pfCand_chHad_valid - PFchH_index_offset);
2487 get(dnn::pfCand_chHad_rel_pt) =
2488 sp.scale(chH_cand.polarP4().pt() /
tau.polarP4().pt(), dnn::pfCand_chHad_rel_pt - PFchH_index_offset);
2489 get(dnn::pfCand_chHad_deta) =
2490 sp.scale(chH_cand.polarP4().eta() -
tau.polarP4().eta(), dnn::pfCand_chHad_deta - PFchH_index_offset);
2491 get(dnn::pfCand_chHad_dphi) =
2492 sp.scale(
dPhi(
tau.polarP4(), chH_cand.polarP4()), dnn::pfCand_chHad_dphi - PFchH_index_offset);
2493 get(dnn::pfCand_chHad_leadChargedHadrCand) =
2494 sp.scale(&chH_cand == dynamic_cast<const CandidateCastType*>(
tau.leadChargedHadrCand().get()),
2495 dnn::pfCand_chHad_leadChargedHadrCand - PFchH_index_offset);
2496 get(dnn::pfCand_chHad_pvAssociationQuality) = sp.scale<
int>(
2497 candFunc::getPvAssocationQuality(chH_cand), dnn::pfCand_chHad_pvAssociationQuality - PFchH_index_offset);
2498 get(dnn::pfCand_chHad_fromPV) =
2499 sp.scale<
int>(candFunc::getFromPV(chH_cand), dnn::pfCand_chHad_fromPV - PFchH_index_offset);
2500 const float default_chH_pw_inner = 0.7614090f;
2501 const float default_chH_pw_outer = 0.1974930f;
2502 get(dnn::pfCand_chHad_puppiWeight) = is_inner ? sp.scale(candFunc::getPuppiWeight(chH_cand, default_chH_pw_inner),
2503 dnn::pfCand_chHad_puppiWeight - PFchH_index_offset)
2504 : sp.scale(candFunc::getPuppiWeight(chH_cand, default_chH_pw_outer),
2505 dnn::pfCand_chHad_puppiWeight - PFchH_index_offset);
2506 get(dnn::pfCand_chHad_puppiWeightNoLep) =
2507 is_inner ? sp.scale(candFunc::getPuppiWeightNoLep(chH_cand, default_chH_pw_inner),
2508 dnn::pfCand_chHad_puppiWeightNoLep - PFchH_index_offset)
2509 : sp.scale(candFunc::getPuppiWeightNoLep(chH_cand, default_chH_pw_outer),
2510 dnn::pfCand_chHad_puppiWeightNoLep - PFchH_index_offset);
2511 get(dnn::pfCand_chHad_charge) = sp.scale(chH_cand.charge(), dnn::pfCand_chHad_charge - PFchH_index_offset);
2512 get(dnn::pfCand_chHad_lostInnerHits) =
2513 sp.scale<
int>(candFunc::getLostInnerHits(chH_cand, 0), dnn::pfCand_chHad_lostInnerHits - PFchH_index_offset);
2514 get(dnn::pfCand_chHad_numberOfPixelHits) = sp.scale(candFunc::getNumberOfPixelHits(chH_cand, 0),
2515 dnn::pfCand_chHad_numberOfPixelHits - PFchH_index_offset);
2516 get(dnn::pfCand_chHad_vertex_dx) =
2517 sp.scale(chH_cand.vertex().x() -
pv.position().x(), dnn::pfCand_chHad_vertex_dx - PFchH_index_offset);
2518 get(dnn::pfCand_chHad_vertex_dy) =
2519 sp.scale(chH_cand.vertex().y() -
pv.position().y(), dnn::pfCand_chHad_vertex_dy - PFchH_index_offset);
2520 get(dnn::pfCand_chHad_vertex_dz) =
2521 sp.scale(chH_cand.vertex().z() -
pv.position().z(), dnn::pfCand_chHad_vertex_dz - PFchH_index_offset);
2522 get(dnn::pfCand_chHad_vertex_dx_tauFL) =
2523 sp.scale(chH_cand.vertex().x() -
pv.position().x() - tau_funcs.getFlightLength(
tau, tau_index).x(),
2524 dnn::pfCand_chHad_vertex_dx_tauFL - PFchH_index_offset);
2525 get(dnn::pfCand_chHad_vertex_dy_tauFL) =
2526 sp.scale(chH_cand.vertex().y() -
pv.position().y() - tau_funcs.getFlightLength(
tau, tau_index).y(),
2527 dnn::pfCand_chHad_vertex_dy_tauFL - PFchH_index_offset);
2528 get(dnn::pfCand_chHad_vertex_dz_tauFL) =
2529 sp.scale(chH_cand.vertex().z() -
pv.position().z() - tau_funcs.getFlightLength(
tau, tau_index).z(),
2530 dnn::pfCand_chHad_vertex_dz_tauFL - PFchH_index_offset);
2532 const bool hasTrackDetails = candFunc::getHasTrackDetails(chH_cand);
2533 if (hasTrackDetails) {
2534 get(dnn::pfCand_chHad_hasTrackDetails) =
2535 sp.scale(hasTrackDetails, dnn::pfCand_chHad_hasTrackDetails - PFchH_index_offset);
2536 get(dnn::pfCand_chHad_dxy) =
2537 sp.scale(candFunc::getTauDxy(chH_cand), dnn::pfCand_chHad_dxy - PFchH_index_offset);
2538 get(dnn::pfCand_chHad_dxy_sig) = sp.scale(
std::abs(candFunc::getTauDxy(chH_cand)) / chH_cand.dxyError(),
2539 dnn::pfCand_chHad_dxy_sig - PFchH_index_offset);
2540 get(dnn::pfCand_chHad_dz) = sp.scale(candFunc::getTauDz(chH_cand), dnn::pfCand_chHad_dz - PFchH_index_offset);
2541 get(dnn::pfCand_chHad_dz_sig) = sp.scale(
std::abs(candFunc::getTauDz(chH_cand)) / chH_cand.dzError(),
2542 dnn::pfCand_chHad_dz_sig - PFchH_index_offset);
2543 get(dnn::pfCand_chHad_track_chi2_ndof) =
2544 candFunc::getPseudoTrack(chH_cand).ndof() > 0
2545 ? sp.scale(candFunc::getPseudoTrack(chH_cand).
chi2() / candFunc::getPseudoTrack(chH_cand).
ndof(),
2546 dnn::pfCand_chHad_track_chi2_ndof - PFchH_index_offset)
2548 get(dnn::pfCand_chHad_track_ndof) =
2549 candFunc::getPseudoTrack(chH_cand).ndof() > 0
2550 ? sp.scale(candFunc::getPseudoTrack(chH_cand).
ndof(), dnn::pfCand_chHad_track_ndof - PFchH_index_offset)
2554 get(dnn::pfCand_chHad_hcalFraction) =
2555 sp.scale(hcal_fraction, dnn::pfCand_chHad_hcalFraction - PFchH_index_offset);
2556 get(dnn::pfCand_chHad_rawCaloFraction) =
2557 sp.scale(candFunc::getRawCaloFraction(chH_cand), dnn::pfCand_chHad_rawCaloFraction - PFchH_index_offset);
2560 const sc::ScalingParams& sp =
scalingParamsMap_->at(std::make_pair(ft_PFnH, is_inner));
2561 size_t index_nH = cell_map.at(CellObjectType::PfCand_neutralHadron);
2562 const auto& nH_cand =
dynamic_cast<const CandidateCastType&
>(pfCands.
at(index_nH));
2564 get(dnn::pfCand_nHad_valid) = sp.scale(valid_nH, dnn::pfCand_nHad_valid - PFnH_index_offset);
2565 get(dnn::pfCand_nHad_rel_pt) =
2566 sp.scale(nH_cand.polarP4().pt() /
tau.polarP4().pt(), dnn::pfCand_nHad_rel_pt - PFnH_index_offset);
2567 get(dnn::pfCand_nHad_deta) =
2568 sp.scale(nH_cand.polarP4().eta() -
tau.polarP4().eta(), dnn::pfCand_nHad_deta - PFnH_index_offset);
2569 get(dnn::pfCand_nHad_dphi) =
2570 sp.scale(
dPhi(
tau.polarP4(), nH_cand.polarP4()), dnn::pfCand_nHad_dphi - PFnH_index_offset);
2571 get(dnn::pfCand_nHad_puppiWeight) = is_inner ? sp.scale(candFunc::getPuppiWeight(nH_cand, 0.9798355f),
2572 dnn::pfCand_nHad_puppiWeight - PFnH_index_offset)
2573 : sp.scale(candFunc::getPuppiWeight(nH_cand, 0.7813260
f),
2574 dnn::pfCand_nHad_puppiWeight - PFnH_index_offset);
2575 get(dnn::pfCand_nHad_puppiWeightNoLep) = is_inner
2576 ? sp.scale(candFunc::getPuppiWeightNoLep(nH_cand, 0.9046796f),
2577 dnn::pfCand_nHad_puppiWeightNoLep - PFnH_index_offset)
2578 : sp.scale(candFunc::getPuppiWeightNoLep(nH_cand, 0.6554860
f),
2579 dnn::pfCand_nHad_puppiWeightNoLep - PFnH_index_offset);
2581 get(dnn::pfCand_nHad_hcalFraction) = sp.scale(hcal_fraction, dnn::pfCand_nHad_hcalFraction - PFnH_index_offset);
2587 elecEe = elecEgamma = 0;
2589 if (superCluster.isNonnull() && superCluster.isAvailable() && superCluster->clusters().isNonnull() &&
2590 superCluster->clusters().isAvailable()) {
2591 for (
auto iter = superCluster->clustersBegin(); iter != superCluster->clustersEnd(); ++iter) {
2592 const double energy = (*iter)->energy();
2593 if (iter == superCluster->clustersBegin())
2604 template <
typename Cand
idateCollection,
typename TauCastType>
2627 const bool isInside_innerSigCone =
dR < innerSigCone_radius;
2628 if (isInside_innerSigCone) {
2629 p4_inner +=
cand->p4();
2632 p4_outer +=
cand->p4();
2648 template <
typename Cand
idateCollection,
typename TauCastType>
2672 static constexpr
double min_pt = 30., min_radius = 0.05, cone_opening_coef = 3.;
2678 template <
typename TauCastType>
2680 const size_t tau_index,
2682 TauFunc tau_funcs) {
2683 if (tau_funcs.getHasSecondaryVertex(
tau, tau_index)) {
2684 static constexpr
double mTau = 1.77682;
2685 const double mAOne =
tau.p4().M();
2686 const double pAOneMag =
tau.p();
2687 const double argumentThetaGJmax = (
std::pow(mTau, 2) -
std::pow(mAOne, 2)) / (2 * mTau * pAOneMag);
2688 const double argumentThetaGJmeasured =
tau.p4().Vect().Dot(tau_funcs.getFlightLength(
tau, tau_index)) /
2689 (pAOneMag * tau_funcs.getFlightLength(
tau, tau_index).R());
2690 if (
std::abs(argumentThetaGJmax) <= 1. &&
std::abs(argumentThetaGJmeasured) <= 1.) {
2691 double thetaGJmax = std::asin(argumentThetaGJmax);
2692 double thetaGJmeasured = std::acos(argumentThetaGJmeasured);
2693 gj_diff = thetaGJmeasured - thetaGJmax;
2700 template <
typename TauCastType>
2702 const size_t tau_index,
2703 TauFunc tau_funcs) {
2706 return static_cast<float>(gj_diff);
2712 return abs_eta > 1.46 && abs_eta < 1.558;
2715 template <
typename TauCastType>
2717 const std::vector<pat::Electron>*
electrons,
2722 if (
reco::deltaR2(
tau.p4(), ele.p4()) < dR2 && (!matched_ele || matched_ele->
pt() < ele.pt())) {
void createConvFeatures(const TauCastType &tau, const size_t tau_index, const edm::RefToBase< reco::BaseTau > tau_ref, const reco::Vertex &pv, double rho, const std::vector< pat::Electron > *electrons, const std::vector< pat::Muon > *muons, const edm::View< reco::Candidate > &pfCands, const CellGrid &grid, TauFunc tau_funcs, bool is_inner)
static constexpr float default_value
constexpr double deltaPhi(double phi1, double phi2)
std::unique_ptr< Cutter > CutterPtr
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)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
tensorflow::Tensor getPredictions(edm::Event &event, edm::Handle< TauCollection > taus)
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::array< std::unique_ptr< tensorflow::Tensor >, 2 > hadronsTensor_
std::map< BasicDiscriminator, size_t > basicDiscrdR03IndexMap_
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
std::map< std::string, WPList > workingPoints_
static void processIsolationPFComponents(const TauCastType &tau, const CandidateCollection &candidates, LorentzVectorXYZ &p4, float &pt, float &d_eta, float &d_phi, float &m, float &n)
static std::unique_ptr< deep_tau::DeepTauCache > initializeGlobalCache(const edm::ParameterSet &cfg)
double pt() const final
transverse momentum
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)
DeepTauCache(const std::map< std::string, std::string > &graph_names, bool mem_mapped)
float pt_weighted_dr_signal(const reco::PFTau &tau, int dm)
std::string fullPath() const
std::unique_ptr< TF1 > fn_
const bool disable_dxy_pca_
static float getValueLinear(T value, float min_value, float max_value, bool positive)
static const pat::Electron * findMatchedElectron(const TauCastType &tau, const std::vector< pat::Electron > *electrons, double deltaR)
constexpr bool isNotFinite(T x)
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)
void fillGrids(const TauCastType &tau, const Collection &objects, CellGrid &inner_grid, CellGrid &outer_grid)
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > zeroOutputTensor_
std::map< BasicDiscriminator, size_t > basicDiscrIndexMap_
std::map< std::string, tensorflow::Session * > sessions_
edm::EDGetTokenT< reco::VertexCollection > vtxToken_
GraphDef * loadGraphDef(const std::string &pbFile)
static double getInnerSignalConeRadius(double pt)
std::vector< TauDiscInfo< reco::PFTauDiscriminator > > recoPrediscriminants_
uint8_t andPrediscriminants_
std::ofstream * json_file_
unsigned long long EventNumber_t
OutputCollection outputs_
static bool isAbove(double value, double min)
static bool isInEcalCrack(double eta)
void setCellConvFeatures(tensorflow::Tensor &convTensor, const tensorflow::Tensor &features, unsigned batch_idx, int eta_index, int phi_index)
std::vector< TauDiscInfo< pat::PATTauDiscriminator > > patPrediscriminants_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
pat::ElectronCollection ElectronCollection
const unsigned sub_version_
pfTauTransverseImpactParameters
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)
void getPredictionsV2(TauCollection::const_reference &tau, const size_t tau_index, const edm::RefToBase< reco::BaseTau > tau_ref, const std::vector< pat::Electron > *electrons, const std::vector< pat::Muon > *muons, const edm::View< reco::Candidate > &pfCands, const reco::Vertex &pv, double rho, const edm::EventNumber_t &eventnr, std::vector< tensorflow::Tensor > &pred_vector, TauFunc tau_funcs)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
std::vector< Vertex > VertexCollection
edm::RefProd< PFTauCollection > PFTauRefProd
references to PFTau collection
const std::map< ValueQuantityType, double > min_value
ParameterSet const & parameterSet(StableProvenance const &provenance, ProcessHistory const &history)
edm::EDGetTokenT< TauCollection > tausToken_
static const double deltaEta
static std::string to_string(const XMLCh *ch)
const std::map< std::pair< deep_tau::Scaling::FeatureT, bool >, deep_tau::Scaling::ScalingParams > * scalingParamsMap_
static const OutputCollection & GetOutputs()
static std::string const input
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > convTensor_
DeepTauId(const edm::ParameterSet &cfg, const deep_tau::DeepTauCache *cache)
const std::map< std::pair< FeatureT, bool >, ScalingParams > scalingParamsMap_v2p5
std::unique_ptr< TauDiscriminator > get_value(const edm::Handle< TauCollection > &taus, const tensorflow::Tensor &pred, const WPList *working_points, bool is_online) const
void fill(const edm::Event &evt)
const deep_tau::DeepTauCache * cache_
edm::EDGetTokenT< CandidateCollection > pfcandToken_
std::string output_layer_
std::vector< Electron > ElectronCollection
std::shared_ptr< tensorflow::GraphDef > GraphPtr
static constexpr float pi
static float getValue(T value)
const tensorflow::GraphDef & getGraph(const std::string &name="") const
float pt_weighted_deta_strip(const reco::PFTau &tau, int dm)
std::vector< float > features(const reco::PreId &ecal, const reco::PreId &hcal, double rho, const reco::BeamSpot &spot, noZS::EcalClusterLazyTools &ecalTools)
const std::map< BasicDiscriminator, size_t > matchDiscriminatorIndices(edm::Event &event, edm::EDGetTokenT< reco::TauDiscriminatorContainer > discriminatorContainerToken, std::vector< BasicDiscriminator > requiredDiscr)
TauWPThreshold(const std::string &cut_str)
edm::Handle< ConsumeType > handle
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
void run(Session *session, const NamedTensorList &inputs, const std::vector< std::string > &outputNames, std::vector< Tensor > *outputs, const thread::ThreadPoolOptions &threadPoolOptions)
void saveInputs(const tensorflow::Tensor &inputs, const std::string &block_name, int n_inputs, const CellGrid *grid=nullptr)
const bool disable_CellIndex_workaround_
bool closeSession(Session *&session)
static float getValueNorm(T value, float mean, float sigma, float n_sigmas_max=5)
Abs< T >::type abs(const T &t)
float pt_weighted_dr_iso(const reco::PFTau &tau, int dm)
basicTauDiscriminatorsdR03
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)
#define DEFINE_FWK_MODULE(type)
static void globalEndJob(const deep_tau::DeepTauCache *cache_)
std::vector< size_t > den_
std::vector< size_t > num_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void checkInputs(const tensorflow::Tensor &inputs, const std::string &block_name, int n_inputs, const CellGrid *grid=nullptr) const
tensorflow::Session & getSession(const std::string &name="") const
const_reference at(size_type pos) const
Analysis-level tau class.
const std::map< std::pair< FeatureT, bool >, ScalingParams > scalingParamsMap_v2p1
Session * createSession()
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
const std::vector< BasicDiscriminator > requiredBasicDiscriminators_
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > LorentzVectorXYZ
tensorflow::Tensor getPartialPredictions(bool is_inner)
const std::vector< BasicDiscriminator > requiredBasicDiscriminatorsdR03_
static bool calculateGottfriedJacksonAngleDifference(const TauCastType &tau, const size_t tau_index, double &gj_diff, TauFunc tau_funcs)
edm::EDGetTokenT< edm::AssociationVector< reco::PFTauRefProd, std::vector< reco::PFTauTransverseImpactParameterRef > > > pfTauTransverseImpactParameters_token_
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
edm::ValueMap< SingleTauDiscriminatorContainer > TauDiscriminatorContainer
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)
float pt_weighted_dphi_strip(const reco::PFTau &tau, int dm)
double operator()(const reco::BaseTau &tau, bool isPFTau) const
float eratio(const reco::PFTau &tau)
return ratio of energy in ECAL over sum of energy in ECAL and HCAL
void createOutputs(edm::Event &event, const tensorflow::Tensor &pred, edm::Handle< TauCollection > taus)
Analysis-level electron class.
void add(std::string const &label, ParameterSetDescription const &psetDescription)
disable_CellIndex_workaround
pat::MuonCollection MuonCollection
edm::Ref< PFTauTransverseImpactParameterCollection > PFTauTransverseImpactParameterRef
presistent reference to a PFTauTransverseImpactParameter
edm::EDGetTokenT< reco::TauDiscriminatorContainer > basicTauDiscriminators_inputToken_
std::vector< Muon > MuonCollection
bool operator<(DTCELinkId const &lhs, DTCELinkId const &rhs)
static float calculateGottfriedJacksonAngleDifference(const TauCastType &tau, const size_t tau_index, TauFunc tau_funcs)
static bool calculateElectronClusterVarsV2(const pat::Electron &ele, float &cc_ele_energy, float &cc_gamma_energy, int &cc_n_gamma)
Particle reconstructed by the particle flow algorithm.
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > eGammaTensor_
const bool disable_hcalFraction_workaround_
edm::EDGetTokenT< reco::TauDiscriminatorContainer > basicTauDiscriminatorsdR03_inputToken_
std::map< std::string, GraphPtr > graphs_
const std::map< ValueQuantityType, double > max_value
disable_hcalFraction_workaround
const std::map< BasicDiscriminator, std::string > stringFromDiscriminator_
std::vector< int > tauInputs_indices_
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
float lead_track_chi2(const reco::PFTau &tau)
return chi2 of the leading track ==> deprecated? <==
std::map< std::string, std::unique_ptr< tensorflow::MemmappedEnv > > memmappedEnv_
Log< level::Warning, false > LogWarning
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > muonTensor_
edm::EDGetTokenT< std::vector< pat::Electron > > electrons_token_
TupleMultiplicity< TrackerTraits > const *__restrict__ uint32_t nHits
Output(const std::vector< size_t > &num, const std::vector< size_t > &den)
void produce(edm::Event &event, const edm::EventSetup &es) override
edm::EDGetTokenT< std::vector< pat::Muon > > muons_token_
T operator[](int i) const
edm::EDGetTokenT< double > rho_token_
static void calculateElectronClusterVars(const pat::Electron *ele, float &elecEe, float &elecEgamma)
T const & const_reference
static const std::string subdets[7]
const std::map< std::pair< FeatureT, bool >, ScalingParams > scalingParamsMap_PhaseIIv2p5
Analysis-level muon class.
std::map< std::string, Output > OutputCollection
void countHits(const reco::Muon &muon, std::vector< int > &numHitsDT, std::vector< int > &numHitsCSC, std::vector< int > &numHitsRPC)
std::vector< CutterPtr > WPList
edm::EDGetTokenT< ConsumeType > disc_token
constexpr int NumberOfOutputs
std::unique_ptr< tensorflow::Tensor > tauBlockTensor_