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 = deep_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 944 of file DeepTauId.cc.

Member Typedef Documentation

◆ BasicDiscriminator

Definition at line 1009 of file DeepTauId.cc.

◆ CandidateCollection

Definition at line 948 of file DeepTauId.cc.

◆ Cutter

Definition at line 954 of file DeepTauId.cc.

◆ CutterPtr

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

Definition at line 955 of file DeepTauId.cc.

◆ ElectronCollection

Definition at line 951 of file DeepTauId.cc.

◆ LorentzVectorXYZ

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

Definition at line 953 of file DeepTauId.cc.

◆ MuonCollection

Definition at line 952 of file DeepTauId.cc.

◆ OutputCollection

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

Definition at line 995 of file DeepTauId.cc.

◆ TauCollection

Definition at line 947 of file DeepTauId.cc.

◆ TauDiscriminator

Definition at line 946 of file DeepTauId.cc.

◆ TauRef

Definition at line 949 of file DeepTauId.cc.

◆ TauRefProd

Definition at line 950 of file DeepTauId.cc.

◆ WPList

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

Definition at line 956 of file DeepTauId.cc.

Constructor & Destructor Documentation

◆ DeepTauId()

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

Definition at line 1088 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_.

1089  : tausToken_(consumes<TauCollection>(cfg.getParameter<edm::InputTag>("taus"))),
1090  pfcandToken_(consumes<CandidateCollection>(cfg.getParameter<edm::InputTag>("pfcands"))),
1091  vtxToken_(consumes<reco::VertexCollection>(cfg.getParameter<edm::InputTag>("vertices"))),
1092  is_online_(cfg.getParameter<bool>("is_online")),
1093  outputs_(GetOutputs()),
1094  cache_(cache),
1095  electrons_token_(consumes<std::vector<pat::Electron>>(cfg.getParameter<edm::InputTag>("electrons"))),
1096  muons_token_(consumes<std::vector<pat::Muon>>(cfg.getParameter<edm::InputTag>("muons"))),
1097  rho_token_(consumes<double>(cfg.getParameter<edm::InputTag>("rho"))),
1098  basicTauDiscriminators_inputToken_(consumes<reco::TauDiscriminatorContainer>(
1099  cfg.getUntrackedParameter<edm::InputTag>("basicTauDiscriminators"))),
1100  basicTauDiscriminatorsdR03_inputToken_(consumes<reco::TauDiscriminatorContainer>(
1101  cfg.getUntrackedParameter<edm::InputTag>("basicTauDiscriminatorsdR03"))),
1103  consumes<edm::AssociationVector<reco::PFTauRefProd, std::vector<reco::PFTauTransverseImpactParameterRef>>>(
1104  cfg.getParameter<edm::InputTag>("pfTauTransverseImpactParameters"))),
1105  year_(cfg.getParameter<unsigned>("year")),
1106  version_(cfg.getParameter<unsigned>("version")),
1107  sub_version_(cfg.getParameter<unsigned>("sub_version")),
1108  debug_level(cfg.getParameter<int>("debug_level")),
1109  disable_dxy_pca_(cfg.getParameter<bool>("disable_dxy_pca")),
1110  disable_hcalFraction_workaround_(cfg.getParameter<bool>("disable_hcalFraction_workaround")),
1111  disable_CellIndex_workaround_(cfg.getParameter<bool>("disable_CellIndex_workaround")),
1112  save_inputs_(cfg.getParameter<bool>("save_inputs")),
1113  json_file_(nullptr),
1114  file_counter_(0) {
1115  for (const auto& output_desc : outputs_) {
1116  produces<TauDiscriminator>(output_desc.first);
1117  const auto& cut_list = cfg.getParameter<std::vector<std::string>>(output_desc.first + "WP");
1118  for (const std::string& cut_str : cut_list) {
1119  workingPoints_[output_desc.first].push_back(std::make_unique<Cutter>(cut_str));
1120  }
1121  }
1122 
1123  // prediscriminant operator
1124  // require the tau to pass the following prediscriminants
1125  const edm::ParameterSet& prediscriminantConfig = cfg.getParameter<edm::ParameterSet>("Prediscriminants");
1126 
1127  // determine boolean operator used on the prediscriminants
1128  std::string pdBoolOperator = prediscriminantConfig.getParameter<std::string>("BooleanOperator");
1129  // convert string to lowercase
1130  transform(pdBoolOperator.begin(), pdBoolOperator.end(), pdBoolOperator.begin(), ::tolower);
1131 
1132  if (pdBoolOperator == "and") {
1133  andPrediscriminants_ = 0x1; //use chars instead of bools so we can do a bitwise trick later
1134  } else if (pdBoolOperator == "or") {
1135  andPrediscriminants_ = 0x0;
1136  } else {
1137  throw cms::Exception("TauDiscriminationProducerBase")
1138  << "PrediscriminantBooleanOperator defined incorrectly, options are: AND,OR";
1139  }
1140 
1141  // get the list of prediscriminants
1142  std::vector<std::string> prediscriminantsNames =
1143  prediscriminantConfig.getParameterNamesForType<edm::ParameterSet>();
1144 
1145  for (auto const& iDisc : prediscriminantsNames) {
1146  const edm::ParameterSet& iPredisc = prediscriminantConfig.getParameter<edm::ParameterSet>(iDisc);
1147  const edm::InputTag& label = iPredisc.getParameter<edm::InputTag>("Producer");
1148  double cut = iPredisc.getParameter<double>("cut");
1149 
1150  if (is_online_) {
1151  TauDiscInfo<reco::PFTauDiscriminator> thisDiscriminator;
1152  thisDiscriminator.label = label;
1153  thisDiscriminator.cut = cut;
1154  thisDiscriminator.disc_token = consumes<reco::PFTauDiscriminator>(label);
1155  recoPrediscriminants_.push_back(thisDiscriminator);
1156  } else {
1157  TauDiscInfo<pat::PATTauDiscriminator> thisDiscriminator;
1158  thisDiscriminator.label = label;
1159  thisDiscriminator.cut = cut;
1160  thisDiscriminator.disc_token = consumes<pat::PATTauDiscriminator>(label);
1161  patPrediscriminants_.push_back(thisDiscriminator);
1162  }
1163  }
1164  if (version_ == 2) {
1165  using namespace dnn_inputs_v2;
1166  namespace sc = deep_tau::Scaling;
1167  tauInputs_indices_.resize(TauBlockInputs::NumberOfInputs);
1168  std::iota(std::begin(tauInputs_indices_), std::end(tauInputs_indices_), 0);
1169 
1170  if (sub_version_ == 1) {
1171  tauBlockTensor_ = std::make_unique<tensorflow::Tensor>(
1172  tensorflow::DT_FLOAT, tensorflow::TensorShape{1, TauBlockInputs::NumberOfInputs});
1174  } else if (sub_version_ == 5) {
1175  std::sort(TauBlockInputs::varsToDrop.begin(), TauBlockInputs::varsToDrop.end());
1176  for (auto v : TauBlockInputs::varsToDrop) {
1177  tauInputs_indices_.at(v) = -1; // set index to -1
1178  for (std::size_t i = v + 1; i < TauBlockInputs::NumberOfInputs; ++i)
1179  tauInputs_indices_.at(i) -= 1; // shift all the following indices by 1
1180  }
1181  tauBlockTensor_ = std::make_unique<tensorflow::Tensor>(
1182  tensorflow::DT_FLOAT,
1183  tensorflow::TensorShape{1,
1184  static_cast<int>(TauBlockInputs::NumberOfInputs) -
1185  static_cast<int>(TauBlockInputs::varsToDrop.size())});
1186  if (year_ == 2026) {
1188  } else {
1190  }
1191  } else
1192  throw cms::Exception("DeepTauId") << "subversion " << sub_version_ << " is not supported.";
1193 
1194  std::map<std::vector<bool>, std::vector<sc::FeatureT>> GridFeatureTypes_map = {
1195  {{false}, {sc::FeatureT::TauFlat, sc::FeatureT::GridGlobal}}, // feature types without inner/outer grid split
1196  {{false, true},
1197  {sc::FeatureT::PfCand_electron,
1198  sc::FeatureT::PfCand_muon, // feature types with inner/outer grid split
1199  sc::FeatureT::PfCand_chHad,
1200  sc::FeatureT::PfCand_nHad,
1201  sc::FeatureT::PfCand_gamma,
1203  sc::FeatureT::Muon}}};
1204 
1205  // check that sizes of mean/std/lim_min/lim_max vectors are equal between each other
1206  for (const auto& p : GridFeatureTypes_map) {
1207  for (auto is_inner : p.first) {
1208  for (auto featureType : p.second) {
1209  const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(featureType, is_inner));
1210  if (!(sp.mean_.size() == sp.std_.size() && sp.mean_.size() == sp.lim_min_.size() &&
1211  sp.mean_.size() == sp.lim_max_.size()))
1212  throw cms::Exception("DeepTauId") << "sizes of scaling parameter vectors do not match between each other";
1213  }
1214  }
1215  }
1216 
1217  for (size_t n = 0; n < 2; ++n) {
1218  const bool is_inner = n == 0;
1219  const auto n_cells = is_inner ? number_of_inner_cell : number_of_outer_cell;
1220  eGammaTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1221  tensorflow::DT_FLOAT, tensorflow::TensorShape{1, 1, 1, EgammaBlockInputs::NumberOfInputs});
1222  muonTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1223  tensorflow::DT_FLOAT, tensorflow::TensorShape{1, 1, 1, MuonBlockInputs::NumberOfInputs});
1224  hadronsTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1225  tensorflow::DT_FLOAT, tensorflow::TensorShape{1, 1, 1, HadronBlockInputs::NumberOfInputs});
1226  convTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1227  tensorflow::DT_FLOAT, tensorflow::TensorShape{1, n_cells, n_cells, number_of_conv_features});
1228  zeroOutputTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1229  tensorflow::DT_FLOAT, tensorflow::TensorShape{1, 1, 1, number_of_conv_features});
1230 
1231  eGammaTensor_[is_inner]->flat<float>().setZero();
1232  muonTensor_[is_inner]->flat<float>().setZero();
1233  hadronsTensor_[is_inner]->flat<float>().setZero();
1234 
1235  setCellConvFeatures(*zeroOutputTensor_[is_inner], getPartialPredictions(is_inner), 0, 0, 0);
1236  }
1237  } else {
1238  throw cms::Exception("DeepTauId") << "version " << version_ << " is not supported.";
1239  }
1240  }
size
Write out results.
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > hadronsTensor_
Definition: DeepTauId.cc:2773
std::map< std::string, WPList > workingPoints_
Definition: DeepTauId.cc:2733
const bool disable_dxy_pca_
Definition: DeepTauId.cc:2769
const bool save_inputs_
Definition: DeepTauId.cc:2776
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > zeroOutputTensor_
Definition: DeepTauId.cc:2773
int file_counter_
Definition: DeepTauId.cc:2779
edm::EDGetTokenT< reco::VertexCollection > vtxToken_
Definition: DeepTauId.cc:2732
std::vector< TauDiscInfo< reco::PFTauDiscriminator > > recoPrediscriminants_
Definition: DeepTauId.cc:1309
uint8_t andPrediscriminants_
Definition: DeepTauId.cc:1307
std::ofstream * json_file_
Definition: DeepTauId.cc:2777
OutputCollection outputs_
Definition: DeepTauId.cc:2735
void setCellConvFeatures(tensorflow::Tensor &convTensor, const tensorflow::Tensor &features, unsigned batch_idx, int eta_index, int phi_index)
Definition: DeepTauId.cc:1861
const unsigned version_
Definition: DeepTauId.cc:2766
std::vector< TauDiscInfo< pat::PATTauDiscriminator > > patPrediscriminants_
Definition: DeepTauId.cc:1308
const unsigned sub_version_
Definition: DeepTauId.cc:2767
edm::EDGetTokenT< TauCollection > tausToken_
Definition: DeepTauId.cc:2730
const std::map< std::pair< deep_tau::Scaling::FeatureT, bool >, deep_tau::Scaling::ScalingParams > * scalingParamsMap_
Definition: DeepTauId.cc:2775
static const OutputCollection & GetOutputs()
Definition: DeepTauId.cc:999
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > convTensor_
Definition: DeepTauId.cc:2773
const std::map< std::pair< FeatureT, bool >, ScalingParams > scalingParamsMap_v2p5
const deep_tau::DeepTauCache * cache_
Definition: DeepTauId.cc:2736
char const * label
edm::EDGetTokenT< CandidateCollection > pfcandToken_
Definition: DeepTauId.cc:2731
const unsigned year_
Definition: DeepTauId.cc:2765
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:179
const bool disable_CellIndex_workaround_
Definition: DeepTauId.cc:2771
const std::map< std::pair< FeatureT, bool >, ScalingParams > scalingParamsMap_v2p1
tensorflow::Tensor getPartialPredictions(bool is_inner)
Definition: DeepTauId.cc:1755
edm::EDGetTokenT< edm::AssociationVector< reco::PFTauRefProd, std::vector< reco::PFTauTransverseImpactParameterRef > > > pfTauTransverseImpactParameters_token_
Definition: DeepTauId.cc:2763
edm::EDGetTokenT< reco::TauDiscriminatorContainer > basicTauDiscriminators_inputToken_
Definition: DeepTauId.cc:2760
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > eGammaTensor_
Definition: DeepTauId.cc:2773
const bool disable_hcalFraction_workaround_
Definition: DeepTauId.cc:2770
const bool is_online_
Definition: DeepTauId.cc:2734
def cache(function)
Definition: utilities.py:3
edm::EDGetTokenT< reco::TauDiscriminatorContainer > basicTauDiscriminatorsdR03_inputToken_
Definition: DeepTauId.cc:2761
std::vector< int > tauInputs_indices_
Definition: DeepTauId.cc:2780
const int debug_level
Definition: DeepTauId.cc:2768
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > muonTensor_
Definition: DeepTauId.cc:2773
edm::EDGetTokenT< std::vector< pat::Electron > > electrons_token_
Definition: DeepTauId.cc:2757
edm::EDGetTokenT< std::vector< pat::Muon > > muons_token_
Definition: DeepTauId.cc:2758
edm::EDGetTokenT< double > rho_token_
Definition: DeepTauId.cc:2759
const std::map< std::pair< FeatureT, bool >, ScalingParams > scalingParamsMap_PhaseIIv2p5
std::unique_ptr< tensorflow::Tensor > tauBlockTensor_
Definition: DeepTauId.cc:2772
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 2585 of file DeepTauId.cc.

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

2585  {
2586  if (ele) {
2587  elecEe = elecEgamma = 0;
2588  auto superCluster = ele->superCluster();
2589  if (superCluster.isNonnull() && superCluster.isAvailable() && superCluster->clusters().isNonnull() &&
2590  superCluster->clusters().isAvailable()) {
2591  for (auto iter = superCluster->clustersBegin(); iter != superCluster->clustersEnd(); ++iter) {
2592  const double energy = (*iter)->energy();
2593  if (iter == superCluster->clustersBegin())
2594  elecEe += energy;
2595  else
2596  elecEgamma += energy;
2597  }
2598  }
2599  } else {
2600  elecEe = elecEgamma = default_value;
2601  }
2602  }
static constexpr float default_value
Definition: DeepTauId.cc:997
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 1349 of file DeepTauId.cc.

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

Referenced by createEgammaBlockInputs().

1352  {
1353  cc_ele_energy = cc_gamma_energy = 0;
1354  cc_n_gamma = 0;
1355  const auto& superCluster = ele.superCluster();
1356  if (superCluster.isNonnull() && superCluster.isAvailable() && superCluster->clusters().isNonnull() &&
1357  superCluster->clusters().isAvailable()) {
1358  for (auto iter = superCluster->clustersBegin(); iter != superCluster->clustersEnd(); ++iter) {
1359  const float energy = static_cast<float>((*iter)->energy());
1360  if (iter == superCluster->clustersBegin())
1361  cc_ele_energy += energy;
1362  else {
1363  cc_gamma_energy += energy;
1364  ++cc_n_gamma;
1365  }
1366  }
1367  return true;
1368  } else
1369  return false;
1370  }
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 2679 of file DeepTauId.cc.

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

