CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes
DeepTauId Class Reference
Inheritance diagram for DeepTauId:
edm::stream::EDProducer< edm::GlobalCache< deep_tau::DeepTauCache > >

Classes

struct  Output
 
struct  TauDiscInfo
 

Public Types

using BasicDiscriminator = deep_tau::BasicDiscriminator
 
using CandidateCollection = edm::View< reco::Candidate >
 
using Cutter = tau::TauWPThreshold
 
using CutterPtr = std::unique_ptr< Cutter >
 
using ElectronCollection = pat::ElectronCollection
 
using LorentzVectorXYZ = ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > >
 
using MuonCollection = pat::MuonCollection
 
using OutputCollection = std::map< std::string, Output >
 
using TauCollection = edm::View< reco::BaseTau >
 
using TauDiscriminator = reco::TauDiscriminatorContainer
 
using TauRef = edm::Ref< TauCollection >
 
using TauRefProd = edm::RefProd< TauCollection >
 
using WPList = std::vector< CutterPtr >
 
- Public Types inherited from edm::stream::EDProducer< edm::GlobalCache< deep_tau::DeepTauCache > >
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Public Member Functions

 DeepTauId (const edm::ParameterSet &cfg, const deep_tau::DeepTauCache *cache)
 
const std::map< BasicDiscriminator, size_t > matchDiscriminatorIndices (edm::Event &event, edm::EDGetTokenT< reco::TauDiscriminatorContainer > discriminatorContainerToken, std::vector< BasicDiscriminator > requiredDiscr)
 
void produce (edm::Event &event, const edm::EventSetup &es) override
 
- Public Member Functions inherited from edm::stream::EDProducer< edm::GlobalCache< deep_tau::DeepTauCache > >
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
static const OutputCollectionGetOutputs ()
 
static void globalEndJob (const deep_tau::DeepTauCache *cache_)
 
static std::unique_ptr< deep_tau::DeepTauCacheinitializeGlobalCache (const edm::ParameterSet &cfg)
 

Public Attributes

uint8_t andPrediscriminants_
 
std::vector< TauDiscInfo< pat::PATTauDiscriminator > > patPrediscriminants_
 
std::vector< TauDiscInfo< reco::PFTauDiscriminator > > recoPrediscriminants_
 

Static Public Attributes

static constexpr float default_value = -999.
 

Private Member Functions

void checkInputs (const tensorflow::Tensor &inputs, const std::string &block_name, int n_inputs, const CellGrid *grid=nullptr) const
 
template<typename CandidateCastType , typename TauCastType >
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)
 
template<typename CandidateCastType , typename TauCastType >
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)
 
template<typename CandidateCastType , typename TauCastType >
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)
 
template<typename CandidateCastType , typename TauCastType >
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)
 
void createOutputs (edm::Event &event, const tensorflow::Tensor &pred, edm::Handle< TauCollection > taus)
 
template<typename CandidateCastType , typename TauCastType >
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)
 
template<typename Collection , typename TauCastType >
void fillGrids (const TauCastType &tau, const Collection &objects, CellGrid &inner_grid, CellGrid &outer_grid)
 
tensorflow::Tensor getPartialPredictions (bool is_inner)
 
tensorflow::Tensor getPredictions (edm::Event &event, edm::Handle< TauCollection > taus)
 
template<typename CandidateCastType , typename TauCastType >
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 saveInputs (const tensorflow::Tensor &inputs, const std::string &block_name, int n_inputs, const CellGrid *grid=nullptr)
 
void setCellConvFeatures (tensorflow::Tensor &convTensor, const tensorflow::Tensor &features, unsigned batch_idx, int eta_index, int phi_index)
 

Static Private Member Functions

static void calculateElectronClusterVars (const pat::Electron *ele, float &elecEe, float &elecEgamma)
 
static bool calculateElectronClusterVarsV2 (const pat::Electron &ele, float &cc_ele_energy, float &cc_gamma_energy, int &cc_n_gamma)
 
template<typename TauCastType >
static bool calculateGottfriedJacksonAngleDifference (const TauCastType &tau, const size_t tau_index, double &gj_diff, TauFunc tau_funcs)
 
template<typename TauCastType >
static float calculateGottfriedJacksonAngleDifference (const TauCastType &tau, const size_t tau_index, TauFunc tau_funcs)
 
template<typename TauCastType >
static const pat::ElectronfindMatchedElectron (const TauCastType &tau, const std::vector< pat::Electron > *electrons, double deltaR)
 
static double getInnerSignalConeRadius (double pt)
 
template<typename T >
static float getValue (T value)
 
template<typename T >
static float getValueLinear (T value, float min_value, float max_value, bool positive)
 
template<typename T >
static float getValueNorm (T value, float mean, float sigma, float n_sigmas_max=5)
 
static bool isAbove (double value, double min)
 
static bool isInEcalCrack (double eta)
 
template<typename CandidateCollection , typename TauCastType >
static void processIsolationPFComponents (const TauCastType &tau, const CandidateCollection &candidates, LorentzVectorXYZ &p4, float &pt, float &d_eta, float &d_phi, float &m, float &n)
 
template<typename CandidateCollection , typename TauCastType >
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)
 

Private Attributes

std::map< BasicDiscriminator, size_t > basicDiscrdR03IndexMap_
 
std::map< BasicDiscriminator, size_t > basicDiscrIndexMap_
 
edm::EDGetTokenT< reco::TauDiscriminatorContainerbasicTauDiscriminators_inputToken_
 
edm::EDGetTokenT< reco::TauDiscriminatorContainerbasicTauDiscriminatorsdR03_inputToken_
 
const deep_tau::DeepTauCachecache_
 
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > convTensor_
 
const int debug_level
 
const bool disable_CellIndex_workaround_
 
const bool disable_dxy_pca_
 
const bool disable_hcalFraction_workaround_
 
bool discrIndicesMapped_ = false
 
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > eGammaTensor_
 
edm::EDGetTokenT< std::vector< pat::Electron > > electrons_token_
 
int file_counter_
 
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > hadronsTensor_
 
std::string input_layer_
 
bool is_first_block_
 
const bool is_online_
 
std::ofstream * json_file_
 
edm::EDGetTokenT< std::vector< pat::Muon > > muons_token_
 
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > muonTensor_
 
std::string output_layer_
 
OutputCollection outputs_
 
edm::EDGetTokenT< CandidateCollectionpfcandToken_
 
edm::EDGetTokenT< edm::AssociationVector< reco::PFTauRefProd, std::vector< reco::PFTauTransverseImpactParameterRef > > > pfTauTransverseImpactParameters_token_
 
const std::vector< BasicDiscriminatorrequiredBasicDiscriminators_
 
const std::vector< BasicDiscriminatorrequiredBasicDiscriminatorsdR03_
 
edm::EDGetTokenT< double > rho_token_
 
const bool save_inputs_
 
const std::map< std::pair< deep_tau::Scaling::FeatureT, bool >, deep_tau::Scaling::ScalingParams > * scalingParamsMap_
 
const std::map< BasicDiscriminator, std::string > stringFromDiscriminator_
 
const unsigned sub_version_
 
std::unique_ptr< tensorflow::Tensor > tauBlockTensor_
 
std::vector< int > tauInputs_indices_
 
edm::EDGetTokenT< TauCollectiontausToken_
 
const unsigned version_
 
edm::EDGetTokenT< reco::VertexCollectionvtxToken_
 
std::map< std::string, WPListworkingPoints_
 
const unsigned year_
 
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > zeroOutputTensor_
 

Static Private Attributes

static constexpr float pi = M_PI
 

Detailed Description

Definition at line 895 of file DeepTauId.cc.

Member Typedef Documentation

◆ BasicDiscriminator

Definition at line 960 of file DeepTauId.cc.

◆ CandidateCollection

Definition at line 899 of file DeepTauId.cc.

◆ Cutter

Definition at line 905 of file DeepTauId.cc.

◆ CutterPtr

using DeepTauId::CutterPtr = std::unique_ptr<Cutter>

Definition at line 906 of file DeepTauId.cc.

◆ ElectronCollection

Definition at line 902 of file DeepTauId.cc.

◆ LorentzVectorXYZ

using DeepTauId::LorentzVectorXYZ = ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> >

Definition at line 904 of file DeepTauId.cc.

◆ MuonCollection

Definition at line 903 of file DeepTauId.cc.

◆ OutputCollection

using DeepTauId::OutputCollection = std::map<std::string, Output>

Definition at line 946 of file DeepTauId.cc.

◆ TauCollection

Definition at line 898 of file DeepTauId.cc.

◆ TauDiscriminator

Definition at line 897 of file DeepTauId.cc.

◆ TauRef

Definition at line 900 of file DeepTauId.cc.

◆ TauRefProd

Definition at line 901 of file DeepTauId.cc.

◆ WPList

using DeepTauId::WPList = std::vector<CutterPtr>

Definition at line 907 of file DeepTauId.cc.

Constructor & Destructor Documentation

◆ DeepTauId()

DeepTauId::DeepTauId ( const edm::ParameterSet cfg,
const deep_tau::DeepTauCache cache 
)
inlineexplicit

Definition at line 1039 of file DeepTauId.cc.

References andPrediscriminants_, looper::cfg, convTensor_, DMR_cfg::cut, DeepTauId::TauDiscInfo< ConsumeType >::cut, DeepTauId::TauDiscInfo< ConsumeType >::disc_token, eGammaTensor_, nanoDQM_cfi::Electron, mps_fire::end, Exception, edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterNamesForType(), getPartialPredictions(), hadronsTensor_, mps_fire::i, is_online_, label, DeepTauId::TauDiscInfo< ConsumeType >::label, dumpRecoGeometry_cfg::Muon, muonTensor_, dqmiodumpmetadata::n, outputs_, AlCaHLTBitMon_ParallelJobs::p, patPrediscriminants_, recoPrediscriminants_, scalingParamsMap_, deep_tau::Scaling::scalingParamsMap_PhaseIIv2p5, deep_tau::Scaling::scalingParamsMap_v2p1, deep_tau::Scaling::scalingParamsMap_v2p5, setCellConvFeatures(), findQualityFiles::size, jetUpdater_cfi::sort, AlCaHLTBitMon_QueryRunRegistry::string, sub_version_, tauBlockTensor_, tauInputs_indices_, HcalDetIdTransform::transform(), findQualityFiles::v, version_, workingPoints_, year_, and zeroOutputTensor_.

1040  : tausToken_(consumes<TauCollection>(cfg.getParameter<edm::InputTag>("taus"))),
1041  pfcandToken_(consumes<CandidateCollection>(cfg.getParameter<edm::InputTag>("pfcands"))),
1042  vtxToken_(consumes<reco::VertexCollection>(cfg.getParameter<edm::InputTag>("vertices"))),
1043  is_online_(cfg.getParameter<bool>("is_online")),
1044  outputs_(GetOutputs()),
1045  cache_(cache),
1046  electrons_token_(consumes<std::vector<pat::Electron>>(cfg.getParameter<edm::InputTag>("electrons"))),
1047  muons_token_(consumes<std::vector<pat::Muon>>(cfg.getParameter<edm::InputTag>("muons"))),
1048  rho_token_(consumes<double>(cfg.getParameter<edm::InputTag>("rho"))),
1049  basicTauDiscriminators_inputToken_(consumes<reco::TauDiscriminatorContainer>(
1050  cfg.getUntrackedParameter<edm::InputTag>("basicTauDiscriminators"))),
1051  basicTauDiscriminatorsdR03_inputToken_(consumes<reco::TauDiscriminatorContainer>(
1052  cfg.getUntrackedParameter<edm::InputTag>("basicTauDiscriminatorsdR03"))),
1054  consumes<edm::AssociationVector<reco::PFTauRefProd, std::vector<reco::PFTauTransverseImpactParameterRef>>>(
1055  cfg.getParameter<edm::InputTag>("pfTauTransverseImpactParameters"))),
1056  year_(cfg.getParameter<unsigned>("year")),
1057  version_(cfg.getParameter<unsigned>("version")),
1058  sub_version_(cfg.getParameter<unsigned>("sub_version")),
1059  debug_level(cfg.getParameter<int>("debug_level")),
1060  disable_dxy_pca_(cfg.getParameter<bool>("disable_dxy_pca")),
1061  disable_hcalFraction_workaround_(cfg.getParameter<bool>("disable_hcalFraction_workaround")),
1062  disable_CellIndex_workaround_(cfg.getParameter<bool>("disable_CellIndex_workaround")),
1063  save_inputs_(cfg.getParameter<bool>("save_inputs")),
1064  json_file_(nullptr),
1065  file_counter_(0) {
1066  for (const auto& output_desc : outputs_) {
1067  produces<TauDiscriminator>(output_desc.first);
1068  const auto& cut_list = cfg.getParameter<std::vector<std::string>>(output_desc.first + "WP");
1069  for (const std::string& cut_str : cut_list) {
1070  workingPoints_[output_desc.first].push_back(std::make_unique<Cutter>(cut_str));
1071  }
1072  }
1073 
1074  // prediscriminant operator
1075  // require the tau to pass the following prediscriminants
1076  const edm::ParameterSet& prediscriminantConfig = cfg.getParameter<edm::ParameterSet>("Prediscriminants");
1077 
1078  // determine boolean operator used on the prediscriminants
1079  std::string pdBoolOperator = prediscriminantConfig.getParameter<std::string>("BooleanOperator");
1080  // convert string to lowercase
1081  transform(pdBoolOperator.begin(), pdBoolOperator.end(), pdBoolOperator.begin(), ::tolower);
1082 
1083  if (pdBoolOperator == "and") {
1084  andPrediscriminants_ = 0x1; //use chars instead of bools so we can do a bitwise trick later
1085  } else if (pdBoolOperator == "or") {
1086  andPrediscriminants_ = 0x0;
1087  } else {
1088  throw cms::Exception("TauDiscriminationProducerBase")
1089  << "PrediscriminantBooleanOperator defined incorrectly, options are: AND,OR";
1090  }
1091 
1092  // get the list of prediscriminants
1093  std::vector<std::string> prediscriminantsNames =
1094  prediscriminantConfig.getParameterNamesForType<edm::ParameterSet>();
1095 
1096  for (auto const& iDisc : prediscriminantsNames) {
1097  const edm::ParameterSet& iPredisc = prediscriminantConfig.getParameter<edm::ParameterSet>(iDisc);
1098  const edm::InputTag& label = iPredisc.getParameter<edm::InputTag>("Producer");
1099  double cut = iPredisc.getParameter<double>("cut");
1100 
1101  if (is_online_) {
1102  TauDiscInfo<reco::PFTauDiscriminator> thisDiscriminator;
1103  thisDiscriminator.label = label;
1104  thisDiscriminator.cut = cut;
1105  thisDiscriminator.disc_token = consumes<reco::PFTauDiscriminator>(label);
1106  recoPrediscriminants_.push_back(thisDiscriminator);
1107  } else {
1108  TauDiscInfo<pat::PATTauDiscriminator> thisDiscriminator;
1109  thisDiscriminator.label = label;
1110  thisDiscriminator.cut = cut;
1111  thisDiscriminator.disc_token = consumes<pat::PATTauDiscriminator>(label);
1112  patPrediscriminants_.push_back(thisDiscriminator);
1113  }
1114  }
1115  if (version_ == 2) {
1116  using namespace dnn_inputs_v2;
1117  namespace sc = deep_tau::Scaling;
1118  tauInputs_indices_.resize(TauBlockInputs::NumberOfInputs);
1119  std::iota(std::begin(tauInputs_indices_), std::end(tauInputs_indices_), 0);
1120 
1121  if (sub_version_ == 1) {
1122  tauBlockTensor_ = std::make_unique<tensorflow::Tensor>(
1123  tensorflow::DT_FLOAT, tensorflow::TensorShape{1, TauBlockInputs::NumberOfInputs});
1125  } else if (sub_version_ == 5) {
1126  std::sort(TauBlockInputs::varsToDrop.begin(), TauBlockInputs::varsToDrop.end());
1127  for (auto v : TauBlockInputs::varsToDrop) {
1128  tauInputs_indices_.at(v) = -1; // set index to -1
1129  for (std::size_t i = v + 1; i < TauBlockInputs::NumberOfInputs; ++i)
1130  tauInputs_indices_.at(i) -= 1; // shift all the following indices by 1
1131  }
1132  tauBlockTensor_ = std::make_unique<tensorflow::Tensor>(
1133  tensorflow::DT_FLOAT,
1134  tensorflow::TensorShape{1,
1135  static_cast<int>(TauBlockInputs::NumberOfInputs) -
1136  static_cast<int>(TauBlockInputs::varsToDrop.size())});
1137  if (year_ == 2026) {
1139  } else {
1141  }
1142  } else
1143  throw cms::Exception("DeepTauId") << "subversion " << sub_version_ << " is not supported.";
1144 
1145  std::map<std::vector<bool>, std::vector<sc::FeatureT>> GridFeatureTypes_map = {
1146  {{false}, {sc::FeatureT::TauFlat, sc::FeatureT::GridGlobal}}, // feature types without inner/outer grid split
1147  {{false, true},
1148  {sc::FeatureT::PfCand_electron,
1149  sc::FeatureT::PfCand_muon, // feature types with inner/outer grid split
1150  sc::FeatureT::PfCand_chHad,
1151  sc::FeatureT::PfCand_nHad,
1152  sc::FeatureT::PfCand_gamma,
1154  sc::FeatureT::Muon}}};
1155 
1156  // check that sizes of mean/std/lim_min/lim_max vectors are equal between each other
1157  for (const auto& p : GridFeatureTypes_map) {
1158  for (auto is_inner : p.first) {
1159  for (auto featureType : p.second) {
1160  const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(featureType, is_inner));
1161  if (!(sp.mean_.size() == sp.std_.size() && sp.mean_.size() == sp.lim_min_.size() &&
1162  sp.mean_.size() == sp.lim_max_.size()))
1163  throw cms::Exception("DeepTauId") << "sizes of scaling parameter vectors do not match between each other";
1164  }
1165  }
1166  }
1167 
1168  for (size_t n = 0; n < 2; ++n) {
1169  const bool is_inner = n == 0;
1170  const auto n_cells = is_inner ? number_of_inner_cell : number_of_outer_cell;
1171  eGammaTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1172  tensorflow::DT_FLOAT, tensorflow::TensorShape{1, 1, 1, EgammaBlockInputs::NumberOfInputs});
1173  muonTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1174  tensorflow::DT_FLOAT, tensorflow::TensorShape{1, 1, 1, MuonBlockInputs::NumberOfInputs});
1175  hadronsTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1176  tensorflow::DT_FLOAT, tensorflow::TensorShape{1, 1, 1, HadronBlockInputs::NumberOfInputs});
1177  convTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1178  tensorflow::DT_FLOAT, tensorflow::TensorShape{1, n_cells, n_cells, number_of_conv_features});
1179  zeroOutputTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1180  tensorflow::DT_FLOAT, tensorflow::TensorShape{1, 1, 1, number_of_conv_features});
1181 
1182  eGammaTensor_[is_inner]->flat<float>().setZero();
1183  muonTensor_[is_inner]->flat<float>().setZero();
1184  hadronsTensor_[is_inner]->flat<float>().setZero();
1185 
1186  setCellConvFeatures(*zeroOutputTensor_[is_inner], getPartialPredictions(is_inner), 0, 0, 0);
1187  }
1188  } else {
1189  throw cms::Exception("DeepTauId") << "version " << version_ << " is not supported.";
1190  }
1191  }
size
Write out results.
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > hadronsTensor_
Definition: DeepTauId.cc:2732
std::map< std::string, WPList > workingPoints_
Definition: DeepTauId.cc:2692
const bool disable_dxy_pca_
Definition: DeepTauId.cc:2728
const bool save_inputs_
Definition: DeepTauId.cc:2735
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > zeroOutputTensor_
Definition: DeepTauId.cc:2732
int file_counter_
Definition: DeepTauId.cc:2738
edm::EDGetTokenT< reco::VertexCollection > vtxToken_
Definition: DeepTauId.cc:2691
std::vector< TauDiscInfo< reco::PFTauDiscriminator > > recoPrediscriminants_
Definition: DeepTauId.cc:1268
uint8_t andPrediscriminants_
Definition: DeepTauId.cc:1266
std::ofstream * json_file_
Definition: DeepTauId.cc:2736
OutputCollection outputs_
Definition: DeepTauId.cc:2694
void setCellConvFeatures(tensorflow::Tensor &convTensor, const tensorflow::Tensor &features, unsigned batch_idx, int eta_index, int phi_index)
Definition: DeepTauId.cc:1820
const unsigned version_
Definition: DeepTauId.cc:2725
std::vector< TauDiscInfo< pat::PATTauDiscriminator > > patPrediscriminants_
Definition: DeepTauId.cc:1267
const unsigned sub_version_
Definition: DeepTauId.cc:2726
edm::EDGetTokenT< TauCollection > tausToken_
Definition: DeepTauId.cc:2689
const std::map< std::pair< deep_tau::Scaling::FeatureT, bool >, deep_tau::Scaling::ScalingParams > * scalingParamsMap_
Definition: DeepTauId.cc:2734
static const OutputCollection & GetOutputs()
Definition: DeepTauId.cc:950
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > convTensor_
Definition: DeepTauId.cc:2732
const std::map< std::pair< FeatureT, bool >, ScalingParams > scalingParamsMap_v2p5
const deep_tau::DeepTauCache * cache_
Definition: DeepTauId.cc:2695
char const * label
edm::EDGetTokenT< CandidateCollection > pfcandToken_
Definition: DeepTauId.cc:2690
const unsigned year_
Definition: DeepTauId.cc:2724
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:180
const bool disable_CellIndex_workaround_
Definition: DeepTauId.cc:2730
const std::map< std::pair< FeatureT, bool >, ScalingParams > scalingParamsMap_v2p1
tensorflow::Tensor getPartialPredictions(bool is_inner)
Definition: DeepTauId.cc:1714
edm::EDGetTokenT< edm::AssociationVector< reco::PFTauRefProd, std::vector< reco::PFTauTransverseImpactParameterRef > > > pfTauTransverseImpactParameters_token_
Definition: DeepTauId.cc:2722
edm::EDGetTokenT< reco::TauDiscriminatorContainer > basicTauDiscriminators_inputToken_
Definition: DeepTauId.cc:2719
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > eGammaTensor_
Definition: DeepTauId.cc:2732
const bool disable_hcalFraction_workaround_
Definition: DeepTauId.cc:2729
const bool is_online_
Definition: DeepTauId.cc:2693
def cache(function)
Definition: utilities.py:3
edm::EDGetTokenT< reco::TauDiscriminatorContainer > basicTauDiscriminatorsdR03_inputToken_
Definition: DeepTauId.cc:2720
std::vector< int > tauInputs_indices_
Definition: DeepTauId.cc:2739
const int debug_level
Definition: DeepTauId.cc:2727
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > muonTensor_
Definition: DeepTauId.cc:2732
edm::EDGetTokenT< std::vector< pat::Electron > > electrons_token_
Definition: DeepTauId.cc:2716
edm::EDGetTokenT< std::vector< pat::Muon > > muons_token_
Definition: DeepTauId.cc:2717
edm::EDGetTokenT< double > rho_token_
Definition: DeepTauId.cc:2718
const std::map< std::pair< FeatureT, bool >, ScalingParams > scalingParamsMap_PhaseIIv2p5
std::unique_ptr< tensorflow::Tensor > tauBlockTensor_
Definition: DeepTauId.cc:2731
unsigned transform(const HcalDetId &id, unsigned transformCode)