Referenced by calculateGottfriedJacksonAngleDifference(), and createTauBlockInputs().

2682  {
2683  if (tau_funcs.getHasSecondaryVertex(tau, tau_index)) {
2684  static constexpr double mTau = 1.77682;
2685  const double mAOne = tau.p4().M();
2686  const double pAOneMag = tau.p();
2687  const double argumentThetaGJmax = (std::pow(mTau, 2) - std::pow(mAOne, 2)) / (2 * mTau * pAOneMag);
2688  const double argumentThetaGJmeasured = tau.p4().Vect().Dot(tau_funcs.getFlightLength(tau, tau_index)) /
2689  (pAOneMag * tau_funcs.getFlightLength(tau, tau_index).R());
2690  if (std::abs(argumentThetaGJmax) <= 1. && std::abs(argumentThetaGJmeasured) <= 1.) {
2691  double thetaGJmax = std::asin(argumentThetaGJmax);
2692  double thetaGJmeasured = std::acos(argumentThetaGJmeasured);
2693  gj_diff = thetaGJmeasured - thetaGJmax;
2694  return true;
2695  }
2696  }
2697  return false;
2698  }
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 2701 of file DeepTauId.cc.

References calculateGottfriedJacksonAngleDifference(), default_value, and metsig::tau.

2703  {
2704  double gj_diff;
2705  if (calculateGottfriedJacksonAngleDifference(tau, tau_index, gj_diff, tau_funcs))
2706  return static_cast<float>(gj_diff);
2707  return default_value;
2708  }
static constexpr float default_value
Definition: DeepTauId.cc:997
static bool calculateGottfriedJacksonAngleDifference(const TauCastType &tau, const size_t tau_index, double &gj_diff, TauFunc tau_funcs)
Definition: DeepTauId.cc:2679

◆ 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 1372 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().

1375  {
1376  if (debug_level >= 1) {
1377  std::cout << "<checkInputs>: block_name = " << block_name << std::endl;
1378  if (block_name == "input_tau") {
1379  for (int input_index = 0; input_index < n_inputs; ++input_index) {
1380  float input = inputs.matrix<float>()(0, input_index);
1381  if (edm::isNotFinite(input)) {
1382  throw cms::Exception("DeepTauId")
1383  << "in the " << block_name
1384  << ", input is not finite, i.e. infinite or NaN, for input_index = " << input_index;
1385  }
1386  if (debug_level >= 2) {
1387  std::cout << block_name << "[var = " << input_index << "] = " << std::setprecision(5) << std::fixed << input
1388  << std::endl;
1389  }
1390  }
1391  } else {
1392  assert(grid);
1393  int n_eta, n_phi;
1394  if (block_name.find("input_inner") != std::string::npos) {
1395  n_eta = 5;
1396  n_phi = 5;
1397  } else if (block_name.find("input_outer") != std::string::npos) {
1398  n_eta = 10;
1399  n_phi = 10;
1400  } else
1401  assert(0);
1402  int eta_phi_index = 0;
1403  for (int eta = -n_eta; eta <= n_eta; ++eta) {
1404  for (int phi = -n_phi; phi <= n_phi; ++phi) {
1405  const CellIndex cell_index{eta, phi};
1406  const auto cell_iter = grid->find(cell_index);
1407  if (cell_iter != grid->end()) {
1408  for (int input_index = 0; input_index < n_inputs; ++input_index) {
1409  float input = inputs.tensor<float, 4>()(eta_phi_index, 0, 0, input_index);
1410  if (edm::isNotFinite(input)) {
1411  throw cms::Exception("DeepTauId")
1412  << "in the " << block_name << ", input is not finite, i.e. infinite or NaN, for eta = " << eta
1413  << ", phi = " << phi << ", input_index = " << input_index;
1414  }
1415  if (debug_level >= 2) {
1416  std::cout << block_name << "[eta = " << eta << "][phi = " << phi << "][var = " << input_index
1417  << "] = " << std::setprecision(5) << std::fixed << input << std::endl;
1418  }
1419  }
1420  eta_phi_index += 1;
1421  }
1422  }
1423  }
1424  }
1425  }
1426  }
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:2768

◆ 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 1780 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_.

1790  {
1791  if (debug_level >= 2) {
1792  std::cout << "<DeepTauId::createConvFeatures (is_inner = " << is_inner << ")>:" << std::endl;
1793  }
1794  tensorflow::Tensor& convTensor = *convTensor_.at(is_inner);
1795  eGammaTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1796  tensorflow::DT_FLOAT,
1797  tensorflow::TensorShape{
1798  (long long int)grid.num_valid_cells(), 1, 1, dnn_inputs_v2::EgammaBlockInputs::NumberOfInputs});
1799  muonTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1800  tensorflow::DT_FLOAT,
1801  tensorflow::TensorShape{
1802  (long long int)grid.num_valid_cells(), 1, 1, dnn_inputs_v2::MuonBlockInputs::NumberOfInputs});
1803  hadronsTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
1804  tensorflow::DT_FLOAT,
1805  tensorflow::TensorShape{
1806  (long long int)grid.num_valid_cells(), 1, 1, dnn_inputs_v2::HadronBlockInputs::NumberOfInputs});
1807 
1808  eGammaTensor_[is_inner]->flat<float>().setZero();
1809  muonTensor_[is_inner]->flat<float>().setZero();
1810  hadronsTensor_[is_inner]->flat<float>().setZero();
1811 
1812  unsigned idx = 0;
1813  for (int eta = -grid.maxEtaIndex(); eta <= grid.maxEtaIndex(); ++eta) {
1814  for (int phi = -grid.maxPhiIndex(); phi <= grid.maxPhiIndex(); ++phi) {
1815  if (debug_level >= 2) {
1816  std::cout << "processing ( eta = " << eta << ", phi = " << phi << " )" << std::endl;
1817  }
1818  const CellIndex cell_index{eta, phi};
1819  const auto cell_iter = grid.find(cell_index);
1820  if (cell_iter != grid.end()) {
1821  if (debug_level >= 2) {
1822  std::cout << " creating inputs for ( eta = " << eta << ", phi = " << phi << " ): idx = " << idx
1823  << std::endl;
1824  }
1825  const Cell& cell = cell_iter->second;
1826  createEgammaBlockInputs<CandidateCastType>(
1827  idx, tau, tau_index, tau_ref, pv, rho, electrons, pfCands, cell, tau_funcs, is_inner);
1828  createMuonBlockInputs<CandidateCastType>(
1829  idx, tau, tau_index, tau_ref, pv, rho, muons, pfCands, cell, tau_funcs, is_inner);
1830  createHadronsBlockInputs<CandidateCastType>(
1831  idx, tau, tau_index, tau_ref, pv, rho, pfCands, cell, tau_funcs, is_inner);
1832  idx += 1;
1833  } else {
1834  if (debug_level >= 2) {
1835  std::cout << " skipping creation of inputs, because ( eta = " << eta << ", phi = " << phi
1836  << " ) is not in the grid !!" << std::endl;
1837  }
1838  }
1839  }
1840  }
1841 
1842  const auto predTensor = getPartialPredictions(is_inner);
1843  idx = 0;
1844  for (int eta = -grid.maxEtaIndex(); eta <= grid.maxEtaIndex(); ++eta) {
1845  for (int phi = -grid.maxPhiIndex(); phi <= grid.maxPhiIndex(); ++phi) {
1846  const CellIndex cell_index{eta, phi};
1847  const int eta_index = grid.getEtaTensorIndex(cell_index);
1848  const int phi_index = grid.getPhiTensorIndex(cell_index);
1849 
1850  const auto cell_iter = grid.find(cell_index);
1851  if (cell_iter != grid.end()) {
1852  setCellConvFeatures(convTensor, predTensor, idx, eta_index, phi_index);
1853  idx += 1;
1854  } else {
1855  setCellConvFeatures(convTensor, *zeroOutputTensor_[is_inner], 0, eta_index, phi_index);
1856  }
1857  }
1858  }
1859  }
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > hadronsTensor_
Definition: DeepTauId.cc:2773
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > zeroOutputTensor_
Definition: DeepTauId.cc:2773
void setCellConvFeatures(tensorflow::Tensor &convTensor, const tensorflow::Tensor &features, unsigned batch_idx, int eta_index, int phi_index)
Definition: DeepTauId.cc:1861
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > convTensor_
Definition: DeepTauId.cc:2773
def pv(vc)
Definition: MetAnalyzer.py:7
tensorflow::Tensor getPartialPredictions(bool is_inner)
Definition: DeepTauId.cc:1755
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > eGammaTensor_
Definition: DeepTauId.cc:2773
const int debug_level
Definition: DeepTauId.cc:2768
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > muonTensor_
Definition: DeepTauId.cc:2773

◆ 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 2017 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_, metsig::tau, runTauDisplay::tau_eta, runTauDisplay::tau_pt, and year_.