Member Function Documentation

◆ calculateElectronClusterVars()

static void DeepTauId::calculateElectronClusterVars ( const pat::Electron ele,
float &  elecEe,
float &  elecEgamma 
)
inlinestaticprivate

Definition at line 2544 of file DeepTauId.cc.

References default_value, hcalRecHitTable_cff::energy, and pat::Electron::superCluster().

2544  {
2545  if (ele) {
2546  elecEe = elecEgamma = 0;
2547  auto superCluster = ele->superCluster();
2548  if (superCluster.isNonnull() && superCluster.isAvailable() && superCluster->clusters().isNonnull() &&
2549  superCluster->clusters().isAvailable()) {
2550  for (auto iter = superCluster->clustersBegin(); iter != superCluster->clustersEnd(); ++iter) {
2551  const double energy = (*iter)->energy();
2552  if (iter == superCluster->clustersBegin())
2553  elecEe += energy;
2554  else
2555  elecEgamma += energy;
2556  }
2557  }
2558  } else {
2559  elecEe = elecEgamma = default_value;
2560  }
2561  }
static constexpr float default_value
Definition: DeepTauId.cc:948
reco::SuperClusterRef superCluster() const override
override the reco::GsfElectron::superCluster method, to access the internal storage of the superclust...

◆ calculateElectronClusterVarsV2()

static bool DeepTauId::calculateElectronClusterVarsV2 ( const pat::Electron ele,
float &  cc_ele_energy,
float &  cc_gamma_energy,
int &  cc_n_gamma 
)
inlinestaticprivate

Definition at line 1308 of file DeepTauId.cc.

References hcalRecHitTable_cff::energy, and pat::Electron::superCluster().

Referenced by createEgammaBlockInputs().

1311  {
1312  cc_ele_energy = cc_gamma_energy = 0;
1313  cc_n_gamma = 0;
1314  const auto& superCluster = ele.superCluster();
1315  if (superCluster.isNonnull() && superCluster.isAvailable() && superCluster->clusters().isNonnull() &&
1316  superCluster->clusters().isAvailable()) {
1317  for (auto iter = superCluster->clustersBegin(); iter != superCluster->clustersEnd(); ++iter) {
1318  const float energy = static_cast<float>((*iter)->energy());
1319  if (iter == superCluster->clustersBegin())
1320  cc_ele_energy += energy;
1321  else {
1322  cc_gamma_energy += energy;
1323  ++cc_n_gamma;
1324  }
1325  }
1326  return true;
1327  } else
1328  return false;
1329  }
reco::SuperClusterRef superCluster() const override
override the reco::GsfElectron::superCluster method, to access the internal storage of the superclust...

◆ calculateGottfriedJacksonAngleDifference() [1/2]

template<typename TauCastType >
static bool DeepTauId::calculateGottfriedJacksonAngleDifference ( const TauCastType &  tau,
const size_t  tau_index,
double &  gj_diff,
TauFunc  tau_funcs 
)
inlinestaticprivate

Definition at line 2638 of file DeepTauId.cc.

References funct::abs(), and conifer::pow().

Referenced by calculateGottfriedJacksonAngleDifference(), and createTauBlockInputs().

2641  {
2642  if (tau_funcs.getHasSecondaryVertex(tau, tau_index)) {
2643  static constexpr double mTau = 1.77682;
2644  const double mAOne = tau.p4().M();
2645  const double pAOneMag = tau.p();
2646  const double argumentThetaGJmax = (std::pow(mTau, 2) - std::pow(mAOne, 2)) / (2 * mTau * pAOneMag);
2647  const double argumentThetaGJmeasured = tau.p4().Vect().Dot(tau_funcs.getFlightLength(tau, tau_index)) /
2648  (pAOneMag * tau_funcs.getFlightLength(tau, tau_index).R());
2649  if (std::abs(argumentThetaGJmax) <= 1. && std::abs(argumentThetaGJmeasured) <= 1.) {
2650  double thetaGJmax = std::asin(argumentThetaGJmax);
2651  double thetaGJmeasured = std::acos(argumentThetaGJmeasured);
2652  gj_diff = thetaGJmeasured - thetaGJmax;
2653  return true;
2654  }
2655  }
2656  return false;
2657  }
constexpr int pow(int x)
Definition: conifer.h:24
Abs< T >::type abs(const T &t)
Definition: Abs.h:22

◆ calculateGottfriedJacksonAngleDifference() [2/2]

template<typename TauCastType >
static float DeepTauId::calculateGottfriedJacksonAngleDifference ( const TauCastType &  tau,
const size_t  tau_index,
TauFunc  tau_funcs 
)
inlinestaticprivate

Definition at line 2660 of file DeepTauId.cc.

References calculateGottfriedJacksonAngleDifference(), and default_value.

2662  {
2663  double gj_diff;
2664  if (calculateGottfriedJacksonAngleDifference(tau, tau_index, gj_diff, tau_funcs))
2665  return static_cast<float>(gj_diff);
2666  return default_value;
2667  }
static constexpr float default_value
Definition: DeepTauId.cc:948
static bool calculateGottfriedJacksonAngleDifference(const TauCastType &tau, const size_t tau_index, double &gj_diff, TauFunc tau_funcs)
Definition: DeepTauId.cc:2638

◆ checkInputs()

void DeepTauId::checkInputs ( const tensorflow::Tensor &  inputs,
const std::string &  block_name,
int  n_inputs,
const CellGrid *  grid = nullptr 
) const
inlineprivate

Definition at line 1331 of file DeepTauId.cc.

References cms::cuda::assert(), gather_cfg::cout, debug_level, PVValHelper::eta, Exception, alignBH_cfg::fixed, nano_mu_digi_cff::float, getRunAppsInfo::grid, input, PixelMapPlotter::inputs, edm::isNotFinite(), and phi.

Referenced by getPredictionsV2().

1334  {
1335  if (debug_level >= 1) {
1336  std::cout << "<checkInputs>: block_name = " << block_name << std::endl;
1337  if (block_name == "input_tau") {
1338  for (int input_index = 0; input_index < n_inputs; ++input_index) {
1339  float input = inputs.matrix<float>()(0, input_index);
1340  if (edm::isNotFinite(input)) {
1341  throw cms::Exception("DeepTauId")
1342  << "in the " << block_name
1343  << ", input is not finite, i.e. infinite or NaN, for input_index = " << input_index;
1344  }
1345  if (debug_level >= 2) {
1346  std::cout << block_name << "[var = " << input_index << "] = " << std::setprecision(5) << std::fixed << input
1347  << std::endl;
1348  }
1349  }
1350  } else {
1351  assert(grid);
1352  int n_eta, n_phi;
1353  if (block_name.find("input_inner") != std::string::npos) {
1354  n_eta = 5;
1355  n_phi = 5;
1356  } else if (block_name.find("input_outer") != std::string::npos) {
1357  n_eta = 10;
1358  n_phi = 10;
1359  } else
1360  assert(0);
1361  int eta_phi_index = 0;
1362  for (int eta = -n_eta; eta <= n_eta; ++eta) {
1363  for (int phi = -n_phi; phi <= n_phi; ++phi) {
1364  const CellIndex cell_index{eta, phi};
1365  const auto cell_iter = grid->find(cell_index);
1366  if (cell_iter != grid->end()) {
1367  for (int input_index = 0; input_index < n_inputs; ++input_index) {
1368  float input = inputs.tensor<float, 4>()(eta_phi_index, 0, 0, input_index);
1369  if (edm::isNotFinite(input)) {
1370  throw cms::Exception("DeepTauId")
1371  << "in the " << block_name << ", input is not finite, i.e. infinite or NaN, for eta = " << eta
1372  << ", phi = " << phi << ", input_index = " << input_index;
1373  }
1374  if (debug_level >= 2) {
1375  std::cout << block_name << "[eta = " << eta << "][phi = " << phi << "][var = " << input_index
1376  << "] = " << std::setprecision(5) << std::fixed << input << std::endl;
1377  }
1378  }
1379  eta_phi_index += 1;
1380  }
1381  }
1382  }
1383  }
1384  }
1385  }
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
assert(be >=bs)
static std::string const input
Definition: EdmProvDump.cc:50
const int debug_level
Definition: DeepTauId.cc:2727

◆ createConvFeatures()

template<typename CandidateCastType , typename TauCastType >
void DeepTauId::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 
)
inlineprivate

Definition at line 1739 of file DeepTauId.cc.

References convTensor_, gather_cfg::cout, debug_level, eGammaTensor_, pwdgSkimBPark_cfi::electrons, PVValHelper::eta, getPartialPredictions(), getRunAppsInfo::grid, hadronsTensor_, heavyIonCSV_trainingSettings::idx, createfilelist::int, PDWG_BPHSkim_cff::muons, muonTensor_, phi, MetAnalyzer::pv(), rho, setCellConvFeatures(), metsig::tau, and zeroOutputTensor_.

1749  {
1750  if (debug_level >= 2) {
1751  std::cout << "<DeepTauId::createConvFeatures (is_inner = " << is_inner << ")>:" << std::endl;
1752  }
1753  tensorflow::Tensor& convTensor = *convTensor_.at(is_inner);
1754  eGammaTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1755  tensorflow::DT_FLOAT,
1756  tensorflow::TensorShape{
1757  (long long int)grid.num_valid_cells(), 1, 1, dnn_inputs_v2::EgammaBlockInputs::NumberOfInputs});
1758  muonTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1759  tensorflow::DT_FLOAT,
1760  tensorflow::TensorShape{
1761  (long long int)grid.num_valid_cells(), 1, 1, dnn_inputs_v2::MuonBlockInputs::NumberOfInputs});
1762  hadronsTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1763  tensorflow::DT_FLOAT,
1764  tensorflow::TensorShape{
1765  (long long int)grid.num_valid_cells(), 1, 1, dnn_inputs_v2::HadronBlockInputs::NumberOfInputs});
1766 
1767  eGammaTensor_[is_inner]->flat<float>().setZero();
1768  muonTensor_[is_inner]->flat<float>().setZero();
1769  hadronsTensor_[is_inner]->flat<float>().setZero();
1770 
1771  unsigned idx = 0;
1772  for (int eta = -grid.maxEtaIndex(); eta <= grid.maxEtaIndex(); ++eta) {
1773  for (int phi = -grid.maxPhiIndex(); phi <= grid.maxPhiIndex(); ++phi) {
1774  if (debug_level >= 2) {
1775  std::cout << "processing ( eta = " << eta << ", phi = " << phi << " )" << std::endl;
1776  }
1777  const CellIndex cell_index{eta, phi};
1778  const auto cell_iter = grid.find(cell_index);
1779  if (cell_iter != grid.end()) {
1780  if (debug_level >= 2) {
1781  std::cout << " creating inputs for ( eta = " << eta << ", phi = " << phi << " ): idx = " << idx
1782  << std::endl;
1783  }
1784  const Cell& cell = cell_iter->second;
1785  createEgammaBlockInputs<CandidateCastType>(
1786  idx, tau, tau_index, tau_ref, pv, rho, electrons, pfCands, cell, tau_funcs, is_inner);
1787  createMuonBlockInputs<CandidateCastType>(
1788  idx, tau, tau_index, tau_ref, pv, rho, muons, pfCands, cell, tau_funcs, is_inner);
1789  createHadronsBlockInputs<CandidateCastType>(
1790  idx, tau, tau_index, tau_ref, pv, rho, pfCands, cell, tau_funcs, is_inner);
1791  idx += 1;
1792  } else {
1793  if (debug_level >= 2) {
1794  std::cout << " skipping creation of inputs, because ( eta = " << eta << ", phi = " << phi
1795  << " ) is not in the grid !!" << std::endl;
1796  }
1797  }
1798  }
1799  }
1800 
1801  const auto predTensor = getPartialPredictions(is_inner);
1802  idx = 0;
1803  for (int eta = -grid.maxEtaIndex(); eta <= grid.maxEtaIndex(); ++eta) {
1804  for (int phi = -grid.maxPhiIndex(); phi <= grid.maxPhiIndex(); ++phi) {
1805  const CellIndex cell_index{eta, phi};
1806  const int eta_index = grid.getEtaTensorIndex(cell_index);
1807  const int phi_index = grid.getPhiTensorIndex(cell_index);
1808 
1809  const auto cell_iter = grid.find(cell_index);
1810  if (cell_iter != grid.end()) {
1811  setCellConvFeatures(convTensor, predTensor, idx, eta_index, phi_index);
1812  idx += 1;
1813  } else {
1814  setCellConvFeatures(convTensor, *zeroOutputTensor_[is_inner], 0, eta_index, phi_index);
1815  }
1816  }
1817  }
1818  }
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > hadronsTensor_
Definition: DeepTauId.cc:2732
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > zeroOutputTensor_
Definition: DeepTauId.cc:2732
void setCellConvFeatures(tensorflow::Tensor &convTensor, const tensorflow::Tensor &features, unsigned batch_idx, int eta_index, int phi_index)
Definition: DeepTauId.cc:1820
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > convTensor_
Definition: DeepTauId.cc:2732
def pv(vc)
Definition: MetAnalyzer.py:7
tensorflow::Tensor getPartialPredictions(bool is_inner)
Definition: DeepTauId.cc:1714
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > eGammaTensor_
Definition: DeepTauId.cc:2732
const int debug_level
Definition: DeepTauId.cc:2727
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > muonTensor_
Definition: DeepTauId.cc:2732

◆ createEgammaBlockInputs()

template<typename CandidateCastType , typename TauCastType >
void DeepTauId::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 
)
inlineprivate

Definition at line 1976 of file DeepTauId.cc.

References funct::abs(), edm::View< T >::at(), calculateElectronClusterVarsV2(), nano_mu_local_reco_cff::chi2, HLT_2023v12_cff::dPhi, eGammaTensor_, nanoDQM_cfi::Electron, pwdgSkimBPark_cfi::electrons, f, nano_mu_digi_cff::float, heavyIonCSV_trainingSettings::idx, PixelMapPlotter::inputs, isInEcalCrack(), ndof, rho, IsoPhotonEBSkim_cff::rho, scalingParamsMap_, sub_version_, runTauDisplay::tau_eta, runTauDisplay::tau_pt, and year_.