2027  {
2028  namespace dnn = dnn_inputs_v2::EgammaBlockInputs;
2029  namespace sc = deep_tau::Scaling;
2030  sc::FeatureT ft_global = sc::FeatureT::GridGlobal;
2031  sc::FeatureT ft_PFe = sc::FeatureT::PfCand_electron;
2032  sc::FeatureT ft_PFg = sc::FeatureT::PfCand_gamma;
2034 
2035  // needed to remap indices from scaling vectors to those from dnn_inputs_v2::EgammaBlockInputs
2036  int PFe_index_offset = scalingParamsMap_->at(std::make_pair(ft_global, false)).mean_.size();
2037  int e_index_offset = PFe_index_offset + scalingParamsMap_->at(std::make_pair(ft_PFe, false)).mean_.size();
2038  int PFg_index_offset = e_index_offset + scalingParamsMap_->at(std::make_pair(ft_e, false)).mean_.size();
2039 
2040  // to account for swapped order of PfCand_gamma and Electron blocks for v2p5 training w.r.t. v2p1
2041  int fill_index_offset_e = 0;
2042  int fill_index_offset_PFg = 0;
2043  if (sub_version_ == 5) {
2044  fill_index_offset_e =
2045  scalingParamsMap_->at(std::make_pair(ft_PFg, false)).mean_.size(); // size of PF gamma features
2046  fill_index_offset_PFg =
2047  -scalingParamsMap_->at(std::make_pair(ft_e, false)).mean_.size(); // size of Electron features
2048  }
2049 
2050  tensorflow::Tensor& inputs = *eGammaTensor_.at(is_inner);
2051 
2052  const auto& get = [&](int var_index) -> float& { return inputs.tensor<float, 4>()(idx, 0, 0, var_index); };
2053 
2054  const bool valid_index_pf_ele = cell_map.count(CellObjectType::PfCand_electron);
2055  const bool valid_index_pf_gamma = cell_map.count(CellObjectType::PfCand_gamma);
2056  const bool valid_index_ele = cell_map.count(CellObjectType::Electron);
2057 
2058  if (!cell_map.empty()) {
2059  const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft_global, false));
2060  get(dnn::rho) = sp.scale(rho, dnn::rho);
2061  get(dnn::tau_pt) = sp.scale(tau.polarP4().pt(), dnn::tau_pt);
2062  get(dnn::tau_eta) = sp.scale(tau.polarP4().eta(), dnn::tau_eta);
2063  get(dnn::tau_inside_ecal_crack) = sp.scale(isInEcalCrack(tau.polarP4().eta()), dnn::tau_inside_ecal_crack);
2064  }
2065  if (valid_index_pf_ele) {
2066  const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft_PFe, is_inner));
2067  size_t index_pf_ele = cell_map.at(CellObjectType::PfCand_electron);
2068  const auto& ele_cand = dynamic_cast<const CandidateCastType&>(pfCands.at(index_pf_ele));
2069 
2070  get(dnn::pfCand_ele_valid) = sp.scale(valid_index_pf_ele, dnn::pfCand_ele_valid - PFe_index_offset);
2071  get(dnn::pfCand_ele_rel_pt) =
2072  sp.scale(ele_cand.polarP4().pt() / tau.polarP4().pt(), dnn::pfCand_ele_rel_pt - PFe_index_offset);
2073  get(dnn::pfCand_ele_deta) =
2074  sp.scale(ele_cand.polarP4().eta() - tau.polarP4().eta(), dnn::pfCand_ele_deta - PFe_index_offset);
2075  get(dnn::pfCand_ele_dphi) =
2076  sp.scale(dPhi(tau.polarP4(), ele_cand.polarP4()), dnn::pfCand_ele_dphi - PFe_index_offset);
2077  get(dnn::pfCand_ele_pvAssociationQuality) = sp.scale<int>(
2078  candFunc::getPvAssocationQuality(ele_cand), dnn::pfCand_ele_pvAssociationQuality - PFe_index_offset);
2079  get(dnn::pfCand_ele_puppiWeight) = is_inner ? sp.scale(candFunc::getPuppiWeight(ele_cand, 0.9906834f),
2080  dnn::pfCand_ele_puppiWeight - PFe_index_offset)
2081  : sp.scale(candFunc::getPuppiWeight(ele_cand, 0.9669586f),
2082  dnn::pfCand_ele_puppiWeight - PFe_index_offset);
2083  get(dnn::pfCand_ele_charge) = sp.scale(ele_cand.charge(), dnn::pfCand_ele_charge - PFe_index_offset);
2084  get(dnn::pfCand_ele_lostInnerHits) =
2085  sp.scale<int>(candFunc::getLostInnerHits(ele_cand, 0), dnn::pfCand_ele_lostInnerHits - PFe_index_offset);
2086  get(dnn::pfCand_ele_numberOfPixelHits) =
2087  sp.scale(candFunc::getNumberOfPixelHits(ele_cand, 0), dnn::pfCand_ele_numberOfPixelHits - PFe_index_offset);
2088  get(dnn::pfCand_ele_vertex_dx) =
2089  sp.scale(ele_cand.vertex().x() - pv.position().x(), dnn::pfCand_ele_vertex_dx - PFe_index_offset);
2090  get(dnn::pfCand_ele_vertex_dy) =
2091  sp.scale(ele_cand.vertex().y() - pv.position().y(), dnn::pfCand_ele_vertex_dy - PFe_index_offset);
2092  get(dnn::pfCand_ele_vertex_dz) =
2093  sp.scale(ele_cand.vertex().z() - pv.position().z(), dnn::pfCand_ele_vertex_dz - PFe_index_offset);
2094  get(dnn::pfCand_ele_vertex_dx_tauFL) =
2095  sp.scale(ele_cand.vertex().x() - pv.position().x() - tau_funcs.getFlightLength(tau, tau_index).x(),
2096  dnn::pfCand_ele_vertex_dx_tauFL - PFe_index_offset);
2097  get(dnn::pfCand_ele_vertex_dy_tauFL) =
2098  sp.scale(ele_cand.vertex().y() - pv.position().y() - tau_funcs.getFlightLength(tau, tau_index).y(),
2099  dnn::pfCand_ele_vertex_dy_tauFL - PFe_index_offset);
2100  get(dnn::pfCand_ele_vertex_dz_tauFL) =
2101  sp.scale(ele_cand.vertex().z() - pv.position().z() - tau_funcs.getFlightLength(tau, tau_index).z(),
2102  dnn::pfCand_ele_vertex_dz_tauFL - PFe_index_offset);
2103 
2104  const bool hasTrackDetails = candFunc::getHasTrackDetails(ele_cand);
2105  if (hasTrackDetails) {
2106  get(dnn::pfCand_ele_hasTrackDetails) =
2107  sp.scale(hasTrackDetails, dnn::pfCand_ele_hasTrackDetails - PFe_index_offset);
2108  get(dnn::pfCand_ele_dxy) = sp.scale(candFunc::getTauDxy(ele_cand), dnn::pfCand_ele_dxy - PFe_index_offset);
2109  get(dnn::pfCand_ele_dxy_sig) = sp.scale(std::abs(candFunc::getTauDxy(ele_cand)) / ele_cand.dxyError(),
2110  dnn::pfCand_ele_dxy_sig - PFe_index_offset);
2111  get(dnn::pfCand_ele_dz) = sp.scale(candFunc::getTauDz(ele_cand), dnn::pfCand_ele_dz - PFe_index_offset);
2112  get(dnn::pfCand_ele_dz_sig) = sp.scale(std::abs(candFunc::getTauDz(ele_cand)) / ele_cand.dzError(),
2113  dnn::pfCand_ele_dz_sig - PFe_index_offset);
2114  get(dnn::pfCand_ele_track_chi2_ndof) =
2115  candFunc::getPseudoTrack(ele_cand).ndof() > 0
2116  ? sp.scale(candFunc::getPseudoTrack(ele_cand).chi2() / candFunc::getPseudoTrack(ele_cand).ndof(),
2117  dnn::pfCand_ele_track_chi2_ndof - PFe_index_offset)
2118  : 0;
2119  get(dnn::pfCand_ele_track_ndof) =
2120  candFunc::getPseudoTrack(ele_cand).ndof() > 0
2121  ? sp.scale(candFunc::getPseudoTrack(ele_cand).ndof(), dnn::pfCand_ele_track_ndof - PFe_index_offset)
2122  : 0;
2123  }
2124  }
2125  if (valid_index_pf_gamma) {
2126  const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft_PFg, is_inner));
2127  size_t index_pf_gamma = cell_map.at(CellObjectType::PfCand_gamma);
2128  const auto& gamma_cand = dynamic_cast<const CandidateCastType&>(pfCands.at(index_pf_gamma));
2129 
2130  get(dnn::pfCand_gamma_valid + fill_index_offset_PFg) =
2131  sp.scale(valid_index_pf_gamma, dnn::pfCand_gamma_valid - PFg_index_offset);
2132  get(dnn::pfCand_gamma_rel_pt + fill_index_offset_PFg) =
2133  sp.scale(gamma_cand.polarP4().pt() / tau.polarP4().pt(), dnn::pfCand_gamma_rel_pt - PFg_index_offset);
2134  get(dnn::pfCand_gamma_deta + fill_index_offset_PFg) =
2135  sp.scale(gamma_cand.polarP4().eta() - tau.polarP4().eta(), dnn::pfCand_gamma_deta - PFg_index_offset);
2136  get(dnn::pfCand_gamma_dphi + fill_index_offset_PFg) =
2137  sp.scale(dPhi(tau.polarP4(), gamma_cand.polarP4()), dnn::pfCand_gamma_dphi - PFg_index_offset);
2138  get(dnn::pfCand_gamma_pvAssociationQuality + fill_index_offset_PFg) = sp.scale<int>(
2139  candFunc::getPvAssocationQuality(gamma_cand), dnn::pfCand_gamma_pvAssociationQuality - PFg_index_offset);
2140  get(dnn::pfCand_gamma_fromPV + fill_index_offset_PFg) =
2141  sp.scale<int>(candFunc::getFromPV(gamma_cand), dnn::pfCand_gamma_fromPV - PFg_index_offset);
2142  get(dnn::pfCand_gamma_puppiWeight + fill_index_offset_PFg) =
2143  is_inner ? sp.scale(candFunc::getPuppiWeight(gamma_cand, 0.9084110f),
2144  dnn::pfCand_gamma_puppiWeight - PFg_index_offset)
2145  : sp.scale(candFunc::getPuppiWeight(gamma_cand, 0.4211567f),
2146  dnn::pfCand_gamma_puppiWeight - PFg_index_offset);
2147  get(dnn::pfCand_gamma_puppiWeightNoLep + fill_index_offset_PFg) =
2148  is_inner ? sp.scale(candFunc::getPuppiWeightNoLep(gamma_cand, 0.8857716f),
2149  dnn::pfCand_gamma_puppiWeightNoLep - PFg_index_offset)
2150  : sp.scale(candFunc::getPuppiWeightNoLep(gamma_cand, 0.3822604f),
2151  dnn::pfCand_gamma_puppiWeightNoLep - PFg_index_offset);
2152  get(dnn::pfCand_gamma_lostInnerHits + fill_index_offset_PFg) =
2153  sp.scale<int>(candFunc::getLostInnerHits(gamma_cand, 0), dnn::pfCand_gamma_lostInnerHits - PFg_index_offset);
2154  get(dnn::pfCand_gamma_numberOfPixelHits + fill_index_offset_PFg) = sp.scale(
2155  candFunc::getNumberOfPixelHits(gamma_cand, 0), dnn::pfCand_gamma_numberOfPixelHits - PFg_index_offset);
2156  get(dnn::pfCand_gamma_vertex_dx + fill_index_offset_PFg) =
2157  sp.scale(gamma_cand.vertex().x() - pv.position().x(), dnn::pfCand_gamma_vertex_dx - PFg_index_offset);
2158  get(dnn::pfCand_gamma_vertex_dy + fill_index_offset_PFg) =
2159  sp.scale(gamma_cand.vertex().y() - pv.position().y(), dnn::pfCand_gamma_vertex_dy - PFg_index_offset);
2160  get(dnn::pfCand_gamma_vertex_dz + fill_index_offset_PFg) =
2161  sp.scale(gamma_cand.vertex().z() - pv.position().z(), dnn::pfCand_gamma_vertex_dz - PFg_index_offset);
2162  get(dnn::pfCand_gamma_vertex_dx_tauFL + fill_index_offset_PFg) =
2163  sp.scale(gamma_cand.vertex().x() - pv.position().x() - tau_funcs.getFlightLength(tau, tau_index).x(),
2164  dnn::pfCand_gamma_vertex_dx_tauFL - PFg_index_offset);
2165  get(dnn::pfCand_gamma_vertex_dy_tauFL + fill_index_offset_PFg) =
2166  sp.scale(gamma_cand.vertex().y() - pv.position().y() - tau_funcs.getFlightLength(tau, tau_index).y(),
2167  dnn::pfCand_gamma_vertex_dy_tauFL - PFg_index_offset);
2168  get(dnn::pfCand_gamma_vertex_dz_tauFL + fill_index_offset_PFg) =
2169  sp.scale(gamma_cand.vertex().z() - pv.position().z() - tau_funcs.getFlightLength(tau, tau_index).z(),
2170  dnn::pfCand_gamma_vertex_dz_tauFL - PFg_index_offset);
2171  const bool hasTrackDetails = candFunc::getHasTrackDetails(gamma_cand);
2172  if (hasTrackDetails) {
2173  get(dnn::pfCand_gamma_hasTrackDetails + fill_index_offset_PFg) =
2174  sp.scale(hasTrackDetails, dnn::pfCand_gamma_hasTrackDetails - PFg_index_offset);
2175  get(dnn::pfCand_gamma_dxy + fill_index_offset_PFg) =
2176  sp.scale(candFunc::getTauDxy(gamma_cand), dnn::pfCand_gamma_dxy - PFg_index_offset);
2177  get(dnn::pfCand_gamma_dxy_sig + fill_index_offset_PFg) =
2178  sp.scale(std::abs(candFunc::getTauDxy(gamma_cand)) / gamma_cand.dxyError(),
2179  dnn::pfCand_gamma_dxy_sig - PFg_index_offset);
2180  get(dnn::pfCand_gamma_dz + fill_index_offset_PFg) =
2181  sp.scale(candFunc::getTauDz(gamma_cand), dnn::pfCand_gamma_dz - PFg_index_offset);
2182  get(dnn::pfCand_gamma_dz_sig + fill_index_offset_PFg) =
2183  sp.scale(std::abs(candFunc::getTauDz(gamma_cand)) / gamma_cand.dzError(),
2184  dnn::pfCand_gamma_dz_sig - PFg_index_offset);
2185  get(dnn::pfCand_gamma_track_chi2_ndof + fill_index_offset_PFg) =
2186  candFunc::getPseudoTrack(gamma_cand).ndof() > 0
2187  ? sp.scale(candFunc::getPseudoTrack(gamma_cand).chi2() / candFunc::getPseudoTrack(gamma_cand).ndof(),
2188  dnn::pfCand_gamma_track_chi2_ndof - PFg_index_offset)
2189  : 0;
2190  get(dnn::pfCand_gamma_track_ndof + fill_index_offset_PFg) =
2191  candFunc::getPseudoTrack(gamma_cand).ndof() > 0
2192  ? sp.scale(candFunc::getPseudoTrack(gamma_cand).ndof(), dnn::pfCand_gamma_track_ndof - PFg_index_offset)
2193  : 0;
2194  }
2195  }
2196  if (valid_index_ele) {
2197  const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft_e, is_inner));
2198  size_t index_ele = cell_map.at(CellObjectType::Electron);
2199  const auto& ele = electrons->at(index_ele);
2200 
2201  get(dnn::ele_valid + fill_index_offset_e) = sp.scale(valid_index_ele, dnn::ele_valid - e_index_offset);
2202  get(dnn::ele_rel_pt + fill_index_offset_e) =
2203  sp.scale(ele.polarP4().pt() / tau.polarP4().pt(), dnn::ele_rel_pt - e_index_offset);
2204  get(dnn::ele_deta + fill_index_offset_e) =
2205  sp.scale(ele.polarP4().eta() - tau.polarP4().eta(), dnn::ele_deta - e_index_offset);
2206  get(dnn::ele_dphi + fill_index_offset_e) =
2207  sp.scale(dPhi(tau.polarP4(), ele.polarP4()), dnn::ele_dphi - e_index_offset);
2208 
2209  float cc_ele_energy, cc_gamma_energy;
2210  int cc_n_gamma;
2211  const bool cc_valid = calculateElectronClusterVarsV2(ele, cc_ele_energy, cc_gamma_energy, cc_n_gamma);
2212  if (cc_valid) {
2213  get(dnn::ele_cc_valid + fill_index_offset_e) = sp.scale(cc_valid, dnn::ele_cc_valid - e_index_offset);
2214  get(dnn::ele_cc_ele_rel_energy + fill_index_offset_e) =
2215  sp.scale(cc_ele_energy / ele.polarP4().pt(), dnn::ele_cc_ele_rel_energy - e_index_offset);
2216  get(dnn::ele_cc_gamma_rel_energy + fill_index_offset_e) =
2217  sp.scale(cc_gamma_energy / cc_ele_energy, dnn::ele_cc_gamma_rel_energy - e_index_offset);
2218  get(dnn::ele_cc_n_gamma + fill_index_offset_e) = sp.scale(cc_n_gamma, dnn::ele_cc_n_gamma - e_index_offset);
2219  }
2220  get(dnn::ele_rel_trackMomentumAtVtx + fill_index_offset_e) =
2221  sp.scale(ele.trackMomentumAtVtx().R() / ele.polarP4().pt(), dnn::ele_rel_trackMomentumAtVtx - e_index_offset);
2222  get(dnn::ele_rel_trackMomentumAtCalo + fill_index_offset_e) = sp.scale(
2223  ele.trackMomentumAtCalo().R() / ele.polarP4().pt(), dnn::ele_rel_trackMomentumAtCalo - e_index_offset);
2224  get(dnn::ele_rel_trackMomentumOut + fill_index_offset_e) =
2225  sp.scale(ele.trackMomentumOut().R() / ele.polarP4().pt(), dnn::ele_rel_trackMomentumOut - e_index_offset);
2226  get(dnn::ele_rel_trackMomentumAtEleClus + fill_index_offset_e) = sp.scale(
2227  ele.trackMomentumAtEleClus().R() / ele.polarP4().pt(), dnn::ele_rel_trackMomentumAtEleClus - e_index_offset);
2228  get(dnn::ele_rel_trackMomentumAtVtxWithConstraint + fill_index_offset_e) =
2229  sp.scale(ele.trackMomentumAtVtxWithConstraint().R() / ele.polarP4().pt(),
2230  dnn::ele_rel_trackMomentumAtVtxWithConstraint - e_index_offset);
2231  get(dnn::ele_rel_ecalEnergy + fill_index_offset_e) =
2232  sp.scale(ele.ecalEnergy() / ele.polarP4().pt(), dnn::ele_rel_ecalEnergy - e_index_offset);
2233  get(dnn::ele_ecalEnergy_sig + fill_index_offset_e) =
2234  sp.scale(ele.ecalEnergy() / ele.ecalEnergyError(), dnn::ele_ecalEnergy_sig - e_index_offset);
2235  get(dnn::ele_eSuperClusterOverP + fill_index_offset_e) =
2236  sp.scale(ele.eSuperClusterOverP(), dnn::ele_eSuperClusterOverP - e_index_offset);
2237  get(dnn::ele_eSeedClusterOverP + fill_index_offset_e) =
2238  sp.scale(ele.eSeedClusterOverP(), dnn::ele_eSeedClusterOverP - e_index_offset);
2239  get(dnn::ele_eSeedClusterOverPout + fill_index_offset_e) =
2240  sp.scale(ele.eSeedClusterOverPout(), dnn::ele_eSeedClusterOverPout - e_index_offset);
2241  get(dnn::ele_eEleClusterOverPout + fill_index_offset_e) =
2242  sp.scale(ele.eEleClusterOverPout(), dnn::ele_eEleClusterOverPout - e_index_offset);
2243  get(dnn::ele_deltaEtaSuperClusterTrackAtVtx + fill_index_offset_e) =
2244  sp.scale(ele.deltaEtaSuperClusterTrackAtVtx(), dnn::ele_deltaEtaSuperClusterTrackAtVtx - e_index_offset);
2245  get(dnn::ele_deltaEtaSeedClusterTrackAtCalo + fill_index_offset_e) =
2246  sp.scale(ele.deltaEtaSeedClusterTrackAtCalo(), dnn::ele_deltaEtaSeedClusterTrackAtCalo - e_index_offset);
2247  get(dnn::ele_deltaEtaEleClusterTrackAtCalo + fill_index_offset_e) =
2248  sp.scale(ele.deltaEtaEleClusterTrackAtCalo(), dnn::ele_deltaEtaEleClusterTrackAtCalo - e_index_offset);
2249  get(dnn::ele_deltaPhiEleClusterTrackAtCalo + fill_index_offset_e) =
2250  sp.scale(ele.deltaPhiEleClusterTrackAtCalo(), dnn::ele_deltaPhiEleClusterTrackAtCalo - e_index_offset);
2251  get(dnn::ele_deltaPhiSuperClusterTrackAtVtx + fill_index_offset_e) =
2252  sp.scale(ele.deltaPhiSuperClusterTrackAtVtx(), dnn::ele_deltaPhiSuperClusterTrackAtVtx - e_index_offset);
2253  get(dnn::ele_deltaPhiSeedClusterTrackAtCalo + fill_index_offset_e) =
2254  sp.scale(ele.deltaPhiSeedClusterTrackAtCalo(), dnn::ele_deltaPhiSeedClusterTrackAtCalo - e_index_offset);
2255  const bool mva_valid =
2256  (ele.mvaInput().earlyBrem > -2) ||
2257  (year_ !=
2258  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
2259  if (mva_valid) {
2260  get(dnn::ele_mvaInput_earlyBrem + fill_index_offset_e) =
2261  sp.scale(ele.mvaInput().earlyBrem, dnn::ele_mvaInput_earlyBrem - e_index_offset);
2262  get(dnn::ele_mvaInput_lateBrem + fill_index_offset_e) =
2263  sp.scale(ele.mvaInput().lateBrem, dnn::ele_mvaInput_lateBrem - e_index_offset);
2264  get(dnn::ele_mvaInput_sigmaEtaEta + fill_index_offset_e) =
2265  sp.scale(ele.mvaInput().sigmaEtaEta, dnn::ele_mvaInput_sigmaEtaEta - e_index_offset);
2266  get(dnn::ele_mvaInput_hadEnergy + fill_index_offset_e) =
2267  sp.scale(ele.mvaInput().hadEnergy, dnn::ele_mvaInput_hadEnergy - e_index_offset);
2268  get(dnn::ele_mvaInput_deltaEta + fill_index_offset_e) =
2269  sp.scale(ele.mvaInput().deltaEta, dnn::ele_mvaInput_deltaEta - e_index_offset);
2270  }
2271  const auto& gsfTrack = ele.gsfTrack();
2272  if (gsfTrack.isNonnull()) {
2273  get(dnn::ele_gsfTrack_normalizedChi2 + fill_index_offset_e) =
2274  sp.scale(gsfTrack->normalizedChi2(), dnn::ele_gsfTrack_normalizedChi2 - e_index_offset);
2275  get(dnn::ele_gsfTrack_numberOfValidHits + fill_index_offset_e) =
2276  sp.scale(gsfTrack->numberOfValidHits(), dnn::ele_gsfTrack_numberOfValidHits - e_index_offset);
2277  get(dnn::ele_rel_gsfTrack_pt + fill_index_offset_e) =
2278  sp.scale(gsfTrack->pt() / ele.polarP4().pt(), dnn::ele_rel_gsfTrack_pt - e_index_offset);
2279  get(dnn::ele_gsfTrack_pt_sig + fill_index_offset_e) =
2280  sp.scale(gsfTrack->pt() / gsfTrack->ptError(), dnn::ele_gsfTrack_pt_sig - e_index_offset);
2281  }
2282  const auto& closestCtfTrack = ele.closestCtfTrackRef();
2283  const bool has_closestCtfTrack = closestCtfTrack.isNonnull();
2284  if (has_closestCtfTrack) {
2285  get(dnn::ele_has_closestCtfTrack + fill_index_offset_e) =
2286  sp.scale(has_closestCtfTrack, dnn::ele_has_closestCtfTrack - e_index_offset);
2287  get(dnn::ele_closestCtfTrack_normalizedChi2 + fill_index_offset_e) =
2288  sp.scale(closestCtfTrack->normalizedChi2(), dnn::ele_closestCtfTrack_normalizedChi2 - e_index_offset);
2289  get(dnn::ele_closestCtfTrack_numberOfValidHits + fill_index_offset_e) =
2290  sp.scale(closestCtfTrack->numberOfValidHits(), dnn::ele_closestCtfTrack_numberOfValidHits - e_index_offset);
2291  }
2292  }
2293  }
static bool isInEcalCrack(double eta)
Definition: DeepTauId.cc:2710
const unsigned sub_version_
Definition: DeepTauId.cc:2767
const std::map< std::pair< deep_tau::Scaling::FeatureT, bool >, deep_tau::Scaling::ScalingParams > * scalingParamsMap_
Definition: DeepTauId.cc:2775
const unsigned year_
Definition: DeepTauId.cc:2765
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:1349
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > eGammaTensor_
Definition: DeepTauId.cc:2773

◆ 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 2447 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_, metsig::tau, runTauDisplay::tau_eta, and runTauDisplay::tau_pt.

2456  {
2457  namespace dnn = dnn_inputs_v2::HadronBlockInputs;
2458  namespace sc = deep_tau::Scaling;
2459  sc::FeatureT ft_global = sc::FeatureT::GridGlobal;
2460  sc::FeatureT ft_PFchH = sc::FeatureT::PfCand_chHad;
2461  sc::FeatureT ft_PFnH = sc::FeatureT::PfCand_nHad;
2462 
2463  // needed to remap indices from scaling vectors to those from dnn_inputs_v2::HadronBlockInputs
2464  int PFchH_index_offset = scalingParamsMap_->at(std::make_pair(ft_global, false)).mean_.size();
2465  int PFnH_index_offset = PFchH_index_offset + scalingParamsMap_->at(std::make_pair(ft_PFchH, false)).mean_.size();
2466 
2467  tensorflow::Tensor& inputs = *hadronsTensor_.at(is_inner);
2468 
2469  const auto& get = [&](int var_index) -> float& { return inputs.tensor<float, 4>()(idx, 0, 0, var_index); };
2470 
2471  const bool valid_chH = cell_map.count(CellObjectType::PfCand_chargedHadron);
2472  const bool valid_nH = cell_map.count(CellObjectType::PfCand_neutralHadron);
2473 
2474  if (!cell_map.empty()) {
2475  const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft_global, false));
2476  get(dnn::rho) = sp.scale(rho, dnn::rho);
2477  get(dnn::tau_pt) = sp.scale(tau.polarP4().pt(), dnn::tau_pt);
2478  get(dnn::tau_eta) = sp.scale(tau.polarP4().eta(), dnn::tau_eta);
2479  get(dnn::tau_inside_ecal_crack) = sp.scale(isInEcalCrack(tau.polarP4().eta()), dnn::tau_inside_ecal_crack);
2480  }
2481  if (valid_chH) {
2482  const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft_PFchH, is_inner));
2483  size_t index_chH = cell_map.at(CellObjectType::PfCand_chargedHadron);
2484  const auto& chH_cand = dynamic_cast<const CandidateCastType&>(pfCands.at(index_chH));
2485 
2486  get(dnn::pfCand_chHad_valid) = sp.scale(valid_chH, dnn::pfCand_chHad_valid - PFchH_index_offset);
2487  get(dnn::pfCand_chHad_rel_pt) =
2488  sp.scale(chH_cand.polarP4().pt() / tau.polarP4().pt(), dnn::pfCand_chHad_rel_pt - PFchH_index_offset);
2489  get(dnn::pfCand_chHad_deta) =
2490  sp.scale(chH_cand.polarP4().eta() - tau.polarP4().eta(), dnn::pfCand_chHad_deta - PFchH_index_offset);
2491  get(dnn::pfCand_chHad_dphi) =
2492  sp.scale(dPhi(tau.polarP4(), chH_cand.polarP4()), dnn::pfCand_chHad_dphi - PFchH_index_offset);
2493  get(dnn::pfCand_chHad_leadChargedHadrCand) =
2494  sp.scale(&chH_cand == dynamic_cast<const CandidateCastType*>(tau.leadChargedHadrCand().get()),
2495  dnn::pfCand_chHad_leadChargedHadrCand - PFchH_index_offset);
2496  get(dnn::pfCand_chHad_pvAssociationQuality) = sp.scale<int>(
2497  candFunc::getPvAssocationQuality(chH_cand), dnn::pfCand_chHad_pvAssociationQuality - PFchH_index_offset);
2498  get(dnn::pfCand_chHad_fromPV) =
2499  sp.scale<int>(candFunc::getFromPV(chH_cand), dnn::pfCand_chHad_fromPV - PFchH_index_offset);
2500  const float default_chH_pw_inner = 0.7614090f;
2501  const float default_chH_pw_outer = 0.1974930f;
2502  get(dnn::pfCand_chHad_puppiWeight) = is_inner ? sp.scale(candFunc::getPuppiWeight(chH_cand, default_chH_pw_inner),
2503  dnn::pfCand_chHad_puppiWeight - PFchH_index_offset)
2504  : sp.scale(candFunc::getPuppiWeight(chH_cand, default_chH_pw_outer),
2505  dnn::pfCand_chHad_puppiWeight - PFchH_index_offset);
2506  get(dnn::pfCand_chHad_puppiWeightNoLep) =
2507  is_inner ? sp.scale(candFunc::getPuppiWeightNoLep(chH_cand, default_chH_pw_inner),
2508  dnn::pfCand_chHad_puppiWeightNoLep - PFchH_index_offset)
2509  : sp.scale(candFunc::getPuppiWeightNoLep(chH_cand, default_chH_pw_outer),
2510  dnn::pfCand_chHad_puppiWeightNoLep - PFchH_index_offset);
2511  get(dnn::pfCand_chHad_charge) = sp.scale(chH_cand.charge(), dnn::pfCand_chHad_charge - PFchH_index_offset);
2512  get(dnn::pfCand_chHad_lostInnerHits) =
2513  sp.scale<int>(candFunc::getLostInnerHits(chH_cand, 0), dnn::pfCand_chHad_lostInnerHits - PFchH_index_offset);
2514  get(dnn::pfCand_chHad_numberOfPixelHits) = sp.scale(candFunc::getNumberOfPixelHits(chH_cand, 0),
2515  dnn::pfCand_chHad_numberOfPixelHits - PFchH_index_offset);
2516  get(dnn::pfCand_chHad_vertex_dx) =
2517  sp.scale(chH_cand.vertex().x() - pv.position().x(), dnn::pfCand_chHad_vertex_dx - PFchH_index_offset);
2518  get(dnn::pfCand_chHad_vertex_dy) =
2519  sp.scale(chH_cand.vertex().y() - pv.position().y(), dnn::pfCand_chHad_vertex_dy - PFchH_index_offset);
2520  get(dnn::pfCand_chHad_vertex_dz) =
2521  sp.scale(chH_cand.vertex().z() - pv.position().z(), dnn::pfCand_chHad_vertex_dz - PFchH_index_offset);
2522  get(dnn::pfCand_chHad_vertex_dx_tauFL) =
2523  sp.scale(chH_cand.vertex().x() - pv.position().x() - tau_funcs.getFlightLength(tau, tau_index).x(),
2524  dnn::pfCand_chHad_vertex_dx_tauFL - PFchH_index_offset);
2525  get(dnn::pfCand_chHad_vertex_dy_tauFL) =
2526  sp.scale(chH_cand.vertex().y() - pv.position().y() - tau_funcs.getFlightLength(tau, tau_index).y(),
2527  dnn::pfCand_chHad_vertex_dy_tauFL - PFchH_index_offset);
2528  get(dnn::pfCand_chHad_vertex_dz_tauFL) =
2529  sp.scale(chH_cand.vertex().z() - pv.position().z() - tau_funcs.getFlightLength(tau, tau_index).z(),
2530  dnn::pfCand_chHad_vertex_dz_tauFL - PFchH_index_offset);
2531 
2532  const bool hasTrackDetails = candFunc::getHasTrackDetails(chH_cand);
2533  if (hasTrackDetails) {
2534  get(dnn::pfCand_chHad_hasTrackDetails) =
2535  sp.scale(hasTrackDetails, dnn::pfCand_chHad_hasTrackDetails - PFchH_index_offset);
2536  get(dnn::pfCand_chHad_dxy) =
2537  sp.scale(candFunc::getTauDxy(chH_cand), dnn::pfCand_chHad_dxy - PFchH_index_offset);
2538  get(dnn::pfCand_chHad_dxy_sig) = sp.scale(std::abs(candFunc::getTauDxy(chH_cand)) / chH_cand.dxyError(),
2539  dnn::pfCand_chHad_dxy_sig - PFchH_index_offset);
2540  get(dnn::pfCand_chHad_dz) = sp.scale(candFunc::getTauDz(chH_cand), dnn::pfCand_chHad_dz - PFchH_index_offset);
2541  get(dnn::pfCand_chHad_dz_sig) = sp.scale(std::abs(candFunc::getTauDz(chH_cand)) / chH_cand.dzError(),
2542  dnn::pfCand_chHad_dz_sig - PFchH_index_offset);
2543  get(dnn::pfCand_chHad_track_chi2_ndof) =
2544  candFunc::getPseudoTrack(chH_cand).ndof() > 0
2545  ? sp.scale(candFunc::getPseudoTrack(chH_cand).chi2() / candFunc::getPseudoTrack(chH_cand).ndof(),
2546  dnn::pfCand_chHad_track_chi2_ndof - PFchH_index_offset)
2547  : 0;
2548  get(dnn::pfCand_chHad_track_ndof) =
2549  candFunc::getPseudoTrack(chH_cand).ndof() > 0
2550  ? sp.scale(candFunc::getPseudoTrack(chH_cand).ndof(), dnn::pfCand_chHad_track_ndof - PFchH_index_offset)
2551  : 0;
2552  }
2553  float hcal_fraction = candFunc::getHCalFraction(chH_cand, disable_hcalFraction_workaround_);
2554  get(dnn::pfCand_chHad_hcalFraction) =
2555  sp.scale(hcal_fraction, dnn::pfCand_chHad_hcalFraction - PFchH_index_offset);
2556  get(dnn::pfCand_chHad_rawCaloFraction) =
2557  sp.scale(candFunc::getRawCaloFraction(chH_cand), dnn::pfCand_chHad_rawCaloFraction - PFchH_index_offset);
2558  }
2559  if (valid_nH) {
2560  const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft_PFnH, is_inner));
2561  size_t index_nH = cell_map.at(CellObjectType::PfCand_neutralHadron);
2562  const auto& nH_cand = dynamic_cast<const CandidateCastType&>(pfCands.at(index_nH));
2563 
2564  get(dnn::pfCand_nHad_valid) = sp.scale(valid_nH, dnn::pfCand_nHad_valid - PFnH_index_offset);
2565  get(dnn::pfCand_nHad_rel_pt) =
2566  sp.scale(nH_cand.polarP4().pt() / tau.polarP4().pt(), dnn::pfCand_nHad_rel_pt - PFnH_index_offset);
2567  get(dnn::pfCand_nHad_deta) =
2568  sp.scale(nH_cand.polarP4().eta() - tau.polarP4().eta(), dnn::pfCand_nHad_deta - PFnH_index_offset);
2569  get(dnn::pfCand_nHad_dphi) =
2570  sp.scale(dPhi(tau.polarP4(), nH_cand.polarP4()), dnn::pfCand_nHad_dphi - PFnH_index_offset);
2571  get(dnn::pfCand_nHad_puppiWeight) = is_inner ? sp.scale(candFunc::getPuppiWeight(nH_cand, 0.9798355f),
2572  dnn::pfCand_nHad_puppiWeight - PFnH_index_offset)
2573  : sp.scale(candFunc::getPuppiWeight(nH_cand, 0.7813260f),
2574  dnn::pfCand_nHad_puppiWeight - PFnH_index_offset);
2575  get(dnn::pfCand_nHad_puppiWeightNoLep) = is_inner
2576  ? sp.scale(candFunc::getPuppiWeightNoLep(nH_cand, 0.9046796f),
2577  dnn::pfCand_nHad_puppiWeightNoLep - PFnH_index_offset)
2578  : sp.scale(candFunc::getPuppiWeightNoLep(nH_cand, 0.6554860f),
2579  dnn::pfCand_nHad_puppiWeightNoLep - PFnH_index_offset);
2580  float hcal_fraction = candFunc::getHCalFraction(nH_cand, disable_hcalFraction_workaround_);
2581  get(dnn::pfCand_nHad_hcalFraction) = sp.scale(hcal_fraction, dnn::pfCand_nHad_hcalFraction - PFnH_index_offset);
2582  }
2583  }
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > hadronsTensor_
Definition: DeepTauId.cc:2773
static bool isInEcalCrack(double eta)
Definition: DeepTauId.cc:2710
const std::map< std::pair< deep_tau::Scaling::FeatureT, bool >, deep_tau::Scaling::ScalingParams > * scalingParamsMap_
Definition: DeepTauId.cc:2775
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:2770

◆ 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 2296 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, metsig::tau, runTauDisplay::tau_eta, and runTauDisplay::tau_pt.