1986  {
1987  namespace dnn = dnn_inputs_v2::EgammaBlockInputs;
1988  namespace sc = deep_tau::Scaling;
1989  sc::FeatureT ft_global = sc::FeatureT::GridGlobal;
1990  sc::FeatureT ft_PFe = sc::FeatureT::PfCand_electron;
1991  sc::FeatureT ft_PFg = sc::FeatureT::PfCand_gamma;
1993 
1994  // needed to remap indices from scaling vectors to those from dnn_inputs_v2::EgammaBlockInputs
1995  int PFe_index_offset = scalingParamsMap_->at(std::make_pair(ft_global, false)).mean_.size();
1996  int e_index_offset = PFe_index_offset + scalingParamsMap_->at(std::make_pair(ft_PFe, false)).mean_.size();
1997  int PFg_index_offset = e_index_offset + scalingParamsMap_->at(std::make_pair(ft_e, false)).mean_.size();
1998 
1999  // to account for swapped order of PfCand_gamma and Electron blocks for v2p5 training w.r.t. v2p1
2000  int fill_index_offset_e = 0;
2001  int fill_index_offset_PFg = 0;
2002  if (sub_version_ == 5) {
2003  fill_index_offset_e =
2004  scalingParamsMap_->at(std::make_pair(ft_PFg, false)).mean_.size(); // size of PF gamma features
2005  fill_index_offset_PFg =
2006  -scalingParamsMap_->at(std::make_pair(ft_e, false)).mean_.size(); // size of Electron features
2007  }
2008 
2009  tensorflow::Tensor& inputs = *eGammaTensor_.at(is_inner);
2010 
2011  const auto& get = [&](int var_index) -> float& { return inputs.tensor<float, 4>()(idx, 0, 0, var_index); };
2012 
2013  const bool valid_index_pf_ele = cell_map.count(CellObjectType::PfCand_electron);
2014  const bool valid_index_pf_gamma = cell_map.count(CellObjectType::PfCand_gamma);
2015  const bool valid_index_ele = cell_map.count(CellObjectType::Electron);
2016 
2017  if (!cell_map.empty()) {
2018  const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft_global, false));
2019  get(dnn::rho) = sp.scale(rho, dnn::rho);
2020  get(dnn::tau_pt) = sp.scale(tau.polarP4().pt(), dnn::tau_pt);
2021  get(dnn::tau_eta) = sp.scale(tau.polarP4().eta(), dnn::tau_eta);
2022  get(dnn::tau_inside_ecal_crack) = sp.scale(isInEcalCrack(tau.polarP4().eta()), dnn::tau_inside_ecal_crack);
2023  }
2024  if (valid_index_pf_ele) {
2025  const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft_PFe, is_inner));
2026  size_t index_pf_ele = cell_map.at(CellObjectType::PfCand_electron);
2027  const auto& ele_cand = dynamic_cast<const CandidateCastType&>(pfCands.at(index_pf_ele));
2028 
2029  get(dnn::pfCand_ele_valid) = sp.scale(valid_index_pf_ele, dnn::pfCand_ele_valid - PFe_index_offset);
2030  get(dnn::pfCand_ele_rel_pt) =
2031  sp.scale(ele_cand.polarP4().pt() / tau.polarP4().pt(), dnn::pfCand_ele_rel_pt - PFe_index_offset);
2032  get(dnn::pfCand_ele_deta) =
2033  sp.scale(ele_cand.polarP4().eta() - tau.polarP4().eta(), dnn::pfCand_ele_deta - PFe_index_offset);
2034  get(dnn::pfCand_ele_dphi) =
2035  sp.scale(dPhi(tau.polarP4(), ele_cand.polarP4()), dnn::pfCand_ele_dphi - PFe_index_offset);
2036  get(dnn::pfCand_ele_pvAssociationQuality) = sp.scale<int>(
2037  candFunc::getPvAssocationQuality(ele_cand), dnn::pfCand_ele_pvAssociationQuality - PFe_index_offset);
2038  get(dnn::pfCand_ele_puppiWeight) = is_inner ? sp.scale(candFunc::getPuppiWeight(ele_cand, 0.9906834f),
2039  dnn::pfCand_ele_puppiWeight - PFe_index_offset)
2040  : sp.scale(candFunc::getPuppiWeight(ele_cand, 0.9669586f),
2041  dnn::pfCand_ele_puppiWeight - PFe_index_offset);
2042  get(dnn::pfCand_ele_charge) = sp.scale(ele_cand.charge(), dnn::pfCand_ele_charge - PFe_index_offset);
2043  get(dnn::pfCand_ele_lostInnerHits) =
2044  sp.scale<int>(candFunc::getLostInnerHits(ele_cand, 0), dnn::pfCand_ele_lostInnerHits - PFe_index_offset);
2045  get(dnn::pfCand_ele_numberOfPixelHits) =
2046  sp.scale(candFunc::getNumberOfPixelHits(ele_cand, 0), dnn::pfCand_ele_numberOfPixelHits - PFe_index_offset);
2047  get(dnn::pfCand_ele_vertex_dx) =
2048  sp.scale(ele_cand.vertex().x() - pv.position().x(), dnn::pfCand_ele_vertex_dx - PFe_index_offset);
2049  get(dnn::pfCand_ele_vertex_dy) =
2050  sp.scale(ele_cand.vertex().y() - pv.position().y(), dnn::pfCand_ele_vertex_dy - PFe_index_offset);
2051  get(dnn::pfCand_ele_vertex_dz) =
2052  sp.scale(ele_cand.vertex().z() - pv.position().z(), dnn::pfCand_ele_vertex_dz - PFe_index_offset);
2053  get(dnn::pfCand_ele_vertex_dx_tauFL) =
2054  sp.scale(ele_cand.vertex().x() - pv.position().x() - tau_funcs.getFlightLength(tau, tau_index).x(),
2055  dnn::pfCand_ele_vertex_dx_tauFL - PFe_index_offset);
2056  get(dnn::pfCand_ele_vertex_dy_tauFL) =
2057  sp.scale(ele_cand.vertex().y() - pv.position().y() - tau_funcs.getFlightLength(tau, tau_index).y(),
2058  dnn::pfCand_ele_vertex_dy_tauFL - PFe_index_offset);
2059  get(dnn::pfCand_ele_vertex_dz_tauFL) =
2060  sp.scale(ele_cand.vertex().z() - pv.position().z() - tau_funcs.getFlightLength(tau, tau_index).z(),
2061  dnn::pfCand_ele_vertex_dz_tauFL - PFe_index_offset);
2062 
2063  const bool hasTrackDetails = candFunc::getHasTrackDetails(ele_cand);
2064  if (hasTrackDetails) {
2065  get(dnn::pfCand_ele_hasTrackDetails) =
2066  sp.scale(hasTrackDetails, dnn::pfCand_ele_hasTrackDetails - PFe_index_offset);
2067  get(dnn::pfCand_ele_dxy) = sp.scale(candFunc::getTauDxy(ele_cand), dnn::pfCand_ele_dxy - PFe_index_offset);
2068  get(dnn::pfCand_ele_dxy_sig) = sp.scale(std::abs(candFunc::getTauDxy(ele_cand)) / ele_cand.dxyError(),
2069  dnn::pfCand_ele_dxy_sig - PFe_index_offset);
2070  get(dnn::pfCand_ele_dz) = sp.scale(candFunc::getTauDz(ele_cand), dnn::pfCand_ele_dz - PFe_index_offset);
2071  get(dnn::pfCand_ele_dz_sig) = sp.scale(std::abs(candFunc::getTauDz(ele_cand)) / ele_cand.dzError(),
2072  dnn::pfCand_ele_dz_sig - PFe_index_offset);
2073  get(dnn::pfCand_ele_track_chi2_ndof) =
2074  candFunc::getPseudoTrack(ele_cand).ndof() > 0
2075  ? sp.scale(candFunc::getPseudoTrack(ele_cand).chi2() / candFunc::getPseudoTrack(ele_cand).ndof(),
2076  dnn::pfCand_ele_track_chi2_ndof - PFe_index_offset)
2077  : 0;
2078  get(dnn::pfCand_ele_track_ndof) =
2079  candFunc::getPseudoTrack(ele_cand).ndof() > 0
2080  ? sp.scale(candFunc::getPseudoTrack(ele_cand).ndof(), dnn::pfCand_ele_track_ndof - PFe_index_offset)
2081  : 0;
2082  }
2083  }
2084  if (valid_index_pf_gamma) {
2085  const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft_PFg, is_inner));
2086  size_t index_pf_gamma = cell_map.at(CellObjectType::PfCand_gamma);
2087  const auto& gamma_cand = dynamic_cast<const CandidateCastType&>(pfCands.at(index_pf_gamma));
2088 
2089  get(dnn::pfCand_gamma_valid + fill_index_offset_PFg) =
2090  sp.scale(valid_index_pf_gamma, dnn::pfCand_gamma_valid - PFg_index_offset);
2091  get(dnn::pfCand_gamma_rel_pt + fill_index_offset_PFg) =
2092  sp.scale(gamma_cand.polarP4().pt() / tau.polarP4().pt(), dnn::pfCand_gamma_rel_pt - PFg_index_offset);
2093  get(dnn::pfCand_gamma_deta + fill_index_offset_PFg) =
2094  sp.scale(gamma_cand.polarP4().eta() - tau.polarP4().eta(), dnn::pfCand_gamma_deta - PFg_index_offset);
2095  get(dnn::pfCand_gamma_dphi + fill_index_offset_PFg) =
2096  sp.scale(dPhi(tau.polarP4(), gamma_cand.polarP4()), dnn::pfCand_gamma_dphi - PFg_index_offset);
2097  get(dnn::pfCand_gamma_pvAssociationQuality + fill_index_offset_PFg) = sp.scale<int>(
2098  candFunc::getPvAssocationQuality(gamma_cand), dnn::pfCand_gamma_pvAssociationQuality - PFg_index_offset);
2099  get(dnn::pfCand_gamma_fromPV + fill_index_offset_PFg) =
2100  sp.scale<int>(candFunc::getFromPV(gamma_cand), dnn::pfCand_gamma_fromPV - PFg_index_offset);
2101  get(dnn::pfCand_gamma_puppiWeight + fill_index_offset_PFg) =
2102  is_inner ? sp.scale(candFunc::getPuppiWeight(gamma_cand, 0.9084110f),
2103  dnn::pfCand_gamma_puppiWeight - PFg_index_offset)
2104  : sp.scale(candFunc::getPuppiWeight(gamma_cand, 0.4211567f),
2105  dnn::pfCand_gamma_puppiWeight - PFg_index_offset);
2106  get(dnn::pfCand_gamma_puppiWeightNoLep + fill_index_offset_PFg) =
2107  is_inner ? sp.scale(candFunc::getPuppiWeightNoLep(gamma_cand, 0.8857716f),
2108  dnn::pfCand_gamma_puppiWeightNoLep - PFg_index_offset)
2109  : sp.scale(candFunc::getPuppiWeightNoLep(gamma_cand, 0.3822604f),
2110  dnn::pfCand_gamma_puppiWeightNoLep - PFg_index_offset);
2111  get(dnn::pfCand_gamma_lostInnerHits + fill_index_offset_PFg) =
2112  sp.scale<int>(candFunc::getLostInnerHits(gamma_cand, 0), dnn::pfCand_gamma_lostInnerHits - PFg_index_offset);
2113  get(dnn::pfCand_gamma_numberOfPixelHits + fill_index_offset_PFg) = sp.scale(
2114  candFunc::getNumberOfPixelHits(gamma_cand, 0), dnn::pfCand_gamma_numberOfPixelHits - PFg_index_offset);
2115  get(dnn::pfCand_gamma_vertex_dx + fill_index_offset_PFg) =
2116  sp.scale(gamma_cand.vertex().x() - pv.position().x(), dnn::pfCand_gamma_vertex_dx - PFg_index_offset);
2117  get(dnn::pfCand_gamma_vertex_dy + fill_index_offset_PFg) =
2118  sp.scale(gamma_cand.vertex().y() - pv.position().y(), dnn::pfCand_gamma_vertex_dy - PFg_index_offset);
2119  get(dnn::pfCand_gamma_vertex_dz + fill_index_offset_PFg) =
2120  sp.scale(gamma_cand.vertex().z() - pv.position().z(), dnn::pfCand_gamma_vertex_dz - PFg_index_offset);
2121  get(dnn::pfCand_gamma_vertex_dx_tauFL + fill_index_offset_PFg) =
2122  sp.scale(gamma_cand.vertex().x() - pv.position().x() - tau_funcs.getFlightLength(tau, tau_index).x(),
2123  dnn::pfCand_gamma_vertex_dx_tauFL - PFg_index_offset);
2124  get(dnn::pfCand_gamma_vertex_dy_tauFL + fill_index_offset_PFg) =
2125  sp.scale(gamma_cand.vertex().y() - pv.position().y() - tau_funcs.getFlightLength(tau, tau_index).y(),
2126  dnn::pfCand_gamma_vertex_dy_tauFL - PFg_index_offset);
2127  get(dnn::pfCand_gamma_vertex_dz_tauFL + fill_index_offset_PFg) =
2128  sp.scale(gamma_cand.vertex().z() - pv.position().z() - tau_funcs.getFlightLength(tau, tau_index).z(),
2129  dnn::pfCand_gamma_vertex_dz_tauFL - PFg_index_offset);
2130  const bool hasTrackDetails = candFunc::getHasTrackDetails(gamma_cand);
2131  if (hasTrackDetails) {
2132  get(dnn::pfCand_gamma_hasTrackDetails + fill_index_offset_PFg) =
2133  sp.scale(hasTrackDetails, dnn::pfCand_gamma_hasTrackDetails - PFg_index_offset);
2134  get(dnn::pfCand_gamma_dxy + fill_index_offset_PFg) =
2135  sp.scale(candFunc::getTauDxy(gamma_cand), dnn::pfCand_gamma_dxy - PFg_index_offset);
2136  get(dnn::pfCand_gamma_dxy_sig + fill_index_offset_PFg) =
2137  sp.scale(std::abs(candFunc::getTauDxy(gamma_cand)) / gamma_cand.dxyError(),
2138  dnn::pfCand_gamma_dxy_sig - PFg_index_offset);
2139  get(dnn::pfCand_gamma_dz + fill_index_offset_PFg) =
2140  sp.scale(candFunc::getTauDz(gamma_cand), dnn::pfCand_gamma_dz - PFg_index_offset);
2141  get(dnn::pfCand_gamma_dz_sig + fill_index_offset_PFg) =
2142  sp.scale(std::abs(candFunc::getTauDz(gamma_cand)) / gamma_cand.dzError(),
2143  dnn::pfCand_gamma_dz_sig - PFg_index_offset);
2144  get(dnn::pfCand_gamma_track_chi2_ndof + fill_index_offset_PFg) =
2145  candFunc::getPseudoTrack(gamma_cand).ndof() > 0
2146  ? sp.scale(candFunc::getPseudoTrack(gamma_cand).chi2() / candFunc::getPseudoTrack(gamma_cand).ndof(),
2147  dnn::pfCand_gamma_track_chi2_ndof - PFg_index_offset)
2148  : 0;
2149  get(dnn::pfCand_gamma_track_ndof + fill_index_offset_PFg) =
2150  candFunc::getPseudoTrack(gamma_cand).ndof() > 0
2151  ? sp.scale(candFunc::getPseudoTrack(gamma_cand).ndof(), dnn::pfCand_gamma_track_ndof - PFg_index_offset)
2152  : 0;
2153  }
2154  }
2155  if (valid_index_ele) {
2156  const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft_e, is_inner));
2157  size_t index_ele = cell_map.at(CellObjectType::Electron);
2158  const auto& ele = electrons->at(index_ele);
2159 
2160  get(dnn::ele_valid + fill_index_offset_e) = sp.scale(valid_index_ele, dnn::ele_valid - e_index_offset);
2161  get(dnn::ele_rel_pt + fill_index_offset_e) =
2162  sp.scale(ele.polarP4().pt() / tau.polarP4().pt(), dnn::ele_rel_pt - e_index_offset);
2163  get(dnn::ele_deta + fill_index_offset_e) =
2164  sp.scale(ele.polarP4().eta() - tau.polarP4().eta(), dnn::ele_deta - e_index_offset);
2165  get(dnn::ele_dphi + fill_index_offset_e) =
2166  sp.scale(dPhi(tau.polarP4(), ele.polarP4()), dnn::ele_dphi - e_index_offset);
2167 
2168  float cc_ele_energy, cc_gamma_energy;
2169  int cc_n_gamma;
2170  const bool cc_valid = calculateElectronClusterVarsV2(ele, cc_ele_energy, cc_gamma_energy, cc_n_gamma);
2171  if (cc_valid) {
2172  get(dnn::ele_cc_valid + fill_index_offset_e) = sp.scale(cc_valid, dnn::ele_cc_valid - e_index_offset);
2173  get(dnn::ele_cc_ele_rel_energy + fill_index_offset_e) =
2174  sp.scale(cc_ele_energy / ele.polarP4().pt(), dnn::ele_cc_ele_rel_energy - e_index_offset);
2175  get(dnn::ele_cc_gamma_rel_energy + fill_index_offset_e) =
2176  sp.scale(cc_gamma_energy / cc_ele_energy, dnn::ele_cc_gamma_rel_energy - e_index_offset);
2177  get(dnn::ele_cc_n_gamma + fill_index_offset_e) = sp.scale(cc_n_gamma, dnn::ele_cc_n_gamma - e_index_offset);
2178  }
2179  get(dnn::ele_rel_trackMomentumAtVtx + fill_index_offset_e) =
2180  sp.scale(ele.trackMomentumAtVtx().R() / ele.polarP4().pt(), dnn::ele_rel_trackMomentumAtVtx - e_index_offset);
2181  get(dnn::ele_rel_trackMomentumAtCalo + fill_index_offset_e) = sp.scale(
2182  ele.trackMomentumAtCalo().R() / ele.polarP4().pt(), dnn::ele_rel_trackMomentumAtCalo - e_index_offset);
2183  get(dnn::ele_rel_trackMomentumOut + fill_index_offset_e) =
2184  sp.scale(ele.trackMomentumOut().R() / ele.polarP4().pt(), dnn::ele_rel_trackMomentumOut - e_index_offset);
2185  get(dnn::ele_rel_trackMomentumAtEleClus + fill_index_offset_e) = sp.scale(
2186  ele.trackMomentumAtEleClus().R() / ele.polarP4().pt(), dnn::ele_rel_trackMomentumAtEleClus - e_index_offset);
2187  get(dnn::ele_rel_trackMomentumAtVtxWithConstraint + fill_index_offset_e) =
2188  sp.scale(ele.trackMomentumAtVtxWithConstraint().R() / ele.polarP4().pt(),
2189  dnn::ele_rel_trackMomentumAtVtxWithConstraint - e_index_offset);
2190  get(dnn::ele_rel_ecalEnergy + fill_index_offset_e) =
2191  sp.scale(ele.ecalEnergy() / ele.polarP4().pt(), dnn::ele_rel_ecalEnergy - e_index_offset);
2192  get(dnn::ele_ecalEnergy_sig + fill_index_offset_e) =
2193  sp.scale(ele.ecalEnergy() / ele.ecalEnergyError(), dnn::ele_ecalEnergy_sig - e_index_offset);
2194  get(dnn::ele_eSuperClusterOverP + fill_index_offset_e) =
2195  sp.scale(ele.eSuperClusterOverP(), dnn::ele_eSuperClusterOverP - e_index_offset);
2196  get(dnn::ele_eSeedClusterOverP + fill_index_offset_e) =
2197  sp.scale(ele.eSeedClusterOverP(), dnn::ele_eSeedClusterOverP - e_index_offset);
2198  get(dnn::ele_eSeedClusterOverPout + fill_index_offset_e) =
2199  sp.scale(ele.eSeedClusterOverPout(), dnn::ele_eSeedClusterOverPout - e_index_offset);
2200  get(dnn::ele_eEleClusterOverPout + fill_index_offset_e) =
2201  sp.scale(ele.eEleClusterOverPout(), dnn::ele_eEleClusterOverPout - e_index_offset);
2202  get(dnn::ele_deltaEtaSuperClusterTrackAtVtx + fill_index_offset_e) =
2203  sp.scale(ele.deltaEtaSuperClusterTrackAtVtx(), dnn::ele_deltaEtaSuperClusterTrackAtVtx - e_index_offset);
2204  get(dnn::ele_deltaEtaSeedClusterTrackAtCalo + fill_index_offset_e) =
2205  sp.scale(ele.deltaEtaSeedClusterTrackAtCalo(), dnn::ele_deltaEtaSeedClusterTrackAtCalo - e_index_offset);
2206  get(dnn::ele_deltaEtaEleClusterTrackAtCalo + fill_index_offset_e) =
2207  sp.scale(ele.deltaEtaEleClusterTrackAtCalo(), dnn::ele_deltaEtaEleClusterTrackAtCalo - e_index_offset);
2208  get(dnn::ele_deltaPhiEleClusterTrackAtCalo + fill_index_offset_e) =
2209  sp.scale(ele.deltaPhiEleClusterTrackAtCalo(), dnn::ele_deltaPhiEleClusterTrackAtCalo - e_index_offset);
2210  get(dnn::ele_deltaPhiSuperClusterTrackAtVtx + fill_index_offset_e) =
2211  sp.scale(ele.deltaPhiSuperClusterTrackAtVtx(), dnn::ele_deltaPhiSuperClusterTrackAtVtx - e_index_offset);
2212  get(dnn::ele_deltaPhiSeedClusterTrackAtCalo + fill_index_offset_e) =
2213  sp.scale(ele.deltaPhiSeedClusterTrackAtCalo(), dnn::ele_deltaPhiSeedClusterTrackAtCalo - e_index_offset);
2214  const bool mva_valid =
2215  (ele.mvaInput().earlyBrem > -2) ||
2216  (year_ !=
2217  2026); // Known issue that input can be invalid in Phase2 samples (early/lateBrem==-2, hadEnergy==0, sigmaEtaEta/deltaEta==3.40282e+38). Unknown if also in Run2/3, so don't change there
2218  if (mva_valid) {
2219  get(dnn::ele_mvaInput_earlyBrem + fill_index_offset_e) =
2220  sp.scale(ele.mvaInput().earlyBrem, dnn::ele_mvaInput_earlyBrem - e_index_offset);
2221  get(dnn::ele_mvaInput_lateBrem + fill_index_offset_e) =
2222  sp.scale(ele.mvaInput().lateBrem, dnn::ele_mvaInput_lateBrem - e_index_offset);
2223  get(dnn::ele_mvaInput_sigmaEtaEta + fill_index_offset_e) =
2224  sp.scale(ele.mvaInput().sigmaEtaEta, dnn::ele_mvaInput_sigmaEtaEta - e_index_offset);
2225  get(dnn::ele_mvaInput_hadEnergy + fill_index_offset_e) =
2226  sp.scale(ele.mvaInput().hadEnergy, dnn::ele_mvaInput_hadEnergy - e_index_offset);
2227  get(dnn::ele_mvaInput_deltaEta + fill_index_offset_e) =
2228  sp.scale(ele.mvaInput().deltaEta, dnn::ele_mvaInput_deltaEta - e_index_offset);
2229  }
2230  const auto& gsfTrack = ele.gsfTrack();
2231  if (gsfTrack.isNonnull()) {
2232  get(dnn::ele_gsfTrack_normalizedChi2 + fill_index_offset_e) =
2233  sp.scale(gsfTrack->normalizedChi2(), dnn::ele_gsfTrack_normalizedChi2 - e_index_offset);
2234  get(dnn::ele_gsfTrack_numberOfValidHits + fill_index_offset_e) =
2235  sp.scale(gsfTrack->numberOfValidHits(), dnn::ele_gsfTrack_numberOfValidHits - e_index_offset);
2236  get(dnn::ele_rel_gsfTrack_pt + fill_index_offset_e) =
2237  sp.scale(gsfTrack->pt() / ele.polarP4().pt(), dnn::ele_rel_gsfTrack_pt - e_index_offset);
2238  get(dnn::ele_gsfTrack_pt_sig + fill_index_offset_e) =
2239  sp.scale(gsfTrack->pt() / gsfTrack->ptError(), dnn::ele_gsfTrack_pt_sig - e_index_offset);
2240  }
2241  const auto& closestCtfTrack = ele.closestCtfTrackRef();
2242  const bool has_closestCtfTrack = closestCtfTrack.isNonnull();
2243  if (has_closestCtfTrack) {
2244  get(dnn::ele_has_closestCtfTrack + fill_index_offset_e) =
2245  sp.scale(has_closestCtfTrack, dnn::ele_has_closestCtfTrack - e_index_offset);
2246  get(dnn::ele_closestCtfTrack_normalizedChi2 + fill_index_offset_e) =
2247  sp.scale(closestCtfTrack->normalizedChi2(), dnn::ele_closestCtfTrack_normalizedChi2 - e_index_offset);
2248  get(dnn::ele_closestCtfTrack_numberOfValidHits + fill_index_offset_e) =
2249  sp.scale(closestCtfTrack->numberOfValidHits(), dnn::ele_closestCtfTrack_numberOfValidHits - e_index_offset);
2250  }
2251  }
2252  }
static bool isInEcalCrack(double eta)
Definition: DeepTauId.cc:2669
const unsigned sub_version_
Definition: DeepTauId.cc:2726
const std::map< std::pair< deep_tau::Scaling::FeatureT, bool >, deep_tau::Scaling::ScalingParams > * scalingParamsMap_
Definition: DeepTauId.cc:2734
const unsigned year_
Definition: DeepTauId.cc:2724
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
const_reference at(size_type pos) const
static bool calculateElectronClusterVarsV2(const pat::Electron &ele, float &cc_ele_energy, float &cc_gamma_energy, int &cc_n_gamma)
Definition: DeepTauId.cc:1308
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > eGammaTensor_
Definition: DeepTauId.cc:2732