2306  {
2307  namespace dnn = dnn_inputs_v2::MuonBlockInputs;
2308  namespace sc = deep_tau::Scaling;
2309  sc::FeatureT ft_global = sc::FeatureT::GridGlobal;
2310  sc::FeatureT ft_PFmu = sc::FeatureT::PfCand_muon;
2312 
2313  // needed to remap indices from scaling vectors to those from dnn_inputs_v2::MuonBlockInputs
2314  int PFmu_index_offset = scalingParamsMap_->at(std::make_pair(ft_global, false)).mean_.size();
2315  int mu_index_offset = PFmu_index_offset + scalingParamsMap_->at(std::make_pair(ft_PFmu, false)).mean_.size();
2316 
2317  tensorflow::Tensor& inputs = *muonTensor_.at(is_inner);
2318 
2319  const auto& get = [&](int var_index) -> float& { return inputs.tensor<float, 4>()(idx, 0, 0, var_index); };
2320 
2321  const bool valid_index_pf_muon = cell_map.count(CellObjectType::PfCand_muon);
2322  const bool valid_index_muon = cell_map.count(CellObjectType::Muon);
2323 
2324  if (!cell_map.empty()) {
2325  const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft_global, false));
2326  get(dnn::rho) = sp.scale(rho, dnn::rho);
2327  get(dnn::tau_pt) = sp.scale(tau.polarP4().pt(), dnn::tau_pt);
2328  get(dnn::tau_eta) = sp.scale(tau.polarP4().eta(), dnn::tau_eta);
2329  get(dnn::tau_inside_ecal_crack) = sp.scale(isInEcalCrack(tau.polarP4().eta()), dnn::tau_inside_ecal_crack);
2330  }
2331  if (valid_index_pf_muon) {
2332  const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft_PFmu, is_inner));
2333  size_t index_pf_muon = cell_map.at(CellObjectType::PfCand_muon);
2334  const auto& muon_cand = dynamic_cast<const CandidateCastType&>(pfCands.at(index_pf_muon));
2335 
2336  get(dnn::pfCand_muon_valid) = sp.scale(valid_index_pf_muon, dnn::pfCand_muon_valid - PFmu_index_offset);
2337  get(dnn::pfCand_muon_rel_pt) =
2338  sp.scale(muon_cand.polarP4().pt() / tau.polarP4().pt(), dnn::pfCand_muon_rel_pt - PFmu_index_offset);
2339  get(dnn::pfCand_muon_deta) =
2340  sp.scale(muon_cand.polarP4().eta() - tau.polarP4().eta(), dnn::pfCand_muon_deta - PFmu_index_offset);
2341  get(dnn::pfCand_muon_dphi) =
2342  sp.scale(dPhi(tau.polarP4(), muon_cand.polarP4()), dnn::pfCand_muon_dphi - PFmu_index_offset);
2343  get(dnn::pfCand_muon_pvAssociationQuality) = sp.scale<int>(
2344  candFunc::getPvAssocationQuality(muon_cand), dnn::pfCand_muon_pvAssociationQuality - PFmu_index_offset);
2345  get(dnn::pfCand_muon_fromPV) =
2346  sp.scale<int>(candFunc::getFromPV(muon_cand), dnn::pfCand_muon_fromPV - PFmu_index_offset);
2347  get(dnn::pfCand_muon_puppiWeight) = is_inner ? sp.scale(candFunc::getPuppiWeight(muon_cand, 0.9786588f),
2348  dnn::pfCand_muon_puppiWeight - PFmu_index_offset)
2349  : sp.scale(candFunc::getPuppiWeight(muon_cand, 0.8132477f),
2350  dnn::pfCand_muon_puppiWeight - PFmu_index_offset);
2351  get(dnn::pfCand_muon_charge) = sp.scale(muon_cand.charge(), dnn::pfCand_muon_charge - PFmu_index_offset);
2352  get(dnn::pfCand_muon_lostInnerHits) =
2353  sp.scale<int>(candFunc::getLostInnerHits(muon_cand, 0), dnn::pfCand_muon_lostInnerHits - PFmu_index_offset);
2354  get(dnn::pfCand_muon_numberOfPixelHits) = sp.scale(candFunc::getNumberOfPixelHits(muon_cand, 0),
2355  dnn::pfCand_muon_numberOfPixelHits - PFmu_index_offset);
2356  get(dnn::pfCand_muon_vertex_dx) =
2357  sp.scale(muon_cand.vertex().x() - pv.position().x(), dnn::pfCand_muon_vertex_dx - PFmu_index_offset);
2358  get(dnn::pfCand_muon_vertex_dy) =
2359  sp.scale(muon_cand.vertex().y() - pv.position().y(), dnn::pfCand_muon_vertex_dy - PFmu_index_offset);
2360  get(dnn::pfCand_muon_vertex_dz) =
2361  sp.scale(muon_cand.vertex().z() - pv.position().z(), dnn::pfCand_muon_vertex_dz - PFmu_index_offset);
2362  get(dnn::pfCand_muon_vertex_dx_tauFL) =
2363  sp.scale(muon_cand.vertex().x() - pv.position().x() - tau_funcs.getFlightLength(tau, tau_index).x(),
2364  dnn::pfCand_muon_vertex_dx_tauFL - PFmu_index_offset);
2365  get(dnn::pfCand_muon_vertex_dy_tauFL) =
2366  sp.scale(muon_cand.vertex().y() - pv.position().y() - tau_funcs.getFlightLength(tau, tau_index).y(),
2367  dnn::pfCand_muon_vertex_dy_tauFL - PFmu_index_offset);
2368  get(dnn::pfCand_muon_vertex_dz_tauFL) =
2369  sp.scale(muon_cand.vertex().z() - pv.position().z() - tau_funcs.getFlightLength(tau, tau_index).z(),
2370  dnn::pfCand_muon_vertex_dz_tauFL - PFmu_index_offset);
2371 
2372  const bool hasTrackDetails = candFunc::getHasTrackDetails(muon_cand);
2373  if (hasTrackDetails) {
2374  get(dnn::pfCand_muon_hasTrackDetails) =
2375  sp.scale(hasTrackDetails, dnn::pfCand_muon_hasTrackDetails - PFmu_index_offset);
2376  get(dnn::pfCand_muon_dxy) = sp.scale(candFunc::getTauDxy(muon_cand), dnn::pfCand_muon_dxy - PFmu_index_offset);
2377  get(dnn::pfCand_muon_dxy_sig) = sp.scale(std::abs(candFunc::getTauDxy(muon_cand)) / muon_cand.dxyError(),
2378  dnn::pfCand_muon_dxy_sig - PFmu_index_offset);
2379  get(dnn::pfCand_muon_dz) = sp.scale(candFunc::getTauDz(muon_cand), dnn::pfCand_muon_dz - PFmu_index_offset);
2380  get(dnn::pfCand_muon_dz_sig) = sp.scale(std::abs(candFunc::getTauDz(muon_cand)) / muon_cand.dzError(),
2381  dnn::pfCand_muon_dz_sig - PFmu_index_offset);
2382  get(dnn::pfCand_muon_track_chi2_ndof) =
2383  candFunc::getPseudoTrack(muon_cand).ndof() > 0
2384  ? sp.scale(candFunc::getPseudoTrack(muon_cand).chi2() / candFunc::getPseudoTrack(muon_cand).ndof(),
2385  dnn::pfCand_muon_track_chi2_ndof - PFmu_index_offset)
2386  : 0;
2387  get(dnn::pfCand_muon_track_ndof) =
2388  candFunc::getPseudoTrack(muon_cand).ndof() > 0
2389  ? sp.scale(candFunc::getPseudoTrack(muon_cand).ndof(), dnn::pfCand_muon_track_ndof - PFmu_index_offset)
2390  : 0;
2391  }
2392  }
2393  if (valid_index_muon) {
2394  const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft_mu, is_inner));
2395  size_t index_muon = cell_map.at(CellObjectType::Muon);
2396  const auto& muon = muons->at(index_muon);
2397 
2398  get(dnn::muon_valid) = sp.scale(valid_index_muon, dnn::muon_valid - mu_index_offset);
2399  get(dnn::muon_rel_pt) = sp.scale(muon.polarP4().pt() / tau.polarP4().pt(), dnn::muon_rel_pt - mu_index_offset);
2400  get(dnn::muon_deta) = sp.scale(muon.polarP4().eta() - tau.polarP4().eta(), dnn::muon_deta - mu_index_offset);
2401  get(dnn::muon_dphi) = sp.scale(dPhi(tau.polarP4(), muon.polarP4()), dnn::muon_dphi - mu_index_offset);
2402  get(dnn::muon_dxy) = sp.scale(muon.dB(pat::Muon::PV2D), dnn::muon_dxy - mu_index_offset);
2403  get(dnn::muon_dxy_sig) =
2404  sp.scale(std::abs(muon.dB(pat::Muon::PV2D)) / muon.edB(pat::Muon::PV2D), dnn::muon_dxy_sig - mu_index_offset);
2405 
2406  const bool normalizedChi2_valid = muon.globalTrack().isNonnull() && muon.normChi2() >= 0;
2407  if (normalizedChi2_valid) {
2408  get(dnn::muon_normalizedChi2_valid) =
2409  sp.scale(normalizedChi2_valid, dnn::muon_normalizedChi2_valid - mu_index_offset);
2410  get(dnn::muon_normalizedChi2) = sp.scale(muon.normChi2(), dnn::muon_normalizedChi2 - mu_index_offset);
2411  if (muon.innerTrack().isNonnull())
2412  get(dnn::muon_numberOfValidHits) =
2413  sp.scale(muon.numberOfValidHits(), dnn::muon_numberOfValidHits - mu_index_offset);
2414  }
2415  get(dnn::muon_segmentCompatibility) =
2416  sp.scale(muon.segmentCompatibility(), dnn::muon_segmentCompatibility - mu_index_offset);
2417  get(dnn::muon_caloCompatibility) =
2418  sp.scale(muon.caloCompatibility(), dnn::muon_caloCompatibility - mu_index_offset);
2419 
2420  const bool pfEcalEnergy_valid = muon.pfEcalEnergy() >= 0;
2421  if (pfEcalEnergy_valid) {
2422  get(dnn::muon_pfEcalEnergy_valid) =
2423  sp.scale(pfEcalEnergy_valid, dnn::muon_pfEcalEnergy_valid - mu_index_offset);
2424  get(dnn::muon_rel_pfEcalEnergy) =
2425  sp.scale(muon.pfEcalEnergy() / muon.polarP4().pt(), dnn::muon_rel_pfEcalEnergy - mu_index_offset);
2426  }
2427 
2428  MuonHitMatchV2 hit_match(muon);
2429  static const std::map<int, std::pair<int, int>> muonMatchHitVars = {
2430  {MuonSubdetId::DT, {dnn::muon_n_matches_DT_1, dnn::muon_n_hits_DT_1}},
2431  {MuonSubdetId::CSC, {dnn::muon_n_matches_CSC_1, dnn::muon_n_hits_CSC_1}},
2432  {MuonSubdetId::RPC, {dnn::muon_n_matches_RPC_1, dnn::muon_n_hits_RPC_1}}};
2433 
2434  for (int subdet : hit_match.MuonHitMatchV2::consideredSubdets()) {
2435  const auto& matchHitVar = muonMatchHitVars.at(subdet);
2436  for (int station = MuonHitMatchV2::first_station_id; station <= MuonHitMatchV2::last_station_id; ++station) {
2437  const unsigned n_matches = hit_match.nMatches(subdet, station);
2438  const unsigned n_hits = hit_match.nHits(subdet, station);
2439  get(matchHitVar.first + station - 1) = sp.scale(n_matches, matchHitVar.first + station - 1 - mu_index_offset);
2440  get(matchHitVar.second + station - 1) = sp.scale(n_hits, matchHitVar.second + station - 1 - mu_index_offset);
2441  }
2442  }
2443  }
2444  }
static bool isInEcalCrack(double eta)
Definition: DeepTauId.cc:2710
const std::map< std::pair< deep_tau::Scaling::FeatureT, bool >, deep_tau::Scaling::ScalingParams > * scalingParamsMap_
Definition: DeepTauId.cc:2775
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:2773
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 1314 of file DeepTauId.cc.

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

Referenced by produce().

1314  {
1315  for (const auto& output_desc : outputs_) {
1316  const WPList* working_points = nullptr;
1317  if (workingPoints_.find(output_desc.first) != workingPoints_.end()) {
1318  working_points = &workingPoints_.at(output_desc.first);
1319  }
1320  auto result = output_desc.second.get_value(taus, pred, working_points, is_online_);
1321  event.put(std::move(result), output_desc.first);
1322  }
1323  }
std::map< std::string, WPList > workingPoints_
Definition: DeepTauId.cc:2733
working_points
Definition: FWLite.py:134
OutputCollection outputs_
Definition: DeepTauId.cc:2735
const bool is_online_
Definition: DeepTauId.cc:2734
std::vector< CutterPtr > WPList
Definition: DeepTauId.cc:956
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 1872 of file DeepTauId.cc.

References funct::abs(), calculateGottfriedJacksonAngleDifference(), disable_dxy_pca_, 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_, metsig::tau, runTauDisplay::tau_eta, runTauDisplay::tau_mass, runTauDisplay::tau_phi, runTauDisplay::tau_pt, tauBlockTensor_, and tauInputs_indices_.

1877  {
1878  namespace dnn = dnn_inputs_v2::TauBlockInputs;
1879  namespace sc = deep_tau::Scaling;
1880  sc::FeatureT ft = sc::FeatureT::TauFlat;
1881  const sc::ScalingParams& sp = scalingParamsMap_->at(std::make_pair(ft, false));
1882 
1883  tensorflow::Tensor& inputs = *tauBlockTensor_;
1884  inputs.flat<float>().setZero();
1885 
1886  const auto& get = [&](int var_index) -> float& {
1887  return inputs.matrix<float>()(0, tauInputs_indices_.at(var_index));
1888  };
1889 
1890  auto leadChargedHadrCand = dynamic_cast<const CandidateCastType*>(tau.leadChargedHadrCand().get());
1891 
1892  get(dnn::rho) = sp.scale(rho, tauInputs_indices_[dnn::rho]);
1893  get(dnn::tau_pt) = sp.scale(tau.polarP4().pt(), tauInputs_indices_[dnn::tau_pt]);
1894  get(dnn::tau_eta) = sp.scale(tau.polarP4().eta(), tauInputs_indices_[dnn::tau_eta]);
1895  if (sub_version_ == 1) {
1896  get(dnn::tau_phi) = getValueLinear(tau.polarP4().phi(), -pi, pi, false);
1897  }
1898  get(dnn::tau_mass) = sp.scale(tau.polarP4().mass(), tauInputs_indices_[dnn::tau_mass]);
1899  get(dnn::tau_E_over_pt) = sp.scale(tau.p4().energy() / tau.p4().pt(), tauInputs_indices_[dnn::tau_E_over_pt]);
1900  get(dnn::tau_charge) = sp.scale(tau.charge(), tauInputs_indices_[dnn::tau_charge]);
1901  get(dnn::tau_n_charged_prongs) = sp.scale(tau.decayMode() / 5 + 1, tauInputs_indices_[dnn::tau_n_charged_prongs]);
1902  get(dnn::tau_n_neutral_prongs) = sp.scale(tau.decayMode() % 5, tauInputs_indices_[dnn::tau_n_neutral_prongs]);
1903  get(dnn::chargedIsoPtSum) =
1904  sp.scale(tau_funcs.getChargedIsoPtSum(tau, tau_ref), tauInputs_indices_[dnn::chargedIsoPtSum]);
1905  get(dnn::chargedIsoPtSumdR03_over_dR05) =
1906  sp.scale(tau_funcs.getChargedIsoPtSumdR03(tau, tau_ref) / tau_funcs.getChargedIsoPtSum(tau, tau_ref),
1907  tauInputs_indices_[dnn::chargedIsoPtSumdR03_over_dR05]);
1908  if (sub_version_ == 1)
1909  get(dnn::footprintCorrection) =
1910  sp.scale(tau_funcs.getFootprintCorrectiondR03(tau, tau_ref), tauInputs_indices_[dnn::footprintCorrection]);
1911  else if (sub_version_ == 5)
1912  get(dnn::footprintCorrection) =
1913  sp.scale(tau_funcs.getFootprintCorrection(tau, tau_ref), tauInputs_indices_[dnn::footprintCorrection]);
1914 
1915  get(dnn::neutralIsoPtSum) =
1916  sp.scale(tau_funcs.getNeutralIsoPtSum(tau, tau_ref), tauInputs_indices_[dnn::neutralIsoPtSum]);
1917  get(dnn::neutralIsoPtSumWeight_over_neutralIsoPtSum) =
1918  sp.scale(tau_funcs.getNeutralIsoPtSumWeight(tau, tau_ref) / tau_funcs.getNeutralIsoPtSum(tau, tau_ref),
1919  tauInputs_indices_[dnn::neutralIsoPtSumWeight_over_neutralIsoPtSum]);
1920  get(dnn::neutralIsoPtSumWeightdR03_over_neutralIsoPtSum) =
1921  sp.scale(tau_funcs.getNeutralIsoPtSumdR03Weight(tau, tau_ref) / tau_funcs.getNeutralIsoPtSum(tau, tau_ref),
1922  tauInputs_indices_[dnn::neutralIsoPtSumWeightdR03_over_neutralIsoPtSum]);
1923  get(dnn::neutralIsoPtSumdR03_over_dR05) =
1924  sp.scale(tau_funcs.getNeutralIsoPtSumdR03(tau, tau_ref) / tau_funcs.getNeutralIsoPtSum(tau, tau_ref),
1925  tauInputs_indices_[dnn::neutralIsoPtSumdR03_over_dR05]);
1926  get(dnn::photonPtSumOutsideSignalCone) = sp.scale(tau_funcs.getPhotonPtSumOutsideSignalCone(tau, tau_ref),
1927  tauInputs_indices_[dnn::photonPtSumOutsideSignalCone]);
1928  get(dnn::puCorrPtSum) = sp.scale(tau_funcs.getPuCorrPtSum(tau, tau_ref), tauInputs_indices_[dnn::puCorrPtSum]);
1929  // The global PCA coordinates were used as inputs during the NN training, but it was decided to disable
1930  // them for the inference, because modeling of dxy_PCA in MC poorly describes the data, and x and y coordinates
1931  // in data results outside of the expected 5 std. dev. input validity range. On the other hand,
1932  // these coordinates are strongly era-dependent. Kept as comment to document what NN expects.
1933  if (sub_version_ == 1) {
1934  if (!disable_dxy_pca_) {
1935  auto const pca = tau_funcs.getdxyPCA(tau, tau_index);
1936  get(dnn::tau_dxy_pca_x) = sp.scale(pca.x(), tauInputs_indices_[dnn::tau_dxy_pca_x]);
1937  get(dnn::tau_dxy_pca_y) = sp.scale(pca.y(), tauInputs_indices_[dnn::tau_dxy_pca_y]);
1938  get(dnn::tau_dxy_pca_z) = sp.scale(pca.z(), tauInputs_indices_[dnn::tau_dxy_pca_z]);
1939  } else {
1940  get(dnn::tau_dxy_pca_x) = 0;
1941  get(dnn::tau_dxy_pca_y) = 0;
1942  get(dnn::tau_dxy_pca_z) = 0;
1943  }
1944  }
1945 
1946  const bool tau_dxy_valid =
1947  isAbove(tau_funcs.getdxy(tau, tau_index), -10) && isAbove(tau_funcs.getdxyError(tau, tau_index), 0);
1948  if (tau_dxy_valid) {
1949  get(dnn::tau_dxy_valid) = sp.scale(tau_dxy_valid, tauInputs_indices_[dnn::tau_dxy_valid]);
1950  get(dnn::tau_dxy) = sp.scale(tau_funcs.getdxy(tau, tau_index), tauInputs_indices_[dnn::tau_dxy]);
1951  get(dnn::tau_dxy_sig) =
1952  sp.scale(std::abs(tau_funcs.getdxy(tau, tau_index)) / tau_funcs.getdxyError(tau, tau_index),
1953  tauInputs_indices_[dnn::tau_dxy_sig]);
1954  }
1955  const bool tau_ip3d_valid =
1956  isAbove(tau_funcs.getip3d(tau, tau_index), -10) && isAbove(tau_funcs.getip3dError(tau, tau_index), 0);
1957  if (tau_ip3d_valid) {
1958  get(dnn::tau_ip3d_valid) = sp.scale(tau_ip3d_valid, tauInputs_indices_[dnn::tau_ip3d_valid]);
1959  get(dnn::tau_ip3d) = sp.scale(tau_funcs.getip3d(tau, tau_index), tauInputs_indices_[dnn::tau_ip3d]);
1960  get(dnn::tau_ip3d_sig) =
1961  sp.scale(std::abs(tau_funcs.getip3d(tau, tau_index)) / tau_funcs.getip3dError(tau, tau_index),
1962  tauInputs_indices_[dnn::tau_ip3d_sig]);
1963  }
1964  if (leadChargedHadrCand) {
1965  const bool hasTrackDetails = candFunc::getHasTrackDetails(*leadChargedHadrCand);
1966  const float tau_dz = (is_online_ && !hasTrackDetails) ? 0 : candFunc::getTauDz(*leadChargedHadrCand);
1967  get(dnn::tau_dz) = sp.scale(tau_dz, tauInputs_indices_[dnn::tau_dz]);
1968  get(dnn::tau_dz_sig_valid) =
1969  sp.scale(candFunc::getTauDZSigValid(*leadChargedHadrCand), tauInputs_indices_[dnn::tau_dz_sig_valid]);
1970  const double dzError = hasTrackDetails ? leadChargedHadrCand->dzError() : -999.;
1971  get(dnn::tau_dz_sig) = sp.scale(std::abs(tau_dz) / dzError, tauInputs_indices_[dnn::tau_dz_sig]);
1972  }
1973  get(dnn::tau_flightLength_x) =
1974  sp.scale(tau_funcs.getFlightLength(tau, tau_index).x(), tauInputs_indices_[dnn::tau_flightLength_x]);
1975  get(dnn::tau_flightLength_y) =
1976  sp.scale(tau_funcs.getFlightLength(tau, tau_index).y(), tauInputs_indices_[dnn::tau_flightLength_y]);
1977  get(dnn::tau_flightLength_z) =
1978  sp.scale(tau_funcs.getFlightLength(tau, tau_index).z(), tauInputs_indices_[dnn::tau_flightLength_z]);
1979  if (sub_version_ == 1)
1980  get(dnn::tau_flightLength_sig) = 0.55756444; //This value is set due to a bug in the training
1981  else if (sub_version_ == 5)
1982  get(dnn::tau_flightLength_sig) =
1983  sp.scale(tau_funcs.getFlightLengthSig(tau, tau_index), tauInputs_indices_[dnn::tau_flightLength_sig]);
1984 
1985  get(dnn::tau_pt_weighted_deta_strip) = sp.scale(reco::tau::pt_weighted_deta_strip(tau, tau.decayMode()),
1986  tauInputs_indices_[dnn::tau_pt_weighted_deta_strip]);
1987 
1988  get(dnn::tau_pt_weighted_dphi_strip) = sp.scale(reco::tau::pt_weighted_dphi_strip(tau, tau.decayMode()),
1989  tauInputs_indices_[dnn::tau_pt_weighted_dphi_strip]);
1990  get(dnn::tau_pt_weighted_dr_signal) = sp.scale(reco::tau::pt_weighted_dr_signal(tau, tau.decayMode()),
1991  tauInputs_indices_[dnn::tau_pt_weighted_dr_signal]);
1992  get(dnn::tau_pt_weighted_dr_iso) =
1993  sp.scale(reco::tau::pt_weighted_dr_iso(tau, tau.decayMode()), tauInputs_indices_[dnn::tau_pt_weighted_dr_iso]);
1994  get(dnn::tau_leadingTrackNormChi2) =
1995  sp.scale(tau_funcs.getLeadingTrackNormChi2(tau), tauInputs_indices_[dnn::tau_leadingTrackNormChi2]);
1996  const auto eratio = reco::tau::eratio(tau);
1997  const bool tau_e_ratio_valid = std::isnormal(eratio) && eratio > 0.f;
1998  get(dnn::tau_e_ratio_valid) = sp.scale(tau_e_ratio_valid, tauInputs_indices_[dnn::tau_e_ratio_valid]);
1999  get(dnn::tau_e_ratio) = tau_e_ratio_valid ? sp.scale(eratio, tauInputs_indices_[dnn::tau_e_ratio]) : 0.f;
2000  const double gj_angle_diff = calculateGottfriedJacksonAngleDifference(tau, tau_index, tau_funcs);
2001  const bool tau_gj_angle_diff_valid = (std::isnormal(gj_angle_diff) || gj_angle_diff == 0) && gj_angle_diff >= 0;
2002  get(dnn::tau_gj_angle_diff_valid) =
2003  sp.scale(tau_gj_angle_diff_valid, tauInputs_indices_[dnn::tau_gj_angle_diff_valid]);
2004  get(dnn::tau_gj_angle_diff) =
2005  tau_gj_angle_diff_valid ? sp.scale(gj_angle_diff, tauInputs_indices_[dnn::tau_gj_angle_diff]) : 0;
2006  get(dnn::tau_n_photons) = sp.scale(reco::tau::n_photons_total(tau), tauInputs_indices_[dnn::tau_n_photons]);
2007  get(dnn::tau_emFraction) = sp.scale(tau_funcs.getEmFraction(tau), tauInputs_indices_[dnn::tau_emFraction]);
2008 
2009  get(dnn::tau_inside_ecal_crack) =
2010  sp.scale(isInEcalCrack(tau.p4().eta()), tauInputs_indices_[dnn::tau_inside_ecal_crack]);
2011  get(dnn::leadChargedCand_etaAtEcalEntrance_minus_tau_eta) =
2012  sp.scale(tau_funcs.getEtaAtEcalEntrance(tau) - tau.p4().eta(),
2013  tauInputs_indices_[dnn::leadChargedCand_etaAtEcalEntrance_minus_tau_eta]);
2014  }
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:2769
static float getValueLinear(T value, float min_value, float max_value, bool positive)
Definition: DeepTauId.cc:1331
static bool isAbove(double value, double min)
Definition: DeepTauId.cc:1347
static bool isInEcalCrack(double eta)
Definition: DeepTauId.cc:2710
const unsigned sub_version_
Definition: DeepTauId.cc:2767
const std::map< std::pair< deep_tau::Scaling::FeatureT, bool >, deep_tau::Scaling::ScalingParams > * scalingParamsMap_
Definition: DeepTauId.cc:2775
static constexpr float pi
Definition: DeepTauId.cc:1312
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:2679
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:2734
std::vector< int > tauInputs_indices_
Definition: DeepTauId.cc:2780
std::unique_ptr< tensorflow::Tensor > tauBlockTensor_
Definition: DeepTauId.cc:2772

◆ fillDescriptions()

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

Definition at line 1043 of file DeepTauId.cc.

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

1043  {
1045  desc.add<edm::InputTag>("electrons", edm::InputTag("slimmedElectrons"));
1046  desc.add<edm::InputTag>("muons", edm::InputTag("slimmedMuons"));
1047  desc.add<edm::InputTag>("taus", edm::InputTag("slimmedTaus"));
1048  desc.add<edm::InputTag>("pfcands", edm::InputTag("packedPFCandidates"));
1049  desc.add<edm::InputTag>("vertices", edm::InputTag("offlineSlimmedPrimaryVertices"));
1050  desc.add<edm::InputTag>("rho", edm::InputTag("fixedGridRhoAll"));
1051  desc.add<std::vector<std::string>>("graph_file",
1052  {"RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6.pb"});
1053  desc.add<bool>("mem_mapped", false);
1054  desc.add<unsigned>("year", 2017);
1055  desc.add<unsigned>("version", 2);
1056  desc.add<unsigned>("sub_version", 1);
1057  desc.add<int>("debug_level", 0);
1058  desc.add<bool>("disable_dxy_pca", false);
1059  desc.add<bool>("disable_hcalFraction_workaround", false);
1060  desc.add<bool>("disable_CellIndex_workaround", false);
1061  desc.add<bool>("save_inputs", false);
1062  desc.add<bool>("is_online", false);
1063 
1064  desc.add<std::vector<std::string>>("VSeWP", {"-1."});
1065  desc.add<std::vector<std::string>>("VSmuWP", {"-1."});
1066  desc.add<std::vector<std::string>>("VSjetWP", {"-1."});
1067 
1068  desc.addUntracked<edm::InputTag>("basicTauDiscriminators", edm::InputTag("basicTauDiscriminators"));
1069  desc.addUntracked<edm::InputTag>("basicTauDiscriminatorsdR03", edm::InputTag("basicTauDiscriminatorsdR03"));
1070  desc.add<edm::InputTag>("pfTauTransverseImpactParameters", edm::InputTag("hpsPFTauTransverseImpactParameters"));
1071 
1072  {
1073  edm::ParameterSetDescription pset_Prediscriminants;
1074  pset_Prediscriminants.add<std::string>("BooleanOperator", "and");
1075  {
1077  psd1.add<double>("cut");
1078  psd1.add<edm::InputTag>("Producer");
1079  pset_Prediscriminants.addOptional<edm::ParameterSetDescription>("decayMode", psd1);
1080  }
1081  desc.add<edm::ParameterSetDescription>("Prediscriminants", pset_Prediscriminants);
1082  }
1083 
1084  descriptions.add("DeepTau", desc);
1085  }
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 1719 of file DeepTauId.cc.

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

Referenced by getPredictionsV2().

1719  {
1720  static constexpr double outer_dR2 = 0.25; //0.5^2
1721  const double inner_radius = getInnerSignalConeRadius(tau.polarP4().pt());
1722  const double inner_dR2 = std::pow(inner_radius, 2);
1723 
1724  const auto addObject = [&](size_t n, double deta, double dphi, CellGrid& grid) {
1725  const auto& obj = objects.at(n);
1726  const CellObjectType obj_type = GetCellObjectType(obj);
1727  if (obj_type == CellObjectType::Other)
1728  return;
1729  CellIndex cell_index;
1730  if (grid.tryGetCellIndex(deta, dphi, cell_index)) {
1731  Cell& cell = grid[cell_index];
1732  auto iter = cell.find(obj_type);
1733  if (iter != cell.end()) {
1734  const auto& prev_obj = objects.at(iter->second);
1735  if (obj.polarP4().pt() > prev_obj.polarP4().pt())
1736  iter->second = n;
1737  } else {
1738  cell[obj_type] = n;
1739  }
1740  }
1741  };
1742 
1743  for (size_t n = 0; n < objects.size(); ++n) {
1744  const auto& obj = objects.at(n);
1745  const double deta = obj.polarP4().eta() - tau.polarP4().eta();
1746  const double dphi = reco::deltaPhi(obj.polarP4().phi(), tau.polarP4().phi());
1747  const double dR2 = std::pow(deta, 2) + std::pow(dphi, 2);
1748  if (dR2 < inner_dR2)
1749  addObject(n, deta, dphi, inner_grid);
1750  if (dR2 < outer_dR2)
1751  addObject(n, deta, dphi, outer_grid);
1752  }
1753  }
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
static double getInnerSignalConeRadius(double pt)
Definition: DeepTauId.cc:2671
constexpr int pow(int x)
Definition: conifer.h:24
CellObjectType
Definition: DeepTauId.cc:826

◆ 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 2716 of file DeepTauId.cc.

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

2718  {
2719  const double dR2 = deltaR * deltaR;
2720  const pat::Electron* matched_ele = nullptr;
2721  for (const auto& ele : *electrons) {
2722  if (reco::deltaR2(tau.p4(), ele.p4()) < dR2 && (!matched_ele || matched_ele->pt() < ele.pt())) {
2723  matched_ele = &ele;
2724  }
2725  }
2726  return matched_ele;
2727  }
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 2671 of file DeepTauId.cc.

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

Referenced by fillGrids(), and processSignalPFComponents().

2671  {
2672  static constexpr double min_pt = 30., min_radius = 0.05, cone_opening_coef = 3.;
2673  // This is equivalent of the original formula (std::max(std::min(0.1, 3.0/pt), 0.05)
2674  return std::max(cone_opening_coef / std::max(pt, min_pt), min_radius);
2675  }

◆ GetOutputs()

static const OutputCollection& DeepTauId::GetOutputs ( )
inlinestatic

Definition at line 999 of file DeepTauId.cc.

References GetRecoTauVFromDQM_MC_cff::Output, and outputs_.

999  {
1000  static constexpr size_t e_index = 0, mu_index = 1, tau_index = 2, jet_index = 3;
1001  static const OutputCollection outputs_ = {
1002  {"VSe", Output({tau_index}, {e_index, tau_index})},
1003  {"VSmu", Output({tau_index}, {mu_index, tau_index})},
1004  {"VSjet", Output({tau_index}, {jet_index, tau_index})},
1005  };
1006  return outputs_;
1007  }
OutputCollection outputs_
Definition: DeepTauId.cc:2735
std::map< std::string, Output > OutputCollection
Definition: DeepTauId.cc:995