◆ createHadronsBlockInputs()

template<typename CandidateCastType , typename TauCastType >
void DeepTauId::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 
)
inlineprivate

Definition at line 2406 of file DeepTauId.cc.

References funct::abs(), edm::View< T >::at(), nano_mu_local_reco_cff::chi2, disable_hcalFraction_workaround_, HLT_2023v12_cff::dPhi, f, nano_mu_digi_cff::float, hadronsTensor_, heavyIonCSV_trainingSettings::idx, PixelMapPlotter::inputs, isInEcalCrack(), ndof, rho, IsoPhotonEBSkim_cff::rho, scalingParamsMap_, runTauDisplay::tau_eta, and runTauDisplay::tau_pt.

2415  {
2416  namespace dnn = dnn_inputs_v2::HadronBlockInputs;
2417  namespace sc = deep_tau::Scaling;
2418  sc::FeatureT ft_global = sc::FeatureT::GridGlobal;
2419  sc::FeatureT ft_PFchH = sc::FeatureT::PfCand_chHad;
2420  sc::FeatureT ft_PFnH = sc::FeatureT::PfCand_nHad;
2421 
2422  // needed to remap indices from scaling vectors to those from dnn_inputs_v2::HadronBlockInputs
2423  int PFchH_index_offset = scalingParamsMap_->at(std::make_pair(ft_global, false)).mean_.size();
2424  int PFnH_index_offset = PFchH_index_offset + scalingParamsMap_->at(std::make_pair(ft_PFchH, false)).mean_.size();
2425 
2426  tensorflow::Tensor& inputs = *hadronsTensor_.at(is_inner);
2427 
2428  const auto& get = [&](int var_index) -> float& { return inputs.tensor<float, 4>()(idx, 0, 0, var_index); };
2429 
2430  const bool valid_chH = cell_map.count(CellObjectType::PfCand_chargedHadron);
2431  const bool valid_nH = cell_map.count(CellObjectType::PfCand_neutralHadron);
2432 
2433  if (!cell_map.empty()) {
2434  const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft_global, false));
2435  get(dnn::rho) = sp.scale(rho, dnn::rho);
2436  get(dnn::tau_pt) = sp.scale(tau.polarP4().pt(), dnn::tau_pt);
2437  get(dnn::tau_eta) = sp.scale(tau.polarP4().eta(), dnn::tau_eta);
2438  get(dnn::tau_inside_ecal_crack) = sp.scale(isInEcalCrack(tau.polarP4().eta()), dnn::tau_inside_ecal_crack);
2439  }
2440  if (valid_chH) {
2441  const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft_PFchH, is_inner));
2442  size_t index_chH = cell_map.at(CellObjectType::PfCand_chargedHadron);
2443  const auto& chH_cand = dynamic_cast<const CandidateCastType&>(pfCands.at(index_chH));
2444 
2445  get(dnn::pfCand_chHad_valid) = sp.scale(valid_chH, dnn::pfCand_chHad_valid - PFchH_index_offset);
2446  get(dnn::pfCand_chHad_rel_pt) =
2447  sp.scale(chH_cand.polarP4().pt() / tau.polarP4().pt(), dnn::pfCand_chHad_rel_pt - PFchH_index_offset);
2448  get(dnn::pfCand_chHad_deta) =
2449  sp.scale(chH_cand.polarP4().eta() - tau.polarP4().eta(), dnn::pfCand_chHad_deta - PFchH_index_offset);
2450  get(dnn::pfCand_chHad_dphi) =
2451  sp.scale(dPhi(tau.polarP4(), chH_cand.polarP4()), dnn::pfCand_chHad_dphi - PFchH_index_offset);
2452  get(dnn::pfCand_chHad_leadChargedHadrCand) =
2453  sp.scale(&chH_cand == dynamic_cast<const CandidateCastType*>(tau.leadChargedHadrCand().get()),
2454  dnn::pfCand_chHad_leadChargedHadrCand - PFchH_index_offset);
2455  get(dnn::pfCand_chHad_pvAssociationQuality) = sp.scale<int>(
2456  candFunc::getPvAssocationQuality(chH_cand), dnn::pfCand_chHad_pvAssociationQuality - PFchH_index_offset);
2457  get(dnn::pfCand_chHad_fromPV) =
2458  sp.scale<int>(candFunc::getFromPV(chH_cand), dnn::pfCand_chHad_fromPV - PFchH_index_offset);
2459  const float default_chH_pw_inner = 0.7614090f;
2460  const float default_chH_pw_outer = 0.1974930f;
2461  get(dnn::pfCand_chHad_puppiWeight) = is_inner ? sp.scale(candFunc::getPuppiWeight(chH_cand, default_chH_pw_inner),
2462  dnn::pfCand_chHad_puppiWeight - PFchH_index_offset)
2463  : sp.scale(candFunc::getPuppiWeight(chH_cand, default_chH_pw_outer),
2464  dnn::pfCand_chHad_puppiWeight - PFchH_index_offset);
2465  get(dnn::pfCand_chHad_puppiWeightNoLep) =
2466  is_inner ? sp.scale(candFunc::getPuppiWeightNoLep(chH_cand, default_chH_pw_inner),
2467  dnn::pfCand_chHad_puppiWeightNoLep - PFchH_index_offset)
2468  : sp.scale(candFunc::getPuppiWeightNoLep(chH_cand, default_chH_pw_outer),
2469  dnn::pfCand_chHad_puppiWeightNoLep - PFchH_index_offset);
2470  get(dnn::pfCand_chHad_charge) = sp.scale(chH_cand.charge(), dnn::pfCand_chHad_charge - PFchH_index_offset);
2471  get(dnn::pfCand_chHad_lostInnerHits) =
2472  sp.scale<int>(candFunc::getLostInnerHits(chH_cand, 0), dnn::pfCand_chHad_lostInnerHits - PFchH_index_offset);
2473  get(dnn::pfCand_chHad_numberOfPixelHits) = sp.scale(candFunc::getNumberOfPixelHits(chH_cand, 0),
2474  dnn::pfCand_chHad_numberOfPixelHits - PFchH_index_offset);
2475  get(dnn::pfCand_chHad_vertex_dx) =
2476  sp.scale(chH_cand.vertex().x() - pv.position().x(), dnn::pfCand_chHad_vertex_dx - PFchH_index_offset);
2477  get(dnn::pfCand_chHad_vertex_dy) =
2478  sp.scale(chH_cand.vertex().y() - pv.position().y(), dnn::pfCand_chHad_vertex_dy - PFchH_index_offset);
2479  get(dnn::pfCand_chHad_vertex_dz) =
2480  sp.scale(chH_cand.vertex().z() - pv.position().z(), dnn::pfCand_chHad_vertex_dz - PFchH_index_offset);
2481  get(dnn::pfCand_chHad_vertex_dx_tauFL) =
2482  sp.scale(chH_cand.vertex().x() - pv.position().x() - tau_funcs.getFlightLength(tau, tau_index).x(),
2483  dnn::pfCand_chHad_vertex_dx_tauFL - PFchH_index_offset);
2484  get(dnn::pfCand_chHad_vertex_dy_tauFL) =
2485  sp.scale(chH_cand.vertex().y() - pv.position().y() - tau_funcs.getFlightLength(tau, tau_index).y(),
2486  dnn::pfCand_chHad_vertex_dy_tauFL - PFchH_index_offset);
2487  get(dnn::pfCand_chHad_vertex_dz_tauFL) =
2488  sp.scale(chH_cand.vertex().z() - pv.position().z() - tau_funcs.getFlightLength(tau, tau_index).z(),
2489  dnn::pfCand_chHad_vertex_dz_tauFL - PFchH_index_offset);
2490 
2491  const bool hasTrackDetails = candFunc::getHasTrackDetails(chH_cand);
2492  if (hasTrackDetails) {
2493  get(dnn::pfCand_chHad_hasTrackDetails) =
2494  sp.scale(hasTrackDetails, dnn::pfCand_chHad_hasTrackDetails - PFchH_index_offset);
2495  get(dnn::pfCand_chHad_dxy) =
2496  sp.scale(candFunc::getTauDxy(chH_cand), dnn::pfCand_chHad_dxy - PFchH_index_offset);
2497  get(dnn::pfCand_chHad_dxy_sig) = sp.scale(std::abs(candFunc::getTauDxy(chH_cand)) / chH_cand.dxyError(),
2498  dnn::pfCand_chHad_dxy_sig - PFchH_index_offset);
2499  get(dnn::pfCand_chHad_dz) = sp.scale(candFunc::getTauDz(chH_cand), dnn::pfCand_chHad_dz - PFchH_index_offset);
2500  get(dnn::pfCand_chHad_dz_sig) = sp.scale(std::abs(candFunc::getTauDz(chH_cand)) / chH_cand.dzError(),
2501  dnn::pfCand_chHad_dz_sig - PFchH_index_offset);
2502  get(dnn::pfCand_chHad_track_chi2_ndof) =
2503  candFunc::getPseudoTrack(chH_cand).ndof() > 0
2504  ? sp.scale(candFunc::getPseudoTrack(chH_cand).chi2() / candFunc::getPseudoTrack(chH_cand).ndof(),
2505  dnn::pfCand_chHad_track_chi2_ndof - PFchH_index_offset)
2506  : 0;
2507  get(dnn::pfCand_chHad_track_ndof) =
2508  candFunc::getPseudoTrack(chH_cand).ndof() > 0
2509  ? sp.scale(candFunc::getPseudoTrack(chH_cand).ndof(), dnn::pfCand_chHad_track_ndof - PFchH_index_offset)
2510  : 0;
2511  }
2512  float hcal_fraction = candFunc::getHCalFraction(chH_cand, disable_hcalFraction_workaround_);
2513  get(dnn::pfCand_chHad_hcalFraction) =
2514  sp.scale(hcal_fraction, dnn::pfCand_chHad_hcalFraction - PFchH_index_offset);
2515  get(dnn::pfCand_chHad_rawCaloFraction) =
2516  sp.scale(candFunc::getRawCaloFraction(chH_cand), dnn::pfCand_chHad_rawCaloFraction - PFchH_index_offset);
2517  }
2518  if (valid_nH) {
2519  const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft_PFnH, is_inner));
2520  size_t index_nH = cell_map.at(CellObjectType::PfCand_neutralHadron);
2521  const auto& nH_cand = dynamic_cast<const CandidateCastType&>(pfCands.at(index_nH));
2522 
2523  get(dnn::pfCand_nHad_valid) = sp.scale(valid_nH, dnn::pfCand_nHad_valid - PFnH_index_offset);
2524  get(dnn::pfCand_nHad_rel_pt) =
2525  sp.scale(nH_cand.polarP4().pt() / tau.polarP4().pt(), dnn::pfCand_nHad_rel_pt - PFnH_index_offset);
2526  get(dnn::pfCand_nHad_deta) =
2527  sp.scale(nH_cand.polarP4().eta() - tau.polarP4().eta(), dnn::pfCand_nHad_deta - PFnH_index_offset);
2528  get(dnn::pfCand_nHad_dphi) =
2529  sp.scale(dPhi(tau.polarP4(), nH_cand.polarP4()), dnn::pfCand_nHad_dphi - PFnH_index_offset);
2530  get(dnn::pfCand_nHad_puppiWeight) = is_inner ? sp.scale(candFunc::getPuppiWeight(nH_cand, 0.9798355f),
2531  dnn::pfCand_nHad_puppiWeight - PFnH_index_offset)
2532  : sp.scale(candFunc::getPuppiWeight(nH_cand, 0.7813260f),
2533  dnn::pfCand_nHad_puppiWeight - PFnH_index_offset);
2534  get(dnn::pfCand_nHad_puppiWeightNoLep) = is_inner
2535  ? sp.scale(candFunc::getPuppiWeightNoLep(nH_cand, 0.9046796f),
2536  dnn::pfCand_nHad_puppiWeightNoLep - PFnH_index_offset)
2537  : sp.scale(candFunc::getPuppiWeightNoLep(nH_cand, 0.6554860f),
2538  dnn::pfCand_nHad_puppiWeightNoLep - PFnH_index_offset);
2539  float hcal_fraction = candFunc::getHCalFraction(nH_cand, disable_hcalFraction_workaround_);
2540  get(dnn::pfCand_nHad_hcalFraction) = sp.scale(hcal_fraction, dnn::pfCand_nHad_hcalFraction - PFnH_index_offset);
2541  }
2542  }
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > hadronsTensor_
Definition: DeepTauId.cc:2732
static bool isInEcalCrack(double eta)
Definition: DeepTauId.cc:2669
const std::map< std::pair< deep_tau::Scaling::FeatureT, bool >, deep_tau::Scaling::ScalingParams > * scalingParamsMap_
Definition: DeepTauId.cc:2734
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
const_reference at(size_type pos) const
const bool disable_hcalFraction_workaround_
Definition: DeepTauId.cc:2729

◆ createMuonBlockInputs()

template<typename CandidateCastType , typename TauCastType >
void DeepTauId::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 
)
inlineprivate

Definition at line 2255 of file DeepTauId.cc.

References funct::abs(), edm::View< T >::at(), nano_mu_local_reco_cff::chi2, MuonSubdetId::CSC, HLT_2023v12_cff::dPhi, MuonSubdetId::DT, f, nano_mu_digi_cff::float, heavyIonCSV_trainingSettings::idx, PixelMapPlotter::inputs, isInEcalCrack(), dumpRecoGeometry_cfg::Muon, PDWG_BPHSkim_cff::muons, muonTensor_, ndof, pat::Muon::PV2D, rho, IsoPhotonEBSkim_cff::rho, MuonSubdetId::RPC, scalingParamsMap_, relativeConstraints::station, runTauDisplay::tau_eta, and runTauDisplay::tau_pt.