◆ getPartialPredictions()

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

Definition at line 1755 of file DeepTauId.cc.

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

Referenced by createConvFeatures(), and DeepTauId().

1755  {
1756  std::vector<tensorflow::Tensor> pred_vector;
1757  if (is_inner) {
1758  tensorflow::run(&(cache_->getSession("inner")),
1759  {
1760  {"input_inner_egamma", *eGammaTensor_.at(is_inner)},
1761  {"input_inner_muon", *muonTensor_.at(is_inner)},
1762  {"input_inner_hadrons", *hadronsTensor_.at(is_inner)},
1763  },
1764  {"inner_all_dropout_4/Identity"},
1765  &pred_vector);
1766  } else {
1767  tensorflow::run(&(cache_->getSession("outer")),
1768  {
1769  {"input_outer_egamma", *eGammaTensor_.at(is_inner)},
1770  {"input_outer_muon", *muonTensor_.at(is_inner)},
1771  {"input_outer_hadrons", *hadronsTensor_.at(is_inner)},
1772  },
1773  {"outer_all_dropout_4/Identity"},
1774  &pred_vector);
1775  }
1776  return pred_vector.at(0);
1777  }
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > hadronsTensor_
Definition: DeepTauId.cc:2773
const deep_tau::DeepTauCache * cache_
Definition: DeepTauId.cc:2736
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:147
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > eGammaTensor_
Definition: DeepTauId.cc:2773
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > muonTensor_
Definition: DeepTauId.cc:2773

◆ getPredictions()

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

Definition at line 1489 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().

1489  {
1490  // Empty dummy vectors
1491  const std::vector<pat::Electron> electron_collection_default;
1492  const std::vector<pat::Muon> muon_collection_default;
1493  const reco::TauDiscriminatorContainer basicTauDiscriminators_default;
1494  const reco::TauDiscriminatorContainer basicTauDiscriminatorsdR03_default;
1496  pfTauTransverseImpactParameters_default;
1497 
1498  const std::vector<pat::Electron>* electron_collection;
1499  const std::vector<pat::Muon>* muon_collection;
1504 
1505  if (!is_online_) {
1506  electron_collection = &event.get(electrons_token_);
1507  muon_collection = &event.get(muons_token_);
1508  pfTauTransverseImpactParameters = &pfTauTransverseImpactParameters_default;
1509  basicTauDiscriminators = &basicTauDiscriminators_default;
1510  basicTauDiscriminatorsdR03 = &basicTauDiscriminatorsdR03_default;
1511  } else {
1512  electron_collection = &electron_collection_default;
1513  muon_collection = &muon_collection_default;
1517 
1518  // Get indices for discriminators
1519  if (!discrIndicesMapped_) {
1524  discrIndicesMapped_ = true;
1525  }
1526  }
1527 
1528  TauFunc tauIDs = {basicTauDiscriminators,
1533 
1535  event.getByToken(pfcandToken_, pfCands);
1536 
1538  event.getByToken(vtxToken_, vertices);
1539 
1541  event.getByToken(rho_token_, rho);
1542 
1543  auto const& eventnr = event.id().event();
1544 
1545  tensorflow::Tensor predictions(tensorflow::DT_FLOAT, {static_cast<int>(taus->size()), deep_tau::NumberOfOutputs});
1546 
1547  for (size_t tau_index = 0; tau_index < taus->size(); ++tau_index) {
1548  const edm::RefToBase<reco::BaseTau> tauRef = taus->refAt(tau_index);
1549 
1550  std::vector<tensorflow::Tensor> pred_vector;
1551 
1552  bool passesPrediscriminants;
1553  if (is_online_) {
1554  passesPrediscriminants = tauIDs.passPrediscriminants<std::vector<TauDiscInfo<reco::PFTauDiscriminator>>>(
1556  } else {
1557  passesPrediscriminants = tauIDs.passPrediscriminants<std::vector<TauDiscInfo<pat::PATTauDiscriminator>>>(
1559  }
1560 
1561  if (passesPrediscriminants) {
1562  if (version_ == 2) {
1563  if (is_online_) {
1564  getPredictionsV2<reco::PFCandidate, reco::PFTau>(taus->at(tau_index),
1565  tau_index,
1566  tauRef,
1567  electron_collection,
1568  muon_collection,
1569  *pfCands,
1570  vertices->at(0),
1571  *rho,
1572  eventnr,
1573  pred_vector,
1574  tauIDs);
1575  } else
1576  getPredictionsV2<pat::PackedCandidate, pat::Tau>(taus->at(tau_index),
1577  tau_index,
1578  tauRef,
1579  electron_collection,
1580  muon_collection,
1581  *pfCands,
1582  vertices->at(0),
1583  *rho,
1584  eventnr,
1585  pred_vector,
1586  tauIDs);
1587  } else {
1588  throw cms::Exception("DeepTauId") << "version " << version_ << " is not supported.";
1589  }
1590 
1591  for (int k = 0; k < deep_tau::NumberOfOutputs; ++k) {
1592  const float pred = pred_vector[0].flat<float>()(k);
1593  if (!(pred >= 0 && pred <= 1))
1594  throw cms::Exception("DeepTauId")
1595  << "invalid prediction = " << pred << " for tau_index = " << tau_index << ", pred_index = " << k;
1596  predictions.matrix<float>()(tau_index, k) = pred;
1597  }
1598  } else {
1599  // This else statement was added as a part of the DeepTau@HLT development. It does not affect the current state
1600  // of offline DeepTauId code as there the preselection is not used (it was added in the DeepTau@HLT). It returns
1601  // default values for deepTau score if the preselection failed. Before this statement the values given for this tau
1602  // were random. k == 2 corresponds to the tau score and all other k values to e, mu and jets. By defining in this way
1603  // the final score is -1.
1604  for (int k = 0; k < deep_tau::NumberOfOutputs; ++k) {
1605  predictions.matrix<float>()(tau_index, k) = (k == 2) ? -1.f : 2.f;
1606  }
1607  }
1608  }
1609  return predictions;
1610  }
std::map< BasicDiscriminator, size_t > basicDiscrdR03IndexMap_
Definition: DeepTauId.cc:2785
std::map< BasicDiscriminator, size_t > basicDiscrIndexMap_
Definition: DeepTauId.cc:2784
edm::EDGetTokenT< reco::VertexCollection > vtxToken_
Definition: DeepTauId.cc:2732
std::vector< TauDiscInfo< reco::PFTauDiscriminator > > recoPrediscriminants_
Definition: DeepTauId.cc:1309
uint8_t andPrediscriminants_
Definition: DeepTauId.cc:1307
const unsigned version_
Definition: DeepTauId.cc:2766
std::vector< TauDiscInfo< pat::PATTauDiscriminator > > patPrediscriminants_
Definition: DeepTauId.cc:1308
edm::EDGetTokenT< CandidateCollection > pfcandToken_
Definition: DeepTauId.cc:2731
const std::map< BasicDiscriminator, size_t > matchDiscriminatorIndices(edm::Event &event, edm::EDGetTokenT< reco::TauDiscriminatorContainer > discriminatorContainerToken, std::vector< BasicDiscriminator > requiredDiscr)
Definition: DeepTauId.cc:1011
double f[11][100]
const std::vector< BasicDiscriminator > requiredBasicDiscriminators_
Definition: DeepTauId.cc:2745
const std::vector< BasicDiscriminator > requiredBasicDiscriminatorsdR03_
Definition: DeepTauId.cc:2750
edm::EDGetTokenT< edm::AssociationVector< reco::PFTauRefProd, std::vector< reco::PFTauTransverseImpactParameterRef > > > pfTauTransverseImpactParameters_token_
Definition: DeepTauId.cc:2763
bool discrIndicesMapped_
Definition: DeepTauId.cc:2783
edm::EDGetTokenT< reco::TauDiscriminatorContainer > basicTauDiscriminators_inputToken_
Definition: DeepTauId.cc:2760
const bool is_online_
Definition: DeepTauId.cc:2734
edm::EDGetTokenT< reco::TauDiscriminatorContainer > basicTauDiscriminatorsdR03_inputToken_
Definition: DeepTauId.cc:2761
edm::EDGetTokenT< std::vector< pat::Electron > > electrons_token_
Definition: DeepTauId.cc:2757
edm::EDGetTokenT< std::vector< pat::Muon > > muons_token_
Definition: DeepTauId.cc:2758
edm::EDGetTokenT< double > rho_token_
Definition: DeepTauId.cc:2759
Definition: event.py:1
constexpr int NumberOfOutputs
Definition: DeepTauId.cc:156

◆ 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 1613 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().

1623  {
1624  using namespace dnn_inputs_v2;
1625  if (debug_level >= 2) {
1626  std::cout << "<DeepTauId::getPredictionsV2 (moduleLabel = " << moduleDescription().moduleLabel()
1627  << ")>:" << std::endl;
1628  std::cout << " tau: pT = " << tau.pt() << ", eta = " << tau.eta() << ", phi = " << tau.phi()
1629  << ", eventnr = " << eventnr << std::endl;
1630  }
1631  CellGrid inner_grid(number_of_inner_cell, number_of_inner_cell, 0.02, 0.02, disable_CellIndex_workaround_);
1632  CellGrid outer_grid(number_of_outer_cell, number_of_outer_cell, 0.05, 0.05, disable_CellIndex_workaround_);
1633  fillGrids(dynamic_cast<const TauCastType&>(tau), *electrons, inner_grid, outer_grid);
1634  fillGrids(dynamic_cast<const TauCastType&>(tau), *muons, inner_grid, outer_grid);
1635  fillGrids(dynamic_cast<const TauCastType&>(tau), pfCands, inner_grid, outer_grid);
1636 
1637  createTauBlockInputs<CandidateCastType>(
1638  dynamic_cast<const TauCastType&>(tau), tau_index, tau_ref, pv, rho, tau_funcs);
1639  checkInputs(*tauBlockTensor_, "input_tau", static_cast<int>(tauBlockTensor_->shape().dim_size(1)));
1640  createConvFeatures<CandidateCastType>(dynamic_cast<const TauCastType&>(tau),
1641  tau_index,
1642  tau_ref,
1643  pv,
1644  rho,
1645  electrons,
1646  muons,
1647  pfCands,
1648  inner_grid,
1649  tau_funcs,
1650  true);
1651  checkInputs(*eGammaTensor_[true], "input_inner_egamma", EgammaBlockInputs::NumberOfInputs, &inner_grid);
1652  checkInputs(*muonTensor_[true], "input_inner_muon", MuonBlockInputs::NumberOfInputs, &inner_grid);
1653  checkInputs(*hadronsTensor_[true], "input_inner_hadrons", HadronBlockInputs::NumberOfInputs, &inner_grid);
1654  createConvFeatures<CandidateCastType>(dynamic_cast<const TauCastType&>(tau),
1655  tau_index,
1656  tau_ref,
1657  pv,
1658  rho,
1659  electrons,
1660  muons,
1661  pfCands,
1662  outer_grid,
1663  tau_funcs,
1664  false);
1665  checkInputs(*eGammaTensor_[false], "input_outer_egamma", EgammaBlockInputs::NumberOfInputs, &outer_grid);
1666  checkInputs(*muonTensor_[false], "input_outer_muon", MuonBlockInputs::NumberOfInputs, &outer_grid);
1667  checkInputs(*hadronsTensor_[false], "input_outer_hadrons", HadronBlockInputs::NumberOfInputs, &outer_grid);
1668 
1669  if (save_inputs_) {
1670  std::string json_file_name = "DeepTauId_" + std::to_string(eventnr) + "_" + std::to_string(tau_index) + ".json";
1671  json_file_ = new std::ofstream(json_file_name.data());
1672  is_first_block_ = true;
1673  (*json_file_) << "{";
1674  saveInputs(*tauBlockTensor_, "input_tau", static_cast<int>(tauBlockTensor_->shape().dim_size(1)));
1675  saveInputs(
1676  *eGammaTensor_[true], "input_inner_egamma", dnn_inputs_v2::EgammaBlockInputs::NumberOfInputs, &inner_grid);
1677  saveInputs(*muonTensor_[true], "input_inner_muon", dnn_inputs_v2::MuonBlockInputs::NumberOfInputs, &inner_grid);
1678  saveInputs(
1679  *hadronsTensor_[true], "input_inner_hadrons", dnn_inputs_v2::HadronBlockInputs::NumberOfInputs, &inner_grid);
1680  saveInputs(
1681  *eGammaTensor_[false], "input_outer_egamma", dnn_inputs_v2::EgammaBlockInputs::NumberOfInputs, &outer_grid);
1682  saveInputs(*muonTensor_[false], "input_outer_muon", dnn_inputs_v2::MuonBlockInputs::NumberOfInputs, &outer_grid);
1683  saveInputs(
1684  *hadronsTensor_[false], "input_outer_hadrons", dnn_inputs_v2::HadronBlockInputs::NumberOfInputs, &outer_grid);
1685  (*json_file_) << "}";
1686  delete json_file_;
1687  ++file_counter_;
1688  }
1689 
1690  tensorflow::run(&(cache_->getSession("core")),
1691  {{"input_tau", *tauBlockTensor_},
1692  {"input_inner", *convTensor_.at(true)},
1693  {"input_outer", *convTensor_.at(false)}},
1694  {"main_output/Softmax"},
1695  &pred_vector);
1696  if (debug_level >= 1) {
1697  std::cout << "output = { ";
1698  for (int idx = 0; idx < deep_tau::NumberOfOutputs; ++idx) {
1699  if (idx > 0)
1700  std::cout << ", ";
1702  if (idx == 0)
1703  label = "e";
1704  else if (idx == 1)
1705  label = "mu";
1706  else if (idx == 2)
1707  label = "tau";
1708  else if (idx == 3)
1709  label = "jet";
1710  else
1711  assert(0);
1712  std::cout << label << " = " << pred_vector[0].flat<float>()(idx);
1713  }
1714  std::cout << " }" << std::endl;
1715  }
1716  }
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > hadronsTensor_
Definition: DeepTauId.cc:2773
void fillGrids(const TauCastType &tau, const Collection &objects, CellGrid &inner_grid, CellGrid &outer_grid)
Definition: DeepTauId.cc:1719
const bool save_inputs_
Definition: DeepTauId.cc:2776
int file_counter_
Definition: DeepTauId.cc:2779
std::ofstream * json_file_
Definition: DeepTauId.cc:2777
assert(be >=bs)
static std::string to_string(const XMLCh *ch)
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > convTensor_
Definition: DeepTauId.cc:2773
const deep_tau::DeepTauCache * cache_
Definition: DeepTauId.cc:2736
char const * label
bool is_first_block_
Definition: DeepTauId.cc:2778
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:1428
const bool disable_CellIndex_workaround_
Definition: DeepTauId.cc:2771
void checkInputs(const tensorflow::Tensor &inputs, const std::string &block_name, int n_inputs, const CellGrid *grid=nullptr) const
Definition: DeepTauId.cc:1372
tensorflow::Session & getSession(const std::string &name="") const
Definition: DeepTauId.cc:147
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > eGammaTensor_
Definition: DeepTauId.cc:2773
const int debug_level
Definition: DeepTauId.cc:2768
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > muonTensor_
Definition: DeepTauId.cc:2773
constexpr int NumberOfOutputs
Definition: DeepTauId.cc:156
std::unique_ptr< tensorflow::Tensor > tauBlockTensor_
Definition: DeepTauId.cc:2772

◆ getValue()

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

Definition at line 1326 of file DeepTauId.cc.

References f, and relativeConstraints::value.

Referenced by getValueLinear(), and getValueNorm().

1326  {
1327  return std::isnormal(value) ? static_cast<float>(value) : 0.f;
1328  }
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 1331 of file DeepTauId.cc.

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

Referenced by createTauBlockInputs().

1331  {
1332  const float fixed_value = getValue(value);
1333  const float clamped_value = std::clamp(fixed_value, min_value, max_value);
1334  float transformed_value = (clamped_value - min_value) / (max_value - min_value);
1335  if (!positive)
1336  transformed_value = transformed_value * 2 - 1;
1337  return transformed_value;
1338  }
const std::map< ValueQuantityType, double > min_value
static float getValue(T value)
Definition: DeepTauId.cc:1326
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 1341 of file DeepTauId.cc.

References getValue(), and SiStripPI::mean.

1341  {
1342  const float fixed_value = getValue(value);
1343  const float norm_value = (fixed_value - mean) / sigma;
1344  return std::clamp(norm_value, -n_sigmas_max, n_sigmas_max);
1345  }
static float getValue(T value)
Definition: DeepTauId.cc:1326
Definition: value.py:1

◆ globalEndJob()

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

Definition at line 1295 of file DeepTauId.cc.

1295 {}

◆ initializeGlobalCache()

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

Definition at line 1273 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.

1273  {
1274  const auto graph_name_vector = cfg.getParameter<std::vector<std::string>>("graph_file");
1275  std::map<std::string, std::string> graph_names;
1276  for (const auto& entry : graph_name_vector) {
1277  const size_t sep_pos = entry.find(':');
1278  std::string entry_name, graph_file;
1279  if (sep_pos != std::string::npos) {
1280  entry_name = entry.substr(0, sep_pos);
1281  graph_file = entry.substr(sep_pos + 1);
1282  } else {
1283  entry_name = "";
1284  graph_file = entry;
1285  }
1287  if (graph_names.count(entry_name))
1288  throw cms::Exception("DeepTauCache") << "Duplicated graph entries";
1289  graph_names[entry_name] = graph_file;
1290  }
1291  bool mem_mapped = cfg.getParameter<bool>("mem_mapped");
1292  return std::make_unique<deep_tau::DeepTauCache>(graph_names, mem_mapped);
1293  }
std::string fullPath() const
Definition: FileInPath.cc:161

◆ isAbove()

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

Definition at line 1347 of file DeepTauId.cc.

References SiStripPI::min.

Referenced by createTauBlockInputs().

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

◆ isInEcalCrack()

static bool DeepTauId::isInEcalCrack ( double  eta)
inlinestaticprivate

Definition at line 2710 of file DeepTauId.cc.

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

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

2710  {
2711  const double abs_eta = std::abs(eta);
2712  return abs_eta > 1.46 && abs_eta < 1.558;
2713  }
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 1011 of file DeepTauId.cc.

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

Referenced by getPredictions().

1014  {
1015  std::map<std::string, size_t> discrIndexMapStr;
1016  auto const aHandle = event.getHandle(discriminatorContainerToken);
1017  auto const aProv = aHandle.provenance();
1018  if (aProv == nullptr)
1019  aHandle.whyFailed()->raise();
1020  const auto& psetsFromProvenance = edm::parameterSet(aProv->stable(), event.processHistory());
1021  auto const idlist = psetsFromProvenance.getParameter<std::vector<edm::ParameterSet>>("IDdefinitions");
1022  for (size_t j = 0; j < idlist.size(); ++j) {
1023  std::string idname = idlist[j].getParameter<std::string>("IDname");
1024  if (discrIndexMapStr.count(idname)) {
1025  throw cms::Exception("DeepTauId")
1026  << "basic discriminator " << idname << " appears more than once in the input.";
1027  }
1028  discrIndexMapStr[idname] = j;
1029  }
1030 
1031  //translate to a map of <BasicDiscriminator, index> and check if all discriminators are present
1032  std::map<BasicDiscriminator, size_t> discrIndexMap;
1033  for (size_t i = 0; i < requiredDiscr.size(); i++) {
1034  if (discrIndexMapStr.find(stringFromDiscriminator_.at(requiredDiscr[i])) == discrIndexMapStr.end())
1035  throw cms::Exception("DeepTauId") << "Basic Discriminator " << stringFromDiscriminator_.at(requiredDiscr[i])
1036  << " was not provided in the config file.";
1037  else
1038  discrIndexMap[requiredDiscr[i]] = discrIndexMapStr[stringFromDiscriminator_.at(requiredDiscr[i])];
1039  }
1040  return discrIndexMap;
1041  }
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
ParameterSet const & parameterSet(StableProvenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:11
const std::map< BasicDiscriminator, std::string > stringFromDiscriminator_
Definition: DeepTauId.cc:2738

◆ 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 2649 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, DiDispStaMuonMonitor_cfi::pt, and metsig::tau.

2656  {
2657  p4 = LorentzVectorXYZ(0, 0, 0, 0);
2658  n = 0;
2659 
2660  for (const auto& cand : candidates) {
2661  p4 += cand->p4();
2662  ++n;
2663  }
2664 
2665  pt = n != 0 ? p4.Pt() : default_value;
2666  d_eta = n != 0 ? dEta(p4, tau.p4()) : default_value;
2667  d_phi = n != 0 ? dPhi(p4, tau.p4()) : default_value;
2668  m = n != 0 ? p4.mass() : default_value;
2669  }
static constexpr float default_value
Definition: DeepTauId.cc:997
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > LorentzVectorXYZ
Definition: DeepTauId.cc:953

◆ 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 2605 of file DeepTauId.cc.

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

2618  {
2619  p4_inner = LorentzVectorXYZ(0, 0, 0, 0);
2620  p4_outer = LorentzVectorXYZ(0, 0, 0, 0);
2621  n_inner = 0;
2622  n_outer = 0;
2623 
2624  const double innerSigCone_radius = getInnerSignalConeRadius(tau.pt());
2625  for (const auto& cand : candidates) {
2626  const double dR = reco::deltaR(cand->p4(), tau.leadChargedHadrCand()->p4());
2627  const bool isInside_innerSigCone = dR < innerSigCone_radius;
2628  if (isInside_innerSigCone) {
2629  p4_inner += cand->p4();
2630  ++n_inner;
2631  } else {
2632  p4_outer += cand->p4();
2633  ++n_outer;
2634  }
2635  }
2636 
2637  pt_inner = n_inner != 0 ? p4_inner.Pt() : default_value;
2638  dEta_inner = n_inner != 0 ? dEta(p4_inner, tau.p4()) : default_value;
2639  dPhi_inner = n_inner != 0 ? dPhi(p4_inner, tau.p4()) : default_value;
2640  m_inner = n_inner != 0 ? p4_inner.mass() : default_value;
2641 
2642  pt_outer = n_outer != 0 ? p4_outer.Pt() : default_value;
2643  dEta_outer = n_outer != 0 ? dEta(p4_outer, tau.p4()) : default_value;
2644  dPhi_outer = n_outer != 0 ? dPhi(p4_outer, tau.p4()) : default_value;
2645  m_outer = n_outer != 0 ? p4_outer.mass() : default_value;
2646  }
static constexpr float default_value
Definition: DeepTauId.cc:997
static double getInnerSignalConeRadius(double pt)
Definition: DeepTauId.cc:2671
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:953

◆ produce()

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

Definition at line 1242 of file DeepTauId.cc.

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

1242  {
1244  event.getByToken(tausToken_, taus);
1245  edm::ProductID tauProductID = taus.id();
1246 
1247  // load prediscriminators
1248  size_t nPrediscriminants =
1250  for (size_t iDisc = 0; iDisc < nPrediscriminants; ++iDisc) {
1251  edm::ProductID discKeyId;
1252  if (is_online_) {
1253  recoPrediscriminants_[iDisc].fill(event);
1254  discKeyId = recoPrediscriminants_[iDisc].handle->keyProduct().id();
1255  } else {
1256  patPrediscriminants_[iDisc].fill(event);
1257  discKeyId = patPrediscriminants_[iDisc].handle->keyProduct().id();
1258  }
1259 
1260  // Check to make sure the product is correct for the discriminator.
1261  // If not, throw a more informative exception.
1262  if (tauProductID != discKeyId) {
1263  throw cms::Exception("MisconfiguredPrediscriminant")
1264  << "The tau collection has product ID: " << tauProductID
1265  << " but the pre-discriminator is keyed with product ID: " << discKeyId << std::endl;
1266  }
1267  }
1268 
1269  const tensorflow::Tensor& pred = getPredictions(event, taus);
1270  createOutputs(event, pred, taus);
1271  }
tensorflow::Tensor getPredictions(edm::Event &event, edm::Handle< TauCollection > taus)
Definition: DeepTauId.cc:1489
std::vector< TauDiscInfo< reco::PFTauDiscriminator > > recoPrediscriminants_
Definition: DeepTauId.cc:1309
std::vector< TauDiscInfo< pat::PATTauDiscriminator > > patPrediscriminants_
Definition: DeepTauId.cc:1308
edm::EDGetTokenT< TauCollection > tausToken_
Definition: DeepTauId.cc:2730
void createOutputs(edm::Event &event, const tensorflow::Tensor &pred, edm::Handle< TauCollection > taus)
Definition: DeepTauId.cc:1314
const bool is_online_
Definition: DeepTauId.cc:2734
Definition: event.py:1

◆ saveInputs()

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

Definition at line 1428 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().

1431  {
1432  if (debug_level >= 1) {
1433  std::cout << "<saveInputs>: block_name = " << block_name << std::endl;
1434  }
1435  if (!is_first_block_)
1436  (*json_file_) << ", ";
1437  (*json_file_) << "\"" << block_name << "\": [";
1438  if (block_name == "input_tau") {
1439  for (int input_index = 0; input_index < n_inputs; ++input_index) {
1440  float input = inputs.matrix<float>()(0, input_index);
1441  if (input_index != 0)
1442  (*json_file_) << ", ";
1443  (*json_file_) << input;
1444  }
1445  } else {
1446  assert(grid);
1447  int n_eta, n_phi;
1448  if (block_name.find("input_inner") != std::string::npos) {
1449  n_eta = 5;
1450  n_phi = 5;
1451  } else if (block_name.find("input_outer") != std::string::npos) {
1452  n_eta = 10;
1453  n_phi = 10;
1454  } else
1455  assert(0);
1456  int eta_phi_index = 0;
1457  for (int eta = -n_eta; eta <= n_eta; ++eta) {
1458  if (eta != -n_eta)
1459  (*json_file_) << ", ";
1460  (*json_file_) << "[";
1461  for (int phi = -n_phi; phi <= n_phi; ++phi) {
1462  if (phi != -n_phi)
1463  (*json_file_) << ", ";
1464  (*json_file_) << "[";
1465  const CellIndex cell_index{eta, phi};
1466  const auto cell_iter = grid->find(cell_index);
1467  for (int input_index = 0; input_index < n_inputs; ++input_index) {
1468  float input = 0.;
1469  if (cell_iter != grid->end()) {
1470  input = inputs.tensor<float, 4>()(eta_phi_index, 0, 0, input_index);
1471  }
1472  if (input_index != 0)
1473  (*json_file_) << ", ";
1474  (*json_file_) << input;
1475  }
1476  if (cell_iter != grid->end()) {
1477  eta_phi_index += 1;
1478  }
1479  (*json_file_) << "]";
1480  }
1481  (*json_file_) << "]";
1482  }
1483  }
1484  (*json_file_) << "]";
1485  is_first_block_ = false;
1486  }
assert(be >=bs)
static std::string const input
Definition: EdmProvDump.cc:50
bool is_first_block_
Definition: DeepTauId.cc:2778
const int debug_level
Definition: DeepTauId.cc:2768

◆ setCellConvFeatures()

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

Definition at line 1861 of file DeepTauId.cc.

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

Referenced by createConvFeatures(), and DeepTauId().

1865  {
1866  for (int n = 0; n < dnn_inputs_v2::number_of_conv_features; ++n) {
1867  convTensor.tensor<float, 4>()(0, eta_index, phi_index, n) = features.tensor<float, 4>()(batch_idx, 0, 0, n);
1868  }
1869  }
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 1307 of file DeepTauId.cc.

Referenced by DeepTauId(), and getPredictions().

◆ basicDiscrdR03IndexMap_

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

Definition at line 2785 of file DeepTauId.cc.

Referenced by getPredictions().

◆ basicDiscrIndexMap_

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

Definition at line 2784 of file DeepTauId.cc.

Referenced by getPredictions().

◆ basicTauDiscriminators_inputToken_

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

Definition at line 2760 of file DeepTauId.cc.

Referenced by getPredictions().

◆ basicTauDiscriminatorsdR03_inputToken_

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

Definition at line 2761 of file DeepTauId.cc.

Referenced by getPredictions().

◆ cache_

const deep_tau::DeepTauCache* DeepTauId::cache_
private

Definition at line 2736 of file DeepTauId.cc.

Referenced by getPartialPredictions(), and getPredictionsV2().

◆ convTensor_

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

Definition at line 2773 of file DeepTauId.cc.

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

◆ debug_level

const int DeepTauId::debug_level
private

Definition at line 2768 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 2771 of file DeepTauId.cc.

Referenced by getPredictionsV2().

◆ disable_dxy_pca_

const bool DeepTauId::disable_dxy_pca_
private

Definition at line 2769 of file DeepTauId.cc.

Referenced by createTauBlockInputs().

◆ disable_hcalFraction_workaround_

const bool DeepTauId::disable_hcalFraction_workaround_
private

Definition at line 2770 of file DeepTauId.cc.

Referenced by createHadronsBlockInputs().

◆ discrIndicesMapped_

bool DeepTauId::discrIndicesMapped_ = false
private

Definition at line 2783 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 2757 of file DeepTauId.cc.

Referenced by getPredictions().

◆ file_counter_

int DeepTauId::file_counter_
private

Definition at line 2779 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 2764 of file DeepTauId.cc.

◆ is_first_block_

bool DeepTauId::is_first_block_
private

Definition at line 2778 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 2777 of file DeepTauId.cc.

Referenced by getPredictionsV2().

◆ muons_token_

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

Definition at line 2758 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 2764 of file DeepTauId.cc.

◆ outputs_

OutputCollection DeepTauId::outputs_
private

Definition at line 2735 of file DeepTauId.cc.

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

◆ patPrediscriminants_

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

Definition at line 1308 of file DeepTauId.cc.

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

◆ pfcandToken_

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

Definition at line 2731 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 2763 of file DeepTauId.cc.

Referenced by getPredictions().

◆ pi

constexpr float DeepTauId::pi = M_PI
staticprivate

Definition at line 1312 of file DeepTauId.cc.

Referenced by createTauBlockInputs().

◆ recoPrediscriminants_

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

Definition at line 1309 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 2759 of file DeepTauId.cc.

Referenced by getPredictions().

◆ save_inputs_

const bool DeepTauId::save_inputs_
private

Definition at line 2776 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 2738 of file DeepTauId.cc.

Referenced by matchDiscriminatorIndices().

◆ sub_version_

const unsigned DeepTauId::sub_version_
private

Definition at line 2767 of file DeepTauId.cc.

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

◆ tauBlockTensor_

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

Definition at line 2772 of file DeepTauId.cc.

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

◆ tauInputs_indices_

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

Definition at line 2780 of file DeepTauId.cc.

Referenced by createTauBlockInputs(), and DeepTauId().

◆ tausToken_

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

Definition at line 2730 of file DeepTauId.cc.

Referenced by produce().

◆ version_

const unsigned DeepTauId::version_
private

Definition at line 2766 of file DeepTauId.cc.

Referenced by DeepTauId(), and getPredictions().

◆ vtxToken_

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

Definition at line 2732 of file DeepTauId.cc.

Referenced by getPredictions().

◆ workingPoints_

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

Definition at line 2733 of file DeepTauId.cc.

Referenced by createOutputs(), and DeepTauId().

◆ year_

const unsigned DeepTauId::year_
private

Definition at line 2765 of file DeepTauId.cc.

Referenced by createEgammaBlockInputs(), and DeepTauId().

◆ zeroOutputTensor_

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

Definition at line 2773 of file DeepTauId.cc.

Referenced by createConvFeatures(), and DeepTauId().