2265  {
2266  namespace dnn = dnn_inputs_v2::MuonBlockInputs;
2267  namespace sc = deep_tau::Scaling;
2268  sc::FeatureT ft_global = sc::FeatureT::GridGlobal;
2269  sc::FeatureT ft_PFmu = sc::FeatureT::PfCand_muon;
2271 
2272  // needed to remap indices from scaling vectors to those from dnn_inputs_v2::MuonBlockInputs
2273  int PFmu_index_offset = scalingParamsMap_->at(std::make_pair(ft_global, false)).mean_.size();
2274  int mu_index_offset = PFmu_index_offset + scalingParamsMap_->at(std::make_pair(ft_PFmu, false)).mean_.size();
2275 
2276  tensorflow::Tensor& inputs = *muonTensor_.at(is_inner);
2277 
2278  const auto& get = [&](int var_index) -> float& { return inputs.tensor<float, 4>()(idx, 0, 0, var_index); };
2279 
2280  const bool valid_index_pf_muon = cell_map.count(CellObjectType::PfCand_muon);
2281  const bool valid_index_muon = cell_map.count(CellObjectType::Muon);
2282 
2283  if (!cell_map.empty()) {
2284  const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft_global, false));
2285  get(dnn::rho) = sp.scale(rho, dnn::rho);
2286  get(dnn::tau_pt) = sp.scale(tau.polarP4().pt(), dnn::tau_pt);
2287  get(dnn::tau_eta) = sp.scale(tau.polarP4().eta(), dnn::tau_eta);
2288  get(dnn::tau_inside_ecal_crack) = sp.scale(isInEcalCrack(tau.polarP4().eta()), dnn::tau_inside_ecal_crack);
2289  }
2290  if (valid_index_pf_muon) {
2291  const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft_PFmu, is_inner));
2292  size_t index_pf_muon = cell_map.at(CellObjectType::PfCand_muon);
2293  const auto& muon_cand = dynamic_cast<const CandidateCastType&>(pfCands.at(index_pf_muon));
2294 
2295  get(dnn::pfCand_muon_valid) = sp.scale(valid_index_pf_muon, dnn::pfCand_muon_valid - PFmu_index_offset);
2296  get(dnn::pfCand_muon_rel_pt) =
2297  sp.scale(muon_cand.polarP4().pt() / tau.polarP4().pt(), dnn::pfCand_muon_rel_pt - PFmu_index_offset);
2298  get(dnn::pfCand_muon_deta) =
2299  sp.scale(muon_cand.polarP4().eta() - tau.polarP4().eta(), dnn::pfCand_muon_deta - PFmu_index_offset);
2300  get(dnn::pfCand_muon_dphi) =
2301  sp.scale(dPhi(tau.polarP4(), muon_cand.polarP4()), dnn::pfCand_muon_dphi - PFmu_index_offset);
2302  get(dnn::pfCand_muon_pvAssociationQuality) = sp.scale<int>(
2303  candFunc::getPvAssocationQuality(muon_cand), dnn::pfCand_muon_pvAssociationQuality - PFmu_index_offset);
2304  get(dnn::pfCand_muon_fromPV) =
2305  sp.scale<int>(candFunc::getFromPV(muon_cand), dnn::pfCand_muon_fromPV - PFmu_index_offset);
2306  get(dnn::pfCand_muon_puppiWeight) = is_inner ? sp.scale(candFunc::getPuppiWeight(muon_cand, 0.9786588f),
2307  dnn::pfCand_muon_puppiWeight - PFmu_index_offset)
2308  : sp.scale(candFunc::getPuppiWeight(muon_cand, 0.8132477f),
2309  dnn::pfCand_muon_puppiWeight - PFmu_index_offset);
2310  get(dnn::pfCand_muon_charge) = sp.scale(muon_cand.charge(), dnn::pfCand_muon_charge - PFmu_index_offset);
2311  get(dnn::pfCand_muon_lostInnerHits) =
2312  sp.scale<int>(candFunc::getLostInnerHits(muon_cand, 0), dnn::pfCand_muon_lostInnerHits - PFmu_index_offset);
2313  get(dnn::pfCand_muon_numberOfPixelHits) = sp.scale(candFunc::getNumberOfPixelHits(muon_cand, 0),
2314  dnn::pfCand_muon_numberOfPixelHits - PFmu_index_offset);
2315  get(dnn::pfCand_muon_vertex_dx) =
2316  sp.scale(muon_cand.vertex().x() - pv.position().x(), dnn::pfCand_muon_vertex_dx - PFmu_index_offset);
2317  get(dnn::pfCand_muon_vertex_dy) =
2318  sp.scale(muon_cand.vertex().y() - pv.position().y(), dnn::pfCand_muon_vertex_dy - PFmu_index_offset);
2319  get(dnn::pfCand_muon_vertex_dz) =
2320  sp.scale(muon_cand.vertex().z() - pv.position().z(), dnn::pfCand_muon_vertex_dz - PFmu_index_offset);
2321  get(dnn::pfCand_muon_vertex_dx_tauFL) =
2322  sp.scale(muon_cand.vertex().x() - pv.position().x() - tau_funcs.getFlightLength(tau, tau_index).x(),
2323  dnn::pfCand_muon_vertex_dx_tauFL - PFmu_index_offset);
2324  get(dnn::pfCand_muon_vertex_dy_tauFL) =
2325  sp.scale(muon_cand.vertex().y() - pv.position().y() - tau_funcs.getFlightLength(tau, tau_index).y(),
2326  dnn::pfCand_muon_vertex_dy_tauFL - PFmu_index_offset);
2327  get(dnn::pfCand_muon_vertex_dz_tauFL) =
2328  sp.scale(muon_cand.vertex().z() - pv.position().z() - tau_funcs.getFlightLength(tau, tau_index).z(),
2329  dnn::pfCand_muon_vertex_dz_tauFL - PFmu_index_offset);
2330 
2331  const bool hasTrackDetails = candFunc::getHasTrackDetails(muon_cand);
2332  if (hasTrackDetails) {
2333  get(dnn::pfCand_muon_hasTrackDetails) =
2334  sp.scale(hasTrackDetails, dnn::pfCand_muon_hasTrackDetails - PFmu_index_offset);
2335  get(dnn::pfCand_muon_dxy) = sp.scale(candFunc::getTauDxy(muon_cand), dnn::pfCand_muon_dxy - PFmu_index_offset);
2336  get(dnn::pfCand_muon_dxy_sig) = sp.scale(std::abs(candFunc::getTauDxy(muon_cand)) / muon_cand.dxyError(),
2337  dnn::pfCand_muon_dxy_sig - PFmu_index_offset);
2338  get(dnn::pfCand_muon_dz) = sp.scale(candFunc::getTauDz(muon_cand), dnn::pfCand_muon_dz - PFmu_index_offset);
2339  get(dnn::pfCand_muon_dz_sig) = sp.scale(std::abs(candFunc::getTauDz(muon_cand)) / muon_cand.dzError(),
2340  dnn::pfCand_muon_dz_sig - PFmu_index_offset);
2341  get(dnn::pfCand_muon_track_chi2_ndof) =
2342  candFunc::getPseudoTrack(muon_cand).ndof() > 0
2343  ? sp.scale(candFunc::getPseudoTrack(muon_cand).chi2() / candFunc::getPseudoTrack(muon_cand).ndof(),
2344  dnn::pfCand_muon_track_chi2_ndof - PFmu_index_offset)
2345  : 0;
2346  get(dnn::pfCand_muon_track_ndof) =
2347  candFunc::getPseudoTrack(muon_cand).ndof() > 0
2348  ? sp.scale(candFunc::getPseudoTrack(muon_cand).ndof(), dnn::pfCand_muon_track_ndof - PFmu_index_offset)
2349  : 0;
2350  }
2351  }
2352  if (valid_index_muon) {
2353  const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft_mu, is_inner));
2354  size_t index_muon = cell_map.at(CellObjectType::Muon);
2355  const auto& muon = muons->at(index_muon);
2356 
2357  get(dnn::muon_valid) = sp.scale(valid_index_muon, dnn::muon_valid - mu_index_offset);
2358  get(dnn::muon_rel_pt) = sp.scale(muon.polarP4().pt() / tau.polarP4().pt(), dnn::muon_rel_pt - mu_index_offset);
2359  get(dnn::muon_deta) = sp.scale(muon.polarP4().eta() - tau.polarP4().eta(), dnn::muon_deta - mu_index_offset);
2360  get(dnn::muon_dphi) = sp.scale(dPhi(tau.polarP4(), muon.polarP4()), dnn::muon_dphi - mu_index_offset);
2361  get(dnn::muon_dxy) = sp.scale(muon.dB(pat::Muon::PV2D), dnn::muon_dxy - mu_index_offset);
2362  get(dnn::muon_dxy_sig) =
2363  sp.scale(std::abs(muon.dB(pat::Muon::PV2D)) / muon.edB(pat::Muon::PV2D), dnn::muon_dxy_sig - mu_index_offset);
2364 
2365  const bool normalizedChi2_valid = muon.globalTrack().isNonnull() && muon.normChi2() >= 0;
2366  if (normalizedChi2_valid) {
2367  get(dnn::muon_normalizedChi2_valid) =
2368  sp.scale(normalizedChi2_valid, dnn::muon_normalizedChi2_valid - mu_index_offset);
2369  get(dnn::muon_normalizedChi2) = sp.scale(muon.normChi2(), dnn::muon_normalizedChi2 - mu_index_offset);
2370  if (muon.innerTrack().isNonnull())
2371  get(dnn::muon_numberOfValidHits) =
2372  sp.scale(muon.numberOfValidHits(), dnn::muon_numberOfValidHits - mu_index_offset);
2373  }
2374  get(dnn::muon_segmentCompatibility) =
2375  sp.scale(muon.segmentCompatibility(), dnn::muon_segmentCompatibility - mu_index_offset);
2376  get(dnn::muon_caloCompatibility) =
2377  sp.scale(muon.caloCompatibility(), dnn::muon_caloCompatibility - mu_index_offset);
2378 
2379  const bool pfEcalEnergy_valid = muon.pfEcalEnergy() >= 0;
2380  if (pfEcalEnergy_valid) {
2381  get(dnn::muon_pfEcalEnergy_valid) =
2382  sp.scale(pfEcalEnergy_valid, dnn::muon_pfEcalEnergy_valid - mu_index_offset);
2383  get(dnn::muon_rel_pfEcalEnergy) =
2384  sp.scale(muon.pfEcalEnergy() / muon.polarP4().pt(), dnn::muon_rel_pfEcalEnergy - mu_index_offset);
2385  }
2386 
2387  MuonHitMatchV2 hit_match(muon);
2388  static const std::map<int, std::pair<int, int>> muonMatchHitVars = {
2389  {MuonSubdetId::DT, {dnn::muon_n_matches_DT_1, dnn::muon_n_hits_DT_1}},
2390  {MuonSubdetId::CSC, {dnn::muon_n_matches_CSC_1, dnn::muon_n_hits_CSC_1}},
2391  {MuonSubdetId::RPC, {dnn::muon_n_matches_RPC_1, dnn::muon_n_hits_RPC_1}}};
2392 
2393  for (int subdet : hit_match.MuonHitMatchV2::consideredSubdets()) {
2394  const auto& matchHitVar = muonMatchHitVars.at(subdet);
2395  for (int station = MuonHitMatchV2::first_station_id; station <= MuonHitMatchV2::last_station_id; ++station) {
2396  const unsigned n_matches = hit_match.nMatches(subdet, station);
2397  const unsigned n_hits = hit_match.nHits(subdet, station);
2398  get(matchHitVar.first + station - 1) = sp.scale(n_matches, matchHitVar.first + station - 1 - mu_index_offset);
2399  get(matchHitVar.second + station - 1) = sp.scale(n_hits, matchHitVar.second + station - 1 - mu_index_offset);
2400  }
2401  }
2402  }
2403  }
static bool isInEcalCrack(double eta)
Definition: DeepTauId.cc:2669
const std::map< std::pair< deep_tau::Scaling::FeatureT, bool >, deep_tau::Scaling::ScalingParams > * scalingParamsMap_
Definition: DeepTauId.cc:2734
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
const_reference at(size_type pos) const
static constexpr int RPC
Definition: MuonSubdetId.h:13
static constexpr int DT
Definition: MuonSubdetId.h:11
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > muonTensor_
Definition: DeepTauId.cc:2732
static constexpr int CSC
Definition: MuonSubdetId.h:12

◆ createOutputs()

void DeepTauId::createOutputs ( edm::Event event,
const tensorflow::Tensor &  pred,
edm::Handle< TauCollection taus 
)
inlineprivate

Definition at line 1273 of file DeepTauId.cc.

References is_online_, eostools::move(), outputs_, mps_fire::result, Tau3MuMonitor_cff::taus, FWLite::working_points, and workingPoints_.

Referenced by produce().

1273  {
1274  for (const auto& output_desc : outputs_) {
1275  const WPList* working_points = nullptr;
1276  if (workingPoints_.find(output_desc.first) != workingPoints_.end()) {
1277  working_points = &workingPoints_.at(output_desc.first);
1278  }
1279  auto result = output_desc.second.get_value(taus, pred, working_points, is_online_);
1280  event.put(std::move(result), output_desc.first);
1281  }
1282  }
std::map< std::string, WPList > workingPoints_
Definition: DeepTauId.cc:2692
working_points
Definition: FWLite.py:134
OutputCollection outputs_
Definition: DeepTauId.cc:2694
const bool is_online_
Definition: DeepTauId.cc:2693
std::vector< CutterPtr > WPList
Definition: DeepTauId.cc:907
def move(src, dest)
Definition: eostools.py:511

◆ createTauBlockInputs()

template<typename CandidateCastType , typename TauCastType >
void DeepTauId::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 
)
inlineprivate

Definition at line 1831 of file DeepTauId.cc.

References funct::abs(), calculateGottfriedJacksonAngleDifference(), disable_dxy_pca_, run3scouting_cff::dzError, reco::tau::eratio(), getValueLinear(), PixelMapPlotter::inputs, is_online_, isAbove(), isInEcalCrack(), reco::tau::n_photons_total(), pi, reco::tau::pt_weighted_deta_strip(), reco::tau::pt_weighted_dphi_strip(), reco::tau::pt_weighted_dr_iso(), reco::tau::pt_weighted_dr_signal(), rho, IsoPhotonEBSkim_cff::rho, scalingParamsMap_, sub_version_, runTauDisplay::tau_eta, runTauDisplay::tau_mass, runTauDisplay::tau_phi, runTauDisplay::tau_pt, tauBlockTensor_, and tauInputs_indices_.

1836  {
1837  namespace dnn = dnn_inputs_v2::TauBlockInputs;
1838  namespace sc = deep_tau::Scaling;
1839  sc::FeatureT ft = sc::FeatureT::TauFlat;
1840  const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft, false));
1841 
1842  tensorflow::Tensor& inputs = *tauBlockTensor_;
1843  inputs.flat<float>().setZero();
1844 
1845  const auto& get = [&](int var_index) -> float& {
1846  return inputs.matrix<float>()(0, tauInputs_indices_.at(var_index));
1847  };
1848 
1849  auto leadChargedHadrCand = dynamic_cast<const CandidateCastType*>(tau.leadChargedHadrCand().get());
1850 
1851  get(dnn::rho) = sp.scale(rho, tauInputs_indices_[dnn::rho]);
1852  get(dnn::tau_pt) = sp.scale(tau.polarP4().pt(), tauInputs_indices_[dnn::tau_pt]);
1853  get(dnn::tau_eta) = sp.scale(tau.polarP4().eta(), tauInputs_indices_[dnn::tau_eta]);
1854  if (sub_version_ == 1) {
1855  get(dnn::tau_phi) = getValueLinear(tau.polarP4().phi(), -pi, pi, false);
1856  }
1857  get(dnn::tau_mass) = sp.scale(tau.polarP4().mass(), tauInputs_indices_[dnn::tau_mass]);
1858  get(dnn::tau_E_over_pt) = sp.scale(tau.p4().energy() / tau.p4().pt(), tauInputs_indices_[dnn::tau_E_over_pt]);
1859  get(dnn::tau_charge) = sp.scale(tau.charge(), tauInputs_indices_[dnn::tau_charge]);
1860  get(dnn::tau_n_charged_prongs) = sp.scale(tau.decayMode() / 5 + 1, tauInputs_indices_[dnn::tau_n_charged_prongs]);
1861  get(dnn::tau_n_neutral_prongs) = sp.scale(tau.decayMode() % 5, tauInputs_indices_[dnn::tau_n_neutral_prongs]);
1862  get(dnn::chargedIsoPtSum) =
1863  sp.scale(tau_funcs.getChargedIsoPtSum(tau, tau_ref), tauInputs_indices_[dnn::chargedIsoPtSum]);
1864  get(dnn::chargedIsoPtSumdR03_over_dR05) =
1865  sp.scale(tau_funcs.getChargedIsoPtSumdR03(tau, tau_ref) / tau_funcs.getChargedIsoPtSum(tau, tau_ref),
1866  tauInputs_indices_[dnn::chargedIsoPtSumdR03_over_dR05]);
1867  if (sub_version_ == 1)
1868  get(dnn::footprintCorrection) =
1869  sp.scale(tau_funcs.getFootprintCorrectiondR03(tau, tau_ref), tauInputs_indices_[dnn::footprintCorrection]);
1870  else if (sub_version_ == 5)
1871  get(dnn::footprintCorrection) =
1872  sp.scale(tau_funcs.getFootprintCorrection(tau, tau_ref), tauInputs_indices_[dnn::footprintCorrection]);
1873 
1874  get(dnn::neutralIsoPtSum) =
1875  sp.scale(tau_funcs.getNeutralIsoPtSum(tau, tau_ref), tauInputs_indices_[dnn::neutralIsoPtSum]);
1876  get(dnn::neutralIsoPtSumWeight_over_neutralIsoPtSum) =
1877  sp.scale(tau_funcs.getNeutralIsoPtSumWeight(tau, tau_ref) / tau_funcs.getNeutralIsoPtSum(tau, tau_ref),
1878  tauInputs_indices_[dnn::neutralIsoPtSumWeight_over_neutralIsoPtSum]);
1879  get(dnn::neutralIsoPtSumWeightdR03_over_neutralIsoPtSum) =
1880  sp.scale(tau_funcs.getNeutralIsoPtSumdR03Weight(tau, tau_ref) / tau_funcs.getNeutralIsoPtSum(tau, tau_ref),
1881  tauInputs_indices_[dnn::neutralIsoPtSumWeightdR03_over_neutralIsoPtSum]);
1882  get(dnn::neutralIsoPtSumdR03_over_dR05) =
1883  sp.scale(tau_funcs.getNeutralIsoPtSumdR03(tau, tau_ref) / tau_funcs.getNeutralIsoPtSum(tau, tau_ref),
1884  tauInputs_indices_[dnn::neutralIsoPtSumdR03_over_dR05]);
1885  get(dnn::photonPtSumOutsideSignalCone) = sp.scale(tau_funcs.getPhotonPtSumOutsideSignalCone(tau, tau_ref),
1886  tauInputs_indices_[dnn::photonPtSumOutsideSignalCone]);
1887  get(dnn::puCorrPtSum) = sp.scale(tau_funcs.getPuCorrPtSum(tau, tau_ref), tauInputs_indices_[dnn::puCorrPtSum]);
1888  // The global PCA coordinates were used as inputs during the NN training, but it was decided to disable
1889  // them for the inference, because modeling of dxy_PCA in MC poorly describes the data, and x and y coordinates
1890  // in data results outside of the expected 5 std. dev. input validity range. On the other hand,
1891  // these coordinates are strongly era-dependent. Kept as comment to document what NN expects.
1892  if (sub_version_ == 1) {
1893  if (!disable_dxy_pca_) {
1894  auto const pca = tau_funcs.getdxyPCA(tau, tau_index);
1895  get(dnn::tau_dxy_pca_x) = sp.scale(pca.x(), tauInputs_indices_[dnn::tau_dxy_pca_x]);
1896  get(dnn::tau_dxy_pca_y) = sp.scale(pca.y(), tauInputs_indices_[dnn::tau_dxy_pca_y]);
1897  get(dnn::tau_dxy_pca_z) = sp.scale(pca.z(), tauInputs_indices_[dnn::tau_dxy_pca_z]);
1898  } else {
1899  get(dnn::tau_dxy_pca_x) = 0;
1900  get(dnn::tau_dxy_pca_y) = 0;
1901  get(dnn::tau_dxy_pca_z) = 0;
1902  }
1903  }
1904 
1905  const bool tau_dxy_valid =
1906  isAbove(tau_funcs.getdxy(tau, tau_index), -10) && isAbove(tau_funcs.getdxyError(tau, tau_index), 0);
1907  if (tau_dxy_valid) {
1908  get(dnn::tau_dxy_valid) = sp.scale(tau_dxy_valid, tauInputs_indices_[dnn::tau_dxy_valid]);
1909  get(dnn::tau_dxy) = sp.scale(tau_funcs.getdxy(tau, tau_index), tauInputs_indices_[dnn::tau_dxy]);
1910  get(dnn::tau_dxy_sig) =
1911  sp.scale(std::abs(tau_funcs.getdxy(tau, tau_index)) / tau_funcs.getdxyError(tau, tau_index),
1912  tauInputs_indices_[dnn::tau_dxy_sig]);
1913  }
1914  const bool tau_ip3d_valid =
1915  isAbove(tau_funcs.getip3d(tau, tau_index), -10) && isAbove(tau_funcs.getip3dError(tau, tau_index), 0);
1916  if (tau_ip3d_valid) {
1917  get(dnn::tau_ip3d_valid) = sp.scale(tau_ip3d_valid, tauInputs_indices_[dnn::tau_ip3d_valid]);
1918  get(dnn::tau_ip3d) = sp.scale(tau_funcs.getip3d(tau, tau_index), tauInputs_indices_[dnn::tau_ip3d]);
1919  get(dnn::tau_ip3d_sig) =
1920  sp.scale(std::abs(tau_funcs.getip3d(tau, tau_index)) / tau_funcs.getip3dError(tau, tau_index),
1921  tauInputs_indices_[dnn::tau_ip3d_sig]);
1922  }
1923  if (leadChargedHadrCand) {
1924  const bool hasTrackDetails = candFunc::getHasTrackDetails(*leadChargedHadrCand);
1925  const float tau_dz = (is_online_ && !hasTrackDetails) ? 0 : candFunc::getTauDz(*leadChargedHadrCand);
1926  get(dnn::tau_dz) = sp.scale(tau_dz, tauInputs_indices_[dnn::tau_dz]);
1927  get(dnn::tau_dz_sig_valid) =
1928  sp.scale(candFunc::getTauDZSigValid(*leadChargedHadrCand), tauInputs_indices_[dnn::tau_dz_sig_valid]);
1929  const double dzError = hasTrackDetails ? leadChargedHadrCand->dzError() : -999.;
1930  get(dnn::tau_dz_sig) = sp.scale(std::abs(tau_dz) / dzError, tauInputs_indices_[dnn::tau_dz_sig]);
1931  }
1932  get(dnn::tau_flightLength_x) =
1933  sp.scale(tau_funcs.getFlightLength(tau, tau_index).x(), tauInputs_indices_[dnn::tau_flightLength_x]);
1934  get(dnn::tau_flightLength_y) =
1935  sp.scale(tau_funcs.getFlightLength(tau, tau_index).y(), tauInputs_indices_[dnn::tau_flightLength_y]);
1936  get(dnn::tau_flightLength_z) =
1937  sp.scale(tau_funcs.getFlightLength(tau, tau_index).z(), tauInputs_indices_[dnn::tau_flightLength_z]);
1938  if (sub_version_ == 1)
1939  get(dnn::tau_flightLength_sig) = 0.55756444; //This value is set due to a bug in the training
1940  else if (sub_version_ == 5)
1941  get(dnn::tau_flightLength_sig) =
1942  sp.scale(tau_funcs.getFlightLengthSig(tau, tau_index), tauInputs_indices_[dnn::tau_flightLength_sig]);
1943 
1944  get(dnn::tau_pt_weighted_deta_strip) = sp.scale(reco::tau::pt_weighted_deta_strip(tau, tau.decayMode()),
1945  tauInputs_indices_[dnn::tau_pt_weighted_deta_strip]);
1946 
1947  get(dnn::tau_pt_weighted_dphi_strip) = sp.scale(reco::tau::pt_weighted_dphi_strip(tau, tau.decayMode()),
1948  tauInputs_indices_[dnn::tau_pt_weighted_dphi_strip]);
1949  get(dnn::tau_pt_weighted_dr_signal) = sp.scale(reco::tau::pt_weighted_dr_signal(tau, tau.decayMode()),
1950  tauInputs_indices_[dnn::tau_pt_weighted_dr_signal]);
1951  get(dnn::tau_pt_weighted_dr_iso) =
1952  sp.scale(reco::tau::pt_weighted_dr_iso(tau, tau.decayMode()), tauInputs_indices_[dnn::tau_pt_weighted_dr_iso]);
1953  get(dnn::tau_leadingTrackNormChi2) =
1954  sp.scale(tau_funcs.getLeadingTrackNormChi2(tau), tauInputs_indices_[dnn::tau_leadingTrackNormChi2]);
1955  const auto eratio = reco::tau::eratio(tau);
1956  const bool tau_e_ratio_valid = std::isnormal(eratio) && eratio > 0.f;
1957  get(dnn::tau_e_ratio_valid) = sp.scale(tau_e_ratio_valid, tauInputs_indices_[dnn::tau_e_ratio_valid]);
1958  get(dnn::tau_e_ratio) = tau_e_ratio_valid ? sp.scale(eratio, tauInputs_indices_[dnn::tau_e_ratio]) : 0.f;
1959  const double gj_angle_diff = calculateGottfriedJacksonAngleDifference(tau, tau_index, tau_funcs);
1960  const bool tau_gj_angle_diff_valid = (std::isnormal(gj_angle_diff) || gj_angle_diff == 0) && gj_angle_diff >= 0;
1961  get(dnn::tau_gj_angle_diff_valid) =
1962  sp.scale(tau_gj_angle_diff_valid, tauInputs_indices_[dnn::tau_gj_angle_diff_valid]);
1963  get(dnn::tau_gj_angle_diff) =
1964  tau_gj_angle_diff_valid ? sp.scale(gj_angle_diff, tauInputs_indices_[dnn::tau_gj_angle_diff]) : 0;
1965  get(dnn::tau_n_photons) = sp.scale(reco::tau::n_photons_total(tau), tauInputs_indices_[dnn::tau_n_photons]);
1966  get(dnn::tau_emFraction) = sp.scale(tau_funcs.getEmFraction(tau), tauInputs_indices_[dnn::tau_emFraction]);
1967 
1968  get(dnn::tau_inside_ecal_crack) =
1969  sp.scale(isInEcalCrack(tau.p4().eta()), tauInputs_indices_[dnn::tau_inside_ecal_crack]);
1970  get(dnn::leadChargedCand_etaAtEcalEntrance_minus_tau_eta) =
1971  sp.scale(tau_funcs.getEtaAtEcalEntrance(tau) - tau.p4().eta(),
1972  tauInputs_indices_[dnn::leadChargedCand_etaAtEcalEntrance_minus_tau_eta]);
1973  }
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 ...
float pt_weighted_dr_signal(const reco::PFTau &tau, int dm)
const bool disable_dxy_pca_
Definition: DeepTauId.cc:2728
static float getValueLinear(T value, float min_value, float max_value, bool positive)
Definition: DeepTauId.cc:1290
static bool isAbove(double value, double min)
Definition: DeepTauId.cc:1306
static bool isInEcalCrack(double eta)
Definition: DeepTauId.cc:2669
const unsigned sub_version_
Definition: DeepTauId.cc:2726
const std::map< std::pair< deep_tau::Scaling::FeatureT, bool >, deep_tau::Scaling::ScalingParams > * scalingParamsMap_
Definition: DeepTauId.cc:2734
static constexpr float pi
Definition: DeepTauId.cc:1271
float pt_weighted_deta_strip(const reco::PFTau &tau, int dm)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
float pt_weighted_dr_iso(const reco::PFTau &tau, int dm)
static bool calculateGottfriedJacksonAngleDifference(const TauCastType &tau, const size_t tau_index, double &gj_diff, TauFunc tau_funcs)
Definition: DeepTauId.cc:2638
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
const bool is_online_
Definition: DeepTauId.cc:2693
std::vector< int > tauInputs_indices_
Definition: DeepTauId.cc:2739
std::unique_ptr< tensorflow::Tensor > tauBlockTensor_
Definition: DeepTauId.cc:2731

◆ fillDescriptions()

static void DeepTauId::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
inlinestatic

Definition at line 994 of file DeepTauId.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::add(), edm::ParameterSetDescription::addOptional(), submitPVResolutionJobs::desc, ProducerED_cfi::InputTag, and AlCaHLTBitMon_QueryRunRegistry::string.

994  {
996  desc.add<edm::InputTag>("electrons", edm::InputTag("slimmedElectrons"));
997  desc.add<edm::InputTag>("muons", edm::InputTag("slimmedMuons"));
998  desc.add<edm::InputTag>("taus", edm::InputTag("slimmedTaus"));
999  desc.add<edm::InputTag>("pfcands", edm::InputTag("packedPFCandidates"));
1000  desc.add<edm::InputTag>("vertices", edm::InputTag("offlineSlimmedPrimaryVertices"));
1001  desc.add<edm::InputTag>("rho", edm::InputTag("fixedGridRhoAll"));
1002  desc.add<std::vector<std::string>>("graph_file",
1003  {"RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6.pb"});
1004  desc.add<bool>("mem_mapped", false);
1005  desc.add<unsigned>("year", 2017);
1006  desc.add<unsigned>("version", 2);
1007  desc.add<unsigned>("sub_version", 1);
1008  desc.add<int>("debug_level", 0);
1009  desc.add<bool>("disable_dxy_pca", false);
1010  desc.add<bool>("disable_hcalFraction_workaround", false);
1011  desc.add<bool>("disable_CellIndex_workaround", false);
1012  desc.add<bool>("save_inputs", false);
1013  desc.add<bool>("is_online", false);
1014 
1015  desc.add<std::vector<std::string>>("VSeWP", {"-1."});
1016  desc.add<std::vector<std::string>>("VSmuWP", {"-1."});
1017  desc.add<std::vector<std::string>>("VSjetWP", {"-1."});
1018 
1019  desc.addUntracked<edm::InputTag>("basicTauDiscriminators", edm::InputTag("basicTauDiscriminators"));
1020  desc.addUntracked<edm::InputTag>("basicTauDiscriminatorsdR03", edm::InputTag("basicTauDiscriminatorsdR03"));
1021  desc.add<edm::InputTag>("pfTauTransverseImpactParameters", edm::InputTag("hpsPFTauTransverseImpactParameters"));
1022 
1023  {
1024  edm::ParameterSetDescription pset_Prediscriminants;
1025  pset_Prediscriminants.add<std::string>("BooleanOperator", "and");
1026  {
1028  psd1.add<double>("cut");
1029  psd1.add<edm::InputTag>("Producer");
1030  pset_Prediscriminants.addOptional<edm::ParameterSetDescription>("decayMode", psd1);
1031  }
1032  desc.add<edm::ParameterSetDescription>("Prediscriminants", pset_Prediscriminants);
1033  }
1034 
1035  descriptions.add("DeepTau", desc);
1036  }
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)

◆ fillGrids()

template<typename Collection , typename TauCastType >
void DeepTauId::fillGrids ( const TauCastType &  tau,
const Collection &  objects,
CellGrid &  inner_grid,
CellGrid &  outer_grid 
)
inlineprivate

Definition at line 1678 of file DeepTauId.cc.

References reco::deltaPhi(), getInnerSignalConeRadius(), getRunAppsInfo::grid, dqmiodumpmetadata::n, getGTfromDQMFile::obj, and conifer::pow().

Referenced by getPredictionsV2().

1678  {
1679  static constexpr double outer_dR2 = 0.25; //0.5^2
1680  const double inner_radius = getInnerSignalConeRadius(tau.polarP4().pt());
1681  const double inner_dR2 = std::pow(inner_radius, 2);
1682 
1683  const auto addObject = [&](size_t n, double deta, double dphi, CellGrid& grid) {
1684  const auto& obj = objects.at(n);
1685  const CellObjectType obj_type = GetCellObjectType(obj);
1686  if (obj_type == CellObjectType::Other)
1687  return;
1688  CellIndex cell_index;
1689  if (grid.tryGetCellIndex(deta, dphi, cell_index)) {
1690  Cell& cell = grid[cell_index];
1691  auto iter = cell.find(obj_type);
1692  if (iter != cell.end()) {
1693  const auto& prev_obj = objects.at(iter->second);
1694  if (obj.polarP4().pt() > prev_obj.polarP4().pt())
1695  iter->second = n;
1696  } else {
1697  cell[obj_type] = n;
1698  }
1699  }
1700  };
1701 
1702  for (size_t n = 0; n < objects.size(); ++n) {
1703  const auto& obj = objects.at(n);
1704  const double deta = obj.polarP4().eta() - tau.polarP4().eta();
1705  const double dphi = reco::deltaPhi(obj.polarP4().phi(), tau.polarP4().phi());
1706  const double dR2 = std::pow(deta, 2) + std::pow(dphi, 2);
1707  if (dR2 < inner_dR2)
1708  addObject(n, deta, dphi, inner_grid);
1709  if (dR2 < outer_dR2)
1710  addObject(n, deta, dphi, outer_grid);
1711  }
1712  }
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
static double getInnerSignalConeRadius(double pt)
Definition: DeepTauId.cc:2630
constexpr int pow(int x)
Definition: conifer.h:24
CellObjectType
Definition: DeepTauId.cc:777

◆ findMatchedElectron()

template<typename TauCastType >
static const pat::Electron* DeepTauId::findMatchedElectron ( const TauCastType &  tau,
const std::vector< pat::Electron > *  electrons,
double  deltaR 
)
inlinestaticprivate

Definition at line 2675 of file DeepTauId.cc.

References PbPb_ZMuSkimMuonDPG_cff::deltaR, reco::deltaR2(), pwdgSkimBPark_cfi::electrons, and reco::LeafCandidate::pt().

2677  {
2678  const double dR2 = deltaR * deltaR;
2679  const pat::Electron* matched_ele = nullptr;
2680  for (const auto& ele : *electrons) {
2681  if (reco::deltaR2(tau.p4(), ele.p4()) < dR2 && (!matched_ele || matched_ele->pt() < ele.pt())) {
2682  matched_ele = &ele;
2683  }
2684  }
2685  return matched_ele;
2686  }
double pt() const final
transverse momentum
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
Analysis-level electron class.
Definition: Electron.h:51

◆ getInnerSignalConeRadius()

static double DeepTauId::getInnerSignalConeRadius ( double  pt)
inlinestaticprivate

Definition at line 2630 of file DeepTauId.cc.

References SiStripPI::max, cosmictrackSelector_cfi::min_pt, and DiDispStaMuonMonitor_cfi::pt.

Referenced by fillGrids(), and processSignalPFComponents().

2630  {
2631  static constexpr double min_pt = 30., min_radius = 0.05, cone_opening_coef = 3.;
2632  // This is equivalent of the original formula (std::max(std::min(0.1, 3.0/pt), 0.05)
2633  return std::max(cone_opening_coef / std::max(pt, min_pt), min_radius);
2634  }

◆ GetOutputs()

static const OutputCollection& DeepTauId::GetOutputs ( )
inlinestatic

Definition at line 950 of file DeepTauId.cc.

References GetRecoTauVFromDQM_MC_cff::Output, and outputs_.

950  {
951  static constexpr size_t e_index = 0, mu_index = 1, tau_index = 2, jet_index = 3;
952  static const OutputCollection outputs_ = {
953  {"VSe", Output({tau_index}, {e_index, tau_index})},
954  {"VSmu", Output({tau_index}, {mu_index, tau_index})},
955  {"VSjet", Output({tau_index}, {jet_index, tau_index})},
956  };
957  return outputs_;
958  }
OutputCollection outputs_
Definition: DeepTauId.cc:2694
std::map< std::string, Output > OutputCollection
Definition: DeepTauId.cc:946

◆ getPartialPredictions()

tensorflow::Tensor DeepTauId::getPartialPredictions ( bool  is_inner)
inlineprivate

Definition at line 1714 of file DeepTauId.cc.

References cache_, eGammaTensor_, deep_tau::DeepTauCache::getSession(), hadronsTensor_, muonTensor_, and tensorflow::run().

Referenced by createConvFeatures(), and DeepTauId().

1714  {
1715  std::vector<tensorflow::Tensor> pred_vector;
1716  if (is_inner) {
1717  tensorflow::run(&(cache_->getSession("inner")),
1718  {
1719  {"input_inner_egamma", *eGammaTensor_.at(is_inner)},
1720  {"input_inner_muon", *muonTensor_.at(is_inner)},
1721  {"input_inner_hadrons", *hadronsTensor_.at(is_inner)},
1722  },
1723  {"inner_all_dropout_4/Identity"},
1724  &pred_vector);
1725  } else {
1726  tensorflow::run(&(cache_->getSession("outer")),
1727  {
1728  {"input_outer_egamma", *eGammaTensor_.at(is_inner)},
1729  {"input_outer_muon", *muonTensor_.at(is_inner)},
1730  {"input_outer_hadrons", *hadronsTensor_.at(is_inner)},
1731  },
1732  {"outer_all_dropout_4/Identity"},
1733  &pred_vector);
1734  }
1735  return pred_vector.at(0);
1736  }
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > hadronsTensor_
Definition: DeepTauId.cc:2732
const deep_tau::DeepTauCache * cache_
Definition: DeepTauId.cc:2695
void run(Session *session, const NamedTensorList &inputs, const std::vector< std::string > &outputNames, std::vector< Tensor > *outputs, const thread::ThreadPoolOptions &threadPoolOptions)
Definition: TensorFlow.cc:259
tensorflow::Session & getSession(const std::string &name="") const
Definition: DeepTauId.cc:98
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > eGammaTensor_
Definition: DeepTauId.cc:2732
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > muonTensor_
Definition: DeepTauId.cc:2732

◆ getPredictions()

tensorflow::Tensor DeepTauId::getPredictions ( edm::Event event,
edm::Handle< TauCollection taus 
)
inlineprivate

Definition at line 1448 of file DeepTauId.cc.

References andPrediscriminants_, basicDiscrdR03IndexMap_, basicDiscrIndexMap_, HLT_2023v12_cff::basicTauDiscriminators, basicTauDiscriminators_inputToken_, HLT_2023v12_cff::basicTauDiscriminatorsdR03, basicTauDiscriminatorsdR03_inputToken_, discrIndicesMapped_, electrons_token_, Exception, f, is_online_, dqmdumpme::k, matchDiscriminatorIndices(), muons_token_, deep_tau::NumberOfOutputs, patPrediscriminants_, pfcandToken_, HLT_2023v12_cff::pfTauTransverseImpactParameters, pfTauTransverseImpactParameters_token_, recoPrediscriminants_, requiredBasicDiscriminators_, requiredBasicDiscriminatorsdR03_, rho, rho_token_, Tau3MuMonitor_cff::taus, version_, AlignmentTracksFromVertexSelector_cfi::vertices, and vtxToken_.

Referenced by produce().

1448  {
1449  // Empty dummy vectors
1450  const std::vector<pat::Electron> electron_collection_default;
1451  const std::vector<pat::Muon> muon_collection_default;
1452  const reco::TauDiscriminatorContainer basicTauDiscriminators_default;
1453  const reco::TauDiscriminatorContainer basicTauDiscriminatorsdR03_default;
1455  pfTauTransverseImpactParameters_default;
1456 
1457  const std::vector<pat::Electron>* electron_collection;
1458  const std::vector<pat::Muon>* muon_collection;
1463 
1464  if (!is_online_) {
1465  electron_collection = &event.get(electrons_token_);
1466  muon_collection = &event.get(muons_token_);
1467  pfTauTransverseImpactParameters = &pfTauTransverseImpactParameters_default;
1468  basicTauDiscriminators = &basicTauDiscriminators_default;
1469  basicTauDiscriminatorsdR03 = &basicTauDiscriminatorsdR03_default;
1470  } else {
1471  electron_collection = &electron_collection_default;
1472  muon_collection = &muon_collection_default;
1476 
1477  // Get indices for discriminators
1478  if (!discrIndicesMapped_) {
1483  discrIndicesMapped_ = true;
1484  }
1485  }
1486 
1487  TauFunc tauIDs = {basicTauDiscriminators,
1492 
1494  event.getByToken(pfcandToken_, pfCands);
1495 
1497  event.getByToken(vtxToken_, vertices);
1498 
1500  event.getByToken(rho_token_, rho);
1501 
1502  auto const& eventnr = event.id().event();
1503 
1504  tensorflow::Tensor predictions(tensorflow::DT_FLOAT, {static_cast<int>(taus->size()), deep_tau::NumberOfOutputs});
1505 
1506  for (size_t tau_index = 0; tau_index < taus->size(); ++tau_index) {
1507  const edm::RefToBase<reco::BaseTau> tauRef = taus->refAt(tau_index);
1508 
1509  std::vector<tensorflow::Tensor> pred_vector;
1510 
1511  bool passesPrediscriminants;
1512  if (is_online_) {
1513  passesPrediscriminants = tauIDs.passPrediscriminants<std::vector<TauDiscInfo<reco::PFTauDiscriminator>>>(
1515  } else {
1516  passesPrediscriminants = tauIDs.passPrediscriminants<std::vector<TauDiscInfo<pat::PATTauDiscriminator>>>(
1518  }
1519 
1520  if (passesPrediscriminants) {
1521  if (version_ == 2) {
1522  if (is_online_) {
1523  getPredictionsV2<reco::PFCandidate, reco::PFTau>(taus->at(tau_index),
1524  tau_index,
1525  tauRef,
1526  electron_collection,
1527  muon_collection,
1528  *pfCands,
1529  vertices->at(0),
1530  *rho,
1531  eventnr,
1532  pred_vector,
1533  tauIDs);
1534  } else
1535  getPredictionsV2<pat::PackedCandidate, pat::Tau>(taus->at(tau_index),
1536  tau_index,
1537  tauRef,
1538  electron_collection,
1539  muon_collection,
1540  *pfCands,
1541  vertices->at(0),
1542  *rho,
1543  eventnr,
1544  pred_vector,
1545  tauIDs);
1546  } else {
1547  throw cms::Exception("DeepTauId") << "version " << version_ << " is not supported.";
1548  }
1549 
1550  for (int k = 0; k < deep_tau::NumberOfOutputs; ++k) {
1551  const float pred = pred_vector[0].flat<float>()(k);
1552  if (!(pred >= 0 && pred <= 1))
1553  throw cms::Exception("DeepTauId")
1554  << "invalid prediction = " << pred << " for tau_index = " << tau_index << ", pred_index = " << k;
1555  predictions.matrix<float>()(tau_index, k) = pred;
1556  }
1557  } else {
1558  // This else statement was added as a part of the DeepTau@HLT development. It does not affect the current state
1559  // of offline DeepTauId code as there the preselection is not used (it was added in the DeepTau@HLT). It returns
1560  // default values for deepTau score if the preselection failed. Before this statement the values given for this tau
1561  // were random. k == 2 corresponds to the tau score and all other k values to e, mu and jets. By defining in this way
1562  // the final score is -1.
1563  for (int k = 0; k < deep_tau::NumberOfOutputs; ++k) {
1564  predictions.matrix<float>()(tau_index, k) = (k == 2) ? -1.f : 2.f;
1565  }
1566  }
1567  }
1568  return predictions;
1569  }
std::map< BasicDiscriminator, size_t > basicDiscrdR03IndexMap_
Definition: DeepTauId.cc:2744
std::map< BasicDiscriminator, size_t > basicDiscrIndexMap_
Definition: DeepTauId.cc:2743
edm::EDGetTokenT< reco::VertexCollection > vtxToken_
Definition: DeepTauId.cc:2691
std::vector< TauDiscInfo< reco::PFTauDiscriminator > > recoPrediscriminants_
Definition: DeepTauId.cc:1268
uint8_t andPrediscriminants_
Definition: DeepTauId.cc:1266
const unsigned version_
Definition: DeepTauId.cc:2725
std::vector< TauDiscInfo< pat::PATTauDiscriminator > > patPrediscriminants_
Definition: DeepTauId.cc:1267
edm::EDGetTokenT< CandidateCollection > pfcandToken_
Definition: DeepTauId.cc:2690
const std::map< BasicDiscriminator, size_t > matchDiscriminatorIndices(edm::Event &event, edm::EDGetTokenT< reco::TauDiscriminatorContainer > discriminatorContainerToken, std::vector< BasicDiscriminator > requiredDiscr)
Definition: DeepTauId.cc:962
double f[11][100]
const std::vector< BasicDiscriminator > requiredBasicDiscriminators_
Definition: DeepTauId.cc:2704
const std::vector< BasicDiscriminator > requiredBasicDiscriminatorsdR03_
Definition: DeepTauId.cc:2709
edm::EDGetTokenT< edm::AssociationVector< reco::PFTauRefProd, std::vector< reco::PFTauTransverseImpactParameterRef > > > pfTauTransverseImpactParameters_token_
Definition: DeepTauId.cc:2722
bool discrIndicesMapped_
Definition: DeepTauId.cc:2742
edm::EDGetTokenT< reco::TauDiscriminatorContainer > basicTauDiscriminators_inputToken_
Definition: DeepTauId.cc:2719
const bool is_online_
Definition: DeepTauId.cc:2693
edm::EDGetTokenT< reco::TauDiscriminatorContainer > basicTauDiscriminatorsdR03_inputToken_
Definition: DeepTauId.cc:2720
edm::EDGetTokenT< std::vector< pat::Electron > > electrons_token_
Definition: DeepTauId.cc:2716
edm::EDGetTokenT< std::vector< pat::Muon > > muons_token_
Definition: DeepTauId.cc:2717
edm::EDGetTokenT< double > rho_token_
Definition: DeepTauId.cc:2718
Definition: event.py:1
constexpr int NumberOfOutputs
Definition: DeepTauId.cc:107

◆ getPredictionsV2()

template<typename CandidateCastType , typename TauCastType >
void DeepTauId::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 
)
inlineprivate

Definition at line 1572 of file DeepTauId.cc.

References cms::cuda::assert(), cache_, checkInputs(), convTensor_, gather_cfg::cout, debug_level, disable_CellIndex_workaround_, eGammaTensor_, pwdgSkimBPark_cfi::electrons, file_counter_, fillGrids(), deep_tau::DeepTauCache::getSession(), hadronsTensor_, heavyIonCSV_trainingSettings::idx, is_first_block_, json_file_, label, PDWG_BPHSkim_cff::muons, muonTensor_, deep_tau::NumberOfOutputs, rho, tensorflow::run(), save_inputs_, saveInputs(), AlCaHLTBitMon_QueryRunRegistry::string, metsig::tau, tauBlockTensor_, and to_string().

1582  {
1583  using namespace dnn_inputs_v2;
1584  if (debug_level >= 2) {
1585  std::cout << "<DeepTauId::getPredictionsV2 (moduleLabel = " << moduleDescription().moduleLabel()
1586  << ")>:" << std::endl;
1587  std::cout << " tau: pT = " << tau.pt() << ", eta = " << tau.eta() << ", phi = " << tau.phi()
1588  << ", eventnr = " << eventnr << std::endl;
1589  }
1590  CellGrid inner_grid(number_of_inner_cell, number_of_inner_cell, 0.02, 0.02, disable_CellIndex_workaround_);
1591  CellGrid outer_grid(number_of_outer_cell, number_of_outer_cell, 0.05, 0.05, disable_CellIndex_workaround_);
1592  fillGrids(dynamic_cast<const TauCastType&>(tau), *electrons, inner_grid, outer_grid);
1593  fillGrids(dynamic_cast<const TauCastType&>(tau), *muons, inner_grid, outer_grid);
1594  fillGrids(dynamic_cast<const TauCastType&>(tau), pfCands, inner_grid, outer_grid);
1595 
1596  createTauBlockInputs<CandidateCastType>(
1597  dynamic_cast<const TauCastType&>(tau), tau_index, tau_ref, pv, rho, tau_funcs);
1598  checkInputs(*tauBlockTensor_, "input_tau", static_cast<int>(tauBlockTensor_->shape().dim_size(1)));
1599  createConvFeatures<CandidateCastType>(dynamic_cast<const TauCastType&>(tau),
1600  tau_index,
1601  tau_ref,
1602  pv,
1603  rho,
1604  electrons,
1605  muons,
1606  pfCands,
1607  inner_grid,
1608  tau_funcs,
1609  true);
1610  checkInputs(*eGammaTensor_[true], "input_inner_egamma", EgammaBlockInputs::NumberOfInputs, &inner_grid);
1611  checkInputs(*muonTensor_[true], "input_inner_muon", MuonBlockInputs::NumberOfInputs, &inner_grid);
1612  checkInputs(*hadronsTensor_[true], "input_inner_hadrons", HadronBlockInputs::NumberOfInputs, &inner_grid);
1613  createConvFeatures<CandidateCastType>(dynamic_cast<const TauCastType&>(tau),
1614  tau_index,
1615  tau_ref,
1616  pv,
1617  rho,
1618  electrons,
1619  muons,
1620  pfCands,
1621  outer_grid,
1622  tau_funcs,
1623  false);
1624  checkInputs(*eGammaTensor_[false], "input_outer_egamma", EgammaBlockInputs::NumberOfInputs, &outer_grid);
1625  checkInputs(*muonTensor_[false], "input_outer_muon", MuonBlockInputs::NumberOfInputs, &outer_grid);
1626  checkInputs(*hadronsTensor_[false], "input_outer_hadrons", HadronBlockInputs::NumberOfInputs, &outer_grid);
1627 
1628  if (save_inputs_) {
1629  std::string json_file_name = "DeepTauId_" + std::to_string(eventnr) + "_" + std::to_string(tau_index) + ".json";
1630  json_file_ = new std::ofstream(json_file_name.data());
1631  is_first_block_ = true;
1632  (*json_file_) << "{";
1633  saveInputs(*tauBlockTensor_, "input_tau", static_cast<int>(tauBlockTensor_->shape().dim_size(1)));
1634  saveInputs(
1635  *eGammaTensor_[true], "input_inner_egamma", dnn_inputs_v2::EgammaBlockInputs::NumberOfInputs, &inner_grid);
1636  saveInputs(*muonTensor_[true], "input_inner_muon", dnn_inputs_v2::MuonBlockInputs::NumberOfInputs, &inner_grid);
1637  saveInputs(
1638  *hadronsTensor_[true], "input_inner_hadrons", dnn_inputs_v2::HadronBlockInputs::NumberOfInputs, &inner_grid);
1639  saveInputs(
1640  *eGammaTensor_[false], "input_outer_egamma", dnn_inputs_v2::EgammaBlockInputs::NumberOfInputs, &outer_grid);
1641  saveInputs(*muonTensor_[false], "input_outer_muon", dnn_inputs_v2::MuonBlockInputs::NumberOfInputs, &outer_grid);
1642  saveInputs(
1643  *hadronsTensor_[false], "input_outer_hadrons", dnn_inputs_v2::HadronBlockInputs::NumberOfInputs, &outer_grid);
1644  (*json_file_) << "}";
1645  delete json_file_;
1646  ++file_counter_;
1647  }
1648 
1649  tensorflow::run(&(cache_->getSession("core")),
1650  {{"input_tau", *tauBlockTensor_},
1651  {"input_inner", *convTensor_.at(true)},
1652  {"input_outer", *convTensor_.at(false)}},
1653  {"main_output/Softmax"},
1654  &pred_vector);
1655  if (debug_level >= 1) {
1656  std::cout << "output = { ";
1657  for (int idx = 0; idx < deep_tau::NumberOfOutputs; ++idx) {
1658  if (idx > 0)
1659  std::cout << ", ";
1661  if (idx == 0)
1662  label = "e";
1663  else if (idx == 1)
1664  label = "mu";
1665  else if (idx == 2)
1666  label = "tau";
1667  else if (idx == 3)
1668  label = "jet";
1669  else
1670  assert(0);
1671  std::cout << label << " = " << pred_vector[0].flat<float>()(idx);
1672  }
1673  std::cout << " }" << std::endl;
1674  }
1675  }
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > hadronsTensor_
Definition: DeepTauId.cc:2732
void fillGrids(const TauCastType &tau, const Collection &objects, CellGrid &inner_grid, CellGrid &outer_grid)
Definition: DeepTauId.cc:1678
const bool save_inputs_
Definition: DeepTauId.cc:2735
int file_counter_
Definition: DeepTauId.cc:2738
std::ofstream * json_file_
Definition: DeepTauId.cc:2736
assert(be >=bs)
static std::string to_string(const XMLCh *ch)
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > convTensor_
Definition: DeepTauId.cc:2732
const deep_tau::DeepTauCache * cache_
Definition: DeepTauId.cc:2695
char const * label
bool is_first_block_
Definition: DeepTauId.cc:2737
void run(Session *session, const NamedTensorList &inputs, const std::vector< std::string > &outputNames, std::vector< Tensor > *outputs, const thread::ThreadPoolOptions &threadPoolOptions)
Definition: TensorFlow.cc:259
void saveInputs(const tensorflow::Tensor &inputs, const std::string &block_name, int n_inputs, const CellGrid *grid=nullptr)
Definition: DeepTauId.cc:1387
const bool disable_CellIndex_workaround_
Definition: DeepTauId.cc:2730
void checkInputs(const tensorflow::Tensor &inputs, const std::string &block_name, int n_inputs, const CellGrid *grid=nullptr) const
Definition: DeepTauId.cc:1331
tensorflow::Session & getSession(const std::string &name="") const
Definition: DeepTauId.cc:98
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > eGammaTensor_
Definition: DeepTauId.cc:2732
const int debug_level
Definition: DeepTauId.cc:2727
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > muonTensor_
Definition: DeepTauId.cc:2732
constexpr int NumberOfOutputs
Definition: DeepTauId.cc:107
std::unique_ptr< tensorflow::Tensor > tauBlockTensor_
Definition: DeepTauId.cc:2731

◆ getValue()

template<typename T >
static float DeepTauId::getValue ( T  value)
inlinestaticprivate

Definition at line 1285 of file DeepTauId.cc.

References f, and relativeConstraints::value.

Referenced by getValueLinear(), and getValueNorm().

1285  {
1286  return std::isnormal(value) ? static_cast<float>(value) : 0.f;
1287  }
double f[11][100]
Definition: value.py:1

◆ getValueLinear()

template<typename T >
static float DeepTauId::getValueLinear ( T  value,
float  min_value,
float  max_value,
bool  positive 
)
inlinestaticprivate

Definition at line 1290 of file DeepTauId.cc.

References getValue(), hcaldqm::quantity::max_value, and hcaldqm::quantity::min_value.

Referenced by createTauBlockInputs().

1290  {
1291  const float fixed_value = getValue(value);
1292  const float clamped_value = std::clamp(fixed_value, min_value, max_value);
1293  float transformed_value = (clamped_value - min_value) / (max_value - min_value);
1294  if (!positive)
1295  transformed_value = transformed_value * 2 - 1;
1296  return transformed_value;
1297  }
const std::map< ValueQuantityType, double > min_value
static float getValue(T value)
Definition: DeepTauId.cc:1285
Definition: value.py:1
const std::map< ValueQuantityType, double > max_value

◆ getValueNorm()

template<typename T >
static float DeepTauId::getValueNorm ( T  value,
float  mean,
float  sigma,
float  n_sigmas_max = 5 
)
inlinestaticprivate

Definition at line 1300 of file DeepTauId.cc.

References getValue(), and SiStripPI::mean.

1300  {
1301  const float fixed_value = getValue(value);
1302  const float norm_value = (fixed_value - mean) / sigma;
1303  return std::clamp(norm_value, -n_sigmas_max, n_sigmas_max);
1304  }
static float getValue(T value)
Definition: DeepTauId.cc:1285
Definition: value.py:1

◆ globalEndJob()

static void DeepTauId::globalEndJob ( const deep_tau::DeepTauCache cache_)
inlinestatic

Definition at line 1254 of file DeepTauId.cc.

1254 {}

◆ initializeGlobalCache()

static std::unique_ptr<deep_tau::DeepTauCache> DeepTauId::initializeGlobalCache ( const edm::ParameterSet cfg)
inlinestatic

Definition at line 1232 of file DeepTauId.cc.

References looper::cfg, mps_splice::entry, edm::FileInPath::fullPath(), HLT_2023v12_cff::graph_file, HLT_2023v12_cff::mem_mapped, and AlCaHLTBitMon_QueryRunRegistry::string.

1232  {
1233  const auto graph_name_vector = cfg.getParameter<std::vector<std::string>>("graph_file");
1234  std::map<std::string, std::string> graph_names;
1235  for (const auto& entry : graph_name_vector) {
1236  const size_t sep_pos = entry.find(':');
1237  std::string entry_name, graph_file;
1238  if (sep_pos != std::string::npos) {
1239  entry_name = entry.substr(0, sep_pos);
1240  graph_file = entry.substr(sep_pos + 1);
1241  } else {
1242  entry_name = "";
1243  graph_file = entry;
1244  }
1246  if (graph_names.count(entry_name))
1247  throw cms::Exception("DeepTauCache") << "Duplicated graph entries";
1248  graph_names[entry_name] = graph_file;
1249  }
1250  bool mem_mapped = cfg.getParameter<bool>("mem_mapped");
1251  return std::make_unique<deep_tau::DeepTauCache>(graph_names, mem_mapped);
1252  }
std::string fullPath() const
Definition: FileInPath.cc:161

◆ isAbove()

static bool DeepTauId::isAbove ( double  value,
double  min 
)
inlinestaticprivate

Definition at line 1306 of file DeepTauId.cc.

References SiStripPI::min.

Referenced by createTauBlockInputs().

1306 { return std::isnormal(value) && value > min; }
Definition: value.py:1

◆ isInEcalCrack()

static bool DeepTauId::isInEcalCrack ( double  eta)
inlinestaticprivate

Definition at line 2669 of file DeepTauId.cc.

References funct::abs(), and PVValHelper::eta.

Referenced by createEgammaBlockInputs(), createHadronsBlockInputs(), createMuonBlockInputs(), and createTauBlockInputs().

2669  {
2670  const double abs_eta = std::abs(eta);
2671  return abs_eta > 1.46 && abs_eta < 1.558;
2672  }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22

◆ matchDiscriminatorIndices()

const std::map<BasicDiscriminator, size_t> DeepTauId::matchDiscriminatorIndices ( edm::Event event,
edm::EDGetTokenT< reco::TauDiscriminatorContainer discriminatorContainerToken,
std::vector< BasicDiscriminator requiredDiscr 
)
inline

Definition at line 962 of file DeepTauId.cc.

References Exception, edm::ParameterSet::getParameter(), mps_fire::i, dqmiolumiharvest::j, edm::parameterSet(), AlCaHLTBitMon_QueryRunRegistry::string, and stringFromDiscriminator_.

Referenced by getPredictions().

965  {
966  std::map<std::string, size_t> discrIndexMapStr;
967  auto const aHandle = event.getHandle(discriminatorContainerToken);
968  auto const aProv = aHandle.provenance();
969  if (aProv == nullptr)
970  aHandle.whyFailed()->raise();
971  const auto& psetsFromProvenance = edm::parameterSet(aProv->stable(), event.processHistory());
972  auto const idlist = psetsFromProvenance.getParameter<std::vector<edm::ParameterSet>>("IDdefinitions");
973  for (size_t j = 0; j < idlist.size(); ++j) {
974  std::string idname = idlist[j].getParameter<std::string>("IDname");
975  if (discrIndexMapStr.count(idname)) {
976  throw cms::Exception("DeepTauId")
977  << "basic discriminator " << idname << " appears more than once in the input.";
978  }
979  discrIndexMapStr[idname] = j;
980  }
981 
982  //translate to a map of <BasicDiscriminator, index> and check if all discriminators are present
983  std::map<BasicDiscriminator, size_t> discrIndexMap;
984  for (size_t i = 0; i < requiredDiscr.size(); i++) {
985  if (discrIndexMapStr.find(stringFromDiscriminator_.at(requiredDiscr[i])) == discrIndexMapStr.end())
986  throw cms::Exception("DeepTauId") << "Basic Discriminator " << stringFromDiscriminator_.at(requiredDiscr[i])
987  << " was not provided in the config file.";
988  else
989  discrIndexMap[requiredDiscr[i]] = discrIndexMapStr[stringFromDiscriminator_.at(requiredDiscr[i])];
990  }
991  return discrIndexMap;
992  }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
ParameterSet const & parameterSet(StableProvenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:11
const std::map< BasicDiscriminator, std::string > stringFromDiscriminator_
Definition: DeepTauId.cc:2697

◆ processIsolationPFComponents()

template<typename CandidateCollection , typename TauCastType >
static void DeepTauId::processIsolationPFComponents ( const TauCastType &  tau,
const CandidateCollection candidates,
LorentzVectorXYZ p4,
float &  pt,
float &  d_eta,
float &  d_phi,
float &  m,
float &  n 
)
inlinestaticprivate

Definition at line 2608 of file DeepTauId.cc.

References HLT_2023v12_cff::candidates, default_value, HLT_2023v12_cff::dEta, HLT_2023v12_cff::dPhi, visualization-live-secondInstance_cfg::m, dqmiodumpmetadata::n, and DiDispStaMuonMonitor_cfi::pt.

2615  {
2616  p4 = LorentzVectorXYZ(0, 0, 0, 0);
2617  n = 0;
2618 
2619  for (const auto& cand : candidates) {
2620  p4 += cand->p4();
2621  ++n;
2622  }
2623 
2624  pt = n != 0 ? p4.Pt() : default_value;
2625  d_eta = n != 0 ? dEta(p4, tau.p4()) : default_value;
2626  d_phi = n != 0 ? dPhi(p4, tau.p4()) : default_value;
2627  m = n != 0 ? p4.mass() : default_value;
2628  }
static constexpr float default_value
Definition: DeepTauId.cc:948
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > LorentzVectorXYZ
Definition: DeepTauId.cc:904

◆ processSignalPFComponents()

template<typename CandidateCollection , typename TauCastType >
static void DeepTauId::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 
)
inlinestaticprivate

Definition at line 2564 of file DeepTauId.cc.

References HLT_2023v12_cff::candidates, default_value, reco::deltaR(), HLT_2023v12_cff::dEta, HLT_2023v12_cff::dPhi, HGC3DClusterGenMatchSelector_cfi::dR, and getInnerSignalConeRadius().

2577  {
2578  p4_inner = LorentzVectorXYZ(0, 0, 0, 0);
2579  p4_outer = LorentzVectorXYZ(0, 0, 0, 0);
2580  n_inner = 0;
2581  n_outer = 0;
2582 
2583  const double innerSigCone_radius = getInnerSignalConeRadius(tau.pt());
2584  for (const auto& cand : candidates) {
2585  const double dR = reco::deltaR(cand->p4(), tau.leadChargedHadrCand()->p4());
2586  const bool isInside_innerSigCone = dR < innerSigCone_radius;
2587  if (isInside_innerSigCone) {
2588  p4_inner += cand->p4();
2589  ++n_inner;
2590  } else {
2591  p4_outer += cand->p4();
2592  ++n_outer;
2593  }
2594  }
2595 
2596  pt_inner = n_inner != 0 ? p4_inner.Pt() : default_value;
2597  dEta_inner = n_inner != 0 ? dEta(p4_inner, tau.p4()) : default_value;
2598  dPhi_inner = n_inner != 0 ? dPhi(p4_inner, tau.p4()) : default_value;
2599  m_inner = n_inner != 0 ? p4_inner.mass() : default_value;
2600 
2601  pt_outer = n_outer != 0 ? p4_outer.Pt() : default_value;
2602  dEta_outer = n_outer != 0 ? dEta(p4_outer, tau.p4()) : default_value;
2603  dPhi_outer = n_outer != 0 ? dPhi(p4_outer, tau.p4()) : default_value;
2604  m_outer = n_outer != 0 ? p4_outer.mass() : default_value;
2605  }
static constexpr float default_value
Definition: DeepTauId.cc:948
static double getInnerSignalConeRadius(double pt)
Definition: DeepTauId.cc:2630
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > LorentzVectorXYZ
Definition: DeepTauId.cc:904

◆ produce()

void DeepTauId::produce ( edm::Event event,
const edm::EventSetup es 
)
inlineoverride

Definition at line 1193 of file DeepTauId.cc.

References createOutputs(), Exception, getPredictions(), is_online_, deep_tau::NumberOfOutputs, patPrediscriminants_, recoPrediscriminants_, Tau3MuMonitor_cff::taus, and tausToken_.

1193  {
1195  event.getByToken(tausToken_, taus);
1196 
1197  // store empty output collection(s) if tau collection is empty
1198  if (taus->empty()) {
1199  const tensorflow::Tensor emptyPrediction(tensorflow::DT_FLOAT, {0, deep_tau::NumberOfOutputs});
1200  createOutputs(event, emptyPrediction, taus);
1201  return;
1202  }
1203 
1204  edm::ProductID tauProductID = taus.id();
1205 
1206  // load prediscriminators
1207  size_t nPrediscriminants =
1209  for (size_t iDisc = 0; iDisc < nPrediscriminants; ++iDisc) {
1210  edm::ProductID discKeyId;
1211  if (is_online_) {
1212  recoPrediscriminants_[iDisc].fill(event);
1213  discKeyId = recoPrediscriminants_[iDisc].handle->keyProduct().id();
1214  } else {
1215  patPrediscriminants_[iDisc].fill(event);
1216  discKeyId = patPrediscriminants_[iDisc].handle->keyProduct().id();
1217  }
1218 
1219  // Check to make sure the product is correct for the discriminator.
1220  // If not, throw a more informative exception.
1221  if (tauProductID != discKeyId) {
1222  throw cms::Exception("MisconfiguredPrediscriminant")
1223  << "The tau collection has product ID: " << tauProductID
1224  << " but the pre-discriminator is keyed with product ID: " << discKeyId << std::endl;
1225  }
1226  }
1227 
1228  const tensorflow::Tensor& pred = getPredictions(event, taus);
1229  createOutputs(event, pred, taus);
1230  }
tensorflow::Tensor getPredictions(edm::Event &event, edm::Handle< TauCollection > taus)
Definition: DeepTauId.cc:1448
std::vector< TauDiscInfo< reco::PFTauDiscriminator > > recoPrediscriminants_
Definition: DeepTauId.cc:1268
std::vector< TauDiscInfo< pat::PATTauDiscriminator > > patPrediscriminants_
Definition: DeepTauId.cc:1267
edm::EDGetTokenT< TauCollection > tausToken_
Definition: DeepTauId.cc:2689
void createOutputs(edm::Event &event, const tensorflow::Tensor &pred, edm::Handle< TauCollection > taus)
Definition: DeepTauId.cc:1273
const bool is_online_
Definition: DeepTauId.cc:2693
Definition: event.py:1
constexpr int NumberOfOutputs
Definition: DeepTauId.cc:107

◆ saveInputs()

void DeepTauId::saveInputs ( const tensorflow::Tensor &  inputs,
const std::string &  block_name,
int  n_inputs,
const CellGrid *  grid = nullptr 
)
inlineprivate

Definition at line 1387 of file DeepTauId.cc.

References cms::cuda::assert(), gather_cfg::cout, debug_level, PVValHelper::eta, nano_mu_digi_cff::float, getRunAppsInfo::grid, input, PixelMapPlotter::inputs, is_first_block_, and phi.

Referenced by getPredictionsV2().

1390  {
1391  if (debug_level >= 1) {
1392  std::cout << "<saveInputs>: block_name = " << block_name << std::endl;
1393  }
1394  if (!is_first_block_)
1395  (*json_file_) << ", ";
1396  (*json_file_) << "\"" << block_name << "\": [";
1397  if (block_name == "input_tau") {
1398  for (int input_index = 0; input_index < n_inputs; ++input_index) {
1399  float input = inputs.matrix<float>()(0, input_index);
1400  if (input_index != 0)
1401  (*json_file_) << ", ";
1402  (*json_file_) << input;
1403  }
1404  } else {
1405  assert(grid);
1406  int n_eta, n_phi;
1407  if (block_name.find("input_inner") != std::string::npos) {
1408  n_eta = 5;
1409  n_phi = 5;
1410  } else if (block_name.find("input_outer") != std::string::npos) {
1411  n_eta = 10;
1412  n_phi = 10;
1413  } else
1414  assert(0);
1415  int eta_phi_index = 0;
1416  for (int eta = -n_eta; eta <= n_eta; ++eta) {
1417  if (eta != -n_eta)
1418  (*json_file_) << ", ";
1419  (*json_file_) << "[";
1420  for (int phi = -n_phi; phi <= n_phi; ++phi) {
1421  if (phi != -n_phi)
1422  (*json_file_) << ", ";
1423  (*json_file_) << "[";
1424  const CellIndex cell_index{eta, phi};
1425  const auto cell_iter = grid->find(cell_index);
1426  for (int input_index = 0; input_index < n_inputs; ++input_index) {
1427  float input = 0.;
1428  if (cell_iter != grid->end()) {
1429  input = inputs.tensor<float, 4>()(eta_phi_index, 0, 0, input_index);
1430  }
1431  if (input_index != 0)
1432  (*json_file_) << ", ";
1433  (*json_file_) << input;
1434  }
1435  if (cell_iter != grid->end()) {
1436  eta_phi_index += 1;
1437  }
1438  (*json_file_) << "]";
1439  }
1440  (*json_file_) << "]";
1441  }
1442  }
1443  (*json_file_) << "]";
1444  is_first_block_ = false;
1445  }
assert(be >=bs)
static std::string const input
Definition: EdmProvDump.cc:50
bool is_first_block_
Definition: DeepTauId.cc:2737
const int debug_level
Definition: DeepTauId.cc:2727

◆ setCellConvFeatures()

void DeepTauId::setCellConvFeatures ( tensorflow::Tensor &  convTensor,
const tensorflow::Tensor &  features,
unsigned  batch_idx,
int  eta_index,
int  phi_index 
)
inlineprivate

Definition at line 1820 of file DeepTauId.cc.

References lowptgsfeleseed::features(), nano_mu_digi_cff::float, and dqmiodumpmetadata::n.

Referenced by createConvFeatures(), and DeepTauId().

1824  {
1825  for (int n = 0; n < dnn_inputs_v2::number_of_conv_features; ++n) {
1826  convTensor.tensor<float, 4>()(0, eta_index, phi_index, n) = features.tensor<float, 4>()(batch_idx, 0, 0, n);
1827  }
1828  }
std::vector< float > features(const reco::PreId &ecal, const reco::PreId &hcal, double rho, const reco::BeamSpot &spot, noZS::EcalClusterLazyTools &ecalTools)

Member Data Documentation

◆ andPrediscriminants_

uint8_t DeepTauId::andPrediscriminants_

Definition at line 1266 of file DeepTauId.cc.

Referenced by DeepTauId(), and getPredictions().

◆ basicDiscrdR03IndexMap_

std::map<BasicDiscriminator, size_t> DeepTauId::basicDiscrdR03IndexMap_
private

Definition at line 2744 of file DeepTauId.cc.

Referenced by getPredictions().

◆ basicDiscrIndexMap_

std::map<BasicDiscriminator, size_t> DeepTauId::basicDiscrIndexMap_
private

Definition at line 2743 of file DeepTauId.cc.

Referenced by getPredictions().

◆ basicTauDiscriminators_inputToken_

edm::EDGetTokenT<reco::TauDiscriminatorContainer> DeepTauId::basicTauDiscriminators_inputToken_
private

Definition at line 2719 of file DeepTauId.cc.

Referenced by getPredictions().

◆ basicTauDiscriminatorsdR03_inputToken_

edm::EDGetTokenT<reco::TauDiscriminatorContainer> DeepTauId::basicTauDiscriminatorsdR03_inputToken_
private

Definition at line 2720 of file DeepTauId.cc.

Referenced by getPredictions().

◆ cache_

const deep_tau::DeepTauCache* DeepTauId::cache_
private

Definition at line 2695 of file DeepTauId.cc.

Referenced by getPartialPredictions(), and getPredictionsV2().

◆ convTensor_

std::array<std::unique_ptr<tensorflow::Tensor>, 2> DeepTauId::convTensor_
private

Definition at line 2732 of file DeepTauId.cc.

Referenced by createConvFeatures(), DeepTauId(), and getPredictionsV2().

◆ debug_level

const int DeepTauId::debug_level
private

Definition at line 2727 of file DeepTauId.cc.

Referenced by checkInputs(), createConvFeatures(), getPredictionsV2(), and saveInputs().

◆ default_value

constexpr float DeepTauId::default_value = -999.
static

◆ disable_CellIndex_workaround_

const bool DeepTauId::disable_CellIndex_workaround_
private

Definition at line 2730 of file DeepTauId.cc.

Referenced by getPredictionsV2().

◆ disable_dxy_pca_

const bool DeepTauId::disable_dxy_pca_
private

Definition at line 2728 of file DeepTauId.cc.

Referenced by createTauBlockInputs().

◆ disable_hcalFraction_workaround_

const bool DeepTauId::disable_hcalFraction_workaround_
private

Definition at line 2729 of file DeepTauId.cc.

Referenced by createHadronsBlockInputs().

◆ discrIndicesMapped_

bool DeepTauId::discrIndicesMapped_ = false
private

Definition at line 2742 of file DeepTauId.cc.

Referenced by getPredictions().

◆ eGammaTensor_

std::array<std::unique_ptr<tensorflow::Tensor>, 2> DeepTauId::eGammaTensor_
private

◆ electrons_token_

edm::EDGetTokenT<std::vector<pat::Electron> > DeepTauId::electrons_token_
private

Definition at line 2716 of file DeepTauId.cc.

Referenced by getPredictions().

◆ file_counter_

int DeepTauId::file_counter_
private

Definition at line 2738 of file DeepTauId.cc.

Referenced by getPredictionsV2().

◆ hadronsTensor_

std::array<std::unique_ptr<tensorflow::Tensor>, 2> DeepTauId::hadronsTensor_
private

◆ input_layer_

std::string DeepTauId::input_layer_
private

Definition at line 2723 of file DeepTauId.cc.

◆ is_first_block_

bool DeepTauId::is_first_block_
private

Definition at line 2737 of file DeepTauId.cc.

Referenced by getPredictionsV2(), and saveInputs().

◆ is_online_

const bool DeepTauId::is_online_
private

◆ json_file_

std::ofstream* DeepTauId::json_file_
private

Definition at line 2736 of file DeepTauId.cc.

Referenced by getPredictionsV2().

◆ muons_token_

edm::EDGetTokenT<std::vector<pat::Muon> > DeepTauId::muons_token_
private

Definition at line 2717 of file DeepTauId.cc.

Referenced by getPredictions().

◆ muonTensor_

std::array<std::unique_ptr<tensorflow::Tensor>, 2> DeepTauId::muonTensor_
private

◆ output_layer_

std::string DeepTauId::output_layer_
private

Definition at line 2723 of file DeepTauId.cc.

◆ outputs_

OutputCollection DeepTauId::outputs_
private

Definition at line 2694 of file DeepTauId.cc.

Referenced by createOutputs(), DeepTauId(), and GetOutputs().

◆ patPrediscriminants_

std::vector<TauDiscInfo<pat::PATTauDiscriminator> > DeepTauId::patPrediscriminants_

Definition at line 1267 of file DeepTauId.cc.

Referenced by DeepTauId(), getPredictions(), and produce().

◆ pfcandToken_

edm::EDGetTokenT<CandidateCollection> DeepTauId::pfcandToken_
private

Definition at line 2690 of file DeepTauId.cc.

Referenced by getPredictions().

◆ pfTauTransverseImpactParameters_token_

edm::EDGetTokenT<edm::AssociationVector<reco::PFTauRefProd, std::vector<reco::PFTauTransverseImpactParameterRef> > > DeepTauId::pfTauTransverseImpactParameters_token_
private

Definition at line 2722 of file DeepTauId.cc.

Referenced by getPredictions().

◆ pi

constexpr float DeepTauId::pi = M_PI
staticprivate

Definition at line 1271 of file DeepTauId.cc.

Referenced by createTauBlockInputs().

◆ recoPrediscriminants_

std::vector<TauDiscInfo<reco::PFTauDiscriminator> > DeepTauId::recoPrediscriminants_

Definition at line 1268 of file DeepTauId.cc.

Referenced by DeepTauId(), getPredictions(), and produce().

◆ requiredBasicDiscriminators_

const std::vector<BasicDiscriminator> DeepTauId::requiredBasicDiscriminators_
private

◆ requiredBasicDiscriminatorsdR03_

const std::vector<BasicDiscriminator> DeepTauId::requiredBasicDiscriminatorsdR03_
private

◆ rho_token_

edm::EDGetTokenT<double> DeepTauId::rho_token_
private

Definition at line 2718 of file DeepTauId.cc.

Referenced by getPredictions().

◆ save_inputs_

const bool DeepTauId::save_inputs_
private

Definition at line 2735 of file DeepTauId.cc.

Referenced by getPredictionsV2().

◆ scalingParamsMap_

const std::map<std::pair<deep_tau::Scaling::FeatureT, bool>, deep_tau::Scaling::ScalingParams>* DeepTauId::scalingParamsMap_
private

◆ stringFromDiscriminator_

const std::map<BasicDiscriminator, std::string> DeepTauId::stringFromDiscriminator_
private
Initial value:
{
{BasicDiscriminator::NeutralIsoPtSumWeight, "NeutralIsoPtSumWeight"},
{BasicDiscriminator::FootprintCorrection, "TauFootprintCorrection"},
{BasicDiscriminator::PhotonPtSumOutsideSignalCone, "PhotonPtSumOutsideSignalCone"},

Definition at line 2697 of file DeepTauId.cc.

Referenced by matchDiscriminatorIndices().

◆ sub_version_

const unsigned DeepTauId::sub_version_
private

Definition at line 2726 of file DeepTauId.cc.

Referenced by createEgammaBlockInputs(), createTauBlockInputs(), and DeepTauId().

◆ tauBlockTensor_

std::unique_ptr<tensorflow::Tensor> DeepTauId::tauBlockTensor_
private

Definition at line 2731 of file DeepTauId.cc.

Referenced by createTauBlockInputs(), DeepTauId(), and getPredictionsV2().

◆ tauInputs_indices_

std::vector<int> DeepTauId::tauInputs_indices_
private

Definition at line 2739 of file DeepTauId.cc.

Referenced by createTauBlockInputs(), and DeepTauId().

◆ tausToken_

edm::EDGetTokenT<TauCollection> DeepTauId::tausToken_
private

Definition at line 2689 of file DeepTauId.cc.

Referenced by produce().

◆ version_

const unsigned DeepTauId::version_
private

Definition at line 2725 of file DeepTauId.cc.

Referenced by DeepTauId(), and getPredictions().

◆ vtxToken_

edm::EDGetTokenT<reco::VertexCollection> DeepTauId::vtxToken_
private

Definition at line 2691 of file DeepTauId.cc.

Referenced by getPredictions().

◆ workingPoints_

std::map<std::string, WPList> DeepTauId::workingPoints_
private

Definition at line 2692 of file DeepTauId.cc.

Referenced by createOutputs(), and DeepTauId().

◆ year_

const unsigned DeepTauId::year_
private

Definition at line 2724 of file DeepTauId.cc.

Referenced by createEgammaBlockInputs(), and DeepTauId().

◆ zeroOutputTensor_

std::array<std::unique_ptr<tensorflow::Tensor>, 2> DeepTauId::zeroOutputTensor_
private

Definition at line 2732 of file DeepTauId.cc.

Referenced by createConvFeatures(), and DeepTauId().